Made LateInitLowering the same in K/N as in other BEs

This commit is contained in:
Igor Chevdar
2019-01-28 13:33:58 +03:00
parent db487a622a
commit c765bd74d7
3 changed files with 13 additions and 18 deletions
@@ -34,20 +34,17 @@ import org.jetbrains.kotlin.ir.util.resolveFakeOverride
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
fun makeLateinitPhase(generateParameterNameInAssertion: Boolean) = object : CompilerPhase<CommonBackendContext, IrFile> { fun makeLateinitPhase() = object : CompilerPhase<CommonBackendContext, IrFile> {
override val name = "Lateinit" override val name = "Lateinit"
override val description = "Insert checks for lateinit field references" override val description = "Insert checks for lateinit field references"
override fun invoke(context: CommonBackendContext, input: IrFile): IrFile { override fun invoke(context: CommonBackendContext, input: IrFile): IrFile {
LateinitLowering(context, generateParameterNameInAssertion).lower(input) LateinitLowering(context).lower(input)
return input return input
} }
} }
class LateinitLowering( class LateinitLowering(val context: CommonBackendContext) : FileLoweringPass {
val context: CommonBackendContext,
private val generateParameterNameInAssertion: Boolean = false
) : FileLoweringPass {
override fun lower(irFile: IrFile) { override fun lower(irFile: IrFile) {
irFile.transformChildrenVoid(object : IrElementTransformerVoid() { irFile.transformChildrenVoid(object : IrElementTransformerVoid() {
override fun visitProperty(declaration: IrProperty): IrStatement { override fun visitProperty(declaration: IrProperty): IrStatement {
@@ -128,17 +125,15 @@ class LateinitLowering(
private fun IrBuilderWithScope.throwUninitializedPropertyAccessException(name: String) = private fun IrBuilderWithScope.throwUninitializedPropertyAccessException(name: String) =
irCall(throwErrorFunction).apply { irCall(throwErrorFunction).apply {
if (generateParameterNameInAssertion) { putValueArgument(
putValueArgument( 0,
0, IrConstImpl.string(
IrConstImpl.string( UNDEFINED_OFFSET,
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
UNDEFINED_OFFSET, context.irBuiltIns.stringType,
context.irBuiltIns.stringType, name
name
)
) )
} )
} }
private val throwErrorFunction = context.ir.symbols.ThrowUninitializedPropertyAccessException.owner private val throwErrorFunction = context.ir.symbols.ThrowUninitializedPropertyAccessException.owner
@@ -67,7 +67,7 @@ private val ArrayInlineConstructorLoweringPhase = makeJsPhase(
) )
private val LateinitLoweringPhase = makeJsPhase( private val LateinitLoweringPhase = makeJsPhase(
{ context, module -> LateinitLowering(context, true).lower(module) }, { context, module -> LateinitLowering(context).lower(module) },
name = "LateinitLowering", name = "LateinitLowering",
description = "Insert checks for lateinit field references" description = "Insert checks for lateinit field references"
) )
@@ -49,7 +49,7 @@ private val KCallableNamePropertyPhase = makeJvmPhase(
) )
private val LateinitPhase = makeJvmPhase( private val LateinitPhase = makeJvmPhase(
{ context, file -> LateinitLowering(context, true).lower(file) }, { context, file -> LateinitLowering(context).lower(file) },
name = "Lateinit", name = "Lateinit",
description = "Insert checks for lateinit field references" description = "Insert checks for lateinit field references"
) )