parser: store FnDecl body position and use for scope
parent
0f0b6a0ccd
commit
d75f286230
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue