From b21ef91f7dd7602b74ce96b2be6d38853f04e749 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 23 Apr 2014 18:20:42 +0000 Subject: [PATCH] Make TypeDecl much less friendly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207007 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Decl.h | 5 ----- lib/AST/Decl.cpp | 4 ++-- lib/AST/DeclBase.cpp | 15 +++++++-------- lib/AST/DeclTemplate.cpp | 8 ++++---- lib/Serialization/ASTReader.cpp | 2 +- 5 files changed, 14 insertions(+), 20 deletions(-) diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 526187e31b..1ad8a90c4f 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -2374,11 +2374,6 @@ class TypeDecl : public NamedDecl { /// LocStart - The start of the source range for this declaration. SourceLocation LocStart; friend class ASTContext; - friend class DeclContext; - friend class TagDecl; - friend class TemplateTypeParmDecl; - friend class TagType; - friend class ASTReader; protected: TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index dd7b0c8194..f3a4ff33b9 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -3202,8 +3202,8 @@ TagDecl *TagDecl::getCanonicalDecl() { return getFirstDecl(); } void TagDecl::setTypedefNameForAnonDecl(TypedefNameDecl *TDD) { NamedDeclOrQualifier = TDD; - if (TypeForDecl) - assert(TypeForDecl->isLinkageValid()); + if (const Type *T = getTypeForDecl()) + assert(T->isLinkageValid()); assert(isLinkageValid()); } diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index c12f53c676..f15639130a 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -900,18 +900,17 @@ DeclContext *DeclContext::getPrimaryContext() { // If this is a tag type that has a definition or is currently // being defined, that definition is our primary context. TagDecl *Tag = cast(this); - assert(isa(Tag->TypeForDecl) || - isa(Tag->TypeForDecl)); if (TagDecl *Def = Tag->getDefinition()) return Def; - if (!isa(Tag->TypeForDecl)) { - const TagType *TagTy = cast(Tag->TypeForDecl); - if (TagTy->isBeingDefined()) - // FIXME: is it necessarily being defined in the decl - // that owns the type? - return TagTy->getDecl(); + if (const TagType *TagTy = dyn_cast(Tag->getTypeForDecl())) { + // Note, TagType::getDecl returns the (partial) definition one exists. + TagDecl *PossiblePartialDef = TagTy->getDecl(); + if (PossiblePartialDef->isBeingDefined()) + return PossiblePartialDef; + } else { + assert(isa(Tag->getTypeForDecl())); } return Tag; diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp index fc73e6f412..408e8548b1 100644 --- a/lib/AST/DeclTemplate.cpp +++ b/lib/AST/DeclTemplate.cpp @@ -472,7 +472,7 @@ TemplateTypeParmDecl::Create(const ASTContext &C, DeclContext *DC, TemplateTypeParmDecl *TTPDecl = new (C, DC) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename); QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl); - TTPDecl->TypeForDecl = TTPType.getTypePtr(); + TTPDecl->setTypeForDecl(TTPType.getTypePtr()); return TTPDecl; } @@ -497,15 +497,15 @@ SourceRange TemplateTypeParmDecl::getSourceRange() const { } unsigned TemplateTypeParmDecl::getDepth() const { - return TypeForDecl->getAs()->getDepth(); + return getTypeForDecl()->getAs()->getDepth(); } unsigned TemplateTypeParmDecl::getIndex() const { - return TypeForDecl->getAs()->getIndex(); + return getTypeForDecl()->getAs()->getIndex(); } bool TemplateTypeParmDecl::isParameterPack() const { - return TypeForDecl->getAs()->isParameterPack(); + return getTypeForDecl()->getAs()->isParameterPack(); } //===----------------------------------------------------------------------===// diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 14075462be..44e98f94c8 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -8019,7 +8019,7 @@ void ASTReader::finishPendingActions() { DEnd = PendingDefinitions.end(); D != DEnd; ++D) { if (TagDecl *TD = dyn_cast(*D)) { - if (const TagType *TagT = dyn_cast(TD->TypeForDecl)) { + if (const TagType *TagT = dyn_cast(TD->getTypeForDecl())) { // Make sure that the TagType points at the definition. const_cast(TagT)->decl = TD; } -- 2.40.0