]> granicus.if.org Git - clang/commitdiff
move the @implementation ivar list to being an ObjCList, which prevents
authorChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2009 20:41:34 +0000 (20:41 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2009 20:41:34 +0000 (20:41 +0000)
it from being leaked, among other things.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65150 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclObjC.h
lib/AST/DeclObjC.cpp
lib/Sema/SemaDecl.cpp

index cd80b70b2a113c95317e77ee5df4f8c3d9c7ea22..cc67431c94a963cb99795f5334848a587427ef40 100644 (file)
@@ -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<ObjCIvarDecl> IVars;
 
   /// implemented instance methods
   llvm::SmallVector<ObjCMethodDecl*, 32> 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<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(); }
   
   static bool classof(const Decl *D) {
     return D->getKind() == ObjCImplementation;
index d0b8a9731a3c402a720e2be12c9e76596074ee3c..ccf641f94d41b88ff3bc0f3000094b81962efb1e 100644 (file)
@@ -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.
index b69453d44730b77fdf189ae428aa6c04f3ae27a8..d91c2c1a19744024a809350b238b1d7b6b76781b 100644 (file)
@@ -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<ObjCImplementationDecl>(EnclosingDecl)) {
       assert(IMPDecl && "ActOnFields - missing ObjCImplementationDecl");
-      IMPDecl->ObjCAddInstanceVariablesToClassImpl(ClsFields, RecFields.size());
+      IMPDecl->setIVarList(ClsFields, RecFields.size());
       CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size(), RBrac);
     }
   }