[PATCH] Add floatLiteral to ASTMatchers

Daniel Jasper djasper at google.com
Fri Jul 26 11:55:20 PDT 2013


Committed as r187232. Thank you!


On Fri, Jul 26, 2013 at 8:14 PM, Chris Gray <chrismgray at gmail.com> wrote:

> 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);
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130726/32d6fabe/attachment.html>


More information about the cfe-commits mailing list