From dec17760923a23c5a185944d14d7455df6b09d86 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 28 May 2012 19:38:42 +0000 Subject: [PATCH] Address minor FIXME in RedeclLink to contain a PointerIntPair instead of derive from it. Use actual factory functions rather than derived classes acting as named constructors/factories. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157588 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Redeclarable.h | 29 ++++++++++++++--------------- lib/Serialization/ASTReaderDecl.cpp | 21 ++++++++++----------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/include/clang/AST/Redeclarable.h b/include/clang/AST/Redeclarable.h index 88abadb26a..e3b340a5a1 100644 --- a/include/clang/AST/Redeclarable.h +++ b/include/clang/AST/Redeclarable.h @@ -25,26 +25,25 @@ template class Redeclarable { protected: - // FIXME: PointerIntPair is a value class that should not be inherited from. - // This should change to using containment. - struct DeclLink : public llvm::PointerIntPair { + class DeclLink { + llvm::PointerIntPair NextAndIsPrevious; + public: DeclLink(decl_type *D, bool isLatest) - : llvm::PointerIntPair(D, isLatest) { } - - typedef llvm::PointerIntPair base_type; + : NextAndIsPrevious(D, isLatest) { } - bool NextIsPrevious() const { return base_type::getInt() == false; } - bool NextIsLatest() const { return base_type::getInt() == true; } - decl_type *getNext() const { return base_type::getPointer(); } + bool NextIsPrevious() const { return !NextAndIsPrevious.getInt(); } + bool NextIsLatest() const { return NextAndIsPrevious.getInt(); } + decl_type *getNext() const { return NextAndIsPrevious.getPointer(); } + void setNext(decl_type *D) { NextAndIsPrevious.setPointer(D); } }; - struct PreviousDeclLink : public DeclLink { - PreviousDeclLink(decl_type *D) : DeclLink(D, false) { } - }; + static DeclLink PreviousDeclLink(decl_type *D) { + return DeclLink(D, false); + } - struct LatestDeclLink : public DeclLink { - LatestDeclLink(decl_type *D) : DeclLink(D, true) { } - }; + static DeclLink LatestDeclLink(decl_type *D) { + return DeclLink(D, true); + } /// \brief Points to the next redeclaration in the chain. /// diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 5870fba36c..cfafc1c6b8 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -1534,7 +1534,7 @@ ASTDeclReader::VisitRedeclarable(Redeclarable *D) { // We temporarily set the first (canonical) declaration as the previous one // which is the one that matters and mark the real previous DeclID to be // loaded & attached later on. - D->RedeclLink = typename Redeclarable::PreviousDeclLink(FirstDecl); + D->RedeclLink = Redeclarable::PreviousDeclLink(FirstDecl); } // Note that this declaration has been deserialized. @@ -1562,8 +1562,7 @@ void ASTDeclReader::mergeRedeclarable(Redeclarable *D, // Have our redeclaration link point back at the canonical declaration // of the existing declaration, so that this declaration has the // appropriate canonical declaration. - D->RedeclLink - = typename Redeclarable::PreviousDeclLink(ExistingCanon); + D->RedeclLink = Redeclarable::PreviousDeclLink(ExistingCanon); // When we merge a namespace, update its pointer to the first namespace. if (NamespaceDecl *Namespace @@ -1805,22 +1804,22 @@ ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) { void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) { assert(D && previous); if (TagDecl *TD = dyn_cast(D)) { - TD->RedeclLink.setPointer(cast(previous)); + TD->RedeclLink.setNext(cast(previous)); } else if (FunctionDecl *FD = dyn_cast(D)) { - FD->RedeclLink.setPointer(cast(previous)); + FD->RedeclLink.setNext(cast(previous)); } else if (VarDecl *VD = dyn_cast(D)) { - VD->RedeclLink.setPointer(cast(previous)); + VD->RedeclLink.setNext(cast(previous)); } else if (TypedefNameDecl *TD = dyn_cast(D)) { - TD->RedeclLink.setPointer(cast(previous)); + TD->RedeclLink.setNext(cast(previous)); } else if (ObjCInterfaceDecl *ID = dyn_cast(D)) { - ID->RedeclLink.setPointer(cast(previous)); + ID->RedeclLink.setNext(cast(previous)); } else if (ObjCProtocolDecl *PD = dyn_cast(D)) { - PD->RedeclLink.setPointer(cast(previous)); + PD->RedeclLink.setNext(cast(previous)); } else if (NamespaceDecl *ND = dyn_cast(D)) { - ND->RedeclLink.setPointer(cast(previous)); + ND->RedeclLink.setNext(cast(previous)); } else { RedeclarableTemplateDecl *TD = cast(D); - TD->RedeclLink.setPointer(cast(previous)); + TD->RedeclLink.setNext(cast(previous)); } } -- 2.50.1