[cfe-dev] Recovering extent expressions

Douglas Gregor dgregor at apple.com
Wed Sep 28 17:34:57 PDT 2011


On Sep 28, 2011, at 5:22 PM, Timothy McClory wrote:

> Consider the program:
> 
> #define m 1
> #define n 2
> 
> int a[m*n];
> int main() {
>    return a[0];
> }
> 
> How can I determine whether or not an array extent is an expression of macro constants, and how can I retrieve this expression?
> During AST traversal, I encounter a VarDecl whose type is ConstantArrayType, but the size of this type has already been reduced to single integer. 

Look at the TypeSourceInfo of the VarDecl. It contains (through the use of TypeLoc) the expression describing the array. At that point, you'll see that the location of the integer literals is a macro instantiation, and can use the source manager to trace it back. It's not trivial, but it's doable.

	- Doug




More information about the cfe-dev mailing list