]> granicus.if.org Git - clang/commitdiff
Refactor ObjCInterfaceDecl::lookupInstanceMethod/lookupClassMethod into one
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 25 Jul 2009 22:15:51 +0000 (22:15 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 25 Jul 2009 22:15:51 +0000 (22:15 +0000)
ObjCInterfaceDecl::lookupMethod.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77093 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclObjC.h
lib/AST/DeclObjC.cpp

index 1e0b857f2a5871f66ca3030ecbc5e3943b8792cd..630723a60a159a71e412cc826cf6652b0fa6e8f6 100644 (file)
@@ -501,8 +501,13 @@ public:
 
   // Lookup a method. First, we search locally. If a method isn't
   // found, we search referenced protocols and class categories.
-  ObjCMethodDecl *lookupInstanceMethod(Selector Sel);
-  ObjCMethodDecl *lookupClassMethod(Selector Sel);
+  ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
+  ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
+    return lookupMethod(Sel, true/*isInstance*/);
+  }
+  ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
+    return lookupMethod(Sel, false/*isInstance*/);
+  }
   ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
 
   // Location information, modeled after the Stmt API.
index 7964f25b30c096f89ea5c9e6faf823742e38a1cb..7b3c853215f21bfb7b31200529d3010799765203 100644 (file)
@@ -145,14 +145,15 @@ ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass(
   return NULL;
 }
 
-/// lookupInstanceMethod - This method returns an instance method by looking in
+/// lookupMethod - This method returns an instance/class method by looking in
 /// the class, its categories, and its super classes (using a linear search).
-ObjCMethodDecl *ObjCInterfaceDecl::lookupInstanceMethod(Selector Sel) {
-  ObjCInterfaceDecl* ClassDecl = this;
+ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel,
+                                                bool isInstance) const {
+  const ObjCInterfaceDecl* ClassDecl = this;
   ObjCMethodDecl *MethodDecl = 0;
   
   while (ClassDecl != NULL) {
-    if ((MethodDecl = ClassDecl->getInstanceMethod(Sel)))
+    if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance)))
       return MethodDecl;
       
     // Didn't find one yet - look through protocols.
@@ -160,49 +161,13 @@ ObjCMethodDecl *ObjCInterfaceDecl::lookupInstanceMethod(Selector Sel) {
       ClassDecl->getReferencedProtocols();
     for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
          E = Protocols.end(); I != E; ++I)
-      if ((MethodDecl = (*I)->lookupInstanceMethod(Sel)))
-        return MethodDecl;
-    
-    // Didn't find one yet - now look through categories.
-    ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
-    while (CatDecl) {
-      if ((MethodDecl = CatDecl->getInstanceMethod(Sel)))
-        return MethodDecl;
-        
-      // Didn't find one yet - look through protocols.
-      const ObjCList<ObjCProtocolDecl> &Protocols =
-        CatDecl->getReferencedProtocols();
-      for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
-           E = Protocols.end(); I != E; ++I)
-        if ((MethodDecl = (*I)->lookupInstanceMethod(Sel)))
-          return MethodDecl;
-      CatDecl = CatDecl->getNextClassCategory();
-    }
-    ClassDecl = ClassDecl->getSuperClass();
-  }
-  return NULL;
-}
-
-// lookupClassMethod - This method returns a class method by looking in the
-// class, its categories, and its super classes (using a linear search).
-ObjCMethodDecl *ObjCInterfaceDecl::lookupClassMethod(Selector Sel) {
-  ObjCInterfaceDecl* ClassDecl = this;
-  ObjCMethodDecl *MethodDecl = 0;
-
-  while (ClassDecl != NULL) {
-    if ((MethodDecl = ClassDecl->getClassMethod(Sel)))
-      return MethodDecl;
-
-    // Didn't find one yet - look through protocols.
-    for (ObjCInterfaceDecl::protocol_iterator I = ClassDecl->protocol_begin(),
-         E = ClassDecl->protocol_end(); I != E; ++I)
-      if ((MethodDecl = (*I)->lookupClassMethod(Sel)))
+      if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
         return MethodDecl;
     
     // Didn't find one yet - now look through categories.
     ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
     while (CatDecl) {
-      if ((MethodDecl = CatDecl->getClassMethod(Sel)))
+      if ((MethodDecl = CatDecl->getMethod(Sel, isInstance)))
         return MethodDecl;
         
       // Didn't find one yet - look through protocols.
@@ -210,7 +175,7 @@ ObjCMethodDecl *ObjCInterfaceDecl::lookupClassMethod(Selector Sel) {
         CatDecl->getReferencedProtocols();
       for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
            E = Protocols.end(); I != E; ++I)
-        if ((MethodDecl = (*I)->lookupClassMethod(Sel)))
+        if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
           return MethodDecl;
       CatDecl = CatDecl->getNextClassCategory();
     }