From 90a43a4c623408a44a2531ea9db65e89d3a4f0ab Mon Sep 17 00:00:00 2001 From: Konstantin Anisimov Date: Wed, 12 Apr 2017 10:27:57 +0700 Subject: [PATCH] Code refactoring --- .../common/DeepCopyIrTreeWithDescriptoros.kt | 13 +++++++------ .../kotlin/backend/konan/lower/FunctionInlining.kt | 12 ++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/common/DeepCopyIrTreeWithDescriptoros.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/common/DeepCopyIrTreeWithDescriptoros.kt index 66d4bccd2c3..2502a8eeb20 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/common/DeepCopyIrTreeWithDescriptoros.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/common/DeepCopyIrTreeWithDescriptoros.kt @@ -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 , containingDeclaration: CallableDescriptor): List { @@ -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 diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt index 29821c4d8c3..197c65f4aa3 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt @@ -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 ) - //---------------------------------------------------------------------// + //-------------------------------------------------------------------------// private fun buildParameterToArgument(irCall : IrCall, // Call site. irFunction: IrFunction // Function to be called.