Index: include/clang/AST/Redeclarable.h =================================================================== --- include/clang/AST/Redeclarable.h +++ include/clang/AST/Redeclarable.h @@ -36,7 +36,7 @@ // DeclLink that may point to one of 3 possible states: // - the "previous" (temporal) element in the chain // - the "latest" (temporal) element in the chain -// - the an "uninitialized-latest" value (when newly-constructed) +// - the "uninitialized-latest" value (when newly-constructed) // // - The first element is also often called the canonical element. Every // element has a pointer to it so that "getCanonical" can be fast. @@ -48,10 +48,8 @@ // "most-recent" when referring to temporal order: order of addition // to the chain. // -// - To make matters confusing, the DeclLink type uses the term "next" -// for its pointer-storage internally (thus functions like -// NextIsPrevious). It's easiest to just ignore the implementation of -// DeclLink when making sense of the redeclaration chain. +// - It's easiest to just ignore the implementation of DeclLink when making +// sense of the redeclaration chain. // // - There's also a "definition" link for several types of // redeclarable, where only one definition should exist at any given @@ -105,66 +103,64 @@ /// previous declaration. using NotKnownLatest = llvm::PointerUnion; - mutable llvm::PointerUnion Next; + mutable llvm::PointerUnion Link; public: enum PreviousTag { PreviousLink }; enum LatestTag { LatestLink }; DeclLink(LatestTag, const ASTContext &Ctx) - : Next(NotKnownLatest(reinterpret_cast(&Ctx))) {} - DeclLink(PreviousTag, decl_type *D) : Next(NotKnownLatest(Previous(D))) {} + : Link(NotKnownLatest(reinterpret_cast(&Ctx))) {} + DeclLink(PreviousTag, decl_type *D) : Link(NotKnownLatest(Previous(D))) {} - bool NextIsPrevious() const { - return Next.is() && + bool isFirst() const { + return Link.is() || // FIXME: 'template' is required on the next line due to an // apparent clang bug. - Next.get().template is(); + Link.get().template is(); } - bool NextIsLatest() const { return !NextIsPrevious(); } - - decl_type *getNext(const decl_type *D) const { - if (Next.is()) { - NotKnownLatest NKL = Next.get(); + decl_type *getPrevious(const decl_type *D) const { + if (Link.is()) { + NotKnownLatest NKL = Link.get(); if (NKL.is()) return static_cast(NKL.get()); // Allocate the generational 'most recent' cache now, if needed. - Next = KnownLatest(*reinterpret_cast( + Link = KnownLatest(*reinterpret_cast( NKL.get()), const_cast(D)); } - return static_cast(Next.get().get(D)); + return static_cast(Link.get().get(D)); } void setPrevious(decl_type *D) { - assert(NextIsPrevious() && "decl became non-canonical unexpectedly"); - Next = Previous(D); + assert(!isFirst() && "decl became non-canonical unexpectedly"); + Link = Previous(D); } void setLatest(decl_type *D) { - assert(NextIsLatest() && "decl became canonical unexpectedly"); - if (Next.is()) { - NotKnownLatest NKL = Next.get(); - Next = KnownLatest(*reinterpret_cast( + assert(isFirst() && "decl became canonical unexpectedly"); + if (Link.is()) { + NotKnownLatest NKL = Link.get(); + Link = KnownLatest(*reinterpret_cast( NKL.get()), D); } else { - auto Latest = Next.get(); + auto Latest = Link.get(); Latest.set(D); - Next = Latest; + Link = Latest; } } - void markIncomplete() { Next.get().markIncomplete(); } + void markIncomplete() { Link.get().markIncomplete(); } Decl *getLatestNotUpdated() const { - assert(NextIsLatest() && "expected a canonical decl"); - if (Next.is()) + assert(isFirst() && "expected a canonical decl"); + if (Link.is()) return nullptr; - return Next.get().getNotUpdated(); + return Link.get().getNotUpdated(); } }; @@ -178,8 +174,8 @@ /// Points to the next redeclaration in the chain. /// - /// If NextIsPrevious() is true, this is a link to the previous declaration - /// of this same Decl. If NextIsLatest() is true, this is the first + /// If isFirst() is false, this is a link to the previous declaration + /// of this same Decl. If isFirst() is true, this is the first /// declaration and Link points to the latest declaration. For example: /// /// #1 int f(int x, int y = 1); // @@ -192,7 +188,7 @@ decl_type *First; decl_type *getNextRedeclaration() const { - return RedeclLink.getNext(static_cast(this)); + return RedeclLink.getPrevious(static_cast(this)); } public: @@ -206,7 +202,7 @@ /// Return the previous declaration of this declaration or NULL if this /// is the first declaration. decl_type *getPreviousDecl() { - if (RedeclLink.NextIsPrevious()) + if (!RedeclLink.isFirst()) return getNextRedeclaration(); return nullptr; } @@ -224,7 +220,7 @@ const decl_type *getFirstDecl() const { return First; } /// True if this is the first declaration in its redeclaration chain. - bool isFirstDecl() const { return RedeclLink.NextIsLatest(); } + bool isFirstDecl() const { return RedeclLink.isFirst(); } /// Returns the most recent (re)declaration of this declaration. decl_type *getMostRecentDecl() {