]> granicus.if.org Git - clang/commitdiff
Modified DeclGroupRef to always load/store the internal pointer value as Decl*. ...
authorTed Kremenek <kremenek@apple.com>
Mon, 6 Oct 2008 22:17:16 +0000 (22:17 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 6 Oct 2008 22:17:16 +0000 (22:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57213 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclGroup.h
lib/AST/DeclGroup.cpp

index 4ad2dfcd22583d57336efc0817172da7e7d86465..4818fc219a1ffd2aa2f27c68c08173ce1c7cc5f9 100644 (file)
@@ -42,31 +42,35 @@ public:
   }
 };
   
+    
 class DeclGroupRef {
 protected:
-  enum Kind { DeclKind=0x0, DeclGroupKind=0x1, Mask=0x1 };
-  union { Decl* D; uintptr_t Raw; };
-  Kind getKind() const { return (Kind) (Raw & Mask); }  
+  enum Kind { DeclKind=0x0, DeclGroupKind=0x1, Mask=0x1 };  
+  Decl* D;
+
+  Kind getKind() const {
+    return (Kind) (reinterpret_cast<uintptr_t>(D) & Mask);
+  }  
   
 public:    
-  DeclGroupRef() : Raw(0) {}
+  DeclGroupRef() : D(0) {}
   
   explicit DeclGroupRef(Decl* d) : D(d) {}
   explicit DeclGroupRef(DeclGroup* dg)
-    : Raw(reinterpret_cast<uintptr_t>(dg) | DeclGroupKind) {}
+    : D((Decl*) (reinterpret_cast<uintptr_t>(D) | DeclGroupKind)) {}
   
   typedef Decl** iterator;
 
   iterator begin() {
-    if (getKind() == DeclKind) return Raw ? &D : 0;
-    DeclGroup* G = reinterpret_cast<DeclGroup*>(Raw & ~Mask);
-    return &(*G)[0];
+    if (getKind() == DeclKind) return D ? &D : 0;
+    DeclGroup& G = *((DeclGroup*) (reinterpret_cast<uintptr_t>(D) & ~Mask));
+    return &G[0];
   }
 
   iterator end() {
-    if (getKind() == DeclKind) return Raw ? &D + 1 : 0;    
-    DeclGroup* G = reinterpret_cast<DeclGroup*>(Raw & ~Mask);
-    return &(*G)[0] + G->size();
+    if (getKind() == DeclKind) return D ? &D + 1 : 0;
+    DeclGroup& G = *((DeclGroup*) (reinterpret_cast<uintptr_t>(D) & ~Mask));
+    return &G[0] + G.size();
   }  
 };
   
@@ -76,11 +80,11 @@ public:
   void Destroy(ASTContext& C);
   
   explicit DeclGroupOwningRef(DeclGroupOwningRef& R)
-    : DeclGroupRef(R) { R.Raw = 0; }
+    : DeclGroupRef(R) { R.D = 0; }
 
   DeclGroupOwningRef& operator=(DeclGroupOwningRef& R) {
-    Raw = R.Raw;
-    R.Raw = 0;
+    D = R.D;
+    R.D = 0;
     return *this;
   }
 };
index 6ec0e5beafa4cfd7abe8853c85617490547d3f4d..34b37dada5c71e12088f58bd053800faa50d1cc8 100644 (file)
@@ -43,17 +43,18 @@ void DeclGroup::Destroy(ASTContext& C) {
 }
 
 DeclGroupOwningRef::~DeclGroupOwningRef() {
-  assert (Raw == 0 && "Destroy method not called.");
+  assert (D == 0 && "Destroy method not called.");
 }
 
 void DeclGroupOwningRef::Destroy(ASTContext& C) {
-  if (!Raw)
+  if (!D)
     return;
   
   if (getKind() == DeclKind)
-    reinterpret_cast<Decl*>(Raw)->Destroy(C);
-  else
-    reinterpret_cast<DeclGroup*>(Raw & ~Mask)->Destroy(C);
+    D->Destroy(C);
+  else    
+    reinterpret_cast<DeclGroup*>(reinterpret_cast<uintptr_t>(D) &
+                                 ~Mask)->Destroy(C);
   
-  Raw = 0;
+  D = 0;
 }