r180580 - Objective-C: This is a small modification to my

Fariborz Jahanian fjahanian at apple.com
Thu Apr 25 14:59:34 PDT 2013


Author: fjahanian
Date: Thu Apr 25 16:59:34 2013
New Revision: 180580

URL: http://llvm.org/viewvc/llvm-project?rev=180580&view=rev
Log:
Objective-C: This is a small modification to my
patch -n r180198.
When reporting on missing property accessor implementation in
categories, do not report when they are declared in primary class,
class's protocol, or one of it super classes or in of the other
categories. // rdar://13713098

Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Sema/SemaObjCProperty.cpp
    cfe/trunk/test/SemaObjC/property-category-4.m
    cfe/trunk/test/SemaObjC/property-category-impl.m

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=180580&r1=180579&r2=180580&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Thu Apr 25 16:59:34 2013
@@ -1137,7 +1137,7 @@ public:
   // found, we search referenced protocols and class categories.
   ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance,
                                bool shallowCategoryLookup= false,
-                               bool CategoryLookup= true) const;
+                               const ObjCCategoryDecl *C= 0) const;
   ObjCMethodDecl *lookupInstanceMethod(Selector Sel,
                             bool shallowCategoryLookup = false) const {
     return lookupMethod(Sel, true/*isInstance*/, shallowCategoryLookup);
@@ -1156,15 +1156,15 @@ public:
     return lookupPrivateMethod(Sel, false);
   }
 
-  /// \brief Lookup a setter or getter in the class hierarchy.
-  /// In this lookup, only class hierarchy and not its categories
-  /// are looked up
-  ObjCMethodDecl *lookupPropertyAccessor(const Selector Sel) const {
-     return lookupMethod(Sel, true/*isInstance*/,
-                         false /*shallowCategoryLookup*/,
-                         false /*CategoryLookup*/);
+  /// \brief Lookup a setter or getter in the class hierarchy,
+  /// including in all categories except for category passed
+  /// as argument.
+  ObjCMethodDecl *lookupPropertyAccessor(const Selector Sel,
+                                         const ObjCCategoryDecl *Cat) const {
+    return lookupMethod(Sel, true/*isInstance*/,
+                        false/*shallowCategoryLookup*/, Cat);
   }
-
+                          
   SourceLocation getEndOfDefinitionLoc() const { 
     if (!hasDefinition())
       return getLocation();

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=180580&r1=180579&r2=180580&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Thu Apr 25 16:59:34 2013
@@ -443,10 +443,12 @@ ObjCInterfaceDecl *ObjCInterfaceDecl::lo
 
 /// lookupMethod - This method returns an instance/class method by looking in
 /// the class, its categories, and its super classes (using a linear search).
+/// When argument category "C" is specified, any implicit method found
+/// in this category is ignored.
 ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel, 
                                      bool isInstance,
                                      bool shallowCategoryLookup,
-                                     bool CategoryLookup) const {
+                                     const ObjCCategoryDecl *C) const {
   // FIXME: Should make sure no callers ever do this.
   if (!hasDefinition())
     return 0;
@@ -469,24 +471,25 @@ ObjCMethodDecl *ObjCInterfaceDecl::looku
         return MethodDecl;
     
     // Didn't find one yet - now look through categories.
-    if (CategoryLookup)
-      for (ObjCInterfaceDecl::visible_categories_iterator
-           Cat = ClassDecl->visible_categories_begin(),
-           CatEnd = ClassDecl->visible_categories_end();
-           Cat != CatEnd; ++Cat) {
-        if ((MethodDecl = Cat->getMethod(Sel, isInstance)))
+    for (ObjCInterfaceDecl::visible_categories_iterator
+         Cat = ClassDecl->visible_categories_begin(),
+         CatEnd = ClassDecl->visible_categories_end();
+         Cat != CatEnd; ++Cat) {
+      if ((MethodDecl = Cat->getMethod(Sel, isInstance)))
+        if (C != (*Cat) || !MethodDecl->isImplicit())
           return MethodDecl;
 
-        if (!shallowCategoryLookup) {
-          // Didn't find one yet - look through protocols.
-          const ObjCList<ObjCProtocolDecl> &Protocols =
-            Cat->getReferencedProtocols();
-          for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
-               E = Protocols.end(); I != E; ++I)
-            if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
+      if (!shallowCategoryLookup) {
+        // Didn't find one yet - look through protocols.
+        const ObjCList<ObjCProtocolDecl> &Protocols =
+        Cat->getReferencedProtocols();
+        for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
+             E = Protocols.end(); I != E; ++I)
+          if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
+            if (C != (*Cat) || !MethodDecl->isImplicit())
               return MethodDecl;
-        }
       }
+    }
   
     ClassDecl = ClassDecl->getSuperClass();
   }

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=180580&r1=180579&r2=180580&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Thu Apr 25 16:59:34 2013
@@ -1726,7 +1726,7 @@ void Sema::DiagnoseUnimplementedProperti
     // the class is going to implement them.
     if (!InsMap.count(Prop->getGetterName()) &&
         (PrimaryClass == 0 ||
-         !PrimaryClass->lookupPropertyAccessor(Prop->getGetterName()))) {
+         !PrimaryClass->lookupPropertyAccessor(Prop->getGetterName(), C))) {
       Diag(IMPDecl->getLocation(),
            isa<ObjCCategoryDecl>(CDecl) ?
             diag::warn_setter_getter_impl_required_in_category :
@@ -1746,7 +1746,7 @@ void Sema::DiagnoseUnimplementedProperti
     // the class is going to implement them.
     if (!Prop->isReadOnly() && !InsMap.count(Prop->getSetterName()) &&
         (PrimaryClass == 0 ||
-         !PrimaryClass->lookupPropertyAccessor(Prop->getSetterName()))) {
+         !PrimaryClass->lookupPropertyAccessor(Prop->getSetterName(), C))) {
       Diag(IMPDecl->getLocation(),
            isa<ObjCCategoryDecl>(CDecl) ?
            diag::warn_setter_getter_impl_required_in_category :

Modified: cfe/trunk/test/SemaObjC/property-category-4.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-category-4.m?rev=180580&r1=180579&r2=180580&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/property-category-4.m (original)
+++ cfe/trunk/test/SemaObjC/property-category-4.m Thu Apr 25 16:59:34 2013
@@ -85,3 +85,39 @@
 
 @implementation I(CAT)
 @end
+
+// Test5 
+ at interface C @end
+
+ at interface C (CAT)
+- (int) p;
+ at end
+
+
+ at interface C (Category)
+ at property (readonly) int p;  // no warning for this property - a getter is declared in another category
+ at property (readonly) int p1; // expected-note {{property declared here}}
+ at property (readonly) int p2;  // no warning for this property - a getter is declared in this category
+- (int) p2;
+ at end
+
+ at implementation C (Category)  // expected-warning {{property 'p1' requires method 'p1' to be defined - use @dynamic or provide a method implementation in this category}}
+ at end
+
+// Test6
+ at protocol MyProtocol
+ at property (readonly) float  anotherFloat; // expected-note {{property declared here}}
+ at property (readonly) float  Float; // no warning for this property - a getter is declared in this protocol
+- (float) Float;
+ at end
+
+ at interface MyObject 
+{ float anotherFloat; }
+ at end
+
+ at interface MyObject (CAT) <MyProtocol>
+ at end
+
+ at implementation MyObject (CAT) // expected-warning {{property 'anotherFloat' requires method 'anotherFloat' to be defined - use @dynamic or provide a method implementation in this category}}
+ at end
+

Modified: cfe/trunk/test/SemaObjC/property-category-impl.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-category-impl.m?rev=180580&r1=180579&r2=180580&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/property-category-impl.m (original)
+++ cfe/trunk/test/SemaObjC/property-category-impl.m Thu Apr 25 16:59:34 2013
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
+// expected-no-diagnostics
 
 /* This test is for categories which don't implement the accessors but some accessors are
    implemented in their base class implementation. In this case,no warning must be issued.
@@ -24,10 +25,10 @@
 @end
 
 @interface MyClass (public)
- at property(readwrite)    int        foo;	// expected-note {{property declared here}}
+ at property(readwrite)    int        foo;	
 @end
 
- at implementation MyClass (public)// expected-warning {{property 'foo' requires method 'setFoo:' to be defined }}
+ at implementation MyClass (public)
 @end 
 
 // rdar://12568064





More information about the cfe-commits mailing list