[cfe-commits] r161974 - in /cfe/trunk: include/clang/ASTMatchers/ASTMatchers.h unittests/ASTMatchers/ASTMatchersTest.cpp
Daniel Jasper
djasper at google.com
Wed Aug 15 11:52:19 PDT 2012
Author: djasper
Date: Wed Aug 15 13:52:19 2012
New Revision: 161974
URL: http://llvm.org/viewvc/llvm-project?rev=161974&view=rev
Log:
Add ASTMatcher for matching extern "C" function declarations.
Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=161974&r1=161973&r2=161974&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Wed Aug 15 13:52:19 2012
@@ -1385,6 +1385,18 @@
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.
///
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=161974&r1=161973&r2=161974&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Wed Aug 15 13:52:19 2012
@@ -1099,6 +1099,12 @@
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")))))));
More information about the cfe-commits
mailing list