summaryrefslogtreecommitdiffstats
path: root/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
diff options
context:
space:
mode:
authorSamuel Benzaquen <sbenza@google.com>2013-06-20 14:28:32 +0000
committerSamuel Benzaquen <sbenza@google.com>2013-06-20 14:28:32 +0000
commit81ef929b8f0fc5bbbe6d7edbde38670bd26f8a5e (patch)
treecf62c7e9897b154061b7c94e4e65b8c1bd23639c /clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
parentca692609d0547908b95e884b881a6bb2f985126b (diff)
downloadbcm5719-llvm-81ef929b8f0fc5bbbe6d7edbde38670bd26f8a5e.tar.gz
bcm5719-llvm-81ef929b8f0fc5bbbe6d7edbde38670bd26f8a5e.zip
Enhancements for the DynTypedMatcher system.
- Added conversion routines and checks in Matcher<T> that take a DynTypedMatcher. - Added type information on the error messages for the marshallers. - Allows future work on Polymorphic/overloaded matchers. We should be able to disambiguate at runtime and choose the appropriate overload. llvm-svn: 184429
Diffstat (limited to 'clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp')
-rw-r--r--clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
index b20c1ac6e9a..d7973c957f1 100644
--- a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -49,6 +49,9 @@ public:
StringRef boundID() const { return BoundID; }
+ virtual ast_type_traits::ASTNodeKind getSupportedKind() const {
+ return ast_type_traits::ASTNodeKind();
+ }
private:
uint64_t ID;
std::string BoundID;
@@ -172,15 +175,19 @@ TEST(ParserTest, ParseMatcher) {
using ast_matchers::internal::Matcher;
TEST(ParserTest, FullParserTest) {
- OwningPtr<DynTypedMatcher> Matcher(Parser::parseMatcherExpression(
- "hasInitializer(binaryOperator(hasLHS(integerLiteral())))", NULL));
- EXPECT_TRUE(matchesDynamic("int x = 1 + false;", *Matcher));
- EXPECT_FALSE(matchesDynamic("int x = true + 1;", *Matcher));
+ OwningPtr<DynTypedMatcher> VarDecl(Parser::parseMatcherExpression(
+ "varDecl(hasInitializer(binaryOperator(hasLHS(integerLiteral()))))",
+ NULL));
+ Matcher<Decl> M = Matcher<Decl>::constructFrom(*VarDecl);
+ EXPECT_TRUE(matches("int x = 1 + false;", M));
+ EXPECT_FALSE(matches("int x = true + 1;", M));
+
+ OwningPtr<DynTypedMatcher> HasParameter(Parser::parseMatcherExpression(
+ "functionDecl(hasParameter(1, hasName(\"x\")))", NULL));
+ M = Matcher<Decl>::constructFrom(*HasParameter);
- Matcher.reset(
- Parser::parseMatcherExpression("hasParameter(1, hasName(\"x\"))", NULL));
- EXPECT_TRUE(matchesDynamic("void f(int a, int x);", *Matcher));
- EXPECT_FALSE(matchesDynamic("void f(int x, int a);", *Matcher));
+ EXPECT_TRUE(matches("void f(int a, int x);", M));
+ EXPECT_FALSE(matches("void f(int x, int a);", M));
Diagnostics Error;
EXPECT_TRUE(Parser::parseMatcherExpression(
@@ -188,7 +195,8 @@ TEST(ParserTest, FullParserTest) {
EXPECT_EQ("1:1: Error parsing argument 1 for matcher hasInitializer.\n"
"2:5: Error parsing argument 1 for matcher binaryOperator.\n"
"2:20: Error building matcher hasLHS.\n"
- "2:27: Incorrect type on function hasLHS for arg 1.",
+ "2:27: Incorrect type for arg 1. "
+ "(Expected = Matcher<Expr>) != (Actual = String)",
Error.ToStringFull());
}
OpenPOWER on IntegriCloud