summaryrefslogtreecommitdiff
path: root/removeFunctionCall.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'removeFunctionCall.cpp')
-rw-r--r--removeFunctionCall.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/removeFunctionCall.cpp b/removeFunctionCall.cpp
index c9d497e..254cfaa 100644
--- a/removeFunctionCall.cpp
+++ b/removeFunctionCall.cpp
@@ -94,6 +94,24 @@ AST_POLYMORPHIC_MATCHER_P2(hasVariableNameArgument,
return false;
return InnerMatcher.matches(*Arg->IgnoreParenImpCasts(), Finder, Builder);
}
+
+AST_POLYMORPHIC_MATCHER_P2(hasExpectedValueArgument,
+ AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr,
+ CXXConstructExpr,
+ CXXUnresolvedConstructExpr,
+ ObjCMessageExpr),
+ unsigned,
+ N,
+ clang::ast_matchers::internal::Matcher<Expr>,
+ InnerMatcher)
+{
+ if (N >= Node.getNumArgs())
+ return false;
+ const Expr* Arg = Node.getArg(N);
+ if (Finder->isTraversalIgnoringImplicitNodes() && isa<CXXDefaultArgExpr>(Arg))
+ return false;
+ return InnerMatcher.matches(*Arg->IgnoreParenImpCasts(), Finder, Builder);
+}
} // namespace
} // namespace ast_matchers
} // namespace clang
@@ -166,9 +184,10 @@ int main(int argc,
// for instance if there is a ternary operator somewhere...
const std::string FunctionCallId{"functionCallId"};
const std::string FunctionReturnValue("true");
- auto Rule = makeRule(
- callExpr(hasVariableNameArgument(0, expr()), callee(FunctionToRemove)).bind(FunctionCallId),
- transformer::changeTo(node(FunctionCallId), cat(FunctionReturnValue)));
+ auto Rule = makeRule(callExpr(hasVariableNameArgument(0, expr()),
+ hasExpectedValueArgument(1, expr()), callee(FunctionToRemove))
+ .bind(FunctionCallId),
+ transformer::changeTo(node(FunctionCallId), cat(FunctionReturnValue)));
AtomicChanges AllChanges;