mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 05:10:55 +00:00
ast: default value support in generation
This commit is contained in:
parent
033da5b2ea
commit
7b4257d719
@ -123,6 +123,7 @@ types:
|
||||
type: Symbol
|
||||
- name: multiple
|
||||
type: Boolean
|
||||
defaultValue: "false"
|
||||
FunctionDefinition:
|
||||
parent: Definition
|
||||
values:
|
||||
|
@ -6,4 +6,4 @@ import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@SerialName("argumentSpec")
|
||||
class ArgumentSpec(var symbol: Symbol, var multiple: Boolean)
|
||||
class ArgumentSpec(var symbol: Symbol, var multiple: Boolean = false)
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user