diff options
-rw-r--r-- | include/clang/ASTMatchers/ASTMatchers.h | 12 | ||||
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.cpp | 6 |
2 files changed, 18 insertions, 0 deletions
diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index 37e82e8318..eec1dbf86d 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -1385,6 +1385,18 @@ AST_MATCHER_P(FunctionDecl, returns, internal::Matcher<QualType>, Matcher) { return Matcher.matches(Node.getResultType(), Finder, Builder); } +/// \brief Matches extern "C" function declarations. +/// +/// Given: +/// extern "C" void f() {} +/// extern "C" { void g() {} } +/// void h() {} +/// function(isExternC()) +/// matches the declaration of f and g, but not the declaration h +AST_MATCHER(FunctionDecl, isExternC) { + return Node.isExternC(); +} + /// \brief Matches the condition expression of an if statement, for loop, /// or conditional operator. /// diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index cf37c7d27a..dba9b7d607 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -1099,6 +1099,12 @@ TEST(Returns, MatchesReturnTypes) { function(returns(hasDeclaration(record(hasName("Y"))))))); } +TEST(IsExternC, MatchesExternCFunctionDeclarations) { + EXPECT_TRUE(matches("extern \"C\" void f() {}", function(isExternC()))); + EXPECT_TRUE(matches("extern \"C\" { void f() {} }", function(isExternC()))); + EXPECT_TRUE(notMatches("void f() {}", function(isExternC()))); +} + TEST(HasAnyParameter, DoesntMatchIfInnerMatcherDoesntMatch) { EXPECT_TRUE(notMatches("class Y {}; class X { void x(int) {} };", method(hasAnyParameter(hasType(record(hasName("X"))))))); |