diff options
| author | Aotrix <[email protected]> | 2026-10-07 19:02:10 +0200 |
|---|---|---|
| committer | Aotrix <[email protected]> | 2026-10-07 19:02:10 +0200 |
| commit | 5b39c848257662ae4a8f890bf4171e36ccf77bb6 (patch) | |
| tree | 9d7e10c4cf579e187c32d5538cf1c2a31b8d02c2 /removeFunctionCall.cpp | |
| parent | bf9c087b5a527a3a4ffd77b559e788ab4a5ab98b (diff) | |
Added a second matcher for the value parameter : need to define both matchers now...
Diffstat (limited to 'removeFunctionCall.cpp')
| -rw-r--r-- | removeFunctionCall.cpp | 25 |
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; |
