aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-20 21:14:14 +0000
committerChris Lattner <sabre@nondot.org>2009-02-20 21:14:14 +0000
commit793ccfd646d0388e06c587e962a18fa723b72f02 (patch)
tree1cb67d55f2a2fc344b572cc255fe66cdf41ae1b7
parentdf9692988591229edfa1d7eeaeaf744ff95acded (diff)
factor a bunch of common code out of the ObjCList template class
into a new shared ObjCListBase class. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65164 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/DeclObjC.h61
1 files changed, 35 insertions, 26 deletions
diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h
index 49221caa81..b03936e7f4 100644
--- a/include/clang/AST/DeclObjC.h
+++ b/include/clang/AST/DeclObjC.h
@@ -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];
}
};