]> granicus.if.org Git - clang/commitdiff
Add ASTMatcher for matching extern "C" function declarations.
authorDaniel Jasper <djasper@google.com>
Wed, 15 Aug 2012 18:52:19 +0000 (18:52 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 15 Aug 2012 18:52:19 +0000 (18:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161974 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/ASTMatchers/ASTMatchers.h
unittests/ASTMatchers/ASTMatchersTest.cpp

index 37e82e8318ddee627b4d3b5bf219bcd6da3d9358..eec1dbf86d1bd5c04af21fb13b46e5e1415fa40e 100644 (file)
@@ -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.
 ///
index cf37c7d27a9c38844fb5d93dd8b6abcaee15f0ae..dba9b7d6074a0ad6668c5118b359c9ab2f580c32 100644 (file)
@@ -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")))))));