summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2017-10-06 19:49:29 +0000
committerAlex Lorenz <arphaman@gmail.com>2017-10-06 19:49:29 +0000
commitf1381a926e22e996f38e74fd74bc9a25dfbac8f9 (patch)
treeacd95877576f97c73eaef03725167dccec4444f2 /tools
parentcc5ee4901e888a08cdea30b25e8df416f3f12be3 (diff)
Revert r315087
clang-refactor crashes on some bots after this commit git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315095 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/clang-refactor/ClangRefactor.cpp121
1 files changed, 7 insertions, 114 deletions
diff --git a/tools/clang-refactor/ClangRefactor.cpp b/tools/clang-refactor/ClangRefactor.cpp
index 47e09e7050..ff13773072 100644
--- a/tools/clang-refactor/ClangRefactor.cpp
+++ b/tools/clang-refactor/ClangRefactor.cpp
@@ -18,7 +18,6 @@
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Refactoring.h"
#include "clang/Tooling/Refactoring/RefactoringAction.h"
-#include "clang/Tooling/Refactoring/RefactoringOptions.h"
#include "clang/Tooling/Refactoring/Rename/RenamingAction.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Support/CommandLine.h"
@@ -33,10 +32,10 @@ namespace cl = llvm::cl;
namespace opts {
-static cl::OptionCategory CommonRefactorOptions("Refactoring options");
+static cl::OptionCategory CommonRefactorOptions("Common refactoring options");
static cl::opt<bool> Verbose("v", cl::desc("Use verbose output"),
- cl::cat(cl::GeneralCategory),
+ cl::cat(CommonRefactorOptions),
cl::sub(*cl::AllSubCommands));
} // end namespace opts
@@ -117,92 +116,6 @@ SourceSelectionArgument::fromString(StringRef Value) {
return nullptr;
}
-/// A container that stores the command-line options used by a single
-/// refactoring option.
-class RefactoringActionCommandLineOptions {
-public:
- void addStringOption(const RefactoringOption &Option,
- std::unique_ptr<cl::opt<std::string>> CLOption) {
- StringOptions[&Option] = std::move(CLOption);
- }
-
- const cl::opt<std::string> &
- getStringOption(const RefactoringOption &Opt) const {
- auto It = StringOptions.find(&Opt);
- return *It->second;
- }
-
-private:
- llvm::DenseMap<const RefactoringOption *,
- std::unique_ptr<cl::opt<std::string>>>
- StringOptions;
-};
-
-/// Passes the command-line option values to the options used by a single
-/// refactoring action rule.
-class CommandLineRefactoringOptionVisitor final
- : public RefactoringOptionVisitor {
-public:
- CommandLineRefactoringOptionVisitor(
- const RefactoringActionCommandLineOptions &Options)
- : Options(Options) {}
-
- void visit(const RefactoringOption &Opt,
- Optional<std::string> &Value) override {
- const cl::opt<std::string> &CLOpt = Options.getStringOption(Opt);
- if (!CLOpt.getValue().empty()) {
- Value = CLOpt.getValue();
- return;
- }
- Value = None;
- if (Opt.isRequired())
- MissingRequiredOptions.push_back(&Opt);
- }
-
- ArrayRef<const RefactoringOption *> getMissingRequiredOptions() const {
- return MissingRequiredOptions;
- }
-
-private:
- llvm::SmallVector<const RefactoringOption *, 4> MissingRequiredOptions;
- const RefactoringActionCommandLineOptions &Options;
-};
-
-/// Creates the refactoring options used by all the rules in a single
-/// refactoring action.
-class CommandLineRefactoringOptionCreator final
- : public RefactoringOptionVisitor {
-public:
- CommandLineRefactoringOptionCreator(
- cl::OptionCategory &Category, cl::SubCommand &Subcommand,
- RefactoringActionCommandLineOptions &Options)
- : Category(Category), Subcommand(Subcommand), Options(Options) {}
-
- void visit(const RefactoringOption &Opt, Optional<std::string> &) override {
- if (Visited.insert(&Opt).second)
- Options.addStringOption(Opt, create<std::string>(Opt));
- }
-
-private:
- template <typename T>
- std::unique_ptr<cl::opt<T>> create(const RefactoringOption &Opt) {
- if (!OptionNames.insert(Opt.getName()).second)
- llvm::report_fatal_error("Multiple identical refactoring options "
- "specified for one refactoring action");
- // FIXME: cl::Required can be specified when this option is present
- // in all rules in an action.
- return llvm::make_unique<cl::opt<T>>(
- Opt.getName(), cl::desc(Opt.getDescription()), cl::Optional,
- cl::cat(Category), cl::sub(Subcommand));
- }
-
- llvm::SmallPtrSet<const RefactoringOption *, 8> Visited;
- llvm::StringSet<> OptionNames;
- cl::OptionCategory &Category;
- cl::SubCommand &Subcommand;
- RefactoringActionCommandLineOptions &Options;
-};
-
/// A subcommand that corresponds to individual refactoring action.
class RefactoringActionSubcommand : public cl::SubCommand {
public:
@@ -225,12 +138,6 @@ public:
"<file>:<line>:<column>)"),
cl::cat(Category), cl::sub(*this));
}
- // Create the refactoring options.
- for (const auto &Rule : this->ActionRules) {
- CommandLineRefactoringOptionCreator OptionCreator(Category, *this,
- Options);
- Rule->visitRefactoringOptions(OptionCreator);
- }
}
~RefactoringActionSubcommand() { unregisterSubCommand(); }
@@ -253,17 +160,11 @@ public:
assert(Selection && "selection not supported!");
return ParsedSelection.get();
}
-
- const RefactoringActionCommandLineOptions &getOptions() const {
- return Options;
- }
-
private:
std::unique_ptr<RefactoringAction> Action;
RefactoringActionRules ActionRules;
std::unique_ptr<cl::opt<std::string>> Selection;
std::unique_ptr<SourceSelectionArgument> ParsedSelection;
- RefactoringActionCommandLineOptions Options;
};
class ClangRefactorConsumer : public RefactoringResultConsumer {
@@ -361,22 +262,14 @@ public:
bool HasSelection = false;
for (const auto &Rule : Subcommand.getActionRules()) {
- bool SelectionMatches = true;
if (Rule->hasSelectionRequirement()) {
HasSelection = true;
- if (!Subcommand.getSelection()) {
+ if (Subcommand.getSelection())
+ MatchingRules.push_back(Rule.get());
+ else
MissingOptions.insert("selection");
- SelectionMatches = false;
- }
- }
- CommandLineRefactoringOptionVisitor Visitor(Subcommand.getOptions());
- Rule->visitRefactoringOptions(Visitor);
- if (SelectionMatches && Visitor.getMissingRequiredOptions().empty()) {
- MatchingRules.push_back(Rule.get());
- continue;
}
- for (const RefactoringOption *Opt : Visitor.getMissingRequiredOptions())
- MissingOptions.insert(Opt->getName());
+ // FIXME (Alex L): Support custom options.
}
if (MatchingRules.empty()) {
llvm::errs() << "error: '" << Subcommand.getName()
@@ -433,7 +326,7 @@ int main(int argc, const char **argv) {
ClangRefactorTool Tool;
CommonOptionsParser Options(
- argc, argv, cl::GeneralCategory, cl::ZeroOrMore,
+ argc, argv, opts::CommonRefactorOptions, cl::ZeroOrMore,
"Clang-based refactoring tool for C, C++ and Objective-C");
// Figure out which action is specified by the user. The user must specify