[cfe-commits] r102919 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaObjCProperty.cpp test/SemaObjC/default-synthesize.m test/SemaObjC/super-class-protocol-conformance.m
Fariborz Jahanian
fjahanian at apple.com
Mon May 3 08:49:20 PDT 2010
Author: fjahanian
Date: Mon May 3 10:49:20 2010
New Revision: 102919
URL: http://llvm.org/viewvc/llvm-project?rev=102919&view=rev
Log:
Do not issue warning on unimplemented property in the class, if it
conforms to a protocol as one of its super classes does. This is because
conforming super class will implement the property. This implements
new warning rules for unimplemented properties (radar 7884086).
Added:
cfe/trunk/test/SemaObjC/super-class-protocol-conformance.m
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
cfe/trunk/test/SemaObjC/default-synthesize.m
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=102919&r1=102918&r2=102919&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Mon May 3 10:49:20 2010
@@ -1539,6 +1539,15 @@
/// the class and its conforming protocols; but not those it its super class.
void CollectImmediateProperties(ObjCContainerDecl *CDecl,
llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap);
+
+ /// 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=102919&r1=102918&r2=102919&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Mon May 3 10:49:20 2010
@@ -719,7 +719,10 @@
// scan through class's protocols.
for (ObjCInterfaceDecl::protocol_iterator PI = IDecl->protocol_begin(),
E = IDecl->protocol_end(); PI != E; ++PI)
- CollectImmediateProperties((*PI), PropMap);
+ // 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);
}
if (ObjCCategoryDecl *CATDecl = dyn_cast<ObjCCategoryDecl>(CDecl)) {
if (!CATDecl->IsClassExtension())
@@ -748,6 +751,33 @@
}
}
+/// 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,
Modified: cfe/trunk/test/SemaObjC/default-synthesize.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/default-synthesize.m?rev=102919&r1=102918&r2=102919&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/default-synthesize.m (original)
+++ cfe/trunk/test/SemaObjC/default-synthesize.m Mon May 3 10:49:20 2010
@@ -85,14 +85,14 @@
@interface TopClass <TopProtocol>
{
- id myString; // expected-note {{previously declared 'myString' here}}
+ id myString;
}
@end
@interface SubClass : TopClass <TopProtocol>
@end
- at implementation SubClass @end // expected-error {{property 'myString' attempting to use ivar 'myString' declared in super class 'TopClass'}}
+ at implementation SubClass @end
// rdar: // 7920807
@interface C @end
Added: 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=102919&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/super-class-protocol-conformance.m (added)
+++ cfe/trunk/test/SemaObjC/super-class-protocol-conformance.m Mon May 3 10:49:20 2010
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// rdar: // 7884086
+
+ at interface NSObject @end
+
+ at protocol TopProtocol
+ @property (readonly) id myString; // expected-warning {{property 'myString' requires method 'myString' to be defined}}
+ at end
+
+ at protocol SubProtocol <TopProtocol>
+ at end
+
+ at interface TopClass : NSObject <TopProtocol> {}
+ at end
+
+ at interface SubClass : TopClass <SubProtocol> {}
+ at end
+
+ at interface SubClass1 : TopClass {}
+ at end
+
+ at implementation SubClass1 @end // Test1 - No Warning
+
+ at implementation TopClass // expected-note {{implementation is here}}
+ at end
+
+ at implementation SubClass // Test3 - No Warning
+ at end
+
+ at interface SubClass2 : TopClass<TopProtocol>
+ at end
+
+ at implementation SubClass2 @end // Test 4 - No Warning
+
+ at interface SubClass3 : TopClass<SubProtocol> @end
+ at implementation SubClass3 @end // Test 5 - No Warning
+
+ at interface SubClass4 : SubClass3 @end
+ at implementation SubClass4 @end // Test 5 - No Warning
+
+ at protocol NewProtocol
+ @property (readonly) id myNewString; // expected-warning {{property 'myNewString' requires method 'myNewString' to be defined}}
+ at end
+
+ at interface SubClass5 : SubClass4 <NewProtocol> @end
+ at implementation SubClass5 @end // expected-note {{implementation is here}}
+
More information about the cfe-commits
mailing list