[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.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
@@ -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,
@@ -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 <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()
fun canAccessDeclarationsOf(irClass: IrClass): Boolean = true
open fun canAccessDeclarationsOf(irClass: IrClass): Boolean = true
}
@Suppress("NOTHING_TO_INLINE")