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 <noel.grandin@collabora.co.uk>
diff --git a/compilerplugins/clang/constantparam.cxx b/compilerplugins/clang/constantparam.cxx
index f73a7d2..175c9d4 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<MyCallSiteInfo> callSet;

class ConstantParam:
    public loplugin::FunctionAddress<ConstantParam>
    public loplugin::FunctionAddress<loplugin::FilteringPlugin<ConstantParam>>
{
public:
    explicit ConstantParam(loplugin::InstantiationData const & data): loplugin::FunctionAddress<ConstantParam>(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 217dd17..e6a5dd1 100644
--- a/compilerplugins/clang/constmethod.cxx
+++ b/compilerplugins/clang/constmethod.cxx
@@ -31,10 +31,10 @@ namespace
{

class ConstMethod:
    public loplugin::FunctionAddress<ConstMethod>
    public loplugin::FunctionAddress<loplugin::FilteringPlugin<ConstMethod>>
{
public:
    explicit ConstMethod(loplugin::InstantiationData const & data): loplugin::FunctionAddress<ConstMethod>(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 388c813..28179f3 100644
--- a/compilerplugins/clang/constparams.cxx
+++ b/compilerplugins/clang/constparams.cxx
@@ -28,10 +28,10 @@ namespace
{

class ConstParams:
    public loplugin::FunctionAddress<ConstParams>
    public loplugin::FunctionAddress<loplugin::FilteringPlugin<ConstParams>>
{
public:
    explicit ConstParams(loplugin::InstantiationData const & data): loplugin::FunctionAddress<ConstParams>(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<ConstParams>::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<ConstParams>::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<ConstParams>::TraverseCXXConstructorDecl(f);
    auto rv = FunctionAddress::TraverseCXXConstructorDecl(f);
    currentFunctionDecl = prev;
    return rv;
}
diff --git a/compilerplugins/clang/functionaddress.hxx b/compilerplugins/clang/functionaddress.hxx
index dc34262a..93241ea 100644
--- a/compilerplugins/clang/functionaddress.hxx
+++ b/compilerplugins/clang/functionaddress.hxx
@@ -19,16 +19,16 @@
 */
namespace loplugin {

template<typename Derived>
class FunctionAddress : public RecursiveASTVisitor<Derived>, public loplugin::Plugin
template<typename Base>
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<Derived>::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<Derived>::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<Derived>::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<Derived>::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<Derived>::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<DeclRefExpr>(
diff --git a/compilerplugins/clang/returnconstant.cxx b/compilerplugins/clang/returnconstant.cxx
index 8040396..70119b0 100644
--- a/compilerplugins/clang/returnconstant.cxx
+++ b/compilerplugins/clang/returnconstant.cxx
@@ -23,11 +23,11 @@
*/
namespace
{
class ReturnConstant : public loplugin::FunctionAddress<ReturnConstant>
class ReturnConstant : public loplugin::FunctionAddress<loplugin::FilteringPlugin<ReturnConstant>>
{
public:
    explicit ReturnConstant(loplugin::InstantiationData const& data)
        : loplugin::FunctionAddress<ReturnConstant>(data)
        : FunctionAddress(data)
    {
    }

diff --git a/compilerplugins/clang/shouldreturnbool.cxx b/compilerplugins/clang/shouldreturnbool.cxx
index a15e9d9..23749d6 100644
--- a/compilerplugins/clang/shouldreturnbool.cxx
+++ b/compilerplugins/clang/shouldreturnbool.cxx
@@ -24,11 +24,12 @@

namespace
{
class ShouldReturnBool : public loplugin::FunctionAddress<ShouldReturnBool>
class ShouldReturnBool
    : public loplugin::FunctionAddress<loplugin::FilteringPlugin<ShouldReturnBool>>
{
public:
    explicit ShouldReturnBool(loplugin::InstantiationData const& data)
        : loplugin::FunctionAddress<ShouldReturnBool>(data)
        : FunctionAddress(data)
    {
    }

@@ -143,13 +144,13 @@ bool ShouldReturnBool::TraverseFunctionDecl(FunctionDecl* functionDecl)
    {
        mbInsideFunction = true;
        mbFunctionOnlyReturningOneOrZero = true;
        ret = loplugin::FunctionAddress<ShouldReturnBool>::TraverseFunctionDecl(functionDecl);
        ret = FunctionAddress::TraverseFunctionDecl(functionDecl);
        mbInsideFunction = false;
        if (mbFunctionOnlyReturningOneOrZero)
            problemFunctions.insert(functionDecl);
    }
    else
        ret = loplugin::FunctionAddress<ShouldReturnBool>::TraverseFunctionDecl(functionDecl);
        ret = FunctionAddress::TraverseFunctionDecl(functionDecl);
    return ret;
}

@@ -160,13 +161,13 @@ bool ShouldReturnBool::TraverseCXXMethodDecl(CXXMethodDecl* methodDecl)
    {
        mbInsideFunction = true;
        mbFunctionOnlyReturningOneOrZero = true;
        ret = loplugin::FunctionAddress<ShouldReturnBool>::TraverseCXXMethodDecl(methodDecl);
        ret = FunctionAddress::TraverseCXXMethodDecl(methodDecl);
        mbInsideFunction = false;
        if (mbFunctionOnlyReturningOneOrZero)
            problemFunctions.insert(methodDecl);
    }
    else
        ret = loplugin::FunctionAddress<ShouldReturnBool>::TraverseCXXMethodDecl(methodDecl);
        ret = FunctionAddress::TraverseCXXMethodDecl(methodDecl);
    return ret;
}