Extract IrBody.statements utility function
This commit is contained in:
committed by
max-kammerer
parent
509d257475
commit
917435a50c
+4
-18
@@ -140,7 +140,7 @@ private class JvmInlineClassLowering(private val context: JvmBackendContext) : F
|
|||||||
)
|
)
|
||||||
valueMap[constructor.constructedClass.thisReceiver!!.symbol] = thisVar
|
valueMap[constructor.constructedClass.thisReceiver!!.symbol] = thisVar
|
||||||
|
|
||||||
constructor.body?.contents?.forEach { statement ->
|
constructor.body?.statements?.forEach { statement ->
|
||||||
+statement
|
+statement
|
||||||
.transform(object : IrElementTransformerVoid() {
|
.transform(object : IrElementTransformerVoid() {
|
||||||
// Don't recurse under nested class declarations
|
// 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 {
|
override fun visitFunctionReference(expression: IrFunctionReference): IrExpression {
|
||||||
val replacement = manager.getReplacementFunction(expression.symbol.owner)
|
val replacement = manager.getReplacementFunction(expression.symbol.owner)
|
||||||
?: return super.visitFunctionReference(expression)
|
?: return super.visitFunctionReference(expression)
|
||||||
@@ -240,7 +232,9 @@ private class JvmInlineClassLowering(private val context: JvmBackendContext) : F
|
|||||||
val function = expression.symbol.owner
|
val function = expression.symbol.owner
|
||||||
val replacement = manager.getReplacementFunction(function)
|
val replacement = manager.getReplacementFunction(function)
|
||||||
?: return super.visitFunctionAccess(expression)
|
?: 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) =
|
private fun coerceInlineClasses(argument: IrExpression, from: IrType, to: IrType) =
|
||||||
@@ -377,11 +371,3 @@ private class JvmInlineClassLowering(private val context: JvmBackendContext) : F
|
|||||||
irClass.declarations += function
|
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.descriptors.*
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||||
@@ -198,6 +199,14 @@ val IrDeclarationContainer.properties: Sequence<IrProperty>
|
|||||||
val IrFunction.explicitParameters: List<IrValueParameter>
|
val IrFunction.explicitParameters: List<IrValueParameter>
|
||||||
get() = (listOfNotNull(dispatchReceiverParameter, extensionReceiverParameter) + valueParameters)
|
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
|
val IrClass.defaultType: IrSimpleType
|
||||||
get() = this.thisReceiver!!.type as IrSimpleType
|
get() = this.thisReceiver!!.type as IrSimpleType
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user