From e881483a3bc22ffad62367501aa09ad8508fe363 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 20 Feb 2009 06:10:45 +0000 Subject: [PATCH] switch the interface ivar list from being explicitly managed to using ObjCList. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65113 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclObjC.h | 33 ++++++++++++++++++++------------- lib/AST/DeclObjC.cpp | 19 ++----------------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 2d1a13c8dd..06cd3e0bea 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -51,8 +51,15 @@ public: delete[] List; } + void clear() { + delete[] List; + NumElts = 0; + } + void set(T* 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]; NumElts = Elts; memcpy(List, InList, sizeof(T*)*Elts); @@ -367,9 +374,8 @@ class ObjCInterfaceDecl : public ObjCContainerDecl { /// Protocols referenced in interface header declaration ObjCList ReferencedProtocols; - /// Ivars/NumIvars - This is a new[]'d array of pointers to Decls. - ObjCIvarDecl **Ivars; // Null if not defined. - unsigned NumIvars; // 0 if none. + /// Instance variables in the interface. + ObjCList IVars; /// List of categories defined for this class. ObjCCategoryDecl *CategoryList; @@ -384,9 +390,7 @@ class ObjCInterfaceDecl : public ObjCContainerDecl { ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, SourceLocation CLoc, bool FD, bool isInternal); - virtual ~ObjCInterfaceDecl() { - assert(Ivars == 0 && "Destroy not called?"); - } + virtual ~ObjCInterfaceDecl() {} public: @@ -409,11 +413,11 @@ public: protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();} protocol_iterator protocol_end() const { return ReferencedProtocols.end(); } - typedef ObjCIvarDecl * const *ivar_iterator; - ivar_iterator ivar_begin() const { return Ivars; } - ivar_iterator ivar_end() const { return Ivars + ivar_size();} - unsigned ivar_size() const { return NumIvars; } - bool ivar_empty() const { return NumIvars == 0; } + typedef ObjCList::iterator ivar_iterator; + ivar_iterator ivar_begin() const { return IVars.begin(); } + ivar_iterator ivar_end() const { return IVars.end(); } + unsigned ivar_size() const { return IVars.size(); } + bool ivar_empty() const { return IVars.empty(); } /// addReferencedProtocols - Set the list of protocols that this interface /// implements. @@ -421,8 +425,11 @@ public: ReferencedProtocols.set(List, NumRPs); } - void addInstanceVariablesToClass(ObjCIvarDecl **ivars, unsigned numIvars, - SourceLocation RBracLoc); + void addInstanceVariablesToClass(ObjCIvarDecl * const* ivars, unsigned Num, + SourceLocation RBracLoc) { + IVars.set(ivars, Num); + setLocEnd(RBracLoc); + } FieldDecl *lookupFieldDeclForIvar(ASTContext &Context, const ObjCIvarDecl *ivar); diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 3417a302dc..629dcca678 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -63,7 +63,7 @@ ObjCInterfaceDecl:: ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, SourceLocation CLoc, bool FD, bool isInternal) : ObjCContainerDecl(ObjCInterface, DC, atLoc, Id), - TypeForDecl(0), SuperClass(0), Ivars(0), NumIvars(0), + TypeForDecl(0), SuperClass(0), CategoryList(0), ForwardDecl(FD), InternalInterface(isInternal), ClassLoc(CLoc) { } @@ -72,8 +72,7 @@ void ObjCInterfaceDecl::Destroy(ASTContext &C) { for (ivar_iterator I=ivar_begin(), E=ivar_end(); I!=E; ++I) if (*I) (*I)->Destroy(C); - delete [] Ivars; - Ivars = 0; + IVars.clear(); // FIXME: CategoryList? // FIXME: Because there is no clear ownership @@ -267,20 +266,6 @@ ObjCCategoryDecl * return 0; } -/// ObjCAddInstanceVariablesToClass - Inserts instance variables -/// into ObjCInterfaceDecl's fields. -/// -void ObjCInterfaceDecl::addInstanceVariablesToClass(ObjCIvarDecl **ivars, - unsigned numIvars, - SourceLocation RBrac) { - NumIvars = numIvars; - if (numIvars) { - Ivars = new ObjCIvarDecl*[numIvars]; - memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*)); - } - setLocEnd(RBrac); -} - /// lookupFieldDeclForIvar - looks up a field decl' in the laid out /// storage which matches this 'ivar'. /// -- 2.50.1