From bee973f4df39f3eaf7fd91f4c3df6d0e64e9ee62 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 29 Dec 2019 14:51:22 +0000 Subject: [PATCH] Fix use of named values surrounded by newlines in clang-query --- .../unittests/clang-query/QueryParserTest.cpp | 19 +++++++++++++++++++ clang/lib/ASTMatchers/Dynamic/Parser.cpp | 15 ++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp b/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp index fa16c71..1f0bbfa 100644 --- a/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp +++ b/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp @@ -356,4 +356,23 @@ match callExpr ASSERT_TRUE(isa(Q)); EXPECT_EQ("1:1: Invalid token found when looking for a value.", cast(Q)->ErrStr); + + Q = parse(R"matcher( + +let Construct parmVarDecl() + +m parmVarDecl( + Construct +) +)matcher"); + + ASSERT_TRUE(isa(Q)); + { + llvm::raw_null_ostream NullOutStream; + dyn_cast(Q)->run(NullOutStream, QS); + } + + Q = parse(Q->RemainingContent); + + ASSERT_TRUE(isa(Q)); } diff --git a/clang/lib/ASTMatchers/Dynamic/Parser.cpp b/clang/lib/ASTMatchers/Dynamic/Parser.cpp index ef209d1..061da8b 100644 --- a/clang/lib/ASTMatchers/Dynamic/Parser.cpp +++ b/clang/lib/ASTMatchers/Dynamic/Parser.cpp @@ -354,13 +354,6 @@ struct Parser::ScopedContextEntry { bool Parser::parseIdentifierPrefixImpl(VariantValue *Value) { const TokenInfo NameToken = Tokenizer->consumeNextToken(); - if (Tokenizer->nextTokenKind() == TokenInfo::TK_NewLine) { - Error->addError(Tokenizer->peekNextToken().Range, - Error->ET_ParserNoOpenParen) - << "NewLine"; - return false; - } - if (Tokenizer->nextTokenKind() != TokenInfo::TK_OpenParen) { // Parse as a named value. if (const VariantValue NamedValue = @@ -388,6 +381,14 @@ bool Parser::parseIdentifierPrefixImpl(VariantValue *Value) { } return false; } + + if (Tokenizer->nextTokenKind() == TokenInfo::TK_NewLine) { + Error->addError(Tokenizer->peekNextToken().Range, + Error->ET_ParserNoOpenParen) + << "NewLine"; + return false; + } + // If the syntax is correct and the name is not a matcher either, report // unknown named value. if ((Tokenizer->nextTokenKind() == TokenInfo::TK_Comma || -- 2.7.4