r336605 - [AST] Rename some Redeclarable functions to reduce confusion

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 9 14:31:20 PDT 2018


Author: maskray
Date: Mon Jul  9 14:31:20 2018
New Revision: 336605

URL: http://llvm.org/viewvc/llvm-project?rev=336605&view=rev
Log:
[AST] Rename some Redeclarable functions to reduce confusion

Reviewers: rsmith, akyrtzi

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D48894

Modified:
    cfe/trunk/include/clang/AST/Redeclarable.h

Modified: cfe/trunk/include/clang/AST/Redeclarable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Redeclarable.h?rev=336605&r1=336604&r2=336605&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Redeclarable.h (original)
+++ cfe/trunk/include/clang/AST/Redeclarable.h Mon Jul  9 14:31:20 2018
@@ -36,7 +36,7 @@ class Decl;
 //    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 @@ class Decl;
 //    "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 @@ protected:
     /// previous declaration.
     using NotKnownLatest = llvm::PointerUnion<Previous, UninitializedLatest>;
 
-    mutable llvm::PointerUnion<NotKnownLatest, KnownLatest> Next;
+    mutable llvm::PointerUnion<NotKnownLatest, KnownLatest> Link;
 
   public:
     enum PreviousTag { PreviousLink };
     enum LatestTag { LatestLink };
 
     DeclLink(LatestTag, const ASTContext &Ctx)
-        : Next(NotKnownLatest(reinterpret_cast<UninitializedLatest>(&Ctx))) {}
-    DeclLink(PreviousTag, decl_type *D) : Next(NotKnownLatest(Previous(D))) {}
+        : Link(NotKnownLatest(reinterpret_cast<UninitializedLatest>(&Ctx))) {}
+    DeclLink(PreviousTag, decl_type *D) : Link(NotKnownLatest(Previous(D))) {}
 
-    bool NextIsPrevious() const {
-      return Next.is<NotKnownLatest>() &&
+    bool isFirst() const {
+      return Link.is<KnownLatest>() ||
              // FIXME: 'template' is required on the next line due to an
              // apparent clang bug.
-             Next.get<NotKnownLatest>().template is<Previous>();
+             Link.get<NotKnownLatest>().template is<UninitializedLatest>();
     }
 
-    bool NextIsLatest() const { return !NextIsPrevious(); }
-
-    decl_type *getNext(const decl_type *D) const {
-      if (Next.is<NotKnownLatest>()) {
-        NotKnownLatest NKL = Next.get<NotKnownLatest>();
+    decl_type *getPrevious(const decl_type *D) const {
+      if (Link.is<NotKnownLatest>()) {
+        NotKnownLatest NKL = Link.get<NotKnownLatest>();
         if (NKL.is<Previous>())
           return static_cast<decl_type*>(NKL.get<Previous>());
 
         // Allocate the generational 'most recent' cache now, if needed.
-        Next = KnownLatest(*reinterpret_cast<const ASTContext *>(
+        Link = KnownLatest(*reinterpret_cast<const ASTContext *>(
                                NKL.get<UninitializedLatest>()),
                            const_cast<decl_type *>(D));
       }
 
-      return static_cast<decl_type*>(Next.get<KnownLatest>().get(D));
+      return static_cast<decl_type*>(Link.get<KnownLatest>().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>()) {
-        NotKnownLatest NKL = Next.get<NotKnownLatest>();
-        Next = KnownLatest(*reinterpret_cast<const ASTContext *>(
+      assert(isFirst() && "decl became canonical unexpectedly");
+      if (Link.is<NotKnownLatest>()) {
+        NotKnownLatest NKL = Link.get<NotKnownLatest>();
+        Link = KnownLatest(*reinterpret_cast<const ASTContext *>(
                                NKL.get<UninitializedLatest>()),
                            D);
       } else {
-        auto Latest = Next.get<KnownLatest>();
+        auto Latest = Link.get<KnownLatest>();
         Latest.set(D);
-        Next = Latest;
+        Link = Latest;
       }
     }
 
-    void markIncomplete() { Next.get<KnownLatest>().markIncomplete(); }
+    void markIncomplete() { Link.get<KnownLatest>().markIncomplete(); }
 
     Decl *getLatestNotUpdated() const {
-      assert(NextIsLatest() && "expected a canonical decl");
-      if (Next.is<NotKnownLatest>())
+      assert(isFirst() && "expected a canonical decl");
+      if (Link.is<NotKnownLatest>())
         return nullptr;
-      return Next.get<KnownLatest>().getNotUpdated();
+      return Link.get<KnownLatest>().getNotUpdated();
     }
   };
 
@@ -178,8 +174,8 @@ protected:
 
   /// 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); // <pointer to #3, true>
@@ -192,7 +188,7 @@ protected:
   decl_type *First;
 
   decl_type *getNextRedeclaration() const {
-    return RedeclLink.getNext(static_cast<const decl_type *>(this));
+    return RedeclLink.getPrevious(static_cast<const decl_type *>(this));
   }
 
 public:
@@ -206,7 +202,7 @@ public:
   /// 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 @@ public:
   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() {




More information about the cfe-commits mailing list