table, vfmt: fix typ_to_string + some fixes to vfmt
parent
ebdfe9a9c5
commit
d94d436273
|
@ -448,7 +448,8 @@ fn (mut f Fmt) struct_decl(node ast.StructDecl) {
|
||||||
f.write(strings.repeat(` `, max - field.name.len))
|
f.write(strings.repeat(` `, max - field.name.len))
|
||||||
f.write(f.type_to_str(field.typ))
|
f.write(f.type_to_str(field.typ))
|
||||||
if field.has_default_expr {
|
if field.has_default_expr {
|
||||||
f.write(' = ${field.default_expr.str()}')
|
f.write(' = ')
|
||||||
|
f.expr(field.default_expr)
|
||||||
}
|
}
|
||||||
// f.write('// $field.pos.line_nr')
|
// f.write('// $field.pos.line_nr')
|
||||||
if field.comment.text != '' && field.comment.pos.line_nr == field.pos.line_nr {
|
if field.comment.text != '' && field.comment.pos.line_nr == field.pos.line_nr {
|
||||||
|
@ -1053,7 +1054,7 @@ fn (mut f Fmt) struct_init(it ast.StructInit) {
|
||||||
if it.fields.len == 0 {
|
if it.fields.len == 0 {
|
||||||
// `Foo{}` on one line if there are no fields
|
// `Foo{}` on one line if there are no fields
|
||||||
f.write('$name{}')
|
f.write('$name{}')
|
||||||
} else if it.fields.len == 0 {
|
} else if it.is_short {
|
||||||
// `Foo{1,2,3}` (short syntax )
|
// `Foo{1,2,3}` (short syntax )
|
||||||
// if name != '' {
|
// if name != '' {
|
||||||
f.write('$name{')
|
f.write('$name{')
|
||||||
|
|
|
@ -624,8 +624,12 @@ pub:
|
||||||
|
|
||||||
pub fn (table &Table) type_to_str(t Type) string {
|
pub fn (table &Table) type_to_str(t Type) string {
|
||||||
sym := table.get_type_symbol(t)
|
sym := table.get_type_symbol(t)
|
||||||
|
mut res := sym.name
|
||||||
if sym.kind == .multi_return {
|
if sym.kind == .multi_return {
|
||||||
mut res := '('
|
res = '('
|
||||||
|
if t.flag_is(.optional) {
|
||||||
|
res = '?' + res
|
||||||
|
}
|
||||||
mr_info := sym.info as MultiReturn
|
mr_info := sym.info as MultiReturn
|
||||||
for i, typ in mr_info.types {
|
for i, typ in mr_info.types {
|
||||||
res += table.type_to_str(typ)
|
res += table.type_to_str(typ)
|
||||||
|
@ -636,10 +640,9 @@ pub fn (table &Table) type_to_str(t Type) string {
|
||||||
res += ')'
|
res += ')'
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
mut res := sym.name
|
if sym.kind == .array || 'array_' in res {
|
||||||
if sym.kind == .array {
|
|
||||||
res = res.replace('array_', '[]')
|
res = res.replace('array_', '[]')
|
||||||
} else if sym.kind == .map {
|
} else if sym.kind == .map || 'map_string_' in res {
|
||||||
res = res.replace('map_string_', 'map[string]')
|
res = res.replace('map_string_', 'map[string]')
|
||||||
}
|
}
|
||||||
// mod.submod.submod2.Type => submod2.Type
|
// mod.submod.submod2.Type => submod2.Type
|
||||||
|
|
Loading…
Reference in New Issue