summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2014-09-04 08:51:06 +0000
committerManuel Klimek <klimek@google.com>2014-09-04 08:51:06 +0000
commit94ad0bf10d5b9f2875485e8c7c70d8c2dc1d577c (patch)
tree0fe9fe1f7e69ee403d4e600cf931e024b5e5a6ee
parent0f54a0b02ad2c649fa6910a75b1a4d72d104a5a9 (diff)
downloadbcm5719-llvm-94ad0bf10d5b9f2875485e8c7c70d8c2dc1d577c.tar.gz
bcm5719-llvm-94ad0bf10d5b9f2875485e8c7c70d8c2dc1d577c.zip
Add matcher for linkage specification
Patch by Jacques Pienaar. llvm-svn: 217135
-rw-r--r--clang/docs/LibASTMatchersReference.html10
-rw-r--r--clang/include/clang/ASTMatchers/ASTMatchers.h11
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersTest.cpp5
3 files changed, 26 insertions, 0 deletions
diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html
index 1a494e6aea4..2c2b68de93f 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -246,6 +246,16 @@ Example matches f
</pre></td></tr>
+<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('linkageSpecDecl0')"><a name="linkageSpecDecl0Anchor">linkageSpecDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1LinkageSpecDecl.html">LinkageSpecDecl</a>&gt;...</td></tr>
+<tr><td colspan="4" class="doc" id="linkageSpecDecl0"><pre>Matches a declaration of a linkage specification.
+
+Given
+ extern "C" {}
+linkageSpecDecl()
+ matches "extern "C" {}"
+</pre></td></tr>
+
+
<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('methodDecl0')"><a name="methodDecl0Anchor">methodDecl</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>&gt;...</td></tr>
<tr><td colspan="4" class="doc" id="methodDecl0"><pre>Matches method declarations.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index b010dd59364..23edcc67564 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -156,6 +156,17 @@ anything() {
/// \endcode
const internal::VariadicAllOfMatcher<Decl> decl;
+/// \brief Matches a declaration of a linkage specification.
+///
+/// Given
+/// \code
+/// extern "C" {}
+/// \endcode
+/// linkageSpecDecl()
+/// matches "extern "C" {}"
+const internal::VariadicDynCastAllOfMatcher<Decl, LinkageSpecDecl>
+ linkageSpecDecl;
+
/// \brief Matches a declaration of anything that could have a name.
///
/// Example matches \c X, \c S, the anonymous union type, \c i, and \c U;
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
index 3fbe896a87b..e074c6ecc05 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -377,6 +377,11 @@ TEST(DeclarationMatcher, hasDeclContext) {
hasName("M"), hasDeclContext(namespaceDecl()))))));
}
+TEST(DeclarationMatcher, LinkageSpecification) {
+ EXPECT_TRUE(matches("extern \"C\" { void foo() {}; }", linkageSpecDecl()));
+ EXPECT_TRUE(notMatches("void foo() {};", linkageSpecDecl()));
+}
+
TEST(ClassTemplate, DoesNotMatchClass) {
DeclarationMatcher ClassX = classTemplateDecl(hasName("X"));
EXPECT_TRUE(notMatches("class X;", ClassX));
OpenPOWER on IntegriCloud