From a0c30af2ac83eb0f7e76c336d60a31872db19938 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 11 Nov 2019 15:55:49 +0100 Subject: Make base of loplugin::FunctionAddress more flexible (I'm planning to use it for a FilteringRewritePlugin.) And while at it, base its current uses on FilteringPlugin. Change-Id: I0acdcc6cb0b3a434b425405c8c438dbf65e4d3cb Reviewed-on: https://gerrit.libreoffice.org/82451 Tested-by: Jenkins Reviewed-by: Noel Grandin --- compilerplugins/clang/constantparam.cxx | 4 ++-- compilerplugins/clang/constmethod.cxx | 4 ++-- compilerplugins/clang/constparams.cxx | 10 +++++----- compilerplugins/clang/functionaddress.hxx | 20 ++++++++++---------- compilerplugins/clang/returnconstant.cxx | 4 ++-- compilerplugins/clang/shouldreturnbool.cxx | 13 +++++++------ 6 files changed, 28 insertions(+), 27 deletions(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/constantparam.cxx b/compilerplugins/clang/constantparam.cxx index f73a7d2ef6c3..175c9d4a42fd 100644 --- a/compilerplugins/clang/constantparam.cxx +++ b/compilerplugins/clang/constantparam.cxx @@ -54,10 +54,10 @@ bool operator < (const MyCallSiteInfo &lhs, const MyCallSiteInfo &rhs) static std::set callSet; class ConstantParam: - public loplugin::FunctionAddress + public loplugin::FunctionAddress> { public: - explicit ConstantParam(loplugin::InstantiationData const & data): loplugin::FunctionAddress(data) {} + explicit ConstantParam(loplugin::InstantiationData const & data): FunctionAddress(data) {} virtual void run() override { diff --git a/compilerplugins/clang/constmethod.cxx b/compilerplugins/clang/constmethod.cxx index 217dd17bd6d7..e6a5dd14069c 100644 --- a/compilerplugins/clang/constmethod.cxx +++ b/compilerplugins/clang/constmethod.cxx @@ -31,10 +31,10 @@ namespace { class ConstMethod: - public loplugin::FunctionAddress + public loplugin::FunctionAddress> { public: - explicit ConstMethod(loplugin::InstantiationData const & data): loplugin::FunctionAddress(data) {} + explicit ConstMethod(loplugin::InstantiationData const & data): FunctionAddress(data) {} virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); diff --git a/compilerplugins/clang/constparams.cxx b/compilerplugins/clang/constparams.cxx index 388c813de18a..28179f30abae 100644 --- a/compilerplugins/clang/constparams.cxx +++ b/compilerplugins/clang/constparams.cxx @@ -28,10 +28,10 @@ namespace { class ConstParams: - public loplugin::FunctionAddress + public loplugin::FunctionAddress> { public: - explicit ConstParams(loplugin::InstantiationData const & data): loplugin::FunctionAddress(data) {} + explicit ConstParams(loplugin::InstantiationData const & data): FunctionAddress(data) {} virtual void run() override { std::string fn(handler.getMainFileName()); @@ -110,7 +110,7 @@ bool ConstParams::TraverseFunctionDecl(FunctionDecl * functionDecl) auto prev = currentFunctionDecl; if (CheckTraverseFunctionDecl(functionDecl)) currentFunctionDecl = functionDecl; - auto rv = loplugin::FunctionAddress::TraverseFunctionDecl(functionDecl); + auto rv = FunctionAddress::TraverseFunctionDecl(functionDecl); currentFunctionDecl = prev; return rv; } @@ -119,7 +119,7 @@ bool ConstParams::TraverseCXXMethodDecl(CXXMethodDecl * f) auto prev = currentFunctionDecl; if (CheckTraverseFunctionDecl(f)) currentFunctionDecl = f; - auto rv = loplugin::FunctionAddress::TraverseCXXMethodDecl(f); + auto rv = FunctionAddress::TraverseCXXMethodDecl(f); currentFunctionDecl = prev; return rv; } @@ -128,7 +128,7 @@ bool ConstParams::TraverseCXXConstructorDecl(CXXConstructorDecl * f) auto prev = currentFunctionDecl; if (CheckTraverseFunctionDecl(f)) currentFunctionDecl = f; - auto rv = loplugin::FunctionAddress::TraverseCXXConstructorDecl(f); + auto rv = FunctionAddress::TraverseCXXConstructorDecl(f); currentFunctionDecl = prev; return rv; } diff --git a/compilerplugins/clang/functionaddress.hxx b/compilerplugins/clang/functionaddress.hxx index dc34262a50b0..93241ea5b4b0 100644 --- a/compilerplugins/clang/functionaddress.hxx +++ b/compilerplugins/clang/functionaddress.hxx @@ -19,16 +19,16 @@ */ namespace loplugin { -template -class FunctionAddress : public RecursiveASTVisitor, public loplugin::Plugin +template +class FunctionAddress : public Base { public: - explicit FunctionAddress( const InstantiationData& data ) : loplugin::Plugin(data) {} + explicit FunctionAddress( const InstantiationData& data ) : Base(data) {} bool TraverseCallExpr(CallExpr * expr) { auto const saved = callee_; callee_ = expr->getCallee(); - auto const ret = RecursiveASTVisitor::TraverseCallExpr(expr); + auto const ret = Base::TraverseCallExpr(expr); callee_ = saved; return ret; } @@ -36,7 +36,7 @@ public: bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr * expr) { auto const saved = callee_; callee_ = expr->getCallee(); - auto const ret = RecursiveASTVisitor::TraverseCXXOperatorCallExpr(expr); + auto const ret = Base::TraverseCXXOperatorCallExpr(expr); callee_ = saved; return ret; } @@ -44,7 +44,7 @@ public: bool TraverseCXXMemberCallExpr(CXXMemberCallExpr * expr) { auto const saved = callee_; callee_ = expr->getCallee(); - auto const ret = RecursiveASTVisitor::TraverseCXXMemberCallExpr(expr); + auto const ret = Base::TraverseCXXMemberCallExpr(expr); callee_ = saved; return ret; } @@ -52,7 +52,7 @@ public: bool TraverseCUDAKernelCallExpr(CUDAKernelCallExpr * expr) { auto const saved = callee_; callee_ = expr->getCallee(); - auto const ret = RecursiveASTVisitor::TraverseCUDAKernelCallExpr(expr); + auto const ret = Base::TraverseCUDAKernelCallExpr(expr); callee_ = saved; return ret; } @@ -60,7 +60,7 @@ public: bool TraverseUserDefinedLiteral(UserDefinedLiteral * expr) { auto const saved = callee_; callee_ = expr->getCallee(); - auto const ret = RecursiveASTVisitor::TraverseUserDefinedLiteral(expr); + auto const ret = Base::TraverseUserDefinedLiteral(expr); callee_ = saved; return ret; } @@ -69,7 +69,7 @@ public: if (expr == callee_) { return true; } - if (ignoreLocation(expr)) { + if (this->ignoreLocation(expr)) { return true; } if (expr->getCastKind() != CK_FunctionToPointerDecay) { @@ -89,7 +89,7 @@ public: } bool VisitUnaryAddrOf(UnaryOperator const * expr) { - if (ignoreLocation(expr)) { + if (this->ignoreLocation(expr)) { return true; } auto const dre = dyn_cast( diff --git a/compilerplugins/clang/returnconstant.cxx b/compilerplugins/clang/returnconstant.cxx index 8040396ef6d0..70119b07bed7 100644 --- a/compilerplugins/clang/returnconstant.cxx +++ b/compilerplugins/clang/returnconstant.cxx @@ -23,11 +23,11 @@ */ namespace { -class ReturnConstant : public loplugin::FunctionAddress +class ReturnConstant : public loplugin::FunctionAddress> { public: explicit ReturnConstant(loplugin::InstantiationData const& data) - : loplugin::FunctionAddress(data) + : FunctionAddress(data) { } diff --git a/compilerplugins/clang/shouldreturnbool.cxx b/compilerplugins/clang/shouldreturnbool.cxx index a15e9d9b872b..23749d6b6428 100644 --- a/compilerplugins/clang/shouldreturnbool.cxx +++ b/compilerplugins/clang/shouldreturnbool.cxx @@ -24,11 +24,12 @@ namespace { -class ShouldReturnBool : public loplugin::FunctionAddress +class ShouldReturnBool + : public loplugin::FunctionAddress> { public: explicit ShouldReturnBool(loplugin::InstantiationData const& data) - : loplugin::FunctionAddress(data) + : FunctionAddress(data) { } @@ -143,13 +144,13 @@ bool ShouldReturnBool::TraverseFunctionDecl(FunctionDecl* functionDecl) { mbInsideFunction = true; mbFunctionOnlyReturningOneOrZero = true; - ret = loplugin::FunctionAddress::TraverseFunctionDecl(functionDecl); + ret = FunctionAddress::TraverseFunctionDecl(functionDecl); mbInsideFunction = false; if (mbFunctionOnlyReturningOneOrZero) problemFunctions.insert(functionDecl); } else - ret = loplugin::FunctionAddress::TraverseFunctionDecl(functionDecl); + ret = FunctionAddress::TraverseFunctionDecl(functionDecl); return ret; } @@ -160,13 +161,13 @@ bool ShouldReturnBool::TraverseCXXMethodDecl(CXXMethodDecl* methodDecl) { mbInsideFunction = true; mbFunctionOnlyReturningOneOrZero = true; - ret = loplugin::FunctionAddress::TraverseCXXMethodDecl(methodDecl); + ret = FunctionAddress::TraverseCXXMethodDecl(methodDecl); mbInsideFunction = false; if (mbFunctionOnlyReturningOneOrZero) problemFunctions.insert(methodDecl); } else - ret = loplugin::FunctionAddress::TraverseCXXMethodDecl(methodDecl); + ret = FunctionAddress::TraverseCXXMethodDecl(methodDecl); return ret; } -- cgit v1.2.3