[cfe-dev] new design of RecursiveASTVisitor

Zhanyong Wan (λx.x x) wan at google.com
Sat Jun 5 01:30:17 PDT 2010


On Saturday, June 5, 2010, Abramo Bagnara <abramo.bagnara at gmail.com> wrote:
>>> Another very useful thing you should consider is to add a child
>>> identifier to handler arguments that inform handler about *which* parent
>>> child is currently visited: this information is not otherwise deducible.
>>
>> Sorry, I don't understand what you mean by "which parent child is
>> currently visited".  Care to clarify?
>>
>>> To better understand this try to imagine an application that want to
>>> check lhs of assign binary operator.
>
> As you've noted in your documentation it might be useful to know the
> ancestor chain of current node and for this aim it is possibile to save
> a stack of node entered, but what about to know *which* child of its
> parent current node is?
>
> This info is not available or deducible *unless* the parent visit (in

It is easily deducible.  Just search for the current node (a pointer)
in the parent's children.

> its general purpose code) pass down this information.
>
> This make possibile to node visit to answer to the following questions:
>
> "I'm the lhs or the rhs expression?", "I'm the return type of function
> decl or the full function type?",  "I'm the return type of function type
> or an argument type?", etc.

Just compare the pointer to the current node with the parent node's
lhs expression child, etc.

-- 
Zhanyong




More information about the cfe-dev mailing list