Kaydet (Commit) be94207e authored tarafından Noel Grandin's avatar Noel Grandin

new loplugin:emptyif

Change-Id: I1092115a0ceb3a5e6680a4b724b129f98a892c42
Reviewed-on: https://gerrit.libreoffice.org/48128Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 7d9a5d88
......@@ -489,10 +489,6 @@ sal_Bool VCLXAccessibleBox::setCurrentValue( const Any& aNumber )
OUString fValue;
bool bValid = (aNumber >>= fValue);
if( bValid )
{
}
return bValid;
}
......
......@@ -125,23 +125,11 @@ void SAL_CALL MediaEventListenersImpl::mouseReleased( const css::awt::MouseEvent
void SAL_CALL MediaEventListenersImpl::mouseEntered( const css::awt::MouseEvent& )
{
const ::osl::MutexGuard aGuard( maMutex );
const SolarMutexGuard aAppGuard;
if( mpNotifyWindow )
{
}
}
void SAL_CALL MediaEventListenersImpl::mouseExited( const css::awt::MouseEvent& )
{
const ::osl::MutexGuard aGuard( maMutex );
const SolarMutexGuard aAppGuard;
if( mpNotifyWindow )
{
}
}
......
......@@ -484,12 +484,6 @@ bool LanguageBox::PreNotify( NotifyEvent& rNEvt )
break;
}
}
else if( rNEvt.GetType() == MouseNotifyEvent::GETFOCUS )
{
}
else if( rNEvt.GetType() == MouseNotifyEvent::LOSEFOCUS )
{
}
return bDone || ListBox::PreNotify( rNEvt );
}
......
......@@ -285,11 +285,7 @@ namespace basctl
,m_bDocumentClosed( false )
{
if ( _rxDocument.is() )
{
if ( impl_initDocument_nothrow( _rxDocument ) )
{
}
}
impl_initDocument_nothrow( _rxDocument );
}
ScriptDocument::Impl::~Impl()
......
......@@ -127,9 +127,6 @@ void Coverage::process_directory(const OUString& sDirName)
}
}
}
else
{
}
fprintf(stderr,"end process directory\n");
}
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* 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/.
*/
#include <cassert>
#include <string>
#include <iostream>
#include <fstream>
#include <set>
#include "plugin.hxx"
/**
Check for places where we do
if (xxx) ;
or
if (xxx) {}
*/
namespace
{
class EmptyIf : public RecursiveASTVisitor<EmptyIf>, public loplugin::RewritePlugin
{
public:
explicit EmptyIf(loplugin::InstantiationData const& data)
: RewritePlugin(data)
{
}
virtual void run() override
{
StringRef fn(compiler.getSourceManager()
.getFileEntryForID(compiler.getSourceManager().getMainFileID())
->getName());
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
bool VisitIfStmt(IfStmt const*);
private:
bool ContainsComment(Stmt const*);
};
static bool empty(Stmt const* stmt)
{
if (isa<NullStmt>(stmt))
return true;
auto compoundStmt = dyn_cast<CompoundStmt>(stmt);
if (!compoundStmt)
return false;
return compoundStmt->size() == 0;
}
bool EmptyIf::ContainsComment(Stmt const* stmt)
{
auto range = stmt->getSourceRange();
SourceManager& SM = compiler.getSourceManager();
SourceLocation startLoc = range.getBegin();
SourceLocation endLoc = range.getEnd();
char const* p1 = SM.getCharacterData(startLoc);
char const* p2 = SM.getCharacterData(endLoc);
p2 += Lexer::MeasureTokenLength(endLoc, SM, compiler.getLangOpts());
auto s = llvm::StringRef(p1, p2 - p1);
return s.find("//") != llvm::StringRef::npos || s.find("/*") != llvm::StringRef::npos
|| s.find("#if") != llvm::StringRef::npos;
}
bool EmptyIf::VisitIfStmt(IfStmt const* ifStmt)
{
if (ignoreLocation(ifStmt))
return true;
if (ifStmt->getElse() && empty(ifStmt->getElse()) && !ContainsComment(ifStmt->getElse()))
{
report(DiagnosticsEngine::Warning, "empty else body", ifStmt->getElse()->getLocStart())
<< ifStmt->getElse()->getSourceRange();
return true;
}
if (!ifStmt->getElse() && empty(ifStmt->getThen()) && !ContainsComment(ifStmt->getThen()))
{
report(DiagnosticsEngine::Warning, "empty if body", ifStmt->getLocStart())
<< ifStmt->getSourceRange();
}
return true;
}
loplugin::Plugin::Registration<EmptyIf> X("emptyif", true);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* 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/.
*/
int main()
{
int x = 1;
if (x == 1) // expected-error {{empty if body [loplugin:emptyif]}}
;
if (x == 1)
{
}
// expected-error@-3 {{empty if body [loplugin:emptyif]}}
if (x == 1)
{
}
else
{
}
// expected-error@-2 {{empty else body [loplugin:emptyif]}}
if (x == 1)
{
}
else
; // expected-error {{empty else body [loplugin:emptyif]}}
if (x == 1)
{
}
else
{
x = 2;
}
// no warning expected
if (x == 1)
{
x = 3;
}
if (x == 1)
x = 3;
if (x == 1)
{
//
}
if (x == 1)
{
/* */
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
......@@ -382,11 +382,6 @@ void OTableHelper::refreshForeignKeys(::std::vector< OUString>& _rNames)
const sal_Int32 nDeleteRule = xRow->getInt(11);
const OUString sFkName = xRow->getString(12);
if ( pKeyProps.get() )
{
}
if ( !sFkName.isEmpty() && !xRow->wasNull() )
{
if ( sOldFKName != sFkName )
......
......@@ -305,13 +305,6 @@ namespace dbtools
OUString sSql = "SELECT * FROM x WHERE " + sField + _rPredicateValue;
std::unique_ptr<OSQLParseNode> pParseNode( const_cast< OSQLParser& >( m_aParser ).parseTree( sError, sSql, true ) );
nType = DataType::DOUBLE;
if ( pParseNode.get() )
{
OSQLParseNode* pColumnRef = pParseNode->getByRule(OSQLParseNode::column_ref);
if ( pColumnRef )
{
}
}
}
Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData();
......
......@@ -166,9 +166,6 @@ BackendImpl::BackendImpl(
"Scripting Framework Script Library"
) )
{
if (! transientMode())
{
}
}
......
......@@ -498,9 +498,6 @@ void UpdateHandler::updateState( UpdateState eState )
if ( meLastState == eState )
return;
if ( isVisible() )
{} // ToTop();
OUString sText;
switch ( eState )
......
......@@ -457,11 +457,6 @@ void CGM::ImplMapDouble( double& nNumb )
break;
}
}
else
{
}
}
void CGM::ImplMapX( double& nNumb )
......@@ -497,11 +492,6 @@ void CGM::ImplMapX( double& nNumb )
break;
}
}
else
{
}
}
void CGM::ImplMapY( double& nNumb )
......@@ -537,11 +527,6 @@ void CGM::ImplMapY( double& nNumb )
break;
}
}
else
{
}
}
// convert a point to the current VC mapmode (1/100TH mm)
......@@ -582,11 +567,6 @@ void CGM::ImplMapPoint( FloatPoint& rFloatPoint )
break;
}
}
else
{
}
}
void CGM::ImplDoClass()
......
......@@ -1011,7 +1011,7 @@ YY_MALLOC_DECL
/* This used to be an fputs(), but since the string might contain NUL's,
* we now use fwrite().
*/
#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (false)
#define ECHO do { fwrite( yytext, yyleng, 1, yyout ); } while (false)
#endif
/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
......
......@@ -261,9 +261,7 @@ void LwpCHBlkMarker::ProcessKeylist(XFContentContainer* pXFPara,sal_uInt8 nType)
pList->SetLabels(m_Keylist);
pXFPara->Add(pList);
}
else if (nType == MARKER_END)//skip
{
}
// else skip MARKER_END
}
else
{
......
......@@ -59,9 +59,6 @@ namespace oox { namespace ppt {
}
return this;
case PPT_TOKEN( bldSub ):
if( mbInBldGraphic )
{
}
return this;
case PPT_TOKEN( bldGraphic ):
{
......
......@@ -890,9 +890,6 @@ void ORptExport::exportContainer(const Reference< XSection>& _xSection)
{
eToken = XML_SUB_DOCUMENT;
}
else if ( xSection.is() )
{
}
if ( bExportData )
{
......
......@@ -1578,11 +1578,7 @@ void OReportController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >
break;
case SID_EXPORTDOC:
case SID_EXPORTDOCASPDF:
break;
case SID_PRINTPREVIEW:
if ( m_xReportDefinition.is() )
{
}
break;
case SID_EDITDOC:
if(isEditable())
......
......@@ -220,9 +220,7 @@ void OpGestep::GenSlidingWindowFunction(
{
ss << " {\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......
......@@ -124,9 +124,7 @@ vSubArguments)
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss <<" temp="<<vSubArguments[i]->GenSlidingWindowDeclRef();
......@@ -2334,9 +2332,7 @@ void OpPMT::GenSlidingWindowFunction(std::stringstream &ss,
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss <<" temp="<<vSubArguments[i]->GenSlidingWindowDeclRef();
......@@ -2528,9 +2524,7 @@ void OpPrice::GenSlidingWindowFunction(std::stringstream &ss,
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -2626,9 +2620,7 @@ void OpOddlprice::GenSlidingWindowFunction(std::stringstream &ss,
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -2725,9 +2717,7 @@ void OpOddlyield::GenSlidingWindowFunction(std::stringstream &ss,
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -2805,9 +2795,7 @@ void OpPriceDisc::GenSlidingWindowFunction(std::stringstream &ss,
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -2867,9 +2855,7 @@ void OpNper::GenSlidingWindowFunction(std::stringstream &ss,
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -2944,9 +2930,7 @@ void OpPPMT::GenSlidingWindowFunction(std::stringstream &ss,
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " arg=";
......
......@@ -159,9 +159,7 @@ void OpMROUND::GenSlidingWindowFunction(std::stringstream &ss,
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " tmp=";
......
......@@ -1156,9 +1156,7 @@ void OpExponDist::GenSlidingWindowFunction(std::stringstream &ss,
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -1245,9 +1243,7 @@ void OpFdist::GenSlidingWindowFunction(std::stringstream &ss,
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -3198,9 +3194,7 @@ void OpNegbinomdist::GenSlidingWindowFunction(
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -3694,9 +3688,7 @@ void OpConfidence::GenSlidingWindowFunction(std::stringstream& ss,
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -3768,9 +3760,7 @@ void OpCritBinom::GenSlidingWindowFunction(std::stringstream& ss,
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -3996,9 +3986,7 @@ void OpChiInv::GenSlidingWindowFunction(
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << "if (isnan(";
......@@ -4121,9 +4109,7 @@ void OpNormsdist::GenSlidingWindowFunction(
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -4181,9 +4167,7 @@ void OpPermut::GenSlidingWindowFunction(
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -4291,9 +4275,7 @@ void OpPhi::GenSlidingWindowFunction(
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -4350,9 +4332,7 @@ void OpNorminv::GenSlidingWindowFunction(
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -4562,9 +4542,7 @@ void OpNormsinv:: GenSlidingWindowFunction
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -5761,9 +5739,7 @@ void OpChiDist::GenSlidingWindowFunction(
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -5871,9 +5847,7 @@ void OpBinomdist::GenSlidingWindowFunction(
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -6803,9 +6777,7 @@ void OpPoisson::GenSlidingWindowFunction(
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -7347,10 +7319,7 @@ void OpBetainv::GenSlidingWindowFunction(
{
ss << "{\n";
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isnan(";
......@@ -7771,9 +7740,6 @@ void OpMinA::GenSlidingWindowFunction(
ss << " {\n";
isMixed = svDoubleDouble;
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
......@@ -7921,9 +7887,6 @@ vSubArguments)
ss << " {\n";
isMixed = svDoubleDouble;
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
......@@ -8060,9 +8023,6 @@ vSubArguments)
ss << " {\n";
isMixed = svDoubleDouble;
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
......@@ -8210,9 +8170,6 @@ vSubArguments)
ss << " {\n";
isMixed = svDoubleDouble;
}
else
{
}
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
......
......@@ -1851,9 +1851,7 @@ void ScRange::ParseRows( const OUString& rStr,
{
if( p[0] == ':')
{
if( nullptr != (p = lcl_a1_get_row( p+1, &aEnd, &ignored, nullptr)))
{
}
p = lcl_a1_get_row( p+1, &aEnd, &ignored, nullptr);
}
else
{
......@@ -1868,9 +1866,9 @@ void ScRange::ParseRows( const OUString& rStr,
{
if( p[0] == ':')
{
if( (p[1] == 'R' || p[1] == 'r') &&
nullptr != (p = lcl_r1c1_get_row( p+1, rDetails, &aEnd, &ignored )))
if( p[1] == 'R' || p[1] == 'r' )
{
p = lcl_r1c1_get_row( p+1, rDetails, &aEnd, &ignored );
}
}
else
......