From: Chris Lattner Date: Fri, 20 Feb 2009 18:04:31 +0000 (+0000) Subject: move the interace list of @class to use ObjCList. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=67956052ea5fb0cd7f443de96a11f9a0176dc681;p=clang move the interace list of @class to use ObjCList. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65129 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp index a20cfe23ee..397170e60d 100644 --- a/Driver/ASTConsumers.cpp +++ b/Driver/ASTConsumers.cpp @@ -117,11 +117,10 @@ void DeclPrinter:: PrintDecl(Decl *D) { PrintObjCCompatibleAliasDecl(OID); } else if (ObjCClassDecl *OFCD = dyn_cast(D)) { Out << "@class "; - ObjCInterfaceDecl **ForwardDecls = OFCD->getForwardDecls(); - for (unsigned i = 0, e = OFCD->getNumForwardDecls(); i != e; ++i) { - const ObjCInterfaceDecl *D = ForwardDecls[i]; - if (i) Out << ", "; - Out << D->getNameAsString(); + for (ObjCClassDecl::iterator I = OFCD->begin(), E = OFCD->end(); + I != E; ++I) { + if (I != OFCD->begin()) Out << ", "; + Out << (*I)->getNameAsString(); } Out << ";\n"; } else if (EnumDecl *ED = dyn_cast(D)) { diff --git a/Driver/RewriteObjC.cpp b/Driver/RewriteObjC.cpp index c6b9b43a9e..0e9eb90da7 100644 --- a/Driver/RewriteObjC.cpp +++ b/Driver/RewriteObjC.cpp @@ -735,9 +735,6 @@ void RewriteObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, } void RewriteObjC::RewriteForwardClassDecl(ObjCClassDecl *ClassDecl) { - int numDecls = ClassDecl->getNumForwardDecls(); - ObjCInterfaceDecl **ForwardDecls = ClassDecl->getForwardDecls(); - // Get the start location and compute the semi location. SourceLocation startLoc = ClassDecl->getLocation(); const char *startBuf = SM->getCharacterData(startLoc); @@ -750,8 +747,9 @@ void RewriteObjC::RewriteForwardClassDecl(ObjCClassDecl *ClassDecl) { typedefString += "// "; typedefString.append(startBuf, semiPtr-startBuf+1); typedefString += "\n"; - for (int i = 0; i < numDecls; i++) { - ObjCInterfaceDecl *ForwardDecl = ForwardDecls[i]; + for (ObjCClassDecl::iterator I = ClassDecl->begin(), E = ClassDecl->end(); + I != E; ++I) { + ObjCInterfaceDecl *ForwardDecl = *I; typedefString += "#ifndef _REWRITER_typedef_"; typedefString += ForwardDecl->getNameAsString(); typedefString += "\n"; diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index d7abcaaa62..10f59bcadf 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -628,34 +628,26 @@ public: /// /// @class NSCursor, NSImage, NSPasteboard, NSWindow; /// -/// FIXME: This could be a transparent DeclContext (!) class ObjCClassDecl : public Decl { - ObjCInterfaceDecl **ForwardDecls; - unsigned NumForwardDecls; + ObjCList ForwardDecls; ObjCClassDecl(DeclContext *DC, SourceLocation L, - ObjCInterfaceDecl **Elts, unsigned nElts); - virtual ~ObjCClassDecl() { - assert(ForwardDecls == 0 && "Destroy not called?"); + ObjCInterfaceDecl *const *Elts, unsigned nElts) + : Decl(ObjCClass, DC, L) { + ForwardDecls.set(Elts, nElts); } + virtual ~ObjCClassDecl() {} public: /// Destroy - Call destructors and release memory. virtual void Destroy(ASTContext& C); static ObjCClassDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L, - ObjCInterfaceDecl **Elts, unsigned nElts); + ObjCInterfaceDecl *const *Elts, unsigned nElts); - void setInterfaceDecl(unsigned idx, ObjCInterfaceDecl *OID) { - assert(idx < NumForwardDecls && "index out of range"); - ForwardDecls[idx] = OID; - } - ObjCInterfaceDecl** getForwardDecls() const { return ForwardDecls; } - int getNumForwardDecls() const { return NumForwardDecls; } - - typedef ObjCInterfaceDecl * const * iterator; - iterator begin() const { return ForwardDecls; } - iterator end() const { return ForwardDecls+NumForwardDecls; } + typedef ObjCList::iterator iterator; + iterator begin() const { return ForwardDecls.begin(); } + iterator end() const { return ForwardDecls.end(); } static bool classof(const Decl *D) { return D->getKind() == ObjCClass; } static bool classof(const ObjCClassDecl *D) { return true; } diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 5b59af9d95..b0d36dbab8 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -115,22 +115,11 @@ void ObjCProtocolDecl::Destroy(ASTContext &C) { ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, - ObjCInterfaceDecl **Elts, unsigned nElts) { + ObjCInterfaceDecl *const *Elts, + unsigned nElts) { return new (C) ObjCClassDecl(DC, L, Elts, nElts); } -ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L, - ObjCInterfaceDecl **Elts, unsigned nElts) - : Decl(ObjCClass, DC, L) { - if (nElts) { - ForwardDecls = new ObjCInterfaceDecl*[nElts]; - memcpy(ForwardDecls, Elts, nElts*sizeof(ObjCInterfaceDecl*)); - } else { - ForwardDecls = 0; - } - NumForwardDecls = nElts; -} - void ObjCClassDecl::Destroy(ASTContext &C) { // FIXME: There is no clear ownership policy now for referenced @@ -141,9 +130,7 @@ void ObjCClassDecl::Destroy(ASTContext &C) { // obviating this problem. Because of this situation, referenced // ObjCInterfaceDecls are destroyed in ~TranslationUnit. - delete [] ForwardDecls; - ForwardDecls = 0; - + ForwardDecls.clear(); Decl::Destroy(C); }