aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2007-10-14 18:27:41 +0000
committerSteve Naroff <snaroff@apple.com>2007-10-14 18:27:41 +0000
commit3d58138992b9bc7b34aaa680f3ddf3971292eb7d (patch)
tree096e1a27fc3213f1c6cdebbc1ebe0db1ced567fe
parent8de2826e4d9680c757b1a9439f60f3ddcb9378fe (diff)
Add category lookup (removing a couple FIXME's).
Changed ObjcInterfaceDecl::ListCategories->CategoryList. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42968 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--AST/Decl.cpp30
-rw-r--r--Sema/SemaDecl.cpp4
-rw-r--r--include/clang/AST/DeclObjC.h14
3 files changed, 37 insertions, 11 deletions
diff --git a/AST/Decl.cpp b/AST/Decl.cpp
index 987e4933a0..908bab4277 100644
--- a/AST/Decl.cpp
+++ b/AST/Decl.cpp
@@ -410,7 +410,8 @@ void ObjcImplementationDecl::ObjcAddImplMethods(ObjcMethodDecl **insMethods,
}
}
-// 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 @@ ObjcMethodDecl *ObjcInterfaceDecl::lookupInstanceMethod(Selector &Sel) {
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 @@ ObjcMethodDecl *ObjcInterfaceDecl::lookupClassMethod(Selector &Sel) {
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;
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index ef99564dac..65f6708b1b 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -1117,7 +1117,7 @@ Sema::DeclTy *Sema::ActOnStartCategoryInterface(
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 @@ void Sema::ActOnAddMethodsToObjcDecl(Scope* S, DeclTy *classDecl,
// 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);
diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h
index 987bf57cb5..9df6a43067 100644
--- a/include/clang/AST/DeclObjC.h
+++ b/include/clang/AST/DeclObjC.h
@@ -70,7 +70,7 @@ class ObjcInterfaceDecl : public TypeDecl {
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 @@ public:
NumIvars(-1),
InstanceMethods(0), NumInstanceMethods(-1),
ClassMethods(0), NumClassMethods(-1),
- ListCategories(0), ForwardDecl(FD) {
+ CategoryList(0), ForwardDecl(FD) {
AllocIntfRefProtocols(numRefProtos);
}
@@ -126,9 +126,9 @@ public:
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 @@ public:
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; }