ObjectiveC migrator: When adding conforming protocol,

only add outer-most conforming protocols as adding
others are redundant.

llvm-svn: 186473
This commit is contained in:
Fariborz Jahanian 2013-07-17 00:02:22 +00:00
parent fee09c68a0
commit cb7b8deecb
3 changed files with 54 additions and 1 deletions

View File

@ -329,8 +329,29 @@ void ObjCMigrateASTConsumer::migrateProtocolConformance(ASTContext &Ctx,
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);
}

View File

@ -61,3 +61,19 @@
@implementation Test5
@synthesize Prop=_XXX;
@end
@protocol P5 <P3, P4>
@property (copy) id Prop;
@end
@protocol P6 <P3, P4, P5>
@property (copy) id Prop;
@end
@interface Test6 : NSObject // Test for minimal listing of conforming protocols
@property (copy) id Prop;
@end
@implementation Test6
@end

View File

@ -61,3 +61,19 @@
@implementation Test5
@synthesize Prop=_XXX;
@end
@protocol P5 <P3, P4>
@property (copy) id Prop;
@end
@protocol P6 <P3, P4, P5>
@property (copy) id Prop;
@end
@interface Test6 : NSObject<P6> // Test for minimal listing of conforming protocols
@property (copy) id Prop;
@end
@implementation Test6
@end