[Compiler-sig] AST observations
Eric C. Newton
ecn@metaslash.com
Fri, 19 Apr 2002 07:26:52 -0400
> I'm sorry this is confusing, but I think it is one of the standard
> variations on the visitor pattern.
Clearly, the class with "visit" methods is a Visitor. Now this other
thing is also called ASTVisitor, even though it delagates visitation
to a third class with visit methods.
Reminds me of java code, where the same word appears 4 times:
Thing thing = new Thing(thingy);
> "Who is responsible for traversing the object structure? A visitor
> must visit each element of the object structure. The question is, how
> does it get there? We can put the responsibility in any of three
> places: in the object structure, in the visitor, or in a separate
> iterator object."
Ok, TreeIterator works for me, too. 8-)
> It might be clearer to merge the walker and the visitor into a single
> class using inheritance. (I think the Walkabout variant described by
> Palsberg and Jay does this,
> cf. http://citeseer.nj.nec.com/palsberg97essence.html.) But I
> thought delegation would be clearer and would avoid the need for a
> magic base class that all visitors must inherit from.
The only advantage I can see for this approach is faster visitation:
the base class could have default visit methods that would know how to
iterate over the child nodes. getChildNodes() would no longer be
necessary.
-Eric