From 49bedf1cc3bb54c597b595383cf4b1348d27b8b1 Mon Sep 17 00:00:00 2001 From: Konstantin Anisimov Date: Mon, 9 Jan 2017 10:51:37 +0700 Subject: [PATCH] Comments added --- .../backend/konan/lower/FunctionInlining.kt | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) 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 c7145b69056..5c41d1a313e 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 @@ -9,7 +9,6 @@ import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.declarations.IrFile import org.jetbrains.kotlin.ir.declarations.IrFunction import org.jetbrains.kotlin.ir.expressions.* -import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl import org.jetbrains.kotlin.ir.expressions.impl.IrBlockImpl import org.jetbrains.kotlin.ir.util.DeepCopyIrTree import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid @@ -30,25 +29,25 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoid( //-------------------------------------------------------------------------// override fun visitCall(expression: IrCall): IrExpression { - val functionDescriptor = expression.descriptor as FunctionDescriptor // - if (!functionDescriptor.isInline) return super.visitCall(expression) // function is not to be inlined - do nothing + val functionDescriptor = expression.descriptor as FunctionDescriptor + if (!functionDescriptor.isInline) return super.visitCall(expression) // Function is not to be inlined - do nothing. - val functionDeclaration = context.ir.moduleIndex.functions[functionDescriptor] // get FunctionDeclaration by FunctionDescriptor - if (functionDeclaration == null) return super.visitCall(expression) // TODO what if we do not have declaration? - val copyFuncDeclaration = functionDeclaration.accept(DeepCopyIrTree(), null) as IrFunction + val functionDeclaration = context.ir.moduleIndex.functions[functionDescriptor] // Get FunctionDeclaration by FunctionDescriptor. + if (functionDeclaration == null) return super.visitCall(expression) // Function is declared in another module. + val copyFuncDeclaration = functionDeclaration.accept(DeepCopyIrTree(), null) as IrFunction // Create copy of the function. val body = copyFuncDeclaration.body!! as IrBlockBody - val statements = removeReturn(body.statements) + val statements = removeReturn(body.statements) // Replace "return" with its value. val startOffset = copyFuncDeclaration.startOffset val endOffset = copyFuncDeclaration.endOffset val returnType = copyFuncDeclaration.descriptor.returnType!! - val irBlock = IrBlockImpl(startOffset, endOffset, returnType, null, statements) // create + val irBlock = IrBlockImpl(startOffset, endOffset, returnType, null, statements) // Create IrBlock containing function statements. - val parameterToExpression = expression.getArguments() + val parameterToExpression = expression.getArguments() // Build map parameter -> expression. val parametersTransformer = ParametersTransformer(parameterToExpression) - irBlock.accept(parametersTransformer, null) + irBlock.accept(parametersTransformer, null) // Replace parameters with expression. - return irBlock + return irBlock // Return newly created IrBlock instead of IrCall. } //-------------------------------------------------------------------------// @@ -66,10 +65,10 @@ internal class ParametersTransformer(val parameterToExpression: List