ast: default value support in generation

This commit is contained in:
2023-09-10 20:54:48 -04:00
parent 033da5b2ea
commit 7b4257d719
6 changed files with 18 additions and 5 deletions

View File

@ -241,6 +241,9 @@ class AstCodegen(val pkg: String, val outputDirectory: Path, val world: AstWorld
for (value in type.values!!) {
val member = KotlinMember(value.name, toKotlinType(value.typeRef))
member.abstract = value.abstract
if (value.defaultValue != null) {
member.value = value.defaultValue
}
if (type.isParentAbstract(value)) {
member.overridden = true
}
@ -279,7 +282,9 @@ class AstCodegen(val pkg: String, val outputDirectory: Path, val world: AstWorld
),
isImmediateExpression = true
)
val anyListMembers = type.values?.any { it.typeRef.form == AstTypeRefForm.List } ?: false
val anyListMembers = type.values?.any {
it.typeRef.form == AstTypeRefForm.List
} ?: false
val elideVisitChildren: Boolean
if (anyListMembers) {
val visitParameters = (type.values?.mapNotNull {

View File

@ -3,5 +3,6 @@ package gay.pizza.pork.buildext.ast
class AstValue(
val name: String,
val typeRef: AstTypeRef,
val abstract: Boolean = false
val abstract: Boolean = false,
val defaultValue: String? = null
)

View File

@ -3,5 +3,6 @@ package gay.pizza.pork.buildext.ast
data class AstValueDescription(
val name: String,
val type: String,
val required: Boolean = false
val required: Boolean = false,
val defaultValue: String? = null
)

View File

@ -59,7 +59,12 @@ class AstWorld {
type.markHasValues()
for (value in typeDescription.values) {
val typeRef = AstTypeRef.parse(value.type, world.typeRegistry)
val typeValue = AstValue(value.name, typeRef, abstract = value.required)
val typeValue = AstValue(
value.name,
typeRef,
abstract = value.required,
defaultValue = value.defaultValue
)
type.addValue(typeValue)
}
}