[IR] minor: make StageController an open class

This should make creating a new "do nothing" controller more straightforward.
This commit is contained in:
Anton Bannykh
2020-03-05 20:58:27 +03:00
committed by Anton Bannykh
parent abc6ecaa1c
commit 939f0d0344
3 changed files with 15 additions and 19 deletions
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrDeclarationBase
import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.util.isLocal import org.jetbrains.kotlin.ir.util.isLocal
open class MutableController(val context: JsIrBackendContext, val lowerings: List<Lowering>) : StageController { open class MutableController(val context: JsIrBackendContext, val lowerings: List<Lowering>) : StageController() {
override var currentStage: Int = 0 override var currentStage: Int = 0
@@ -49,7 +49,7 @@ fun compile(
multiModule: Boolean = false, multiModule: Boolean = false,
relativeRequirePath: Boolean = false relativeRequirePath: Boolean = false
): CompilerResult { ): CompilerResult {
stageController = object : StageController {} stageController = StageController()
val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer) = val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer) =
loadIr(project, mainModule, analyzer, configuration, allDependencies, friendDependencies) loadIr(project, mainModule, analyzer, configuration, allDependencies, friendDependencies)
@@ -86,9 +86,7 @@ fun compile(
eliminateDeadDeclarations(allModules, context) eliminateDeadDeclarations(allModules, context)
// TODO investigate whether this is needed anymore // TODO investigate whether this is needed anymore
stageController = object : StageController { stageController = StageController(controller.currentStage)
override val currentStage: Int = controller.currentStage
}
val transformer = IrModuleToJsTransformer( val transformer = IrModuleToJsTransformer(
context, context,
@@ -10,31 +10,29 @@ import org.jetbrains.kotlin.ir.expressions.IrBody
// TODO threadlocal // TODO threadlocal
// TODO make a IrDeclarationBase field? (requires IR factory) // TODO make a IrDeclarationBase field? (requires IR factory)
var stageController: StageController = object : StageController {} var stageController: StageController = StageController()
// TODO make a class // TODO make a class
interface StageController { open class StageController(open val currentStage: Int = 0) {
val currentStage: Int get() = 0 open fun lazyLower(declaration: IrDeclaration) {}
fun lazyLower(declaration: IrDeclaration) {} open fun lazyLower(body: IrBody) {}
fun lazyLower(body: IrBody) {} open fun <T> withStage(stage: Int, fn: () -> T): T = fn()
fun <T> withStage(stage: Int, fn: () -> T): T = fn() open val bodiesEnabled: Boolean get() = true
val bodiesEnabled: Boolean get() = true open fun <T> withInitialIr(block: () -> T): T = block()
fun <T> withInitialIr(block: () -> T): T = block() open fun <T> restrictTo(declaration: IrDeclaration, fn: () -> T): T = fn()
fun <T> restrictTo(declaration: IrDeclaration, fn: () -> T): T = fn() open fun <T> bodyLowering(fn: () -> T): T = fn()
fun <T> bodyLowering(fn: () -> T): T = fn() open fun canModify(element: IrElement): Boolean = true
fun canModify(element: IrElement): Boolean = true open fun <T> unrestrictDeclarationListsAccess(fn: () -> T): T = fn()
fun <T> unrestrictDeclarationListsAccess(fn: () -> T): T = fn() open fun canAccessDeclarationsOf(irClass: IrClass): Boolean = true
fun canAccessDeclarationsOf(irClass: IrClass): Boolean = true
} }
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")