forked from OSchip/llvm-project
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@epitech.eu> llvm-svn: 185660
This commit is contained in:
parent
31c3b2ddee
commit
17b31f3d43
|
@ -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,
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
using namespace clang;
|
||||
|
||||
llvm::cl::OptionCategory TransformsOptionsCategory("Transforms' options");
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace tooling;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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::StringRef OptName,
|
|||
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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue