mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: store FnDecl body position and use for scope
This commit is contained in:
parent
0f0b6a0ccd
commit
d75f286230
@ -213,6 +213,7 @@ pub:
|
|||||||
is_builtin bool // this function is defined in builtin/strconv
|
is_builtin bool // this function is defined in builtin/strconv
|
||||||
ctdefine string // has [if myflag] tag
|
ctdefine string // has [if myflag] tag
|
||||||
pos token.Position
|
pos token.Position
|
||||||
|
body_pos token.Position
|
||||||
file string
|
file string
|
||||||
pub mut:
|
pub mut:
|
||||||
return_type table.Type
|
return_type table.Type
|
||||||
|
@ -161,7 +161,7 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) {
|
|||||||
// ////////////
|
// ////////////
|
||||||
if g.autofree {
|
if g.autofree {
|
||||||
// println('\n\ncalling free for fn $it.name')
|
// 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 {
|
if is_main {
|
||||||
|
@ -231,6 +231,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
|||||||
// Body
|
// Body
|
||||||
mut stmts := []ast.Stmt{}
|
mut stmts := []ast.Stmt{}
|
||||||
no_body := p.tok.kind != .lcbr
|
no_body := p.tok.kind != .lcbr
|
||||||
|
body_start_pos := p.peek_tok.position()
|
||||||
if p.tok.kind == .lcbr {
|
if p.tok.kind == .lcbr {
|
||||||
stmts = p.parse_block_no_scope()
|
stmts = p.parse_block_no_scope()
|
||||||
}
|
}
|
||||||
@ -255,7 +256,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
|||||||
is_js: is_js
|
is_js: is_js
|
||||||
no_body: no_body
|
no_body: no_body
|
||||||
pos: start_pos.extend(end_pos)
|
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
|
is_builtin: p.builtin_mod || p.mod in util.builtin_module_parts
|
||||||
ctdefine: ctdefine
|
ctdefine: ctdefine
|
||||||
}
|
}
|
||||||
@ -306,7 +307,6 @@ fn (mut p Parser) anon_fn() ast.AnonFn {
|
|||||||
is_anon: true
|
is_anon: true
|
||||||
no_body: no_body
|
no_body: no_body
|
||||||
pos: pos
|
pos: pos
|
||||||
file: p.file_name
|
|
||||||
}
|
}
|
||||||
typ: typ
|
typ: typ
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user