[cfe-commits] r57272 - in /cfe/trunk: include/clang/AST/DeclGroup.h lib/AST/DeclGroup.cpp

Ted Kremenek kremenek at apple.com
Tue Oct 7 16:06:02 PDT 2008


Author: kremenek
Date: Tue Oct  7 18:06:01 2008
New Revision: 57272

URL: http://llvm.org/viewvc/llvm-project?rev=57272&view=rev
Log:
Add const_iterator to DeclGroup.
Serialization for OwningDeclGroupRefs now works.

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

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclGroup.h (original)
+++ cfe/trunk/include/clang/AST/DeclGroup.h Tue Oct  7 18:06:01 2008
@@ -38,14 +38,15 @@
   void Destroy(ASTContext& C);
 
   unsigned size() const { return NumDecls; }
+
   Decl*& operator[](unsigned i) { 
     assert (i < NumDecls && "Out-of-bounds access.");
     return *((Decl**) (this+1));
   }
   
-  const Decl*& operator[](unsigned i) const { 
+  Decl* const& operator[](unsigned i) const { 
     assert (i < NumDecls && "Out-of-bounds access.");
-    return *((const Decl**) (this+1));
+    return *((Decl* const*) (this+1));
   }
   
   /// Emit - Serialize a DeclGroup to Bitcode.
@@ -72,6 +73,11 @@
     : D((Decl*) (reinterpret_cast<uintptr_t>(dg) | DeclGroupKind)) {}
   
   typedef Decl** iterator;
+  typedef Decl* const * const_iterator;
+  
+  bool hasSolitaryDecl() const {
+    return getKind() == DeclKind;
+  }
 
   iterator begin() {
     if (getKind() == DeclKind) return D ? &D : 0;
@@ -84,6 +90,18 @@
     DeclGroup& G = *((DeclGroup*) (reinterpret_cast<uintptr_t>(D) & ~Mask));
     return &G[0] + G.size();
   }
+  
+  const_iterator begin() const {
+    if (getKind() == DeclKind) return D ? &D : 0;
+    DeclGroup& G = *((DeclGroup*) (reinterpret_cast<uintptr_t>(D) & ~Mask));
+    return &G[0];
+  }
+  
+  const_iterator end() const {
+    if (getKind() == DeclKind) return D ? &D + 1 : 0;
+    DeclGroup& G = *((DeclGroup*) (reinterpret_cast<uintptr_t>(D) & ~Mask));
+    return &G[0] + G.size();
+  }
 
   /// Emit - Serialize a DeclGroupRef to Bitcode.
   void Emit(llvm::Serializer& S) const;
@@ -94,6 +112,7 @@
   
 class DeclGroupOwningRef : public DeclGroupRef {
 public:
+  explicit DeclGroupOwningRef() : DeclGroupRef((Decl*)0) {}
   explicit DeclGroupOwningRef(Decl* d) : DeclGroupRef(d) {}
   explicit DeclGroupOwningRef(DeclGroup* dg) : DeclGroupRef(dg) {}
 
@@ -113,7 +132,7 @@
   void Emit(llvm::Serializer& S) const;
   
   /// Read - Deserialize a DeclGroupOwningRef from Bitcode.
-  static DeclGroupOwningRef ReadVal(llvm::Deserializer& D, ASTContext& C);
+  DeclGroupOwningRef& Read(llvm::Deserializer& D, ASTContext& C);
 };
 
 } // end clang namespace

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

==============================================================================
--- cfe/trunk/lib/AST/DeclGroup.cpp (original)
+++ cfe/trunk/lib/AST/DeclGroup.cpp Tue Oct  7 18:06:01 2008
@@ -21,6 +21,7 @@
 using namespace clang;
 
 DeclGroup* DeclGroup::Create(ASTContext& C, unsigned numdecls, Decl** decls) {
+  assert (numdecls > 0);
   unsigned size = sizeof(DeclGroup) + sizeof(Decl*) * numdecls;
   unsigned alignment = llvm::AlignOf<DeclGroup>::Alignment;  
   void* mem = C.getAllocator().Allocate(size, alignment);
@@ -46,7 +47,7 @@
   return DG;
 }
   
-DeclGroup::DeclGroup(unsigned numdecls, Decl** decls) {
+DeclGroup::DeclGroup(unsigned numdecls, Decl** decls) : NumDecls(numdecls) {
   assert (numdecls > 0);
   assert (decls);
   memcpy(this+1, decls, numdecls * sizeof(*decls));
@@ -110,13 +111,15 @@
   }
 }
 
-DeclGroupOwningRef DeclGroupOwningRef::ReadVal(llvm::Deserializer& D,
-                                               ASTContext& C) {
-  if (D.ReadBool()) {
-    DeclGroupOwningRef DG(D.ReadOwnedPtr<Decl>(C));
-    return DG;
+DeclGroupOwningRef& DeclGroupOwningRef::Read(llvm::Deserializer& Dezr, 
+                                             ASTContext& C) {
+  
+  if (!Dezr.ReadBool())
+    D = Dezr.ReadOwnedPtr<Decl>(C);
+  else {
+    uintptr_t x = reinterpret_cast<uintptr_t>(Dezr.ReadOwnedPtr<DeclGroup>(C));
+    D = reinterpret_cast<Decl*>(x | DeclGroupKind);
   }
-
-  DeclGroupOwningRef DG(D.ReadOwnedPtr<DeclGroup>(C));
-  return DG;
+  
+  return *this;
 }





More information about the cfe-commits mailing list