steveire created this revision. steveire added a reviewer: aaron.ballman. Herald added subscribers: cfe-commits, mgorny.
It is possible to pass a file of commands to clang-query using the command line option -f or --preload. Make it possible to write comments in such files. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D52752 Files: CMakeLists.txt clang-query/QueryParser.cpp unittests/clang-query/QueryParserTest.cpp Index: unittests/clang-query/QueryParserTest.cpp =================================================================== --- unittests/clang-query/QueryParserTest.cpp +++ unittests/clang-query/QueryParserTest.cpp @@ -146,6 +146,17 @@ cast<InvalidQuery>(Q)->ErrStr); } +TEST_F(QueryParserTest, Comment) { + QueryRef Q = parse("# let foo decl()"); + ASSERT_TRUE(isa<NoOpQuery>(Q)); + + Q = parse("let foo decl() # creates a decl() matcher called foo"); + ASSERT_TRUE(isa<LetQuery>(Q)); + + Q = parse("set bind-root false # reduce noise"); + ASSERT_TRUE(isa<SetQuery<bool>>(Q)); +} + TEST_F(QueryParserTest, Complete) { std::vector<llvm::LineEditor::Completion> Comps = QueryParser::complete("", 0, QS); Index: clang-query/QueryParser.cpp =================================================================== --- clang-query/QueryParser.cpp +++ clang-query/QueryParser.cpp @@ -37,6 +37,11 @@ ++Begin; } + if (*Begin == '#') { + End = Begin; + return StringRef(Begin, 0); + } + const char *WordBegin = Begin; while (true) { @@ -127,6 +132,7 @@ enum ParsedQueryKind { PQK_Invalid, + PQK_Comment, PQK_NoOp, PQK_Help, PQK_Let, @@ -161,6 +167,7 @@ StringRef CommandStr; ParsedQueryKind QKind = LexOrCompleteWord<ParsedQueryKind>(this, CommandStr) .Case("", PQK_NoOp) + .Case("#", PQK_Comment, /*IsCompletion=*/false) .Case("help", PQK_Help) .Case("l", PQK_Let, /*IsCompletion=*/false) .Case("let", PQK_Let) @@ -173,6 +180,7 @@ .Default(PQK_Invalid); switch (QKind) { + case PQK_Comment: case PQK_NoOp: return new NoOpQuery; Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -1,21 +1,21 @@ -add_subdirectory(clang-apply-replacements) -add_subdirectory(clang-reorder-fields) -add_subdirectory(modularize) +# add_subdirectory(clang-apply-replacements) +# add_subdirectory(clang-reorder-fields) +# add_subdirectory(modularize) add_subdirectory(clang-tidy) add_subdirectory(clang-tidy-vs) -add_subdirectory(change-namespace) -add_subdirectory(clang-doc) +# add_subdirectory(change-namespace) +# add_subdirectory(clang-doc) add_subdirectory(clang-query) -add_subdirectory(clang-move) -add_subdirectory(clangd) -add_subdirectory(include-fixer) -add_subdirectory(pp-trace) -add_subdirectory(tool-template) +# add_subdirectory(clang-move) +# # add_subdirectory(clangd) +# add_subdirectory(include-fixer) +# add_subdirectory(pp-trace) +# add_subdirectory(tool-template) # Add the common testsuite after all the tools. if(CLANG_INCLUDE_TESTS) -add_subdirectory(test) +# add_subdirectory(test) add_subdirectory(unittests) endif()
Index: unittests/clang-query/QueryParserTest.cpp =================================================================== --- unittests/clang-query/QueryParserTest.cpp +++ unittests/clang-query/QueryParserTest.cpp @@ -146,6 +146,17 @@ cast<InvalidQuery>(Q)->ErrStr); } +TEST_F(QueryParserTest, Comment) { + QueryRef Q = parse("# let foo decl()"); + ASSERT_TRUE(isa<NoOpQuery>(Q)); + + Q = parse("let foo decl() # creates a decl() matcher called foo"); + ASSERT_TRUE(isa<LetQuery>(Q)); + + Q = parse("set bind-root false # reduce noise"); + ASSERT_TRUE(isa<SetQuery<bool>>(Q)); +} + TEST_F(QueryParserTest, Complete) { std::vector<llvm::LineEditor::Completion> Comps = QueryParser::complete("", 0, QS); Index: clang-query/QueryParser.cpp =================================================================== --- clang-query/QueryParser.cpp +++ clang-query/QueryParser.cpp @@ -37,6 +37,11 @@ ++Begin; } + if (*Begin == '#') { + End = Begin; + return StringRef(Begin, 0); + } + const char *WordBegin = Begin; while (true) { @@ -127,6 +132,7 @@ enum ParsedQueryKind { PQK_Invalid, + PQK_Comment, PQK_NoOp, PQK_Help, PQK_Let, @@ -161,6 +167,7 @@ StringRef CommandStr; ParsedQueryKind QKind = LexOrCompleteWord<ParsedQueryKind>(this, CommandStr) .Case("", PQK_NoOp) + .Case("#", PQK_Comment, /*IsCompletion=*/false) .Case("help", PQK_Help) .Case("l", PQK_Let, /*IsCompletion=*/false) .Case("let", PQK_Let) @@ -173,6 +180,7 @@ .Default(PQK_Invalid); switch (QKind) { + case PQK_Comment: case PQK_NoOp: return new NoOpQuery; Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -1,21 +1,21 @@ -add_subdirectory(clang-apply-replacements) -add_subdirectory(clang-reorder-fields) -add_subdirectory(modularize) +# add_subdirectory(clang-apply-replacements) +# add_subdirectory(clang-reorder-fields) +# add_subdirectory(modularize) add_subdirectory(clang-tidy) add_subdirectory(clang-tidy-vs) -add_subdirectory(change-namespace) -add_subdirectory(clang-doc) +# add_subdirectory(change-namespace) +# add_subdirectory(clang-doc) add_subdirectory(clang-query) -add_subdirectory(clang-move) -add_subdirectory(clangd) -add_subdirectory(include-fixer) -add_subdirectory(pp-trace) -add_subdirectory(tool-template) +# add_subdirectory(clang-move) +# # add_subdirectory(clangd) +# add_subdirectory(include-fixer) +# add_subdirectory(pp-trace) +# add_subdirectory(tool-template) # Add the common testsuite after all the tools. if(CLANG_INCLUDE_TESTS) -add_subdirectory(test) +# add_subdirectory(test) add_subdirectory(unittests) endif()
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits