Re-committing r253473 after hopefully fixing the bot breakage. There was a copy-pasta issue that my local testing did not catch.

llvm-svn: 253481
This commit is contained in:
Aaron Ballman 2015-11-18 17:56:55 +00:00
parent 763c4ab32d
commit 8e7f00b0eb
4 changed files with 147 additions and 0 deletions

View File

@ -1774,6 +1774,21 @@ cxxMethodDecl(isConst()) matches A::foo() but not A::bar()
</pre></td></tr> </pre></td></tr>
<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>&gt;</td><td class="name" onclick="toggle('isCopyAssignmentOperator0')"><a name="isCopyAssignmentOperator0Anchor">isCopyAssignmentOperator</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="isCopyAssignmentOperator0"><pre>Matches if the given method declaration declares a copy assignment
operator.
Given
struct A {
A &amp;operator=(const A &amp;);
A &amp;operator=(A &amp;&amp;);
};
cxxMethodDecl(isCopyAssignmentOperator()) matches the first method but not
the second one.
</pre></td></tr>
<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>&gt;</td><td class="name" onclick="toggle('isFinal1')"><a name="isFinal1Anchor">isFinal</a></td><td></td></tr> <tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>&gt;</td><td class="name" onclick="toggle('isFinal1')"><a name="isFinal1Anchor">isFinal</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="isFinal1"><pre>Matches if the given method or class declaration is final. <tr><td colspan="4" class="doc" id="isFinal1"><pre>Matches if the given method or class declaration is final.
@ -2749,6 +2764,20 @@ Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))
</pre></td></tr> </pre></td></tr>
<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;</td><td class="name" onclick="toggle('hasAutomaticStorageDuration0')"><a name="hasAutomaticStorageDuration0Anchor">hasAutomaticStorageDuration</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="hasAutomaticStorageDuration0"><pre>Matches a variable declaration that has automatic storage duration.
Example matches x, but not y, z, or a.
(matcher = varDecl(hasAutomaticStorageDuration())
void f() {
int x;
static int y;
thread_local int z;
}
int a;
</pre></td></tr>
<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;</td><td class="name" onclick="toggle('hasGlobalStorage0')"><a name="hasGlobalStorage0Anchor">hasGlobalStorage</a></td><td></td></tr> <tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;</td><td class="name" onclick="toggle('hasGlobalStorage0')"><a name="hasGlobalStorage0Anchor">hasGlobalStorage</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="hasGlobalStorage0"><pre>Matches a variable declaration that does not have local storage. <tr><td colspan="4" class="doc" id="hasGlobalStorage0"><pre>Matches a variable declaration that does not have local storage.
@ -2774,6 +2803,34 @@ int z;
</pre></td></tr> </pre></td></tr>
<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;</td><td class="name" onclick="toggle('hasStaticStorageDuration0')"><a name="hasStaticStorageDuration0Anchor">hasStaticStorageDuration</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="hasStaticStorageDuration0"><pre>Matches a variable declaration that has static storage duration.
Example matches y and a, but not x or z.
(matcher = varDecl(hasStaticStorageDuration())
void f() {
int x;
static int y;
thread_local int z;
}
int a;
</pre></td></tr>
<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;</td><td class="name" onclick="toggle('hasThreadStorageDuration0')"><a name="hasThreadStorageDuration0Anchor">hasThreadStorageDuration</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="hasThreadStorageDuration0"><pre>Matches a variable declaration that has thread storage duration.
Example matches z, but not x, z, or a.
(matcher = varDecl(hasThreadStorageDuration())
void f() {
int x;
static int y;
thread_local int z;
}
int a;
</pre></td></tr>
<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;</td><td class="name" onclick="toggle('isConstexpr0')"><a name="isConstexpr0Anchor">isConstexpr</a></td><td></td></tr> <tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>&gt;</td><td class="name" onclick="toggle('isConstexpr0')"><a name="isConstexpr0Anchor">isConstexpr</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="isConstexpr0"><pre>Matches constexpr variable and function declarations. <tr><td colspan="4" class="doc" id="isConstexpr0"><pre>Matches constexpr variable and function declarations.
@ -3040,6 +3097,22 @@ arraySubscriptExpression(hasIndex(integerLiteral()))
</pre></td></tr> </pre></td></tr>
<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</a>&gt;</td><td class="name" onclick="toggle('hasLHS1')"><a name="hasLHS1Anchor">hasLHS</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
<tr><td colspan="4" class="doc" id="hasLHS1"><pre>Matches the left hand side of binary operator expressions.
Example matches a (matcher = binaryOperator(hasLHS()))
a || b
</pre></td></tr>
<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ArraySubscriptExpr.html">ArraySubscriptExpr</a>&gt;</td><td class="name" onclick="toggle('hasRHS1')"><a name="hasRHS1Anchor">hasRHS</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>&gt; InnerMatcher</td></tr>
<tr><td colspan="4" class="doc" id="hasRHS1"><pre>Matches the right hand side of binary operator expressions.
Example matches b (matcher = binaryOperator(hasRHS()))
a || b
</pre></td></tr>
<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ArrayTypeLoc.html">ArrayTypeLoc</a>&gt;</td><td class="name" onclick="toggle('hasElementTypeLoc0')"><a name="hasElementTypeLoc0Anchor">hasElementTypeLoc</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>&gt;</td></tr> <tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ArrayTypeLoc.html">ArrayTypeLoc</a>&gt;</td><td class="name" onclick="toggle('hasElementTypeLoc0')"><a name="hasElementTypeLoc0Anchor">hasElementTypeLoc</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>&gt;</td></tr>
<tr><td colspan="4" class="doc" id="hasElementTypeLoc0"><pre>Matches arrays and C99 complex types that have a specific element <tr><td colspan="4" class="doc" id="hasElementTypeLoc0"><pre>Matches arrays and C99 complex types that have a specific element
type. type.

View File

@ -2544,6 +2544,54 @@ AST_MATCHER(VarDecl, hasGlobalStorage) {
return Node.hasGlobalStorage(); return Node.hasGlobalStorage();
} }
/// \brief Matches a variable declaration that has automatic storage duration.
///
/// Example matches x, but not y, z, or a.
/// (matcher = varDecl(hasAutomaticStorageDuration())
/// \code
/// void f() {
/// int x;
/// static int y;
/// thread_local int z;
/// }
/// int a;
/// \endcode
AST_MATCHER(VarDecl, hasAutomaticStorageDuration) {
return Node.getStorageDuration() == SD_Automatic;
}
/// \brief Matches a variable declaration that has static storage duration.
///
/// Example matches y and a, but not x or z.
/// (matcher = varDecl(hasStaticStorageDuration())
/// \code
/// void f() {
/// int x;
/// static int y;
/// thread_local int z;
/// }
/// int a;
/// \endcode
AST_MATCHER(VarDecl, hasStaticStorageDuration) {
return Node.getStorageDuration() == SD_Static;
}
/// \brief Matches a variable declaration that has thread storage duration.
///
/// Example matches z, but not x, z, or a.
/// (matcher = varDecl(hasThreadStorageDuration())
/// \code
/// void f() {
/// int x;
/// static int y;
/// thread_local int z;
/// }
/// int a;
/// \endcode
AST_MATCHER(VarDecl, hasThreadStorageDuration) {
return Node.getStorageDuration() == SD_Thread;
}
/// \brief Matches a variable declaration that is an exception variable from /// \brief Matches a variable declaration that is an exception variable from
/// a C++ catch block, or an Objective-C \@catch statement. /// a C++ catch block, or an Objective-C \@catch statement.
/// ///

View File

@ -194,6 +194,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(hasArgument); REGISTER_MATCHER(hasArgument);
REGISTER_MATCHER(hasArgumentOfType); REGISTER_MATCHER(hasArgumentOfType);
REGISTER_MATCHER(hasAttr); REGISTER_MATCHER(hasAttr);
REGISTER_MATCHER(hasAutomaticStorageDuration);
REGISTER_MATCHER(hasBase); REGISTER_MATCHER(hasBase);
REGISTER_MATCHER(hasBody); REGISTER_MATCHER(hasBody);
REGISTER_MATCHER(hasCanonicalType); REGISTER_MATCHER(hasCanonicalType);
@ -238,9 +239,11 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(hasSize); REGISTER_MATCHER(hasSize);
REGISTER_MATCHER(hasSizeExpr); REGISTER_MATCHER(hasSizeExpr);
REGISTER_MATCHER(hasSourceExpression); REGISTER_MATCHER(hasSourceExpression);
REGISTER_MATCHER(hasStaticStorageDuration);
REGISTER_MATCHER(hasTargetDecl); REGISTER_MATCHER(hasTargetDecl);
REGISTER_MATCHER(hasTemplateArgument); REGISTER_MATCHER(hasTemplateArgument);
REGISTER_MATCHER(hasThen); REGISTER_MATCHER(hasThen);
REGISTER_MATCHER(hasThreadStorageDuration);
REGISTER_MATCHER(hasTrueExpression); REGISTER_MATCHER(hasTrueExpression);
REGISTER_MATCHER(hasTypeLoc); REGISTER_MATCHER(hasTypeLoc);
REGISTER_MATCHER(hasUnaryOperand); REGISTER_MATCHER(hasUnaryOperand);

View File

@ -1355,6 +1355,29 @@ TEST(Matcher, VarDecl_Storage) {
EXPECT_TRUE(matches("void f() { static int X; }", M)); EXPECT_TRUE(matches("void f() { static int X; }", M));
} }
TEST(Matcher, VarDecl_StorageDuration) {
std::string T =
"void f() { int x; static int y; thread_local int z; } int a;";
EXPECT_TRUE(matches(T, varDecl(hasName("x"), hasAutomaticStorageDuration())));
EXPECT_TRUE(
notMatches(T, varDecl(hasName("y"), hasAutomaticStorageDuration())));
EXPECT_TRUE(
notMatches(T, varDecl(hasName("z"), hasAutomaticStorageDuration())));
EXPECT_TRUE(
notMatches(T, varDecl(hasName("a"), hasAutomaticStorageDuration())));
EXPECT_TRUE(matches(T, varDecl(hasName("y"), hasStaticStorageDuration())));
EXPECT_TRUE(matches(T, varDecl(hasName("a"), hasStaticStorageDuration())));
EXPECT_TRUE(notMatches(T, varDecl(hasName("x"), hasStaticStorageDuration())));
EXPECT_TRUE(notMatches(T, varDecl(hasName("z"), hasStaticStorageDuration())));
EXPECT_TRUE(matches(T, varDecl(hasName("z"), hasThreadStorageDuration())));
EXPECT_TRUE(notMatches(T, varDecl(hasName("x"), hasThreadStorageDuration())));
EXPECT_TRUE(notMatches(T, varDecl(hasName("y"), hasThreadStorageDuration())));
EXPECT_TRUE(notMatches(T, varDecl(hasName("a"), hasThreadStorageDuration())));
}
TEST(Matcher, FindsVarDeclInFunctionParameter) { TEST(Matcher, FindsVarDeclInFunctionParameter) {
EXPECT_TRUE(matches( EXPECT_TRUE(matches(
"void f(int i) {}", "void f(int i) {}",