[cfe-commits] r42968 - in /cfe/trunk: AST/Decl.cpp Sema/SemaDecl.cpp include/clang/AST/DeclObjC.h
Steve Naroff
snaroff at apple.com
Sun Oct 14 11:27:41 PDT 2007
Author: snaroff
Date: Sun Oct 14 13:27:41 2007
New Revision: 42968
URL: http://llvm.org/viewvc/llvm-project?rev=42968&view=rev
Log:
Add category lookup (removing a couple FIXME's).
Changed ObjcInterfaceDecl::ListCategories->CategoryList.
Modified:
cfe/trunk/AST/Decl.cpp
cfe/trunk/Sema/SemaDecl.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=42968&r1=42967&r2=42968&view=diff
==============================================================================
--- cfe/trunk/AST/Decl.cpp (original)
+++ cfe/trunk/AST/Decl.cpp Sun Oct 14 13:27:41 2007
@@ -410,7 +410,8 @@
}
}
-// FIXME: look through categories...
+// lookupInstanceMethod - This method returns an instance method by looking in
+// the class, it's categories, and it's super classes (using a linear search).
ObjcMethodDecl *ObjcInterfaceDecl::lookupInstanceMethod(Selector &Sel) {
ObjcInterfaceDecl* ClassDecl = this;
while (ClassDecl != NULL) {
@@ -421,12 +422,25 @@
return methods[i];
}
}
+ // Didn't find one yet - now look through categories.
+ ObjcCategoryDecl *CatDecl = this->getCategoryList();
+ while (CatDecl) {
+ ObjcMethodDecl **methods = CatDecl->getInstanceMethods();
+ int methodCount = CatDecl->getNumInstanceMethods();
+ for (int i = 0; i < methodCount; ++i) {
+ if (methods[i]->getSelector() == Sel) {
+ return methods[i];
+ }
+ }
+ CatDecl = CatDecl->getNextClassCategory();
+ }
ClassDecl = ClassDecl->getSuperClass();
}
return NULL;
}
-// FIXME: look through categories...
+// lookupClassMethod - This method returns a class method by looking in the
+// class, it's categories, and it's super classes (using a linear search).
ObjcMethodDecl *ObjcInterfaceDecl::lookupClassMethod(Selector &Sel) {
ObjcInterfaceDecl* ClassDecl = this;
while (ClassDecl != NULL) {
@@ -437,6 +451,18 @@
return methods[i];
}
}
+ // Didn't find one yet - now look through categories.
+ ObjcCategoryDecl *CatDecl = this->getCategoryList();
+ while (CatDecl) {
+ ObjcMethodDecl **methods = CatDecl->getClassMethods();
+ int methodCount = CatDecl->getNumClassMethods();
+ for (int i = 0; i < methodCount; ++i) {
+ if (methods[i]->getSelector() == Sel) {
+ return methods[i];
+ }
+ }
+ CatDecl = CatDecl->getNextClassCategory();
+ }
ClassDecl = ClassDecl->getSuperClass();
}
return NULL;
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=42968&r1=42967&r2=42968&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Sun Oct 14 13:27:41 2007
@@ -1117,7 +1117,7 @@
CDecl->setClassInterface(IDecl);
/// Check for duplicate interface declaration for this category
ObjcCategoryDecl *CDeclChain;
- for (CDeclChain = IDecl->getListCategories(); CDeclChain;
+ for (CDeclChain = IDecl->getCategoryList(); CDeclChain;
CDeclChain = CDeclChain->getNextClassCategory()) {
if (CDeclChain->getIdentifier() == CategoryName) {
Diag(CategoryLoc, diag::err_dup_category_def, ClassName->getName(),
@@ -1889,7 +1889,7 @@
// Find category interface decl and then check that all methods declared
// in this interface is implemented in the category @implementation.
if (IDecl) {
- for (ObjcCategoryDecl *Categories = IDecl->getListCategories();
+ for (ObjcCategoryDecl *Categories = IDecl->getCategoryList();
Categories; Categories = Categories->getNextClassCategory()) {
if (Categories->getIdentifier() == CatImplClass->getIdentifier()) {
ImplCategoryMethodsVsIntfMethods(CatImplClass, Categories);
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=42968&r1=42967&r2=42968&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Sun Oct 14 13:27:41 2007
@@ -70,7 +70,7 @@
int NumClassMethods; // -1 if not defined
/// List of categories defined for this class.
- ObjcCategoryDecl *ListCategories;
+ ObjcCategoryDecl *CategoryList;
bool ForwardDecl; // declared with @class.
public:
@@ -81,7 +81,7 @@
NumIvars(-1),
InstanceMethods(0), NumInstanceMethods(-1),
ClassMethods(0), NumClassMethods(-1),
- ListCategories(0), ForwardDecl(FD) {
+ CategoryList(0), ForwardDecl(FD) {
AllocIntfRefProtocols(numRefProtos);
}
@@ -126,9 +126,9 @@
ObjcInterfaceDecl *getSuperClass() const { return SuperClass; }
void setSuperClass(ObjcInterfaceDecl * superCls) { SuperClass = superCls; }
- ObjcCategoryDecl* getListCategories() const { return ListCategories; }
- void setListCategories(ObjcCategoryDecl *category) {
- ListCategories = category;
+ ObjcCategoryDecl* getCategoryList() const { return CategoryList; }
+ void setCategoryList(ObjcCategoryDecl *category) {
+ CategoryList = category;
}
ObjcMethodDecl *lookupInstanceMethod(Selector &Sel);
ObjcMethodDecl *lookupClassMethod(Selector &Sel);
@@ -480,8 +480,8 @@
ObjcCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
void insertNextClassCategory() {
- NextClassCategory = ClassInterface->getListCategories();
- ClassInterface->setListCategories(this);
+ NextClassCategory = ClassInterface->getCategoryList();
+ ClassInterface->setCategoryList(this);
}
static bool classof(const Decl *D) { return D->getKind() == ObjcCategory; }
More information about the cfe-commits
mailing list