diff options
author | Matthew Dempsky <mdempsky@google.com> | 2021-06-23 12:08:42 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-06-23 22:23:16 +0000 |
commit | 8165256bc2e3298b0d612471d7d2e6c005b984de (patch) | |
tree | 18882bef09768ca852175c55bb9edfbc73b3e269 /src/cmd/compile/internal/noder/quirks.go | |
parent | a72a499c24cfcfce2a16ac7c228c2c914c4f36c4 (diff) | |
download | go-8165256bc2e3298b0d612471d7d2e6c005b984de.tar.gz go-8165256bc2e3298b0d612471d7d2e6c005b984de.zip |
[dev.typeparams] cmd/compile/internal/syntax: go/ast-style walk API
This CL adds go/ast's Visitor, Walk, and Inspect functions to package
syntax. Having functions with the same API and semantics as their
go/ast counterparts reduces the mental load of context switching
between go/ast and syntax.
It also renames the existing Walk function into Crawl, and marks it as
a deprecated wrapper around Inspect. (I named it "Crawl" because it's
less functional than "Walk"... get it??)
There aren't that many callers to Crawl, so we can probably remove it
in the future. But it doesn't seem pressing, and I'm more concerned
about the risk of forgetting to invert a bool condition somewhere.
Change-Id: Ib2fb275873a1d1a730249c9cb584864cb6ec370e
Reviewed-on: https://go-review.googlesource.com/c/go/+/330429
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/noder/quirks.go')
-rw-r--r-- | src/cmd/compile/internal/noder/quirks.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/noder/quirks.go b/src/cmd/compile/internal/noder/quirks.go index 91b4c22025..914c5d2bd7 100644 --- a/src/cmd/compile/internal/noder/quirks.go +++ b/src/cmd/compile/internal/noder/quirks.go @@ -36,7 +36,7 @@ func posBasesOf(noders []*noder) []*syntax.PosBase { var bases []*syntax.PosBase for _, p := range noders { - syntax.Walk(p.file, func(n syntax.Node) bool { + syntax.Crawl(p.file, func(n syntax.Node) bool { if b := n.Pos().Base(); !seen[b] { bases = append(bases, b) seen[b] = true @@ -74,7 +74,7 @@ func importedObjsOf(curpkg *types2.Package, info *types2.Info, noders []*noder) } for _, p := range noders { - syntax.Walk(p.file, func(n syntax.Node) bool { + syntax.Crawl(p.file, func(n syntax.Node) bool { switch n := n.(type) { case *syntax.ConstDecl: assoc(n, n.NameList...) @@ -167,7 +167,7 @@ func importedObjsOf(curpkg *types2.Package, info *types2.Info, noders []*noder) if n == nil { return } - syntax.Walk(n, func(n syntax.Node) bool { + syntax.Crawl(n, func(n syntax.Node) bool { switch n := n.(type) { case *syntax.Name: checkdef(n) @@ -237,7 +237,7 @@ func importedObjsOf(curpkg *types2.Package, info *types2.Info, noders []*noder) } if phase >= 5 { - syntax.Walk(p.file, func(n syntax.Node) bool { + syntax.Crawl(p.file, func(n syntax.Node) bool { if name, ok := n.(*syntax.Name); ok { if obj, ok := info.Uses[name]; ok { resolveObj(name.Pos(), obj) |