Extract IrBody.statements utility function

This commit is contained in:
Steven Schäfer
2019-07-23 14:07:15 +02:00
committed by max-kammerer
parent 509d257475
commit 917435a50c
2 changed files with 13 additions and 18 deletions
@@ -140,7 +140,7 @@ private class JvmInlineClassLowering(private val context: JvmBackendContext) : F
)
valueMap[constructor.constructedClass.thisReceiver!!.symbol] = thisVar
constructor.body?.contents?.forEach { statement ->
constructor.body?.statements?.forEach { statement ->
+statement
.transform(object : IrElementTransformerVoid() {
// Don't recurse under nested class declarations
@@ -213,14 +213,6 @@ private class JvmInlineClassLowering(private val context: JvmBackendContext) : F
}
}
private fun buildReplacementCall(
originalFunction: IrFunction,
original: IrFunctionAccessExpression,
replacement: IrReplacementFunction
) = context.createIrBuilder(original.symbol)
.irCall(replacement.function)
.apply { buildReplacement(originalFunction, original, replacement) }
override fun visitFunctionReference(expression: IrFunctionReference): IrExpression {
val replacement = manager.getReplacementFunction(expression.symbol.owner)
?: return super.visitFunctionReference(expression)
@@ -240,7 +232,9 @@ private class JvmInlineClassLowering(private val context: JvmBackendContext) : F
val function = expression.symbol.owner
val replacement = manager.getReplacementFunction(function)
?: return super.visitFunctionAccess(expression)
return buildReplacementCall(function, expression, replacement)
return context.createIrBuilder(expression.symbol).irCall(replacement.function).apply {
buildReplacement(function, expression, replacement)
}
}
private fun coerceInlineClasses(argument: IrExpression, from: IrType, to: IrType) =
@@ -377,11 +371,3 @@ private class JvmInlineClassLowering(private val context: JvmBackendContext) : F
irClass.declarations += function
}
}
private val IrBody.contents: List<IrStatement>
get() = when (this) {
is IrBlockBody -> statements
is IrExpressionBody -> listOf(expression)
is IrSyntheticBody -> error("Synthetic body contains no statements $this")
else -> throw IllegalStateException()
}
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.ir.util
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
@@ -198,6 +199,14 @@ val IrDeclarationContainer.properties: Sequence<IrProperty>
val IrFunction.explicitParameters: List<IrValueParameter>
get() = (listOfNotNull(dispatchReceiverParameter, extensionReceiverParameter) + valueParameters)
val IrBody.statements: List<IrStatement>
get() = when (this) {
is IrBlockBody -> statements
is IrExpressionBody -> listOf(expression)
is IrSyntheticBody -> error("Synthetic body contains no statements $this")
else -> error("Unknown subclass of IrBody")
}
val IrClass.defaultType: IrSimpleType
get() = this.thisReceiver!!.type as IrSimpleType