[cfe-dev] Source information for types

Argyrios Kyrtzidis kyrtzidis at apple.com
Wed Jul 8 18:56:14 PDT 2009


On Jul 8, 2009, at 6:42 PM, Eli Friedman wrote:

> On Wed, Jul 8, 2009 at 6:11 PM, Argyrios  
> Kyrtzidis<kyrtzidis at apple.com> wrote:
>> Yes exactly; but note that whether a TypeSpecifier wraps a 'plain'  
>> QualType
>> or a QualType containing a SourceType can be varied and checked using
>> TypeSpecifier::isSourceType().
>> This is basically what the TypeSpecifier would look like:
>> class TypeSpecifier {
>>   QualType Ty;
>>
>> public:
>>   explicit TypeSpecifier(QualType type) : Ty(type) { }
>>   TypeSpecifier(SourceType *sourceTy) : Ty(QualType(sourceTy, 0)) { }
>>   QualType getType() const {
>>     if (SourceType *ST = dyn_cast_or_null<SourceType>(Ty.getTypePtr 
>> ()))
>>       return ST->getBaseType();
>>     return Ty;
>>   }
>>
>>   bool isSourceType() const {
>>     return dyn_cast_or_null<SourceType>(Ty.getTypePtr()) != 0;
>>   }
>>   SourceType *getSourceType() const { return cast<SourceType>(Ty); }
>> };
>
> Ah, so SourceType inherits from Type?  That feels slightly nasty, but
> it works, I guess.

Yes, it will be a Type subclass that the type system should not deal  
with and should not be aware of (e.g. CodeGen will never come across a  
SourceType).
The benefit is that the size of Decls remain the same (no need to add  
a pointer to a "type source info" object).

-Argiris



More information about the cfe-dev mailing list