summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2016-08-04 10:02:03 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2016-08-04 10:02:03 +0000
commit87e6d99487ddd7ba4bdc582600f0dfc2ef271ae7 (patch)
tree4706cb0f98ec8af0e1cb94c61d17f458e15048a7 /clang
parent54a54869186ec39694e99300644cd0d3d048a965 (diff)
downloadbcm5719-llvm-87e6d99487ddd7ba4bdc582600f0dfc2ef271ae7.tar.gz
bcm5719-llvm-87e6d99487ddd7ba4bdc582600f0dfc2ef271ae7.zip
Make isExternC work on VarDecls too.
llvm-svn: 277712
Diffstat (limited to 'clang')
-rw-r--r--clang/docs/LibASTMatchersReference.html12
-rw-r--r--clang/include/clang/ASTMatchers/ASTMatchers.h3
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp6
3 files changed, 20 insertions, 1 deletions
diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html
index 35534cb8c84..02af5d578f6 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -3441,6 +3441,18 @@ Usable as: Matcher&lt;<a href="http://clang.llvm.org/doxygen/classclang_1_1Funct
</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('isExternC1')"><a name="isExternC1Anchor">isExternC</a></td><td></td></tr>
+<tr><td colspan="4" class="doc" id="isExternC1"><pre>Matches extern "C" function declarations.
+
+Given:
+ extern "C" void f() {}
+ extern "C" { void g() {} }
+ void h() {}
+functionDecl(isExternC())
+ matches the declaration of f and g, but not the declaration h
+</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('isTemplateInstantiation1')"><a name="isTemplateInstantiation1Anchor">isTemplateInstantiation</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="isTemplateInstantiation1"><pre>Matches template instantiations of function, class, or static
member variable template instantiations.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index eee713c49b8..2a5f0470766 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3342,7 +3342,8 @@ AST_MATCHER_P(FunctionDecl, returns,
/// \endcode
/// functionDecl(isExternC())
/// matches the declaration of f and g, but not the declaration h
-AST_MATCHER(FunctionDecl, isExternC) {
+AST_POLYMORPHIC_MATCHER(isExternC, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+ VarDecl)) {
return Node.isExternC();
}
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 82c5139a78f..108fd435cef 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -842,6 +842,12 @@ TEST(IsExternC, MatchesExternCFunctionDeclarations) {
EXPECT_TRUE(notMatches("void f() {}", functionDecl(isExternC())));
}
+TEST(IsExternC, MatchesExternCVariableDeclarations) {
+ EXPECT_TRUE(matches("extern \"C\" int i;", varDecl(isExternC())));
+ EXPECT_TRUE(matches("extern \"C\" { int i; }", varDecl(isExternC())));
+ EXPECT_TRUE(notMatches("int i;", varDecl(isExternC())));
+}
+
TEST(IsDefaulted, MatchesDefaultedFunctionDeclarations) {
EXPECT_TRUE(notMatches("class A { ~A(); };",
functionDecl(hasName("~A"), isDefaulted())));
OpenPOWER on IntegriCloud