diff options
Diffstat (limited to 'removeFunctionCall.cpp')
| -rw-r--r-- | removeFunctionCall.cpp | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/removeFunctionCall.cpp b/removeFunctionCall.cpp index 42d4645..c9d497e 100644 --- a/removeFunctionCall.cpp +++ b/removeFunctionCall.cpp @@ -57,6 +57,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Signals.h" #include "llvm/Support/raw_ostream.h" +#include <iostream> using namespace clang; using namespace clang::ast_matchers; @@ -76,12 +77,22 @@ namespace ast_matchers { namespace { -AST_MATCHER_P(MemberExpr, - Member, - clang::ast_matchers::internal::Matcher<ValueDecl>, - InnerMatcher) +AST_POLYMORPHIC_MATCHER_P2(hasVariableNameArgument, + AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr, + CXXConstructExpr, + CXXUnresolvedConstructExpr, + ObjCMessageExpr), + unsigned, + N, + clang::ast_matchers::internal::Matcher<Expr>, + InnerMatcher) { - return InnerMatcher.matches(*Node.getMemberDecl(), Finder, Builder); + 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 @@ -153,12 +164,11 @@ int main(int argc, auto FunctionToRemove = functionDecl(matchesName("configValue")); // 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))); + 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))); AtomicChanges AllChanges; |
