[cfe-commits] r67988 - in /cfe/trunk: include/clang/AST/DeclBase.h lib/AST/DeclBase.cpp lib/AST/DeclSerialization.cpp

Chris Lattner sabre at nondot.org
Sat Mar 28 23:07:00 PDT 2009


Author: lattner
Date: Sun Mar 29 01:06:59 2009
New Revision: 67988

URL: http://llvm.org/viewvc/llvm-project?rev=67988&view=rev
Log:
switch DeclBase::DeclCtx to the new happy and type-safe
llvm::PointerUnion class.

Modified:
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/lib/AST/DeclBase.cpp
    cfe/trunk/lib/AST/DeclSerialization.cpp

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=67988&r1=67987&r2=67988&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Sun Mar 29 01:06:59 2009
@@ -19,6 +19,7 @@
 // FIXME: Layering violation
 #include "clang/Parse/AccessSpecifier.h"
 #include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/ADT/PointerUnion.h"
 
 namespace clang {
 class DeclContext;
@@ -113,6 +114,12 @@
 
   friend class DeclContext;
 
+  struct MultipleDC {
+    DeclContext *SemanticDC;
+    DeclContext *LexicalDC;
+  };
+  
+  
   /// DeclCtx - Holds either a DeclContext* or a MultipleDC*.
   /// For declarations that don't contain C++ scope specifiers, it contains
   /// the DeclContext where the Decl was declared.
@@ -126,23 +133,15 @@
   ///   }
   ///   void A::f(); // SemanticDC == namespace 'A'
   ///                // LexicalDC == global namespace
-  llvm::PointerIntPair<DeclContext*, 1, bool> DeclCtx;
+  llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx;
 
-  struct MultipleDC {
-    DeclContext *SemanticDC;
-    DeclContext *LexicalDC;
-  };
-
-  inline bool isInSemaDC() const { return DeclCtx.getInt() == 0; }
-  inline bool isOutOfSemaDC() const { return DeclCtx.getInt() != 0; }
+  inline bool isInSemaDC() const    { return DeclCtx.is<DeclContext*>(); }
+  inline bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); }
   inline MultipleDC *getMultipleDC() const {
-    assert(isOutOfSemaDC() && "Invalid accessor");
-    return reinterpret_cast<MultipleDC*>(DeclCtx.getPointer());
+    return DeclCtx.get<MultipleDC*>();
   }
-
   inline DeclContext *getSemanticDC() const {
-    assert(isInSemaDC() && "Invalid accessor");
-    return static_cast<DeclContext*>(DeclCtx.getPointer());
+    return DeclCtx.get<DeclContext*>();
   }
   
   /// Loc - The location that this decl.
@@ -178,7 +177,7 @@
 
   Decl(Kind DK, DeclContext *DC, SourceLocation L) 
     : NextDeclarator(0), NextDeclInContext(0), 
-      DeclCtx(DC, 0), 
+      DeclCtx(DC), 
       Loc(L), DeclKind(DK), InvalidDecl(0),
       HasAttrs(false), Implicit(false), 
       IdentifierNamespace(getIdentifierNamespaceForKind(DK)), Access(AS_none) {

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=67988&r1=67987&r2=67988&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Sun Mar 29 01:06:59 2009
@@ -129,8 +129,7 @@
   if (isOutOfSemaDC())
     delete getMultipleDC();
   
-  DeclCtx.setPointer(DC);
-  DeclCtx.setInt(false);
+  DeclCtx = DC;
 }
 
 void Decl::setLexicalDeclContext(DeclContext *DC) {
@@ -141,8 +140,7 @@
     MultipleDC *MDC = new MultipleDC();
     MDC->SemanticDC = getDeclContext();
     MDC->LexicalDC = DC;
-    DeclCtx.setPointer(reinterpret_cast<DeclContext*>(MDC));
-    DeclCtx.setInt(true);
+    DeclCtx = MDC;
   } else {
     getMultipleDC()->LexicalDC = DC;
   }

Modified: cfe/trunk/lib/AST/DeclSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclSerialization.cpp?rev=67988&r1=67987&r2=67988&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclSerialization.cpp (original)
+++ cfe/trunk/lib/AST/DeclSerialization.cpp Sun Mar 29 01:06:59 2009
@@ -135,12 +135,10 @@
     // *object* for back-patching. Its actual value will get filled in later.
     uintptr_t X;
     D.ReadUIntPtr(X, SemaDCPtrID); 
-    Dcl->DeclCtx.setFromOpaqueValue(reinterpret_cast<void*>(X));
-  }
-  else {
+    Dcl->DeclCtx = reinterpret_cast<DeclContext*>(X);
+  } else {
     MultipleDC *MDC = new MultipleDC();
-    Dcl->DeclCtx.setPointer(reinterpret_cast<DeclContext*>(MDC));
-    Dcl->DeclCtx.setInt(true);
+    Dcl->DeclCtx = MDC;
     // Allow back-patching.  Observe that we register the variable of the
     // *object* for back-patching. Its actual value will get filled in later.
     D.ReadPtr(MDC->SemanticDC, SemaDCPtrID);





More information about the cfe-commits mailing list