]> Cypherpunks repositories - gostls13.git/commitdiff
gofix: walk names in ValueSpecs
authorRob Pike <r@golang.org>
Thu, 18 Aug 2011 03:48:44 +0000 (13:48 +1000)
committerRob Pike <r@golang.org>
Thu, 18 Aug 2011 03:48:44 +0000 (13:48 +1000)
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4887048

src/cmd/gofix/fix.go
src/cmd/gofix/url.go

index c1c5a746ccf04bd1baab19221e8c223af2731b9c..cc85ceafa30445d651688a17895a5af1ac29f990 100644 (file)
@@ -71,17 +71,21 @@ func walkBeforeAfter(x interface{}, before, after func(interface{})) {
                walkBeforeAfter(*n, before, after)
        case **ast.FuncType:
                walkBeforeAfter(*n, before, after)
+       case **ast.Ident:
+               walkBeforeAfter(*n, before, after)
 
        // pointers to slices
-       case *[]ast.Stmt:
+       case *[]ast.Decl:
                walkBeforeAfter(*n, before, after)
        case *[]ast.Expr:
                walkBeforeAfter(*n, before, after)
-       case *[]ast.Decl:
+       case *[]*ast.File:
+               walkBeforeAfter(*n, before, after)
+       case *[]*ast.Ident:
                walkBeforeAfter(*n, before, after)
        case *[]ast.Spec:
                walkBeforeAfter(*n, before, after)
-       case *[]*ast.File:
+       case *[]ast.Stmt:
                walkBeforeAfter(*n, before, after)
 
        // These are ordered and grouped to match ../../pkg/go/ast/ast.go
@@ -212,6 +216,7 @@ func walkBeforeAfter(x interface{}, before, after func(interface{})) {
        case *ast.ValueSpec:
                walkBeforeAfter(&n.Type, before, after)
                walkBeforeAfter(&n.Values, before, after)
+               walkBeforeAfter(&n.Names, before, after)
        case *ast.TypeSpec:
                walkBeforeAfter(&n.Type, before, after)
 
@@ -245,6 +250,10 @@ func walkBeforeAfter(x interface{}, before, after func(interface{})) {
                for i := range n {
                        walkBeforeAfter(&n[i], before, after)
                }
+       case []*ast.Ident:
+               for i := range n {
+                       walkBeforeAfter(&n[i], before, after)
+               }
        case []ast.Stmt:
                for i := range n {
                        walkBeforeAfter(&n[i], before, after)
index 047fb192fb29baa076f860952e80d88f555046fa..c1e47bd4e552985154229ca664d296de2abe782b 100644 (file)
@@ -51,16 +51,6 @@ func url(f *ast.File) bool {
                        ident.Name = "url_"
                        return
                }
-               // Find declared identifiers called url that might be confused.
-               // TODO: Why does gofix not walk the Names in a ValueSpec?
-               // TODO: Just a bug; fix later as it will have consequences.
-               if valSpec, ok := n.(*ast.ValueSpec); ok {
-                       for _, ident := range valSpec.Names {
-                               if ident.Name == "url" {
-                                       ident.Name = "url_"
-                               }
-                       }
-               }
                // Parameter and result names.
                if fn, ok := n.(*ast.FuncType); ok {
                        fixed = urlDoFields(fn.Params) || fixed