compilerplugins/clang/salunicodeliteral.cxx | 21 compilerplugins/clang/sfxpoolitem.cxx | 7 compilerplugins/clang/sharedvisitor/sharedvisitor.cxx | 381 ++++++++++++++++++ compilerplugins/clang/simplifydynamiccast.cxx | 8 compilerplugins/clang/staticaccess.cxx | 8 compilerplugins/clang/staticanonymous.cxx | 10 compilerplugins/clang/staticconstfield.cxx | 22 - compilerplugins/clang/staticmethods.cxx | 12 compilerplugins/clang/stringconcat.cxx | 8 compilerplugins/clang/stringconstant.cxx | 21 compilerplugins/clang/typedefparam.cxx | 11 compilerplugins/clang/unicodetochar.cxx | 16 compilerplugins/clang/unnecessarycatchthrow.cxx | 8 compilerplugins/clang/unoany.cxx | 17 compilerplugins/clang/unoquery.cxx | 20 compilerplugins/clang/weakbase.cxx | 19 16 files changed, 538 insertions(+), 51 deletions(-)
New commits: commit fc1b213d157afa57704cec5a0fb65ae8c11d7822 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Mon Jul 15 12:14:34 2019 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Jul 15 15:48:48 2019 +0200 convert some plugins to use the sharedplugin infrastructure Change-Id: I690d9df436abdadc51a6d3f7df686a2e37f79f73 Reviewed-on: https://gerrit.libreoffice.org/75624 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/compilerplugins/clang/salunicodeliteral.cxx b/compilerplugins/clang/salunicodeliteral.cxx index bdf83694b77e..cfa37396b02b 100644 --- a/compilerplugins/clang/salunicodeliteral.cxx +++ b/compilerplugins/clang/salunicodeliteral.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 "check.hxx" #include "plugin.hxx" @@ -41,16 +42,18 @@ public: return true; } -private: - void run() override { - if (compiler.getLangOpts().CPlusPlus + bool preRun() override { + return compiler.getLangOpts().CPlusPlus && compiler.getPreprocessor().getIdentifierInfo( - "LIBO_INTERNAL_ONLY")->hasMacroDefinition()) - { + "LIBO_INTERNAL_ONLY")->hasMacroDefinition(); + } + + void run() override { + if (preRun()) TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); - } } +private: void check(ExplicitCastExpr const * expr) { if (ignoreLocation(expr) || isInUnoIncludeFile(expr->getExprLoc())) @@ -90,9 +93,11 @@ private: } }; -static loplugin::Plugin::Registration<SalUnicodeLiteral> reg( +static loplugin::Plugin::Registration<SalUnicodeLiteral> salunicodeliteral( "salunicodeliteral"); -} +} // namespace + +#endif // LO_CLANG_SHARED_PLUGINS /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/compilerplugins/clang/sfxpoolitem.cxx b/compilerplugins/clang/sfxpoolitem.cxx index bd2870fe06d3..ce52336c8e04 100644 --- a/compilerplugins/clang/sfxpoolitem.cxx +++ b/compilerplugins/clang/sfxpoolitem.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 <iostream> @@ -124,8 +125,10 @@ bool SfxPoolItem::VisitCXXRecordDecl(const CXXRecordDecl* decl) } -loplugin::Plugin::Registration< SfxPoolItem > X("sfxpoolitem"); +loplugin::Plugin::Registration< SfxPoolItem > sfxpoolitem("sfxpoolitem"); -} +} // 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 a6df13ca33b4..28adab18e53c 100644 --- a/compilerplugins/clang/sharedvisitor/sharedvisitor.cxx +++ b/compilerplugins/clang/sharedvisitor/sharedvisitor.cxx @@ -26,13 +26,28 @@ #include "../loopvartoosmall.cxx" #include "../privatebase.cxx" #include "../reservedid.cxx" +#include "../salunicodeliteral.cxx" +#include "../sfxpoolitem.cxx" #include "../simplifyconstruct.cxx" +#include "../simplifydynamiccast.cxx" +#include "../staticaccess.cxx" +#include "../staticanonymous.cxx" +#include "../staticconstfield.cxx" +#include "../staticmethods.cxx" +#include "../stringconcat.cxx" +#include "../stringconstant.cxx" #include "../stringstatic.cxx" #include "../subtlezeroinit.cxx" +#include "../typedefparam.cxx" +#include "../unicodetochar.cxx" +#include "../unnecessarycatchthrow.cxx" #include "../unnecessaryoverride.cxx" #include "../unnecessaryparen.cxx" +#include "../unoany.cxx" +#include "../unoquery.cxx" #include "../unreffun.cxx" #include "../unusedvariablecheck.cxx" +#include "../weakbase.cxx" #include "../weakobject.cxx" #include "../dyncastvisibility.cxx" #include "../vclwidgets.cxx" @@ -64,13 +79,28 @@ public: , loopVarTooSmall( nullptr ) , privateBase( nullptr ) , reservedId( nullptr ) + , salUnicodeLiteral( nullptr ) + , sfxPoolItem( nullptr ) , simplifyConstruct( nullptr ) + , simplifyDynamicCast( nullptr ) + , staticAccess( nullptr ) + , staticAnonymous( nullptr ) + , staticConstField( nullptr ) + , staticMethods( nullptr ) + , stringConcat( nullptr ) + , stringConstant( nullptr ) , stringStatic( nullptr ) , subtleZeroInit( nullptr ) + , typedefParam( nullptr ) + , unicodeToChar( nullptr ) + , unnecessaryCatchThrow( nullptr ) , unnecessaryOverride( nullptr ) , unnecessaryParen( nullptr ) + , unoAny( nullptr ) + , unoQuery( nullptr ) , unrefFun( nullptr ) , unusedVariableCheck( nullptr ) + , weakBase( nullptr ) , weakObject( nullptr ) {} virtual bool preRun() override @@ -105,20 +135,50 @@ public: privateBase = nullptr; if( reservedId && !reservedId->preRun()) reservedId = nullptr; + if( salUnicodeLiteral && !salUnicodeLiteral->preRun()) + salUnicodeLiteral = nullptr; + if( sfxPoolItem && !sfxPoolItem->preRun()) + sfxPoolItem = nullptr; if( simplifyConstruct && !simplifyConstruct->preRun()) simplifyConstruct = nullptr; + if( simplifyDynamicCast && !simplifyDynamicCast->preRun()) + simplifyDynamicCast = nullptr; + if( staticAccess && !staticAccess->preRun()) + staticAccess = nullptr; + if( staticAnonymous && !staticAnonymous->preRun()) + staticAnonymous = nullptr; + if( staticConstField && !staticConstField->preRun()) + staticConstField = nullptr; + if( staticMethods && !staticMethods->preRun()) + staticMethods = nullptr; + if( stringConcat && !stringConcat->preRun()) + stringConcat = nullptr; + if( stringConstant && !stringConstant->preRun()) + stringConstant = nullptr; if( stringStatic && !stringStatic->preRun()) stringStatic = nullptr; if( subtleZeroInit && !subtleZeroInit->preRun()) subtleZeroInit = nullptr; + if( typedefParam && !typedefParam->preRun()) + typedefParam = nullptr; + if( unicodeToChar && !unicodeToChar->preRun()) + unicodeToChar = nullptr; + if( unnecessaryCatchThrow && !unnecessaryCatchThrow->preRun()) + unnecessaryCatchThrow = nullptr; if( unnecessaryOverride && !unnecessaryOverride->preRun()) unnecessaryOverride = nullptr; if( unnecessaryParen && !unnecessaryParen->preRun()) unnecessaryParen = nullptr; + if( unoAny && !unoAny->preRun()) + unoAny = nullptr; + if( unoQuery && !unoQuery->preRun()) + unoQuery = nullptr; if( unrefFun && !unrefFun->preRun()) unrefFun = nullptr; if( unusedVariableCheck && !unusedVariableCheck->preRun()) unusedVariableCheck = nullptr; + if( weakBase && !weakBase->preRun()) + weakBase = nullptr; if( weakObject && !weakObject->preRun()) weakObject = nullptr; return anyPluginActive(); @@ -155,20 +215,50 @@ public: privateBase->postRun(); if( reservedId ) reservedId->postRun(); + if( salUnicodeLiteral ) + salUnicodeLiteral->postRun(); + if( sfxPoolItem ) + sfxPoolItem->postRun(); if( simplifyConstruct ) simplifyConstruct->postRun(); + if( simplifyDynamicCast ) + simplifyDynamicCast->postRun(); + if( staticAccess ) + staticAccess->postRun(); + if( staticAnonymous ) + staticAnonymous->postRun(); + if( staticConstField ) + staticConstField->postRun(); + if( staticMethods ) + staticMethods->postRun(); + if( stringConcat ) + stringConcat->postRun(); + if( stringConstant ) + stringConstant->postRun(); if( stringStatic ) stringStatic->postRun(); if( subtleZeroInit ) subtleZeroInit->postRun(); + if( typedefParam ) + typedefParam->postRun(); + if( unicodeToChar ) + unicodeToChar->postRun(); + if( unnecessaryCatchThrow ) + unnecessaryCatchThrow->postRun(); if( unnecessaryOverride ) unnecessaryOverride->postRun(); if( unnecessaryParen ) unnecessaryParen->postRun(); + if( unoAny ) + unoAny->postRun(); + if( unoQuery ) + unoQuery->postRun(); if( unrefFun ) unrefFun->postRun(); if( unusedVariableCheck ) unusedVariableCheck->postRun(); + if( weakBase ) + weakBase->postRun(); if( weakObject ) weakObject->postRun(); } @@ -211,20 +301,50 @@ public: privateBase = static_cast< PrivateBase* >( plugin ); else if( strcmp( name, "reservedid" ) == 0 ) reservedId = static_cast< ReservedId* >( plugin ); + else if( strcmp( name, "salunicodeliteral" ) == 0 ) + salUnicodeLiteral = static_cast< SalUnicodeLiteral* >( plugin ); + else if( strcmp( name, "sfxpoolitem" ) == 0 ) + sfxPoolItem = static_cast< SfxPoolItem* >( plugin ); else if( strcmp( name, "simplifyconstruct" ) == 0 ) simplifyConstruct = static_cast< SimplifyConstruct* >( plugin ); + else if( strcmp( name, "simplifydynamiccast" ) == 0 ) + simplifyDynamicCast = static_cast< SimplifyDynamicCast* >( plugin ); + else if( strcmp( name, "staticaccess" ) == 0 ) + staticAccess = static_cast< StaticAccess* >( plugin ); + else if( strcmp( name, "staticanonymous" ) == 0 ) + staticAnonymous = static_cast< StaticAnonymous* >( plugin ); + else if( strcmp( name, "staticconstfield" ) == 0 ) + staticConstField = static_cast< StaticConstField* >( plugin ); + else if( strcmp( name, "staticmethods" ) == 0 ) + staticMethods = static_cast< StaticMethods* >( plugin ); + else if( strcmp( name, "stringconcat" ) == 0 ) + stringConcat = static_cast< StringConcat* >( plugin ); + else if( strcmp( name, "stringconstant" ) == 0 ) + stringConstant = static_cast< StringConstant* >( plugin ); else if( strcmp( name, "stringstatic" ) == 0 ) stringStatic = static_cast< StringStatic* >( plugin ); else if( strcmp( name, "subtlezeroinit" ) == 0 ) subtleZeroInit = static_cast< SubtleZeroInit* >( plugin ); + else if( strcmp( name, "typedefparam" ) == 0 ) + typedefParam = static_cast< TypedefParam* >( plugin ); + else if( strcmp( name, "unicodetochar" ) == 0 ) + unicodeToChar = static_cast< UnicodeToChar* >( plugin ); + else if( strcmp( name, "unnecessarycatchthrow" ) == 0 ) + unnecessaryCatchThrow = static_cast< UnnecessaryCatchThrow* >( plugin ); else if( strcmp( name, "unnecessaryoverride" ) == 0 ) unnecessaryOverride = static_cast< UnnecessaryOverride* >( plugin ); else if( strcmp( name, "unnecessaryparen" ) == 0 ) unnecessaryParen = static_cast< UnnecessaryParen* >( plugin ); + else if( strcmp( name, "unoany" ) == 0 ) + unoAny = static_cast< UnoAny* >( plugin ); + else if( strcmp( name, "unoquery" ) == 0 ) + unoQuery = static_cast< UnoQuery* >( plugin ); else if( strcmp( name, "unreffun" ) == 0 ) unrefFun = static_cast< UnrefFun* >( plugin ); else if( strcmp( name, "unusedvariablecheck" ) == 0 ) unusedVariableCheck = static_cast< UnusedVariableCheck* >( plugin ); + else if( strcmp( name, "weakbase" ) == 0 ) + weakBase = static_cast< WeakBase* >( plugin ); else if( strcmp( name, "weakobject" ) == 0 ) weakObject = static_cast< WeakObject* >( plugin ); else @@ -319,6 +439,17 @@ public: } return anyPluginActive(); } + bool VisitCStyleCastExpr(const class clang::CStyleCastExpr * arg) + { + if( ignoreLocation( arg )) + return true; + if( salUnicodeLiteral != nullptr ) + { + if( !salUnicodeLiteral->VisitCStyleCastExpr( arg )) + salUnicodeLiteral = nullptr; + } + return anyPluginActive(); + } bool VisitCXXConstructExpr(const class clang::CXXConstructExpr * arg) { if( ignoreLocation( arg )) @@ -328,6 +459,11 @@ public: if( !simplifyConstruct->VisitCXXConstructExpr( arg )) simplifyConstruct = nullptr; } + if( stringConstant != nullptr ) + { + if( !stringConstant->VisitCXXConstructExpr( arg )) + stringConstant = nullptr; + } return anyPluginActive(); } bool VisitCXXDeleteExpr(const class clang::CXXDeleteExpr * arg) @@ -341,10 +477,48 @@ public: } return anyPluginActive(); } + bool VisitCXXDependentScopeMemberExpr(const class clang::CXXDependentScopeMemberExpr * arg) + { + if( ignoreLocation( arg )) + return true; + if( staticMethods != nullptr ) + { + if( !staticMethods->VisitCXXDependentScopeMemberExpr( arg )) + staticMethods = nullptr; + } + return anyPluginActive(); + } + bool VisitCXXFunctionalCastExpr(const class clang::CXXFunctionalCastExpr * arg) + { + if( ignoreLocation( arg )) + return true; + if( salUnicodeLiteral != nullptr ) + { + if( !salUnicodeLiteral->VisitCXXFunctionalCastExpr( arg )) + salUnicodeLiteral = nullptr; + } + return anyPluginActive(); + } + bool VisitCXXMemberCallExpr(const class clang::CXXMemberCallExpr * arg) + { + if( ignoreLocation( arg )) + return true; + if( unoQuery != nullptr ) + { + if( !unoQuery->VisitCXXMemberCallExpr( arg )) + unoQuery = nullptr; + } + return anyPluginActive(); + } bool VisitCXXMethodDecl(const class clang::CXXMethodDecl * arg) { if( ignoreLocation( arg )) return true; + if( typedefParam != nullptr ) + { + if( !typedefParam->VisitCXXMethodDecl( arg )) + typedefParam = nullptr; + } if( unnecessaryOverride != nullptr ) { if( !unnecessaryOverride->VisitCXXMethodDecl( arg )) @@ -377,6 +551,11 @@ public: if( !unnecessaryParen->VisitCXXOperatorCallExpr( arg )) unnecessaryParen = nullptr; } + if( unoAny != nullptr ) + { + if( !unoAny->VisitCXXOperatorCallExpr( arg )) + unoAny = nullptr; + } return anyPluginActive(); } bool VisitCXXRecordDecl(const class clang::CXXRecordDecl * arg) @@ -388,6 +567,54 @@ public: if( !privateBase->VisitCXXRecordDecl( arg )) privateBase = nullptr; } + if( sfxPoolItem != nullptr ) + { + if( !sfxPoolItem->VisitCXXRecordDecl( arg )) + sfxPoolItem = nullptr; + } + if( weakBase != nullptr ) + { + if( !weakBase->VisitCXXRecordDecl( arg )) + weakBase = nullptr; + } + return anyPluginActive(); + } + bool VisitCXXStaticCastExpr(const class clang::CXXStaticCastExpr * arg) + { + if( ignoreLocation( arg )) + return true; + if( salUnicodeLiteral != nullptr ) + { + if( !salUnicodeLiteral->VisitCXXStaticCastExpr( arg )) + salUnicodeLiteral = nullptr; + } + if( simplifyDynamicCast != nullptr ) + { + if( !simplifyDynamicCast->VisitCXXStaticCastExpr( arg )) + simplifyDynamicCast = nullptr; + } + return anyPluginActive(); + } + bool VisitCXXThisExpr(const class clang::CXXThisExpr * arg) + { + if( ignoreLocation( arg )) + return true; + if( staticMethods != nullptr ) + { + if( !staticMethods->VisitCXXThisExpr( arg )) + staticMethods = nullptr; + } + return anyPluginActive(); + } + bool VisitCXXTryStmt(const class clang::CXXTryStmt * arg) + { + if( ignoreLocation( arg )) + return true; + if( unnecessaryCatchThrow != nullptr ) + { + if( !unnecessaryCatchThrow->VisitCXXTryStmt( arg )) + unnecessaryCatchThrow = nullptr; + } return anyPluginActive(); } bool VisitCallExpr(const class clang::CallExpr * arg) @@ -399,6 +626,16 @@ public: if( !dbgUnhandledException->VisitCallExpr( arg )) dbgUnhandledException = nullptr; } + if( stringConcat != nullptr ) + { + if( !stringConcat->VisitCallExpr( arg )) + stringConcat = nullptr; + } + if( stringConstant != nullptr ) + { + if( !stringConstant->VisitCallExpr( arg )) + stringConstant = nullptr; + } if( unnecessaryParen != nullptr ) { if( !unnecessaryParen->VisitCallExpr( arg )) @@ -501,6 +738,16 @@ public: if( !inlineVisible->VisitFunctionDecl( arg )) inlineVisible = nullptr; } + if( staticAnonymous != nullptr ) + { + if( !staticAnonymous->VisitFunctionDecl( arg )) + staticAnonymous = nullptr; + } + if( typedefParam != nullptr ) + { + if( !typedefParam->VisitFunctionDecl( arg )) + typedefParam = nullptr; + } if( unrefFun != nullptr ) { if( !unrefFun->VisitFunctionDecl( arg )) @@ -524,6 +771,17 @@ public: } return anyPluginActive(); } + bool VisitImplicitCastExpr(const class clang::ImplicitCastExpr * arg) + { + if( ignoreLocation( arg )) + return true; + if( unicodeToChar != nullptr ) + { + if( !unicodeToChar->VisitImplicitCastExpr( arg )) + unicodeToChar = nullptr; + } + return anyPluginActive(); + } bool VisitMaterializeTemporaryExpr(const class clang::MaterializeTemporaryExpr * arg) { if( ignoreLocation( arg )) @@ -539,6 +797,11 @@ public: { if( ignoreLocation( arg )) return true; + if( staticAccess != nullptr ) + { + if( !staticAccess->VisitMemberExpr( arg )) + staticAccess = nullptr; + } if( unnecessaryParen != nullptr ) { if( !unnecessaryParen->VisitMemberExpr( arg )) @@ -617,6 +880,17 @@ public: } return anyPluginActive(); } + bool VisitUnresolvedMemberExpr(const class clang::UnresolvedMemberExpr * arg) + { + if( ignoreLocation( arg )) + return true; + if( staticMethods != nullptr ) + { + if( !staticMethods->VisitUnresolvedMemberExpr( arg )) + staticMethods = nullptr; + } + return anyPluginActive(); + } bool VisitVarDecl(const class clang::VarDecl *const arg) { if( ignoreLocation( arg )) @@ -669,6 +943,13 @@ public: } return anyPluginActive(); } + bool TraverseCStyleCastExpr(class clang::CStyleCastExpr * arg) + { + UnicodeToChar* saveUnicodeToChar = unicodeToChar; + bool ret = RecursiveASTVisitor::TraverseCStyleCastExpr( arg ); + unicodeToChar = saveUnicodeToChar; + return ret; + } bool TraverseCXXBindTemporaryExpr(class clang::CXXBindTemporaryExpr * arg) { SimplifyConstruct* saveSimplifyConstruct = simplifyConstruct; @@ -698,6 +979,69 @@ public: dbgUnhandledException = saveDbgUnhandledException; return ret; } + bool TraverseCXXConstructExpr(class clang::CXXConstructExpr * arg) + { + StringConstant* saveStringConstant = stringConstant; + bool ret = RecursiveASTVisitor::TraverseCXXConstructExpr( arg ); + stringConstant = saveStringConstant; + return ret; + } + bool TraverseCXXConstructorDecl(class clang::CXXConstructorDecl * arg) + { + StaticConstField* saveStaticConstField = staticConstField; + bool ret = RecursiveASTVisitor::TraverseCXXConstructorDecl( arg ); + staticConstField = saveStaticConstField; + return ret; + } + bool TraverseCXXFunctionalCastExpr(class clang::CXXFunctionalCastExpr * arg) + { + UnicodeToChar* saveUnicodeToChar = unicodeToChar; + bool ret = RecursiveASTVisitor::TraverseCXXFunctionalCastExpr( arg ); + unicodeToChar = saveUnicodeToChar; + return ret; + } + bool TraverseCXXMemberCallExpr(class clang::CXXMemberCallExpr * arg) + { + StringConstant* saveStringConstant = stringConstant; + bool ret = RecursiveASTVisitor::TraverseCXXMemberCallExpr( arg ); + stringConstant = saveStringConstant; + return ret; + } + bool TraverseCXXMethodDecl(class clang::CXXMethodDecl * arg) + { + StaticMethods* saveStaticMethods = staticMethods; + bool ret = RecursiveASTVisitor::TraverseCXXMethodDecl( arg ); + staticMethods = saveStaticMethods; + return ret; + } + bool TraverseCXXOperatorCallExpr(class clang::CXXOperatorCallExpr * arg) + { + StringConstant* saveStringConstant = stringConstant; + bool ret = RecursiveASTVisitor::TraverseCXXOperatorCallExpr( arg ); + stringConstant = saveStringConstant; + return ret; + } + bool TraverseCXXStaticCastExpr(class clang::CXXStaticCastExpr * arg) + { + UnicodeToChar* saveUnicodeToChar = unicodeToChar; + bool ret = RecursiveASTVisitor::TraverseCXXStaticCastExpr( arg ); + unicodeToChar = saveUnicodeToChar; + return ret; + } + bool TraverseCallExpr(class clang::CallExpr * arg) + { + StringConstant* saveStringConstant = stringConstant; + bool ret = RecursiveASTVisitor::TraverseCallExpr( arg ); + stringConstant = saveStringConstant; + return ret; + } + bool TraverseConstructorInitializer(class clang::CXXCtorInitializer * arg) + { + StaticConstField* saveStaticConstField = staticConstField; + bool ret = RecursiveASTVisitor::TraverseConstructorInitializer( arg ); + staticConstField = saveStaticConstField; + return ret; + } bool TraverseFriendDecl(class clang::FriendDecl * arg) { UnrefFun* saveUnrefFun = unrefFun; @@ -715,6 +1059,13 @@ public: unrefFun = saveUnrefFun; return ret; } + bool TraverseIfStmt(class clang::IfStmt * arg) + { + SimplifyDynamicCast* saveSimplifyDynamicCast = simplifyDynamicCast; + bool ret = RecursiveASTVisitor::TraverseIfStmt( arg ); + simplifyDynamicCast = saveSimplifyDynamicCast; + return ret; + } bool TraverseInitListExpr(class clang::InitListExpr * arg) { SimplifyConstruct* saveSimplifyConstruct = simplifyConstruct; @@ -757,13 +1108,28 @@ private: || loopVarTooSmall != nullptr || privateBase != nullptr || reservedId != nullptr + || salUnicodeLiteral != nullptr + || sfxPoolItem != nullptr || simplifyConstruct != nullptr + || simplifyDynamicCast != nullptr + || staticAccess != nullptr + || staticAnonymous != nullptr + || staticConstField != nullptr + || staticMethods != nullptr + || stringConcat != nullptr + || stringConstant != nullptr || stringStatic != nullptr || subtleZeroInit != nullptr + || typedefParam != nullptr + || unicodeToChar != nullptr + || unnecessaryCatchThrow != nullptr || unnecessaryOverride != nullptr || unnecessaryParen != nullptr + || unoAny != nullptr + || unoQuery != nullptr || unrefFun != nullptr || unusedVariableCheck != nullptr + || weakBase != nullptr || weakObject != nullptr; } BadStatics* badStatics; @@ -781,13 +1147,28 @@ private: LoopVarTooSmall* loopVarTooSmall; PrivateBase* privateBase; ReservedId* reservedId; + SalUnicodeLiteral* salUnicodeLiteral; + SfxPoolItem* sfxPoolItem; SimplifyConstruct* simplifyConstruct; + SimplifyDynamicCast* simplifyDynamicCast; + StaticAccess* staticAccess; + StaticAnonymous* staticAnonymous; + StaticConstField* staticConstField; + StaticMethods* staticMethods; + StringConcat* stringConcat; + StringConstant* stringConstant; StringStatic* stringStatic; SubtleZeroInit* subtleZeroInit; + TypedefParam* typedefParam; + UnicodeToChar* unicodeToChar; + UnnecessaryCatchThrow* unnecessaryCatchThrow; UnnecessaryOverride* unnecessaryOverride; UnnecessaryParen* unnecessaryParen; + UnoAny* unoAny; + UnoQuery* unoQuery; UnrefFun* unrefFun; UnusedVariableCheck* unusedVariableCheck; + WeakBase* weakBase; WeakObject* weakObject; }; diff --git a/compilerplugins/clang/simplifydynamiccast.cxx b/compilerplugins/clang/simplifydynamiccast.cxx index b1f06179ee71..bb6e81d6ca58 100644 --- a/compilerplugins/clang/simplifydynamiccast.cxx +++ b/compilerplugins/clang/simplifydynamiccast.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 <cassert> #include <string> @@ -111,7 +112,10 @@ bool SimplifyDynamicCast::VisitCXXStaticCastExpr(CXXStaticCastExpr const* static return true; } -loplugin::Plugin::Registration<SimplifyDynamicCast> X("simplifydynamiccast", true); -} +loplugin::Plugin::Registration<SimplifyDynamicCast> simplifydynamiccast("simplifydynamiccast"); + +} // namespace + +#endif // LO_CLANG_SHARED_PLUGINS /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/staticaccess.cxx b/compilerplugins/clang/staticaccess.cxx index 6b15bfb15349..9c1abbc5cba4 100644 --- a/compilerplugins/clang/staticaccess.cxx +++ b/compilerplugins/clang/staticaccess.cxx @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef LO_CLANG_SHARED_PLUGINS + #include <cassert> #include "plugin.hxx" @@ -89,8 +91,10 @@ bool StaticAccess::VisitMemberExpr(MemberExpr const * expr) { return true; } -loplugin::Plugin::Registration<StaticAccess> X("staticaccess"); +loplugin::Plugin::Registration<StaticAccess> staticaccess("staticaccess"); -} +} // namespace + +#endif // LO_CLANG_SHARED_PLUGINS /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/staticanonymous.cxx b/compilerplugins/clang/staticanonymous.cxx index f31499af6f73..0fd00f2279e7 100644 --- a/compilerplugins/clang/staticanonymous.cxx +++ b/compilerplugins/clang/staticanonymous.cxx @@ -5,6 +5,8 @@ * Based on LLVM/Clang. * */ +#ifndef LO_CLANG_SHARED_PLUGINS + #include "plugin.hxx" /* @@ -22,7 +24,7 @@ class StaticAnonymous public: explicit StaticAnonymous( const InstantiationData& data ); virtual void run() override; - bool VisitFunctionDecl( FunctionDecl* func ); + bool VisitFunctionDecl( const FunctionDecl* func ); }; @@ -37,7 +39,7 @@ void StaticAnonymous::run() } -bool StaticAnonymous::VisitFunctionDecl( FunctionDecl* func ) +bool StaticAnonymous::VisitFunctionDecl( const FunctionDecl* func ) { if( ignoreLocation( func ) ) @@ -59,8 +61,10 @@ bool StaticAnonymous::VisitFunctionDecl( FunctionDecl* func ) } // Register the plugin action with the LO plugin handling. -static Plugin::Registration< StaticAnonymous > X( "staticanonymous",true); +static Plugin::Registration< StaticAnonymous > staticanonymous("staticanonymous"); } // namespace +#endif // LO_CLANG_SHARED_PLUGINS + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/staticconstfield.cxx b/compilerplugins/clang/staticconstfield.cxx index 91a798daa5bd..3d9d4c6411ae 100644 --- a/compilerplugins/clang/staticconstfield.cxx +++ b/compilerplugins/clang/staticconstfield.cxx @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef LO_CLANG_SHARED_PLUGINS + #include "plugin.hxx" #include "check.hxx" #include "compat.hxx" @@ -28,6 +30,7 @@ public: { } + bool preRun() override; void run() override; bool TraverseConstructorInitializer(CXXCtorInitializer* init); @@ -44,15 +47,23 @@ private: CXXConstructorDecl* m_currentConstructor = nullptr; }; -void StaticConstField::run() +bool StaticConstField::preRun() { std::string fn = handler.getMainFileName(); loplugin::normalizeDotDotInFilePath(fn); // unusual case where a user constructor sets a field to one value, and a copy constructor sets it to a different value if (fn == SRCDIR "/sw/source/core/attr/hints.cxx") - return; + return false; if (fn == SRCDIR "/oox/source/core/contexthandler2.cxx") + return false; + + return true; +} + +void StaticConstField::run() +{ + if (!preRun()) return; TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); @@ -168,7 +179,10 @@ bool StaticConstField::TraverseConstructorInitializer(CXXCtorInitializer* init) return true; } -loplugin::Plugin::Registration<StaticConstField> X("staticconstfield", true); -} +loplugin::Plugin::Registration<StaticConstField> staticconstfield("staticconstfield"); + +} // namespace + +#endif // LO_CLANG_SHARED_PLUGINS /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/staticmethods.cxx b/compilerplugins/clang/staticmethods.cxx index bc37189eb64b..0d82170a4b3e 100644 --- a/compilerplugins/clang/staticmethods.cxx +++ b/compilerplugins/clang/staticmethods.cxx @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef LO_CLANG_SHARED_PLUGINS + #include "clang/AST/Attr.h" #include "check.hxx" @@ -28,7 +30,7 @@ public: void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } - bool TraverseCXXMethodDecl(const CXXMethodDecl * decl); + bool TraverseCXXMethodDecl(CXXMethodDecl * decl); bool VisitCXXThisExpr(const CXXThisExpr *) { bVisitedThis = true; return true; } // these two indicate that we hit something that makes our analysis unreliable @@ -67,7 +69,7 @@ bool startsWith(const std::string& rStr, const char* pSubStr) { return rStr.compare(0, strlen(pSubStr), pSubStr) == 0; } -bool StaticMethods::TraverseCXXMethodDecl(const CXXMethodDecl * pCXXMethodDecl) { +bool StaticMethods::TraverseCXXMethodDecl(CXXMethodDecl * pCXXMethodDecl) { if (ignoreLocation(pCXXMethodDecl)) { return true; } @@ -231,8 +233,10 @@ bool StaticMethods::TraverseCXXMethodDecl(const CXXMethodDecl * pCXXMethodDecl) return true; } -loplugin::Plugin::Registration<StaticMethods> X("staticmethods"); +loplugin::Plugin::Registration<StaticMethods> staticmethods("staticmethods"); -} +} // namespace + +#endif // LO_CLANG_SHARED_PLUGINS /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/stringconcat.cxx b/compilerplugins/clang/stringconcat.cxx index da4b212e9f73..8511f849d64f 100644 --- a/compilerplugins/clang/stringconcat.cxx +++ b/compilerplugins/clang/stringconcat.cxx @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef LO_CLANG_SHARED_PLUGINS + #include "plugin.hxx" #include "check.hxx" @@ -151,8 +153,10 @@ bool StringConcat::isStringLiteral(Expr const * expr) { != "OSL_THIS_FUNC"); } -loplugin::Plugin::Registration<StringConcat> X("stringconcat"); +loplugin::Plugin::Registration<StringConcat> stringconcat("stringconcat"); -} +} // namespace + +#endif // LO_CLANG_SHARED_PLUGINS /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx index 05cfa03ff711..29ff508e8c7c 100644 --- a/compilerplugins/clang/stringconstant.cxx +++ b/compilerplugins/clang/stringconstant.cxx @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef LO_CLANG_SHARED_PLUGINS + #include <algorithm> #include <cassert> #include <cstdint> @@ -108,6 +110,8 @@ public: explicit StringConstant(loplugin::InstantiationData const & data): FilteringRewritePlugin(data) {} + bool preRun() override; + void run() override; bool TraverseCallExpr(CallExpr * expr); @@ -186,14 +190,15 @@ private: std::stack<Expr const *> calls_; }; -void StringConstant::run() { - if (compiler.getLangOpts().CPlusPlus +bool StringConstant::preRun() { + return compiler.getLangOpts().CPlusPlus && compiler.getPreprocessor().getIdentifierInfo( - "LIBO_INTERNAL_ONLY")->hasMacroDefinition()) + "LIBO_INTERNAL_ONLY")->hasMacroDefinition(); //TODO: some parts of it are useful for external code, too - { +} +void StringConstant::run() { + if (preRun()) TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); - } } bool StringConstant::TraverseCallExpr(CallExpr * expr) { @@ -2087,8 +2092,10 @@ void StringConstant::handleFunArgOstring( } } -loplugin::Plugin::Registration< StringConstant > X("stringconstant", true); +loplugin::Plugin::Registration< StringConstant > stringconstant("stringconstant"); -} +} // namespace + +#endif // LO_CLANG_SHARED_PLUGINS /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/typedefparam.cxx b/compilerplugins/clang/typedefparam.cxx index 0b7a74ba1696..2c7031ff7af0 100644 --- a/compilerplugins/clang/typedefparam.cxx +++ b/compilerplugins/clang/typedefparam.cxx @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef LO_CLANG_SHARED_PLUGINS + #include <cassert> #include <string> #include <iostream> @@ -31,7 +33,7 @@ public: { } - virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } + void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } bool VisitFunctionDecl(FunctionDecl const*); bool VisitCXXMethodDecl(CXXMethodDecl const*); @@ -321,7 +323,10 @@ static bool areTypesEqual(QualType lhs, QualType rhs) return lhsType == rhsType; } -loplugin::Plugin::Registration<TypedefParam> X("typedefparam", true); -} +loplugin::Plugin::Registration<TypedefParam> typedefparam("typedefparam"); + +} // namespace + +#endif // LO_CLANG_SHARED_PLUGINS /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/unicodetochar.cxx b/compilerplugins/clang/unicodetochar.cxx index e1e381ad2c71..14a59e35f462 100644 --- a/compilerplugins/clang/unicodetochar.cxx +++ b/compilerplugins/clang/unicodetochar.cxx @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef LO_CLANG_SHARED_PLUGINS + #include <stack> #include "check.hxx" @@ -72,18 +74,24 @@ public: return true; } -private: + bool preRun() override { + return compiler.getLangOpts().CPlusPlus; + } + void run() override { - if (compiler.getLangOpts().CPlusPlus) { + if (preRun()) { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } } +private: std::stack<Expr const *> subExprs_; }; -static loplugin::Plugin::Registration<UnicodeToChar> reg("unicodetochar"); +static loplugin::Plugin::Registration<UnicodeToChar> unicodetochar("unicodetochar"); + +} // namespace -} +#endif // LO_CLANG_SHARED_PLUGINS /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/compilerplugins/clang/unnecessarycatchthrow.cxx b/compilerplugins/clang/unnecessarycatchthrow.cxx index 73cb01456a40..903e903823ab 100644 --- a/compilerplugins/clang/unnecessarycatchthrow.cxx +++ b/compilerplugins/clang/unnecessarycatchthrow.cxx @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef LO_CLANG_SHARED_PLUGINS + #include <cassert> #include <string> #include <iostream> @@ -81,8 +83,10 @@ bool UnnecessaryCatchThrow::VisitCXXTryStmt(CXXTryStmt const * tryStmt) } -loplugin::Plugin::Registration< UnnecessaryCatchThrow > X("unnecessarycatchthrow"); +loplugin::Plugin::Registration< UnnecessaryCatchThrow > unnecessarycatchthrow("unnecessarycatchthrow"); -} +} // namespace + +#endif // LO_CLANG_SHARED_PLUGINS /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/unoany.cxx b/compilerplugins/clang/unoany.cxx index 7d10a2361878..38e216fed437 100644 --- a/compilerplugins/clang/unoany.cxx +++ b/compilerplugins/clang/unoany.cxx @@ -7,9 +7,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef LO_CLANG_SHARED_PLUGINS + #include "check.hxx" #include "plugin.hxx" +namespace { class UnoAny: public loplugin::FilteringPlugin<UnoAny> @@ -17,9 +20,16 @@ class UnoAny: public: explicit UnoAny(loplugin::InstantiationData const & data): FilteringPlugin(data) {} + bool preRun() override { + return compiler.getLangOpts().CPlusPlus; + } + void run() override { - TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); + if (preRun()) { + TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); + } } + bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr); }; @@ -71,7 +81,10 @@ bool UnoAny::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr) return true; } -loplugin::Plugin::Registration<UnoAny> X("unoany"); +loplugin::Plugin::Registration<UnoAny> unoany("unoany"); + +} // namespace +#endif // LO_CLANG_SHARED_PLUGINS /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/compilerplugins/clang/unoquery.cxx b/compilerplugins/clang/unoquery.cxx index d445aa250623..82427555fef9 100644 --- a/compilerplugins/clang/unoquery.cxx +++ b/compilerplugins/clang/unoquery.cxx @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef LO_CLANG_SHARED_PLUGINS + #include "check.hxx" #include "plugin.hxx" @@ -24,7 +26,16 @@ public: { } - void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } + bool preRun() override { return compiler.getLangOpts().CPlusPlus; } + + void run() override + { + if (preRun()) + { + TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); + } + } + bool VisitCXXMemberCallExpr(CXXMemberCallExpr const*); }; @@ -79,7 +90,10 @@ bool UnoQuery::VisitCXXMemberCallExpr(CXXMemberCallExpr const* memberCallExpr) return true; } -loplugin::Plugin::Registration<UnoQuery> unoquery("unoquery", true); -}; +loplugin::Plugin::Registration<UnoQuery> unoquery("unoquery"); + +} // namespace + +#endif // LO_CLANG_SHARED_PLUGINS /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/compilerplugins/clang/weakbase.cxx b/compilerplugins/clang/weakbase.cxx index fbd72955c0ba..a0040dd37c30 100644 --- a/compilerplugins/clang/weakbase.cxx +++ b/compilerplugins/clang/weakbase.cxx @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef LO_CLANG_SHARED_PLUGINS + #include <string> #include <iostream> #include <map> @@ -28,7 +30,15 @@ public: { } - virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } + bool preRun() override { return compiler.getLangOpts().CPlusPlus; } + + void run() override + { + if (preRun()) + { + TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); + } + } bool VisitCXXRecordDecl(CXXRecordDecl const*); }; @@ -104,7 +114,10 @@ bool WeakBase::VisitCXXRecordDecl(CXXRecordDecl const* recordDecl) return true; } -loplugin::Plugin::Registration<WeakBase> WeakBase("weakbase", true); -} +loplugin::Plugin::Registration<WeakBase> weakbase("weakbase"); + +} // namespace + +#endif // LO_CLANG_SHARED_PLUGINS /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits