make cppunitassertequals a shared plugin
Change-Id: Ied9c26248cb72f2146fbe1a985f825f7525fa17c Reviewed-on: https://gerrit.libreoffice.org/75836 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
#ifndef LO_CLANG_SHARED_PLUGINS
|
||||||
|
|
||||||
#include "plugin.hxx"
|
#include "plugin.hxx"
|
||||||
#include "check.hxx"
|
#include "check.hxx"
|
||||||
@@ -27,9 +28,14 @@ public:
|
|||||||
explicit CppunitAssertEquals(loplugin::InstantiationData const & data):
|
explicit CppunitAssertEquals(loplugin::InstantiationData const & data):
|
||||||
FilteringPlugin(data) {}
|
FilteringPlugin(data) {}
|
||||||
|
|
||||||
|
virtual bool preRun() override
|
||||||
|
{
|
||||||
|
return compiler.getLangOpts().CPlusPlus;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void run() override
|
virtual void run() override
|
||||||
{
|
{
|
||||||
if (compiler.getLangOpts().CPlusPlus) {
|
if (preRun()) {
|
||||||
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
|
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,7 +135,7 @@ bool CppunitAssertEquals::VisitCallExpr(const CallExpr* callExpr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// copied from stringconcat.cxx
|
// copied from stringconcat.cxx
|
||||||
Expr const * stripCtor(Expr const * expr) {
|
Expr const * stripConstructor(Expr const * expr) {
|
||||||
auto e0 = expr;
|
auto e0 = expr;
|
||||||
auto const e1 = dyn_cast<CXXFunctionalCastExpr>(e0);
|
auto const e1 = dyn_cast<CXXFunctionalCastExpr>(e0);
|
||||||
if (e1 != nullptr) {
|
if (e1 != nullptr) {
|
||||||
@@ -164,7 +170,7 @@ bool CppunitAssertEquals::isCompileTimeConstant(Expr const * expr)
|
|||||||
return true;
|
return true;
|
||||||
// is string literal ?
|
// is string literal ?
|
||||||
expr = expr->IgnoreParenImpCasts();
|
expr = expr->IgnoreParenImpCasts();
|
||||||
expr = stripCtor(expr);
|
expr = stripConstructor(expr);
|
||||||
return isa<clang::StringLiteral>(expr);
|
return isa<clang::StringLiteral>(expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,8 +226,10 @@ void CppunitAssertEquals::reportEquals(
|
|||||||
<< (name == "CPPUNIT_ASSERT_MESSAGE") << negative << range;
|
<< (name == "CPPUNIT_ASSERT_MESSAGE") << negative << range;
|
||||||
}
|
}
|
||||||
|
|
||||||
loplugin::Plugin::Registration< CppunitAssertEquals > X("cppunitassertequals");
|
loplugin::Plugin::Registration< CppunitAssertEquals > cppunitassertequals("cppunitassertequals");
|
||||||
|
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
|
#endif // LO_CLANG_SHARED_PLUGINS
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
#include "../badstatics.cxx"
|
#include "../badstatics.cxx"
|
||||||
#include "../blockblock.cxx"
|
#include "../blockblock.cxx"
|
||||||
#include "../charrightshift.cxx"
|
#include "../charrightshift.cxx"
|
||||||
|
#include "../cppunitassertequals.cxx"
|
||||||
#include "../data.cxx"
|
#include "../data.cxx"
|
||||||
#include "../datamembershadow.cxx"
|
#include "../datamembershadow.cxx"
|
||||||
#include "../dbgunhandledexception.cxx"
|
#include "../dbgunhandledexception.cxx"
|
||||||
@@ -84,6 +85,7 @@ public:
|
|||||||
, badStatics( nullptr )
|
, badStatics( nullptr )
|
||||||
, blockBlock( nullptr )
|
, blockBlock( nullptr )
|
||||||
, charRightShift( nullptr )
|
, charRightShift( nullptr )
|
||||||
|
, cppunitAssertEquals( nullptr )
|
||||||
, data( nullptr )
|
, data( nullptr )
|
||||||
, dataMemberShadow( nullptr )
|
, dataMemberShadow( nullptr )
|
||||||
, dbgUnhandledException( nullptr )
|
, dbgUnhandledException( nullptr )
|
||||||
@@ -143,6 +145,8 @@ public:
|
|||||||
blockBlock = nullptr;
|
blockBlock = nullptr;
|
||||||
if( charRightShift && !charRightShift->preRun())
|
if( charRightShift && !charRightShift->preRun())
|
||||||
charRightShift = nullptr;
|
charRightShift = nullptr;
|
||||||
|
if( cppunitAssertEquals && !cppunitAssertEquals->preRun())
|
||||||
|
cppunitAssertEquals = nullptr;
|
||||||
if( data && !data->preRun())
|
if( data && !data->preRun())
|
||||||
data = nullptr;
|
data = nullptr;
|
||||||
if( dataMemberShadow && !dataMemberShadow->preRun())
|
if( dataMemberShadow && !dataMemberShadow->preRun())
|
||||||
@@ -253,6 +257,8 @@ public:
|
|||||||
blockBlock->postRun();
|
blockBlock->postRun();
|
||||||
if( charRightShift )
|
if( charRightShift )
|
||||||
charRightShift->postRun();
|
charRightShift->postRun();
|
||||||
|
if( cppunitAssertEquals )
|
||||||
|
cppunitAssertEquals->postRun();
|
||||||
if( data )
|
if( data )
|
||||||
data->postRun();
|
data->postRun();
|
||||||
if( dataMemberShadow )
|
if( dataMemberShadow )
|
||||||
@@ -369,6 +375,8 @@ public:
|
|||||||
blockBlock = static_cast< BlockBlock* >( plugin );
|
blockBlock = static_cast< BlockBlock* >( plugin );
|
||||||
else if( strcmp( name, "charrightshift" ) == 0 )
|
else if( strcmp( name, "charrightshift" ) == 0 )
|
||||||
charRightShift = static_cast< CharRightShift* >( plugin );
|
charRightShift = static_cast< CharRightShift* >( plugin );
|
||||||
|
else if( strcmp( name, "cppunitassertequals" ) == 0 )
|
||||||
|
cppunitAssertEquals = static_cast< CppunitAssertEquals* >( plugin );
|
||||||
else if( strcmp( name, "data" ) == 0 )
|
else if( strcmp( name, "data" ) == 0 )
|
||||||
data = static_cast< Data* >( plugin );
|
data = static_cast< Data* >( plugin );
|
||||||
else if( strcmp( name, "datamembershadow" ) == 0 )
|
else if( strcmp( name, "datamembershadow" ) == 0 )
|
||||||
@@ -773,6 +781,11 @@ public:
|
|||||||
{
|
{
|
||||||
if( ignoreLocation( arg ))
|
if( ignoreLocation( arg ))
|
||||||
return true;
|
return true;
|
||||||
|
if( cppunitAssertEquals != nullptr )
|
||||||
|
{
|
||||||
|
if( !cppunitAssertEquals->VisitCallExpr( arg ))
|
||||||
|
cppunitAssertEquals = nullptr;
|
||||||
|
}
|
||||||
if( dbgUnhandledException != nullptr )
|
if( dbgUnhandledException != nullptr )
|
||||||
{
|
{
|
||||||
if( !dbgUnhandledException->VisitCallExpr( arg ))
|
if( !dbgUnhandledException->VisitCallExpr( arg ))
|
||||||
@@ -1425,6 +1438,7 @@ private:
|
|||||||
return badStatics != nullptr
|
return badStatics != nullptr
|
||||||
|| blockBlock != nullptr
|
|| blockBlock != nullptr
|
||||||
|| charRightShift != nullptr
|
|| charRightShift != nullptr
|
||||||
|
|| cppunitAssertEquals != nullptr
|
||||||
|| data != nullptr
|
|| data != nullptr
|
||||||
|| dataMemberShadow != nullptr
|
|| dataMemberShadow != nullptr
|
||||||
|| dbgUnhandledException != nullptr
|
|| dbgUnhandledException != nullptr
|
||||||
@@ -1479,6 +1493,7 @@ private:
|
|||||||
BadStatics* badStatics;
|
BadStatics* badStatics;
|
||||||
BlockBlock* blockBlock;
|
BlockBlock* blockBlock;
|
||||||
CharRightShift* charRightShift;
|
CharRightShift* charRightShift;
|
||||||
|
CppunitAssertEquals* cppunitAssertEquals;
|
||||||
Data* data;
|
Data* data;
|
||||||
DataMemberShadow* dataMemberShadow;
|
DataMemberShadow* dataMemberShadow;
|
||||||
DbgUnhandledException* dbgUnhandledException;
|
DbgUnhandledException* dbgUnhandledException;
|
||||||
|
Reference in New Issue
Block a user