loplugin:simplifybool a little more aggressive

with expressions like !(a && b)

Change-Id: Id2acec2a8d0eaaa8e5e37dbd2cae7281be36572e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100040
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2020-08-04 08:45:36 +02:00
parent f45ff1a714
commit cda88ec7a4
21 changed files with 42 additions and 38 deletions

View File

@ -255,12 +255,6 @@ static bool isAssignmentOp(clang::OverloadedOperatorKind Opc)
|| Opc == OO_AmpEqual || Opc == OO_CaretEqual || Opc == OO_PipeEqual;
}
static bool isComparisonOp(clang::OverloadedOperatorKind op)
{
return op == OO_Less || op == OO_Greater || op == OO_LessEqual || op == OO_GreaterEqual
|| op == OO_EqualEqual || op == OO_ExclaimEqual;
}
static const Expr* IgnoreImplicitAndConversionOperator(const Expr* expr)
{
expr = compat::IgnoreImplicit(expr);
@ -570,7 +564,7 @@ void BuriedAssign::MarkConditionForControlLoops(Expr const* expr)
else if (auto cxxOper = dyn_cast<CXXOperatorCallExpr>(expr))
{
// handle: ((xxx = foo()) != error)
if (isComparisonOp(cxxOper->getOperator()))
if (compat::isComparisonOp(cxxOper))
{
MarkIfAssignment(compat::IgnoreImplicit(cxxOper->getArg(0))->IgnoreParens());
MarkIfAssignment(compat::IgnoreImplicit(cxxOper->getArg(1))->IgnoreParens());

View File

@ -300,6 +300,15 @@ inline clang::QualType getDeclaredReturnType(clang::FunctionDecl const * decl) {
#endif
}
// The isComparisonOp method on CXXOperatorCallExpr is not available yet for the clang we require
inline bool isComparisonOp(clang::CXXOperatorCallExpr const * callExpr)
{
using namespace clang;
auto op = callExpr->getOperator();
return op == OO_Less || op == OO_Greater || op == OO_LessEqual || op == OO_GreaterEqual
|| op == OO_EqualEqual || op == OO_ExclaimEqual;
}
}
#endif

View File

@ -302,7 +302,7 @@ bool SimplifyBool::VisitUnaryOperator(UnaryOperator const * expr) {
if (binaryOp->isComparisonOp())
return expr;
if (auto cxxOpCall = dyn_cast<CXXOperatorCallExpr>(expr))
if (cxxOpCall->getOperator() == OO_ExclaimEqual)
if (compat::isComparisonOp(cxxOpCall))
return expr;
return (Expr const*)nullptr;
};

View File

@ -708,8 +708,8 @@ Sequence< Type > SAL_CALL ODbaseTable::getTypes( )
const Type* pEnd = pBegin + aTypes.getLength();
for(;pBegin != pEnd;++pBegin)
{
if(!(*pBegin == cppu::UnoType<XKeysSupplier>::get()||
*pBegin == cppu::UnoType<XDataDescriptorFactory>::get()))
if(*pBegin != cppu::UnoType<XKeysSupplier>::get() &&
*pBegin != cppu::UnoType<XDataDescriptorFactory>::get())
{
aOwnTypes.push_back(*pBegin);
}

View File

@ -791,7 +791,7 @@ void SAL_CALL Connection::documentEventOccured( const DocumentEvent& Event )
if (!m_bIsEmbedded)
return;
if (!(Event.EventName == "OnSave" || Event.EventName == "OnSaveAs"))
if (Event.EventName != "OnSave" && Event.EventName != "OnSaveAs")
return;
commit(); // Commit and close transaction

View File

@ -159,7 +159,7 @@ void printEntries(SvxEntries* entries)
bool
SvxConfigPage::CanConfig( const OUString& aModuleId )
{
return !(aModuleId == "com.sun.star.script.BasicIDE" || aModuleId == "com.sun.star.frame.Bibliography");
return aModuleId != "com.sun.star.script.BasicIDE" && aModuleId != "com.sun.star.frame.Bibliography";
}
static std::unique_ptr<SfxTabPage> CreateSvxMenuConfigPage( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet )

View File

@ -601,10 +601,11 @@ void ODefinitionContainer::approveNewObject(const OUString& _sName,const Referen
// XPropertyChangeListener
void SAL_CALL ODefinitionContainer::propertyChange( const PropertyChangeEvent& evt )
{
MutexGuard aGuard(m_aMutex);
if( !(evt.PropertyName == PROPERTY_NAME || evt.PropertyName == "Title") )
if( evt.PropertyName != PROPERTY_NAME && evt.PropertyName != "Title" )
return;
MutexGuard aGuard(m_aMutex);
m_bInPropertyChange = true;
try
{

View File

@ -636,7 +636,7 @@ bool BackendImpl::PackageImpl::checkLicense(
OUString sLicense = getTextFromURL(xCmdEnv, sHref);
////determine who has to agree to the license
//check correct value for attribute
if ( ! (simplLicAttr->acceptBy == "user" || simplLicAttr->acceptBy == "admin"))
if ( simplLicAttr->acceptBy != "user" && simplLicAttr->acceptBy != "admin")
throw css::deployment::DeploymentException(
"Could not obtain attribute simple-license@accept-by or it has no valid value", nullptr, Any());

View File

@ -83,8 +83,8 @@ void ImageButtonToolbarController::executeControlCommand( const css::frame::Cont
{
SolarMutexGuard aSolarMutexGuard;
// i73486 to be downward compatible use old and "wrong" also!
if( !(rControlCommand.Command == "SetImag" ||
rControlCommand.Command == "SetImage") )
if( rControlCommand.Command != "SetImag" &&
rControlCommand.Command != "SetImage" )
return;
for ( const NamedValue& rArg : rControlCommand.Arguments )

View File

@ -152,8 +152,8 @@ void FilterDetectDocHandler::parseRelationship( const AttributeList& rAttribs )
else if (aType.startsWithIgnoreAsciiCase("http://purl.oclc.org/ooxml/officeDocument"))
maOOXMLVariant = OOXMLVariant::ISO_Strict;
if ( !(aType == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" // OOXML Transitional
|| aType == "http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument") ) //OOXML strict
if ( aType != "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" // OOXML Transitional
&& aType != "http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument" ) //OOXML strict
return;
Reference<XUriReferenceFactory> xFactory = UriReferenceFactory::create( mxContext );

View File

@ -452,7 +452,8 @@ void SAL_CALL ManifestImport::endElement( const OUString& aName )
assert(nLevel >= 1);
OUString aConvertedName = ConvertName( aName );
if ( !(!aStack.empty() && aStack.rbegin()->m_aConvertedName == aConvertedName) ) return;
if ( aStack.empty() || aStack.rbegin()->m_aConvertedName != aConvertedName )
return;
if ( aConvertedName == gsFileEntryElement && aStack.back().m_bValid ) {
// root folder gets KeyInfo entry if any, for PGP encryption

View File

@ -864,9 +864,7 @@ void ParagraphObj::ImplGetNumberingLevel( PPTExBulletProvider* pBuProv, sal_Int1
else if ( aPropName == "Suffix" )
sSuffix = *o3tl::doAccess<OUString>(rPropValue.Value);
#ifdef DBG_UTIL
else if ( ! (
( aPropName == "SymbolTextDistance" )
|| ( aPropName == "GraphicBitmap" ) ) )
else if ( aPropName != "SymbolTextDistance" && aPropName != "GraphicBitmap" )
{
OSL_FAIL( "Unknown Property" );
}

View File

@ -2921,8 +2921,8 @@ sal_Int32 SAL_CALL SwAccessibleParagraph::getHyperLinkIndex( sal_Int32 nCharInde
sal_Int32 nPos = 0;
SwTextNode const* pNode(nullptr);
const SwTextAttr *pHt = aHIter.next(&pNode);
while (pHt && !(nIdx >= pTextFrame->MapModelToView(pNode, pHt->GetStart())
&& nIdx < pTextFrame->MapModelToView(pNode, pHt->GetAnyEnd())))
while (pHt && (nIdx < pTextFrame->MapModelToView(pNode, pHt->GetStart())
|| nIdx >= pTextFrame->MapModelToView(pNode, pHt->GetAnyEnd())))
{
pHt = aHIter.next(&pNode);
nPos++;

View File

@ -1016,8 +1016,8 @@ namespace sw::mark
bDeleteMark = rbIsOtherPosInRange
|| pMark->IsExpanded()
|| pSttIdx == nullptr
|| !( pMark->GetMarkPos().nNode == rStt
&& pMark->GetMarkPos().nContent == *pSttIdx );
|| pMark->GetMarkPos().nNode != rStt
|| pMark->GetMarkPos().nContent != *pSttIdx;
break;
default:
bDeleteMark = true;

View File

@ -161,8 +161,8 @@ void SaveFlyInRange( const SwPaM& rPam, const SwPosition& rInsPos,
(RndStdIds::FLY_AT_CHAR == pAnchor->GetAnchorId())) &&
// do not move if the InsPos is in the ContentArea of the Fly
( nullptr == ( pContentIdx = pFormat->GetContent().GetContentIdx() ) ||
!(*pContentIdx < rInsPos.nNode &&
rInsPos.nNode < pContentIdx->GetNode().EndOfSectionIndex())))
(*pContentIdx >= rInsPos.nNode ||
rInsPos.nNode >= pContentIdx->GetNode().EndOfSectionIndex())))
{
bool bInsPos = false;

View File

@ -2119,7 +2119,7 @@ bool SwDoc::MoveParagraphImpl(SwPaM& rPam, long const nOffset,
}
if( pOwnRedl &&
!( pRStt->nNode <= aIdx && aIdx <= pREnd->nNode ))
( pRStt->nNode > aIdx || aIdx > pREnd->nNode ))
{
// it's not in itself, so don't move it
pOwnRedl = nullptr;

View File

@ -700,7 +700,7 @@ const SfxItemPropertyMapEntry* SwUnoPropertyMapProvider::GetPropertyMapEntries(s
!pMap->aName.isEmpty(); ++pMap )
{
// OUString(UNO_NAME_PAGE_DESC_NAME) should keep its MAYBEVOID flag
if (!(RES_PAGEDESC == pMap->nWID && MID_PAGEDESC_PAGEDESCNAME == pMap->nMemberId))
if (RES_PAGEDESC != pMap->nWID || MID_PAGEDESC_PAGEDESCNAME != pMap->nMemberId)
pMap->nFlags &= ~PropertyAttribute::MAYBEVOID;
}
}

View File

@ -1509,7 +1509,7 @@ const SwRedlineData* SwWW8AttrIter::GetRunLevelRedline( sal_Int32 nPos )
if( pCurRedline )
{
const SwPosition* pEnd = pCurRedline->End();
if (!(pEnd->nNode == rNd && pEnd->nContent.GetIndex() <= nPos))
if (pEnd->nNode != rNd || pEnd->nContent.GetIndex() > nPos)
{
switch( pCurRedline->GetType() )
{

View File

@ -3363,11 +3363,11 @@ void SwXTextDocument::getPostIts(tools::JsonWriter& rJsonWriter)
void SwXTextDocument::executeFromFieldEvent(const StringMap& aArguments)
{
auto aIter = aArguments.find("type");
if (!(aIter != aArguments.end() && aIter->second == "drop-down"))
if (aIter == aArguments.end() || aIter->second != "drop-down")
return;
aIter = aArguments.find("cmd");
if (!(aIter != aArguments.end() && aIter->second == "selected"))
if (aIter == aArguments.end() || aIter->second != "selected")
return;
aIter = aArguments.find("data");

View File

@ -628,10 +628,10 @@ rtl::Reference< Entity > readEntity(
+ sub.getName()));
}
if ((mode & RT_PARAM_REST) != 0
&& !(m == 1
&& ((reader.getMethodParameterTypeName(
&& (m != 1
|| ((reader.getMethodParameterTypeName(
j, 0))
== "any")))
!= "any")))
{
throw FileFormatException(
key.getRegistryName(),

View File

@ -984,7 +984,8 @@ void ElementDescriptor::readSelectionTypeAttr( OUString const & rPropName, OUStr
Any aSelectionType ( _xProps->getPropertyValue( rPropName ) );
if (!(aSelectionType.getValueTypeClass() == TypeClass_ENUM && aSelectionType.getValueType() == cppu::UnoType<view::SelectionType>::get()))
if (aSelectionType.getValueTypeClass() != TypeClass_ENUM ||
aSelectionType.getValueType() != cppu::UnoType<view::SelectionType>::get())
return;
::view::SelectionType eSelectionType;