[cfe-dev] clang::Stmt, what's a child?

Eric Niebler eric at boostpro.com
Wed Feb 23 23:02:38 PST 2011

On 2/24/2011 1:09 PM, Chandler Carruth wrote:
> On Wed, Feb 23, 2011 at 9:46 PM, Eric Niebler <eric at boostpro.com
> <mailto:eric at boostpro.com>> wrote:
>     OK, this seems like a stupid question, and maybe it is. What should be
>     considered a "child" of an expression in the AST? Imagine a node that
>     holds both a rewritten tree (that will be used for code-gen purposes) as
>     well as the original AST as the user wrote it. (This is the
>     PropertyAccessOperator node as suggested by John McCall.) Clearly, the
>     rewritten node is a child. But is the original expression? What does is
>     really mean to be a child?
> I don't know about the specific case you're referring to, but in
> general, a child of an expression is some other expression of which the
> parent is composed. I think an example explains it best: "x + y" is an
> expression, the binary operator "+". It contains two child expressions,
> "x" and "y".
> I wouldn't expect the rewritten node and the original node to have any
> parent / child relationship. That relationship should be reserved for
> nodes that are part of the same tree structure. IE, what a consumer (say
> codegen) would walk to get a "complete" view of the program, whether
> that view is semantic or syntax oriented in nature.
> Look at the relationship of a template specialization's AST nodes and
> the template definition's AST nodes -- neither is the child of the
> other, but we  create a separate connection between them so we can
> navigate from a definition to all specializations and from a particular
> specialization back to the definition.

Thanks. I wasn't suggesting a parent/child relationship between the
original expression and the rewritten one. I was asking whether there
is/should be a sibling relationship between them (the parent being
PropertyAccessOperator which holds them both). They are both AST
representations of the same thing. One is more like what the user wrote,
and other other is more like what will be generated. I imagine that,
with the exception of error reporting, most AST consumers would be more
interested in the transformed AST. But some may be interested in the
other, or both.

The answer to my question depends on whether the AST mainly represents
the surface syntax of the program, or the semantics of it.

The specifics, if it helps, is that property access like:

  obj.property += value;

will be evaluated as:

  obj.set_property( obj.get_property() + value );

With my change, the AST for *both* will be stored under a new node type.
So, what should child_begin and child_end iterate over for this node
type? (My hunch is that only the rewritten node is really a child.)

Thanks in advance,

Eric Niebler
BoostPro Computing

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 551 bytes
Desc: OpenPGP digital signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110224/195e44c1/attachment.sig>

More information about the cfe-dev mailing list