From: Chris Lattner Date: Fri, 20 Feb 2009 21:14:14 +0000 (+0000) Subject: factor a bunch of common code out of the ObjCList template class X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=793ccfd646d0388e06c587e962a18fa723b72f02;p=clang 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 --- 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 -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 +class ObjCList : public ObjCListBase { +public: + void set(T* const* InList, unsigned Elts) { + ObjCListBase::set(reinterpret_cast(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]; } };