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

Enea Zaffanella zaffanella at cs.unipr.it
Tue Dec 7 06:39:24 PST 2010


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?

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?
Are there simpler ways to achieve the same effect?

Cheers,
Enea.



More information about the cfe-dev mailing list