r191842 - Objective-C migrator. Simplify migrator option

Fariborz Jahanian fjahanian at apple.com
Wed Oct 2 10:08:12 PDT 2013


Author: fjahanian
Date: Wed Oct  2 12:08:12 2013
New Revision: 191842

URL: http://llvm.org/viewvc/llvm-project?rev=191842&view=rev
Log:
Objective-C migrator. Simplify migrator option 
processing in preparation for adding several more
options. // rdar://15003157

Modified:
    cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h
    cfe/trunk/include/clang/Frontend/FrontendOptions.h
    cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
    cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp

Modified: cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h?rev=191842&r1=191841&r2=191842&view=diff
==============================================================================
--- cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h (original)
+++ cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h Wed Oct  2 12:08:12 2013
@@ -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);

Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=191842&r1=191841&r2=191842&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Wed Oct  2 12:08:12 2013
@@ -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;
 

Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=191842&r1=191841&r2=191842&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Wed Oct  2 12:08:12 2013
@@ -75,10 +75,7 @@ class ObjCMigrateASTConsumer : public AS
                                   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::CreateAS
   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::migrateProp
     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, c
 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::Create
     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,

Modified: cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp?rev=191842&r1=191841&r2=191842&view=diff
==============================================================================
--- cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp (original)
+++ cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp Wed Oct  2 12:08:12 2013
@@ -162,10 +162,7 @@ static FrontendAction *CreateFrontendAct
 
   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
 





More information about the cfe-commits mailing list