[SIR] Add SirTransformerVoid class
This is convenient for cases when the transformer has no context to pass to each method
This commit is contained in:
committed by
Space Team
parent
1bc2ac2c87
commit
1bed6a063f
@@ -9,6 +9,7 @@
|
||||
package org.jetbrains.kotlin.sir
|
||||
|
||||
import org.jetbrains.kotlin.sir.visitors.SirTransformer
|
||||
import org.jetbrains.kotlin.sir.visitors.SirTransformerVoid
|
||||
import org.jetbrains.kotlin.sir.visitors.SirVisitor
|
||||
import org.jetbrains.kotlin.sir.visitors.SirVisitorVoid
|
||||
|
||||
@@ -54,6 +55,15 @@ sealed interface SirElement {
|
||||
|
||||
fun acceptChildren(visitor: SirVisitorVoid) = acceptChildren(visitor, null)
|
||||
|
||||
/**
|
||||
* Runs the provided [transformer] on the Swift IR subtree with the root at this node.
|
||||
*
|
||||
* @param transformer The transformer to use.
|
||||
* @return The transformed node.
|
||||
*/
|
||||
fun <E : SirElement> transform(transformer: SirTransformerVoid): E =
|
||||
transform(transformer, null)
|
||||
|
||||
/**
|
||||
* Recursively transforms this node's children *in place* using [transformer].
|
||||
*
|
||||
@@ -65,4 +75,16 @@ sealed interface SirElement {
|
||||
* @param data An arbitrary context to pass to each invocation of [transformer]'s methods.
|
||||
*/
|
||||
fun <D> transformChildren(transformer: SirTransformer<D>, data: D)
|
||||
|
||||
/**
|
||||
* Recursively transforms this node's children *in place* using [transformer].
|
||||
*
|
||||
* Basically, executes `this.child = this.child.transform(transformer)` for each child of this node.
|
||||
*
|
||||
* Does **not** run [transformer] on this node itself.
|
||||
*
|
||||
* @param transformer The transformer to use for transforming the children.
|
||||
*/
|
||||
fun transformChildren(transformer: SirTransformerVoid) =
|
||||
transformChildren(transformer, null)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
// This file was generated automatically. See native/swift/sir/tree-generator/Readme.md.
|
||||
// DO NOT MODIFY IT MANUALLY.
|
||||
|
||||
package org.jetbrains.kotlin.sir.visitors
|
||||
|
||||
import org.jetbrains.kotlin.sir.*
|
||||
|
||||
/**
|
||||
* Auto-generated by [org.jetbrains.kotlin.sir.tree.generator.printer.TransformerVoidPrinter]
|
||||
*/
|
||||
abstract class SirTransformerVoid : SirTransformer<Nothing?>() {
|
||||
|
||||
abstract fun <E : SirElement> transformElement(element: E): E
|
||||
|
||||
final override fun <E : SirElement> transformElement(element: E, data: Nothing?): E =
|
||||
transformElement(element)
|
||||
|
||||
open fun transformModule(module: SirModule): SirModule =
|
||||
transformElement(module)
|
||||
|
||||
final override fun transformModule(module: SirModule, data: Nothing?): SirModule =
|
||||
transformModule(module)
|
||||
|
||||
open fun transformDeclarationContainer(declarationContainer: SirDeclarationContainer): SirDeclarationContainer =
|
||||
transformElement(declarationContainer)
|
||||
|
||||
final override fun transformDeclarationContainer(declarationContainer: SirDeclarationContainer, data: Nothing?): SirDeclarationContainer =
|
||||
transformDeclarationContainer(declarationContainer)
|
||||
|
||||
open fun transformDeclaration(declaration: SirDeclaration): SirDeclaration =
|
||||
transformElement(declaration)
|
||||
|
||||
final override fun transformDeclaration(declaration: SirDeclaration, data: Nothing?): SirDeclaration =
|
||||
transformDeclaration(declaration)
|
||||
|
||||
open fun transformForeignDeclaration(foreignDeclaration: SirForeignDeclaration): SirDeclaration =
|
||||
transformDeclaration(foreignDeclaration)
|
||||
|
||||
final override fun transformForeignDeclaration(foreignDeclaration: SirForeignDeclaration, data: Nothing?): SirDeclaration =
|
||||
transformForeignDeclaration(foreignDeclaration)
|
||||
|
||||
open fun transformNamedDeclaration(namedDeclaration: SirNamedDeclaration): SirDeclaration =
|
||||
transformDeclaration(namedDeclaration)
|
||||
|
||||
final override fun transformNamedDeclaration(namedDeclaration: SirNamedDeclaration, data: Nothing?): SirDeclaration =
|
||||
transformNamedDeclaration(namedDeclaration)
|
||||
|
||||
open fun transformEnum(enum: SirEnum): SirDeclaration =
|
||||
transformNamedDeclaration(enum)
|
||||
|
||||
final override fun transformEnum(enum: SirEnum, data: Nothing?): SirDeclaration =
|
||||
transformEnum(enum)
|
||||
|
||||
open fun transformStruct(struct: SirStruct): SirDeclaration =
|
||||
transformNamedDeclaration(struct)
|
||||
|
||||
final override fun transformStruct(struct: SirStruct, data: Nothing?): SirDeclaration =
|
||||
transformStruct(struct)
|
||||
|
||||
open fun transformCallable(callable: SirCallable): SirDeclaration =
|
||||
transformDeclaration(callable)
|
||||
|
||||
final override fun transformCallable(callable: SirCallable, data: Nothing?): SirDeclaration =
|
||||
transformCallable(callable)
|
||||
|
||||
open fun transformFunction(function: SirFunction): SirDeclaration =
|
||||
transformCallable(function)
|
||||
|
||||
final override fun transformFunction(function: SirFunction, data: Nothing?): SirDeclaration =
|
||||
transformFunction(function)
|
||||
|
||||
open fun transformForeignFunction(foreignFunction: SirForeignFunction): SirDeclaration =
|
||||
transformCallable(foreignFunction)
|
||||
|
||||
final override fun transformForeignFunction(foreignFunction: SirForeignFunction, data: Nothing?): SirDeclaration =
|
||||
transformForeignFunction(foreignFunction)
|
||||
}
|
||||
@@ -29,6 +29,7 @@ fun main(args: Array<String>) {
|
||||
elementVisitorType to ::VisitorPrinter,
|
||||
elementVisitorVoidType to ::VisitorVoidPrinter,
|
||||
elementTransformerType to ::TransformerPrinter.bind(model.rootElement),
|
||||
elementTransformerVoidType to ::TransformerVoidPrinter,
|
||||
),
|
||||
ImplementationConfigurator,
|
||||
BuilderConfigurator(model.elements),
|
||||
|
||||
@@ -20,6 +20,7 @@ private const val VISITORS_PACKAGE = "$BASE_PACKAGE.visitors"
|
||||
val elementVisitorType = type(VISITORS_PACKAGE, "SirVisitor", TypeKind.Class)
|
||||
val elementVisitorVoidType = type(VISITORS_PACKAGE, "SirVisitorVoid", TypeKind.Class)
|
||||
val elementTransformerType = type(VISITORS_PACKAGE, "SirTransformer", TypeKind.Class)
|
||||
val elementTransformerVoidType = type(VISITORS_PACKAGE, "SirTransformerVoid", TypeKind.Class)
|
||||
|
||||
val swiftIrImplementationDetailAnnotation = type(BASE_PACKAGE, "SirImplementationDetail", TypeKind.Class)
|
||||
val swiftIrBuilderDslAnnotation = type(BASE_PACKAGE, "SirBuilderDsl", TypeKind.Class)
|
||||
|
||||
+5
-4
@@ -7,10 +7,7 @@ package org.jetbrains.kotlin.sir.tree.generator.printer
|
||||
|
||||
import org.jetbrains.kotlin.generators.tree.*
|
||||
import org.jetbrains.kotlin.generators.tree.printer.*
|
||||
import org.jetbrains.kotlin.sir.tree.generator.SwiftIrTree
|
||||
import org.jetbrains.kotlin.sir.tree.generator.elementTransformerType
|
||||
import org.jetbrains.kotlin.sir.tree.generator.elementVisitorType
|
||||
import org.jetbrains.kotlin.sir.tree.generator.elementVisitorVoidType
|
||||
import org.jetbrains.kotlin.sir.tree.generator.*
|
||||
import org.jetbrains.kotlin.sir.tree.generator.model.Element
|
||||
import org.jetbrains.kotlin.sir.tree.generator.model.Field
|
||||
import org.jetbrains.kotlin.utils.SmartPrinter
|
||||
@@ -42,8 +39,12 @@ internal class ElementPrinter(printer: SmartPrinter) : AbstractElementPrinter<El
|
||||
println()
|
||||
println()
|
||||
printAcceptChildrenVoidMethod(elementVisitorVoidType)
|
||||
println()
|
||||
printTransformVoidMethod(element, elementTransformerVoidType, treeName)
|
||||
printTransformChildrenMethod(element, elementTransformerType, StandardTypes.unit)
|
||||
println()
|
||||
println()
|
||||
printTransformChildrenVoidMethod(element, elementTransformerVoidType, StandardTypes.unit)
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.sir.tree.generator.printer
|
||||
|
||||
import org.jetbrains.kotlin.generators.tree.AbstractTransformerVoidPrinter
|
||||
import org.jetbrains.kotlin.generators.tree.ClassRef
|
||||
import org.jetbrains.kotlin.generators.tree.PositionTypeParameterRef
|
||||
import org.jetbrains.kotlin.sir.tree.generator.elementTransformerType
|
||||
import org.jetbrains.kotlin.sir.tree.generator.model.Element
|
||||
import org.jetbrains.kotlin.sir.tree.generator.model.Field
|
||||
import org.jetbrains.kotlin.utils.SmartPrinter
|
||||
|
||||
internal class TransformerVoidPrinter(
|
||||
printer: SmartPrinter,
|
||||
override val visitorType: ClassRef<*>,
|
||||
) : AbstractTransformerVoidPrinter<Element, Field>(printer) {
|
||||
|
||||
override val transformerSuperClass: ClassRef<PositionTypeParameterRef>
|
||||
get() = elementTransformerType
|
||||
}
|
||||
Reference in New Issue
Block a user