Change ObjCForwardProtocolDecl to use an ObjCList.

llvm-svn: 65131
This commit is contained in:
Chris Lattner 2009-02-20 18:10:37 +00:00
parent cdbb5e336d
commit ed89b3ff2f
3 changed files with 18 additions and 42 deletions

View File

@ -97,10 +97,10 @@ void DeclPrinter:: PrintDecl(Decl *D) {
} else if (ObjCForwardProtocolDecl *OFPD = } else if (ObjCForwardProtocolDecl *OFPD =
dyn_cast<ObjCForwardProtocolDecl>(D)) { dyn_cast<ObjCForwardProtocolDecl>(D)) {
Out << "@protocol "; Out << "@protocol ";
for (unsigned i = 0, e = OFPD->getNumForwardDecls(); i != e; ++i) { for (ObjCForwardProtocolDecl::iterator I = OFPD->begin(), E = OFPD->end();
const ObjCProtocolDecl *D = OFPD->getForwardProtocolDecl(i); I != E; ++I) {
if (i) Out << ", "; if (I != OFPD->begin()) Out << ", ";
Out << D->getNameAsString(); Out << (*I)->getNameAsString();
} }
Out << ";\n"; Out << ";\n";
} else if (ObjCImplementationDecl *OID = } else if (ObjCImplementationDecl *OID =

View File

@ -658,44 +658,25 @@ public:
/// ///
/// @protocol NSTextInput, NSChangeSpelling, NSDraggingInfo; /// @protocol NSTextInput, NSChangeSpelling, NSDraggingInfo;
/// ///
/// FIXME: Should this be a transparent DeclContext?
class ObjCForwardProtocolDecl : public Decl { class ObjCForwardProtocolDecl : public Decl {
ObjCProtocolDecl **ReferencedProtocols; ObjCList<ObjCProtocolDecl> ReferencedProtocols;
unsigned NumReferencedProtocols;
ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L, ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
ObjCProtocolDecl **Elts, unsigned nElts); ObjCProtocolDecl *const *Elts, unsigned nElts);
virtual ~ObjCForwardProtocolDecl() { virtual ~ObjCForwardProtocolDecl() {}
assert(ReferencedProtocols == 0 && "Destroy not called?");
}
public: public:
static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC, static ObjCForwardProtocolDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L, SourceLocation L,
ObjCProtocolDecl **Elts, unsigned Num); ObjCProtocolDecl *const *Elts,
unsigned Num);
/// Destroy - Call destructors and release memory. /// Destroy - Call destructors and release memory.
virtual void Destroy(ASTContext& C); virtual void Destroy(ASTContext& C);
void setForwardProtocolDecl(unsigned idx, ObjCProtocolDecl *OID) { typedef ObjCList<ObjCProtocolDecl>::iterator iterator;
assert(idx < NumReferencedProtocols && "index out of range"); iterator begin() const { return ReferencedProtocols.begin(); }
ReferencedProtocols[idx] = OID; iterator end() const { return ReferencedProtocols.end(); }
}
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; }
static bool classof(const Decl *D) { static bool classof(const Decl *D) {
return D->getKind() == ObjCForwardProtocol; return D->getKind() == ObjCForwardProtocol;

View File

@ -137,26 +137,21 @@ void ObjCClassDecl::Destroy(ASTContext &C) {
ObjCForwardProtocolDecl * ObjCForwardProtocolDecl *
ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC, ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation L, SourceLocation L,
ObjCProtocolDecl **Elts, unsigned NumElts) { ObjCProtocolDecl *const *Elts,
unsigned NumElts) {
return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts); return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts);
} }
ObjCForwardProtocolDecl:: ObjCForwardProtocolDecl::
ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L, ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
ObjCProtocolDecl **Elts, unsigned nElts) ObjCProtocolDecl *const *Elts, unsigned nElts)
: Decl(ObjCForwardProtocol, DC, L) { : Decl(ObjCForwardProtocol, DC, L) {
NumReferencedProtocols = nElts; ReferencedProtocols.set(Elts, nElts);
if (nElts) {
ReferencedProtocols = new ObjCProtocolDecl*[nElts];
memcpy(ReferencedProtocols, Elts, nElts*sizeof(ObjCProtocolDecl*));
} else {
ReferencedProtocols = 0;
}
} }
void ObjCForwardProtocolDecl::Destroy(ASTContext &C) { void ObjCForwardProtocolDecl::Destroy(ASTContext &C) {
delete [] ReferencedProtocols; ReferencedProtocols.clear();
ReferencedProtocols = 0; Decl::Destroy(C);
} }
ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC, ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,