Add an AST matcher for real floating-point types. e.g., float, double, long double, but not complex.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@261221 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Aaron Ballman 2016-02-18 16:36:01 +00:00
Родитель 98c4d57826
Коммит 005df9362e
4 изменённых файлов: 63 добавлений и 18 удалений

Просмотреть файл

@ -2176,23 +2176,6 @@ fieldDecl(isPublic())
</pre></td></tr>
<tr><td>Matcher&lt;<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;</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&lt;<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>&gt;</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&lt;<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>&gt;</td><td class="name" onclick="toggle('hasName0')"><a name="hasName0Anchor">hasName</a></td><td>std::string Name</td></tr>
<tr><td>Matcher&lt;<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">NamedDecl</a>&gt;</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 "c(double)".
</pre></td></tr>
<tr><td>Matcher&lt;<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt;</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&lt;<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>&gt;</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 declaration within a compound statement.
</pre></td></tr>
<tr><td>Matcher&lt;<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>&gt;</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&lt;<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>&gt;</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&lt;internal::Matcher&lt;<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt;&gt;</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&lt;internal::Matcher&lt;<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;&gt;</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.

Просмотреть файл

@ -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.
///

Просмотреть файл

@ -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);

Просмотреть файл

@ -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()));