forked from OSchip/llvm-project
Add matcher for float literals.
Patch by Chris Gray! Thanks! llvm-svn: 187232
This commit is contained in:
parent
0b40014d4e
commit
91f1c8ca27
|
@ -1069,15 +1069,25 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
Stmt,
|
||||
CharacterLiteral> characterLiteral;
|
||||
|
||||
/// \brief Matches integer literals of all sizes / encodings.
|
||||
/// \brief Matches integer literals of all sizes / encodings, e.g.
|
||||
/// 1, 1L, 0x1 and 1U.
|
||||
///
|
||||
/// Not matching character-encoded integers such as L'a'.
|
||||
///
|
||||
/// Example matches 1, 1L, 0x1, 1U
|
||||
/// Does not match character-encoded integers such as L'a'.
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
IntegerLiteral> integerLiteral;
|
||||
|
||||
/// \brief Matches float literals of all sizes / encodings, e.g.
|
||||
/// 1.0, 1.0f, 1.0L and 1e10.
|
||||
///
|
||||
/// Does not match implicit conversions such as
|
||||
/// \code
|
||||
/// float a = 10;
|
||||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
FloatingLiteral> floatLiteral;
|
||||
|
||||
/// \brief Matches user defined literal operator call.
|
||||
///
|
||||
/// Example match: "foo"_suffix
|
||||
|
|
|
@ -252,6 +252,7 @@ RegistryMaps::RegistryMaps() {
|
|||
REGISTER_MATCHER(explicitCastExpr);
|
||||
REGISTER_MATCHER(expr);
|
||||
REGISTER_MATCHER(fieldDecl);
|
||||
REGISTER_MATCHER(floatLiteral);
|
||||
REGISTER_MATCHER(forField);
|
||||
REGISTER_MATCHER(forRangeStmt);
|
||||
REGISTER_MATCHER(forStmt);
|
||||
|
|
|
@ -1853,6 +1853,17 @@ TEST(Matcher, IntegerLiterals) {
|
|||
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()));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue