[clang-tools-extra] r185660 - cpp11-migrate: Minor command-line fixes and improvements

Edwin Vane edwin.vane at intel.com
Thu Jul 4 10:49:59 PDT 2013


Author: revane
Date: Thu Jul  4 12:49:59 2013
New Revision: 185660

URL: http://llvm.org/viewvc/llvm-project?rev=185660&view=rev
Log:
cpp11-migrate: Minor command-line fixes and improvements

* all transforms are in the same category
* all transforms' options are in the same category
* display the CommonOptionParser extra-help (which describe in more details the
  compilation database stuff)
* add EXAMPLES section

Author: Guillaume Papin <guillaume.papin at epitech.eu>

Modified:
    clang-tools-extra/trunk/cpp11-migrate/AddOverride/AddOverride.cpp
    clang-tools-extra/trunk/cpp11-migrate/Core/Transform.cpp
    clang-tools-extra/trunk/cpp11-migrate/Core/Transform.h
    clang-tools-extra/trunk/cpp11-migrate/Core/Transforms.cpp
    clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.cpp
    clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp

Modified: clang-tools-extra/trunk/cpp11-migrate/AddOverride/AddOverride.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/AddOverride/AddOverride.cpp?rev=185660&r1=185659&r2=185660&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/AddOverride/AddOverride.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/AddOverride/AddOverride.cpp Thu Jul  4 12:49:59 2013
@@ -21,16 +21,16 @@
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "clang/Tooling/Refactoring.h"
 #include "clang/Tooling/Tooling.h"
-#include "llvm/Support/CommandLine.h"
 
 using clang::ast_matchers::MatchFinder;
 using namespace clang::tooling;
 using namespace clang;
+namespace cl = llvm::cl;
 
-static llvm::cl::opt<bool> DetectMacros(
+static cl::opt<bool> DetectMacros(
     "override-macros",
-    llvm::cl::desc(
-        "Detect and use macros that expand to the 'override' keyword."));
+    cl::desc("Detect and use macros that expand to the 'override' keyword."),
+    cl::cat(TransformsOptionsCategory));
 
 int AddOverrideTransform::apply(FileOverrides &InputStates,
                                 const CompilationDatabase &Database,

Modified: clang-tools-extra/trunk/cpp11-migrate/Core/Transform.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Core/Transform.cpp?rev=185660&r1=185659&r2=185660&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Core/Transform.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Core/Transform.cpp Thu Jul  4 12:49:59 2013
@@ -11,6 +11,8 @@
 
 using namespace clang;
 
+llvm::cl::OptionCategory TransformsOptionsCategory("Transforms' options");
+
 namespace {
 
 using namespace tooling;

Modified: clang-tools-extra/trunk/cpp11-migrate/Core/Transform.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Core/Transform.h?rev=185660&r1=185659&r2=185660&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Core/Transform.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Core/Transform.h Thu Jul  4 12:49:59 2013
@@ -20,8 +20,9 @@
 #include "Core/IncludeExcludeInfo.h"
 #include "Core/FileOverrides.h"
 #include "clang/Tooling/Refactoring.h"
-#include "llvm/Support/Timer.h"
 #include "llvm/ADT/OwningPtr.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Timer.h"
 
 
 /// \brief Description of the riskiness of actions that can be taken by
@@ -51,6 +52,9 @@ class MatchFinder;
 
 class RewriterManager;
 
+/// \brief To group transforms' options together when printing the help.
+extern llvm::cl::OptionCategory TransformsOptionsCategory;
+
 /// \brief Container for global options affecting all transforms.
 struct TransformOptions {
   /// \brief Enable the use of performance timers.

Modified: clang-tools-extra/trunk/cpp11-migrate/Core/Transforms.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Core/Transforms.cpp?rev=185660&r1=185659&r2=185660&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Core/Transforms.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Core/Transforms.cpp Thu Jul  4 12:49:59 2013
@@ -17,6 +17,8 @@
 
 namespace cl = llvm::cl;
 
+static cl::OptionCategory TransformCategory("Transforms");
+
 Transforms::~Transforms() {
   for (std::vector<Transform*>::iterator I = ChosenTransforms.begin(),
        E = ChosenTransforms.end(); I != E; ++I) {
@@ -32,7 +34,8 @@ void Transforms::registerTransform(llvm:
                                    llvm::StringRef Description,
                                    TransformCreator Creator) {
   Options.push_back(OptionVec::value_type(
-      new cl::opt<bool>(OptName.data(), cl::desc(Description.data())),
+      new cl::opt<bool>(OptName.data(), cl::desc(Description.data()),
+                        cl::cat(TransformCategory)),
       Creator));
 }
 

Modified: clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.cpp?rev=185660&r1=185659&r2=185660&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.cpp Thu Jul  4 12:49:59 2013
@@ -26,15 +26,17 @@
 using namespace clang::ast_matchers;
 using namespace clang::tooling;
 using namespace clang;
+namespace cl = llvm::cl;
 
 namespace {
 
 const char *NullMacroName = "NULL";
 
-static llvm::cl::opt<std::string> UserNullMacroNames(
-    "user-null-macros", llvm::cl::desc("Comma-separated list of user-defined "
-                                       "macro names that behave like NULL"),
-    llvm::cl::init(""));
+static cl::opt<std::string>
+UserNullMacroNames("user-null-macros",
+                   cl::desc("Comma-separated list of user-defined "
+                            "macro names that behave like NULL"),
+                   cl::cat(TransformsOptionsCategory), cl::init(""));
 
 bool isReplaceableRange(SourceLocation StartLoc, SourceLocation EndLoc,
                         const SourceManager &SM, const Transform &Owner) {

Modified: clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp?rev=185660&r1=185659&r2=185660&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp Thu Jul  4 12:49:59 2013
@@ -34,6 +34,22 @@ using namespace clang::tooling;
 
 TransformOptions GlobalOptions;
 
+static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
+static cl::extrahelp MoreHelp(
+    "EXAMPLES:\n\n"
+    "Use 'auto' type specifier, no compilation database:\n\n"
+    "  cpp11-migrate -use-auto path/to/file.cpp -- -Ipath/to/include/\n"
+    "\n"
+    "Convert for loops to the new ranged-based for loops on all files in a "
+    "subtree:\n\n"
+    "  find path/in/subtree -name '*.cpp' -exec \\\n"
+    "    cpp11-migrate -p build/path -loop-convert {} ';'\n"
+    "\n"
+    "Make use of both nullptr and the override specifier, using git ls-files:\n"
+    "\n"
+    "  git ls-files '*.cpp' | xargs -I{} cpp11-migrate -p build/path \\\n"
+    "    -use-nullptr -add-override -override-macros {}\n");
+
 static cl::opt<RiskLevel, /*ExternalStorage=*/true> MaxRiskLevel(
     "risk", cl::desc("Select a maximum risk level:"),
     cl::values(clEnumValN(RL_Safe, "safe", "Only safe transformations"),
@@ -131,7 +147,7 @@ int main(int argc, const char **argv) {
   TransformManager.createSelectedTransforms(GlobalOptions);
 
   if (TransformManager.begin() == TransformManager.end()) {
-    llvm::errs() << "No selected transforms\n";
+    llvm::errs() << argv[0] << ": No selected transforms\n";
     return 1;
   }
 





More information about the cfe-commits mailing list