[cfe-commits] r44927 - in /cfe/trunk: AST/Decl.cpp Driver/ASTConsumers.cpp Driver/RewriteTest.cpp include/clang/AST/DeclObjC.h
Chris Lattner
sabre at nondot.org
Tue Dec 11 23:46:12 PST 2007
Author: lattner
Date: Wed Dec 12 01:46:12 2007
New Revision: 44927
URL: http://llvm.org/viewvc/llvm-project?rev=44927&view=rev
Log:
resolve some fixmes and clean up some code by eliminating the get*Vars apis to some classes and use iterators instead.
Modified:
cfe/trunk/AST/Decl.cpp
cfe/trunk/Driver/ASTConsumers.cpp
cfe/trunk/Driver/RewriteTest.cpp
cfe/trunk/include/clang/AST/DeclObjC.h
Modified: cfe/trunk/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Decl.cpp?rev=44927&r1=44926&r2=44927&view=diff
==============================================================================
--- cfe/trunk/AST/Decl.cpp (original)
+++ cfe/trunk/AST/Decl.cpp Wed Dec 12 01:46:12 2007
@@ -502,13 +502,10 @@
/// 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;
}
@@ -516,13 +513,9 @@
// 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;
}
@@ -530,13 +523,10 @@
// 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;
}
Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=44927&r1=44926&r2=44927&view=diff
==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Wed Dec 12 01:46:12 2007
@@ -123,9 +123,10 @@
else
Out << "@implementation " << I;
- for (int i = 0; i < OID->getNumInstanceMethods(); i++) {
- PrintObjcMethodDecl(OID->getInstanceMethods()[i]);
- ObjcMethodDecl *OMD = OID->getInstanceMethods()[i];
+ for (ObjcImplementationDecl::instmeth_iterator I = OID->instmeth_begin(),
+ E = OID->instmeth_end(); I != E; ++I) {
+ ObjcMethodDecl *OMD = *I;
+ PrintObjcMethodDecl(OMD);
if (OMD->getBody()) {
Out << ' ';
OMD->getBody()->printPretty(Out);
@@ -133,9 +134,10 @@
}
}
- for (int i = 0; i < OID->getNumClassMethods(); i++) {
- PrintObjcMethodDecl(OID->getClassMethods()[i]);
- ObjcMethodDecl *OMD = OID->getClassMethods()[i];
+ for (ObjcImplementationDecl::classmeth_iterator I = OID->classmeth_begin(),
+ E = OID->classmeth_end(); I != E; ++I) {
+ ObjcMethodDecl *OMD = *I;
+ PrintObjcMethodDecl(OMD);
if (OMD->getBody()) {
Out << ' ';
OMD->getBody()->printPretty(Out);
Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=44927&r1=44926&r2=44927&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Wed Dec 12 01:46:12 2007
@@ -184,8 +184,9 @@
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,
@@ -560,16 +561,11 @@
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();
@@ -580,14 +576,11 @@
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();
@@ -1747,14 +1740,16 @@
// 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;
@@ -1779,40 +1774,39 @@
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.
@@ -2000,16 +1994,12 @@
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
@@ -2172,22 +2162,17 @@
}
// 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
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=44927&r1=44926&r2=44927&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Wed Dec 12 01:46:12 2007
@@ -155,8 +155,7 @@
// 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; }
@@ -479,24 +478,14 @@
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);
@@ -507,6 +496,17 @@
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; }
@@ -577,20 +577,11 @@
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
More information about the cfe-commits
mailing list