[cfe-commits] r83116 - in /cfe/trunk: include/clang/AST/Type.h include/clang/Analysis/PathSensitive/MemRegion.h lib/AST/Type.cpp lib/Analysis/RegionStore.cpp lib/Sema/Sema.cpp lib/Sema/SemaDeclCXX.cpp
Douglas Gregor
dgregor at apple.com
Wed Sep 30 09:09:59 PDT 2009
On Sep 29, 2009, at 5:25 PM, John McCall wrote:
> Douglas Gregor wrote:
>>> + /// getUnqualifiedDesugaredType() - Return the specified type
>>> with
>>> + /// any "sugar" removed from the type, removing any typedefs,
>>> + /// typeofs, etc., as well as any qualifiers.
>>> + const Type *getUnqualifiedDesugaredType() const;
>> [snip]
>>> +/// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic
>>> +/// sugar off the given type. This should produce an object of the
>>> +/// same dynamic type as the canonical type.
>>> +const Type *Type::getUnqualifiedDesugaredType() const {
>>> + const Type *Cur = this;
>>> +
>>> + while (true) {
>>> + switch (Cur->getTypeClass()) {
>>> +#define ABSTRACT_TYPE(Class, Parent)
>>> +#define TYPE(Class, Parent) \
>>> + case Class: { \
>>> + const Class##Type *Ty = cast<Class##Type>(Cur); \
>>> + if (!Ty->isSugared()) return Cur; \
>>> + Cur = Ty->desugar().getTypePtr(); \
>>> + break; \
>>> + }
>>> +#include "clang/AST/TypeNodes.def"
>>> + }
>>> + }
>>> }
>>
>> I think it's just a minor documentation issue, but this routine won't
>> remove *all* qualifiers. For example, I expect that, given
>>
>> typedef const int CInt1;
>> typedef CInt1 CInt2;
>> typedef CInt2 CInt3;
>>
>> desugaring "CInt3" will get us CInt2, which still points to a
>> const-qualified type. That's the right behavior IMO, but I think the
>> comment for getUnqualifedDesugaredType should make that clear.
>
> getUnqualifiedDesugaredType() is a multi-step desugar --- witness the
> loop --- and will indeed get us down to 'int'. The postcondition is
> that the returned type should never be sugared and hence should
> exactly
> match the (outermost) type of the canonical type, which is what makes
> the cast in getAs<> sound.
Ah, I see it now. Thanks for setting me straight.
- Doug
More information about the cfe-commits
mailing list