cgen: format if_guard_expr generated c codes (#9290)

pull/9298/head
yuyi 2021-03-14 08:54:05 +08:00 committed by GitHub
parent e9797c618a
commit 5a6b321656
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 7 deletions

View File

@ -2859,7 +2859,7 @@ fn (mut g Gen) expr(node ast.Expr) {
}
if is_gen_or_and_assign_rhs {
elem_styp := g.typ(elem_type)
g.write('\n$cur_line*($elem_styp*)${tmp_opt}.data')
g.write(';\n$cur_line*($elem_styp*)${tmp_opt}.data')
}
}
} else {
@ -3703,7 +3703,7 @@ fn (mut g Gen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var str
g.write('(')
} else {
if j == 0 && sumtype_index == 0 {
g.writeln('')
g.empty_line = true
}
g.write_v_source_line_info(branch.pos)
g.write('if (')
@ -4204,8 +4204,6 @@ fn (mut g Gen) if_expr(node ast.IfExpr) {
is_guard = true
guard_idx = i
guard_vars = []string{len: node.branches.len}
g.writeln(';')
g.writeln('{ /* if guard */ ')
}
if cond.expr !is ast.IndexExpr && cond.expr !is ast.PrefixExpr {
var_name := g.new_tmp_var()
@ -4285,9 +4283,6 @@ fn (mut g Gen) if_expr(node ast.IfExpr) {
g.stmts(branch.stmts)
}
}
if is_guard {
g.write('}')
}
g.writeln('}')
if needs_tmp_var {
g.empty_line = false