From 29943d7a916118710004e3d07317c009c8990b63 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 2 Jul 2020 15:06:29 +0300 Subject: [PATCH] vfmt: fix eating C. from C.sapp_desc{} and adding & to &&&App() --- vlib/v/fmt/fmt.v | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 1366514f8d..cf676e08e1 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -257,7 +257,7 @@ pub fn (mut f Fmt) stmt(node ast.Stmt) { f.is_assign = true f.write(' $node.op.str() ') for i, val in node.right { - f.expr(val) + f.prefix_expr_cast_expr(val) if i < node.right.len - 1 { f.write(', ') } @@ -595,7 +595,7 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) { } if field.has_default_expr { f.write(' = ') - f.struct_field_expr(field.default_expr) + f.prefix_expr_cast_expr(field.default_expr) } f.write('\n') continue @@ -625,7 +625,7 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) { } if field.has_default_expr { f.write(' = ') - f.struct_field_expr(field.default_expr) + f.prefix_expr_cast_expr(field.default_expr) } // Handle comments after field type (same line) 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') } -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 ce := ast.CastExpr{} if fexpr is ast.PrefixExpr { pe := fexpr as ast.PrefixExpr if pe.right is ast.CastExpr && pe.op == .amp { ce = pe.right as ast.CastExpr + ce.typname = f.table.get_type_symbol(ce.typ).name is_pe_amp_ce = true f.expr(ce) } @@ -716,6 +717,7 @@ pub fn (mut f Fmt) expr(node ast.Expr) { f.write(node.val.str()) } ast.CastExpr { + node.typname = f.table.get_type_symbol(node.typ).name f.write(f.type_to_str(node.typ) + '(') f.expr(node.expr) 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) { type_sym := f.table.get_type_symbol(it.typ) // f.write('') - 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' { name = '' } @@ -1490,7 +1495,7 @@ pub fn (mut f Fmt) struct_init(it ast.StructInit) { f.write('$name{') // } 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 { f.write(', ') } @@ -1505,7 +1510,7 @@ pub fn (mut f Fmt) struct_init(it ast.StructInit) { f.indent++ for field in it.fields { f.write('$field.name: ') - f.struct_field_expr(field.expr) + f.prefix_expr_cast_expr(field.expr) f.writeln('') } f.indent--