[cfe-dev] Array with size of an Enum Constant

Murat B murat8307 at yahoo.com
Mon Aug 23 10:23:00 PDT 2010


Thanks for the reply Doug!

I have following situation, I have a variable T of class Type which is the type of the array size expression.

My function progress following way.
ArrayType *AT = dyn_cast<ArrayType>(T);
if (VariableArrayType::classof(AT)
   ......................
else if (ConstantArrayType::classof(AT) {
    ConstantArrayType *CAT = cast<ConstantArrayType>(AT);
}

For the structure field the type will be ConstantArrayType. Can you tell me how I can get TypeSourceInfo from it.

Thanks,
Murat


--- On Mon, 8/23/10, Douglas Gregor <dgregor at apple.com> wrote:

From: Douglas Gregor <dgregor at apple.com>
Subject: Re: [cfe-dev] Array with size of an Enum Constant
To: "Murat B" <murat8307 at yahoo.com>
Cc: cfe-dev at cs.uiuc.edu
Date: Monday, August 23, 2010, 10:47 AM


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/51143d14/attachment.html>


More information about the cfe-dev mailing list