Skip to content

Commit

Permalink
[clang-move] Use cl::list for the list of names
Browse files Browse the repository at this point in the history
This diff replaces manual parsing of the comma-separated list of names with 
cl::list and cl::CommaSeparated.
Test plan: make -j8 check-clang-tools

Differential revision: https://reviews.llvm.org/D25586

llvm-svn: 284291
  • Loading branch information
alexander-shaposhnikov committed Oct 14, 2016
1 parent 48fd87e commit 5fe0678
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
4 changes: 1 addition & 3 deletions clang-tools-extra/clang-move/ClangMove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,8 @@ ClangMoveTool::ClangMoveTool(
}

void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
SmallVector<StringRef, 4> ClassNames;
llvm::StringRef(Spec.Names).split(ClassNames, ',');
Optional<ast_matchers::internal::Matcher<NamedDecl>> InMovedClassNames;
for (StringRef ClassName : ClassNames) {
for (StringRef ClassName : Spec.Names) {
llvm::StringRef GlobalClassName = ClassName.trim().ltrim(':');
const auto HasName = hasName(("::" + GlobalClassName).str());
InMovedClassNames =
Expand Down
5 changes: 2 additions & 3 deletions clang-tools-extra/clang-move/ClangMove.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ class ClangMoveTool : public ast_matchers::MatchFinder::MatchCallback {
};

struct MoveDefinitionSpec {
// A comma-separated list of fully qualified names, e.g. "Foo",
// "a::Foo, b::Foo".
std::string Names;
// The list of fully qualified names, e.g. Foo, a::Foo, b::Foo.
SmallVector<std::string, 4> Names;
// The file path of old header, can be relative path and absolute path.
std::string OldHeader;
// The file path of old cc, can be relative path and absolute path.
Expand Down
10 changes: 5 additions & 5 deletions clang-tools-extra/clang-move/tool/ClangMoveMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ std::error_code CreateNewFile(const llvm::Twine &path) {

cl::OptionCategory ClangMoveCategory("clang-move options");

cl::opt<std::string>
Names("names", cl::desc("A comma-separated list of the names of classes "
"being moved, e.g. \"Foo\", \"a::Foo, b::Foo\"."),
cl::cat(ClangMoveCategory));
cl::list<std::string> Names("names", cl::CommaSeparated, cl::OneOrMore,
cl::desc("The list of the names of classes being "
"moved, e.g. \"Foo,a::Foo,b::Foo\"."),
cl::cat(ClangMoveCategory));

cl::opt<std::string>
OldHeader("old_header",
Expand Down Expand Up @@ -90,7 +90,7 @@ int main(int argc, const char **argv) {
tooling::RefactoringTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());
move::ClangMoveTool::MoveDefinitionSpec Spec;
Spec.Names = Names;
Spec.Names = { Names.begin(), Names.end() };
Spec.OldHeader = OldHeader;
Spec.NewHeader = NewHeader;
Spec.OldCC = OldCC;
Expand Down
8 changes: 4 additions & 4 deletions clang-tools-extra/unittests/clang-move/ClangMoveTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ runClangMoveOnCode(const move::ClangMoveTool::MoveDefinitionSpec &Spec) {

TEST(ClangMove, MoveHeaderAndCC) {
move::ClangMoveTool::MoveDefinitionSpec Spec;
Spec.Names = "a::b::Foo";
Spec.Names = { "a::b::Foo" };
Spec.OldHeader = "foo.h";
Spec.OldCC = "foo.cc";
Spec.NewHeader = "new_foo.h";
Expand All @@ -228,7 +228,7 @@ TEST(ClangMove, MoveHeaderAndCC) {

TEST(ClangMove, MoveHeaderOnly) {
move::ClangMoveTool::MoveDefinitionSpec Spec;
Spec.Names = "a::b::Foo";
Spec.Names = { "a::b::Foo" };
Spec.OldHeader = "foo.h";
Spec.NewHeader = "new_foo.h";
auto Results = runClangMoveOnCode(Spec);
Expand All @@ -239,7 +239,7 @@ TEST(ClangMove, MoveHeaderOnly) {

TEST(ClangMove, MoveCCOnly) {
move::ClangMoveTool::MoveDefinitionSpec Spec;
Spec.Names = "a::b::Foo";
Spec.Names = { "a::b::Foo" };
Spec.OldCC = "foo.cc";
Spec.NewCC = "new_foo.cc";
std::string ExpectedHeader = "#include \"foo.h\"\n\n";
Expand All @@ -251,7 +251,7 @@ TEST(ClangMove, MoveCCOnly) {

TEST(ClangMove, MoveNonExistClass) {
move::ClangMoveTool::MoveDefinitionSpec Spec;
Spec.Names = "NonExistFoo";
Spec.Names = { "NonExistFoo" };
Spec.OldHeader = "foo.h";
Spec.OldCC = "foo.cc";
Spec.NewHeader = "new_foo.h";
Expand Down

0 comments on commit 5fe0678

Please sign in to comment.