r178556 - Adding a hasLocalQualifiers() AST Matcher.
Edwin Vane
edwin.vane at intel.com
Tue Apr 2 11:15:55 PDT 2013
Author: revane
Date: Tue Apr 2 13:15:55 2013
New Revision: 178556
URL: http://llvm.org/viewvc/llvm-project?rev=178556&view=rev
Log:
Adding a hasLocalQualifiers() AST Matcher.
Updated tests and docs.
Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
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=178556&r1=178555&r2=178556&view=diff
==============================================================================
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Tue Apr 2 13:15:55 2013
@@ -1840,6 +1840,21 @@ callExpr(on(hasType(asString("class Y *"
</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('hasLocalQualifiers0')"><a name="hasLocalQualifiers0Anchor">hasLocalQualifiers</a></td><td></td></tr>
+<tr><td colspan="4" class="doc" id="hasLocalQualifiers0"><pre>Matches QualType nodes that have local CV-qualifiers attached to
+the node, not hidden within a typedef.
+
+Given
+ typedef const int const_int;
+ const_int i;
+ int *const j;
+ int *volatile k;
+ int m;
+varDecl(hasType(hasLocalQualifiers())) matches only j and k.
+i is const-qualified but the qualifier is not local.
+</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.
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=178556&r1=178555&r2=178556&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Tue Apr 2 13:15:55 2013
@@ -2566,6 +2566,23 @@ AST_MATCHER(QualType, isConstQualified)
return Node.isConstQualified();
}
+/// \brief Matches QualType nodes that have local CV-qualifiers attached to
+/// the node, not hidden within a typedef.
+///
+/// Given
+/// \code
+/// typedef const int const_int;
+/// const_int i;
+/// int *const j;
+/// int *volatile k;
+/// int m;
+/// \endcode
+/// \c varDecl(hasType(hasLocalQualifiers())) matches only \c j and \c k.
+/// \c i is const-qualified but the qualifier is not local.
+AST_MATCHER(QualType, hasLocalQualifiers) {
+ return Node.hasLocalQualifiers();
+}
+
/// \brief Matches a member expression where the member is matched by a
/// given matcher.
///
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=178556&r1=178555&r2=178556&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Tue Apr 2 13:15:55 2013
@@ -1356,6 +1356,17 @@ TEST(QualType, hasCanonicalType) {
varDecl(hasType(qualType(hasCanonicalType(referenceType()))))));
}
+TEST(QualType, hasLocalQualifiers) {
+ EXPECT_TRUE(notMatches("typedef const int const_int; const_int i = 1;",
+ varDecl(hasType(hasLocalQualifiers()))));
+ EXPECT_TRUE(matches("int *const j = nullptr;",
+ varDecl(hasType(hasLocalQualifiers()))));
+ EXPECT_TRUE(matches("int *volatile k;",
+ varDecl(hasType(hasLocalQualifiers()))));
+ EXPECT_TRUE(notMatches("int m;",
+ varDecl(hasType(hasLocalQualifiers()))));
+}
+
TEST(HasParameter, CallsInnerMatcher) {
EXPECT_TRUE(matches("class X { void x(int) {} };",
methodDecl(hasParameter(0, varDecl()))));
More information about the cfe-commits
mailing list