[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

llvm-svn: 343666
This commit is contained in:
Stephen Kelly 2018-10-03 08:21:54 +00:00
parent 7c787b8adf
commit 2c4079c090
2 changed files with 19 additions and 0 deletions

View File

@ -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;

View File

@ -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);