mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker/fmt/cgen: fun vfmt on changes from previous commit
This commit is contained in:
parent
a331abf675
commit
15d4b5fcdb
@ -912,7 +912,7 @@ pub fn (c mut Checker) if_expr(node mut ast.IfExpr) table.Type {
|
||||
node.typ = table.void_type
|
||||
for i, branch in node.branches {
|
||||
typ := c.expr(branch.cond)
|
||||
if i < node.branches.len-1 || !node.has_else {
|
||||
if i < node.branches.len - 1 || !node.has_else {
|
||||
typ_sym := c.table.get_type_symbol(typ)
|
||||
// if typ_sym.kind != .bool {
|
||||
if table.type_idx(typ) != table.bool_type_idx {
|
||||
@ -922,7 +922,7 @@ pub fn (c mut Checker) if_expr(node mut ast.IfExpr) table.Type {
|
||||
c.stmts(branch.stmts)
|
||||
}
|
||||
if node.has_else && node.is_expr {
|
||||
last_branch := node.branches[node.branches.len-1]
|
||||
last_branch := node.branches[node.branches.len - 1]
|
||||
if last_branch.stmts.len > 0 {
|
||||
match last_branch.stmts[last_branch.stmts.len - 1] {
|
||||
ast.ExprStmt {
|
||||
@ -933,7 +933,7 @@ pub fn (c mut Checker) if_expr(node mut ast.IfExpr) table.Type {
|
||||
return t
|
||||
}
|
||||
else {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return table.bool_type
|
||||
|
@ -406,9 +406,6 @@ fn (f mut Fmt) expr(node ast.Expr) {
|
||||
f.write(' ')
|
||||
}
|
||||
}
|
||||
// if !single_line {
|
||||
// f.writeln('')
|
||||
// }
|
||||
f.write('}')
|
||||
f.single_line_if = false
|
||||
}
|
||||
|
@ -1176,14 +1176,14 @@ fn (g mut Gen) if_expr(node ast.IfExpr) {
|
||||
}
|
||||
// one line ?:
|
||||
// TODO clean this up once `is` is supported
|
||||
// TODO: make sure only one stmt in eac branch
|
||||
// TODO: make sure only one stmt in each branch
|
||||
if node.is_expr && node.branches.len >= 2 && node.has_else && type_sym.kind != .void {
|
||||
g.inside_ternary = true
|
||||
for i, branch in node.branches {
|
||||
if i > 0 {
|
||||
g.write(' : ')
|
||||
}
|
||||
if i < node.branches.len-1 || !node.has_else {
|
||||
if i < node.branches.len - 1 || !node.has_else {
|
||||
g.expr(branch.cond)
|
||||
g.write(' ? ')
|
||||
}
|
||||
@ -1210,15 +1210,14 @@ fn (g mut Gen) if_expr(node ast.IfExpr) {
|
||||
g.expr(branch.cond)
|
||||
g.writeln(') {')
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if i < node.branches.len-1 || !node.has_else {
|
||||
else if i < node.branches.len - 1 || !node.has_else {
|
||||
g.writeln('} else if (')
|
||||
g.expr(branch.cond)
|
||||
g.write(') {')
|
||||
}
|
||||
else if i == node.branches.len-1 && node.has_else {
|
||||
else if i == node.branches.len - 1 && node.has_else {
|
||||
if is_guard {
|
||||
g.writeln('} if (!$guard_ok) { /* else */')
|
||||
}
|
||||
@ -1229,9 +1228,7 @@ fn (g mut Gen) if_expr(node ast.IfExpr) {
|
||||
// Assign ret value
|
||||
// if i == node.stmts.len - 1 && type_sym.kind != .void {}
|
||||
// g.writeln('$tmp =')
|
||||
//
|
||||
g.stmts(branch.stmts)
|
||||
// g.writeln('')
|
||||
}
|
||||
if is_guard {
|
||||
g.write('}')
|
||||
|
Loading…
Reference in New Issue
Block a user