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

Chris Lattner sabre at nondot.org
Fri Mar 27 23:26:18 PDT 2009


Author: lattner
Date: Sat Mar 28 01:26:18 2009
New Revision: 67922

URL: http://llvm.org/viewvc/llvm-project?rev=67922&view=rev
Log:
Cleanups for DeclGroup.

Modified:
    cfe/trunk/include/clang/AST/DeclGroup.h
    cfe/trunk/include/clang/AST/Stmt.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=67922&r1=67921&r2=67922&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclGroup.h (original)
+++ cfe/trunk/include/clang/AST/DeclGroup.h Sat Mar 28 01:26:18 2009
@@ -58,7 +58,7 @@
     
 class DeclGroupRef {
 protected:
-  enum Kind { DeclKind=0x0, DeclGroupKind=0x1, Mask=0x1 };  
+  enum Kind { SingleDeclKind=0x0, DeclGroupKind=0x1, Mask=0x1 };  
   Decl* D;
 
   Kind getKind() const {
@@ -75,31 +75,49 @@
   typedef Decl** iterator;
   typedef Decl* const * const_iterator;
   
-  bool hasSolitaryDecl() const {
-    return getKind() == DeclKind;
+  bool isSingleDecl() const { return getKind() == SingleDeclKind; }
+  bool isDeclGroup() const { return getKind() == DeclGroupKind; }
+
+  Decl *getSingleDecl() {
+    assert(isSingleDecl() && "Isn't a declgroup");
+    return D;
+  }
+  const Decl *getSingleDecl() const {
+    return const_cast<DeclGroupRef*>(this)->getSingleDecl();
+  }
+  
+  DeclGroup &getDeclGroup() {
+    assert(isDeclGroup() && "Isn't a declgroup");
+    return *((DeclGroup*)(reinterpret_cast<uintptr_t>(D) & ~Mask));
+  }
+  const DeclGroup &getDeclGroup() const {
+    return const_cast<DeclGroupRef*>(this)->getDeclGroup();
   }
+  
 
   iterator begin() {
-    if (getKind() == DeclKind) return D ? &D : 0;
-    DeclGroup& G = *((DeclGroup*) (reinterpret_cast<uintptr_t>(D) & ~Mask));
-    return &G[0];
+    if (isSingleDecl())
+      return D ? &D : 0;
+    return &getDeclGroup()[0];
   }
 
   iterator end() {
-    if (getKind() == DeclKind) return D ? &D + 1 : 0;
-    DeclGroup& G = *((DeclGroup*) (reinterpret_cast<uintptr_t>(D) & ~Mask));
+    if (isSingleDecl())
+      return D ? &D+1 : 0;
+    DeclGroup &G = getDeclGroup();
     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];
+    if (isSingleDecl())
+      return D ? &D : 0;
+    return &getDeclGroup()[0];
   }
   
   const_iterator end() const {
-    if (getKind() == DeclKind) return D ? &D + 1 : 0;
-    DeclGroup& G = *((DeclGroup*) (reinterpret_cast<uintptr_t>(D) & ~Mask));
+    if (isSingleDecl())
+      return D ? &D+1 : 0;
+    const DeclGroup &G = getDeclGroup();
     return &G[0] + G.size();
   }
 

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

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Sat Mar 28 01:26:18 2009
@@ -235,23 +235,14 @@
   
   virtual void Destroy(ASTContext& Ctx);
 
-  // hasSolitaryDecl - This method returns true if this DeclStmt refers
-  // to a single Decl.
+  /// hasSolitaryDecl - This method returns true if this DeclStmt refers
+  /// to a single Decl.
   bool hasSolitaryDecl() const {
-    return DG.hasSolitaryDecl();
+    return DG.isSingleDecl();
   }
  
-  const Decl* getSolitaryDecl() const {
-    assert (hasSolitaryDecl() &&
-            "Caller assumes this DeclStmt points to one Decl*");
-    return *DG.begin();
-  }
-  
-  Decl* getSolitaryDecl() {
-    assert (hasSolitaryDecl() &&
-            "Caller assumes this DeclStmt points to one Decl*");
-    return *DG.begin();
-  }  
+  const Decl* getSolitaryDecl() const { return DG.getSingleDecl(); }
+  Decl *getSolitaryDecl() { return DG.getSingleDecl(); }  
 
   SourceLocation getStartLoc() const { return StartLoc; }
   SourceLocation getEndLoc() const { return EndLoc; }

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

==============================================================================
--- cfe/trunk/lib/AST/DeclGroup.cpp (original)
+++ cfe/trunk/lib/AST/DeclGroup.cpp Sat Mar 28 01:26:18 2009
@@ -17,7 +17,6 @@
 #include "llvm/Support/Allocator.h"
 #include "llvm/Bitcode/Serialize.h"
 #include "llvm/Bitcode/Deserialize.h"
-
 using namespace clang;
 
 DeclGroup* DeclGroup::Create(ASTContext& C, unsigned numdecls, Decl** decls) {
@@ -48,8 +47,8 @@
 }
   
 DeclGroup::DeclGroup(unsigned numdecls, Decl** decls) : NumDecls(numdecls) {
-  assert (numdecls > 0);
-  assert (decls);
+  assert(numdecls > 0);
+  assert(decls);
   memcpy(this+1, decls, numdecls * sizeof(*decls));
 }
 
@@ -59,14 +58,12 @@
 }
 
 void DeclGroupRef::Emit(llvm::Serializer& S) const {
-  if (getKind() == DeclKind) {
+  if (isSingleDecl()) {
     S.EmitBool(false);
     S.EmitPtr(D);
-  }
-  else {
+  } else {
     S.EmitBool(true);
-    S.EmitPtr(reinterpret_cast<DeclGroup*>(reinterpret_cast<uintptr_t>(D) 
-                                           & ~Mask));        
+    S.EmitPtr(&getDeclGroup());        
   }
 }
 





More information about the cfe-commits mailing list