[cfe-commits] r107174 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaObjCProperty.cpp test/SemaObjC/super-class-protocol-conformance.m

Fariborz Jahanian fjahanian at apple.com
Tue Jun 29 11:12:32 PDT 2010


Author: fjahanian
Date: Tue Jun 29 13:12:32 2010
New Revision: 107174

URL: http://llvm.org/viewvc/llvm-project?rev=107174&view=rev
Log:
This patch fixes a bug whereby, clang skipped 
unimplemented property warning for properties 
coming from class's conformin protocol. It also
simplifies the algorithm in the process.
Fixes radar 8035776.

Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaObjCProperty.cpp
    cfe/trunk/test/SemaObjC/super-class-protocol-conformance.m

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=107174&r1=107173&r2=107174&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Jun 29 13:12:32 2010
@@ -1573,16 +1573,9 @@
   /// CollectImmediateProperties - This routine collects all properties in
   /// the class and its conforming protocols; but not those it its super class.
   void CollectImmediateProperties(ObjCContainerDecl *CDecl,
-                  llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap);
+            llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap,
+            llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& SuperPropMap);
   
-  /// ProtocolConformsToSuperClass - Returns true if class has a super class
-  /// and it, or its nested super class conforms to the protocol.
-  bool ProtocolConformsToSuperClass(const ObjCInterfaceDecl *IDecl, 
-                                    const ObjCProtocolDecl *PDecl);
-  /// ProtocolConformsToProtocol - Returns true if 2nd Protocol (PDecl) is
-  /// qualified by the 1st.
-  bool ProtocolConformsToProtocol(const ObjCProtocolDecl *NestedProtocol,
-                                  const ObjCProtocolDecl *PDecl);
 
   /// LookupPropertyDecl - Looks up a property in the current class and all
   /// its protocols.

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=107174&r1=107173&r2=107174&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Tue Jun 29 13:12:32 2010
@@ -778,7 +778,8 @@
 /// CollectImmediateProperties - This routine collects all properties in
 /// the class and its conforming protocols; but not those it its super class.
 void Sema::CollectImmediateProperties(ObjCContainerDecl *CDecl,
-                llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap) {
+            llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap,
+            llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& SuperPropMap) {
   if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl)) {
     for (ObjCContainerDecl::prop_iterator P = IDecl->prop_begin(),
          E = IDecl->prop_end(); P != E; ++P) {
@@ -788,10 +789,7 @@
     // scan through class's protocols.
     for (ObjCInterfaceDecl::protocol_iterator PI = IDecl->protocol_begin(),
          E = IDecl->protocol_end(); PI != E; ++PI)
-      // Exclude property for protocols which conform to class's super-class, 
-      // as super-class has to implement the property.
-      if (!ProtocolConformsToSuperClass(IDecl, (*PI)))
-        CollectImmediateProperties((*PI), PropMap);
+        CollectImmediateProperties((*PI), PropMap, SuperPropMap);
   }
   if (ObjCCategoryDecl *CATDecl = dyn_cast<ObjCCategoryDecl>(CDecl)) {
     if (!CATDecl->IsClassExtension())
@@ -803,20 +801,25 @@
     // scan through class's protocols.
     for (ObjCInterfaceDecl::protocol_iterator PI = CATDecl->protocol_begin(),
          E = CATDecl->protocol_end(); PI != E; ++PI)
-      CollectImmediateProperties((*PI), PropMap);
+      CollectImmediateProperties((*PI), PropMap, SuperPropMap);
   }
   else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(CDecl)) {
     for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
          E = PDecl->prop_end(); P != E; ++P) {
       ObjCPropertyDecl *Prop = (*P);
-      ObjCPropertyDecl *&PropEntry = PropMap[Prop->getIdentifier()];
-      if (!PropEntry)
-        PropEntry = Prop;
+      ObjCPropertyDecl *PropertyFromSuper = SuperPropMap[Prop->getIdentifier()];
+      // Exclude property for protocols which conform to class's super-class, 
+      // as super-class has to implement the property.
+      if (!PropertyFromSuper || PropertyFromSuper != Prop) {
+        ObjCPropertyDecl *&PropEntry = PropMap[Prop->getIdentifier()];
+        if (!PropEntry)
+          PropEntry = Prop;
+      }
     }
     // scan through protocol's protocols.
     for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
          E = PDecl->protocol_end(); PI != E; ++PI)
-      CollectImmediateProperties((*PI), PropMap);
+      CollectImmediateProperties((*PI), PropMap, SuperPropMap);
   }
 }
 
@@ -861,33 +864,6 @@
   }
 }
 
-/// ProtocolConformsToSuperClass - Returns true if class's given protocol
-/// conforms to one of its super class's protocols.
-bool Sema::ProtocolConformsToSuperClass(const ObjCInterfaceDecl *IDecl,
-                                        const ObjCProtocolDecl *PDecl) {
-  if (const ObjCInterfaceDecl *CDecl = IDecl->getSuperClass()) {
-    for (ObjCInterfaceDecl::protocol_iterator PI = CDecl->protocol_begin(),
-         E = CDecl->protocol_end(); PI != E; ++PI) {
-      if (ProtocolConformsToProtocol((*PI), PDecl))
-        return true;
-      return ProtocolConformsToSuperClass(CDecl, PDecl);
-    }
-  }
-  return false;
-}
-
-bool Sema::ProtocolConformsToProtocol(const ObjCProtocolDecl *NestedProtocol,
-                                      const ObjCProtocolDecl *PDecl) {
-  if (PDecl->getIdentifier() == NestedProtocol->getIdentifier())
-    return true;
-  // scan through protocol's protocols.
-  for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
-       E = PDecl->protocol_end(); PI != E; ++PI)
-    if (ProtocolConformsToProtocol(NestedProtocol, (*PI)))
-      return true;
-  return false;
-}
-
 /// LookupPropertyDecl - Looks up a property in the current class and all
 /// its protocols.
 ObjCPropertyDecl *Sema::LookupPropertyDecl(const ObjCContainerDecl *CDecl,
@@ -959,8 +935,12 @@
 void Sema::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
                                       ObjCContainerDecl *CDecl,
                                       const llvm::DenseSet<Selector>& InsMap) {
+  llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*> SuperPropMap;
+  if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl))
+    CollectSuperClassPropertyImplementations(IDecl, SuperPropMap);
+  
   llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*> PropMap;
-  CollectImmediateProperties(CDecl, PropMap);
+  CollectImmediateProperties(CDecl, PropMap, SuperPropMap);
   if (PropMap.empty())
     return;
 

Modified: cfe/trunk/test/SemaObjC/super-class-protocol-conformance.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/super-class-protocol-conformance.m?rev=107174&r1=107173&r2=107174&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/super-class-protocol-conformance.m (original)
+++ cfe/trunk/test/SemaObjC/super-class-protocol-conformance.m Tue Jun 29 13:12:32 2010
@@ -45,3 +45,19 @@
 @interface SubClass5 : SubClass4 <NewProtocol> @end
 @implementation SubClass5 @end   // expected-note {{implementation is here}}
 
+
+// Radar 8035776
+ at protocol SuperProtocol
+ at end
+
+ at interface Super <SuperProtocol> 
+ at end
+
+ at protocol ProtocolWithProperty <SuperProtocol>
+ at property (readonly, assign) id invalidationBacktrace; // expected-warning {{property 'invalidationBacktrace' requires method 'invalidationBacktrace' to be defined}}
+ at end
+
+ at interface INTF : Super <ProtocolWithProperty> 
+ at end
+
+ at implementation INTF @end // expected-note {{implementation is here}}





More information about the cfe-commits mailing list