diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-01-10 16:13:34 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-01-11 11:45:35 +0100 |
| commit | 9dc808a65eb3f44d64e078b79bcac0f0510629f6 (patch) | |
| tree | f07b2a683fd60be7c401e4b22d1e3b106f81b3d7 /pkg/compiler/consts.go | |
| parent | 7a4d53c30f5365112314a372b4ef6112b9e6b282 (diff) | |
pkg/ast: refactor Walk
Refactor Walk so that it's possible to abort or wrap walk of child nodes.
Will be needed for future changes.
Diffstat (limited to 'pkg/compiler/consts.go')
| -rw-r--r-- | pkg/compiler/consts.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/pkg/compiler/consts.go b/pkg/compiler/consts.go index 338dea4b1..f2e4d4850 100644 --- a/pkg/compiler/consts.go +++ b/pkg/compiler/consts.go @@ -43,8 +43,8 @@ func ExtractConsts(desc *ast.Description, target *targets.Target, eh0 ast.ErrorH incdirMap := make(map[string]bool) constMap := make(map[string]bool) - ast.Walk(desc, func(n1 ast.Node) { - switch n := n1.(type) { + desc.Walk(ast.Recursive(func(n0 ast.Node) { + switch n := n0.(type) { case *ast.Include: file := n.File.Value if includeMap[file] { @@ -85,7 +85,7 @@ func ExtractConsts(desc *ast.Description, target *targets.Target, eh0 ast.ErrorH case *ast.Int: constMap[n.Ident] = true } - }) + })) if errors != 0 { return nil @@ -179,7 +179,7 @@ func (comp *compiler) patchConsts(consts map[string]uint64) { case *ast.Resource, *ast.Struct, *ast.Call, *ast.TypeDef: // Walk whole tree and replace consts in Int's and Type's. missing := "" - ast.WalkNode(decl, func(n0 ast.Node) { + decl.Walk(ast.Recursive(func(n0 ast.Node) { switch n := n0.(type) { case *ast.Int: comp.patchIntConst(n.Pos, &n.Value, &n.Ident, consts, &missing) @@ -193,7 +193,7 @@ func (comp *compiler) patchConsts(consts map[string]uint64) { } } } - }) + })) if missing == "" { top = append(top, decl) continue |
