IR: minor, give names to anonymous lowering visitors
To improve stacktraces and make the code a bit more readable.
This commit is contained in:
@@ -76,29 +76,37 @@ fun FileLoweringPass.lower(moduleFragment: IrModuleFragment) = moduleFragment.fi
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
fun ClassLoweringPass.runOnFilePostfix(irFile: IrFile) {
|
fun ClassLoweringPass.runOnFilePostfix(irFile: IrFile) {
|
||||||
irFile.acceptVoid(object : IrElementVisitorVoid {
|
irFile.acceptVoid(ClassLoweringVisitor(this))
|
||||||
override fun visitElement(element: IrElement) {
|
}
|
||||||
element.acceptChildrenVoid(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitClass(declaration: IrClass) {
|
private class ClassLoweringVisitor(
|
||||||
declaration.acceptChildrenVoid(this)
|
private val loweringPass: ClassLoweringPass
|
||||||
lower(declaration)
|
) : IrElementVisitorVoid {
|
||||||
}
|
override fun visitElement(element: IrElement) {
|
||||||
})
|
element.acceptChildrenVoid(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitClass(declaration: IrClass) {
|
||||||
|
declaration.acceptChildrenVoid(this)
|
||||||
|
loweringPass.lower(declaration)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ScriptLoweringPass.runOnFilePostfix(irFile: IrFile) {
|
fun ScriptLoweringPass.runOnFilePostfix(irFile: IrFile) {
|
||||||
irFile.acceptVoid(object : IrElementVisitorVoid {
|
irFile.acceptVoid(ScriptLoweringVisitor(this))
|
||||||
override fun visitElement(element: IrElement) {
|
}
|
||||||
element.acceptChildrenVoid(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitScript(declaration: IrScript) {
|
private class ScriptLoweringVisitor(
|
||||||
declaration.acceptChildrenVoid(this)
|
private val loweringPass: ScriptLoweringPass
|
||||||
lower(declaration)
|
) : IrElementVisitorVoid {
|
||||||
}
|
override fun visitElement(element: IrElement) {
|
||||||
})
|
element.acceptChildrenVoid(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitScript(declaration: IrScript) {
|
||||||
|
declaration.acceptChildrenVoid(this)
|
||||||
|
loweringPass.lower(declaration)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun DeclarationContainerLoweringPass.asClassLoweringPass() = object : ClassLoweringPass {
|
fun DeclarationContainerLoweringPass.asClassLoweringPass() = object : ClassLoweringPass {
|
||||||
@@ -125,42 +133,48 @@ fun BodyLoweringPass.runOnFilePostfix(
|
|||||||
withLocalDeclarations: Boolean = false,
|
withLocalDeclarations: Boolean = false,
|
||||||
allowDeclarationModification: Boolean = false
|
allowDeclarationModification: Boolean = false
|
||||||
) {
|
) {
|
||||||
ArrayList(irFile.declarations).forEach {
|
val visitor = BodyLoweringVisitor(this, withLocalDeclarations, allowDeclarationModification)
|
||||||
it.accept(object : IrElementVisitor<Unit, IrDeclaration?> {
|
for (declaration in ArrayList(irFile.declarations)) {
|
||||||
override fun visitElement(element: IrElement, data: IrDeclaration?) {
|
declaration.accept(visitor, null)
|
||||||
element.acceptChildren(this, data)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitDeclaration(declaration: IrDeclarationBase, data: IrDeclaration?) {
|
private class BodyLoweringVisitor(
|
||||||
declaration.acceptChildren(this, declaration)
|
private val loweringPass: BodyLoweringPass,
|
||||||
}
|
private val withLocalDeclarations: Boolean,
|
||||||
|
private val allowDeclarationModification: Boolean,
|
||||||
|
) : IrElementVisitor<Unit, IrDeclaration?> {
|
||||||
|
override fun visitElement(element: IrElement, data: IrDeclaration?) {
|
||||||
|
element.acceptChildren(this, data)
|
||||||
|
}
|
||||||
|
|
||||||
override fun visitClass(declaration: IrClass, data: IrDeclaration?) {
|
override fun visitDeclaration(declaration: IrDeclarationBase, data: IrDeclaration?) {
|
||||||
declaration.thisReceiver?.accept(this, declaration)
|
declaration.acceptChildren(this, declaration)
|
||||||
declaration.typeParameters.forEach { it.accept(this, declaration) }
|
}
|
||||||
ArrayList(declaration.declarations).forEach { it.accept(this, declaration) }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitBody(body: IrBody, data: IrDeclaration?) {
|
override fun visitClass(declaration: IrClass, data: IrDeclaration?) {
|
||||||
if (withLocalDeclarations) body.acceptChildren(this, null)
|
declaration.thisReceiver?.accept(this, declaration)
|
||||||
if (allowDeclarationModification) {
|
declaration.typeParameters.forEach { it.accept(this, declaration) }
|
||||||
lower(body, data!!)
|
ArrayList(declaration.declarations).forEach { it.accept(this, declaration) }
|
||||||
} else {
|
}
|
||||||
stageController.bodyLowering {
|
|
||||||
lower(body, data!!)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitScript(declaration: IrScript, data: IrDeclaration?) {
|
override fun visitBody(body: IrBody, data: IrDeclaration?) {
|
||||||
ArrayList(declaration.declarations).forEach { it.accept(this, declaration) }
|
if (withLocalDeclarations) body.acceptChildren(this, null)
|
||||||
if (withLocalDeclarations) {
|
if (allowDeclarationModification) {
|
||||||
declaration.statements.forEach { it.accept(this, null) }
|
loweringPass.lower(body, data!!)
|
||||||
}
|
} else {
|
||||||
declaration.thisReceiver.accept(this, declaration)
|
stageController.bodyLowering {
|
||||||
|
loweringPass.lower(body, data!!)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}, null)
|
override fun visitScript(declaration: IrScript, data: IrDeclaration?) {
|
||||||
|
ArrayList(declaration.declarations).forEach { it.accept(this, declaration) }
|
||||||
|
if (withLocalDeclarations) {
|
||||||
|
declaration.statements.forEach { it.accept(this, null) }
|
||||||
|
}
|
||||||
|
declaration.thisReceiver.accept(this, declaration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user