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>
This commit is contained in:
committed by
Noel Grandin
parent
19e96dc156
commit
a0c30af2ac
@@ -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
|
||||
{
|
||||
|
@@ -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());
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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>(
|
||||
|
@@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user