summaryrefslogtreecommitdiffstats
path: root/clang/unittests/ASTMatchers/Dynamic
diff options
context:
space:
mode:
authorSamuel Benzaquen <sbenza@google.com>2013-08-27 16:04:53 +0000
committerSamuel Benzaquen <sbenza@google.com>2013-08-27 16:04:53 +0000
commitfe48aaf1a4aa0cf13bdd8c1754de11b39f03290f (patch)
treeb12d53816fadd5650445ec3373767bca8f18bdb4 /clang/unittests/ASTMatchers/Dynamic
parent3407030d12f7be88cb4852003176493c714f554a (diff)
downloadbcm5719-llvm-fe48aaf1a4aa0cf13bdd8c1754de11b39f03290f.tar.gz
bcm5719-llvm-fe48aaf1a4aa0cf13bdd8c1754de11b39f03290f.zip
Add support for eachOf/allOf/anyOf variadic matchers in the dynamic layer.
Summary: Add support for eachOf/allOf/anyOf variadic matchers in the dynamic layer. These function require some late binding behavior for the type conversions, thus changes in VariadicValue's MatcherList. Reviewers: klimek CC: cfe-commits, revane Differential Revision: http://llvm-reviews.chandlerc.com/D1531 llvm-svn: 189362
Diffstat (limited to 'clang/unittests/ASTMatchers/Dynamic')
-rw-r--r--clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp4
-rw-r--r--clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp45
2 files changed, 47 insertions, 2 deletions
diff --git a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
index 71b0f87e027..9116ab8a9f3 100644
--- a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -137,9 +137,9 @@ bool matchesRange(const SourceRange &Range, unsigned StartLine,
Range.Start.Column == StartColumn && Range.End.Column == EndColumn;
}
-const DynTypedMatcher *getSingleMatcher(const VariantValue &value) {
+const DynTypedMatcher *getSingleMatcher(const VariantValue &Value) {
const DynTypedMatcher *Out;
- EXPECT_TRUE(value.getMatcher().getSingleMatcher(Out));
+ EXPECT_TRUE(Value.getMatcher().getSingleMatcher(Out));
return Out;
}
diff --git a/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp b/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
index 55490a5bab9..874a4f35a0b 100644
--- a/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
+++ b/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
@@ -261,6 +261,33 @@ TEST_F(RegistryTest, Adaptative) {
EXPECT_FALSE(matches("void foo() { if (true) return; }", S));
}
+TEST_F(RegistryTest, VariadicOp) {
+ Matcher<Decl> D = constructMatcher(
+ "anyOf", constructMatcher("recordDecl"),
+ constructMatcher("namedDecl",
+ constructMatcher("hasName", std::string("foo"))))
+ .getTypedMatcher<Decl>();
+
+ EXPECT_TRUE(matches("void foo(){}", D));
+ EXPECT_TRUE(matches("struct Foo{};", D));
+ EXPECT_FALSE(matches("int i = 0;", D));
+
+ D = constructMatcher(
+ "allOf", constructMatcher("recordDecl"),
+ constructMatcher(
+ "namedDecl",
+ constructMatcher("anyOf",
+ constructMatcher("hasName", std::string("Foo")),
+ constructMatcher("hasName", std::string("Bar")))))
+ .getTypedMatcher<Decl>();
+
+ EXPECT_FALSE(matches("void foo(){}", D));
+ EXPECT_TRUE(matches("struct Foo{};", D));
+ EXPECT_FALSE(matches("int i = 0;", D));
+ EXPECT_TRUE(matches("class Bar{};", D));
+ EXPECT_FALSE(matches("class OtherBar{};", D));
+}
+
TEST_F(RegistryTest, Errors) {
// Incorrect argument count.
OwningPtr<Diagnostics> Error(new Diagnostics());
@@ -285,6 +312,24 @@ TEST_F(RegistryTest, Errors) {
EXPECT_EQ("Incorrect type for arg 2. (Expected = Matcher<CXXRecordDecl>) != "
"(Actual = Matcher<FunctionDecl>)",
Error->toString());
+
+ // Bad argument type with variadic.
+ Error.reset(new Diagnostics());
+ EXPECT_TRUE(constructMatcher("anyOf", std::string(), Error.get()).isNull());
+ EXPECT_EQ(
+ "Incorrect type for arg 1. (Expected = Matcher<>) != (Actual = String)",
+ Error->toString());
+ Error.reset(new Diagnostics());
+ EXPECT_TRUE(constructMatcher(
+ "recordDecl",
+ constructMatcher("allOf",
+ constructMatcher("isDerivedFrom", std::string("FOO")),
+ constructMatcher("isArrow")),
+ Error.get()).isNull());
+ EXPECT_EQ("Incorrect type for arg 1. "
+ "(Expected = Matcher<CXXRecordDecl>) != "
+ "(Actual = Matcher<CXXRecordDecl>&Matcher<MemberExpr>)",
+ Error->toString());
}
} // end anonymous namespace
OpenPOWER on IntegriCloud