r186220 - ObjC migrator: early work for migrating implicitly conforming
Fariborz Jahanian
fjahanian at apple.com
Fri Jul 12 15:32:19 PDT 2013
Author: fjahanian
Date: Fri Jul 12 17:32:19 2013
New Revision: 186220
URL: http://llvm.org/viewvc/llvm-project?rev=186220&view=rev
Log:
ObjC migrator: early work for migrating implicitly conforming
protocols to classes. This is wip.
Modified:
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=186220&r1=186219&r2=186220&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Fri Jul 12 17:32:19 2013
@@ -33,6 +33,8 @@ namespace {
class ObjCMigrateASTConsumer : public ASTConsumer {
void migrateDecl(Decl *D);
void migrateObjCInterfaceDecl(ASTContext &Ctx, ObjCInterfaceDecl *D);
+ void migrateProtocolConformance(ASTContext &Ctx,
+ const ObjCImplementationDecl *ImpDecl);
public:
std::string MigrateDir;
@@ -46,7 +48,8 @@ public:
const PPConditionalDirectiveRecord *PPRec;
Preprocessor &PP;
bool IsOutputFile;
-
+ llvm::SmallPtrSet<ObjCProtocolDecl *, 32> ObjCProtocolDecls;
+
ObjCMigrateASTConsumer(StringRef migrateDir,
bool migrateLiterals,
bool migrateSubscripting,
@@ -232,6 +235,27 @@ void ObjCMigrateASTConsumer::migrateObjC
}
}
+void ObjCMigrateASTConsumer::migrateProtocolConformance(ASTContext &Ctx,
+ const ObjCImplementationDecl *ImpDecl) {
+ const ObjCInterfaceDecl *IDecl = ImpDecl->getClassInterface();
+ if (!IDecl || ObjCProtocolDecls.empty())
+ return;
+ // Find all implicit conforming protocols for this class
+ // and make them explicit.
+ llvm::SmallPtrSet<ObjCProtocolDecl *, 8> ExplicitProtocols;
+ Ctx.CollectInheritedProtocols(IDecl, ExplicitProtocols);
+ llvm::SmallPtrSet<ObjCProtocolDecl *, 8> PotentialImplicitProtocols;
+
+ for (llvm::SmallPtrSet<ObjCProtocolDecl*,32>::iterator I =
+ ObjCProtocolDecls.begin(),
+ E = ObjCProtocolDecls.end(); I != E; ++I)
+ if (!ExplicitProtocols.count(*I))
+ PotentialImplicitProtocols.insert(*I);
+
+ if (PotentialImplicitProtocols.empty())
+ return;
+}
+
namespace {
class RewritesReceiver : public edit::EditsReceiver {
@@ -258,6 +282,11 @@ void ObjCMigrateASTConsumer::HandleTrans
D != DEnd; ++D) {
if (ObjCInterfaceDecl *CDecl = dyn_cast<ObjCInterfaceDecl>(*D))
migrateObjCInterfaceDecl(Ctx, CDecl);
+ else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(*D))
+ ObjCProtocolDecls.insert(PDecl);
+ else if (const ObjCImplementationDecl *ImpDecl =
+ dyn_cast<ObjCImplementationDecl>(*D))
+ migrateProtocolConformance(Ctx, ImpDecl);
}
Rewriter rewriter(Ctx.getSourceManager(), Ctx.getLangOpts());
More information about the cfe-commits
mailing list