Author: aaronballman Date: Thu Feb 18 10:36:01 2016 New Revision: 261221 URL: http://llvm.org/viewvc/llvm-project?rev=261221&view=rev Log: Add an AST matcher for real floating-point types. e.g., float, double, long double, but not complex.
Modified: cfe/trunk/docs/LibASTMatchersReference.html cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Modified: cfe/trunk/docs/LibASTMatchersReference.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=261221&r1=261220&r2=261221&view=diff ============================================================================== --- cfe/trunk/docs/LibASTMatchersReference.html (original) +++ cfe/trunk/docs/LibASTMatchersReference.html Thu Feb 18 10:36:01 2016 @@ -2176,23 +2176,6 @@ fieldDecl(isPublic()) </pre></td></tr> -<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('nullPointerConstant0')"><a name="nullPointerConstant0Anchor">nullPointerConstant</a></td><td></td></tr> -<tr><td colspan="4" class="doc" id="nullPointerConstant0"><pre>Matches expressions that resolve to a null pointer constant, such as -GNU's __null, C++11's nullptr, or C's NULL macro. - -Given: - void *v1 = NULL; - void *v2 = nullptr; - void *v3 = __null; GNU extension - char *cp = (char *)0; - int *ip = 0; - int i = 0; -expr(nullPointerConstant()) - matches the initializer for v1, v2, v3, cp, and ip. Does not match the - initializer for i. -</pre></td></tr> - - <tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>></td><td class="name" onclick="toggle('equals1')"><a name="equals1Anchor">equals</a></td><td>ValueT Value</td></tr> <tr><td colspan="4" class="doc" id="equals1"><pre>Matches literals that are equal to the given value. @@ -2429,7 +2412,7 @@ memberExpr(isArrow()) </pre></td></tr> -<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>></td><td class="name" onclick="toggle('hasName0')"><a name="hasName0Anchor">hasName</a></td><td>std::string Name</td></tr> +<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>></td><td class="name" onclick="toggle('hasName0')"><a name="hasName0Anchor">hasName</a></td><td>std::string Name</td></tr> <tr><td colspan="4" class="doc" id="hasName0"><pre>Matches NamedDecl nodes that have the specified name. Supports specifying enclosing namespaces or classes by prefixing the name @@ -2621,6 +2604,17 @@ matches "a(char)", "b(wchar_t)", but not </pre></td></tr> +<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('isAnyPointer0')"><a name="isAnyPointer0Anchor">isAnyPointer</a></td><td></td></tr> +<tr><td colspan="4" class="doc" id="isAnyPointer0"><pre>Matches QualType nodes that are of any pointer type. + +Given + int *i = nullptr; + int j; +varDecl(hasType(isAnyPointer())) + matches "int *i", but not "int j". +</pre></td></tr> + + <tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('isConstQualified0')"><a name="isConstQualified0Anchor">isConstQualified</a></td><td></td></tr> <tr><td colspan="4" class="doc" id="isConstQualified0"><pre>Matches QualType nodes that are const-qualified, i.e., that include "top-level" const. @@ -2894,6 +2888,17 @@ and reference to that variable declarati </pre></td></tr> +<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('realFloatingPointType0')"><a name="realFloatingPointType0Anchor">realFloatingPointType</a></td><td></td></tr> +<tr><td colspan="4" class="doc" id="realFloatingPointType0"><pre>Matches any real floating-point type (float, double, long double). + +Given + int i; + float f; +realFloatingPointType() + matches "float f" but not "int i" +</pre></td></tr> + + <tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td><td class="name" onclick="toggle('voidType0')"><a name="voidType0Anchor">voidType</a></td><td></td></tr> <tr><td colspan="4" class="doc" id="voidType0"><pre>Matches type void. @@ -3080,6 +3085,23 @@ functionDecl(isInstantiated()) </pre></td></tr> +<tr><td>Matcher<internal::Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>>></td><td class="name" onclick="toggle('nullPointerConstant0')"><a name="nullPointerConstant0Anchor">nullPointerConstant</a></td><td></td></tr> +<tr><td colspan="4" class="doc" id="nullPointerConstant0"><pre>Matches expressions that resolve to a null pointer constant, such as +GNU's __null, C++11's nullptr, or C's NULL macro. + +Given: + void *v1 = NULL; + void *v2 = nullptr; + void *v3 = __null; GNU extension + char *cp = (char *)0; + int *ip = 0; + int i = 0; +expr(nullPointerConstant()) + matches the initializer for v1, v2, v3, cp, and ip. Does not match the + initializer for i. +</pre></td></tr> + + <tr><td>Matcher<internal::Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>>></td><td class="name" onclick="toggle('isInTemplateInstantiation0')"><a name="isInTemplateInstantiation0Anchor">isInTemplateInstantiation</a></td><td></td></tr> <tr><td colspan="4" class="doc" id="isInTemplateInstantiation0"><pre>Matches statements inside of a template instantiation. Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=261221&r1=261220&r2=261221&view=diff ============================================================================== --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original) +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Thu Feb 18 10:36:01 2016 @@ -3961,6 +3961,19 @@ AST_TYPE_MATCHER(ArrayType, arrayType); /// matches "_Complex float f" AST_TYPE_MATCHER(ComplexType, complexType); +/// \brief Matches any real floating-point type (float, double, long double). +/// +/// Given +/// \code +/// int i; +/// float f; +/// \endcode +/// realFloatingPointType() +/// matches "float f" but not "int i" +AST_MATCHER(Type, realFloatingPointType) { + return Node.isRealFloatingType(); +} + /// \brief Matches arrays and C99 complex types that have a specific element /// type. /// Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=261221&r1=261220&r2=261221&view=diff ============================================================================== --- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original) +++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Thu Feb 18 10:36:01 2016 @@ -342,6 +342,7 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(pointee); REGISTER_MATCHER(pointerType); REGISTER_MATCHER(qualType); + REGISTER_MATCHER(realFloatingPointType); REGISTER_MATCHER(recordDecl); REGISTER_MATCHER(recordType); REGISTER_MATCHER(referenceType); Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=261221&r1=261220&r2=261221&view=diff ============================================================================== --- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original) +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Thu Feb 18 10:36:01 2016 @@ -4415,6 +4415,15 @@ TEST(TypeMatching, MatchesVoid) { cxxMethodDecl(returns(voidType())))); } +TEST(TypeMatching, MatchesRealFloats) { + EXPECT_TRUE(matches("struct S { float func(); };", + cxxMethodDecl(returns(realFloatingPointType())))); + EXPECT_TRUE(notMatches("struct S { int func(); };", + cxxMethodDecl(returns(realFloatingPointType())))); + EXPECT_TRUE(matches("struct S { long double func(); };", + cxxMethodDecl(returns(realFloatingPointType())))); +} + TEST(TypeMatching, MatchesArrayTypes) { EXPECT_TRUE(matches("int a[] = {2,3};", arrayType())); EXPECT_TRUE(matches("int a[42];", arrayType())); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits