diff options
| -rw-r--r-- | clang/include/clang/AST/DeclObjC.h | 33 | ||||
| -rw-r--r-- | clang/lib/AST/DeclObjC.cpp | 19 |
2 files changed, 22 insertions, 30 deletions
diff --git a/clang/include/clang/AST/DeclObjC.h b/clang/include/clang/AST/DeclObjC.h index 2d1a13c8dda..06cd3e0bea7 100644 --- a/clang/include/clang/AST/DeclObjC.h +++ b/clang/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<ObjCProtocolDecl> 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<ObjCIvarDecl> 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<ObjCIvarDecl>::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/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index 3417a302dcb..629dcca6782 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/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'. /// |

