Add ASTMatcher for matching extern "C" function declarations.

llvm-svn: 161974
This commit is contained in:
Daniel Jasper 2012-08-15 18:52:19 +00:00
parent ba072d6b2c
commit faaffe373e
2 changed files with 18 additions and 0 deletions

View 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.
///

View 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")))))));