]> granicus.if.org Git - clang/commitdiff
factor a bunch of common code out of the ObjCList template class
authorChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2009 21:14:14 +0000 (21:14 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2009 21:14:14 +0000 (21:14 +0000)
into a new shared ObjCListBase class.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65164 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclObjC.h

index 49221caa815d526a3bfe926a25b5f3e3de82a47e..b03936e7f439c7e621200f557f69eb27e0347587 100644 (file)
@@ -29,50 +29,59 @@ class ObjCCategoryDecl;
 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];
   }
 };