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 a20cfe2..397170e 100644
--- a/Driver/ASTConsumers.cpp
+++ b/Driver/ASTConsumers.cpp
@@ -117,11 +117,10 @@
PrintObjCCompatibleAliasDecl(OID);
} else if (ObjCClassDecl *OFCD = dyn_cast<ObjCClassDecl>(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<EnumDecl>(D)) {
diff --git a/Driver/RewriteObjC.cpp b/Driver/RewriteObjC.cpp
index c6b9b43..0e9eb90 100644
--- a/Driver/RewriteObjC.cpp
+++ b/Driver/RewriteObjC.cpp
@@ -735,9 +735,6 @@
}
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 @@
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 d7abcaa..10f59bc 100644
--- a/include/clang/AST/DeclObjC.h
+++ b/include/clang/AST/DeclObjC.h
@@ -628,34 +628,26 @@
///
/// @class NSCursor, NSImage, NSPasteboard, NSWindow;
///
-/// FIXME: This could be a transparent DeclContext (!)
class ObjCClassDecl : public Decl {
- ObjCInterfaceDecl **ForwardDecls;
- unsigned NumForwardDecls;
+ ObjCList<ObjCInterfaceDecl> 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<ObjCInterfaceDecl>::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 5b59af9..b0d36db 100644
--- a/lib/AST/DeclObjC.cpp
+++ b/lib/AST/DeclObjC.cpp
@@ -115,22 +115,11 @@
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 @@
// obviating this problem. Because of this situation, referenced
// ObjCInterfaceDecls are destroyed in ~TranslationUnit.
- delete [] ForwardDecls;
- ForwardDecls = 0;
-
+ ForwardDecls.clear();
Decl::Destroy(C);
}