1
0
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:
Daniel Däschle 2020-11-24 12:53:39 +01:00 committed by GitHub
parent 9fbf38c798
commit 789912238f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {