[cfe-dev] Cleaning up the representation of Decls in the AST

Argiris Kirtzidis akyrtzi at gmail.com
Fri Sep 12 03:21:02 PDT 2008

Zhongxing Xu wrote:
> I agree with Ted that we should separate syntax thing from semantics 
> thing in the AST.
> struct s;
> struct s a;
> struct s { int d; } x;
> These 'struct s' have different meanings: type declaration, type 
> specifier, type definition.
> But syntactically they are all RecordDecl.

Strictly syntactically speaking, and by standard terminology, here's 
what the above constructs are:

struct s;       ->   type-specifier ';'
struct s a;    ->   type-specifier 'a' ';'
struct s { int d; } x;    ->  type-specifier 'x' ';'

Isn't it more faithful to the syntax to consider "struct s { int d; }" 
as part of the type-specifier for 'x' ?
Here's how a client may work when it receives "struct s { int d; } x;" 
and wants to pretty-print it:

-I've got a DeclGroup of one VarDecl named 'x'.
-Print its type. It's type (the type-specifier part of the syntax) is 
RecordTypeDef. Print the RecordDecl by getting it from the RecordTypeDef.
-Print "x;"

This seems more syntactically-oriented to me, why is it more confusing ?


More information about the cfe-dev mailing list