diff options
author | Peter Wu <peter@lekensteyn.nl> | 2017-06-08 22:00:58 +0000 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2017-06-08 22:00:58 +0000 |
commit | a9244b57ff3a319961f32facfa551888b8a20279 (patch) | |
tree | 2cc51db06c9a7ebc52fe97a762101c7854a60ff7 /clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp | |
parent | 2bbed50a45c5fc445de3fe87cbac13dbbed38c53 (diff) | |
download | bcm5719-llvm-a9244b57ff3a319961f32facfa551888b8a20279.tar.gz bcm5719-llvm-a9244b57ff3a319961f32facfa551888b8a20279.zip |
[ASTMatchers] Add clang-query support for equals matcher
Summary:
This allows the clang-query tool to use matchers like
"integerLiteral(equals(32))". For this to work, an overloaded function
is added for each possible parameter type.
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D33094
llvm-svn: 305022
Diffstat (limited to 'clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp')
-rw-r--r-- | clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp b/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp index 6bbbc2bd356..84e31f721a9 100644 --- a/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp +++ b/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp @@ -511,6 +511,46 @@ TEST_F(RegistryTest, ParenExpr) { EXPECT_FALSE(matches("int i = 1;", Value)); } +TEST_F(RegistryTest, EqualsMatcher) { + Matcher<Stmt> BooleanStmt = constructMatcher( + "cxxBoolLiteral", constructMatcher("equals", VariantValue(true))) + .getTypedMatcher<Stmt>(); + EXPECT_TRUE(matches("bool x = true;", BooleanStmt)); + EXPECT_FALSE(matches("bool x = false;", BooleanStmt)); + EXPECT_FALSE(matches("bool x = 0;", BooleanStmt)); + + BooleanStmt = constructMatcher( + "cxxBoolLiteral", constructMatcher("equals", VariantValue(0))) + .getTypedMatcher<Stmt>(); + EXPECT_TRUE(matches("bool x = false;", BooleanStmt)); + EXPECT_FALSE(matches("bool x = true;", BooleanStmt)); + EXPECT_FALSE(matches("bool x = 0;", BooleanStmt)); + + Matcher<Stmt> DoubleStmt = constructMatcher( + "floatLiteral", constructMatcher("equals", VariantValue(1.2))) + .getTypedMatcher<Stmt>(); + EXPECT_TRUE(matches("double x = 1.2;", DoubleStmt)); + EXPECT_TRUE(matches("double x = 1.2f;", DoubleStmt)); + EXPECT_TRUE(matches("double x = 1.2l;", DoubleStmt)); + EXPECT_TRUE(matches("double x = 12e-1;", DoubleStmt)); + EXPECT_FALSE(matches("double x = 1.23;", DoubleStmt)); + + Matcher<Stmt> IntegerStmt = constructMatcher( + "integerLiteral", constructMatcher("equals", VariantValue(42))) + .getTypedMatcher<Stmt>(); + EXPECT_TRUE(matches("int x = 42;", IntegerStmt)); + EXPECT_FALSE(matches("int x = 1;", IntegerStmt)); + + Matcher<Stmt> CharStmt = constructMatcher( + "characterLiteral", constructMatcher("equals", VariantValue('x'))) + .getTypedMatcher<Stmt>(); + EXPECT_TRUE(matches("int x = 'x';", CharStmt)); + EXPECT_TRUE(matches("int x = L'x';", CharStmt)); + EXPECT_TRUE(matches("int x = u'x';", CharStmt)); + EXPECT_TRUE(matches("int x = U'x';", CharStmt)); + EXPECT_FALSE(matches("int x = 120;", CharStmt)); +} + } // end anonymous namespace } // end namespace dynamic } // end namespace ast_matchers |