[PATCH] Add floatLiteral to ASTMatchers
Chris Gray
chrismgray at gmail.com
Fri Jul 26 11:14:16 PDT 2013
Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h (revision 187216)
+++ include/clang/ASTMatchers/ASTMatchers.h (working copy)
@@ -1078,6 +1078,18 @@
Stmt,
IntegerLiteral> integerLiteral;
+/// \brief Matches float literals of all sizes / encodings.
+///
+/// Not matching implicit conversions such as
+/// \code
+/// float a = 10;
+/// \endcode
+///
+/// Example matches 1.0, 1.0f, 1.0L, 1e10
+const internal::VariadicDynCastAllOfMatcher<
+ Stmt,
+ FloatingLiteral> floatLiteral;
+
/// \brief Matches user defined literal operator call.
///
/// Example match: "foo"_suffix
Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===================================================================
--- unittests/ASTMatchers/ASTMatchersTest.cpp (revision 187216)
+++ unittests/ASTMatchers/ASTMatchersTest.cpp (working copy)
@@ -1853,6 +1853,17 @@
EXPECT_TRUE(notMatches("int i = 10.0;", HasIntLiteral));
}
+TEST(Matcher, FloatLiterals) {
+ StatementMatcher HasFloatLiteral = floatLiteral();
+ EXPECT_TRUE(matches("float i = 10.0;", HasFloatLiteral));
+ EXPECT_TRUE(matches("float i = 10.0f;", HasFloatLiteral));
+ EXPECT_TRUE(matches("double i = 10.0;", HasFloatLiteral));
+ EXPECT_TRUE(matches("double i = 10.0L;", HasFloatLiteral));
+ EXPECT_TRUE(matches("double i = 1e10;", HasFloatLiteral));
+
+ EXPECT_TRUE(notMatches("float i = 10;", HasFloatLiteral));
+}
+
TEST(Matcher, NullPtrLiteral) {
EXPECT_TRUE(matches("int* i = nullptr;", nullPtrLiteralExpr()));
}
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===================================================================
--- lib/ASTMatchers/Dynamic/Registry.cpp (revision 187216)
+++ lib/ASTMatchers/Dynamic/Registry.cpp (working copy)
@@ -252,6 +252,7 @@
REGISTER_MATCHER(explicitCastExpr);
REGISTER_MATCHER(expr);
REGISTER_MATCHER(fieldDecl);
+ REGISTER_MATCHER(floatLiteral);
REGISTER_MATCHER(forField);
REGISTER_MATCHER(forRangeStmt);
REGISTER_MATCHER(forStmt);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130726/8f43f5b9/attachment.html>
More information about the cfe-commits
mailing list