[PATCH] Use -std=c++11 when no arguments are provided.

Ariel Bernal ariel.j.bernal at intel.com
Thu Aug 8 21:47:29 PDT 2013


Hi revane, tareqsiraj, Sarcasm,

Added c++11 support to the migrator when no compilation database is provided. 

http://llvm-reviews.chandlerc.com/D1337

Files:
  cpp11-migrate/tool/Cpp11Migrate.cpp

Index: cpp11-migrate/tool/Cpp11Migrate.cpp
===================================================================
--- cpp11-migrate/tool/Cpp11Migrate.cpp
+++ cpp11-migrate/tool/Cpp11Migrate.cpp
@@ -36,6 +36,10 @@
 TransformOptions GlobalOptions;
 
 static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
+static cl::opt<std::string> BuildPath(
+    "p", cl::desc("Build Path"), cl::Optional);
+static cl::list<std::string> SourcePaths(
+    cl::Positional, cl::desc("<source0> [... <sourceN>]"), cl::OneOrMore);
 static cl::extrahelp MoreHelp(
     "EXAMPLES:\n\n"
     "Apply all transforms on a given file, no compilation database:\n\n"
@@ -220,8 +224,30 @@
 
   TransformManager.registerTransforms();
 
-  // This causes options to be parsed.
-  CommonOptionsParser OptionsParser(argc, argv);
+  // Parse options and generate compilations.
+  OwningPtr<CompilationDatabase> Compilations(
+      FixedCompilationDatabase::loadFromCommandLine(argc, argv));
+  cl::ParseCommandLineOptions(argc, argv);
+  if (!Compilations) {
+    std::string ErrorMessage;
+    if (!BuildPath.empty()) {
+      Compilations.reset(CompilationDatabase::autoDetectFromDirectory(
+          BuildPath, ErrorMessage));
+    } else {
+      Compilations.reset(CompilationDatabase::autoDetectFromSource(
+          SourcePaths[0], ErrorMessage));
+      // If no compilation database can be detected from source then we create
+      // a new FixedCompilationDatabase with c++11 support.
+      if (!Compilations) {
+        std::vector<std::string> CommandLine;
+        CommandLine.push_back("-std=c++11");
+        Compilations.reset(new FixedCompilationDatabase(".", CommandLine));
+      }
+    }
+    if (!Compilations) {
+      llvm::report_fatal_error(ErrorMessage);
+    }
+  }
 
   // Since ExecutionTimeDirectoryName could be an empty string we compare
   // against the default value when the command line option is not specified.
@@ -269,9 +295,7 @@
        I != E; ++I) {
     Transform *T = *I;
 
-    if (T->apply(FileStates, OptionsParser.getCompilations(),
-                 OptionsParser.getSourcePathList()) !=
-        0) {
+    if (T->apply(FileStates, *Compilations, SourcePaths) != 0) {
       // FIXME: Improve ClangTool to not abort if just one file fails.
       return 1;
     }
@@ -300,8 +324,7 @@
     }
 
   if (FinalSyntaxCheck)
-    if (!doSyntaxCheck(OptionsParser.getCompilations(),
-                       OptionsParser.getSourcePathList(), FileStates))
+    if (!doSyntaxCheck(*Compilations, SourcePaths, FileStates))
       return 1;
 
   // Write results to file.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1337.1.patch
Type: text/x-patch
Size: 2589 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130808/04004569/attachment.bin>


More information about the cfe-commits mailing list