From 31ee230b6efac9a6a60ceb5c2367ae9a5cf98929 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Tue, 6 Oct 2015 10:50:12 +0100 Subject: Related: tdf#94814 some cleanup of static_cast following dynamic_cast to the same type Change-Id: I197e88acbc30f8e8bb9e7f2d54803971df6062af --- basic/source/runtime/runtime.cxx | 55 ++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 33 deletions(-) (limited to 'basic/source/runtime/runtime.cxx') 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( pParent) ) - { - pCurBasic = static_cast(pParent); - } + if (StarBASIC *pBasic = dynamic_cast(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( pObj)) != NULL ) + if (SbxDimArray* pArray = dynamic_cast(pObj)) { p->eForType = FOR_EACH_ARRAY; p->refEnd = reinterpret_cast(pArray); @@ -1186,13 +1181,13 @@ void SbiRuntime::PushForEach() p->pArrayUpperBounds[i] = uBound; } } - else if( (pCollection = dynamic_cast( pObj)) != NULL ) + else if (BasicCollection* pCollection = dynamic_cast(pObj)) { p->eForType = FOR_EACH_COLLECTION; p->refEnd = pCollection; p->nCurCollectionIndex = 0; } - else if( (pUnoObj = dynamic_cast( pObj)) != NULL ) + else if (SbUnoObject* pUnoObj = dynamic_cast(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(pVal) != nullptr ) - pObj = static_cast( pVal ); - else + SbxObject* pObj = dynamic_cast(pVal); + if (!pObj) { - pObj = static_cast( refVal->GetObject() ); - if( pObj && dynamic_cast(pObj) == nullptr ) - pObj = NULL; + pObj = dynamic_cast(refVal->GetObject()); } if( pObj ) { if( !implIsClass( pObj, aClass ) ) { - if ( ( bVBAEnabled || CodeCompleteOptions::IsExtendedTypeDeclaration() ) && dynamic_cast(pObj) != nullptr ) + SbUnoObject* pUnoObj(nullptr); + if (bVBAEnabled || CodeCompleteOptions::IsExtendedTypeDeclaration()) { - SbUnoObject& rUnoObj = dynamic_cast(*pObj); - bOk = checkUnoObjectType(rUnoObj, aClass); + pUnoObj = dynamic_cast(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(pElem) != nullptr ) + if (SbxMethod* pMethod = dynamic_cast(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(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( &pObj) ) + if (SbUnoObject* pUnoObj = dynamic_cast(static_cast(pObj))) { - SbUnoObject* pUnoObj = static_cast(static_cast(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( &pDfltObj) ) + if (SbUnoObject* pSbObj = dynamic_cast(static_cast(pDfltObj))) { - pUnoObj = static_cast(static_cast(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( &pObj) ) + else if (BasicCollection* pCol = dynamic_cast(static_cast(pObj))) { - BasicCollection* pCol = static_cast(static_cast(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( &xObj) ) + SbxDimArray* pArray = dynamic_cast(static_cast(xObj)); + if (pArray) { - SbxBase* pObj = static_cast(xObj); - pArray = static_cast(pObj); - short nDims = pArray->GetDims(); sal_Int32 nTotalSize = 0; -- cgit