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

loplugin:useuniqueptr in svtools,toolkits

Change-Id: Ied7768293e7781772205c9e8f9fb743a584e3125
Reviewed-on: https://gerrit.libreoffice.org/64880
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 28726190
......@@ -205,7 +205,7 @@ void UseUniquePtr::CheckCompoundStmt(const FunctionDecl* functionDecl, const Com
// if (m_pField != nullptr) delete m_pField;
void UseUniquePtr::CheckIfStmt(const FunctionDecl* functionDecl, const IfStmt* ifStmt)
{
auto cond = ifStmt->getCond()->IgnoreImpCasts();
auto cond = ifStmt->getCond()->IgnoreImplicit();
if (auto ifCondMemberExpr = dyn_cast<MemberExpr>(cond))
{
// ignore "if (bMine)"
......@@ -215,9 +215,9 @@ void UseUniquePtr::CheckIfStmt(const FunctionDecl* functionDecl, const IfStmt* i
}
else if (auto binaryOp = dyn_cast<BinaryOperator>(cond))
{
if (!isa<MemberExpr>(binaryOp->getLHS()->IgnoreImpCasts()))
if (!isa<MemberExpr>(binaryOp->getLHS()->IgnoreImplicit()))
return;
if (!isa<CXXNullPtrLiteralExpr>(binaryOp->getRHS()->IgnoreImpCasts()))
if (!isa<CXXNullPtrLiteralExpr>(binaryOp->getRHS()->IgnoreImplicit()))
return;
// good
}
......@@ -254,7 +254,7 @@ void UseUniquePtr::CheckIfStmt(const FunctionDecl* functionDecl, const IfStmt* i
void UseUniquePtr::CheckDeleteExpr(const FunctionDecl* functionDecl, const CXXDeleteExpr* deleteExpr)
{
auto deleteExprArg = deleteExpr->getArgument()->IgnoreParenImpCasts();
auto deleteExprArg = deleteExpr->getArgument()->IgnoreParens()->IgnoreImplicit();
if (const MemberExpr* memberExpr = dyn_cast<MemberExpr>(deleteExprArg))
......@@ -292,7 +292,7 @@ void UseUniquePtr::CheckDeleteExpr(const FunctionDecl* functionDecl, const CXXDe
const ArraySubscriptExpr* arrayExpr = dyn_cast<ArraySubscriptExpr>(deleteExprArg);
if (arrayExpr)
{
auto baseMemberExpr = dyn_cast<MemberExpr>(arrayExpr->getBase()->IgnoreParenImpCasts());
auto baseMemberExpr = dyn_cast<MemberExpr>(arrayExpr->getBase()->IgnoreParens()->IgnoreImplicit());
if (baseMemberExpr)
CheckMemberDeleteExpr(functionDecl, deleteExpr, baseMemberExpr,
"unconditional call to delete on an array member, should be using std::unique_ptr");
......@@ -478,7 +478,8 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C
if (parentName == "ScFunctionList" || parentName == "SwNodes"
|| parentName == "SwUnoCursor" || parentName == "SortedResultSet"
|| parentName == "Atom" || parentName == "RegionBand" || parentName == "WMFWriter"
|| parentName == "Scheduler" || parentName == "OpenGLContext")
|| parentName == "Scheduler" || parentName == "OpenGLContext"
|| parentName == "WizardDialog")
return;
// manual ref counting
if (parentName == "ScBroadcastAreaSlot")
......@@ -518,7 +519,9 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C
if (name == "UCBStorage::OpenStorage_Impl")
return;
// complicated ownership
if (name == "ParseCMAP" || name == "OpenGLSalBitmap::CreateTexture" || name == "X11SalGraphicsImpl::drawAlphaBitmap")
if (name == "ParseCMAP" || name == "OpenGLSalBitmap::CreateTexture" || name == "X11SalGraphicsImpl::drawAlphaBitmap"
|| name == "SvEmbedTransferHelper::GetData" || name == "ORoadmap::dispose"
|| name == "BrowseBox::SetMode" || name == "ExportDialog::GetFilterData")
return;
// complicated delete
if (name == "X11SalObject::CreateObject")
......@@ -573,7 +576,7 @@ void UseUniquePtr::CheckLoopDelete(const FunctionDecl* functionDecl, const CXXDe
// drill down looking for a MemberExpr
for (;;)
{
subExpr = subExpr->IgnoreParenImpCasts();
subExpr = subExpr->IgnoreParens()->IgnoreImplicit();
if ((memberExpr = dyn_cast<MemberExpr>(subExpr)))
{
if (memberExpr->getMemberDecl()->getName() == "first" || memberExpr->getMemberDecl()->getName() == "second")
......@@ -594,7 +597,7 @@ void UseUniquePtr::CheckLoopDelete(const FunctionDecl* functionDecl, const CXXDe
else if (auto cxxOperatorCallExpr = dyn_cast<CXXOperatorCallExpr>(subExpr))
{
// look for deletes of an iterator object where the iterator is over a member field
if (auto declRefExpr = dyn_cast<DeclRefExpr>(cxxOperatorCallExpr->getArg(0)->IgnoreImpCasts()))
if (auto declRefExpr = dyn_cast<DeclRefExpr>(cxxOperatorCallExpr->getArg(0)->IgnoreImplicit()))
{
if (auto iterVarDecl = dyn_cast<VarDecl>(declRefExpr->getDecl()))
{
......@@ -628,7 +631,7 @@ void UseUniquePtr::CheckLoopDelete(const FunctionDecl* functionDecl, const CXXDe
// look for deletes like "delete m_pField[0]"
if (cxxOperatorCallExpr->getOperator() == OO_Subscript)
{
subExpr = cxxOperatorCallExpr->getArg(0)->IgnoreImpCasts();
subExpr = cxxOperatorCallExpr->getArg(0)->IgnoreImplicit();
if ((memberExpr = dyn_cast<MemberExpr>(subExpr)))
break;
if (auto declRefExpr = dyn_cast<DeclRefExpr>(subExpr))
......@@ -805,7 +808,7 @@ void UseUniquePtr::CheckCXXForRangeStmt(const FunctionDecl* functionDecl, const
}
// check for delete of var
if (auto declRefExpr = dyn_cast<DeclRefExpr>(cxxForRangeStmt->getRangeInit()->IgnoreParenImpCasts()))
if (auto declRefExpr = dyn_cast<DeclRefExpr>(cxxForRangeStmt->getRangeInit()->IgnoreParens()->IgnoreImplicit()))
{
auto varDecl = dyn_cast<VarDecl>(declRefExpr->getDecl());
if (!varDecl)
......@@ -1054,7 +1057,7 @@ bool UseUniquePtr::VisitCXXDeleteExpr(const CXXDeleteExpr* deleteExpr)
return true;
if (isInUnoIncludeFile(compat::getBeginLoc(mpCurrentFunctionDecl->getCanonicalDecl())))
return true;
auto declRefExpr = dyn_cast<DeclRefExpr>(deleteExpr->getArgument()->IgnoreParenImpCasts());
auto declRefExpr = dyn_cast<DeclRefExpr>(deleteExpr->getArgument()->IgnoreParenImpCasts()->IgnoreImplicit());
if (!declRefExpr)
return true;
if (auto parmVarDecl = dyn_cast<ParmVarDecl>(declRefExpr->getDecl()))
......
......@@ -660,10 +660,10 @@ void ToolboxController::dispatchCommand( const OUString& sCommandURL, const Sequ
Reference< XDispatch > xDispatch( xDispatchProvider->queryDispatch( aURL, sTarget, 0 ), UNO_QUERY_THROW );
DispatchInfo *pDispatchInfo = new DispatchInfo( xDispatch, aURL, rArgs );
if ( !Application::PostUserEvent( LINK(nullptr, ToolboxController, ExecuteHdl_Impl),
pDispatchInfo ) )
delete pDispatchInfo;
std::unique_ptr<DispatchInfo> pDispatchInfo(new DispatchInfo( xDispatch, aURL, rArgs ));
if ( Application::PostUserEvent( LINK(nullptr, ToolboxController, ExecuteHdl_Impl),
pDispatchInfo.get() ) )
pDispatchInfo.release();
}
catch( Exception& )
......
......@@ -774,7 +774,7 @@ void UnoControlModel::read( const css::uno::Reference< css::io::XObjectInputStre
// No data for the model may be added following the properties
// Used for import of old parts in css::awt::FontDescriptor
css::awt::FontDescriptor* pFD = nullptr;
std::unique_ptr<css::awt::FontDescriptor> pFD;
sal_uInt32 i;
for ( i = 0; i < nProps; i++ )
......@@ -911,7 +911,7 @@ void UnoControlModel::read( const css::uno::Reference< css::io::XObjectInputStre
{
if ( !pFD )
{
pFD = new css::awt::FontDescriptor;
pFD.reset(new css::awt::FontDescriptor);
if ( maData.find( BASEPROPERTY_FONTDESCRIPTOR ) != maData.end() ) // due to defaults...
maData[ BASEPROPERTY_FONTDESCRIPTOR ] >>= *pFD;
}
......@@ -928,7 +928,7 @@ void UnoControlModel::read( const css::uno::Reference< css::io::XObjectInputStre
{
if ( !pFD )
{
pFD = new css::awt::FontDescriptor;
pFD.reset(new css::awt::FontDescriptor);
if ( maData.find(BASEPROPERTY_FONTDESCRIPTOR) != maData.end() ) // due to defaults...
maData[BASEPROPERTY_FONTDESCRIPTOR] >>= *pFD;
}
......@@ -945,7 +945,7 @@ void UnoControlModel::read( const css::uno::Reference< css::io::XObjectInputStre
{
if ( !pFD )
{
pFD = new css::awt::FontDescriptor;
pFD.reset(new css::awt::FontDescriptor);
if ( maData.find(BASEPROPERTY_FONTDESCRIPTOR) != maData.end() ) // due to defaults...
maData[BASEPROPERTY_FONTDESCRIPTOR] >>= *pFD;
}
......@@ -1015,7 +1015,6 @@ void UnoControlModel::read( const css::uno::Reference< css::io::XObjectInputStre
css::uno::Any aValue;
aValue <<= *pFD;
setPropertyValue( GetPropertyName( BASEPROPERTY_FONTDESCRIPTOR ), aValue );
delete pFD;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment