parser: support `mut static x := y` in -translated mode
parent
04d3ca7dbe
commit
e862fad917
|
@ -0,0 +1,6 @@
|
||||||
|
vlib/v/checker/tests/static_vars_in_translated_mode.vv:2:13: error: static variables are supported only in -translated mode
|
||||||
|
1 | fn counter() int {
|
||||||
|
2 | mut static icounter := 0
|
||||||
|
| ~~~~~~~~
|
||||||
|
3 | icounter++
|
||||||
|
4 | return icounter
|
|
@ -0,0 +1,12 @@
|
||||||
|
fn counter() int {
|
||||||
|
mut static icounter := 0
|
||||||
|
icounter++
|
||||||
|
return icounter
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println(counter())
|
||||||
|
println(counter())
|
||||||
|
println(counter())
|
||||||
|
println(counter())
|
||||||
|
}
|
|
@ -263,6 +263,9 @@ pub fn (mut f Fmt) stmt(node ast.Stmt) {
|
||||||
if var_info.is_mut {
|
if var_info.is_mut {
|
||||||
f.write(var_info.share.str() + ' ')
|
f.write(var_info.share.str() + ' ')
|
||||||
}
|
}
|
||||||
|
if var_info.is_static {
|
||||||
|
f.write('static ')
|
||||||
|
}
|
||||||
f.expr(left)
|
f.expr(left)
|
||||||
} else {
|
} else {
|
||||||
f.expr(left)
|
f.expr(left)
|
||||||
|
|
|
@ -105,6 +105,7 @@ fn (mut p Parser) partial_assign_stmt(left []ast.Expr, left_comments []ast.Comme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mut is_static := false
|
||||||
for i, lx in left {
|
for i, lx in left {
|
||||||
match mut lx {
|
match mut lx {
|
||||||
ast.Ident {
|
ast.Ident {
|
||||||
|
@ -114,7 +115,14 @@ fn (mut p Parser) partial_assign_stmt(left []ast.Expr, left_comments []ast.Comme
|
||||||
}
|
}
|
||||||
mut share := table.ShareType(0)
|
mut share := table.ShareType(0)
|
||||||
if lx.info is ast.IdentVar {
|
if lx.info is ast.IdentVar {
|
||||||
share = (lx.info as ast.IdentVar).share
|
iv := lx.info as ast.IdentVar
|
||||||
|
share = iv.share
|
||||||
|
if iv.is_static {
|
||||||
|
if !p.pref.translated {
|
||||||
|
p.error_with_pos('static variables are supported only in -translated mode', lx.pos)
|
||||||
|
}
|
||||||
|
is_static = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mut v := ast.Var{
|
mut v := ast.Var{
|
||||||
name: lx.name
|
name: lx.name
|
||||||
|
@ -157,5 +165,6 @@ fn (mut p Parser) partial_assign_stmt(left []ast.Expr, left_comments []ast.Comme
|
||||||
pos: pos
|
pos: pos
|
||||||
has_cross_var: has_cross_var
|
has_cross_var: has_cross_var
|
||||||
is_simple: p.inside_for && p.tok.kind == .lcbr
|
is_simple: p.inside_for && p.tok.kind == .lcbr
|
||||||
|
is_static: is_static
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue