[PATCH] cpp11-migrate: Minor command-line fixes and improvements

Guillaume Papin guillaume.papin at epitech.eu
Wed Jul 3 05:41:54 PDT 2013


Hi revane,

- 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

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

Files:
  cpp11-migrate/AddOverride/AddOverride.cpp
  cpp11-migrate/Core/Transform.cpp
  cpp11-migrate/Core/Transform.h
  cpp11-migrate/Core/Transforms.cpp
  cpp11-migrate/UseNullptr/NullptrActions.cpp
  cpp11-migrate/tool/Cpp11Migrate.cpp

Index: cpp11-migrate/AddOverride/AddOverride.cpp
===================================================================
--- cpp11-migrate/AddOverride/AddOverride.cpp
+++ cpp11-migrate/AddOverride/AddOverride.cpp
@@ -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,
Index: cpp11-migrate/Core/Transform.cpp
===================================================================
--- cpp11-migrate/Core/Transform.cpp
+++ cpp11-migrate/Core/Transform.cpp
@@ -11,6 +11,8 @@
 
 using namespace clang;
 
+llvm::cl::OptionCategory TransformsOptionsCategory("Transforms' options");
+
 namespace {
 
 using namespace tooling;
Index: cpp11-migrate/Core/Transform.h
===================================================================
--- cpp11-migrate/Core/Transform.h
+++ cpp11-migrate/Core/Transform.h
@@ -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 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.
Index: cpp11-migrate/Core/Transforms.cpp
===================================================================
--- cpp11-migrate/Core/Transforms.cpp
+++ cpp11-migrate/Core/Transforms.cpp
@@ -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 @@
                                    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));
 }
 
Index: cpp11-migrate/UseNullptr/NullptrActions.cpp
===================================================================
--- cpp11-migrate/UseNullptr/NullptrActions.cpp
+++ cpp11-migrate/UseNullptr/NullptrActions.cpp
@@ -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) {
Index: cpp11-migrate/tool/Cpp11Migrate.cpp
===================================================================
--- cpp11-migrate/tool/Cpp11Migrate.cpp
+++ cpp11-migrate/tool/Cpp11Migrate.cpp
@@ -33,6 +33,22 @@
 
 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' | xargs -I{} \\\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"),
@@ -126,7 +142,7 @@
   TransformManager.createSelectedTransforms(GlobalOptions);
 
   if (TransformManager.begin() == TransformManager.end()) {
-    llvm::errs() << "No selected transforms\n";
+    llvm::errs() << argv[0] << ": No selected transforms\n";
     return 1;
   }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1085.1.patch
Type: text/x-patch
Size: 5545 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130703/82379fa0/attachment.bin>


More information about the cfe-commits mailing list