New "return" remove scheme
This commit is contained in:
+10
-2
@@ -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 copyFuncDeclaration = functionDeclaration.accept(DeepCopyIrTree(), null) as IrFunction // Create copy of the function.
|
||||||
|
|
||||||
val body = copyFuncDeclaration.body!! as IrBlockBody
|
val body = copyFuncDeclaration.body!! as IrBlockBody
|
||||||
val statements = removeReturn(body.statements) // Replace "return" with its value.
|
|
||||||
val startOffset = copyFuncDeclaration.startOffset
|
val startOffset = copyFuncDeclaration.startOffset
|
||||||
val endOffset = copyFuncDeclaration.endOffset
|
val endOffset = copyFuncDeclaration.endOffset
|
||||||
val returnType = copyFuncDeclaration.descriptor.returnType!!
|
val returnType = copyFuncDeclaration.descriptor.returnType!!
|
||||||
|
val statements = body.statements
|
||||||
val irBlock = IrBlockImpl(startOffset, endOffset, returnType, null, statements) // Create IrBlock containing function statements.
|
val irBlock = IrBlockImpl(startOffset, endOffset, returnType, null, statements) // Create IrBlock containing function statements.
|
||||||
|
|
||||||
val parameterToExpression = expression.getArguments() // Build map parameter -> expression.
|
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 {
|
override fun visitGetValue(expression: IrGetValue): IrExpression {
|
||||||
val descriptor = expression.descriptor
|
val descriptor = expression.descriptor
|
||||||
if (descriptor !is ParameterDescriptor) { // TODO do we need this check?
|
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.
|
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?
|
return parExp?.let { parExp.second } ?: super.visitGetValue(expression) // TODO should we proceed with IR iteration here?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user