r343665 - Allow comments with '#' in dynamic AST Matchers
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 3 00:56:43 PDT 2018
Author: steveire
Date: Wed Oct 3 00:56:43 2018
New Revision: 343665
URL: http://llvm.org/viewvc/llvm-project?rev=343665&view=rev
Log:
Allow comments with '#' in dynamic AST Matchers
Summary: This is necessary for clang-query to be able to handle comments.
Reviewers: aaron.ballman
Reviewed By: aaron.ballman
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D52751
Modified:
cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp
cfe/trunk/unittests/ASTMatchers/Dynamic/ParserTest.cpp
Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp?rev=343665&r1=343664&r2=343665&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp Wed Oct 3 00:56:43 2018
@@ -110,6 +110,10 @@ private:
}
switch (Code[0]) {
+ case '#':
+ Result.Kind = TokenInfo::TK_Eof;
+ Result.Text = "";
+ return Result;
case ',':
Result.Kind = TokenInfo::TK_Comma;
Result.Text = Code.substr(0, 1);
Modified: cfe/trunk/unittests/ASTMatchers/Dynamic/ParserTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/Dynamic/ParserTest.cpp?rev=343665&r1=343664&r2=343665&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/Dynamic/ParserTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/Dynamic/ParserTest.cpp Wed Oct 3 00:56:43 2018
@@ -148,8 +148,8 @@ TEST(ParserTest, ParseMatcher) {
const uint64_t ExpectedBar = Sema.expectMatcher("Bar");
const uint64_t ExpectedBaz = Sema.expectMatcher("Baz");
Sema.parse(" Foo ( Bar ( 17), Baz( \n \"B A,Z\") ) .bind( \"Yo!\") ");
- for (size_t i = 0, e = Sema.Errors.size(); i != e; ++i) {
- EXPECT_EQ("", Sema.Errors[i]);
+ for (const auto &E : Sema.Errors) {
+ EXPECT_EQ("", E);
}
EXPECT_NE(ExpectedFoo, ExpectedBar);
@@ -181,6 +181,21 @@ TEST(ParserTest, ParseMatcher) {
EXPECT_EQ("Yo!", Foo.BoundID);
}
+TEST(ParserTest, ParseComment) {
+ MockSema Sema;
+ const uint64_t ExpectedFoo = Sema.expectMatcher("Foo");
+ Sema.parse(" Foo() # Bar() ");
+ for (const auto &E : Sema.Errors) {
+ EXPECT_EQ("", E);
+ }
+
+ EXPECT_EQ(1ULL, Sema.Matchers.size());
+
+ Sema.parse("Foo(#) ");
+
+ EXPECT_EQ("1:4: Error parsing matcher. Found end-of-code while looking for ')'.", Sema.Errors[1]);
+}
+
using ast_matchers::internal::Matcher;
Parser::NamedValueMap getTestNamedValues() {
More information about the cfe-commits
mailing list