Skip to content

Commit

Permalink
parser: store FnDecl body position and use for scope
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-conigliaro committed May 4, 2020
1 parent 0f0b6a0 commit d75f286
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions vlib/v/ast/ast.v
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ pub:
is_builtin bool // this function is defined in builtin/strconv
ctdefine string // has [if myflag] tag
pos token.Position
body_pos token.Position
file string
pub mut:
return_type table.Type
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/gen/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) {
// ////////////
if g.autofree {
// println('\n\ncalling free for fn $it.name')
g.free_scope_vars(it.pos.pos + it.pos.len/2)
g.free_scope_vars(it.body_pos.pos)
}
// /////////
if is_main {
Expand Down
4 changes: 2 additions & 2 deletions vlib/v/parser/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
// Body
mut stmts := []ast.Stmt{}
no_body := p.tok.kind != .lcbr
body_start_pos := p.peek_tok.position()
if p.tok.kind == .lcbr {
stmts = p.parse_block_no_scope()
}
Expand All @@ -255,7 +256,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
is_js: is_js
no_body: no_body
pos: start_pos.extend(end_pos)
file: p.file_name
body_pos: body_start_pos
is_builtin: p.builtin_mod || p.mod in util.builtin_module_parts
ctdefine: ctdefine
}
Expand Down Expand Up @@ -306,7 +307,6 @@ fn (mut p Parser) anon_fn() ast.AnonFn {
is_anon: true
no_body: no_body
pos: pos
file: p.file_name
}
typ: typ
}
Expand Down

0 comments on commit d75f286

Please sign in to comment.