cgen: format if_expr generated c codes (#9084)
parent
a5dd7faf3c
commit
6825b4cb30
|
@ -4117,14 +4117,12 @@ fn (mut g Gen) if_expr(node ast.IfExpr) {
|
|||
if node.typ.has_flag(.optional) {
|
||||
g.inside_if_optional = true
|
||||
}
|
||||
g.write('/*experimental if expr*/')
|
||||
styp := g.typ(node.typ)
|
||||
// g.insert_before_stmt('$styp $tmp;')
|
||||
cur_line = g.go_before_stmt(0)
|
||||
g.empty_line = true
|
||||
g.writeln('$styp $tmp; /* if prepend */')
|
||||
} else if node.is_expr || g.inside_ternary != 0 {
|
||||
g.inside_ternary++
|
||||
// g.inside_if_expr = true
|
||||
g.write('(')
|
||||
for i, branch in node.branches {
|
||||
if i > 0 {
|
||||
|
@ -4239,8 +4237,8 @@ fn (mut g Gen) if_expr(node ast.IfExpr) {
|
|||
}
|
||||
g.writeln('}')
|
||||
if needs_tmp_var {
|
||||
// g.writeln('$cur_line $tmp; /*Z*/')
|
||||
g.write('$cur_line $tmp /*Z*/')
|
||||
g.empty_line = false
|
||||
g.write('$cur_line $tmp')
|
||||
}
|
||||
if node.typ.has_flag(.optional) {
|
||||
g.inside_if_optional = false
|
||||
|
@ -4455,9 +4453,6 @@ fn (mut g Gen) return_statement(node ast.Return) {
|
|||
if expr is ast.Ident {
|
||||
g.returned_var_name = expr.name
|
||||
}
|
||||
if tmp != '' {
|
||||
g.writeln('; // free tmp exprs + all vars before return')
|
||||
}
|
||||
g.writeln(';')
|
||||
// autofree before `return`
|
||||
// set free_parent_scopes to true, since all variables defined in parent
|
||||
|
|
Loading…
Reference in New Issue