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
|
type: Symbol
|
||||||
- name: multiple
|
- name: multiple
|
||||||
type: Boolean
|
type: Boolean
|
||||||
|
defaultValue: "false"
|
||||||
FunctionDefinition:
|
FunctionDefinition:
|
||||||
parent: Definition
|
parent: Definition
|
||||||
values:
|
values:
|
||||||
|
@ -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)
|
||||||
|
@ -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 {
|
||||||
|
@ -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
|
||||||
)
|
)
|
||||||
|
@ -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
|
||||||
)
|
)
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user