Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
ae3c9992
Commit
ae3c9992
authored
Oct 26, 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
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
44 deletions
+67
-44
src/pkg/go/ast/walk.go
src/pkg/go/ast/walk.go
+67
-44
No files found.
src/pkg/go/ast/walk.go
View file @
ae3c9992
...
...
@@ -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
...
...
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