diff options
author | Caolán McNamara <caolanm@redhat.com> | 2015-10-06 10:50:12 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2015-10-06 15:10:51 +0100 |
commit | 31ee230b6efac9a6a60ceb5c2367ae9a5cf98929 (patch) | |
tree | c7ff6f56f5295caa88bda7ceb2036691e3db5c36 /basic | |
parent | 5a242f651c8ae8d53ac67f5059f64629303848ab (diff) |
Related: tdf#94814 some cleanup of static_cast following dynamic_cast
to the same type
Change-Id: I197e88acbc30f8e8bb9e7f2d54803971df6062af
Diffstat (limited to 'basic')
-rw-r--r-- | basic/source/comp/parser.cxx | 3 | ||||
-rw-r--r-- | basic/source/runtime/methods.cxx | 22 | ||||
-rw-r--r-- | basic/source/runtime/runtime.cxx | 55 | ||||
-rw-r--r-- | basic/source/sbx/sbxobj.cxx | 20 |
4 files changed, 42 insertions, 58 deletions
diff --git a/basic/source/comp/parser.cxx b/basic/source/comp/parser.cxx index c3e7a898fceb..29533876dfb2 100644 --- a/basic/source/comp/parser.cxx +++ b/basic/source/comp/parser.cxx @@ -156,10 +156,9 @@ SbiSymDef* SbiParser::CheckRTLForSym(const OUString& rSym, SbxDataType eType) if (!pVar) return nullptr; - if (dynamic_cast<const SbxMethod *>(pVar) != nullptr) + if (SbxMethod* pMethod = dynamic_cast<SbxMethod*>(pVar)) { SbiProcDef* pProc_ = aRtlSyms.AddProc( rSym ); - SbxMethod* pMethod = static_cast<SbxMethod*>(pVar); if (pMethod->IsRuntimeFunction()) { pProc_->SetType( pMethod->GetRuntimeFunctionReturnType() ); diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 9d83fcc2d2f1..6c396ae507db 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -4449,13 +4449,13 @@ RTLFUNC(Load) SbxBase* pObj = static_cast<SbxObject*>(rPar.Get(1)->GetObject()); if ( pObj ) { - if( dynamic_cast<const SbUserFormModule *>(pObj) != nullptr ) + if (SbUserFormModule* pModule = dynamic_cast<SbUserFormModule*>(pObj)) { - static_cast<SbUserFormModule*>(pObj)->Load(); + pModule->Load(); } - else if( dynamic_cast<const SbxObject *>(pObj) != nullptr ) + else if (SbxObject* pSbxObj = dynamic_cast<SbxObject*>(pObj)) { - SbxVariable* pVar = static_cast<SbxObject*>(pObj)->Find( OUString("Load"), SbxCLASS_METHOD ); + SbxVariable* pVar = pSbxObj->Find(OUString("Load"), SbxCLASS_METHOD); if( pVar ) { pVar->GetInteger(); @@ -4480,14 +4480,13 @@ RTLFUNC(Unload) SbxBase* pObj = static_cast<SbxObject*>(rPar.Get(1)->GetObject()); if ( pObj ) { - if( dynamic_cast<const SbUserFormModule *>(pObj) != nullptr ) + if (SbUserFormModule* pFormModule = dynamic_cast<SbUserFormModule*>(pObj)) { - SbUserFormModule* pFormModule = static_cast<SbUserFormModule*>(pObj); pFormModule->Unload(); } - else if( dynamic_cast<const SbxObject *>(pObj) != nullptr ) + else if (SbxObject *pSbxObj = dynamic_cast<SbxObject*>(pObj)) { - SbxVariable* pVar = static_cast<SbxObject*>(pObj)->Find( OUString("Unload"), SbxCLASS_METHOD ); + SbxVariable* pVar = pSbxObj->Find(OUString("Unload"), SbxCLASS_METHOD); if( pVar ) { pVar->GetInteger(); @@ -4534,17 +4533,14 @@ RTLFUNC(SavePicture) } SbxBase* pObj = static_cast<SbxObject*>(rPar.Get(1)->GetObject()); - if( dynamic_cast<const SbStdPicture *>(pObj) != nullptr ) + if (SbStdPicture *pPicture = dynamic_cast<SbStdPicture*>(pObj)) { SvFileStream aOStream( rPar.Get(2)->GetOUString(), StreamMode::WRITE | StreamMode::TRUNC ); - Graphic aGraphic = static_cast<SbStdPicture*>(pObj)->GetGraphic(); + Graphic aGraphic = pPicture->GetGraphic(); WriteGraphic( aOStream, aGraphic ); } } - - - RTLFUNC(MsgBox) { (void)pBasic; diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx index 33ab052aa623..6cff6020fde1 100644 --- a/basic/source/runtime/runtime.cxx +++ b/basic/source/runtime/runtime.cxx @@ -528,10 +528,8 @@ StarBASIC* GetCurrentBasic( StarBASIC* pRTBasic ) if( pActiveModule ) { SbxObject* pParent = pActiveModule->GetParent(); - if( pParent && 0 != dynamic_cast<const StarBASIC*>( pParent) ) - { - pCurBasic = static_cast<StarBASIC*>(pParent); - } + if (StarBASIC *pBasic = dynamic_cast<StarBASIC*>(pParent)) + pCurBasic = pBasic; } return pCurBasic; } @@ -1166,10 +1164,7 @@ void SbiRuntime::PushForEach() } bool bError_ = false; - BasicCollection* pCollection; - SbxDimArray* pArray; - SbUnoObject* pUnoObj; - if( (pArray = dynamic_cast<SbxDimArray*>( pObj)) != NULL ) + if (SbxDimArray* pArray = dynamic_cast<SbxDimArray*>(pObj)) { p->eForType = FOR_EACH_ARRAY; p->refEnd = reinterpret_cast<SbxVariable*>(pArray); @@ -1186,13 +1181,13 @@ void SbiRuntime::PushForEach() p->pArrayUpperBounds[i] = uBound; } } - else if( (pCollection = dynamic_cast<BasicCollection*>( pObj)) != NULL ) + else if (BasicCollection* pCollection = dynamic_cast<BasicCollection*>(pObj)) { p->eForType = FOR_EACH_COLLECTION; p->refEnd = pCollection; p->nCurCollectionIndex = 0; } - else if( (pUnoObj = dynamic_cast<SbUnoObject*>( pObj)) != NULL ) + else if (SbUnoObject* pUnoObj = dynamic_cast<SbUnoObject*>(pObj)) { // XEnumerationAccess? Any aAny = pUnoObj->getUnoAny(); @@ -3239,24 +3234,23 @@ bool SbiRuntime::checkClass_Impl( const SbxVariableRef& refVal, } if( t == SbxOBJECT ) { - SbxObject* pObj; - if( dynamic_cast<const SbxObject *>(pVal) != nullptr ) - pObj = static_cast<SbxObject*>( pVal ); - else + SbxObject* pObj = dynamic_cast<SbxObject*>(pVal); + if (!pObj) { - pObj = static_cast<SbxObject*>( refVal->GetObject() ); - if( pObj && dynamic_cast<const SbxObject *>(pObj) == nullptr ) - pObj = NULL; + pObj = dynamic_cast<SbxObject*>(refVal->GetObject()); } if( pObj ) { if( !implIsClass( pObj, aClass ) ) { - if ( ( bVBAEnabled || CodeCompleteOptions::IsExtendedTypeDeclaration() ) && dynamic_cast<const SbUnoObject *>(pObj) != nullptr ) + SbUnoObject* pUnoObj(nullptr); + if (bVBAEnabled || CodeCompleteOptions::IsExtendedTypeDeclaration()) { - SbUnoObject& rUnoObj = dynamic_cast<SbUnoObject&>(*pObj); - bOk = checkUnoObjectType(rUnoObj, aClass); + pUnoObj = dynamic_cast<SbUnoObject*>(pObj); } + + if (pUnoObj) + bOk = checkUnoObjectType(*pUnoObj, aClass); else bOk = false; if ( !bOk ) @@ -3540,7 +3534,7 @@ SbxVariable* SbiRuntime::FindElement( SbxObject* pObj, sal_uInt32 nOp1, sal_uInt SetupArgs( pElem, nOp1 ); } // because a particular call-type is requested - if( dynamic_cast<const SbxMethod *>(pElem) != nullptr ) + if (SbxMethod* pMethod = dynamic_cast<SbxMethod*>(pElem)) { // shall the type be converted? SbxDataType t2 = pElem->GetType(); @@ -3567,7 +3561,7 @@ SbxVariable* SbiRuntime::FindElement( SbxObject* pObj, sal_uInt32 nOp1, sal_uInt // has to know the difference between Left$() and Left() // because the methods' parameters are cut away in PopVar() - SbxVariable* pNew = new SbxMethod( *(static_cast<SbxMethod*>(pElem)) ); + SbxVariable* pNew = new SbxMethod(*pMethod); //OLD: SbxVariable* pNew = new SbxVariable( *pElem ); pElem->SetParameters(0); @@ -3853,9 +3847,8 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem ) SbxBaseRef pObj = pElem->GetObject(); if( pObj ) { - if( 0 != dynamic_cast<const SbUnoObject*>( &pObj) ) + if (SbUnoObject* pUnoObj = dynamic_cast<SbUnoObject*>(static_cast<SbxBase*>(pObj))) { - SbUnoObject* pUnoObj = static_cast<SbUnoObject*>(static_cast<SbxBase*>(pObj)); Any aAny = pUnoObj->getUnoAny(); if( aAny.getValueType().getTypeClass() == TypeClass_INTERFACE ) @@ -3924,9 +3917,9 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem ) SbxBaseRef pDfltObj = pDflt->GetObject(); if( pDfltObj ) { - if( 0 != dynamic_cast<const SbUnoObject*>( &pDfltObj) ) + if (SbUnoObject* pSbObj = dynamic_cast<SbUnoObject*>(static_cast<SbxBase*>(pDfltObj))) { - pUnoObj = static_cast<SbUnoObject*>(static_cast<SbxBase*>(pDfltObj)); + pUnoObj = pSbObj; Any aUnoAny = pUnoObj->getUnoAny(); if( aUnoAny.getValueType().getTypeClass() == TypeClass_INTERFACE ) @@ -3964,9 +3957,8 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem ) // #42940, set parameter 0 to NULL so that var doesn't contain itself pPar->Put( NULL, 0 ); } - else if( 0 != dynamic_cast<const BasicCollection*>( &pObj) ) + else if (BasicCollection* pCol = dynamic_cast<BasicCollection*>(static_cast<SbxBase*>(pObj))) { - BasicCollection* pCol = static_cast<BasicCollection*>(static_cast<SbxBase*>(pObj)); pElem = new SbxVariable( SbxVARIANT ); pPar->Put( pElem, 0 ); pCol->CollItem( pPar ); @@ -4382,12 +4374,9 @@ void SbiRuntime::StepDCREATE_IMPL( sal_uInt32 nOp1, sal_uInt32 nOp2 ) return; } - SbxDimArray* pArray = 0; - if( 0 != dynamic_cast<const SbxDimArray*>( &xObj) ) + SbxDimArray* pArray = dynamic_cast<SbxDimArray*>(static_cast<SbxBase*>(xObj)); + if (pArray) { - SbxBase* pObj = static_cast<SbxBase*>(xObj); - pArray = static_cast<SbxDimArray*>(pObj); - short nDims = pArray->GetDims(); sal_Int32 nTotalSize = 0; diff --git a/basic/source/sbx/sbxobj.cxx b/basic/source/sbx/sbxobj.cxx index 46f34f13d2e6..f6babf55b951 100644 --- a/basic/source/sbx/sbxobj.cxx +++ b/basic/source/sbx/sbxobj.cxx @@ -463,9 +463,9 @@ void SbxObject::Insert( SbxVariable* pVar ) static const char* pCls[] = { "DontCare","Array","Value","Variable","Method","Property","Object" }; OUString aVarName( pVar->GetName() ); - if ( aVarName.isEmpty() && 0 != dynamic_cast<const SbxObject*>( pVar) ) + if (const SbxObject *pSbxObj = aVarName.isEmpty() ? dynamic_cast<const SbxObject*>(pVar) : nullptr) { - aVarName = dynamic_cast<SbxObject*>( pVar)->GetClassName( ); + aVarName = pSbxObj->GetClassName(); } SAL_INFO( "basic.sbx", @@ -507,9 +507,9 @@ void SbxObject::QuickInsert( SbxVariable* pVar ) static const char* pCls[] = { "DontCare","Array","Value","Variable","Method","Property","Object" }; OUString aVarName( pVar->GetName() ); - if ( aVarName.isEmpty() && 0 != dynamic_cast<const SbxObject*>( pVar) ) + if (const SbxObject *pSbxObj = aVarName.isEmpty() ? dynamic_cast<const SbxObject*>(pVar) : nullptr) { - aVarName = dynamic_cast<SbxObject*>( pVar)->GetClassName( ); + aVarName = pSbxObj->GetClassName(); } SAL_INFO( "basic.sbx", @@ -535,9 +535,9 @@ void SbxObject::Remove( SbxVariable* pVar ) { #ifdef DBG_UTIL OUString aVarName( pVar->GetName() ); - if ( aVarName.isEmpty() && 0 != dynamic_cast<const SbxObject*>( pVar) ) + if (const SbxObject *pSbxObj = aVarName.isEmpty() ? dynamic_cast<const SbxObject*>(pVar) : nullptr) { - aVarName = dynamic_cast<SbxObject*>( pVar)->GetClassName( ); + aVarName = pSbxObj->GetClassName(); } SAL_INFO( "basic.sbx", @@ -855,13 +855,13 @@ void SbxObject::Dump( SvStream& rStrm, bool bFill ) if ( pVar ) { rStrm.WriteCharPtr( aIndentNameStr.getStr() ).WriteCharPtr( " - Sub" ); - if ( 0 != dynamic_cast<const SbxObject*>( pVar) ) + if (SbxObject *pSbxObj = dynamic_cast<SbxObject*>(pVar)) { - static_cast<SbxObject*>(pVar)->Dump( rStrm, bFill ); + pSbxObj->Dump(rStrm, bFill); } - else if ( 0 != dynamic_cast<const SbxVariable*>( pVar) ) + else if (SbxVariable *pSbxVar = dynamic_cast<SbxVariable*>(pVar)) { - static_cast<SbxVariable*>(pVar)->Dump( rStrm, bFill ); + pSbxVar->Dump(rStrm, bFill); } } } |