[cfe-dev] Source information for types

Eli Friedman eli.friedman at gmail.com
Wed Jul 8 18:42:18 PDT 2009


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.

-Eli




More information about the cfe-dev mailing list