]> granicus.if.org Git - clang/commitdiff
Change ObjCForwardProtocolDecl to use an ObjCList.
authorChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2009 18:10:37 +0000 (18:10 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 20 Feb 2009 18:10:37 +0000 (18:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65131 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 397170e60d2c87e57013c768a4cc31987126d79e..f3bfc0b4345a3bfa60204023ba20f6ffcefbdb05 100644 (file)
@@ -97,10 +97,10 @@ void DeclPrinter:: PrintDecl(Decl *D) {
   } 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 = 
index 10f59bcadfefaab44a4ca339fd7482da0bde3b78..efd5242953d9d00c82a02d762d278b9698465939 100644 (file)
@@ -658,44 +658,25 @@ public:
 /// 
 /// @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;
index b0d36dbab8db6fab0af21db614f6666f00642b19..2ae7ccc8165139ed7d950fb0be0fad566f501a87 100644 (file)
@@ -137,26 +137,21 @@ void ObjCClassDecl::Destroy(ASTContext &C) {
 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,