[PATCH] D18243: [ASTMatchers] Existing matcher hasAnyArgument fixed
Balogh, Ádám via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 21 08:35:13 PDT 2016
baloghadamsoftware updated this revision to Diff 51167.
http://reviews.llvm.org/D18243
Files:
include/clang/ASTMatchers/ASTMatchers.h
unittests/ASTMatchers/ASTMatchersTest.cpp
Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===================================================================
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -1628,10 +1628,15 @@
TEST(Matcher, AnyArgument) {
StatementMatcher CallArgumentY = callExpr(
- hasAnyArgument(declRefExpr(to(varDecl(hasName("y"))))));
+ hasAnyArgument(
+ ignoringParenImpCasts(declRefExpr(to(varDecl(hasName("y")))))));
EXPECT_TRUE(matches("void x(int, int) { int y; x(1, y); }", CallArgumentY));
EXPECT_TRUE(matches("void x(int, int) { int y; x(y, 42); }", CallArgumentY));
EXPECT_TRUE(notMatches("void x(int, int) { x(1, 2); }", CallArgumentY));
+
+ StatementMatcher ImplicitCastedArgument = callExpr(
+ hasAnyArgument(implicitCastExpr()));
+ EXPECT_TRUE(matches("void x(long) { int y; x(y); }", ImplicitCastedArgument));
}
TEST(ForEachArgumentWithParam, ReportsNoFalsePositives) {
Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -2859,18 +2859,13 @@
/// matches x(1, y, 42)
/// with hasAnyArgument(...)
/// matching y
-///
-/// FIXME: Currently this will ignore parentheses and implicit casts on
-/// the argument before applying the inner matcher. We'll want to remove
-/// this to allow for greater control by the user once \c ignoreImplicit()
-/// has been implemented.
AST_POLYMORPHIC_MATCHER_P(hasAnyArgument,
AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr,
CXXConstructExpr),
internal::Matcher<Expr>, InnerMatcher) {
for (const Expr *Arg : Node.arguments()) {
BoundNodesTreeBuilder Result(*Builder);
- if (InnerMatcher.matches(*Arg->IgnoreParenImpCasts(), Finder, &Result)) {
+ if (InnerMatcher.matches(*Arg, Finder, &Result)) {
*Builder = std::move(Result);
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18243.51167.patch
Type: text/x-patch
Size: 2065 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160321/47819bde/attachment.bin>
More information about the cfe-commits
mailing list