r201880 - [ObjC] add support for properties in attribute 'objc_protocol_requires_explicit_implementation'.

Ted Kremenek kremenek at apple.com
Fri Feb 21 11:41:40 PST 2014


Author: kremenek
Date: Fri Feb 21 13:41:39 2014
New Revision: 201880

URL: http://llvm.org/viewvc/llvm-project?rev=201880&view=rev
Log:
[ObjC] add support for properties in attribute 'objc_protocol_requires_explicit_implementation'.

Modified:
    cfe/trunk/lib/Sema/SemaObjCProperty.cpp
    cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=201880&r1=201879&r2=201880&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Fri Feb 21 13:41:39 2014
@@ -1653,12 +1653,13 @@ void Sema::DiagnoseUnimplementedProperti
                                            ObjCContainerDecl *CDecl,
                                            bool SynthesizeProperties) {
   ObjCContainerDecl::PropertyMap PropMap;
+  ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl);
+
   if (!SynthesizeProperties) {
     ObjCContainerDecl::PropertyMap NoNeedToImplPropMap;
-    ObjCInterfaceDecl *IDecl;
     // Gather properties which need not be implemented in this class
     // or category.
-    if (!(IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl)))
+    if (!IDecl)
       if (ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(CDecl)) {
         // For categories, no need to implement properties declared in
         // its primary class (and its super classes) if property is
@@ -1674,6 +1675,27 @@ void Sema::DiagnoseUnimplementedProperti
     CollectImmediateProperties(CDecl, PropMap, NoNeedToImplPropMap);
   }
 
+  // Scan the @interface to see if any of the protocols it adopts
+  // require an explicit implementation, via attribute
+  // 'objc_protocol_requires_explicit_implementation'.
+  if (IDecl)
+    for (ObjCInterfaceDecl::all_protocol_iterator
+          PI = IDecl->all_referenced_protocol_begin(),
+          PE = IDecl->all_referenced_protocol_end();
+          PI != PE; ++PI) {
+      ObjCProtocolDecl *PDecl = *PI;
+      if (!PDecl->hasAttr<ObjCExplicitProtocolImplAttr>())
+        continue;
+      // Add the properties of 'PDecl' to the list of properties that
+      // need to be implemented.
+      for (ObjCProtocolDecl::prop_iterator
+           PRI = PDecl->prop_begin(), PRE = PDecl->prop_end();
+           PRI != PRE; ++PRI) {
+        ObjCPropertyDecl *PropDecl = *PRI;
+        PropMap[PRI->getIdentifier()] = PropDecl;
+      }
+    }
+
   if (PropMap.empty())
     return;
 

Modified: cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m?rev=201880&r1=201879&r2=201880&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m (original)
+++ cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m Fri Feb 21 13:41:39 2014
@@ -5,7 +5,7 @@
 __attribute__((objc_protocol_requires_explicit_implementation))
 @protocol Protocol
 - (void) theBestOfTimes; // expected-note {{method 'theBestOfTimes' declared here}}
- at property (readonly) id theWorstOfTimes;
+ at property (readonly) id theWorstOfTimes; // expected-note {{property declared here}}
 @end
 
 // In this example, ClassA adopts the protocol.  We won't
@@ -21,7 +21,15 @@ __attribute__((objc_protocol_requires_ex
 @interface ClassB : ClassA <Protocol>
 @end
 
- at implementation ClassB // expected-warning {{method 'theBestOfTimes' in protocol 'Protocol' not implemented}}
+ at implementation ClassB // expected-warning {{method 'theBestOfTimes' in protocol 'Protocol' not implemented}} expected-warning {{property 'theWorstOfTimes' requires method 'theWorstOfTimes' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation}}
+ at end
+
+ at interface ClassB_Good : ClassA <Protocol>
+ at end
+
+ at implementation ClassB_Good // no-warning
+- (void) theBestOfTimes {}
+ at dynamic theWorstOfTimes;
 @end
 
 // Test that inherited protocols do not get the explicit conformance requirement.





More information about the cfe-commits mailing list