Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
ae3c9992
Commit
ae3c9992
authored
Oct 27, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- gofmt-ify walk.go
- fixed several bugs R=rsc
http://go/go-review/1015015
parent
5a75ac88
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
44 deletions
+67
-44
walk.go
src/pkg/go/ast/walk.go
+67
-44
No files found.
src/pkg/go/ast/walk.go
View file @
ae3c9992
...
...
@@ -69,18 +69,28 @@ 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
);
walkIdentList
(
v
,
n
.
Names
);
...
...
@@ -91,51 +101,54 @@ 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
:
Walk
(
v
,
n
.
Type
);
if
n
!=
nil
{
Walk
(
v
,
n
.
Type
);
}
walkBlockStmt
(
v
,
n
.
Body
);
case
*
CompositeLit
:
Walk
(
v
,
n
.
Type
);
walkExprList
(
v
,
n
.
Elts
);
case
*
ParenExpr
:
Walk
(
v
,
n
.
X
);
case
*
SelectorExpr
:
Walk
(
v
,
n
.
X
);
if
n
.
Sel
!=
nil
{
Walk
(
v
,
n
.
Sel
);
}
walkIdent
(
v
,
n
.
Sel
);
case
*
IndexExpr
:
Walk
(
v
,
n
.
X
);
Walk
(
v
,
n
.
Index
);
Walk
(
v
,
n
.
End
);
case
*
TypeAssertExpr
:
Walk
(
v
,
n
.
X
);
Walk
(
v
,
n
.
Type
);
case
*
CallExpr
:
Walk
(
v
,
n
.
Fun
);
walkExprList
(
v
,
n
.
Args
);
case
*
StarExpr
:
Walk
(
v
,
n
.
X
);
case
*
UnaryExpr
:
Walk
(
v
,
n
.
X
);
case
*
BinaryExpr
:
Walk
(
v
,
n
.
X
);
Walk
(
v
,
n
.
Y
);
case
*
KeyValueExpr
:
Walk
(
v
,
n
.
Key
);
Walk
(
v
,
n
.
Value
);
...
...
@@ -144,76 +157,82 @@ func Walk(v Visitor, node interface{}) {
case
*
ArrayType
:
Walk
(
v
,
n
.
Len
);
Walk
(
v
,
n
.
Elt
);
case
*
StructType
:
walkFieldList
(
v
,
n
.
Fields
);
case
*
FuncType
:
walkFieldList
(
v
,
n
.
Params
);
walkFieldList
(
v
,
n
.
Results
);
case
*
InterfaceType
:
walkFieldList
(
v
,
n
.
Methods
);
case
*
MapType
:
Walk
(
v
,
n
.
Key
);
Walk
(
v
,
n
.
Value
);
case
*
ChanType
:
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
);
case
*
ExprStmt
:
Walk
(
v
,
n
.
X
);
case
*
IncDecStmt
:
Walk
(
v
,
n
.
X
);
case
*
AssignStmt
:
walkExprList
(
v
,
n
.
Lhs
);
walkExprList
(
v
,
n
.
Rhs
);
case
*
GoStmt
:
if
n
.
Call
!=
nil
{
Walk
(
v
,
n
.
Call
);
}
case
*
DeferStmt
:
if
n
.
Call
!=
nil
{
Walk
(
v
,
n
.
Call
);
}
case
*
ReturnStmt
:
walkExprList
(
v
,
n
.
Results
);
case
*
BranchStmt
:
walkIdent
(
v
,
n
.
Label
);
case
*
BlockStmt
:
walkStmtList
(
v
,
n
.
List
);
case
*
IfStmt
:
Walk
(
v
,
n
.
Init
);
Walk
(
v
,
n
.
Cond
);
walkBlockStmt
(
v
,
n
.
Body
);
Walk
(
v
,
n
.
Else
);
case
*
CaseClause
:
walkExprList
(
v
,
n
.
Values
);
walkStmtList
(
v
,
n
.
Body
);
case
*
SwitchStmt
:
Walk
(
v
,
n
.
Init
);
Walk
(
v
,
n
.
Tag
);
walkBlockStmt
(
v
,
n
.
Body
);
case
*
TypeCaseClause
:
walkExprList
(
v
,
n
.
Types
);
walkStmtList
(
v
,
n
.
Body
);
...
...
@@ -222,12 +241,12 @@ func Walk(v Visitor, node interface{}) {
Walk
(
v
,
n
.
Init
);
Walk
(
v
,
n
.
Assign
);
walkBlockStmt
(
v
,
n
.
Body
);
case
*
CommClause
:
Walk
(
v
,
n
.
Lhs
);
Walk
(
v
,
n
.
Rhs
);
walkStmtList
(
v
,
n
.
Body
);
case
*
SelectStmt
:
walkBlockStmt
(
v
,
n
.
Body
);
...
...
@@ -236,13 +255,13 @@ func Walk(v Visitor, node interface{}) {
Walk
(
v
,
n
.
Cond
);
Walk
(
v
,
n
.
Post
);
walkBlockStmt
(
v
,
n
.
Body
);
case
*
RangeStmt
:
Walk
(
v
,
n
.
Key
);
Walk
(
v
,
n
.
Value
);
Walk
(
v
,
n
.
X
);
walkBlockStmt
(
v
,
n
.
Body
);
// Declarations
case
*
ImportSpec
:
walkCommentGroup
(
v
,
n
.
Doc
);
...
...
@@ -251,34 +270,38 @@ func Walk(v Visitor, node interface{}) {
Walk
(
v
,
x
);
}
walkCommentGroup
(
v
,
n
.
Comment
);
case
*
ValueSpec
:
walkCommentGroup
(
v
,
n
.
Doc
);
walkIdentList
(
v
,
n
.
Names
);
Walk
(
v
,
n
.
Type
);
walkExprList
(
v
,
n
.
Values
);
walkCommentGroup
(
v
,
n
.
Comment
);
case
*
TypeSpec
:
walkCommentGroup
(
v
,
n
.
Doc
);
walkIdent
(
v
,
n
.
Name
);
Walk
(
v
,
n
.
Type
);
walkCommentGroup
(
v
,
n
.
Comment
);
case
*
BadDecl
:
// nothing to do
case
*
GenDecl
:
walkCommentGroup
(
v
,
n
.
Doc
);
for
_
,
s
:=
range
n
.
Specs
{
Walk
(
v
,
s
);
}
case
*
FuncDecl
:
walkCommentGroup
(
v
,
n
.
Doc
);
if
n
.
Recv
!=
nil
{
Walk
(
v
,
n
.
Recv
);
}
walkIdent
(
v
,
n
.
Name
);
Walk
(
v
,
n
.
Type
);
if
n
.
Type
!=
nil
{
Walk
(
v
,
n
.
Type
);
}
walkBlockStmt
(
v
,
n
.
Body
);
// Files and packages
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment