From b354f9ae9aee6e36209bbceaca58eb6f2f666c8e Mon Sep 17 00:00:00 2001 From: zakuro Date: Thu, 23 Sep 2021 20:52:32 +0900 Subject: [PATCH] cgen: fix c error of if-expression when debug mode (#11950) --- vlib/v/gen/c/array.v | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/vlib/v/gen/c/array.v b/vlib/v/gen/c/array.v index 5bfe78a49c..4a42421c72 100644 --- a/vlib/v/gen/c/array.v +++ b/vlib/v/gen/c/array.v @@ -139,7 +139,9 @@ fn (mut g Gen) array_init(node ast.ArrayInit) { fn (mut g Gen) gen_array_map(node ast.CallExpr) { g.inside_lambda = true tmp := g.new_tmp_var() - s := g.go_before_stmt(0).trim_space() + mut s := g.go_before_stmt(0) + s_ends_with_ln := s.ends_with('\n') + s = s.trim_space() // println('filter s="$s"') ret_typ := g.typ(node.return_type) // inp_typ := g.typ(node.receiver_type) @@ -215,7 +217,11 @@ fn (mut g Gen) gen_array_map(node ast.CallExpr) { g.indent-- g.writeln('}') } - g.write(s) + if s_ends_with_ln { + g.writeln(s) + } else { + g.write(s) + } g.write(tmp) g.inside_lambda = false } @@ -326,7 +332,9 @@ fn (mut g Gen) gen_array_sort_call(node ast.CallExpr, compare_fn string) { // `nums.filter(it % 2 == 0)` fn (mut g Gen) gen_array_filter(node ast.CallExpr) { tmp := g.new_tmp_var() - s := g.go_before_stmt(0).trim_space() + mut s := g.go_before_stmt(0) + s_ends_with_ln := s.ends_with('\n') + s = s.trim_space() // println('filter s="$s"') sym := g.table.get_type_symbol(node.return_type) if sym.kind != .array { @@ -399,7 +407,11 @@ fn (mut g Gen) gen_array_filter(node ast.CallExpr) { g.indent-- g.writeln('}') } - g.write(s) + if s_ends_with_ln { + g.writeln(s) + } else { + g.write(s) + } g.write(tmp) } @@ -615,7 +627,9 @@ fn (mut g Gen) gen_array_wait(node ast.CallExpr) { fn (mut g Gen) gen_array_any(node ast.CallExpr) { tmp := g.new_tmp_var() - s := g.go_before_stmt(0).trim_space() + mut s := g.go_before_stmt(0) + s_ends_with_ln := s.ends_with('\n') + s = s.trim_space() sym := g.table.get_type_symbol(node.left_type) info := sym.info as ast.Array // styp := g.typ(node.return_type) @@ -683,13 +697,19 @@ fn (mut g Gen) gen_array_any(node ast.CallExpr) { g.indent-- g.writeln('}') } - g.write(s) + if s_ends_with_ln { + g.writeln(s) + } else { + g.write(s) + } g.write(tmp) } fn (mut g Gen) gen_array_all(node ast.CallExpr) { tmp := g.new_tmp_var() - s := g.go_before_stmt(0).trim_space() + mut s := g.go_before_stmt(0) + s_ends_with_ln := s.ends_with('\n') + s = s.trim_space() sym := g.table.get_type_symbol(node.left_type) info := sym.info as ast.Array // styp := g.typ(node.return_type) @@ -757,6 +777,10 @@ fn (mut g Gen) gen_array_all(node ast.CallExpr) { g.indent-- g.writeln('}') } - g.write(s) + if s_ends_with_ln { + g.writeln(s) + } else { + g.write(s) + } g.write(tmp) }