]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/syntax: remove Crawl, not needed anymore (cleanup)
authorRobert Griesemer <gri@golang.org>
Thu, 5 Jan 2023 23:07:04 +0000 (15:07 -0800)
committerGopher Robot <gobot@golang.org>
Tue, 17 Jan 2023 19:55:04 +0000 (19:55 +0000)
This also brings some of the types2 testing code better in sync with
go/types.

Also: fix a minor bug in resolver_test.go (continue traversing
      SelectorExpr if the first part is not an identifier).

Change-Id: Ib6c5f6228812b49c185b52a4f02ca5b393418e01
Reviewed-on: https://go-review.googlesource.com/c/go/+/460760
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/noder/irgen.go
src/cmd/compile/internal/syntax/walk.go
src/cmd/compile/internal/types2/issues_test.go
src/cmd/compile/internal/types2/resolver_test.go
src/go/types/resolver_test.go

index d0349260e85468066fef25b929d4282fe781ec22..b5e10236ce8978b27e5510d313fb79d0d013c510 100644 (file)
@@ -359,9 +359,9 @@ Outer:
 
                // Double check for any type-checking inconsistencies. This can be
                // removed once we're confident in IR generation results.
-               syntax.Crawl(p.file, func(n syntax.Node) bool {
+               syntax.Inspect(p.file, func(n syntax.Node) bool {
                        g.validate(n)
-                       return false
+                       return true
                })
        }
 
index 8f1d566155d2328021966a19def18658f5e07ec3..b03a7c14b0d14e579fb6ec91d4334fd397735a24 100644 (file)
@@ -8,10 +8,9 @@ package syntax
 
 import "fmt"
 
-// Inspect traverses an AST in pre-order: It starts by calling
-// f(node); node must not be nil. If f returns true, Inspect invokes f
-// recursively for each of the non-nil children of node, followed by a
-// call of f(nil).
+// Inspect traverses an AST in pre-order: it starts by calling f(root);
+// root must not be nil. If f returns true, Inspect invokes f recursively
+// for each of the non-nil children of root, followed by a call of f(nil).
 //
 // See Walk for caveats about shared nodes.
 func Inspect(root Node, f func(Node) bool) {
@@ -27,21 +26,6 @@ func (v inspector) Visit(node Node) Visitor {
        return nil
 }
 
-// Crawl traverses a syntax in pre-order: It starts by calling f(root);
-// root must not be nil. If f returns false (== "continue"), Crawl calls
-// f recursively for each of the non-nil children of that node; if f
-// returns true (== "stop"), Crawl does not traverse the respective node's
-// children.
-//
-// See Walk for caveats about shared nodes.
-//
-// Deprecated: Use Inspect instead.
-func Crawl(root Node, f func(Node) bool) {
-       Inspect(root, func(node Node) bool {
-               return node != nil && !f(node)
-       })
-}
-
 // Walk traverses an AST in pre-order: It starts by calling
 // v.Visit(node); node must not be nil. If the visitor w returned by
 // v.Visit(node) is not nil, Walk is invoked recursively with visitor
index 52784207d7d9acf8467f274174d529affbc82722..0ea5df5d5b8e0cac7c8019622d6dc9a36edc0860 100644 (file)
@@ -302,7 +302,7 @@ func TestIssue25627(t *testing.T) {
                        }
                }
 
-               syntax.Crawl(f, func(n syntax.Node) bool {
+               syntax.Inspect(f, func(n syntax.Node) bool {
                        if decl, _ := n.(*syntax.TypeDecl); decl != nil {
                                if tv, ok := info.Types[decl.Type]; ok && decl.Name.Value == "T" {
                                        want := strings.Count(src, ";") + 1
@@ -311,7 +311,7 @@ func TestIssue25627(t *testing.T) {
                                        }
                                }
                        }
-                       return false
+                       return true
                })
        }
 }
index e303d34827ec5e4f1c7ce48eed20c1495487b345..cafbfc9af6b9e3f4aed1a986235a0fc365dd632e 100644 (file)
@@ -139,23 +139,23 @@ func TestResolveIdents(t *testing.T) {
 
        // check that qualified identifiers are resolved
        for _, f := range files {
-               syntax.Crawl(f, func(n syntax.Node) bool {
+               syntax.Inspect(f, func(n syntax.Node) bool {
                        if s, ok := n.(*syntax.SelectorExpr); ok {
                                if x, ok := s.X.(*syntax.Name); ok {
                                        obj := uses[x]
                                        if obj == nil {
                                                t.Errorf("%s: unresolved qualified identifier %s", x.Pos(), x.Value)
-                                               return true
+                                               return false
                                        }
                                        if _, ok := obj.(*PkgName); ok && uses[s.Sel] == nil {
                                                t.Errorf("%s: unresolved selector %s", s.Sel.Pos(), s.Sel.Value)
-                                               return true
+                                               return false
                                        }
-                                       return true
+                                       return false
                                }
                                return true
                        }
-                       return false
+                       return true
                })
        }
 
@@ -173,7 +173,7 @@ func TestResolveIdents(t *testing.T) {
        foundDefs := make(map[*syntax.Name]bool)
        var both []string
        for _, f := range files {
-               syntax.Crawl(f, func(n syntax.Node) bool {
+               syntax.Inspect(f, func(n syntax.Node) bool {
                        if x, ok := n.(*syntax.Name); ok {
                                var objects int
                                if _, found := uses[x]; found {
@@ -190,9 +190,9 @@ func TestResolveIdents(t *testing.T) {
                                case 3:
                                        both = append(both, x.Value)
                                }
-                               return true
+                               return false
                        }
-                       return false
+                       return true
                })
        }
 
index 376ecfbea05be5c1464c55fc87f1491769a94a8b..284ad8e998d652fe022e32e8e4902b7139478a16 100644 (file)
@@ -156,7 +156,7 @@ func TestResolveIdents(t *testing.T) {
                                        }
                                        return false
                                }
-                               return false
+                               return true
                        }
                        return true
                })