parser/checker/gen: match shaddow cond var & as support: p2

pull/5416/head
joe-conigliaro 2020-06-19 00:41:00 +10:00
parent 68143b7b22
commit 45239cbd62
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1
2 changed files with 21 additions and 34 deletions

View File

@ -126,33 +126,22 @@ pub fn (lit &StringInterLiteral) get_fspec_braces(i int) (string, bool) {
}
}
}
// TODO: remove sponge - put back match
if !needs_braces {
mut sub_expr := lit.exprs[i]
for {
if sub_expr is Ident { break }
else if sub_expr is SelectorExpr {
se := sub_expr as SelectorExpr
sub_expr = se.expr
continue
match sub_expr as sx {
Ident {
break
}
SelectorExpr {
sub_expr = sx.expr
continue
}
else {
needs_braces = true
break
}
}
else {
needs_braces = true
break
}
// match sub_expr {
// Ident {
// break
// }
// SelectorExpr {
// sub_expr = it.expr
// continue
// }
// else {
// needs_braces = true
// break
// }
// }
}
}
if needs_fspec {

View File

@ -1227,15 +1227,13 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
}
fn (mut g Gen) gen_cross_tmp_variable(left []ast.Expr, val ast.Expr) {
// TODO: remove sponge
tmp_val := val
match tmp_val {
match val as val_expr {
ast.Ident {
mut has_var := false
for lx in left {
if lx is ast.Ident {
ident := lx as ast.Ident
if it.name == ident.name {
if val_expr.name == ident.name {
g.write('_var_${ident.pos.pos}')
has_var = true
break
@ -1247,17 +1245,17 @@ fn (mut g Gen) gen_cross_tmp_variable(left []ast.Expr, val ast.Expr) {
}
}
ast.InfixExpr {
g.gen_cross_tmp_variable(left, it.left)
g.write(it.op.str())
g.gen_cross_tmp_variable(left, it.right)
g.gen_cross_tmp_variable(left, val_expr.left)
g.write(val_expr.op.str())
g.gen_cross_tmp_variable(left, val_expr.right)
}
ast.PrefixExpr {
g.write(it.op.str())
g.gen_cross_tmp_variable(left, it.right)
g.write(val_expr.op.str())
g.gen_cross_tmp_variable(left, val_expr.right)
}
ast.PostfixExpr {
g.gen_cross_tmp_variable(left, it.expr)
g.write(it.op.str())
g.gen_cross_tmp_variable(left, val_expr.expr)
g.write(val_expr.op.str())
}
else {
g.expr(val)