1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
d2verb 2019-07-31 01:05:06 +09:00 committed by Alexander Medvednikov
parent acd28fa495
commit 9bcb5aaa55

View File

@ -3283,14 +3283,18 @@ fn (p mut Parser) attribute() {
fn (p mut Parser) defer_st() { fn (p mut Parser) defer_st() {
p.check(.key_defer) p.check(.key_defer)
// Wrap everything inside the defer block in /**/ comments, and save it in
// `defer_text`. It will be inserted before every `return`.
p.genln('/*')
pos := p.cgen.lines.len
p.check(.lcbr) p.check(.lcbr)
pos := p.cgen.lines.len
// Save everything inside the defer block to `defer_text`.
// It will be inserted before every `return`
p.genln('{') p.genln('{')
p.statements() p.statements()
p.cur_fn.defer_text = p.cgen.lines.right(pos).join('\n') + p.cur_fn.defer_text p.cur_fn.defer_text = p.cgen.lines.right(pos).join('\n') + p.cur_fn.defer_text
p.genln('*/')
// Rollback p.cgen.lines
p.cgen.lines = p.cgen.lines.left(pos)
p.cgen.resetln('')
} }