/// the class implementation. Unlike interfaces, we don't look outside the
/// implementation.
ObjcMethodDecl *ObjcImplementationDecl::lookupClassMethod(Selector Sel) {
- ObjcMethodDecl *const*methods = getClassMethods();
- int methodCount = getNumClassMethods();
- for (int i = 0; i < methodCount; ++i) {
- if (methods[i]->getSelector() == Sel) {
- return methods[i];
- }
- }
+ for (classmeth_iterator I = classmeth_begin(), E = classmeth_end();
+ I != E; ++I)
+ if ((*I)->getSelector() == Sel)
+ return *I;
return NULL;
}
// the class implementation. Unlike interfaces, we don't look outside the
// implementation.
ObjcMethodDecl *ObjcCategoryImplDecl::lookupInstanceMethod(Selector &Sel) {
- ObjcMethodDecl *const*methods = getInstanceMethods();
- int methodCount = getNumInstanceMethods();
- for (int i = 0; i < methodCount; ++i) {
- if (methods[i]->getSelector() == Sel) {
- return methods[i];
- }
- }
+ for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I)
+ if ((*I)->getSelector() == Sel)
+ return *I;
return NULL;
}
// the class implementation. Unlike interfaces, we don't look outside the
// implementation.
ObjcMethodDecl *ObjcCategoryImplDecl::lookupClassMethod(Selector &Sel) {
- ObjcMethodDecl *const*methods = getClassMethods();
- int methodCount = getNumClassMethods();
- for (int i = 0; i < methodCount; ++i) {
- if (methods[i]->getSelector() == Sel) {
- return methods[i];
- }
- }
+ for (classmeth_iterator I = classmeth_begin(), E = classmeth_end();
+ I != E; ++I)
+ if ((*I)->getSelector() == Sel)
+ return *I;
return NULL;
}
void RewriteObjcCategoryImplDecl(ObjcCategoryImplDecl *CDecl,
std::string &Result);
- void RewriteObjcMethodsMetaData(ObjcMethodDecl *const*Methods,
- int NumMethods,
+ typedef ObjcCategoryImplDecl::instmeth_iterator instmeth_iterator;
+ void RewriteObjcMethodsMetaData(instmeth_iterator MethodBegin,
+ instmeth_iterator MethodEnd,
bool IsInstanceMethod,
const char *prefix,
const char *ClassName,
else
Rewrite.InsertText(CID->getLocStart(), "// ", 3);
- int numMethods = IMD ? IMD->getNumInstanceMethods()
- : CID->getNumInstanceMethods();
-
- for (int i = 0; i < numMethods; i++) {
+ for (ObjcCategoryImplDecl::instmeth_iterator
+ I = IMD ? IMD->instmeth_begin() : CID->instmeth_begin(),
+ E = IMD ? IMD->instmeth_end() : CID->instmeth_end(); I != E; ++I) {
std::string ResultStr;
- ObjcMethodDecl *OMD;
- if (IMD)
- OMD = IMD->getInstanceMethods()[i];
- else
- OMD = CID->getInstanceMethods()[i];
+ ObjcMethodDecl *OMD = *I;
RewriteObjcMethodDecl(OMD, ResultStr);
SourceLocation LocStart = OMD->getLocStart();
SourceLocation LocEnd = OMD->getBody()->getLocStart();
ResultStr.c_str(), ResultStr.size());
}
- numMethods = IMD ? IMD->getNumClassMethods() : CID->getNumClassMethods();
- for (int i = 0; i < numMethods; i++) {
+ for (ObjcCategoryImplDecl::classmeth_iterator
+ I = IMD ? IMD->classmeth_begin() : CID->classmeth_begin(),
+ E = IMD ? IMD->classmeth_end() : CID->classmeth_end(); I != E; ++I) {
std::string ResultStr;
- ObjcMethodDecl *OMD;
- if (IMD)
- OMD = IMD->getClassMethods()[i];
- else
- OMD = CID->getClassMethods()[i];
+ ObjcMethodDecl *OMD = *I;
RewriteObjcMethodDecl(OMD, ResultStr);
SourceLocation LocStart = OMD->getLocStart();
SourceLocation LocEnd = OMD->getBody()->getLocStart();
// RewriteObjcMethodsMetaData - Rewrite methods metadata for instance or
/// class methods.
-void RewriteTest::RewriteObjcMethodsMetaData(ObjcMethodDecl *const*Methods,
- int NumMethods,
+void RewriteTest::RewriteObjcMethodsMetaData(instmeth_iterator MethodBegin,
+ instmeth_iterator MethodEnd,
bool IsInstanceMethod,
const char *prefix,
const char *ClassName,
std::string &Result) {
+ if (MethodBegin == MethodEnd) return;
+
static bool objc_impl_method = false;
- if (NumMethods > 0 && !objc_impl_method) {
+ if (!objc_impl_method) {
/* struct _objc_method {
SEL _cmd;
char *method_types;
Result += "\tstruct _objc_method method_list[];\n};\n";
objc_impl_method = true;
}
+
// Build _objc_method_list for class's methods if needed
- if (NumMethods > 0) {
- Result += "\nstatic struct _objc_method_list _OBJC_";
- Result += prefix;
- Result += IsInstanceMethod ? "INSTANCE" : "CLASS";
- Result += "_METHODS_";
- Result += ClassName;
- Result += " __attribute__ ((section (\"__OBJC, __";
- Result += IsInstanceMethod ? "inst" : "cls";
- Result += "_meth\")))= ";
- Result += "{\n\t0, " + utostr(NumMethods) + "\n";
-
- Result += "\t,{{(SEL)\"";
- Result += Methods[0]->getSelector().getName().c_str();
+ Result += "\nstatic struct _objc_method_list _OBJC_";
+ Result += prefix;
+ Result += IsInstanceMethod ? "INSTANCE" : "CLASS";
+ Result += "_METHODS_";
+ Result += ClassName;
+ Result += " __attribute__ ((section (\"__OBJC, __";
+ Result += IsInstanceMethod ? "inst" : "cls";
+ Result += "_meth\")))= ";
+ Result += "{\n\t0, " + utostr(MethodEnd-MethodBegin) + "\n";
+
+ Result += "\t,{{(SEL)\"";
+ Result += (*MethodBegin)->getSelector().getName().c_str();
+ std::string MethodTypeString;
+ Context->getObjcEncodingForMethodDecl(*MethodBegin, MethodTypeString);
+ Result += "\", \"";
+ Result += MethodTypeString;
+ Result += "\", ";
+ Result += MethodInternalNames[*MethodBegin];
+ Result += "}\n";
+ for (++MethodBegin; MethodBegin != MethodEnd; ++MethodBegin) {
+ Result += "\t ,{(SEL)\"";
+ Result += (*MethodBegin)->getSelector().getName().c_str();
std::string MethodTypeString;
- Context->getObjcEncodingForMethodDecl(Methods[0], MethodTypeString);
+ Context->getObjcEncodingForMethodDecl(*MethodBegin, MethodTypeString);
Result += "\", \"";
Result += MethodTypeString;
Result += "\", ";
- Result += MethodInternalNames[Methods[0]];
+ Result += MethodInternalNames[*MethodBegin];
Result += "}\n";
- for (int i = 1; i < NumMethods; i++) {
- Result += "\t ,{(SEL)\"";
- Result += Methods[i]->getSelector().getName().c_str();
- std::string MethodTypeString;
- Context->getObjcEncodingForMethodDecl(Methods[i], MethodTypeString);
- Result += "\", \"";
- Result += MethodTypeString;
- Result += "\", ";
- Result += MethodInternalNames[Methods[i]];
- Result += "}\n";
- }
- Result += "\t }\n};\n";
}
+ Result += "\t }\n};\n";
}
/// RewriteObjcProtocolsMetaData - Rewrite protocols meta-data.
sprintf(FullCategoryName, "%s_%s", ClassDecl->getName(), IDecl->getName());
// Build _objc_method_list for class's instance methods if needed
- RewriteObjcMethodsMetaData(IDecl->getInstanceMethods(),
- IDecl->getNumInstanceMethods(),
- true,
- "CATEGORY_", FullCategoryName, Result);
+ RewriteObjcMethodsMetaData(IDecl->instmeth_begin(), IDecl->instmeth_end(),
+ true, "CATEGORY_", FullCategoryName, Result);
// Build _objc_method_list for class's class methods if needed
- RewriteObjcMethodsMetaData(IDecl->getClassMethods(),
- IDecl->getNumClassMethods(),
- false,
- "CATEGORY_", FullCategoryName, Result);
+ RewriteObjcMethodsMetaData(IDecl->classmeth_begin(), IDecl->classmeth_end(),
+ false, "CATEGORY_", FullCategoryName, Result);
// Protocols referenced in class declaration?
// Null CDecl is case of a category implementation with no category interface
}
// Build _objc_method_list for class's instance methods if needed
- RewriteObjcMethodsMetaData(IDecl->getInstanceMethods(),
- IDecl->getNumInstanceMethods(),
- true,
- "", IDecl->getName(), Result);
+ RewriteObjcMethodsMetaData(IDecl->instmeth_begin(), IDecl->instmeth_end(),
+ true, "", IDecl->getName(), Result);
// Build _objc_method_list for class's class methods if needed
- RewriteObjcMethodsMetaData(IDecl->getClassMethods(),
- IDecl->getNumClassMethods(),
- false,
- "", IDecl->getName(), Result);
+ RewriteObjcMethodsMetaData(IDecl->classmeth_begin(), IDecl->classmeth_end(),
+ false, "", IDecl->getName(), Result);
// Protocols referenced in class declaration?
RewriteObjcProtocolsMetaData(CDecl->getReferencedProtocols(),
CDecl->getNumIntfRefProtocols(),
- "CLASS",
- CDecl->getName(), Result);
+ "CLASS", CDecl->getName(), Result);
// Declaration of class/meta-class metadata
// We also need to record the @end location.
SourceLocation getAtEndLoc() const { return AtEndLoc; }
- const int getNumPropertyDecl() const { return NumPropertyDecl; }
- int getNumPropertyDecl() { return NumPropertyDecl; }
+ int getNumPropertyDecl() const { return NumPropertyDecl; }
void setNumPropertyDecl(int num) { NumPropertyDecl = num; }
ObjcPropertyDecl **const getPropertyDecl() const { return PropertyDecl; }
SourceLocation EndLoc;
public:
- ObjcCategoryImplDecl(SourceLocation L, IdentifierInfo *Id,
- ObjcInterfaceDecl *classInterface)
- : NamedDecl(ObjcCategoryImpl, L, Id),
- ClassInterface(classInterface) {}
+ ObjcCategoryImplDecl(SourceLocation L, IdentifierInfo *Id,
+ ObjcInterfaceDecl *classInterface)
+ : NamedDecl(ObjcCategoryImpl, L, Id), ClassInterface(classInterface) {}
ObjcInterfaceDecl *getClassInterface() const { return ClassInterface; }
- // FIXME: Figure out how to remove the const pointer below.
- ObjcMethodDecl *const*getInstanceMethods() const {
- return &InstanceMethods[0];
- }
- int getNumInstanceMethods() const { return InstanceMethods.size(); }
-
- // FIXME: Figure out how to remove the const pointer below.
- ObjcMethodDecl *const*getClassMethods() const {
- return &ClassMethods[0];
- }
- int getNumClassMethods() const { return ClassMethods.size(); }
+ unsigned getNumInstanceMethods() const { return InstanceMethods.size(); }
+ unsigned getNumClassMethods() const { return ClassMethods.size(); }
void addInstanceMethod(ObjcMethodDecl *method) {
InstanceMethods.push_back(method);
ObjcMethodDecl *lookupInstanceMethod(Selector &Sel);
ObjcMethodDecl *lookupClassMethod(Selector &Sel);
+ typedef llvm::SmallVector<ObjcMethodDecl*, 32>::const_iterator
+ instmeth_iterator;
+ instmeth_iterator instmeth_begin() const { return InstanceMethods.begin(); }
+ instmeth_iterator instmeth_end() const { return InstanceMethods.end(); }
+
+ typedef llvm::SmallVector<ObjcMethodDecl*, 32>::const_iterator
+ classmeth_iterator;
+ classmeth_iterator classmeth_begin() const { return ClassMethods.begin(); }
+ classmeth_iterator classmeth_end() const { return ClassMethods.end(); }
+
+
// Location information, modeled after the Stmt API.
SourceLocation getLocStart() const { return getLocation(); }
SourceLocation getLocEnd() const { return EndLoc; }
void setSuperClass(ObjcInterfaceDecl * superCls)
{ SuperClass = superCls; }
- // FIXME: Figure out how to remove the const pointer below.
- ObjcMethodDecl *const*getInstanceMethods() const {
- return &InstanceMethods[0];
- }
- int getNumInstanceMethods() const { return InstanceMethods.size(); }
-
- // FIXME: Figure out how to remove the const pointer below.
- ObjcMethodDecl *const*getClassMethods() const {
- return &ClassMethods[0];
- }
- int getNumClassMethods() const { return ClassMethods.size(); }
+ unsigned getNumInstanceMethods() const { return InstanceMethods.size(); }
+ unsigned getNumClassMethods() const { return ClassMethods.size(); }
ObjcIvarDecl **getImplDeclIVars() const { return Ivars; }
- int getImplDeclNumIvars() const { return NumIvars; }
+ unsigned getImplDeclNumIvars() const { return NumIvars; }
typedef llvm::SmallVector<ObjcMethodDecl*, 32>::const_iterator