Code refactoring
This commit is contained in:
committed by
KonstantinAnisimov
parent
1f1de99878
commit
90a43a4c62
+7
-6
@@ -33,7 +33,6 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrTypeOperatorCallImpl
|
|||||||
import org.jetbrains.kotlin.ir.util.DeepCopyIrTree
|
import org.jetbrains.kotlin.ir.util.DeepCopyIrTree
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassOrAny
|
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassOrAny
|
||||||
@@ -125,6 +124,8 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------//
|
||||||
|
|
||||||
override fun visitPropertyNew(declaration: IrProperty) {
|
override fun visitPropertyNew(declaration: IrProperty) {
|
||||||
|
|
||||||
copyPropertyOrField(declaration.descriptor)
|
copyPropertyOrField(declaration.descriptor)
|
||||||
@@ -132,6 +133,8 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr,
|
|||||||
super.visitPropertyNew(declaration)
|
super.visitPropertyNew(declaration)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------//
|
||||||
|
|
||||||
override fun visitFieldNew(declaration: IrField) {
|
override fun visitFieldNew(declaration: IrField) {
|
||||||
|
|
||||||
val oldDescriptor = declaration.descriptor
|
val oldDescriptor = declaration.descriptor
|
||||||
@@ -267,7 +270,7 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr,
|
|||||||
|
|
||||||
initialize(
|
initialize(
|
||||||
/* receiverParameterType = */ receiverParameterType,
|
/* receiverParameterType = */ receiverParameterType,
|
||||||
/* dispatchReceiverParameter = */ null, // For constructor there is no explicit dispatch receiver.
|
/* dispatchReceiverParameter = */ null, // For constructor there is no explicit dispatch receiver.
|
||||||
/* typeParameters = */ newTypeParameters,
|
/* typeParameters = */ newTypeParameters,
|
||||||
/* unsubstitutedValueParameters = */ newValueParameters,
|
/* unsubstitutedValueParameters = */ newValueParameters,
|
||||||
/* unsubstitutedReturnType = */ returnType,
|
/* unsubstitutedReturnType = */ returnType,
|
||||||
@@ -277,7 +280,6 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------//
|
//---------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun copyPropertyDescriptor(oldDescriptor: PropertyDescriptor): PropertyDescriptor {
|
private fun copyPropertyDescriptor(oldDescriptor: PropertyDescriptor): PropertyDescriptor {
|
||||||
@@ -413,7 +415,6 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr,
|
|||||||
//--- Visits ----------------------------------------------------------//
|
//--- Visits ----------------------------------------------------------//
|
||||||
|
|
||||||
override fun visitCall(expression: IrCall): IrCall {
|
override fun visitCall(expression: IrCall): IrCall {
|
||||||
|
|
||||||
val oldExpression = super.visitCall(expression)
|
val oldExpression = super.visitCall(expression)
|
||||||
if (oldExpression !is IrCallImpl) return oldExpression // TODO what other kinds of call can we meet?
|
if (oldExpression !is IrCallImpl) return oldExpression // TODO what other kinds of call can we meet?
|
||||||
|
|
||||||
@@ -473,7 +474,6 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr,
|
|||||||
//---------------------------------------------------------------------//
|
//---------------------------------------------------------------------//
|
||||||
|
|
||||||
override fun visitTypeOperator(expression: IrTypeOperatorCall): IrTypeOperatorCall {
|
override fun visitTypeOperator(expression: IrTypeOperatorCall): IrTypeOperatorCall {
|
||||||
|
|
||||||
val typeOperand = substituteType(expression.typeOperand)!!
|
val typeOperand = substituteType(expression.typeOperand)!!
|
||||||
val returnType = getTypeOperatorReturnType(expression.operator, typeOperand)
|
val returnType = getTypeOperatorReturnType(expression.operator, typeOperand)
|
||||||
return IrTypeOperatorCallImpl(
|
return IrTypeOperatorCallImpl(
|
||||||
@@ -515,7 +515,7 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun copyValueParameters(oldValueParameters: List <ValueParameterDescriptor>, containingDeclaration: CallableDescriptor): List <ValueParameterDescriptor> {
|
private fun copyValueParameters(oldValueParameters: List <ValueParameterDescriptor>, containingDeclaration: CallableDescriptor): List <ValueParameterDescriptor> {
|
||||||
|
|
||||||
@@ -541,6 +541,7 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr,
|
|||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun copyIrCallImpl(oldExpression: IrCallImpl): IrCallImpl {
|
private fun copyIrCallImpl(oldExpression: IrCallImpl): IrCallImpl {
|
||||||
|
|
||||||
val oldDescriptor = oldExpression.descriptor
|
val oldDescriptor = oldExpression.descriptor
|
||||||
val newDescriptor = descriptorSubstituteMap.getOrDefault(oldDescriptor.original,
|
val newDescriptor = descriptorSubstituteMap.getOrDefault(oldDescriptor.original,
|
||||||
oldDescriptor) as FunctionDescriptor
|
oldDescriptor) as FunctionDescriptor
|
||||||
|
|||||||
+6
-6
@@ -61,7 +61,7 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoidW
|
|||||||
|
|
||||||
val functionDeclaration = getFunctionDeclaration(irCall) // Get declaration of the function to be inlined.
|
val functionDeclaration = getFunctionDeclaration(irCall) // Get declaration of the function to be inlined.
|
||||||
if (functionDeclaration == null) { // We failed to get the declaration.
|
if (functionDeclaration == null) { // We failed to get the declaration.
|
||||||
val message = "Failed to obtain inline function declaration"
|
val message = "Inliner failed to obtain inline function declaration"
|
||||||
context.reportWarning(message, currentFile, irCall) // Report warning.
|
context.reportWarning(message, currentFile, irCall) // Report warning.
|
||||||
return irCall
|
return irCall
|
||||||
}
|
}
|
||||||
@@ -122,7 +122,7 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoidW
|
|||||||
) as IrExpression
|
) as IrExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------//
|
//---------------------------------------------------------------------//
|
||||||
|
|
||||||
override fun visitCall(expression: IrCall): IrExpression {
|
override fun visitCall(expression: IrCall): IrExpression {
|
||||||
if (!isLambdaCall(expression)) return super.visitCall(expression) // If it is not lambda call - return.
|
if (!isLambdaCall(expression)) return super.visitCall(expression) // If it is not lambda call - return.
|
||||||
@@ -156,7 +156,7 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoidW
|
|||||||
return true // It is lambda call.
|
return true // It is lambda call.
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun isLambdaExpression(expression: IrExpression) : Boolean {
|
private fun isLambdaExpression(expression: IrExpression) : Boolean {
|
||||||
if (expression !is IrBlock) return false // Lambda mast be represented with IrBlock.
|
if (expression !is IrBlock) return false // Lambda mast be represented with IrBlock.
|
||||||
@@ -171,14 +171,14 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoidW
|
|||||||
return true // The expression represents lambda.
|
return true // The expression represents lambda.
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun getLambdaFunction(lambdaArgument: IrBlock): IrFunction {
|
private fun getLambdaFunction(lambdaArgument: IrBlock): IrFunction {
|
||||||
val statements = lambdaArgument.statements
|
val statements = lambdaArgument.statements
|
||||||
return statements[0] as IrFunction
|
return statements[0] as IrFunction
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun argumentNeedsEvaluation(expression: IrExpression): Boolean {
|
private fun argumentNeedsEvaluation(expression: IrExpression): Boolean {
|
||||||
if (expression is IrGetValue) return false // Parameter is already GetValue - nothing to evaluate.
|
if (expression is IrGetValue) return false // Parameter is already GetValue - nothing to evaluate.
|
||||||
@@ -224,7 +224,7 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoidW
|
|||||||
val evaluationStatements : MutableList<IrStatement>
|
val evaluationStatements : MutableList<IrStatement>
|
||||||
)
|
)
|
||||||
|
|
||||||
//---------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun buildParameterToArgument(irCall : IrCall, // Call site.
|
private fun buildParameterToArgument(irCall : IrCall, // Call site.
|
||||||
irFunction: IrFunction // Function to be called.
|
irFunction: IrFunction // Function to be called.
|
||||||
|
|||||||
Reference in New Issue
Block a user