[cfe-commits] r157588 - in /cfe/trunk: include/clang/AST/Redeclarable.h lib/Serialization/ASTReaderDecl.cpp

David Blaikie dblaikie at gmail.com
Mon May 28 12:38:42 PDT 2012


Author: dblaikie
Date: Mon May 28 14:38:42 2012
New Revision: 157588

URL: http://llvm.org/viewvc/llvm-project?rev=157588&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/AST/Redeclarable.h
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp

Modified: cfe/trunk/include/clang/AST/Redeclarable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Redeclarable.h?rev=157588&r1=157587&r2=157588&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Redeclarable.h (original)
+++ cfe/trunk/include/clang/AST/Redeclarable.h Mon May 28 14:38:42 2012
@@ -25,26 +25,25 @@
 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<decl_type *, 1, bool> {
+  class DeclLink {
+    llvm::PointerIntPair<decl_type *, 1, bool> NextAndIsPrevious;
+  public:
     DeclLink(decl_type *D, bool isLatest)
-      : llvm::PointerIntPair<decl_type *, 1, bool>(D, isLatest) { }
-
-    typedef llvm::PointerIntPair<decl_type *, 1, bool> 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.
   ///

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=157588&r1=157587&r2=157588&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Mon May 28 14:38:42 2012
@@ -1534,7 +1534,7 @@
     // 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<T>::PreviousDeclLink(FirstDecl);
+    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl);
   }    
   
   // Note that this declaration has been deserialized.
@@ -1562,8 +1562,7 @@
         // 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<T>::PreviousDeclLink(ExistingCanon);
+        D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon);
         
         // When we merge a namespace, update its pointer to the first namespace.
         if (NamespaceDecl *Namespace
@@ -1805,22 +1804,22 @@
 void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) {
   assert(D && previous);
   if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
-    TD->RedeclLink.setPointer(cast<TagDecl>(previous));
+    TD->RedeclLink.setNext(cast<TagDecl>(previous));
   } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
-    FD->RedeclLink.setPointer(cast<FunctionDecl>(previous));
+    FD->RedeclLink.setNext(cast<FunctionDecl>(previous));
   } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
-    VD->RedeclLink.setPointer(cast<VarDecl>(previous));
+    VD->RedeclLink.setNext(cast<VarDecl>(previous));
   } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
-    TD->RedeclLink.setPointer(cast<TypedefNameDecl>(previous));
+    TD->RedeclLink.setNext(cast<TypedefNameDecl>(previous));
   } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
-    ID->RedeclLink.setPointer(cast<ObjCInterfaceDecl>(previous));
+    ID->RedeclLink.setNext(cast<ObjCInterfaceDecl>(previous));
   } else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) {
-    PD->RedeclLink.setPointer(cast<ObjCProtocolDecl>(previous));
+    PD->RedeclLink.setNext(cast<ObjCProtocolDecl>(previous));
   } else if (NamespaceDecl *ND = dyn_cast<NamespaceDecl>(D)) {
-    ND->RedeclLink.setPointer(cast<NamespaceDecl>(previous));
+    ND->RedeclLink.setNext(cast<NamespaceDecl>(previous));
   } else {
     RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D);
-    TD->RedeclLink.setPointer(cast<RedeclarableTemplateDecl>(previous));
+    TD->RedeclLink.setNext(cast<RedeclarableTemplateDecl>(previous));
   }
 }
 





More information about the cfe-commits mailing list