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

Chris Lattner sabre at nondot.org
Fri Feb 20 10:10:37 PST 2009


Author: lattner
Date: Fri Feb 20 12:10:37 2009
New Revision: 65131

URL: http://llvm.org/viewvc/llvm-project?rev=65131&view=rev
Log:
Change ObjCForwardProtocolDecl to use an ObjCList.

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

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=65131&r1=65130&r2=65131&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Fri Feb 20 12:10:37 2009
@@ -97,10 +97,10 @@
   } else if (ObjCForwardProtocolDecl *OFPD = 
              dyn_cast<ObjCForwardProtocolDecl>(D)) {
     Out << "@protocol ";
-    for (unsigned i = 0, e = OFPD->getNumForwardDecls(); i != e; ++i) {
-      const ObjCProtocolDecl *D = OFPD->getForwardProtocolDecl(i);
-      if (i) Out << ", ";
-      Out << D->getNameAsString();
+    for (ObjCForwardProtocolDecl::iterator I = OFPD->begin(), E = OFPD->end();
+         I != E; ++I) {
+      if (I != OFPD->begin()) Out << ", ";
+      Out << (*I)->getNameAsString();
     }
     Out << ";\n";
   } else if (ObjCImplementationDecl *OID = 

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Feb 20 12:10:37 2009
@@ -658,44 +658,25 @@
 /// 
 /// @protocol NSTextInput, NSChangeSpelling, NSDraggingInfo;
 /// 
-/// FIXME: Should this be a transparent DeclContext?
 class ObjCForwardProtocolDecl : public Decl {
-  ObjCProtocolDecl **ReferencedProtocols;
-  unsigned NumReferencedProtocols;
+  ObjCList<ObjCProtocolDecl> ReferencedProtocols;
   
   ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
-                          ObjCProtocolDecl **Elts, unsigned nElts);  
-  virtual ~ObjCForwardProtocolDecl() {
-    assert(ReferencedProtocols == 0 && "Destroy not called?");
-  }
+                          ObjCProtocolDecl *const *Elts, unsigned nElts);  
+  virtual ~ObjCForwardProtocolDecl() {}
   
 public:
   static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC,
                                          SourceLocation L, 
-                                         ObjCProtocolDecl **Elts, unsigned Num);
+                                         ObjCProtocolDecl *const *Elts,
+                                         unsigned Num);
 
   /// Destroy - Call destructors and release memory.
   virtual void Destroy(ASTContext& C);
-
-  void setForwardProtocolDecl(unsigned idx, ObjCProtocolDecl *OID) {
-    assert(idx < NumReferencedProtocols && "index out of range");
-    ReferencedProtocols[idx] = OID;
-  }
-  
-  unsigned getNumForwardDecls() const { return NumReferencedProtocols; }
-  
-  ObjCProtocolDecl *getForwardProtocolDecl(unsigned idx) {
-    assert(idx < NumReferencedProtocols && "index out of range");
-    return ReferencedProtocols[idx];
-  }
-  const ObjCProtocolDecl *getForwardProtocolDecl(unsigned idx) const {
-    assert(idx < NumReferencedProtocols && "index out of range");
-    return ReferencedProtocols[idx];
-  }
   
-  typedef ObjCProtocolDecl * const * iterator;
-  iterator begin() const { return ReferencedProtocols; }
-  iterator end() const { return ReferencedProtocols+NumReferencedProtocols; }
+  typedef ObjCList<ObjCProtocolDecl>::iterator iterator;
+  iterator begin() const { return ReferencedProtocols.begin(); }
+  iterator end() const { return ReferencedProtocols.end(); }
   
   static bool classof(const Decl *D) {
     return D->getKind() == ObjCForwardProtocol;

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

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Fri Feb 20 12:10:37 2009
@@ -137,26 +137,21 @@
 ObjCForwardProtocolDecl *
 ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC,
                                 SourceLocation L, 
-                                ObjCProtocolDecl **Elts, unsigned NumElts) {
+                                ObjCProtocolDecl *const *Elts,
+                                unsigned NumElts) {
   return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts);
 }
 
 ObjCForwardProtocolDecl::
 ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
-                        ObjCProtocolDecl **Elts, unsigned nElts)
+                        ObjCProtocolDecl *const *Elts, unsigned nElts)
   : Decl(ObjCForwardProtocol, DC, L) { 
-  NumReferencedProtocols = nElts;
-  if (nElts) {
-    ReferencedProtocols = new ObjCProtocolDecl*[nElts];
-    memcpy(ReferencedProtocols, Elts, nElts*sizeof(ObjCProtocolDecl*));
-  } else {
-    ReferencedProtocols = 0;
-  }
+  ReferencedProtocols.set(Elts, nElts);
 }
 
 void ObjCForwardProtocolDecl::Destroy(ASTContext &C) {
-  delete [] ReferencedProtocols;
-  ReferencedProtocols = 0;
+  ReferencedProtocols.clear();
+  Decl::Destroy(C);
 }
 
 ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,





More information about the cfe-commits mailing list