[cfe-commits] r65526 - in /cfe/trunk: lib/AST/DeclObjC.cpp test/SemaObjC/protocol-lookup-2.m

Steve Naroff snaroff at apple.com
Thu Feb 26 03:32:09 PST 2009


Author: snaroff
Date: Thu Feb 26 05:32:02 2009
New Revision: 65526

URL: http://llvm.org/viewvc/llvm-project?rev=65526&view=rev
Log:
Fix ObjCInterfaceDecl::lookupInstanceMethod()/lookupClassMethod() to search in inherited protocols.

Also changed ObjCInterfaceDecl::lookupClassMethod() to look through a categories protocols.

Test/patch submitted by Jean-Daniel Dupas (thanks!).

Added:
    cfe/trunk/test/SemaObjC/protocol-lookup-2.m
Modified:
    cfe/trunk/lib/AST/DeclObjC.cpp

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=65526&r1=65525&r2=65526&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Thu Feb 26 05:32:02 2009
@@ -157,7 +157,7 @@
       ClassDecl->getReferencedProtocols();
     for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
          E = Protocols.end(); I != E; ++I)
-      if ((MethodDecl = (*I)->getInstanceMethod(Sel)))
+      if ((MethodDecl = (*I)->lookupInstanceMethod(Sel)))
         return MethodDecl;
     
     // Didn't find one yet - now look through categories.
@@ -171,7 +171,7 @@
         CatDecl->getReferencedProtocols();
       for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
            E = Protocols.end(); I != E; ++I)
-        if ((MethodDecl = (*I)->getInstanceMethod(Sel)))
+        if ((MethodDecl = (*I)->lookupInstanceMethod(Sel)))
           return MethodDecl;
       CatDecl = CatDecl->getNextClassCategory();
     }
@@ -193,7 +193,7 @@
     // 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)->getClassMethod(Sel)))
+      if ((MethodDecl = (*I)->lookupClassMethod(Sel)))
         return MethodDecl;
     
     // Didn't find one yet - now look through categories.
@@ -201,6 +201,14 @@
     while (CatDecl) {
       if ((MethodDecl = CatDecl->getClassMethod(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)->lookupClassMethod(Sel)))
+          return MethodDecl;
       CatDecl = CatDecl->getNextClassCategory();
     }
     ClassDecl = ClassDecl->getSuperClass();

Added: cfe/trunk/test/SemaObjC/protocol-lookup-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/protocol-lookup-2.m?rev=65526&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/protocol-lookup-2.m (added)
+++ cfe/trunk/test/SemaObjC/protocol-lookup-2.m Thu Feb 26 05:32:02 2009
@@ -0,0 +1,33 @@
+// RUN: clang -fsyntax-only -verify %s
+ at interface NSObject @end
+
+ at protocol ProtocolA
+
++ (id)classMethod;
+- (id)instanceMethod;
+
+ at end
+
+ at protocol ProtocolB <ProtocolA>
+
+ at end
+
+ at interface Foo : NSObject <ProtocolB>
+
+ at end
+
+ at interface SubFoo : Foo
+
+ at end
+
+ at implementation SubFoo
+
++ (id)method {
+  return [super classMethod];
+}
+
+- (id)method {
+  return [super instanceMethod];
+}
+
+ at end





More information about the cfe-commits mailing list