parser: store FnDecl body position and use for scope

pull/4700/head
joe-conigliaro 2020-05-04 20:31:34 +10:00
parent 0f0b6a0ccd
commit d75f286230
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1
3 changed files with 4 additions and 3 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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()
}
@ -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
}
@ -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
}