const char *ClassName,
std::string &Result);
- void RewriteObjCProtocolsMetaData(ObjCProtocolDecl *const*Protocols,
- int NumProtocols,
+ void RewriteObjCProtocolsMetaData(const ObjCList<ObjCProtocolDecl>
+ &Protocols,
const char *prefix,
const char *ClassName,
std::string &Result);
}
/// RewriteObjCProtocolsMetaData - Rewrite protocols meta-data.
-void RewriteObjC::RewriteObjCProtocolsMetaData(ObjCProtocolDecl*const*Protocols,
- int NumProtocols,
- const char *prefix,
- const char *ClassName,
- std::string &Result) {
+void RewriteObjC::
+RewriteObjCProtocolsMetaData(const ObjCList<ObjCProtocolDecl> &Protocols,
+ const char *prefix,
+ const char *ClassName,
+ std::string &Result) {
static bool objc_protocol_methods = false;
- if (NumProtocols > 0) {
- for (int i = 0; i < NumProtocols; i++) {
+ if (!Protocols.empty()) {
+ for (unsigned i = 0; i != Protocols.size(); i++) {
ObjCProtocolDecl *PDecl = Protocols[i];
// Output struct protocol_methods holder of method selector and type.
if (!objc_protocol_methods && !PDecl->isForwardDecl()) {
Result += "\tstruct _objc_protocol_list *next;\n";
Result += "\tint protocol_count;\n";
Result += "\tstruct _objc_protocol *class_protocols[";
- Result += utostr(NumProtocols);
+ Result += utostr(Protocols.size());
Result += "];\n} _OBJC_";
Result += prefix;
Result += "_PROTOCOLS_";
Result += ClassName;
Result += " __attribute__ ((used, section (\"__OBJC, __cat_cls_meth\")))= "
"{\n\t0, ";
- Result += utostr(NumProtocols);
+ Result += utostr(Protocols.size());
Result += "\n";
Result += "\t,{&_OBJC_PROTOCOL_";
Result += Protocols[0]->getName();
Result += " \n";
- for (int i = 1; i < NumProtocols; i++) {
- ObjCProtocolDecl *PDecl = Protocols[i];
+ for (unsigned i = 1; i != Protocols.size(); i++) {
Result += "\t ,&_OBJC_PROTOCOL_";
- Result += PDecl->getName();
+ Result += Protocols[i]->getName();
Result += "\n";
}
Result += "\t }\n};\n";
// Protocols referenced in class declaration?
// Null CDecl is case of a category implementation with no category interface
if (CDecl)
- RewriteObjCProtocolsMetaData(CDecl->getReferencedProtocols(),
- CDecl->getNumReferencedProtocols(),
- "CATEGORY",
+ RewriteObjCProtocolsMetaData(CDecl->getReferencedProtocols(), "CATEGORY",
FullCategoryName.c_str(), Result);
/* struct _objc_category {
else
Result += "\t, 0\n";
- if (CDecl && CDecl->getNumReferencedProtocols() > 0) {
+ if (CDecl && !CDecl->getReferencedProtocols().empty()) {
Result += "\t, (struct _objc_protocol_list *)&_OBJC_CATEGORY_PROTOCOLS_";
Result += FullCategoryName;
Result += "\n";
false, "", IDecl->getName(), Result);
// Protocols referenced in class declaration?
- RewriteObjCProtocolsMetaData(CDecl->getReferencedProtocols().begin(),
- CDecl->getReferencedProtocols().size(),
+ RewriteObjCProtocolsMetaData(CDecl->getReferencedProtocols(),
"CLASS", CDecl->getName(), Result);
unsigned size() const { return NumElts; }
bool empty() const { return NumElts == 0; }
- T* get(unsigned idx) const {
+ T* operator[](unsigned idx) const {
assert(idx < NumElts && "Invalid access");
return List[idx];
}
return ClassMethods+NumClassMethods;
}
-
/// addReferencedProtocols - Set the list of protocols that this interface
/// implements.
- void addReferencedProtocols(ObjCProtocolDecl * const *OID, unsigned NumRPs) {
- ReferencedProtocols.set(OID, NumRPs);
+ void addReferencedProtocols(ObjCProtocolDecl *const*List, unsigned NumRPs) {
+ ReferencedProtocols.set(List, NumRPs);
}
void addInstanceVariablesToClass(ObjCIvarDecl **ivars, unsigned numIvars,
/// id <NSDraggingInfo> anyObjectThatImplementsNSDraggingInfo;
///
class ObjCProtocolDecl : public NamedDecl {
- /// referenced protocols
- ObjCProtocolDecl **ReferencedProtocols; // Null if none
- unsigned NumReferencedProtocols; // 0 if none
+ /// Referenced protocols
+ ObjCList<ObjCProtocolDecl> ReferencedProtocols;
/// protocol instance methods
ObjCMethodDecl **InstanceMethods; // Null if not defined
SourceLocation EndLoc; // marks the '>' or identifier.
SourceLocation AtEndLoc; // marks the end of the entire interface.
- ObjCProtocolDecl(SourceLocation L, unsigned numRefProtos, IdentifierInfo *Id)
+ ObjCProtocolDecl(SourceLocation L, IdentifierInfo *Id)
: NamedDecl(ObjCProtocol, L, Id),
- ReferencedProtocols(0), NumReferencedProtocols(0),
InstanceMethods(0), NumInstanceMethods(0),
ClassMethods(0), NumClassMethods(0),
PropertyDecl(0), NumPropertyDecl(0),
isForwardProtoDecl(true) {
- AllocReferencedProtocols(numRefProtos);
}
virtual ~ObjCProtocolDecl();
virtual void Destroy(ASTContext& C);
static ObjCProtocolDecl *Create(ASTContext &C, SourceLocation L,
- unsigned numRefProtos, IdentifierInfo *Id);
+ IdentifierInfo *Id);
- void AllocReferencedProtocols(unsigned numRefProtos) {
- if (numRefProtos) {
- ReferencedProtocols = new ObjCProtocolDecl*[numRefProtos];
- memset(ReferencedProtocols, '\0',
- numRefProtos*sizeof(ObjCProtocolDecl*));
- NumReferencedProtocols = numRefProtos;
- }
- }
void addMethods(ObjCMethodDecl **insMethods, unsigned numInsMembers,
ObjCMethodDecl **clsMethods, unsigned numClsMembers,
SourceLocation AtEndLoc);
- void setReferencedProtocols(unsigned idx, ObjCProtocolDecl *OID) {
- assert((idx < NumReferencedProtocols) && "index out of range");
- ReferencedProtocols[idx] = OID;
- }
-
- ObjCProtocolDecl** getReferencedProtocols() const {
- return ReferencedProtocols;
+ const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const {
+ return ReferencedProtocols;
}
- unsigned getNumReferencedProtocols() const { return NumReferencedProtocols; }
typedef ObjCProtocolDecl * const * protocol_iterator;
- protocol_iterator protocol_begin() const { return ReferencedProtocols; }
- protocol_iterator protocol_end() const {
- return ReferencedProtocols+NumReferencedProtocols;
+ protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
+ protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
+
+ /// addReferencedProtocols - Set the list of protocols that this interface
+ /// implements.
+ void addReferencedProtocols(ObjCProtocolDecl *const*List, unsigned NumRPs) {
+ ReferencedProtocols.set(List, NumRPs);
}
unsigned getNumInstanceMethods() const { return NumInstanceMethods; }
ObjCInterfaceDecl *ClassInterface;
/// referenced protocols in this category.
- ObjCProtocolDecl **ReferencedProtocols; // Null if none
- unsigned NumReferencedProtocols; // 0 if none
+ ObjCList<ObjCProtocolDecl> ReferencedProtocols;
/// category instance methods
ObjCMethodDecl **InstanceMethods; // Null if not defined
ObjCCategoryDecl(SourceLocation L, IdentifierInfo *Id)
: NamedDecl(ObjCCategory, L, Id),
- ClassInterface(0), ReferencedProtocols(0), NumReferencedProtocols(0),
+ ClassInterface(0),
InstanceMethods(0), NumInstanceMethods(0),
ClassMethods(0), NumClassMethods(0),
NextClassCategory(0), PropertyDecl(0), NumPropertyDecl(0) {
/// addReferencedProtocols - Set the list of protocols that this interface
/// implements.
- void addReferencedProtocols(ObjCProtocolDecl **List, unsigned NumRPs);
+ void addReferencedProtocols(ObjCProtocolDecl *const*List, unsigned NumRPs) {
+ ReferencedProtocols.set(List, NumRPs);
+ }
- ObjCProtocolDecl **getReferencedProtocols() const {
- return ReferencedProtocols;
+ const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const {
+ return ReferencedProtocols;
}
- unsigned getNumReferencedProtocols() const { return NumReferencedProtocols; }
+
+ typedef ObjCProtocolDecl * const * protocol_iterator;
+ protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
+ protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
+
+
unsigned getNumInstanceMethods() const { return NumInstanceMethods; }
unsigned getNumClassMethods() const { return NumClassMethods; }
ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C,
SourceLocation L,
- unsigned numRefProtos,
IdentifierInfo *Id) {
void *Mem = C.getAllocator().Allocate<ObjCProtocolDecl>();
- return new (Mem) ObjCProtocolDecl(L, numRefProtos, Id);
+ return new (Mem) ObjCProtocolDecl(L, Id);
}
ObjCProtocolDecl::~ObjCProtocolDecl() {
- delete [] ReferencedProtocols;
delete [] InstanceMethods;
delete [] ClassMethods;
delete [] PropertyDecl;
AtEndLoc = endLoc;
}
-void ObjCCategoryDecl::addReferencedProtocols(ObjCProtocolDecl **List,
- unsigned NumRPs) {
- assert(NumReferencedProtocols == 0 && "Protocol list already set");
- if (NumRPs == 0) return;
-
- ReferencedProtocols = new ObjCProtocolDecl*[NumRPs];
- memcpy(ReferencedProtocols, List, NumRPs*sizeof(ObjCProtocolDecl*));
- NumReferencedProtocols = NumRPs;
-}
/// addMethods - Insert instance and methods declarations into
return MethodDecl;
// Didn't find one yet - look through protocols.
- const ObjCList<ObjCProtocolDecl> &Protocols =
- ClassDecl->getReferencedProtocols();
-
- for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
- E = Protocols.end(); I != E; ++I) {
+ for (ObjCInterfaceDecl::protocol_iterator I = ClassDecl->protocol_begin(),
+ E = ClassDecl->protocol_end(); I != E; ++I)
if ((MethodDecl = (*I)->getClassMethod(Sel)))
return MethodDecl;
- }
+
// Didn't find one yet - now look through categories.
ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
while (CatDecl) {
if ((MethodDecl = getInstanceMethod(Sel)))
return MethodDecl;
- if (getNumReferencedProtocols() > 0) {
- ObjCProtocolDecl **RefPDecl = getReferencedProtocols();
-
- for (unsigned i = 0; i < getNumReferencedProtocols(); i++) {
- if ((MethodDecl = RefPDecl[i]->getInstanceMethod(Sel)))
- return MethodDecl;
- }
- }
+ for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
+ if ((MethodDecl = (*I)->getInstanceMethod(Sel)))
+ return MethodDecl;
return NULL;
}
if ((MethodDecl = getClassMethod(Sel)))
return MethodDecl;
- if (getNumReferencedProtocols() > 0) {
- ObjCProtocolDecl **RefPDecl = getReferencedProtocols();
-
- for(unsigned i = 0; i < getNumReferencedProtocols(); i++) {
- if ((MethodDecl = RefPDecl[i]->getClassMethod(Sel)))
- return MethodDecl;
- }
- }
+ for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
+ if ((MethodDecl = (*I)->getClassMethod(Sel)))
+ return MethodDecl;
return NULL;
}
}
void CodeGenModule::EmitObjCProtocolImplementation(const ObjCProtocolDecl *PD){
llvm::SmallVector<std::string, 16> Protocols;
- for (unsigned i = 0, e = PD->getNumReferencedProtocols() ; i < e ; i++)
- Protocols.push_back(PD->getReferencedProtocols()[i]->getName());
+ for (ObjCProtocolDecl::protocol_iterator PI = PD->protocol_begin(),
+ E = PD->protocol_end(); PI != E; ++PI)
+ Protocols.push_back((*PI)->getName());
llvm::SmallVector<llvm::Constant*, 16> InstanceMethodNames;
llvm::SmallVector<llvm::Constant*, 16> InstanceMethodTypes;
for (ObjCProtocolDecl::instmeth_iterator iter = PD->instmeth_begin(),
- endIter = PD->instmeth_end() ; iter != endIter ; iter++) {
+ E = PD->instmeth_end(); iter != E; iter++) {
std::string TypeStr;
- Context.getObjCEncodingForMethodDecl((*iter),TypeStr);
+ Context.getObjCEncodingForMethodDecl(*iter, TypeStr);
InstanceMethodNames.push_back(
GetAddrOfConstantString((*iter)->getSelector().getName()));
InstanceMethodTypes.push_back(GetAddrOfConstantString(TypeStr));
}
PDecl->setForwardDecl(false);
- PDecl->AllocReferencedProtocols(NumProtoRefs);
} else {
- PDecl = ObjCProtocolDecl::Create(Context, AtProtoInterfaceLoc, NumProtoRefs,
- ProtocolName);
+ PDecl = ObjCProtocolDecl::Create(Context, AtProtoInterfaceLoc,ProtocolName);
PDecl->setForwardDecl(false);
ObjCProtocols[ProtocolName] = PDecl;
}
if (NumProtoRefs) {
/// Check then save referenced protocols.
+ llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols;
for (unsigned int i = 0; i != NumProtoRefs; i++) {
- ObjCProtocolDecl* RefPDecl = ObjCProtocols[ProtoRefNames[i]];
+ ObjCProtocolDecl *RefPDecl = ObjCProtocols[ProtoRefNames[i]];
if (!RefPDecl)
Diag(ProtocolLoc, diag::err_undef_protocolref,
ProtoRefNames[i]->getName(), ProtocolName->getName());
if (RefPDecl->isForwardDecl())
Diag(ProtocolLoc, diag::warn_undef_protocolref,
ProtoRefNames[i]->getName(), ProtocolName->getName());
- PDecl->setReferencedProtocols(i, RefPDecl);
+ Protocols.push_back(RefPDecl);
}
}
+ if (!Protocols.empty())
+ PDecl->addReferencedProtocols(&Protocols[0], Protocols.size());
PDecl->setLocEnd(EndProtoLoc);
}
return PDecl;
ObjCProtocolDecl *&PDecl = ObjCProtocols[Ident];
if (PDecl == 0) { // Not already seen?
// FIXME: Pass in the location of the identifier!
- PDecl = ObjCProtocolDecl::Create(Context, AtProtocolLoc, 0, Ident);
+ PDecl = ObjCProtocolDecl::Create(Context, AtProtocolLoc, Ident);
}
Protocols.push_back(PDecl);
method->getImplementationControl() != ObjCMethodDecl::Optional)
WarnUndefinedMethod(ImpLoc, method, IncompleteImpl);
}
- // Check on this protocols's referenced protocols, recursively
- ObjCProtocolDecl** RefPDecl = PDecl->getReferencedProtocols();
- for (unsigned i = 0; i < PDecl->getNumReferencedProtocols(); i++)
- CheckProtocolMethodDefs(ImpLoc, RefPDecl[i], IncompleteImpl, InsMap, ClsMap);
+ // Check on this protocols's referenced protocols, recursively.
+ for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
+ E = PDecl->protocol_end(); PI != E; ++PI)
+ CheckProtocolMethodDefs(ImpLoc, *PI, IncompleteImpl, InsMap, ClsMap);
}
void Sema::ImplMethodsVsClassMethods(ObjCImplementationDecl* IMPDecl,
// Check the protocol list for unimplemented methods in the @implementation
// class.
- ObjCProtocolDecl** protocols = CatClassDecl->getReferencedProtocols();
- for (unsigned i = 0; i < CatClassDecl->getNumReferencedProtocols(); i++) {
- ObjCProtocolDecl* PDecl = protocols[i];
- CheckProtocolMethodDefs(CatImplDecl->getLocation(), PDecl, IncompleteImpl,
+ for (ObjCCategoryDecl::protocol_iterator PI = CatClassDecl->protocol_begin(),
+ E = CatClassDecl->protocol_end(); PI != E; ++PI)
+ CheckProtocolMethodDefs(CatImplDecl->getLocation(), *PI, IncompleteImpl,
InsMap, ClsMap);
- }
}
/// ActOnForwardClassDeclaration -
ObjCProtocolDecl *rProto) {
if (lProto == rProto)
return true;
- ObjCProtocolDecl** RefPDecl = rProto->getReferencedProtocols();
- for (unsigned i = 0; i < rProto->getNumReferencedProtocols(); i++)
- if (ProtocolCompatibleWithProtocol(lProto, RefPDecl[i]))
+ for (ObjCProtocolDecl::protocol_iterator PI = rProto->protocol_begin(),
+ E = rProto->protocol_end(); PI != E; ++PI)
+ if (ProtocolCompatibleWithProtocol(lProto, *PI))
return true;
return false;
}
if (lookupCategory)
for (ObjCCategoryDecl *CDecl = IDecl->getCategoryList(); CDecl;
CDecl = CDecl->getNextClassCategory()) {
- ObjCProtocolDecl **protoList = CDecl->getReferencedProtocols();
- for (unsigned i = 0; i < CDecl->getNumReferencedProtocols(); i++) {
- if (ProtocolCompatibleWithProtocol(lProto, protoList[i]))
+ for (ObjCCategoryDecl::protocol_iterator PI = CDecl->protocol_begin(),
+ E = CDecl->protocol_end(); PI != E; ++PI)
+ if (ProtocolCompatibleWithProtocol(lProto, *PI))
return true;
- }
}
// 3rd, look up the super class(s)