]> granicus.if.org Git - clang/commitdiff
Objective-C migrator. Simplify migrator option
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 2 Oct 2013 17:08:12 +0000 (17:08 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 2 Oct 2013 17:08:12 +0000 (17:08 +0000)
processing in preparation for adding several more
options. // rdar://15003157

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191842 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/ARCMigrate/ARCMTActions.h
include/clang/Frontend/FrontendOptions.h
lib/ARCMigrate/ObjCMT.cpp
lib/FrontendTool/ExecuteCompilerInvocation.cpp

index 50f8b281ed66a641d58737604c3e6a67d8737656..45c8b4ed1a39c6905b509a60d6c89fa28e1ff8eb 100644 (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);
index 9c1b8d5ac51391e8555a34335229b5c92ead1970..9092adce20845d87a194aeed0392c47686d2badc 100644 (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;
 
index d84cbbcffc82ddf5759f5a0af91caedd57231976..54e5662fae22822788c002f4d3df08d4392f6361 100644 (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,
index 7ba7103c7663ad24bc34c684aeb5d94ec739cd4f..acda3169323b1c31d9a112e41be3c86cba6f1953 100644 (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