From 9dc808a65eb3f44d64e078b79bcac0f0510629f6 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 10 Jan 2018 16:13:34 +0100 Subject: 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. --- pkg/compiler/consts.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'pkg/compiler/consts.go') 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 -- cgit mrf-deployment