mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
gen: generate typedef first on sum types (#6930)
This commit is contained in:
parent
9fbf38c798
commit
789912238f
@ -4652,19 +4652,20 @@ fn (mut g Gen) write_types(types []table.TypeSymbol) {
|
|||||||
g.type_definitions.writeln('')
|
g.type_definitions.writeln('')
|
||||||
}
|
}
|
||||||
table.UnionSumType {
|
table.UnionSumType {
|
||||||
|
g.typedefs.writeln('typedef struct $name $name;')
|
||||||
g.type_definitions.writeln('')
|
g.type_definitions.writeln('')
|
||||||
g.type_definitions.writeln('// Union sum type $name = ')
|
g.type_definitions.writeln('// Union sum type $name = ')
|
||||||
for variant in it.variants {
|
for variant in it.variants {
|
||||||
g.type_definitions.writeln('// | ${variant:4d} = ${g.typ(variant.idx()):-20s}')
|
g.type_definitions.writeln('// | ${variant:4d} = ${g.typ(variant.idx()):-20s}')
|
||||||
}
|
}
|
||||||
g.type_definitions.writeln('typedef struct {')
|
g.type_definitions.writeln('struct $name {')
|
||||||
g.type_definitions.writeln(' union {')
|
g.type_definitions.writeln(' union {')
|
||||||
for variant in it.variants {
|
for variant in it.variants {
|
||||||
g.type_definitions.writeln(' ${g.typ(variant.to_ptr())} _$variant.idx();')
|
g.type_definitions.writeln(' ${g.typ(variant.to_ptr())} _$variant.idx();')
|
||||||
}
|
}
|
||||||
g.type_definitions.writeln(' };')
|
g.type_definitions.writeln(' };')
|
||||||
g.type_definitions.writeln(' int typ;')
|
g.type_definitions.writeln(' int typ;')
|
||||||
g.type_definitions.writeln('} $name;')
|
g.type_definitions.writeln('};')
|
||||||
g.type_definitions.writeln('')
|
g.type_definitions.writeln('')
|
||||||
}
|
}
|
||||||
table.ArrayFixed {
|
table.ArrayFixed {
|
||||||
|
Loading…
Reference in New Issue
Block a user