From cf1afd9352f56d8765b66f785bd01964213f59c2 Mon Sep 17 00:00:00 2001 From: Aotrix <9aotrix@protonmail.com> Date: Wed, 30 Sep 2026 19:16:12 +0200 Subject: Bind call expression --- clang_query_examples.txt | 1 + main.cc | 3 ++- removeFunctionCall.cpp | 10 ++++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 clang_query_examples.txt diff --git a/clang_query_examples.txt b/clang_query_examples.txt new file mode 100644 index 0000000..d526cc1 --- /dev/null +++ b/clang_query_examples.txt @@ -0,0 +1 @@ +callExpr(hasArgument(0, hasDescendant(stringLiteral())), callee(functionDecl(matchesName("configValue")))) diff --git a/main.cc b/main.cc index 9030b12..de75719 100644 --- a/main.cc +++ b/main.cc @@ -16,7 +16,8 @@ bool coucouEveryone() int main() { - if (configValue("aparam")) + std::string aValue{"aparam"}; + if (configValue(aValue)) { coucouEveryone(); } diff --git a/removeFunctionCall.cpp b/removeFunctionCall.cpp index b60070d..42d4645 100644 --- a/removeFunctionCall.cpp +++ b/removeFunctionCall.cpp @@ -151,8 +151,14 @@ int main(int argc, // changeTo(node(ArgId), transformer::maybeDeref(ArgId))); auto FunctionToRemove = functionDecl(matchesName("configValue")); - auto Rule = makeRule(callExpr(hasArgument(0, expr().bind("keyName")), callee(FunctionToRemove)), - changeTo(cat("true"))); + // FIXME: do not clean a function call if it used by strictly more than one parameter + // for instance if there is a ternary operator somewhere... + const std::string FunctionCallId{"x"}; + const std::string ExpectedValue("true"); + auto Rule = + makeRule(callExpr(hasArgument(0, hasDescendant(stringLiteral())), callee(FunctionToRemove)) + .bind(FunctionCallId), + transformer::changeTo(node(FunctionCallId), cat(ExpectedValue))); AtomicChanges AllChanges; -- cgit v1.2.3