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.transformChildrenVoid
fun makeLateinitPhase(generateParameterNameInAssertion: Boolean) = object : CompilerPhase<CommonBackendContext, IrFile> {
fun makeLateinitPhase() = object : CompilerPhase<CommonBackendContext, IrFile> {
override val name = "Lateinit"
override val description = "Insert checks for lateinit field references"
override fun invoke(context: CommonBackendContext, input: IrFile): IrFile {
LateinitLowering(context, generateParameterNameInAssertion).lower(input)
LateinitLowering(context).lower(input)
return input
}
}
class LateinitLowering(
val context: CommonBackendContext,
private val generateParameterNameInAssertion: Boolean = false
) : FileLoweringPass {
class LateinitLowering(val context: CommonBackendContext) : FileLoweringPass {
override fun lower(irFile: IrFile) {
irFile.transformChildrenVoid(object : IrElementTransformerVoid() {
override fun visitProperty(declaration: IrProperty): IrStatement {
@@ -128,17 +125,15 @@ class LateinitLowering(
private fun IrBuilderWithScope.throwUninitializedPropertyAccessException(name: String) =
irCall(throwErrorFunction).apply {
if (generateParameterNameInAssertion) {
putValueArgument(
0,
IrConstImpl.string(
UNDEFINED_OFFSET,
UNDEFINED_OFFSET,
context.irBuiltIns.stringType,
name
)
putValueArgument(
0,
IrConstImpl.string(
UNDEFINED_OFFSET,
UNDEFINED_OFFSET,
context.irBuiltIns.stringType,
name
)
}
)
}
private val throwErrorFunction = context.ir.symbols.ThrowUninitializedPropertyAccessException.owner
@@ -67,7 +67,7 @@ private val ArrayInlineConstructorLoweringPhase = makeJsPhase(
)
private val LateinitLoweringPhase = makeJsPhase(
{ context, module -> LateinitLowering(context, true).lower(module) },
{ context, module -> LateinitLowering(context).lower(module) },
name = "LateinitLowering",
description = "Insert checks for lateinit field references"
)
@@ -49,7 +49,7 @@ private val KCallableNamePropertyPhase = makeJvmPhase(
)
private val LateinitPhase = makeJvmPhase(
{ context, file -> LateinitLowering(context, true).lower(file) },
{ context, file -> LateinitLowering(context).lower(file) },
name = "Lateinit",
description = "Insert checks for lateinit field references"
)