[cfe-dev] Understanding Clang parsing

Charles Davis cdavis at mymail.mines.edu
Wed Mar 3 20:44:36 PST 2010


On 3/3/10 9:15 PM, kalyan ponnala wrote:
> Hi again,
> 
> Could you tell me what's a Qualtype in detail. How does it save space
> for representing different types ?
A QualType holds a pointer to a Type object as well as qualifiers such
as 'const', 'volatile', and 'restrict'. This way, we don't have to have
separate Type objects for 'int', 'const int', 'volatile int', 'const
volatile int', etc.

Some of the qualifiers are stored in the lower bits of the pointer
itself (on the assumption that it is always 8-byte aligned). Other
qualifiers have to be stored elsewhere. The ones that are stored in the
pointer are called 'fast' qualifiers, and the others are called 'slow'
qualifiers.

You can get the underlying Type pointer by calling getTypePtr(), and you
can read all the qualifiers by getting a Qualifiers object from the
QualType with getQualifiers(). You can read only the ones that don't
come from typedefs with the getLocalQualifiers() method, and you can
query particular qualifiers with the isXxxQualified() and
isLocalXxxQualified() methods.

The definition of the QualType class is in include/clang/AST/Type.h.
Take a look.

Chip



More information about the cfe-dev mailing list