]> granicus.if.org Git - clang/commitdiff
switch the interface ivar list from being explicitly managed to using ObjCList.
authorChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2009 06:10:45 +0000 (06:10 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2009 06:10:45 +0000 (06:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65113 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 2d1a13c8dda21877be460388ecde89126ce7c96d..06cd3e0bea792f0b07b13d11dff941617620a656 100644 (file)
@@ -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);
 
index 3417a302dcb78c2a13b35c9f9e89cc470b5432eb..629dcca67828de7af0f0837f3d6f22c8117068da 100644 (file)
@@ -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'.
 ///