diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-07-16 12:35:16 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-07-16 21:31:07 +0200 |
commit | 70c6651e02c4582d66d8e1c1286406c4f01a7d4b (patch) | |
tree | 6a49b8cb229f7eed80e9d461fc70da76237c4bb1 /compilerplugins/clang | |
parent | 08b4e947584d3e3629089cdcec50dd566c5c031c (diff) |
convert redundantfcast to LO_CLANG_SHARED_PLUGINS
Change-Id: I8c1c990d91676b33f2fd508025acfa93a66f4950
Reviewed-on: https://gerrit.libreoffice.org/75724
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang')
-rw-r--r-- | compilerplugins/clang/redundantfcast.cxx | 35 | ||||
-rw-r--r-- | compilerplugins/clang/sharedvisitor/sharedvisitor.cxx | 30 |
2 files changed, 47 insertions, 18 deletions
diff --git a/compilerplugins/clang/redundantfcast.cxx b/compilerplugins/clang/redundantfcast.cxx index 43049700ee35..a53c42d73add 100644 --- a/compilerplugins/clang/redundantfcast.cxx +++ b/compilerplugins/clang/redundantfcast.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 "compat.hxx" @@ -23,15 +24,6 @@ public: { } - bool TraverseFunctionDecl(FunctionDecl* functionDecl) - { - auto prev = m_CurrentFunctionDecl; - m_CurrentFunctionDecl = functionDecl; - auto rv = RecursiveASTVisitor<RedundantFCast>::TraverseFunctionDecl(functionDecl); - m_CurrentFunctionDecl = prev; - return rv; - } - bool VisitReturnStmt(ReturnStmt const* returnStmt) { if (ignoreLocation(returnStmt)) @@ -206,25 +198,32 @@ public: return true; } -private: - void run() override + bool preRun() override { if (!compiler.getLangOpts().CPlusPlus) - return; + return false; std::string fn = handler.getMainFileName(); loplugin::normalizeDotDotInFilePath(fn); // necessary on some other platforms if (fn == SRCDIR "/sal/osl/unx/socket.cxx") - return; + return false; // compile-time check of constant if (fn == SRCDIR "/bridges/source/jni_uno/jni_bridge.cxx") - return; - TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); + return false; + return true; + } + + void run() override + { + if (preRun()) + TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } - FunctionDecl const* m_CurrentFunctionDecl; }; -static loplugin::Plugin::Registration<RedundantFCast> reg("redundantfcast"); -} +static loplugin::Plugin::Registration<RedundantFCast> redundantfcast("redundantfcast"); + +} // 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/sharedvisitor/sharedvisitor.cxx b/compilerplugins/clang/sharedvisitor/sharedvisitor.cxx index d48343171646..714aa3fd589f 100644 --- a/compilerplugins/clang/sharedvisitor/sharedvisitor.cxx +++ b/compilerplugins/clang/sharedvisitor/sharedvisitor.cxx @@ -25,6 +25,7 @@ #include "../inlinevisible.cxx" #include "../loopvartoosmall.cxx" #include "../privatebase.cxx" +#include "../redundantfcast.cxx" #include "../redundantinline.cxx" #include "../redundantpointerops.cxx" #include "../reservedid.cxx" @@ -77,6 +78,7 @@ public: , inlineVisible( nullptr ) , loopVarTooSmall( nullptr ) , privateBase( nullptr ) + , redundantFCast( nullptr ) , redundantInline( nullptr ) , redundantPointerOps( nullptr ) , reservedId( nullptr ) @@ -131,6 +133,8 @@ public: loopVarTooSmall = nullptr; if( privateBase && !privateBase->preRun()) privateBase = nullptr; + if( redundantFCast && !redundantFCast->preRun()) + redundantFCast = nullptr; if( redundantInline && !redundantInline->preRun()) redundantInline = nullptr; if( redundantPointerOps && !redundantPointerOps->preRun()) @@ -209,6 +213,8 @@ public: loopVarTooSmall->postRun(); if( privateBase ) privateBase->postRun(); + if( redundantFCast ) + redundantFCast->postRun(); if( redundantInline ) redundantInline->postRun(); if( redundantPointerOps ) @@ -293,6 +299,8 @@ public: loopVarTooSmall = static_cast< LoopVarTooSmall* >( plugin ); else if( strcmp( name, "privatebase" ) == 0 ) privateBase = static_cast< PrivateBase* >( plugin ); + else if( strcmp( name, "redundantfcast" ) == 0 ) + redundantFCast = static_cast< RedundantFCast* >( plugin ); else if( strcmp( name, "redundantinline" ) == 0 ) redundantInline = static_cast< RedundantInline* >( plugin ); else if( strcmp( name, "redundantpointerops" ) == 0 ) @@ -446,6 +454,11 @@ public: { if( ignoreLocation( arg )) return true; + if( redundantFCast != nullptr ) + { + if( !redundantFCast->VisitCXXConstructExpr( arg )) + redundantFCast = nullptr; + } if( simplifyConstruct != nullptr ) { if( !simplifyConstruct->VisitCXXConstructExpr( arg )) @@ -468,6 +481,11 @@ public: { if( ignoreLocation( arg )) return true; + if( redundantFCast != nullptr ) + { + if( !redundantFCast->VisitCXXFunctionalCastExpr( arg )) + redundantFCast = nullptr; + } if( salUnicodeLiteral != nullptr ) { if( !salUnicodeLiteral->VisitCXXFunctionalCastExpr( arg )) @@ -586,6 +604,11 @@ public: if( !dbgUnhandledException->VisitCallExpr( arg )) dbgUnhandledException = nullptr; } + if( redundantFCast != nullptr ) + { + if( !redundantFCast->VisitCallExpr( arg )) + redundantFCast = nullptr; + } if( salLogAreas != nullptr ) { if( !salLogAreas->VisitCallExpr( arg )) @@ -815,6 +838,11 @@ public: { if( ignoreLocation( arg )) return true; + if( redundantFCast != nullptr ) + { + if( !redundantFCast->VisitReturnStmt( arg )) + redundantFCast = nullptr; + } if( stringStatic != nullptr ) { if( !stringStatic->VisitReturnStmt( arg )) @@ -1061,6 +1089,7 @@ private: || inlineVisible != nullptr || loopVarTooSmall != nullptr || privateBase != nullptr + || redundantFCast != nullptr || redundantInline != nullptr || redundantPointerOps != nullptr || reservedId != nullptr @@ -1099,6 +1128,7 @@ private: InlineVisible* inlineVisible; LoopVarTooSmall* loopVarTooSmall; PrivateBase* privateBase; + RedundantFCast* redundantFCast; RedundantInline* redundantInline; RedundantPointerOps* redundantPointerOps; ReservedId* reservedId; |