[cfe-dev] AST representation for parentheses inside types.

Douglas Gregor dgregor at apple.com
Tue Dec 7 09:36:32 PST 2010


On Dec 7, 2010, at 6:39 AM, Enea Zaffanella wrote:

> Hello.
> 
> We noticed some time ago that the AST representation used in clang does
> not allow for the representation of those pairs of parentheses that can
> occur inside a syntactic type. For instance, the following C code:
> 
> void ((((*fun_ptr))))(void);
> int (*(int_arr_ptr))[15];
> void (((*((*fun_ptr_arr_ptr)[10]))))(int, int);
> int ((a));
> 
> is printed (using -ast-print) as follows
> 
> void (*fun_ptr)(void);
> int (*int_arr_ptr)[15];
> void (*(*fun_ptr_arr_ptr)[10])(int, int);
> int a;
> 
> The printed parentheses are not directly represented in the AST: they
> are inserted by the pretty printer (to respect precedence).
> 
> Are there plans to extend the AST in order to faithfully represent the
> code above?

Not that I know of.

> To our eyes, it seems that the Type hierarchy should be enriched by
> adding a ParenType derived class (similar to the ParenExpr class for the
> Expr hierarchy). A ParenType would always be a non-canonical type and
> the corresponding ParenTypeLoc would provide locations for the two
> parentheses. At the parser level, we would have another kind of
> DeclaratorChunk.
> 
> Would this approach make sense?

Yes, this approach makes sense to me.

	- Doug




More information about the cfe-dev mailing list