[cfe-commits] r65164 - /cfe/trunk/include/clang/AST/DeclObjC.h

Chris Lattner sabre at nondot.org
Fri Feb 20 13:14:14 PST 2009


Author: lattner
Date: Fri Feb 20 15:14:14 2009
New Revision: 65164

URL: http://llvm.org/viewvc/llvm-project?rev=65164&view=rev
Log:
factor a bunch of common code out of the ObjCList template class
into a new shared ObjCListBase class.

Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Feb 20 15:14:14 2009
@@ -29,50 +29,59 @@
 class ObjCPropertyDecl;
 class ObjCPropertyImplDecl;
 
-/// ObjCList - This is a simple template class used to hold various lists of
-/// decls etc, which is heavily used by the ObjC front-end.  This only use case
-/// this supports is setting the list all at once and then reading elements out
-/// of it.
-template <typename T>
-class ObjCList {
-  /// List is a new[]'d array of pointers to objects that are not owned by this
-  /// list.
-  T **List;
+class ObjCListBase {
+  void operator=(const ObjCListBase &);     // DO NOT IMPLEMENT
+  ObjCListBase(const ObjCListBase&);        // DO NOT IMPLEMENT
+protected:
+  /// List is an array of pointers to objects that are not owned by this object.
+  void **List;
   unsigned NumElts;
-  
-  void operator=(const ObjCList &); // DO NOT IMPLEMENT
-  ObjCList(const ObjCList&);        // DO NOT IMPLEMENT
+
 public:
-  ObjCList() : List(0), NumElts(0) {}
-  ~ObjCList() {
+  ObjCListBase() : List(0), NumElts(0) {}
+  ~ObjCListBase() {
     assert(List == 0 && "Destroy should have been called before dtor");
   }
-
+  
   void Destroy() {
     delete[] List;
     NumElts = 0;
     List = 0;
   }
   
-  void set(T* const* InList, unsigned Elts) {
+  unsigned size() const { return NumElts; }
+  bool empty() const { return NumElts == 0; }
+  
+protected:
+  void set(void *const* InList, unsigned Elts) {
     assert(List == 0 && "Elements already set!");
     if (Elts == 0) return;  // Setting to an empty list is a noop.
     
-    List = new T*[Elts];
+    List = new void*[Elts];
     NumElts = Elts;
-    memcpy(List, InList, sizeof(T*)*Elts);
+    memcpy(List, InList, sizeof(void*)*Elts);
   }
+};
   
-  typedef T* const * iterator;
-  iterator begin() const { return List; }
-  iterator end() const { return List+NumElts; }
   
-  unsigned size() const { return NumElts; }
-  bool empty() const { return NumElts == 0; }
+/// ObjCList - This is a simple template class used to hold various lists of
+/// decls etc, which is heavily used by the ObjC front-end.  This only use case
+/// this supports is setting the list all at once and then reading elements out
+/// of it.
+template <typename T>
+class ObjCList : public ObjCListBase {
+public:
+  void set(T* const* InList, unsigned Elts) {
+    ObjCListBase::set(reinterpret_cast<void*const*>(InList), Elts);
+  }
+  
+  typedef T* const * iterator;
+  iterator begin() const { return (iterator)List; }
+  iterator end() const { return (iterator)List+NumElts; }
   
-  T* operator[](unsigned idx) const {
-    assert(idx < NumElts && "Invalid access");
-    return List[idx];
+  T* operator[](unsigned Idx) const {
+    assert(Idx < NumElts && "Invalid access");
+    return (T*)List[Idx];
   }
 };
 





More information about the cfe-commits mailing list