diff options
Diffstat (limited to 'clang/lib/AST')
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 2 | ||||
-rw-r--r-- | clang/lib/AST/Decl.cpp | 14 | ||||
-rw-r--r-- | clang/lib/AST/DeclBase.cpp | 3 | ||||
-rw-r--r-- | clang/lib/AST/DeclTemplate.cpp | 1 | ||||
-rw-r--r-- | clang/lib/AST/Type.cpp | 20 |
5 files changed, 30 insertions, 10 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 60d8b8be801..2b4bc89aace 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1307,6 +1307,8 @@ ASTContext::getClassTemplateSpecializationType(TemplateDecl *Template, unsigned NumArgs, uintptr_t *Args, bool *ArgIsType, QualType Canon) { + Canon = getCanonicalType(Canon); + llvm::FoldingSetNodeID ID; ClassTemplateSpecializationType::Profile(ID, Template, NumArgs, Args, ArgIsType); diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 2732bf93c18..ab654920238 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -374,22 +374,24 @@ OverloadedOperatorKind FunctionDecl::getOverloadedOperator() const { //===----------------------------------------------------------------------===// void TagDecl::startDefinition() { - cast<TagType>(TypeForDecl)->decl.setPointer(this); - cast<TagType>(TypeForDecl)->decl.setInt(1); + TagType *TagT = const_cast<TagType *>(TypeForDecl->getAsTagType()); + TagT->decl.setPointer(this); + TagT->getAsTagType()->decl.setInt(1); } void TagDecl::completeDefinition() { assert((!TypeForDecl || - cast<TagType>(TypeForDecl)->decl.getPointer() == this) && + TypeForDecl->getAsTagType()->decl.getPointer() == this) && "Attempt to redefine a tag definition?"); IsDefinition = true; - cast<TagType>(TypeForDecl)->decl.setPointer(this); - cast<TagType>(TypeForDecl)->decl.setInt(0); + TagType *TagT = const_cast<TagType *>(TypeForDecl->getAsTagType()); + TagT->decl.setPointer(this); + TagT->decl.setInt(0); } TagDecl* TagDecl::getDefinition(ASTContext& C) const { QualType T = C.getTypeDeclType(const_cast<TagDecl*>(this)); - TagDecl* D = cast<TagDecl>(cast<TagType>(T)->getDecl()); + TagDecl* D = cast<TagDecl>(T->getAsTagType()->getDecl()); return D->isDefinition() ? D : 0; } diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index d6a0c35d928..574de1675f4 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -446,8 +446,7 @@ DeclContext *DeclContext::getPrimaryContext() { if (DeclKind >= Decl::TagFirst && DeclKind <= Decl::TagLast) { // If this is a tag type that has a definition or is currently // being defined, that definition is our primary context. - if (TagType *TagT - = cast_or_null<TagType>(cast<TagDecl>(this)->TypeForDecl)) + if (const TagType *TagT = cast<TagDecl>(this)->TypeForDecl->getAsTagType()) if (TagT->isBeingDefined() || (TagT->getDecl() && TagT->getDecl()->isDefinition())) return TagT->getDecl(); diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 3ed4435bb37..ed4fd44e707 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -179,7 +179,6 @@ ClassTemplateSpecializationDecl::Create(ASTContext &Context, ClassTemplateSpecializationDecl *Result = new (Mem) ClassTemplateSpecializationDecl(DC, L, SpecializedTemplate, TemplateArgs, NumTemplateArgs); - // FIXME: Do we want a prettier type here? Context.getTypeDeclType(Result, PrevDecl); return Result; } diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index 210be03fa83..327e623aafd 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -331,7 +331,7 @@ bool Type::isVariablyModifiedType() const { } const RecordType *Type::getAsRecordType() const { - // If this is directly a reference type, return it. + // If this is directly a record type, return it. if (const RecordType *RTy = dyn_cast<RecordType>(this)) return RTy; @@ -348,6 +348,24 @@ const RecordType *Type::getAsRecordType() const { return getDesugaredType()->getAsRecordType(); } +const TagType *Type::getAsTagType() const { + // If this is directly a tag type, return it. + if (const TagType *TagTy = dyn_cast<TagType>(this)) + return TagTy; + + // If the canonical form of this type isn't the right kind, reject it. + if (!isa<TagType>(CanonicalType)) { + // Look through type qualifiers + if (isa<TagType>(CanonicalType.getUnqualifiedType())) + return CanonicalType.getUnqualifiedType()->getAsTagType(); + return 0; + } + + // If this is a typedef for a tag type, strip the typedef off without + // losing all typedef information. + return getDesugaredType()->getAsTagType(); +} + const RecordType *Type::getAsStructureType() const { // If this is directly a structure type, return it. if (const RecordType *RT = dyn_cast<RecordType>(this)) { |