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
diff --git a/AST/Decl.cpp b/AST/Decl.cpp
index 987e493..908bab4 100644
--- a/AST/Decl.cpp
+++ b/AST/Decl.cpp
@@ -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;