v: cgen fix struct ordering

pull/3944/head
Joe Conigliaro 2020-03-07 02:57:27 +11:00
parent be2480c320
commit ea2a79ec20
1 changed files with 7 additions and 12 deletions

View File

@ -652,13 +652,13 @@ fn (g mut Gen) write_sorted_types() {
// builtin types need to be on top // builtin types need to be on top
builtins := ['string', 'array', 'KeyValue', 'map', 'Option'] builtins := ['string', 'array', 'KeyValue', 'map', 'Option']
// everything except builtin will get sorted // everything except builtin will get sorted
for builtin_name in builtins {
builtin_types << g.table.types[g.table.type_idxs[builtin_name]]
}
for typ in g.table.types { for typ in g.table.types {
if typ.name in builtins { if !(typ.name in builtins) {
// || t.is_generic { types << typ
builtin_types << typ
continue
} }
types << typ
} }
// sort structs // sort structs
types_sorted := g.sort_structs(types) types_sorted := g.sort_structs(types)
@ -712,7 +712,7 @@ fn (g &Gen) sort_structs(types []table.TypeSymbol) []table.TypeSymbol {
// ft := if field.typ.starts_with('[') { field.typ.all_after(']') } else { field.typ } // ft := if field.typ.starts_with('[') { field.typ.all_after(']') } else { field.typ }
dep := g.table.get_type_symbol(field.typ).name dep := g.table.get_type_symbol(field.typ).name
// skip if not in types list or already in deps // skip if not in types list or already in deps
if !(dep in type_names) || dep in field_deps { if !(dep in type_names) || dep in field_deps || table.type_is_ptr(field.typ){
continue continue
} }
field_deps << dep field_deps << dep
@ -731,12 +731,7 @@ fn (g &Gen) sort_structs(types []table.TypeSymbol) []table.TypeSymbol {
// sort types // sort types
mut types_sorted := []table.TypeSymbol mut types_sorted := []table.TypeSymbol
for node in dep_graph_sorted.nodes { for node in dep_graph_sorted.nodes {
for t in types { types_sorted << g.table.types[g.table.type_idxs[node.name]]
if t.name == node.name {
types_sorted << t
continue
}
}
} }
return types_sorted return types_sorted
} }