From: Chris Lattner Date: Fri, 20 Feb 2009 20:41:34 +0000 (+0000) Subject: move the @implementation ivar list to being an ObjCList, which prevents X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7a21bd046fe57629ab074980cf8193f5e0c15735;p=clang move the @implementation ivar list to being an ObjCList, which prevents it from being leaked, among other things. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65150 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index cd80b70b2a..cc67431c94 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -861,9 +861,8 @@ class ObjCImplementationDecl : public Decl, public DeclContext { /// Implementation Class's super class. ObjCInterfaceDecl *SuperClass; - /// Optional Ivars/NumIvars - This is a new[]'d array of pointers to Decls. - ObjCIvarDecl **Ivars; // Null if not specified - unsigned NumIvars; // 0 if none. + /// Instance variables declared in the @implementation. + ObjCList IVars; /// implemented instance methods llvm::SmallVector InstanceMethods; @@ -880,18 +879,20 @@ class ObjCImplementationDecl : public Decl, public DeclContext { ObjCInterfaceDecl *classInterface, ObjCInterfaceDecl *superDecl) : Decl(ObjCImplementation, DC, L), DeclContext(ObjCImplementation), - ClassInterface(classInterface), SuperClass(superDecl), - Ivars(0), NumIvars(0) {} + ClassInterface(classInterface), SuperClass(superDecl){} public: static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L, ObjCInterfaceDecl *classInterface, ObjCInterfaceDecl *superDecl); + /// Destroy - Call destructors and release memory. + virtual void Destroy(ASTContext& C); + + void setIVarList(ObjCIvarDecl *const *InArray, unsigned Num) { + IVars.set(InArray, Num); + } - void ObjCAddInstanceVariablesToClassImpl(ObjCIvarDecl **ivars, - unsigned numIvars); - void addInstanceMethod(ObjCMethodDecl *method) { InstanceMethods.push_back(method); } @@ -963,11 +964,11 @@ public: return isInstance ? getInstanceMethod(Sel) : getClassMethod(Sel); } - typedef ObjCIvarDecl * const *ivar_iterator; - ivar_iterator ivar_begin() const { return Ivars; } - ivar_iterator ivar_end() const { return Ivars+NumIvars; } - 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(); } static bool classof(const Decl *D) { return D->getKind() == ObjCImplementation; diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index d0b8a9731a..ccf641f94d 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -175,6 +175,12 @@ ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, return new (C) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl); } +/// Destroy - Call destructors and release memory. +void ObjCImplementationDecl::Destroy(ASTContext& C) { + IVars.clear(); +} + + ObjCCompatibleAliasDecl * ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, @@ -250,18 +256,6 @@ FieldDecl *ObjCInterfaceDecl::lookupFieldDeclForIvar(ASTContext &Context, return MemberDecl; } -/// ObjCAddInstanceVariablesToClassImpl - Checks for correctness of Instance -/// Variables (Ivars) relative to what declared in @implementation;s class. -/// Ivars into ObjCImplementationDecl's fields. -/// -void ObjCImplementationDecl::ObjCAddInstanceVariablesToClassImpl( - ObjCIvarDecl **ivars, unsigned numIvars) { - NumIvars = numIvars; - if (numIvars) { - Ivars = new ObjCIvarDecl*[numIvars]; - memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*)); - } -} // Get the local instance method declared in this interface. // FIXME: handle overloading, instance & class methods can have the same name. diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index b69453d447..d91c2c1a19 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3458,13 +3458,10 @@ Sema::DeclTy *Sema::ActOnField(Scope *S, DeclTy *TagD, } - // FIXME: Chain fielddecls together. - FieldDecl *NewFD; - - NewFD = FieldDecl::Create(Context, Record, - Loc, II, T, BitWidth, - D.getDeclSpec().getStorageClassSpec() == - DeclSpec::SCS_mutable); + FieldDecl *NewFD = FieldDecl::Create(Context, Record, + Loc, II, T, BitWidth, + D.getDeclSpec().getStorageClassSpec() == + DeclSpec::SCS_mutable); if (II) { NamedDecl *PrevDecl = LookupName(S, II, LookupMemberName, true); @@ -3710,7 +3707,7 @@ void Sema::ActOnFields(Scope* S, else if (ObjCImplementationDecl *IMPDecl = dyn_cast(EnclosingDecl)) { assert(IMPDecl && "ActOnFields - missing ObjCImplementationDecl"); - IMPDecl->ObjCAddInstanceVariablesToClassImpl(ClsFields, RecFields.size()); + IMPDecl->setIVarList(ClsFields, RecFields.size()); CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size(), RBrac); } }