[clang-tools-extra] r343666 - [clang-query] Add comment token handling
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 3 01:21:54 PDT 2018
Author: steveire
Date: Wed Oct 3 01:21:54 2018
New Revision: 343666
URL: http://llvm.org/viewvc/llvm-project?rev=343666&view=rev
Log:
[clang-query] Add comment token handling
Summary:
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.
Reviewers: aaron.ballman
Reviewed By: aaron.ballman
Subscribers: mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D52752
Modified:
clang-tools-extra/trunk/clang-query/QueryParser.cpp
clang-tools-extra/trunk/unittests/clang-query/QueryParserTest.cpp
Modified: clang-tools-extra/trunk/clang-query/QueryParser.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-query/QueryParser.cpp?rev=343666&r1=343665&r2=343666&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-query/QueryParser.cpp (original)
+++ clang-tools-extra/trunk/clang-query/QueryParser.cpp Wed Oct 3 01:21:54 2018
@@ -37,6 +37,11 @@ StringRef QueryParser::lexWord() {
++Begin;
}
+ if (*Begin == '#') {
+ End = Begin;
+ return StringRef();
+ }
+
const char *WordBegin = Begin;
while (true) {
@@ -127,6 +132,7 @@ namespace {
enum ParsedQueryKind {
PQK_Invalid,
+ PQK_Comment,
PQK_NoOp,
PQK_Help,
PQK_Let,
@@ -161,6 +167,7 @@ QueryRef QueryParser::doParse() {
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 @@ QueryRef QueryParser::doParse() {
.Default(PQK_Invalid);
switch (QKind) {
+ case PQK_Comment:
case PQK_NoOp:
return new NoOpQuery;
Modified: clang-tools-extra/trunk/unittests/clang-query/QueryParserTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-query/QueryParserTest.cpp?rev=343666&r1=343665&r2=343666&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-query/QueryParserTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-query/QueryParserTest.cpp Wed Oct 3 01:21:54 2018
@@ -146,6 +146,17 @@ TEST_F(QueryParserTest, LetUnlet) {
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);
More information about the cfe-commits
mailing list