[SIR generator] Add SirVisitorVoid class

This is convenient for cases when the visitor has no context to pass to
each method
This commit is contained in:
Sergej Jaskiewicz
2023-12-11 18:14:07 +01:00
committed by Space Team
parent 80c9eae409
commit 80847b9ee2
9 changed files with 166 additions and 14 deletions
@@ -60,8 +60,8 @@ abstract class AbstractVisitorVoidPrinter<Element, Field>(
element,
hasDataParameter = false,
modality = when {
element.isRootElement && visitorType.kind == TypeKind.Class -> Modality.ABSTRACT
!element.isRootElement && visitorType.kind == TypeKind.Class -> Modality.OPEN
isAbstractVisitRootElementMethod && visitorType.kind == TypeKind.Class -> Modality.ABSTRACT
!isAbstractVisitRootElementMethod && visitorType.kind == TypeKind.Class -> Modality.OPEN
else -> null
}
)
@@ -348,4 +348,18 @@ fun SmartPrinter.printTransformChildrenMethod(
)
}
context(ImportCollector)
fun SmartPrinter.printAcceptVoidMethod(visitorType: ClassRef<*>) {
val visitorParameter = FunctionParameter("visitor", visitorType)
printFunctionDeclaration("accept", listOf(visitorParameter), StandardTypes.unit)
println(" = accept(", visitorParameter.name, ", null)")
}
context(ImportCollector)
fun SmartPrinter.printAcceptChildrenVoidMethod(visitorType: ClassRef<*>) {
val visitorParameter = FunctionParameter("visitor", visitorType)
printFunctionDeclaration("acceptChildren", listOf(visitorParameter), StandardTypes.unit)
println(" = acceptChildren(", visitorParameter.name, ", null)")
}
fun AbstractField<*>.call(): String = if (nullable) "?." else "."