summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clang_query_examples.txt1
-rw-r--r--main.cc3
-rw-r--r--removeFunctionCall.cpp10
3 files changed, 11 insertions, 3 deletions
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;