diff --git a/buildext/src/main/kotlin/gay/pizza/pork/buildext/ast/AstCodegen.kt b/buildext/src/main/kotlin/gay/pizza/pork/buildext/ast/AstCodegen.kt index c82cec9..89a9dfb 100644 --- a/buildext/src/main/kotlin/gay/pizza/pork/buildext/ast/AstCodegen.kt +++ b/buildext/src/main/kotlin/gay/pizza/pork/buildext/ast/AstCodegen.kt @@ -1,3 +1,4 @@ +@file:Suppress("ConstPropertyName") package gay.pizza.pork.buildext.ast import com.fasterxml.jackson.databind.ObjectMapper @@ -85,6 +86,12 @@ class AstCodegen(val pkg: String, val outputDirectory: Path, val world: AstWorld ), isImmediateExpression = true ) + + if (enableVisitAnyInline) { + visitAnyFunction.inline = true + visitAnyFunction.annotations.add("""@Suppress("NOTHING_TO_INLINE")""") + } + visitAnyFunction.body.add("when (node) {") for (type in world.typeRegistry.types.filter { world.typeRegistry.roleOfType(it) == AstTypeRole.AstNode @@ -391,6 +398,8 @@ class AstCodegen(val pkg: String, val outputDirectory: Path, val world: AstWorld } companion object { + private const val enableVisitAnyInline = false + fun run(pkg: String, astDescriptionFile: Path, outputDirectory: Path) { if (!outputDirectory.exists()) { outputDirectory.createDirectories() diff --git a/buildext/src/main/kotlin/gay/pizza/pork/buildext/codegen/KotlinFunction.kt b/buildext/src/main/kotlin/gay/pizza/pork/buildext/codegen/KotlinFunction.kt index 27ef3fe..8069b5c 100644 --- a/buildext/src/main/kotlin/gay/pizza/pork/buildext/codegen/KotlinFunction.kt +++ b/buildext/src/main/kotlin/gay/pizza/pork/buildext/codegen/KotlinFunction.kt @@ -2,12 +2,14 @@ package gay.pizza.pork.buildext.codegen class KotlinFunction( val name: String, + var annotations: MutableList = mutableListOf(), var typeParameters: MutableList = mutableListOf(), var extensionOf: String? = null, var parameters: MutableList = mutableListOf(), var returnType: String? = null, var abstract: Boolean = false, var open: Boolean = false, + var inline: Boolean = false, var overridden: Boolean = false, var isImmediateExpression: Boolean = false, var body: MutableList = mutableListOf(), diff --git a/buildext/src/main/kotlin/gay/pizza/pork/buildext/codegen/KotlinWriter.kt b/buildext/src/main/kotlin/gay/pizza/pork/buildext/codegen/KotlinWriter.kt index 05abb08..7940dc7 100644 --- a/buildext/src/main/kotlin/gay/pizza/pork/buildext/codegen/KotlinWriter.kt +++ b/buildext/src/main/kotlin/gay/pizza/pork/buildext/codegen/KotlinWriter.kt @@ -143,6 +143,10 @@ class KotlinWriter() { } fun writeFunction(function: KotlinFunction, index: Int = 0, functionCount: Int = 1, indent: String = ""): Unit = buffer.run { + for (annotation in function.annotations) { + append(indent) + appendLine(annotation) + } append(indent) if (function.overridden) { @@ -157,6 +161,10 @@ class KotlinWriter() { append("open ") } + if (function.inline) { + append("inline ") + } + append("fun ") if (function.typeParameters.isNotEmpty()) { append("<${function.typeParameters.joinToString(", ")}> ") diff --git a/parser/src/main/kotlin/gay/pizza/pork/parser/Token.kt b/parser/src/main/kotlin/gay/pizza/pork/parser/Token.kt index 8a39a0d..a6c8683 100644 --- a/parser/src/main/kotlin/gay/pizza/pork/parser/Token.kt +++ b/parser/src/main/kotlin/gay/pizza/pork/parser/Token.kt @@ -1,7 +1,8 @@ package gay.pizza.pork.parser class Token(val type: TokenType, val start: Int, val text: String) { - override fun toString(): String = "$start ${type.name} '${text.replace("\n", "\\n")}'" + override fun toString(): String = + "$start ${type.name} '${text.replace("\n", "\\n")}'" companion object { fun endOfFile(size: Int): Token =