[cfe-commits] r65113 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp

Chris Lattner sabre at nondot.org
Thu Feb 19 22:10:45 PST 2009


Author: lattner
Date: Fri Feb 20 00:10:45 2009
New Revision: 65113

URL: http://llvm.org/viewvc/llvm-project?rev=65113&view=rev
Log:
switch the interface ivar list from being explicitly managed to using ObjCList.

Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=65113&r1=65112&r2=65113&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Feb 20 00:10:45 2009
@@ -51,8 +51,15 @@
     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 @@
   /// 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 @@
   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 @@
   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 @@
     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);
 

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=65113&r1=65112&r2=65113&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Fri Feb 20 00:10:45 2009
@@ -63,7 +63,7 @@
 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 @@
   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 @@
     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'.
 ///





More information about the cfe-commits mailing list