New "return" remove scheme

This commit is contained in:
Konstantin Anisimov
2017-01-11 16:21:42 +07:00
parent 9a363ceaf6
commit eba08c5674
@@ -37,10 +37,10 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoid(
val copyFuncDeclaration = functionDeclaration.accept(DeepCopyIrTree(), null) as IrFunction // Create copy of the function.
val body = copyFuncDeclaration.body!! as IrBlockBody
val statements = removeReturn(body.statements) // Replace "return" with its value.
val startOffset = copyFuncDeclaration.startOffset
val endOffset = copyFuncDeclaration.endOffset
val returnType = copyFuncDeclaration.descriptor.returnType!!
val statements = body.statements
val irBlock = IrBlockImpl(startOffset, endOffset, returnType, null, statements) // Create IrBlock containing function statements.
val parameterToExpression = expression.getArguments() // Build map parameter -> expression.
@@ -63,6 +63,14 @@ internal class ParametersTransformer(val parameterToExpression: List <Pair<Param
//-------------------------------------------------------------------------//
override fun visitReturn(expression: IrReturn): IrExpression {
val transformedExpression = super.visitReturn(expression) as IrReturn
return transformedExpression.value
}
//-------------------------------------------------------------------------//
override fun visitGetValue(expression: IrGetValue): IrExpression {
val descriptor = expression.descriptor
if (descriptor !is ParameterDescriptor) { // TODO do we need this check?
@@ -71,4 +79,4 @@ internal class ParametersTransformer(val parameterToExpression: List <Pair<Param
val parExp = parameterToExpression.find { it.first == descriptor } // Find expression to replace this parameter.
return parExp?.let { parExp.second } ?: super.visitGetValue(expression) // TODO should we proceed with IR iteration here?
}
}
}