As I mentioned the mechanisms are there to
traverse the tree anyway you want to. You should be able to do what you need
without changing current code. I assume the information you are passing up to
the parent is specific to your application so I’m not sure you can do
something like this using a general pattern such as the visitor pattern anyway.
From:
cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Yuan Zhang
Sent: Sunday, July 09, 2006 9:36
AM
To: CDT
General developers list.
Subject: Re: [cdt-dev] AST
traversal
The current
ASTNode.accept() method first visit the current node, then visit its children.
What I need is to visit Children first, collect some information from them, and
feedback to their parent. This traversal is bottom-up because leaves nodes
are visted before the root node. This can be achieved by calling,
say ASTVisitor.leave(), upon leaving the ASTNode.accept(). But I
am afraid all subclasses of ASTVisitor have to be changed. So I
am wondering whether I can implement this bottom-up traversal in some
other way without changing the current code?
On 7/8/06, Doug Schaefer <DSchaefer@xxxxxxx> wrote:
Not sure what you mean by
bottom up. Certainly you can navigate from a child node to its parent by
following the getParent links. You can also tell what property you are in the
parent by looking at getPropertyInParent. Not sure what else you would need.
I noticed that ASTNode.accept() and ASTVisitor.visit()
together provide a top-down traversal of the AST. I am wondering whether there
is a way to traverse the AST from bottom-up without modifying the current code?
I have thought to associate each node a "property", and during the
traversal change the parent node's property of the currently
visited node. However, I cannot find any appropriate place to store
this "property". Anybody can give me some hint?
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev