Author: alexshap Date: Fri Oct 14 18:16:25 2016 New Revision: 284291 URL: http://llvm.org/viewvc/llvm-project?rev=284291&view=rev Log: [clang-move] Use cl::list for the list of names
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 Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp clang-tools-extra/trunk/clang-move/ClangMove.h clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=284291&r1=284290&r2=284291&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original) +++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Fri Oct 14 18:16:25 2016 @@ -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 = Modified: clang-tools-extra/trunk/clang-move/ClangMove.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.h?rev=284291&r1=284290&r2=284291&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-move/ClangMove.h (original) +++ clang-tools-extra/trunk/clang-move/ClangMove.h Fri Oct 14 18:16:25 2016 @@ -37,9 +37,8 @@ public: }; 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. Modified: clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp?rev=284291&r1=284290&r2=284291&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp (original) +++ clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp Fri Oct 14 18:16:25 2016 @@ -38,10 +38,10 @@ std::error_code CreateNewFile(const llvm 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", @@ -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; Modified: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp?rev=284291&r1=284290&r2=284291&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp Fri Oct 14 18:16:25 2016 @@ -213,7 +213,7 @@ runClangMoveOnCode(const move::ClangMove 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"; @@ -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); @@ -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"; @@ -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"; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits