r186473 - ObjectiveC migrator: When adding conforming protocol,
Fariborz Jahanian
fjahanian at apple.com
Tue Jul 16 17:02:23 PDT 2013
Author: fjahanian
Date: Tue Jul 16 19:02:22 2013
New Revision: 186473
URL: http://llvm.org/viewvc/llvm-project?rev=186473&view=rev
Log:
ObjectiveC migrator: When adding conforming protocol,
only add outer-most conforming protocols as adding
others are redundant.
Modified:
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m
cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m.result
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=186473&r1=186472&r2=186473&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Tue Jul 16 19:02:22 2013
@@ -329,8 +329,29 @@ void ObjCMigrateASTConsumer::migrateProt
if (ConformingProtocols.empty())
return;
+
+ // Further reduce number of conforming protocols. If protocol P1 is in the list
+ // protocol P2 (P2<P1>), No need to include P1.
+ llvm::SmallVector<ObjCProtocolDecl*, 8> MinimalConformingProtocols;
+ for (unsigned i = 0, e = ConformingProtocols.size(); i != e; i++) {
+ bool DropIt = false;
+ ObjCProtocolDecl *TargetPDecl = ConformingProtocols[i];
+ for (unsigned i1 = 0, e1 = ConformingProtocols.size(); i1 != e1; i1++) {
+ ObjCProtocolDecl *PDecl = ConformingProtocols[i1];
+ if (PDecl == TargetPDecl)
+ continue;
+ if (PDecl->lookupProtocolNamed(
+ TargetPDecl->getDeclName().getAsIdentifierInfo())) {
+ DropIt = true;
+ break;
+ }
+ }
+ if (!DropIt)
+ MinimalConformingProtocols.push_back(TargetPDecl);
+ }
edit::Commit commit(*Editor);
- edit::rewriteToObjCInterfaceDecl(IDecl, ConformingProtocols, *NSAPIObj, commit);
+ edit::rewriteToObjCInterfaceDecl(IDecl, MinimalConformingProtocols,
+ *NSAPIObj, commit);
Editor->commit(commit);
}
Modified: cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m?rev=186473&r1=186472&r2=186473&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m (original)
+++ cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m Tue Jul 16 19:02:22 2013
@@ -61,3 +61,19 @@
@implementation Test5
@synthesize Prop=_XXX;
@end
+
+ at protocol P5 <P3, P4>
+ at property (copy) id Prop;
+ at end
+
+ at protocol P6 <P3, P4, P5>
+ at property (copy) id Prop;
+ at end
+
+ at interface Test6 : NSObject // Test for minimal listing of conforming protocols
+ at property (copy) id Prop;
+ at end
+
+ at implementation Test6
+ at end
+
Modified: cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m.result?rev=186473&r1=186472&r2=186473&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m.result Tue Jul 16 19:02:22 2013
@@ -61,3 +61,19 @@
@implementation Test5
@synthesize Prop=_XXX;
@end
+
+ at protocol P5 <P3, P4>
+ at property (copy) id Prop;
+ at end
+
+ at protocol P6 <P3, P4, P5>
+ at property (copy) id Prop;
+ at end
+
+ at interface Test6 : NSObject<P6> // Test for minimal listing of conforming protocols
+ at property (copy) id Prop;
+ at end
+
+ at implementation Test6
+ at end
+
More information about the cfe-commits
mailing list