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.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassOrAny
|
||||
@@ -125,6 +124,8 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr,
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------//
|
||||
|
||||
override fun visitPropertyNew(declaration: IrProperty) {
|
||||
|
||||
copyPropertyOrField(declaration.descriptor)
|
||||
@@ -132,6 +133,8 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr,
|
||||
super.visitPropertyNew(declaration)
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------//
|
||||
|
||||
override fun visitFieldNew(declaration: IrField) {
|
||||
|
||||
val oldDescriptor = declaration.descriptor
|
||||
@@ -267,7 +270,7 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr,
|
||||
|
||||
initialize(
|
||||
/* receiverParameterType = */ receiverParameterType,
|
||||
/* dispatchReceiverParameter = */ null, // For constructor there is no explicit dispatch receiver.
|
||||
/* dispatchReceiverParameter = */ null, // For constructor there is no explicit dispatch receiver.
|
||||
/* typeParameters = */ newTypeParameters,
|
||||
/* unsubstitutedValueParameters = */ newValueParameters,
|
||||
/* unsubstitutedReturnType = */ returnType,
|
||||
@@ -277,7 +280,6 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------//
|
||||
|
||||
private fun copyPropertyDescriptor(oldDescriptor: PropertyDescriptor): PropertyDescriptor {
|
||||
@@ -413,7 +415,6 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr,
|
||||
//--- Visits ----------------------------------------------------------//
|
||||
|
||||
override fun visitCall(expression: IrCall): IrCall {
|
||||
|
||||
val oldExpression = super.visitCall(expression)
|
||||
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 {
|
||||
|
||||
val typeOperand = substituteType(expression.typeOperand)!!
|
||||
val returnType = getTypeOperatorReturnType(expression.operator, typeOperand)
|
||||
return IrTypeOperatorCallImpl(
|
||||
@@ -515,7 +515,7 @@ internal class DeepCopyIrTreeWithDescriptors(val targetScope: ScopeWithIr,
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------//
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
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 {
|
||||
|
||||
val oldDescriptor = oldExpression.descriptor
|
||||
val newDescriptor = descriptorSubstituteMap.getOrDefault(oldDescriptor.original,
|
||||
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.
|
||||
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.
|
||||
return irCall
|
||||
}
|
||||
@@ -122,7 +122,7 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoidW
|
||||
) as IrExpression
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------//
|
||||
//---------------------------------------------------------------------//
|
||||
|
||||
override fun visitCall(expression: IrCall): IrExpression {
|
||||
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.
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------//
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
private fun isLambdaExpression(expression: IrExpression) : Boolean {
|
||||
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.
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------//
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
private fun getLambdaFunction(lambdaArgument: IrBlock): IrFunction {
|
||||
val statements = lambdaArgument.statements
|
||||
return statements[0] as IrFunction
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------//
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
private fun argumentNeedsEvaluation(expression: IrExpression): Boolean {
|
||||
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>
|
||||
)
|
||||
|
||||
//---------------------------------------------------------------------//
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
private fun buildParameterToArgument(irCall : IrCall, // Call site.
|
||||
irFunction: IrFunction // Function to be called.
|
||||
|
||||
Reference in New Issue
Block a user