diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-07-16 13:05:34 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-07-16 21:31:22 +0200 |
commit | 40fc30d05d9cce7ce7a9cdcb718dcb0f0aab8ac7 (patch) | |
tree | c856f18770e4183bdaff9760124d96a464e84ce6 /compilerplugins | |
parent | 70c6651e02c4582d66d8e1c1286406c4f01a7d4b (diff) |
convert some plugins to LO_CLANG_SHARED_PLUGINS
Change-Id: I63c9e010d83c24e18a36164ceb0441e48b757142
Reviewed-on: https://gerrit.libreoffice.org/75725
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/overrideparam.cxx | 15 | ||||
-rw-r--r-- | compilerplugins/clang/pointerbool.cxx | 14 | ||||
-rw-r--r-- | compilerplugins/clang/ptrvector.cxx | 10 | ||||
-rw-r--r-- | compilerplugins/clang/rangedforcopy.cxx | 10 | ||||
-rw-r--r-- | compilerplugins/clang/sharedvisitor/sharedvisitor.cxx | 72 |
5 files changed, 104 insertions, 17 deletions
diff --git a/compilerplugins/clang/overrideparam.cxx b/compilerplugins/clang/overrideparam.cxx index 43ba2f74b9a1..27aecb82615f 100644 --- a/compilerplugins/clang/overrideparam.cxx +++ b/compilerplugins/clang/overrideparam.cxx @@ -6,6 +6,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef LO_CLANG_SHARED_PLUGINS #include <string> #include <set> @@ -41,12 +42,8 @@ private: void OverrideParam::run() { - /* - StringRef fn(handler.getMainFileName()); - if (fn == SRCDIR "/include/svx/checklbx.hxx") - return; -*/ - TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); + if (preRun()) + TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } bool OverrideParam::VisitCXXMethodDecl(const CXXMethodDecl * methodDecl) { @@ -164,8 +161,10 @@ bool OverrideParam::hasSameDefaultParams(const ParmVarDecl * parmVarDecl, const // that would probably have unwanted side-effects) } -loplugin::Plugin::Registration< OverrideParam > X("overrideparam"); +loplugin::Plugin::Registration< OverrideParam > overrideparam("overrideparam"); -} +} // namespace + +#endif // LO_CLANG_SHARED_PLUGINS /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/pointerbool.cxx b/compilerplugins/clang/pointerbool.cxx index a3ed40506b8b..66c6a04b3697 100644 --- a/compilerplugins/clang/pointerbool.cxx +++ b/compilerplugins/clang/pointerbool.cxx @@ -20,6 +20,7 @@ /** Look for calls where the param is bool but the call-site-arg is pointer. */ +#ifndef LO_CLANG_SHARED_PLUGINS namespace { @@ -31,7 +32,11 @@ public: { } - virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } + virtual void run() override + { + if (preRun()) + TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); + } bool VisitCallExpr(CallExpr const*); @@ -117,7 +122,10 @@ llvm::Optional<APSInt> PointerBool::getCallValue(const Expr* arg) return llvm::Optional<APSInt>(); } -loplugin::Plugin::Registration<PointerBool> X("pointerbool", true); -} +loplugin::Plugin::Registration<PointerBool> pointerbool("pointerbool"); + +} // namespace + +#endif // LO_CLANG_SHARED_PLUGINS /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/ptrvector.cxx b/compilerplugins/clang/ptrvector.cxx index ed0893e3558f..758e3e90f34c 100644 --- a/compilerplugins/clang/ptrvector.cxx +++ b/compilerplugins/clang/ptrvector.cxx @@ -6,6 +6,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef LO_CLANG_SHARED_PLUGINS #include <memory> #include <cassert> @@ -33,7 +34,8 @@ public: virtual void run() override { - TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); + if (preRun()) + TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } bool shouldVisitTemplateInstantiations () const { return true; } @@ -80,8 +82,10 @@ bool PtrVector::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr* expr) } -loplugin::Plugin::Registration< PtrVector > X("ptrvector"); +loplugin::Plugin::Registration< PtrVector > ptrvector("ptrvector"); -} +} // namespace + +#endif // LO_CLANG_SHARED_PLUGINS /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/rangedforcopy.cxx b/compilerplugins/clang/rangedforcopy.cxx index a8a6e7d6cfbb..68004a1708ae 100644 --- a/compilerplugins/clang/rangedforcopy.cxx +++ b/compilerplugins/clang/rangedforcopy.cxx @@ -7,6 +7,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef LO_CLANG_SHARED_PLUGINS #include <string> #include <iostream> @@ -29,7 +30,8 @@ public: FilteringPlugin(data) {} virtual void run() override { - TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); + if (preRun()) + TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } bool VisitCXXForRangeStmt( const CXXForRangeStmt* stmt ); @@ -59,8 +61,10 @@ bool RangedForCopy::VisitCXXForRangeStmt( const CXXForRangeStmt* stmt ) } -loplugin::Plugin::Registration< RangedForCopy > X("rangedforcopy"); +loplugin::Plugin::Registration< RangedForCopy > rangedforcopy("rangedforcopy"); -} +} // namespace + +#endif // LO_CLANG_SHARED_PLUGINS /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/sharedvisitor/sharedvisitor.cxx b/compilerplugins/clang/sharedvisitor/sharedvisitor.cxx index 714aa3fd589f..f746fd9b070f 100644 --- a/compilerplugins/clang/sharedvisitor/sharedvisitor.cxx +++ b/compilerplugins/clang/sharedvisitor/sharedvisitor.cxx @@ -24,7 +24,10 @@ #include "../externvar.cxx" #include "../inlinevisible.cxx" #include "../loopvartoosmall.cxx" +#include "../overrideparam.cxx" +#include "../pointerbool.cxx" #include "../privatebase.cxx" +#include "../rangedforcopy.cxx" #include "../redundantfcast.cxx" #include "../redundantinline.cxx" #include "../redundantpointerops.cxx" @@ -50,6 +53,7 @@ #include "../weakbase.cxx" #include "../weakobject.cxx" #include "../dyncastvisibility.cxx" +#include "../ptrvector.cxx" #include "../vclwidgets.cxx" using namespace clang; @@ -77,7 +81,10 @@ public: , externVar( nullptr ) , inlineVisible( nullptr ) , loopVarTooSmall( nullptr ) + , overrideParam( nullptr ) + , pointerBool( nullptr ) , privateBase( nullptr ) + , rangedForCopy( nullptr ) , redundantFCast( nullptr ) , redundantInline( nullptr ) , redundantPointerOps( nullptr ) @@ -131,8 +138,14 @@ public: inlineVisible = nullptr; if( loopVarTooSmall && !loopVarTooSmall->preRun()) loopVarTooSmall = nullptr; + if( overrideParam && !overrideParam->preRun()) + overrideParam = nullptr; + if( pointerBool && !pointerBool->preRun()) + pointerBool = nullptr; if( privateBase && !privateBase->preRun()) privateBase = nullptr; + if( rangedForCopy && !rangedForCopy->preRun()) + rangedForCopy = nullptr; if( redundantFCast && !redundantFCast->preRun()) redundantFCast = nullptr; if( redundantInline && !redundantInline->preRun()) @@ -211,8 +224,14 @@ public: inlineVisible->postRun(); if( loopVarTooSmall ) loopVarTooSmall->postRun(); + if( overrideParam ) + overrideParam->postRun(); + if( pointerBool ) + pointerBool->postRun(); if( privateBase ) privateBase->postRun(); + if( rangedForCopy ) + rangedForCopy->postRun(); if( redundantFCast ) redundantFCast->postRun(); if( redundantInline ) @@ -297,8 +316,14 @@ public: inlineVisible = static_cast< InlineVisible* >( plugin ); else if( strcmp( name, "loopvartoosmall" ) == 0 ) loopVarTooSmall = static_cast< LoopVarTooSmall* >( plugin ); + else if( strcmp( name, "overrideparam" ) == 0 ) + overrideParam = static_cast< OverrideParam* >( plugin ); + else if( strcmp( name, "pointerbool" ) == 0 ) + pointerBool = static_cast< PointerBool* >( plugin ); else if( strcmp( name, "privatebase" ) == 0 ) privateBase = static_cast< PrivateBase* >( plugin ); + else if( strcmp( name, "rangedforcopy" ) == 0 ) + rangedForCopy = static_cast< RangedForCopy* >( plugin ); else if( strcmp( name, "redundantfcast" ) == 0 ) redundantFCast = static_cast< RedundantFCast* >( plugin ); else if( strcmp( name, "redundantinline" ) == 0 ) @@ -477,6 +502,17 @@ public: } return anyPluginActive(); } + bool VisitCXXForRangeStmt(const class clang::CXXForRangeStmt * arg) + { + if( ignoreLocation( arg )) + return true; + if( rangedForCopy != nullptr ) + { + if( !rangedForCopy->VisitCXXForRangeStmt( arg )) + rangedForCopy = nullptr; + } + return anyPluginActive(); + } bool VisitCXXFunctionalCastExpr(const class clang::CXXFunctionalCastExpr * arg) { if( ignoreLocation( arg )) @@ -508,6 +544,11 @@ public: { if( ignoreLocation( arg )) return true; + if( overrideParam != nullptr ) + { + if( !overrideParam->VisitCXXMethodDecl( arg )) + overrideParam = nullptr; + } if( typedefParam != nullptr ) { if( !typedefParam->VisitCXXMethodDecl( arg )) @@ -604,6 +645,11 @@ public: if( !dbgUnhandledException->VisitCallExpr( arg )) dbgUnhandledException = nullptr; } + if( pointerBool != nullptr ) + { + if( !pointerBool->VisitCallExpr( arg )) + pointerBool = nullptr; + } if( redundantFCast != nullptr ) { if( !redundantFCast->VisitCallExpr( arg )) @@ -1088,7 +1134,10 @@ private: || externVar != nullptr || inlineVisible != nullptr || loopVarTooSmall != nullptr + || overrideParam != nullptr + || pointerBool != nullptr || privateBase != nullptr + || rangedForCopy != nullptr || redundantFCast != nullptr || redundantInline != nullptr || redundantPointerOps != nullptr @@ -1127,7 +1176,10 @@ private: ExternVar* externVar; InlineVisible* inlineVisible; LoopVarTooSmall* loopVarTooSmall; + OverrideParam* overrideParam; + PointerBool* pointerBool; PrivateBase* privateBase; + RangedForCopy* rangedForCopy; RedundantFCast* redundantFCast; RedundantInline* redundantInline; RedundantPointerOps* redundantPointerOps; @@ -1164,12 +1216,15 @@ public: explicit SharedRecursiveASTVisitorVisitTemplates(const InstantiationData& rData) : FilteringPlugin(rData) , dynCastVisibility( nullptr ) + , ptrVector( nullptr ) , vCLWidgets( nullptr ) {} virtual bool preRun() override { if( dynCastVisibility && !dynCastVisibility->preRun()) dynCastVisibility = nullptr; + if( ptrVector && !ptrVector->preRun()) + ptrVector = nullptr; if( vCLWidgets && !vCLWidgets->preRun()) vCLWidgets = nullptr; return anyPluginActive(); @@ -1178,6 +1233,8 @@ public: { if( dynCastVisibility ) dynCastVisibility->postRun(); + if( ptrVector ) + ptrVector->postRun(); if( vCLWidgets ) vCLWidgets->postRun(); } @@ -1192,6 +1249,8 @@ public: { if( strcmp( name, "dyncastvisibility" ) == 0 ) dynCastVisibility = static_cast< DynCastVisibility* >( plugin ); + else if( strcmp( name, "ptrvector" ) == 0 ) + ptrVector = static_cast< PtrVector* >( plugin ); else if( strcmp( name, "vclwidgets" ) == 0 ) vCLWidgets = static_cast< VCLWidgets* >( plugin ); else @@ -1254,6 +1313,17 @@ bool shouldVisitTemplateInstantiations() const { return true; } } return anyPluginActive(); } + bool VisitCXXOperatorCallExpr(const class clang::CXXOperatorCallExpr * arg) + { + if( ignoreLocation( arg )) + return true; + if( ptrVector != nullptr ) + { + if( !ptrVector->VisitCXXOperatorCallExpr( arg )) + ptrVector = nullptr; + } + return anyPluginActive(); + } bool VisitCallExpr(const class clang::CallExpr * arg) { if( ignoreLocation( arg )) @@ -1324,9 +1394,11 @@ private: bool anyPluginActive() const { return dynCastVisibility != nullptr + || ptrVector != nullptr || vCLWidgets != nullptr; } DynCastVisibility* dynCastVisibility; + PtrVector* ptrVector; VCLWidgets* vCLWidgets; }; |