[cfe-commits] r154132 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/Sema/SemaDeclObjC.cpp test/SemaObjC/method-undef-category-warn-1.m

Fariborz Jahanian fjahanian at apple.com
Thu Apr 5 15:14:12 PDT 2012


Author: fjahanian
Date: Thu Apr  5 17:14:12 2012
New Revision: 154132

URL: http://llvm.org/viewvc/llvm-project?rev=154132&view=rev
Log:
objective-c: Don't warn when a category does not implement a method
declared in its adopted protocol when another category declares it  
because that category will implement it. // rdar://11186449

Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/test/SemaObjC/method-undef-category-warn-1.m

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=154132&r1=154131&r2=154132&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Thu Apr  5 17:14:12 2012
@@ -901,14 +901,14 @@
   // Lookup a method. First, we search locally. If a method isn't
   // found, we search referenced protocols and class categories.
   ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance,
-                               bool noCategoryLookup= false) const;
+                               bool shallowCategoryLookup= false) const;
   ObjCMethodDecl *lookupInstanceMethod(Selector Sel,
-                                       bool noCategoryLookup = false) const {
-    return lookupMethod(Sel, true/*isInstance*/, noCategoryLookup);
+                            bool shallowCategoryLookup = false) const {
+    return lookupMethod(Sel, true/*isInstance*/, shallowCategoryLookup);
   }
   ObjCMethodDecl *lookupClassMethod(Selector Sel,
-                                    bool noCategoryLookup = false) const {
-    return lookupMethod(Sel, false/*isInstance*/, noCategoryLookup);
+                     bool shallowCategoryLookup = false) const {
+    return lookupMethod(Sel, false/*isInstance*/, shallowCategoryLookup);
   }
   ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
 

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=154132&r1=154131&r2=154132&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Thu Apr  5 17:14:12 2012
@@ -316,9 +316,9 @@
 
 /// 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::lookupMethod(Selector Sel,
-                                                bool isInstance,
-                                                bool noCategoryLookup) const {
+ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel, 
+                                     bool isInstance,
+                                     bool shallowCategoryLookup) const {
   // FIXME: Should make sure no callers ever do this.
   if (!hasDefinition())
     return 0;
@@ -339,13 +339,14 @@
            I != E; ++I)
       if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
         return MethodDecl;
-    if (!noCategoryLookup) {
-      // Didn't find one yet - now look through categories.
-      ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
-      while (CatDecl) {
-        if ((MethodDecl = CatDecl->getMethod(Sel, isInstance)))
-          return MethodDecl;
+    
+    // Didn't find one yet - now look through categories.
+    ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
+    while (CatDecl) {
+      if ((MethodDecl = CatDecl->getMethod(Sel, isInstance)))
+        return MethodDecl;
 
+      if (!shallowCategoryLookup) {
         // Didn't find one yet - look through protocols.
         const ObjCList<ObjCProtocolDecl> &Protocols =
           CatDecl->getReferencedProtocols();
@@ -353,9 +354,10 @@
              E = Protocols.end(); I != E; ++I)
           if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
             return MethodDecl;
-        CatDecl = CatDecl->getNextClassCategory();
       }
+      CatDecl = CatDecl->getNextClassCategory();
     }
+  
     ClassDecl = ClassDecl->getSuperClass();
   }
   return NULL;

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=154132&r1=154131&r2=154132&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Apr  5 17:14:12 2012
@@ -1537,7 +1537,7 @@
             // uses the protocol.
             if (ObjCMethodDecl *MethodInClass =
                   IDecl->lookupInstanceMethod(method->getSelector(), 
-                                              true /*noCategoryLookup*/))
+                                              true /*shallowCategoryLookup*/))
               if (C || MethodInClass->isSynthesized())
                 continue;
             unsigned DIAG = diag::warn_unimplemented_protocol_method;
@@ -1561,7 +1561,7 @@
         (!Super || !Super->lookupClassMethod(method->getSelector()))) {
       // See above comment for instance method lookups.
       if (C && IDecl->lookupClassMethod(method->getSelector(), 
-                                        true /*noCategoryLookup*/))
+                                        true /*shallowCategoryLookup*/))
         continue;
       unsigned DIAG = diag::warn_unimplemented_protocol_method;
       if (Diags.getDiagnosticLevel(DIAG, ImpLoc) !=

Modified: cfe/trunk/test/SemaObjC/method-undef-category-warn-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-undef-category-warn-1.m?rev=154132&r1=154131&r2=154132&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/method-undef-category-warn-1.m (original)
+++ cfe/trunk/test/SemaObjC/method-undef-category-warn-1.m Thu Apr  5 17:14:12 2012
@@ -51,3 +51,24 @@
 
 @implementation NSObject (FooConformance)
 @end
+
+// rdar://11186449
+// Don't warn when a category does not implemented a method imported
+// by its protocol because another category has its declaration and
+// that category will implement it.
+ at interface NSOrderedSet @end
+
+ at interface NSOrderedSet(CoolectionImplements)
+- (unsigned char)containsObject:(id)object;
+ at end
+
+ at protocol Collection
+- (unsigned char)containsObject:(id)object;
+ at end
+
+ at interface NSOrderedSet (CollectionConformance) <Collection>
+ at end
+
+ at implementation NSOrderedSet (CollectionConformance)
+ at end
+





More information about the cfe-commits mailing list