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)) {
}
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);
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";
///
/// @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; }
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
// obviating this problem. Because of this situation, referenced
// ObjCInterfaceDecls are destroyed in ~TranslationUnit.
- delete [] ForwardDecls;
- ForwardDecls = 0;
-
+ ForwardDecls.clear();
Decl::Destroy(C);
}