]> granicus.if.org Git - clang/commitdiff
Add matcher for linkage specification
authorManuel Klimek <klimek@google.com>
Thu, 4 Sep 2014 08:51:06 +0000 (08:51 +0000)
committerManuel Klimek <klimek@google.com>
Thu, 4 Sep 2014 08:51:06 +0000 (08:51 +0000)
Patch by Jacques Pienaar.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@217135 91177308-0d34-0410-b5e6-96231b3b80d8

docs/LibASTMatchersReference.html
include/clang/ASTMatchers/ASTMatchers.h
unittests/ASTMatchers/ASTMatchersTest.cpp

index 1a494e6aea4309f95d5008c9b2a0a6a94fe904e4..2c2b68de93f972d174ea4064b520b76ec3013d0d 100644 (file)
@@ -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.
 
index b010dd593647c90ac8bf4cef89366794c13e6222..23edcc6756466234bc00e7d7c04c4c78e74a5324 100644 (file)
@@ -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;
index 3fbe896a87b4652fa51221d403c9a3d0e4368f2f..e074c6ecc0505656e3c3506357296384a686046c 100644 (file)
@@ -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));