diff options
author | John McCall <rjmccall@apple.com> | 2010-12-10 11:01:00 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-12-10 11:01:00 +0000 |
commit | 49f4e1cbd839da27ff4814b4ea6d85a79f786cbd (patch) | |
tree | 9ab7a1af57b1fc26ad1d0b8913ac7da554101ff3 /lib/AST/Type.cpp | |
parent | 55270e4bde91bd30d16086ae71f0f65caf3b8a51 (diff) |
It's kindof silly that ExtQuals has an ASTContext&, and we can use that
space better. Remove this reference. To make that work, change some APIs
(most importantly, getDesugaredType()) to take an ASTContext& if they
need to return a QualType. Simultaneously, diminish the need to return a
QualType by introducing some useful APIs on SplitQualType, which is
just a std::pair<const Type *, Qualifiers>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121478 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Type.cpp')
-rw-r--r-- | lib/AST/Type.cpp | 45 |
1 files changed, 11 insertions, 34 deletions
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 489f766d04..705b097212 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -145,7 +145,12 @@ QualType QualType::getUnqualifiedTypeSlow() const { /// to getting the canonical type, but it doesn't remove *all* typedefs. For /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is /// concrete. -QualType QualType::getDesugaredType(QualType T) { +QualType QualType::getDesugaredType(QualType T, ASTContext &Context) { + SplitQualType split = getSplitDesugaredType(T); + return Context.getQualifiedType(split.first, split.second); +} + +SplitQualType QualType::getSplitDesugaredType(QualType T) { QualifierCollector Qs; QualType Cur = T; @@ -157,7 +162,7 @@ QualType QualType::getDesugaredType(QualType T) { case Type::Class: { \ const Class##Type *Ty = cast<Class##Type>(CurTy); \ if (!Ty->isSugared()) \ - return Qs.apply(Cur); \ + return SplitQualType(Ty, Qs); \ Cur = Ty->desugar(); \ break; \ } @@ -1089,32 +1094,6 @@ void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID) { getExtInfo()); } -/// LookThroughTypedefs - Return the ultimate type this typedef corresponds to -/// potentially looking through *all* consequtive typedefs. This returns the -/// sum of the type qualifiers, so if you have: -/// typedef const int A; -/// typedef volatile A B; -/// looking through the typedefs for B will give you "const volatile A". -/// -QualType TypedefType::LookThroughTypedefs() const { - // Usually, there is only a single level of typedefs, be fast in that case. - QualType FirstType = getDecl()->getUnderlyingType(); - if (!isa<TypedefType>(FirstType)) - return FirstType; - - // Otherwise, do the fully general loop. - QualifierCollector Qs; - - QualType CurType; - const TypedefType *TDT = this; - do { - CurType = TDT->getDecl()->getUnderlyingType(); - TDT = dyn_cast<TypedefType>(Qs.strip(CurType)); - } while (TDT); - - return Qs.apply(CurType); -} - QualType TypedefType::desugar() const { return getDecl()->getUnderlyingType(); } @@ -1280,20 +1259,18 @@ TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, Args[Idx].Profile(ID, Context); } -QualType QualifierCollector::apply(QualType QT) const { +QualType QualifierCollector::apply(ASTContext &Context, QualType QT) const { if (!hasNonFastQualifiers()) return QT.withFastQualifiers(getFastQualifiers()); - assert(Context && "extended qualifiers but no context!"); - return Context->getQualifiedType(QT, *this); + return Context.getQualifiedType(QT, *this); } -QualType QualifierCollector::apply(const Type *T) const { +QualType QualifierCollector::apply(ASTContext &Context, const Type *T) const { if (!hasNonFastQualifiers()) return QualType(T, getFastQualifiers()); - assert(Context && "extended qualifiers but no context!"); - return Context->getQualifiedType(T, *this); + return Context.getQualifiedType(T, *this); } void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID, |