vfmt: fix eating C. from C.sapp_desc{} and adding & to &&&App()

pull/5622/head
Delyan Angelov 2020-07-02 15:06:29 +03:00
parent aa270263c9
commit 29943d7a91
1 changed files with 12 additions and 7 deletions

View File

@ -257,7 +257,7 @@ pub fn (mut f Fmt) stmt(node ast.Stmt) {
f.is_assign = true f.is_assign = true
f.write(' $node.op.str() ') f.write(' $node.op.str() ')
for i, val in node.right { for i, val in node.right {
f.expr(val) f.prefix_expr_cast_expr(val)
if i < node.right.len - 1 { if i < node.right.len - 1 {
f.write(', ') f.write(', ')
} }
@ -595,7 +595,7 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
} }
if field.has_default_expr { if field.has_default_expr {
f.write(' = ') f.write(' = ')
f.struct_field_expr(field.default_expr) f.prefix_expr_cast_expr(field.default_expr)
} }
f.write('\n') f.write('\n')
continue continue
@ -625,7 +625,7 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
} }
if field.has_default_expr { if field.has_default_expr {
f.write(' = ') f.write(' = ')
f.struct_field_expr(field.default_expr) f.prefix_expr_cast_expr(field.default_expr)
} }
// Handle comments after field type (same line) // Handle comments after field type (same line)
for j < comments.len && field.pos.line_nr == comments[j].pos.line_nr { for j < comments.len && field.pos.line_nr == comments[j].pos.line_nr {
@ -644,13 +644,14 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
f.writeln('}\n') f.writeln('}\n')
} }
pub fn (mut f Fmt) struct_field_expr(fexpr ast.Expr) { pub fn (mut f Fmt) prefix_expr_cast_expr(fexpr ast.Expr) {
mut is_pe_amp_ce := false mut is_pe_amp_ce := false
mut ce := ast.CastExpr{} mut ce := ast.CastExpr{}
if fexpr is ast.PrefixExpr { if fexpr is ast.PrefixExpr {
pe := fexpr as ast.PrefixExpr pe := fexpr as ast.PrefixExpr
if pe.right is ast.CastExpr && pe.op == .amp { if pe.right is ast.CastExpr && pe.op == .amp {
ce = pe.right as ast.CastExpr ce = pe.right as ast.CastExpr
ce.typname = f.table.get_type_symbol(ce.typ).name
is_pe_amp_ce = true is_pe_amp_ce = true
f.expr(ce) f.expr(ce)
} }
@ -716,6 +717,7 @@ pub fn (mut f Fmt) expr(node ast.Expr) {
f.write(node.val.str()) f.write(node.val.str())
} }
ast.CastExpr { ast.CastExpr {
node.typname = f.table.get_type_symbol(node.typ).name
f.write(f.type_to_str(node.typ) + '(') f.write(f.type_to_str(node.typ) + '(')
f.expr(node.expr) f.expr(node.expr)
f.write(')') f.write(')')
@ -1477,7 +1479,10 @@ pub fn (mut f Fmt) array_init(it ast.ArrayInit) {
pub fn (mut f Fmt) struct_init(it ast.StructInit) { pub fn (mut f Fmt) struct_init(it ast.StructInit) {
type_sym := f.table.get_type_symbol(it.typ) type_sym := f.table.get_type_symbol(it.typ)
// f.write('<old name: $type_sym.name>') // f.write('<old name: $type_sym.name>')
mut name := f.short_module(type_sym.name).replace(f.cur_mod + '.', '') // TODO f.type_to_str? mut name := type_sym.name
if !name.starts_with('C.') {
name = f.short_module(type_sym.name).replace(f.cur_mod + '.', '') // TODO f.type_to_str?
}
if name == 'void' { if name == 'void' {
name = '' name = ''
} }
@ -1490,7 +1495,7 @@ pub fn (mut f Fmt) struct_init(it ast.StructInit) {
f.write('$name{') f.write('$name{')
// } // }
for i, field in it.fields { for i, field in it.fields {
f.struct_field_expr(field.expr) f.prefix_expr_cast_expr(field.expr)
if i < it.fields.len - 1 { if i < it.fields.len - 1 {
f.write(', ') f.write(', ')
} }
@ -1505,7 +1510,7 @@ pub fn (mut f Fmt) struct_init(it ast.StructInit) {
f.indent++ f.indent++
for field in it.fields { for field in it.fields {
f.write('$field.name: ') f.write('$field.name: ')
f.struct_field_expr(field.expr) f.prefix_expr_cast_expr(field.expr)
f.writeln('') f.writeln('')
} }
f.indent-- f.indent--