[cfe-dev] Recovering extent expressions

Fariborz Jahanian fjahanian at apple.com
Wed Sep 28 17:53:34 PDT 2011


On Sep 28, 2011, at 5:34 PM, Douglas Gregor wrote:

> 
> 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.

What would you do if it was not macro and a was declared as a[1*2] ? It seems you are relying on macros to get the info. that is not generally
available in clang.

- Fariborz

> 
> 	- Doug
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list