cmd/tools/vast: update DeferStmt (#10291)

pull/10297/head
lydiandy 2021-06-01 03:49:16 +08:00 committed by GitHub
parent 90292ce981
commit 67518f946b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -97,6 +97,17 @@ fn add(x int, y int) int {
return x + y return x + y
} }
// function with defer stmt
fn defer_fn() {
mut x := 1
println('start fn')
defer {
println('in defer block')
println(x)
}
println('end fn')
}
// generic function // generic function
fn g_fn<T>(p T) T { fn g_fn<T>(p T) T {
return p return p

View File

@ -687,7 +687,9 @@ fn (t Tree) defer_stmt(node ast.DeferStmt) &Node {
obj := new_object() obj := new_object()
obj.add('ast_type', t.string_node('DeferStmt')) obj.add('ast_type', t.string_node('DeferStmt'))
obj.add('stmts', t.array_node_stmt(node.stmts)) obj.add('stmts', t.array_node_stmt(node.stmts))
obj.add('defer_vars', t.array_node_ident(node.defer_vars))
obj.add('ifdef', t.string_node(node.ifdef)) obj.add('ifdef', t.string_node(node.ifdef))
obj.add('idx_in_fn', t.number_node(node.idx_in_fn))
obj.add('pos', t.position(node.pos)) obj.add('pos', t.position(node.pos))
return obj return obj
} }
@ -1329,10 +1331,11 @@ fn (t Tree) if_branch(node ast.IfBranch) &Node {
fn (t Tree) ident(node ast.Ident) &Node { fn (t Tree) ident(node ast.Ident) &Node {
obj := new_object() obj := new_object()
obj.add('ast_type', t.string_node('Ident')) obj.add('ast_type', t.string_node('Ident'))
obj.add('name', t.string_node(node.name))
obj.add('mod', t.string_node(node.mod)) obj.add('mod', t.string_node(node.mod))
obj.add('name', t.string_node(node.name))
obj.add('language', t.enum_node(node.language)) obj.add('language', t.enum_node(node.language))
obj.add('is_mut', t.bool_node(node.is_mut)) obj.add('is_mut', t.bool_node(node.is_mut))
obj.add('comptime', t.bool_node(node.comptime))
obj.add('tok_kind', t.token_node(node.tok_kind)) obj.add('tok_kind', t.token_node(node.tok_kind))
obj.add('kind', t.enum_node(node.kind)) obj.add('kind', t.enum_node(node.kind))
obj.add('info', t.ident_info(node.info)) obj.add('info', t.ident_info(node.info))