Objective-C migrator. Simplify migrator option

processing in preparation for adding several more
options. // rdar://15003157

llvm-svn: 191842
This commit is contained in:
Fariborz Jahanian 2013-10-02 17:08:12 +00:00
parent d3e916eb6a
commit 182486c9d9
4 changed files with 18 additions and 45 deletions

View File

@ -57,18 +57,12 @@ public:
/// \brief Migrates to modern ObjC syntax.
class ObjCMigrateAction : public WrapperFrontendAction {
std::string MigrateDir;
bool MigrateLiterals;
bool MigrateSubscripting;
bool MigrateProperty;
bool MigrateReadonlyProperty;
unsigned ObjCMigAction;
FileRemapper Remapper;
CompilerInstance *CompInst;
public:
ObjCMigrateAction(FrontendAction *WrappedAction, StringRef migrateDir,
bool migrateLiterals,
bool migrateSubscripting,
bool migrateProperty,
bool migrateReadonlyProperty);
unsigned migrateAction);
protected:
virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,StringRef InFile);

View File

@ -163,7 +163,9 @@ public:
/// \brief Enable migration to modern ObjC property.
ObjCMT_Property = 0x4,
/// \brief Enable migration to modern ObjC readonly property.
ObjCMT_ReadonlyProperty = 0x8
ObjCMT_ReadonlyProperty = 0x8,
ObjCMT_All = (ObjCMT_Literals | ObjCMT_Subscripting |
ObjCMT_Property | ObjCMT_ReadonlyProperty)
};
unsigned ObjCMTAction;

View File

@ -75,10 +75,7 @@ class ObjCMigrateASTConsumer : public ASTConsumer {
const ObjCMethodDecl *MethodDecl);
public:
std::string MigrateDir;
bool MigrateLiterals;
bool MigrateSubscripting;
bool MigrateProperty;
bool MigrateReadonlyProperty;
unsigned ASTMigrateActions;
unsigned FileId;
OwningPtr<NSAPI> NSAPIObj;
OwningPtr<edit::EditedSource> Editor;
@ -91,20 +88,14 @@ public:
llvm::SmallVector<const Decl *, 8> CFFunctionIBCandidates;
ObjCMigrateASTConsumer(StringRef migrateDir,
bool migrateLiterals,
bool migrateSubscripting,
bool migrateProperty,
bool migrateReadonlyProperty,
unsigned astMigrateActions,
FileRemapper &remapper,
FileManager &fileMgr,
const PPConditionalDirectiveRecord *PPRec,
Preprocessor &PP,
bool isOutputFile = false)
: MigrateDir(migrateDir),
MigrateLiterals(migrateLiterals),
MigrateSubscripting(migrateSubscripting),
MigrateProperty(migrateProperty),
MigrateReadonlyProperty(migrateReadonlyProperty),
ASTMigrateActions(astMigrateActions),
FileId(0), Remapper(remapper), FileMgr(fileMgr), PPRec(PPRec), PP(PP),
IsOutputFile(isOutputFile) { }
@ -134,15 +125,10 @@ protected:
}
ObjCMigrateAction::ObjCMigrateAction(FrontendAction *WrappedAction,
StringRef migrateDir,
bool migrateLiterals,
bool migrateSubscripting,
bool migrateProperty,
bool migrateReadonlyProperty)
StringRef migrateDir,
unsigned migrateAction)
: WrapperFrontendAction(WrappedAction), MigrateDir(migrateDir),
MigrateLiterals(migrateLiterals), MigrateSubscripting(migrateSubscripting),
MigrateProperty(migrateProperty),
MigrateReadonlyProperty(migrateReadonlyProperty),
ObjCMigAction(migrateAction),
CompInst(0) {
if (MigrateDir.empty())
MigrateDir = "."; // user current directory if none is given.
@ -156,10 +142,7 @@ ASTConsumer *ObjCMigrateAction::CreateASTConsumer(CompilerInstance &CI,
ASTConsumer *
WrappedConsumer = WrapperFrontendAction::CreateASTConsumer(CI, InFile);
ASTConsumer *MTConsumer = new ObjCMigrateASTConsumer(MigrateDir,
MigrateLiterals,
MigrateSubscripting,
MigrateProperty,
MigrateReadonlyProperty,
ObjCMigAction,
Remapper,
CompInst->getFileManager(),
PPRec,
@ -189,13 +172,13 @@ public:
bool shouldWalkTypesOfTypeLocs() const { return false; }
bool VisitObjCMessageExpr(ObjCMessageExpr *E) {
if (Consumer.MigrateLiterals) {
if (Consumer.ASTMigrateActions & FrontendOptions::ObjCMT_Literals) {
edit::Commit commit(*Consumer.Editor);
edit::rewriteToObjCLiteralSyntax(E, *Consumer.NSAPIObj, commit, &PMap);
Consumer.Editor->commit(commit);
}
if (Consumer.MigrateSubscripting) {
if (Consumer.ASTMigrateActions & FrontendOptions::ObjCMT_Subscripting) {
edit::Commit commit(*Consumer.Editor);
edit::rewriteToObjCSubscriptSyntax(E, *Consumer.NSAPIObj, commit);
Consumer.Editor->commit(commit);
@ -841,7 +824,7 @@ bool ObjCMigrateASTConsumer::migrateProperty(ASTContext &Ctx,
Editor->commit(commit);
return true;
}
else if (MigrateReadonlyProperty) {
else if (ASTMigrateActions & FrontendOptions::ObjCMT_ReadonlyProperty) {
// Try a non-void method with no argument (and no setter or property of same name
// as a 'readonly' property.
edit::Commit commit(*Editor);
@ -1341,7 +1324,7 @@ IsReallyASystemHeader(ASTContext &Ctx, const FileEntry *file, FileID FID) {
void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl();
if (MigrateProperty) {
if (ASTMigrateActions & FrontendOptions::ObjCMT_Property) {
for (DeclContext::decl_iterator D = TU->decls_begin(), DEnd = TU->decls_end();
D != DEnd; ++D) {
if (unsigned FID =
@ -1419,10 +1402,7 @@ ASTConsumer *MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI,
PPRec = new PPConditionalDirectiveRecord(CI.getSourceManager());
CI.getPreprocessor().addPPCallbacks(PPRec);
return new ObjCMigrateASTConsumer(CI.getFrontendOpts().OutputFile,
/*MigrateLiterals=*/true,
/*MigrateSubscripting=*/true,
/*MigrateProperty*/true,
/*MigrateReadonlyProperty*/true,
FrontendOptions::ObjCMT_All,
Remapper,
CI.getFileManager(),
PPRec,

View File

@ -162,10 +162,7 @@ static FrontendAction *CreateFrontendAction(CompilerInstance &CI) {
if (FEOpts.ObjCMTAction != FrontendOptions::ObjCMT_None) {
Act = new arcmt::ObjCMigrateAction(Act, FEOpts.MTMigrateDir,
FEOpts.ObjCMTAction & FrontendOptions::ObjCMT_Literals,
FEOpts.ObjCMTAction & FrontendOptions::ObjCMT_Subscripting,
FEOpts.ObjCMTAction & FrontendOptions::ObjCMT_Property,
FEOpts.ObjCMTAction & FrontendOptions::ObjCMT_ReadonlyProperty);
FEOpts.ObjCMTAction);
}
#endif