ast: default value support in generation

This commit is contained in:
Alex Zenla 2023-09-10 20:54:48 -04:00
parent 033da5b2ea
commit 7b4257d719
Signed by: alex
GPG Key ID: C0780728420EBFE5
6 changed files with 18 additions and 5 deletions

View File

@ -123,6 +123,7 @@ types:
type: Symbol type: Symbol
- name: multiple - name: multiple
type: Boolean type: Boolean
defaultValue: "false"
FunctionDefinition: FunctionDefinition:
parent: Definition parent: Definition
values: values:

View File

@ -6,4 +6,4 @@ import kotlinx.serialization.Serializable
@Serializable @Serializable
@SerialName("argumentSpec") @SerialName("argumentSpec")
class ArgumentSpec(var symbol: Symbol, var multiple: Boolean) class ArgumentSpec(var symbol: Symbol, var multiple: Boolean = false)

View File

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

View File

@ -3,5 +3,6 @@ package gay.pizza.pork.buildext.ast
class AstValue( class AstValue(
val name: String, val name: String,
val typeRef: AstTypeRef, 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( data class AstValueDescription(
val name: String, val name: String,
val type: 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() type.markHasValues()
for (value in typeDescription.values) { for (value in typeDescription.values) {
val typeRef = AstTypeRef.parse(value.type, world.typeRegistry) 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) type.addValue(typeValue)
} }
} }