[cfe-dev] Cleaning up the representation of Decls in the AST
Ted Kremenek
kremenek at apple.com
Fri Sep 12 08:59:25 PDT 2008
Hi Argiris,
I think part of this dialogue stems from our different perspective of
the ASTs. In my mind, the ASTs should be designed to (1) faithfully
represent the program and (2) make it easy for clients of the ASTs to
understand their structure and purpose. I'm personally not married to
creating a one-to-one mapping between the terminology used in the C99
standard to describe grammar and syntax and the ASTs themselves. I
*do* think, however, that faithfully following this terminology is
important in the parser and its actions, but not the ASTs.
On Sep 12, 2008, at 4:01 AM, Argiris Kirtzidis wrote:
> To sum up my point here, it is more syntactically accurate to
> consider RecordDecl a part of type-specifier.
> In the syntax it's the type-specifier of a syntactic construct that
> tells us whether it's "struct s" or "struct s { int d; }".
The DeclGroup proposal (which I want to add that I'm not married to)
handles this case. RecordDecls indicate with a bit whether or not
they are a forward declaration or a definition.
Note that the DeclGroup proposal can directly represent the following
beast with complete fidelity:
struct { int x; } a, *b, **c;
The DeclGroup would point to the RecordDecl for the anonymous
structure, as well as point the the three VarDecls for a, b, and c
respectively. The VarDecls would still have QualTypes that refer to
the appropriate types.
>
> If we are not getting this kind of information, the type-specifier
> is not represented correctly in the AST.
>
> -Argiris
One of the other design points of the ASTs is that we represent
directly represent the information that most clients need, for the
remaining 10% of the information that we don't directly represent we
rely on being able to lazily recreate them, either by relexing or
other means. The problem with the current representation of
declarations in the ASTs is that we lose critical source information
as well as a clear idea of where types are defined, etc. That's the
motivation of DeclGroup (as well as your type-specifier proposal).
Ted
More information about the cfe-dev
mailing list