parser/cgen: autofree - move branch_parent_pos to cgen.
parent
d7c057840a
commit
7733834751
|
@ -289,7 +289,6 @@ pub:
|
||||||
kind token.Kind
|
kind token.Kind
|
||||||
label string
|
label string
|
||||||
pos token.Position
|
pos token.Position
|
||||||
parent_pos int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CallExpr {
|
pub struct CallExpr {
|
||||||
|
|
|
@ -126,6 +126,7 @@ mut:
|
||||||
// sum type deref needs to know which index to deref because unions take care of the correct field
|
// sum type deref needs to know which index to deref because unions take care of the correct field
|
||||||
aggregate_type_idx int
|
aggregate_type_idx int
|
||||||
returned_var_name string // to detect that a var doesn't need to be freed since it's being returned
|
returned_var_name string // to detect that a var doesn't need to be freed since it's being returned
|
||||||
|
branch_parent_pos int // used in BranchStmt (continue/break) for autofree stop position
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -853,7 +854,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
|
||||||
if g.pref.autofree && !g.is_builtin_mod {
|
if g.pref.autofree && !g.is_builtin_mod {
|
||||||
g.writeln('// free before continue/break')
|
g.writeln('// free before continue/break')
|
||||||
g.autofree_scope_vars_stop(node.pos.pos - 1, node.pos.line_nr, true,
|
g.autofree_scope_vars_stop(node.pos.pos - 1, node.pos.line_nr, true,
|
||||||
node.parent_pos)
|
g.branch_parent_pos)
|
||||||
}
|
}
|
||||||
g.writeln('$node.kind;')
|
g.writeln('$node.kind;')
|
||||||
}
|
}
|
||||||
|
@ -1008,6 +1009,8 @@ fn (mut g Gen) stmt(node ast.Stmt) {
|
||||||
g.for_in(node)
|
g.for_in(node)
|
||||||
}
|
}
|
||||||
ast.ForStmt {
|
ast.ForStmt {
|
||||||
|
prev_branch_parent_pos := g.branch_parent_pos
|
||||||
|
g.branch_parent_pos = node.pos.pos
|
||||||
g.write_v_source_line_info(node.pos)
|
g.write_v_source_line_info(node.pos)
|
||||||
g.is_vlines_enabled = false
|
g.is_vlines_enabled = false
|
||||||
if node.label.len > 0 {
|
if node.label.len > 0 {
|
||||||
|
@ -1031,6 +1034,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
|
||||||
if node.label.len > 0 {
|
if node.label.len > 0 {
|
||||||
g.writeln('${node.label}__break: {}')
|
g.writeln('${node.label}__break: {}')
|
||||||
}
|
}
|
||||||
|
g.branch_parent_pos = prev_branch_parent_pos
|
||||||
}
|
}
|
||||||
ast.GlobalDecl {
|
ast.GlobalDecl {
|
||||||
g.global_decl(node)
|
g.global_decl(node)
|
||||||
|
|
|
@ -9,11 +9,6 @@ import v.table
|
||||||
fn (mut p Parser) for_stmt() ast.Stmt {
|
fn (mut p Parser) for_stmt() ast.Stmt {
|
||||||
p.check(.key_for)
|
p.check(.key_for)
|
||||||
pos := p.tok.position()
|
pos := p.tok.position()
|
||||||
prev_branch_parent_pos := p.branch_parent_pos
|
|
||||||
p.branch_parent_pos = pos.pos
|
|
||||||
defer {
|
|
||||||
p.branch_parent_pos = prev_branch_parent_pos
|
|
||||||
}
|
|
||||||
p.open_scope()
|
p.open_scope()
|
||||||
p.inside_for = true
|
p.inside_for = true
|
||||||
if p.tok.kind == .key_match {
|
if p.tok.kind == .key_match {
|
||||||
|
|
|
@ -60,7 +60,6 @@ mut:
|
||||||
vet_errors []string
|
vet_errors []string
|
||||||
cur_fn_name string
|
cur_fn_name string
|
||||||
in_generic_params bool // indicates if parsing between `<` and `>` of a method/function
|
in_generic_params bool // indicates if parsing between `<` and `>` of a method/function
|
||||||
branch_parent_pos int // used in BranchStmt (continue/break) autofree stop position
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for tests
|
// for tests
|
||||||
|
@ -691,7 +690,6 @@ pub fn (mut p Parser) stmt(is_top_level bool) ast.Stmt {
|
||||||
kind: tok.kind
|
kind: tok.kind
|
||||||
label: label
|
label: label
|
||||||
pos: tok.position()
|
pos: tok.position()
|
||||||
parent_pos: p.branch_parent_pos
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.key_unsafe {
|
.key_unsafe {
|
||||||
|
|
Loading…
Reference in New Issue