Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(68)

Issue 166047: code review 166047: the AST walker currently provides no way to find out how the (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
16 years, 6 months ago by rog
Modified:
16 years, 6 months ago
Reviewers:
gri
CC:
rsc
Visibility:
Public.

Description

the AST walker currently provides no way to find out how the nodes in the tree are nested with respect to one another. a simple change to the Visitor interface makes it possible to do this (for example to maintain a current node-depth, or a knowledge of the name of the current function). Visit(nil) is called at the end of a node's children; this make possible the channel-based interface below, amongst other possibilities. It is still just as simple to get the original behaviour - just return the same Visitor from Visit. Here are a couple of possible Visitor types. // closure-based type FVisitor func(n interface{}) FVisitor func (f FVisitor) Visit(n interface{}) Visitor { return f(n); } // channel-based type CVisitor chan Visit; type Visit struct { node interface{}; reply chan CVisitor; }; func (v CVisitor) Visit(n interface{}) Visitor { if n == nil { close(v); } else { reply := make(chan CVisitor); v <- Visit{n, reply}; r := <-reply; if r == nil { return nil; } return r; } return nil; }

Patch Set 1 #

Patch Set 2 : code review 166047: the AST walker currently provides no way to find out how the #

Patch Set 3 : code review 166047: the AST walker currently provides no way to find out how the #

Patch Set 4 : code review 166047: the AST walker currently provides no way to find out how the #

Total comments: 7

Patch Set 5 : code review 166047: the AST walker currently provides no way to find out how the #

Patch Set 6 : code review 166047: the AST walker currently provides no way to find out how the #

Patch Set 7 : code review 166047: the AST walker currently provides no way to find out how the #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+61 lines, -57 lines) Patch
M src/cmd/godoc/index.go View 1 2 3 4 2 chunks +6 lines, -3 lines 0 comments Download
M src/pkg/go/ast/walk.go View 1 2 3 4 5 6 14 chunks +55 lines, -54 lines 1 comment Download

Messages

Total messages: 8
rog
Hello r, rsc (cc: rog), I'd like you to review the following change.
16 years, 6 months ago (2009-12-03 23:23:01 UTC) #1
r
16 years, 6 months ago (2009-12-03 23:26:30 UTC) #2
rog
one other thing: i changed Walk so that it's possible to call it directly on ...
16 years, 6 months ago (2009-12-03 23:27:17 UTC) #3
gri
Good idea. Some comments below. http://codereview.appspot.com/166047/diff/1012/1013 File src/cmd/godoc/index.go (right): http://codereview.appspot.com/166047/diff/1012/1013#newcode512 src/cmd/godoc/index.go:512: if node == nil ...
16 years, 6 months ago (2009-12-04 22:25:56 UTC) #4
rog
done (with one additional comment indicating that arrays are allowed in Walk).
16 years, 6 months ago (2009-12-07 10:48:17 UTC) #5
gri
LGTM. Thanks. I'll fix the typos. http://codereview.appspot.com/166047/diff/2007/1021 File src/pkg/go/ast/walk.go (right): http://codereview.appspot.com/166047/diff/2007/1021#newcode45 src/pkg/go/ast/walk.go:45: // on of ...
16 years, 6 months ago (2009-12-07 18:17:35 UTC) #6
gri
*** Submitted as http://code.google.com/p/go/source/detail?r=4d6d9a144130 *** the AST walker currently provides no way to find out ...
16 years, 6 months ago (2009-12-07 18:33:49 UTC) #7
rog
16 years, 6 months ago (2009-12-07 20:01:37 UTC) #8
On 2009/12/07 18:33:49, gri wrote:
> // closure-based
> type FVisitor func(n interface{}) FVisitor
> func (f FVisitor) Visit(n interface{}) Visitor {
> 	return f(n);
> }

just noticed, this isn't submitted code (although
it came from some of my code), but this has the standard
typed-nil-becomes-non-nil-interface bug.

it should be something like:

func (f FVisitor) Visit(n interface{}) Visitor {
	if f := f(n); f != nil {
		return f;
	}
	return nil;
}
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b