[cfe-dev] Array with size of an Enum Constant
Douglas Gregor
dgregor at apple.com
Mon Aug 23 07:47:33 PDT 2010
On Aug 18, 2010, at 10:55 AM, Murat B wrote:
> Dear all,
>
> I have an enum declaration and a structure declaration of following kind:
>
> typedef enum
> {
> BITS_HEADER,
> BITS_TOTAL_MB,
> BITS_MB_MODE,
> BITS_INTER_MB,
> BITS_CBP_MB,
> BITS_COEFF_Y_MB,
> BITS_COEFF_UV_MB,
> BITS_DELTA_QUANT_MB,
> MAX_BITCOUNTER_MB
> } BitCountType;
>
> typedef struct macroblock
> {
> .......
> int bitcounter[MAX_BITCOUNTER_MB];
> .......
> } Macroblock;
>
> In my clang plugin, the type of the field bitcounter is shown as ConstantArrayType of size 8.
>
> Is there a way to determine that the size of this array is MAX_BITCOUNTER_MB and not 8, so I can make this structure dependent to the enum.
Get the TypeSourceInfo (and, then, the TypeLoc) of the field. From there, you can find the actual size expression as written in the source code. It will be a DeclRefExpr pointing to the enumerator.
- Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100823/9f53df79/attachment.html>
More information about the cfe-dev
mailing list