mirror of
https://github.com/golang/go
synced 2024-11-20 09:44:45 -07:00
- gofmt-ify walk.go
- fixed several bugs R=rsc http://go/go-review/1015015
This commit is contained in:
parent
5a75ac88c9
commit
ae3c9992ae
@ -69,17 +69,27 @@ func walkBlockStmt(v Visitor, b *BlockStmt) {
|
||||
// Walk visits each of the children of n.
|
||||
//
|
||||
func Walk(v Visitor, node interface{}) {
|
||||
if node != nil && !v.Visit(node) {
|
||||
if node == nil || !v.Visit(node) {
|
||||
return;
|
||||
}
|
||||
|
||||
// walk children
|
||||
// (the order of the cases matches the order
|
||||
// of the corresponding declaration in ast.go)
|
||||
switch n := node.(type) {
|
||||
// Comments and fields
|
||||
case *Comment:
|
||||
// nothing to do
|
||||
|
||||
case *CommentGroup:
|
||||
for _, c := range n.List {
|
||||
Walk(v, c);
|
||||
}
|
||||
// TODO(gri): Keep comments in a list/vector instead
|
||||
// of linking them via Next. Following next will lead
|
||||
// to multiple visits and potentially n^2 behavior
|
||||
// since Doc and Comments fields point into the global
|
||||
// comments list.
|
||||
|
||||
case *Field:
|
||||
walkCommentGroup(v, n.Doc);
|
||||
@ -91,13 +101,18 @@ func Walk(v Visitor, node interface{}) {
|
||||
walkCommentGroup(v, n.Comment);
|
||||
|
||||
// Expressions
|
||||
case *BadExpr, *Ident, *Ellipsis, *BasicLit:
|
||||
// nothing to do
|
||||
|
||||
case *StringList:
|
||||
for _, x := range n.Strings {
|
||||
Walk(v, x);
|
||||
}
|
||||
|
||||
case *FuncLit:
|
||||
if n != nil {
|
||||
Walk(v, n.Type);
|
||||
}
|
||||
walkBlockStmt(v, n.Body);
|
||||
|
||||
case *CompositeLit:
|
||||
@ -109,9 +124,7 @@ func Walk(v Visitor, node interface{}) {
|
||||
|
||||
case *SelectorExpr:
|
||||
Walk(v, n.X);
|
||||
if n.Sel != nil {
|
||||
Walk(v, n.Sel);
|
||||
}
|
||||
walkIdent(v, n.Sel);
|
||||
|
||||
case *IndexExpr:
|
||||
Walk(v, n.X);
|
||||
@ -163,9 +176,15 @@ func Walk(v Visitor, node interface{}) {
|
||||
Walk(v, n.Value);
|
||||
|
||||
// Statements
|
||||
case *BadStmt:
|
||||
// nothing to do
|
||||
|
||||
case *DeclStmt:
|
||||
Walk(v, n.Decl);
|
||||
|
||||
case *EmptyStmt:
|
||||
// nothing to do
|
||||
|
||||
case *LabeledStmt:
|
||||
walkIdent(v, n.Label);
|
||||
Walk(v, n.Stmt);
|
||||
@ -252,7 +271,6 @@ func Walk(v Visitor, node interface{}) {
|
||||
}
|
||||
walkCommentGroup(v, n.Comment);
|
||||
|
||||
|
||||
case *ValueSpec:
|
||||
walkCommentGroup(v, n.Doc);
|
||||
walkIdentList(v, n.Names);
|
||||
@ -266,6 +284,9 @@ func Walk(v Visitor, node interface{}) {
|
||||
Walk(v, n.Type);
|
||||
walkCommentGroup(v, n.Comment);
|
||||
|
||||
case *BadDecl:
|
||||
// nothing to do
|
||||
|
||||
case *GenDecl:
|
||||
walkCommentGroup(v, n.Doc);
|
||||
for _, s := range n.Specs {
|
||||
@ -278,7 +299,9 @@ func Walk(v Visitor, node interface{}) {
|
||||
Walk(v, n.Recv);
|
||||
}
|
||||
walkIdent(v, n.Name);
|
||||
if n.Type != nil {
|
||||
Walk(v, n.Type);
|
||||
}
|
||||
walkBlockStmt(v, n.Body);
|
||||
|
||||
// Files and packages
|
||||
|
Loading…
Reference in New Issue
Block a user