From 939f0d0344820b1eb6bdaf5f4fde0eba741bbb19 Mon Sep 17 00:00:00 2001 From: Anton Bannykh Date: Thu, 5 Mar 2020 20:58:27 +0300 Subject: [PATCH] [IR] minor: make StageController an open class This should make creating a new "do nothing" controller more straightforward. --- .../kotlin/ir/backend/js/MutableController.kt | 2 +- .../kotlin/ir/backend/js/compiler.kt | 6 ++--- .../kotlin/ir/declarations/PersistentApi.kt | 26 +++++++++---------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/MutableController.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/MutableController.kt index 2c12539d482..da4e7b949ff 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/MutableController.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/MutableController.kt @@ -13,7 +13,7 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrDeclarationBase import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.util.isLocal -open class MutableController(val context: JsIrBackendContext, val lowerings: List) : StageController { +open class MutableController(val context: JsIrBackendContext, val lowerings: List) : StageController() { override var currentStage: Int = 0 diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt index eab379d30f6..1cf59ccaefe 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt @@ -49,7 +49,7 @@ fun compile( multiModule: Boolean = false, relativeRequirePath: Boolean = false ): CompilerResult { - stageController = object : StageController {} + stageController = StageController() val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer) = loadIr(project, mainModule, analyzer, configuration, allDependencies, friendDependencies) @@ -86,9 +86,7 @@ fun compile( eliminateDeadDeclarations(allModules, context) // TODO investigate whether this is needed anymore - stageController = object : StageController { - override val currentStage: Int = controller.currentStage - } + stageController = StageController(controller.currentStage) val transformer = IrModuleToJsTransformer( context, diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/PersistentApi.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/PersistentApi.kt index a23964c9615..2bf93168907 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/PersistentApi.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/PersistentApi.kt @@ -10,31 +10,29 @@ import org.jetbrains.kotlin.ir.expressions.IrBody // TODO threadlocal // TODO make a IrDeclarationBase field? (requires IR factory) -var stageController: StageController = object : StageController {} +var stageController: StageController = StageController() // TODO make a class -interface StageController { - val currentStage: Int get() = 0 +open class StageController(open val currentStage: Int = 0) { + open fun lazyLower(declaration: IrDeclaration) {} - fun lazyLower(declaration: IrDeclaration) {} + open fun lazyLower(body: IrBody) {} - fun lazyLower(body: IrBody) {} + open fun withStage(stage: Int, fn: () -> T): T = fn() - fun withStage(stage: Int, fn: () -> T): T = fn() + open val bodiesEnabled: Boolean get() = true - val bodiesEnabled: Boolean get() = true + open fun withInitialIr(block: () -> T): T = block() - fun withInitialIr(block: () -> T): T = block() + open fun restrictTo(declaration: IrDeclaration, fn: () -> T): T = fn() - fun restrictTo(declaration: IrDeclaration, fn: () -> T): T = fn() + open fun bodyLowering(fn: () -> T): T = fn() - fun bodyLowering(fn: () -> T): T = fn() + open fun canModify(element: IrElement): Boolean = true - fun canModify(element: IrElement): Boolean = true + open fun unrestrictDeclarationListsAccess(fn: () -> T): T = fn() - fun unrestrictDeclarationListsAccess(fn: () -> T): T = fn() - - fun canAccessDeclarationsOf(irClass: IrClass): Boolean = true + open fun canAccessDeclarationsOf(irClass: IrClass): Boolean = true } @Suppress("NOTHING_TO_INLINE")