basic/source/basmgr/basmgr.cxx | 144 ++--- basic/source/basmgr/vbahelper.cxx | 26 - basic/source/classes/image.cxx | 48 - basic/source/classes/sbunoobj.cxx | 958 +++++++++++++++++++------------------- basic/source/classes/sbxmod.cxx | 542 ++++++++++----------- basic/source/comp/buffer.cxx | 42 - basic/source/comp/dim.cxx | 198 +++---- basic/source/comp/exprgen.cxx | 76 +-- basic/source/comp/exprnode.cxx | 336 ++++++------- basic/source/comp/parser.cxx | 70 +- basic/source/comp/symtbl.cxx | 80 +-- basic/source/runtime/basrdll.cxx | 30 - basic/source/runtime/iosys.cxx | 124 ++-- basic/source/runtime/methods.cxx | 82 +-- basic/source/runtime/runtime.cxx | 181 +++---- basic/source/runtime/stdobj.cxx | 46 - basic/source/runtime/stdobj1.cxx | 126 ++-- basic/source/sbx/sbxobj.cxx | 236 ++++----- basic/source/sbx/sbxvar.cxx | 56 +- basic/source/uno/namecont.cxx | 763 +++++++++++++++--------------- basic/source/uno/scriptcont.cxx | 54 +- 21 files changed, 2110 insertions(+), 2108 deletions(-)
New commits: commit 8b0a69498b025e13d9772689e9e4fa3d6b05e609 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Sat Apr 18 14:35:43 2020 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sun Apr 19 08:30:49 2020 +0200 loplugin:flatten in basic Change-Id: Icb8e3cda312b50c9a9f12f96bec1c746f41c8979 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92483 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx index 764e5d70150e..753aaf04b201 100644 --- a/basic/source/basmgr/basmgr.cxx +++ b/basic/source/basmgr/basmgr.cxx @@ -179,27 +179,27 @@ void BasMgrContainerListenerImpl::addLibraryModulesImpl( BasicManager const * pM StarBASIC* pLib = pMgr->GetLib( aLibName ); DBG_ASSERT( pLib, "BasMgrContainerListenerImpl::addLibraryModulesImpl: Unknown lib!"); - if( pLib ) + if( !pLib ) + return; + + const OUString* pNames = aModuleNames.getConstArray(); + for( sal_Int32 j = 0 ; j < nModuleCount ; j++ ) { - const OUString* pNames = aModuleNames.getConstArray(); - for( sal_Int32 j = 0 ; j < nModuleCount ; j++ ) + OUString aModuleName = pNames[ j ]; + uno::Any aElement = xLibNameAccess->getByName( aModuleName ); + OUString aMod; + aElement >>= aMod; + uno::Reference< vba::XVBAModuleInfo > xVBAModuleInfo( xLibNameAccess, uno::UNO_QUERY ); + if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo( aModuleName ) ) { - OUString aModuleName = pNames[ j ]; - uno::Any aElement = xLibNameAccess->getByName( aModuleName ); - OUString aMod; - aElement >>= aMod; - uno::Reference< vba::XVBAModuleInfo > xVBAModuleInfo( xLibNameAccess, uno::UNO_QUERY ); - if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo( aModuleName ) ) - { - ModuleInfo aInfo = xVBAModuleInfo->getModuleInfo( aModuleName ); - pLib->MakeModule( aModuleName, aInfo, aMod ); - } - else - pLib->MakeModule( aModuleName, aMod ); + ModuleInfo aInfo = xVBAModuleInfo->getModuleInfo( aModuleName ); + pLib->MakeModule( aModuleName, aInfo, aMod ); } - - pLib->SetModified( false ); + else + pLib->MakeModule( aModuleName, aMod ); } + + pLib->SetModified( false ); } @@ -266,19 +266,19 @@ void SAL_CALL BasMgrContainerListenerImpl::elementReplaced( const container::Con DBG_ASSERT( !maLibName.isEmpty(), "library container fired elementReplaced()"); StarBASIC* pLib = mpMgr->GetLib( maLibName ); - if( pLib ) - { - SbModule* pMod = pLib->FindModule( aName ); - OUString aMod; - Event.Element >>= aMod; + if( !pLib ) + return; - if( pMod ) - pMod->SetSource32( aMod ); - else - pLib->MakeModule( aName, aMod ); + SbModule* pMod = pLib->FindModule( aName ); + OUString aMod; + Event.Element >>= aMod; - pLib->SetModified( false ); - } + if( pMod ) + pMod->SetSource32( aMod ); + else + pLib->MakeModule( aName, aMod ); + + pLib->SetModified( false ); } @@ -770,51 +770,51 @@ void BasicManager::LoadOldBasicManager( SotStorage& rStorage ) xManagerStream->SetBufferSize( 0 ); xManagerStream.clear(); // Close stream - if ( !aLibs.isEmpty() ) - { - INetURLObject aCurStorage( aStorName, INetProtocol::File ); - sal_Int32 nLibPos {0}; - do { - const OUString aLibInfo(aLibs.getToken(0, LIB_SEP, nLibPos)); - sal_Int32 nInfoPos {0}; - const OUString aLibName( aLibInfo.getToken( 0, LIBINFO_SEP, nInfoPos ) ); - DBG_ASSERT( nInfoPos >= 0, "Invalid Lib-Info!" ); - const OUString aLibAbsStorageName( aLibInfo.getToken( 0, LIBINFO_SEP, nInfoPos ) ); - // TODO: fail also here if there are no more tokens? - const OUString aLibRelStorageName( aLibInfo.getToken( 0, LIBINFO_SEP, nInfoPos ) ); - DBG_ASSERT( nInfoPos < 0, "Invalid Lib-Info!" ); - INetURLObject aLibAbsStorage( aLibAbsStorageName, INetProtocol::File ); - - INetURLObject aLibRelStorage( aStorName ); - aLibRelStorage.removeSegment(); - bool bWasAbsolute = false; - aLibRelStorage = aLibRelStorage.smartRel2Abs( aLibRelStorageName, bWasAbsolute); - DBG_ASSERT(!bWasAbsolute, "RelStorageName was absolute!" ); + if ( aLibs.isEmpty() ) + return; - tools::SvRef<SotStorage> xStorageRef; - if ( aLibAbsStorage == aCurStorage || aLibRelStorageName == szImbedded ) - { - xStorageRef = &rStorage; - } - else - { - xStorageRef = new SotStorage( false, aLibAbsStorage.GetMainURL - ( INetURLObject::DecodeMechanism::NONE ), eStorageReadMode ); - if ( xStorageRef->GetError() != ERRCODE_NONE ) - xStorageRef = new SotStorage( false, aLibRelStorage. - GetMainURL( INetURLObject::DecodeMechanism::NONE ), eStorageReadMode ); - } - if ( xStorageRef.is() ) - { - AddLib( *xStorageRef, aLibName, false ); - } - else - { - StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD, aStorName, DialogMask::ButtonsOk ); - aErrors.emplace_back(*pErrInf, BasicErrorReason::STORAGENOTFOUND); - } - } while (nLibPos>=0); - } + INetURLObject aCurStorage( aStorName, INetProtocol::File ); + sal_Int32 nLibPos {0}; + do { + const OUString aLibInfo(aLibs.getToken(0, LIB_SEP, nLibPos)); + sal_Int32 nInfoPos {0}; + const OUString aLibName( aLibInfo.getToken( 0, LIBINFO_SEP, nInfoPos ) ); + DBG_ASSERT( nInfoPos >= 0, "Invalid Lib-Info!" ); + const OUString aLibAbsStorageName( aLibInfo.getToken( 0, LIBINFO_SEP, nInfoPos ) ); + // TODO: fail also here if there are no more tokens? + const OUString aLibRelStorageName( aLibInfo.getToken( 0, LIBINFO_SEP, nInfoPos ) ); + DBG_ASSERT( nInfoPos < 0, "Invalid Lib-Info!" ); + INetURLObject aLibAbsStorage( aLibAbsStorageName, INetProtocol::File ); + + INetURLObject aLibRelStorage( aStorName ); + aLibRelStorage.removeSegment(); + bool bWasAbsolute = false; + aLibRelStorage = aLibRelStorage.smartRel2Abs( aLibRelStorageName, bWasAbsolute); + DBG_ASSERT(!bWasAbsolute, "RelStorageName was absolute!" ); + + tools::SvRef<SotStorage> xStorageRef; + if ( aLibAbsStorage == aCurStorage || aLibRelStorageName == szImbedded ) + { + xStorageRef = &rStorage; + } + else + { + xStorageRef = new SotStorage( false, aLibAbsStorage.GetMainURL + ( INetURLObject::DecodeMechanism::NONE ), eStorageReadMode ); + if ( xStorageRef->GetError() != ERRCODE_NONE ) + xStorageRef = new SotStorage( false, aLibRelStorage. + GetMainURL( INetURLObject::DecodeMechanism::NONE ), eStorageReadMode ); + } + if ( xStorageRef.is() ) + { + AddLib( *xStorageRef, aLibName, false ); + } + else + { + StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD, aStorName, DialogMask::ButtonsOk ); + aErrors.emplace_back(*pErrInf, BasicErrorReason::STORAGENOTFOUND); + } + } while (nLibPos>=0); } BasicManager::~BasicManager() diff --git a/basic/source/basmgr/vbahelper.cxx b/basic/source/basmgr/vbahelper.cxx index 231452612051..83165374a8f1 100644 --- a/basic/source/basmgr/vbahelper.cxx +++ b/basic/source/basmgr/vbahelper.cxx @@ -164,20 +164,20 @@ void enableContainerWindowsOfAllDocuments( const uno::Reference< frame::XModel > void registerCurrentDirectory( const uno::Reference< frame::XModel >& rxModel, const OUString& rPath ) { - if( !rPath.isEmpty() ) + if( rPath.isEmpty() ) + return; + + CurrDirPool& rPool = StaticCurrDirPool::get(); + ::osl::MutexGuard aGuard( rPool.maMutex ); + try + { + uno::Reference< frame::XModuleManager2 > xModuleManager( lclCreateModuleManager() ); + OUString aIdentifier = xModuleManager->identify( rxModel ); + if( !aIdentifier.isEmpty() ) + rPool.maCurrDirs[ aIdentifier ] = rPath; + } + catch(const uno::Exception& ) { - CurrDirPool& rPool = StaticCurrDirPool::get(); - ::osl::MutexGuard aGuard( rPool.maMutex ); - try - { - uno::Reference< frame::XModuleManager2 > xModuleManager( lclCreateModuleManager() ); - OUString aIdentifier = xModuleManager->identify( rxModel ); - if( !aIdentifier.isEmpty() ) - rPool.maCurrDirs[ aIdentifier ] = rPath; - } - catch(const uno::Exception& ) - { - } } } diff --git a/basic/source/classes/image.cxx b/basic/source/classes/image.cxx index a7f6c75a4bdc..e6e277647459 100644 --- a/basic/source/classes/image.cxx +++ b/basic/source/classes/image.cxx @@ -589,33 +589,33 @@ void SbiImage::AddString( const OUString& r ) { bError = true; } + if( bError ) + return; + + sal_Int32 len = r.getLength() + 1; + sal_uInt32 needed = nStringOff + len; + if( needed > 0xFFFFFF00 ) + { + bError = true; // out of mem! + } + else if( needed > nStringSize ) + { + sal_uInt32 nNewLen = needed + 1024; + nNewLen &= 0xFFFFFC00; // trim to 1K border + std::unique_ptr<sal_Unicode[]> p(new sal_Unicode[nNewLen]); + memcpy( p.get(), pStrings.get(), nStringSize * sizeof( sal_Unicode ) ); + pStrings = std::move(p); + nStringSize = sal::static_int_cast< sal_uInt16 >(nNewLen); + } if( !bError ) { - sal_Int32 len = r.getLength() + 1; - sal_uInt32 needed = nStringOff + len; - if( needed > 0xFFFFFF00 ) + mvStringOffsets[ nStringIdx++ ] = nStringOff; + memcpy( pStrings.get() + nStringOff, r.getStr(), len * sizeof( sal_Unicode ) ); + nStringOff = nStringOff + len; + // Last String? The update the size of the buffer + if( nStringIdx >= short(mvStringOffsets.size()) ) { - bError = true; // out of mem! - } - else if( needed > nStringSize ) - { - sal_uInt32 nNewLen = needed + 1024; - nNewLen &= 0xFFFFFC00; // trim to 1K border - std::unique_ptr<sal_Unicode[]> p(new sal_Unicode[nNewLen]); - memcpy( p.get(), pStrings.get(), nStringSize * sizeof( sal_Unicode ) ); - pStrings = std::move(p); - nStringSize = sal::static_int_cast< sal_uInt16 >(nNewLen); - } - if( !bError ) - { - mvStringOffsets[ nStringIdx++ ] = nStringOff; - memcpy( pStrings.get() + nStringOff, r.getStr(), len * sizeof( sal_Unicode ) ); - nStringOff = nStringOff + len; - // Last String? The update the size of the buffer - if( nStringIdx >= short(mvStringOffsets.size()) ) - { - nStringSize = nStringOff; - } + nStringSize = nStringOff; } } } diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx index deef49e6af1c..1da0bf1b0314 100644 --- a/basic/source/classes/sbunoobj.cxx +++ b/basic/source/classes/sbunoobj.cxx @@ -1999,299 +1999,299 @@ void SbUnoObject::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) doIntrospection(); const SbxHint* pHint = dynamic_cast<const SbxHint*>(&rHint); - if( pHint ) + if( !pHint ) + return; + + SbxVariable* pVar = pHint->GetVar(); + SbxArray* pParams = pVar->GetParameters(); + SbUnoProperty* pProp = dynamic_cast<SbUnoProperty*>( pVar ); + SbUnoMethod* pMeth = dynamic_cast<SbUnoMethod*>( pVar ); + if( pProp ) { - SbxVariable* pVar = pHint->GetVar(); - SbxArray* pParams = pVar->GetParameters(); - SbUnoProperty* pProp = dynamic_cast<SbUnoProperty*>( pVar ); - SbUnoMethod* pMeth = dynamic_cast<SbUnoMethod*>( pVar ); - if( pProp ) + bool bInvocation = pProp->isInvocationBased(); + if( pHint->GetId() == SfxHintId::BasicDataWanted ) { - bool bInvocation = pProp->isInvocationBased(); - if( pHint->GetId() == SfxHintId::BasicDataWanted ) + // Test-Properties + sal_Int32 nId = pProp->nId; + if( nId < 0 ) { - // Test-Properties - sal_Int32 nId = pProp->nId; - if( nId < 0 ) + // Id == -1: Display implemented interfaces according the ClassProvider + if( nId == -1 ) // Property ID_DBG_SUPPORTEDINTERFACES" { - // Id == -1: Display implemented interfaces according the ClassProvider - if( nId == -1 ) // Property ID_DBG_SUPPORTEDINTERFACES" - { - OUString aRetStr = Impl_GetSupportedInterfaces(*this); - pVar->PutString( aRetStr ); - } - // Id == -2: output properties - else if( nId == -2 ) // Property ID_DBG_PROPERTIES - { - // now all properties must be created - implCreateAll(); - OUString aRetStr = Impl_DumpProperties(*this); - pVar->PutString( aRetStr ); - } - // Id == -3: output the methods - else if( nId == -3 ) // Property ID_DBG_METHODS - { - // now all properties must be created - implCreateAll(); - OUString aRetStr = Impl_DumpMethods(*this); - pVar->PutString( aRetStr ); - } - return; + OUString aRetStr = Impl_GetSupportedInterfaces(*this); + pVar->PutString( aRetStr ); + } + // Id == -2: output properties + else if( nId == -2 ) // Property ID_DBG_PROPERTIES + { + // now all properties must be created + implCreateAll(); + OUString aRetStr = Impl_DumpProperties(*this); + pVar->PutString( aRetStr ); + } + // Id == -3: output the methods + else if( nId == -3 ) // Property ID_DBG_METHODS + { + // now all properties must be created + implCreateAll(); + OUString aRetStr = Impl_DumpMethods(*this); + pVar->PutString( aRetStr ); } + return; + } - if( !bInvocation && mxUnoAccess.is() ) + if( !bInvocation && mxUnoAccess.is() ) + { + try { - try + if ( maStructInfo.get() ) { - if ( maStructInfo.get() ) + StructRefInfo aMember = maStructInfo->getStructMember( pProp->GetName() ); + if ( aMember.isEmpty() ) + { + StarBASIC::Error( ERRCODE_BASIC_PROPERTY_NOT_FOUND ); + } + else { - StructRefInfo aMember = maStructInfo->getStructMember( pProp->GetName() ); - if ( aMember.isEmpty() ) + if ( pProp->isUnoStruct() ) { - StarBASIC::Error( ERRCODE_BASIC_PROPERTY_NOT_FOUND ); + SbUnoStructRefObject* pSbUnoObject = new SbUnoStructRefObject( pProp->GetName(), aMember ); + SbxObjectRef xWrapper = static_cast<SbxObject*>(pSbUnoObject); + pVar->PutObject( xWrapper.get() ); } else { - if ( pProp->isUnoStruct() ) - { - SbUnoStructRefObject* pSbUnoObject = new SbUnoStructRefObject( pProp->GetName(), aMember ); - SbxObjectRef xWrapper = static_cast<SbxObject*>(pSbUnoObject); - pVar->PutObject( xWrapper.get() ); - } - else - { - Any aRetAny = aMember.getValue(); - // take over the value from Uno to Sbx - unoToSbxValue( pVar, aRetAny ); - } - return; + Any aRetAny = aMember.getValue(); + // take over the value from Uno to Sbx + unoToSbxValue( pVar, aRetAny ); } + return; } - // get the value - Reference< XPropertySet > xPropSet( mxUnoAccess->queryAdapter( cppu::UnoType<XPropertySet>::get()), UNO_QUERY ); - Any aRetAny = xPropSet->getPropertyValue( pProp->GetName() ); - // The use of getPropertyValue (instead of using the index) is - // suboptimal, but the refactoring to XInvocation is already pending - // Otherwise it is possible to use FastPropertySet - - // take over the value from Uno to Sbx - unoToSbxValue( pVar, aRetAny ); - } - catch( const Exception& ) - { - implHandleAnyException( ::cppu::getCaughtException() ); } + // get the value + Reference< XPropertySet > xPropSet( mxUnoAccess->queryAdapter( cppu::UnoType<XPropertySet>::get()), UNO_QUERY ); + Any aRetAny = xPropSet->getPropertyValue( pProp->GetName() ); + // The use of getPropertyValue (instead of using the index) is + // suboptimal, but the refactoring to XInvocation is already pending + // Otherwise it is possible to use FastPropertySet + + // take over the value from Uno to Sbx + unoToSbxValue( pVar, aRetAny ); } - else if( bInvocation && mxInvocation.is() ) + catch( const Exception& ) { - try - { - sal_uInt32 nParamCount = pParams ? (pParams->Count32() - 1) : 0; - bool bCanBeConsideredAMethod = mxInvocation->hasMethod( pProp->GetName() ); - Any aRetAny; - if ( bCanBeConsideredAMethod && nParamCount ) - { - // Automation properties have methods, so... we need to invoke this through - // XInvocation - Sequence<Any> args; - processAutomationParams( pParams, args, nParamCount ); - aRetAny = invokeAutomationMethod( pProp->GetName(), args, pParams, nParamCount, mxInvocation, INVOKETYPE::GetProp ); - } - else - aRetAny = mxInvocation->getValue( pProp->GetName() ); - // take over the value from Uno to Sbx - unoToSbxValue( pVar, aRetAny ); - if( pParams && bCanBeConsideredAMethod ) - pVar->SetParameters( nullptr ); - - } - catch( const Exception& ) - { - implHandleAnyException( ::cppu::getCaughtException() ); - } + implHandleAnyException( ::cppu::getCaughtException() ); } } - else if( pHint->GetId() == SfxHintId::BasicDataChanged ) + else if( bInvocation && mxInvocation.is() ) { - if( !bInvocation && mxUnoAccess.is() ) + try { - if( pProp->aUnoProp.Attributes & PropertyAttribute::READONLY ) + sal_uInt32 nParamCount = pParams ? (pParams->Count32() - 1) : 0; + bool bCanBeConsideredAMethod = mxInvocation->hasMethod( pProp->GetName() ); + Any aRetAny; + if ( bCanBeConsideredAMethod && nParamCount ) { - StarBASIC::Error( ERRCODE_BASIC_PROP_READONLY ); - return; + // Automation properties have methods, so... we need to invoke this through + // XInvocation + Sequence<Any> args; + processAutomationParams( pParams, args, nParamCount ); + aRetAny = invokeAutomationMethod( pProp->GetName(), args, pParams, nParamCount, mxInvocation, INVOKETYPE::GetProp ); } - if ( maStructInfo.get() ) - { - StructRefInfo aMember = maStructInfo->getStructMember( pProp->GetName() ); - if ( aMember.isEmpty() ) - { - StarBASIC::Error( ERRCODE_BASIC_PROPERTY_NOT_FOUND ); - } - else - { - Any aAnyValue = sbxToUnoValue( pVar, pProp->aUnoProp.Type, &pProp->aUnoProp ); - aMember.setValue( aAnyValue ); - } - return; - } + else + aRetAny = mxInvocation->getValue( pProp->GetName() ); // take over the value from Uno to Sbx - Any aAnyValue = sbxToUnoValue( pVar, pProp->aUnoProp.Type, &pProp->aUnoProp ); - try - { - // set the value - Reference< XPropertySet > xPropSet( mxUnoAccess->queryAdapter( cppu::UnoType<XPropertySet>::get()), UNO_QUERY ); - xPropSet->setPropertyValue( pProp->GetName(), aAnyValue ); - // The use of getPropertyValue (instead of using the index) is - // suboptimal, but the refactoring to XInvocation is already pending - // Otherwise it is possible to use FastPropertySet - } - catch( const Exception& ) - { - implHandleAnyException( ::cppu::getCaughtException() ); - } + unoToSbxValue( pVar, aRetAny ); + if( pParams && bCanBeConsideredAMethod ) + pVar->SetParameters( nullptr ); + } - else if( bInvocation && mxInvocation.is() ) + catch( const Exception& ) { - // take over the value from Uno to Sbx - Any aAnyValue = sbxToUnoValueImpl( pVar ); - try + implHandleAnyException( ::cppu::getCaughtException() ); + } + } + } + else if( pHint->GetId() == SfxHintId::BasicDataChanged ) + { + if( !bInvocation && mxUnoAccess.is() ) + { + if( pProp->aUnoProp.Attributes & PropertyAttribute::READONLY ) + { + StarBASIC::Error( ERRCODE_BASIC_PROP_READONLY ); + return; + } + if ( maStructInfo.get() ) + { + StructRefInfo aMember = maStructInfo->getStructMember( pProp->GetName() ); + if ( aMember.isEmpty() ) { - // set the value - mxInvocation->setValue( pProp->GetName(), aAnyValue ); + StarBASIC::Error( ERRCODE_BASIC_PROPERTY_NOT_FOUND ); } - catch( const Exception& ) + else { - implHandleAnyException( ::cppu::getCaughtException() ); + Any aAnyValue = sbxToUnoValue( pVar, pProp->aUnoProp.Type, &pProp->aUnoProp ); + aMember.setValue( aAnyValue ); } + return; + } + // take over the value from Uno to Sbx + Any aAnyValue = sbxToUnoValue( pVar, pProp->aUnoProp.Type, &pProp->aUnoProp ); + try + { + // set the value + Reference< XPropertySet > xPropSet( mxUnoAccess->queryAdapter( cppu::UnoType<XPropertySet>::get()), UNO_QUERY ); + xPropSet->setPropertyValue( pProp->GetName(), aAnyValue ); + // The use of getPropertyValue (instead of using the index) is + // suboptimal, but the refactoring to XInvocation is already pending + // Otherwise it is possible to use FastPropertySet + } + catch( const Exception& ) + { + implHandleAnyException( ::cppu::getCaughtException() ); + } + } + else if( bInvocation && mxInvocation.is() ) + { + // take over the value from Uno to Sbx + Any aAnyValue = sbxToUnoValueImpl( pVar ); + try + { + // set the value + mxInvocation->setValue( pProp->GetName(), aAnyValue ); + } + catch( const Exception& ) + { + implHandleAnyException( ::cppu::getCaughtException() ); } } } - else if( pMeth ) + } + else if( pMeth ) + { + bool bInvocation = pMeth->isInvocationBased(); + if( pHint->GetId() == SfxHintId::BasicDataWanted ) { - bool bInvocation = pMeth->isInvocationBased(); - if( pHint->GetId() == SfxHintId::BasicDataWanted ) - { - // number of Parameter -1 because of Param0 == this - sal_uInt32 nParamCount = pParams ? (pParams->Count32() - 1) : 0; - Sequence<Any> args; - bool bOutParams = false; + // number of Parameter -1 because of Param0 == this + sal_uInt32 nParamCount = pParams ? (pParams->Count32() - 1) : 0; + Sequence<Any> args; + bool bOutParams = false; - if( !bInvocation && mxUnoAccess.is() ) + if( !bInvocation && mxUnoAccess.is() ) + { + // get info + const Sequence<ParamInfo>& rInfoSeq = pMeth->getParamInfos(); + const ParamInfo* pParamInfos = rInfoSeq.getConstArray(); + sal_uInt32 nUnoParamCount = rInfoSeq.getLength(); + sal_uInt32 nAllocParamCount = nParamCount; + + // ignore surplus parameter; alternative: throw an error + if( nParamCount > nUnoParamCount ) { - // get info - const Sequence<ParamInfo>& rInfoSeq = pMeth->getParamInfos(); - const ParamInfo* pParamInfos = rInfoSeq.getConstArray(); - sal_uInt32 nUnoParamCount = rInfoSeq.getLength(); - sal_uInt32 nAllocParamCount = nParamCount; - - // ignore surplus parameter; alternative: throw an error - if( nParamCount > nUnoParamCount ) - { - nParamCount = nUnoParamCount; - nAllocParamCount = nParamCount; - } - else if( nParamCount < nUnoParamCount ) + nParamCount = nUnoParamCount; + nAllocParamCount = nParamCount; + } + else if( nParamCount < nUnoParamCount ) + { + SbiInstance* pInst = GetSbData()->pInst; + if( pInst && pInst->IsCompatibility() ) { - SbiInstance* pInst = GetSbData()->pInst; - if( pInst && pInst->IsCompatibility() ) + // Check types + bool bError = false; + for( sal_uInt32 i = nParamCount ; i < nUnoParamCount ; i++ ) { - // Check types - bool bError = false; - for( sal_uInt32 i = nParamCount ; i < nUnoParamCount ; i++ ) + const ParamInfo& rInfo = pParamInfos[i]; + const Reference< XIdlClass >& rxClass = rInfo.aType; + if( rxClass->getTypeClass() != TypeClass_ANY ) { - const ParamInfo& rInfo = pParamInfos[i]; - const Reference< XIdlClass >& rxClass = rInfo.aType; - if( rxClass->getTypeClass() != TypeClass_ANY ) - { - bError = true; - StarBASIC::Error( ERRCODE_BASIC_NOT_OPTIONAL ); - } + bError = true; + StarBASIC::Error( ERRCODE_BASIC_NOT_OPTIONAL ); } - if( !bError ) - nAllocParamCount = nUnoParamCount; } + if( !bError ) + nAllocParamCount = nUnoParamCount; } + } - if( nAllocParamCount > 0 ) + if( nAllocParamCount > 0 ) + { + args.realloc( nAllocParamCount ); + Any* pAnyArgs = args.getArray(); + for( sal_uInt32 i = 0 ; i < nParamCount ; i++ ) { - args.realloc( nAllocParamCount ); - Any* pAnyArgs = args.getArray(); - for( sal_uInt32 i = 0 ; i < nParamCount ; i++ ) - { - const ParamInfo& rInfo = pParamInfos[i]; - const Reference< XIdlClass >& rxClass = rInfo.aType; + const ParamInfo& rInfo = pParamInfos[i]; + const Reference< XIdlClass >& rxClass = rInfo.aType; - css::uno::Type aType( rxClass->getTypeClass(), rxClass->getName() ); + css::uno::Type aType( rxClass->getTypeClass(), rxClass->getName() ); - // ATTENTION: Don't forget for Sbx-Parameter the offset! - pAnyArgs[i] = sbxToUnoValue( pParams->Get32(i + 1), aType ); + // ATTENTION: Don't forget for Sbx-Parameter the offset! + pAnyArgs[i] = sbxToUnoValue( pParams->Get32(i + 1), aType ); - // If it is not certain check whether the out-parameter are available. - if( !bOutParams ) - { - ParamMode aParamMode = rInfo.aMode; - if( aParamMode != ParamMode_IN ) - bOutParams = true; - } + // If it is not certain check whether the out-parameter are available. + if( !bOutParams ) + { + ParamMode aParamMode = rInfo.aMode; + if( aParamMode != ParamMode_IN ) + bOutParams = true; } } } - else if( bInvocation && pParams && mxInvocation.is() ) - { - processAutomationParams( pParams, args, nParamCount ); - } + } + else if( bInvocation && pParams && mxInvocation.is() ) + { + processAutomationParams( pParams, args, nParamCount ); + } - // call the method - GetSbData()->bBlockCompilerError = true; // #106433 Block compiler errors for API calls - try + // call the method + GetSbData()->bBlockCompilerError = true; // #106433 Block compiler errors for API calls + try + { + if( !bInvocation && mxUnoAccess.is() ) { - if( !bInvocation && mxUnoAccess.is() ) - { - Any aRetAny = pMeth->m_xUnoMethod->invoke( getUnoAny(), args ); + Any aRetAny = pMeth->m_xUnoMethod->invoke( getUnoAny(), args ); - // take over the value from Uno to Sbx - unoToSbxValue( pVar, aRetAny ); + // take over the value from Uno to Sbx + unoToSbxValue( pVar, aRetAny ); - // Did we to copy back the Out-Parameter? - if( bOutParams ) - { - const Any* pAnyArgs = args.getConstArray(); + // Did we to copy back the Out-Parameter? + if( bOutParams ) + { + const Any* pAnyArgs = args.getConstArray(); - // get info - const Sequence<ParamInfo>& rInfoSeq = pMeth->getParamInfos(); - const ParamInfo* pParamInfos = rInfoSeq.getConstArray(); + // get info + const Sequence<ParamInfo>& rInfoSeq = pMeth->getParamInfos(); + const ParamInfo* pParamInfos = rInfoSeq.getConstArray(); - sal_uInt32 j; - for( j = 0 ; j < nParamCount ; j++ ) - { - const ParamInfo& rInfo = pParamInfos[j]; - ParamMode aParamMode = rInfo.aMode; - if( aParamMode != ParamMode_IN ) - unoToSbxValue( pParams->Get32(j + 1), pAnyArgs[ j ] ); - } + sal_uInt32 j; + for( j = 0 ; j < nParamCount ; j++ ) + { + const ParamInfo& rInfo = pParamInfos[j]; + ParamMode aParamMode = rInfo.aMode; + if( aParamMode != ParamMode_IN ) + unoToSbxValue( pParams->Get32(j + 1), pAnyArgs[ j ] ); } } - else if( bInvocation && mxInvocation.is() ) - { - Any aRetAny = invokeAutomationMethod( pMeth->GetName(), args, pParams, nParamCount, mxInvocation, INVOKETYPE::Func ); - unoToSbxValue( pVar, aRetAny ); - } - - // remove parameter here, because this was not done anymore in unoToSbxValue() - // for arrays - if( pParams ) - pVar->SetParameters( nullptr ); } - catch( const Exception& ) + else if( bInvocation && mxInvocation.is() ) { - implHandleAnyException( ::cppu::getCaughtException() ); - } - GetSbData()->bBlockCompilerError = false; // #106433 Unblock compiler errors + Any aRetAny = invokeAutomationMethod( pMeth->GetName(), args, pParams, nParamCount, mxInvocation, INVOKETYPE::Func ); + unoToSbxValue( pVar, aRetAny ); + } + + // remove parameter here, because this was not done anymore in unoToSbxValue() + // for arrays + if( pParams ) + pVar->SetParameters( nullptr ); + } + catch( const Exception& ) + { + implHandleAnyException( ::cppu::getCaughtException() ); } + GetSbData()->bBlockCompilerError = false; // #106433 Unblock compiler errors } - else - SbxObject::Notify( rBC, rHint ); } + else + SbxObject::Notify( rBC, rHint ); } @@ -3233,47 +3233,47 @@ VBAConstantHelper::instance() void VBAConstantHelper::init() { - if ( !isInited ) - { - Sequence< TypeClass > types(1); - types[ 0 ] = TypeClass_CONSTANTS; - Reference< XTypeDescriptionEnumeration > xEnum = getTypeDescriptorEnumeration( "ooo.vba", types, TypeDescriptionSearchDepth_INFINITE ); + if ( isInited ) + return; - if ( !xEnum.is()) - { - return; //NULL; - } - while ( xEnum->hasMoreElements() ) + Sequence< TypeClass > types(1); + types[ 0 ] = TypeClass_CONSTANTS; + Reference< XTypeDescriptionEnumeration > xEnum = getTypeDescriptorEnumeration( "ooo.vba", types, TypeDescriptionSearchDepth_INFINITE ); + + if ( !xEnum.is()) + { + return; //NULL; + } + while ( xEnum->hasMoreElements() ) + { + Reference< XConstantsTypeDescription > xConstants( xEnum->nextElement(), UNO_QUERY ); + if ( xConstants.is() ) { - Reference< XConstantsTypeDescription > xConstants( xEnum->nextElement(), UNO_QUERY ); - if ( xConstants.is() ) + // store constant group name + OUString sFullName = xConstants->getName(); + sal_Int32 indexLastDot = sFullName.lastIndexOf('.'); + OUString sLeafName( sFullName ); + if ( indexLastDot > -1 ) { - // store constant group name - OUString sFullName = xConstants->getName(); - sal_Int32 indexLastDot = sFullName.lastIndexOf('.'); - OUString sLeafName( sFullName ); + sLeafName = sFullName.copy( indexLastDot + 1); + } + aConstCache.push_back( sLeafName ); // assume constant group names are unique + Sequence< Reference< XConstantTypeDescription > > aConsts = xConstants->getConstants(); + for (sal_Int32 i = 0; i != aConsts.getLength(); ++i) + { + // store constant member name + sFullName = aConsts[i]->getName(); + indexLastDot = sFullName.lastIndexOf('.'); + sLeafName = sFullName; if ( indexLastDot > -1 ) { sLeafName = sFullName.copy( indexLastDot + 1); } - aConstCache.push_back( sLeafName ); // assume constant group names are unique - Sequence< Reference< XConstantTypeDescription > > aConsts = xConstants->getConstants(); - for (sal_Int32 i = 0; i != aConsts.getLength(); ++i) - { - // store constant member name - sFullName = aConsts[i]->getName(); - indexLastDot = sFullName.lastIndexOf('.'); - sLeafName = sFullName; - if ( indexLastDot > -1 ) - { - sLeafName = sFullName.copy( indexLastDot + 1); - } - aConstHash[ sLeafName.toAsciiLowerCase() ] = aConsts[i]->getConstantValue(); - } + aConstHash[ sLeafName.toAsciiLowerCase() ] = aConsts[i]->getConstantValue(); } } - isInited = true; } + isInited = true; } bool @@ -3532,151 +3532,151 @@ SbxVariable* SbUnoService::Find( const OUString& rName, SbxClassType ) void SbUnoService::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) { const SbxHint* pHint = dynamic_cast<const SbxHint*>(&rHint); - if( pHint ) + if( !pHint ) + return; + + SbxVariable* pVar = pHint->GetVar(); + SbxArray* pParams = pVar->GetParameters(); + SbUnoServiceCtor* pUnoCtor = dynamic_cast<SbUnoServiceCtor*>( pVar ); + if( pUnoCtor && pHint->GetId() == SfxHintId::BasicDataWanted ) { - SbxVariable* pVar = pHint->GetVar(); - SbxArray* pParams = pVar->GetParameters(); - SbUnoServiceCtor* pUnoCtor = dynamic_cast<SbUnoServiceCtor*>( pVar ); - if( pUnoCtor && pHint->GetId() == SfxHintId::BasicDataWanted ) - { - // Parameter count -1 because of Param0 == this - sal_uInt32 nParamCount = pParams ? (pParams->Count32() - 1) : 0; - Sequence<Any> args; + // Parameter count -1 because of Param0 == this + sal_uInt32 nParamCount = pParams ? (pParams->Count32() - 1) : 0; + Sequence<Any> args; - Reference< XServiceConstructorDescription > xCtor = pUnoCtor->getServiceCtorDesc(); - Sequence< Reference< XParameter > > aParameterSeq = xCtor->getParameters(); - const Reference< XParameter >* pParameterSeq = aParameterSeq.getConstArray(); - sal_uInt32 nUnoParamCount = aParameterSeq.getLength(); + Reference< XServiceConstructorDescription > xCtor = pUnoCtor->getServiceCtorDesc(); + Sequence< Reference< XParameter > > aParameterSeq = xCtor->getParameters(); + const Reference< XParameter >* pParameterSeq = aParameterSeq.getConstArray(); + sal_uInt32 nUnoParamCount = aParameterSeq.getLength(); - // Default: Ignore not needed parameters - bool bParameterError = false; + // Default: Ignore not needed parameters + bool bParameterError = false; - // Is the last parameter a rest parameter? - bool bRestParameterMode = false; - if( nUnoParamCount > 0 ) + // Is the last parameter a rest parameter? + bool bRestParameterMode = false; + if( nUnoParamCount > 0 ) + { + Reference< XParameter > xLastParam = pParameterSeq[ nUnoParamCount - 1 ]; + if( xLastParam.is() ) { - Reference< XParameter > xLastParam = pParameterSeq[ nUnoParamCount - 1 ]; - if( xLastParam.is() ) - { - if( xLastParam->isRestParameter() ) - bRestParameterMode = true; - } + if( xLastParam->isRestParameter() ) + bRestParameterMode = true; } + } - // Too many parameters with context as first parameter? - sal_uInt32 nSbxParameterOffset = 1; - sal_uInt32 nParameterOffsetByContext = 0; - Reference < XComponentContext > xFirstParamContext; - if( nParamCount > nUnoParamCount ) - { - // Check if first parameter is a context and use it - // then in createInstanceWithArgumentsAndContext - Any aArg0 = sbxToUnoValue( pParams->Get32( nSbxParameterOffset ) ); - if( (aArg0 >>= xFirstParamContext) && xFirstParamContext.is() ) - nParameterOffsetByContext = 1; - } + // Too many parameters with context as first parameter? + sal_uInt32 nSbxParameterOffset = 1; + sal_uInt32 nParameterOffsetByContext = 0; + Reference < XComponentContext > xFirstParamContext; + if( nParamCount > nUnoParamCount ) + { + // Check if first parameter is a context and use it + // then in createInstanceWithArgumentsAndContext + Any aArg0 = sbxToUnoValue( pParams->Get32( nSbxParameterOffset ) ); + if( (aArg0 >>= xFirstParamContext) && xFirstParamContext.is() ) + nParameterOffsetByContext = 1; + } - sal_uInt32 nEffectiveParamCount = nParamCount - nParameterOffsetByContext; - sal_uInt32 nAllocParamCount = nEffectiveParamCount; - if( nEffectiveParamCount > nUnoParamCount ) + sal_uInt32 nEffectiveParamCount = nParamCount - nParameterOffsetByContext; + sal_uInt32 nAllocParamCount = nEffectiveParamCount; + if( nEffectiveParamCount > nUnoParamCount ) + { + if( !bRestParameterMode ) { - if( !bRestParameterMode ) - { - nEffectiveParamCount = nUnoParamCount; - nAllocParamCount = nUnoParamCount; - } + nEffectiveParamCount = nUnoParamCount; + nAllocParamCount = nUnoParamCount; } - // Not enough parameters? - else if( nUnoParamCount > nEffectiveParamCount ) + } + // Not enough parameters? + else if( nUnoParamCount > nEffectiveParamCount ) + { + // RestParameterMode only helps if one (the last) parameter is missing + int nDiff = nUnoParamCount - nEffectiveParamCount; + if( !bRestParameterMode || nDiff > 1 ) { - // RestParameterMode only helps if one (the last) parameter is missing - int nDiff = nUnoParamCount - nEffectiveParamCount; - if( !bRestParameterMode || nDiff > 1 ) - { - bParameterError = true; - StarBASIC::Error( ERRCODE_BASIC_NOT_OPTIONAL ); - } + bParameterError = true; + StarBASIC::Error( ERRCODE_BASIC_NOT_OPTIONAL ); } + } - if( !bParameterError ) + if( !bParameterError ) + { + bool bOutParams = false; + if( nAllocParamCount > 0 ) { - bool bOutParams = false; - if( nAllocParamCount > 0 ) + args.realloc( nAllocParamCount ); + Any* pAnyArgs = args.getArray(); + for( sal_uInt32 i = 0 ; i < nEffectiveParamCount ; i++ ) { - args.realloc( nAllocParamCount ); - Any* pAnyArgs = args.getArray(); - for( sal_uInt32 i = 0 ; i < nEffectiveParamCount ; i++ ) - { - sal_uInt32 iSbx = i + nSbxParameterOffset + nParameterOffsetByContext; + sal_uInt32 iSbx = i + nSbxParameterOffset + nParameterOffsetByContext; - // bRestParameterMode allows nEffectiveParamCount > nUnoParamCount - Reference< XParameter > xParam; - if( i < nUnoParamCount ) - { - xParam = pParameterSeq[i]; - if( !xParam.is() ) - continue; + // bRestParameterMode allows nEffectiveParamCount > nUnoParamCount + Reference< XParameter > xParam; + if( i < nUnoParamCount ) + { + xParam = pParameterSeq[i]; + if( !xParam.is() ) + continue; - Reference< XTypeDescription > xParamTypeDesc = xParam->getType(); - if( !xParamTypeDesc.is() ) - continue; - css::uno::Type aType( xParamTypeDesc->getTypeClass(), xParamTypeDesc->getName() ); + Reference< XTypeDescription > xParamTypeDesc = xParam->getType(); + if( !xParamTypeDesc.is() ) + continue; + css::uno::Type aType( xParamTypeDesc->getTypeClass(), xParamTypeDesc->getName() ); - // sbx parameter needs offset 1 - pAnyArgs[i] = sbxToUnoValue( pParams->Get32( iSbx ), aType ); + // sbx parameter needs offset 1 + pAnyArgs[i] = sbxToUnoValue( pParams->Get32( iSbx ), aType ); - // Check for out parameter if not already done - if( !bOutParams && xParam->isOut() ) - bOutParams = true; - } - else - { - pAnyArgs[i] = sbxToUnoValue( pParams->Get32( iSbx ) ); - } + // Check for out parameter if not already done + if( !bOutParams && xParam->isOut() ) + bOutParams = true; + } + else + { + pAnyArgs[i] = sbxToUnoValue( pParams->Get32( iSbx ) ); } } + } - // "Call" ctor using createInstanceWithArgumentsAndContext - Reference < XComponentContext > xContext( - xFirstParamContext.is() - ? xFirstParamContext - : comphelper::getProcessComponentContext() ); - Reference< XMultiComponentFactory > xServiceMgr( xContext->getServiceManager() ); + // "Call" ctor using createInstanceWithArgumentsAndContext + Reference < XComponentContext > xContext( + xFirstParamContext.is() + ? xFirstParamContext + : comphelper::getProcessComponentContext() ); + Reference< XMultiComponentFactory > xServiceMgr( xContext->getServiceManager() ); - Any aRetAny; - OUString aServiceName = GetName(); - Reference < XInterface > xRet; - try - { - xRet = xServiceMgr->createInstanceWithArgumentsAndContext( aServiceName, args, xContext ); - } - catch( const Exception& ) - { - implHandleAnyException( ::cppu::getCaughtException() ); - } - aRetAny <<= xRet; - unoToSbxValue( pVar, aRetAny ); + Any aRetAny; + OUString aServiceName = GetName(); + Reference < XInterface > xRet; + try + { + xRet = xServiceMgr->createInstanceWithArgumentsAndContext( aServiceName, args, xContext ); + } + catch( const Exception& ) + { + implHandleAnyException( ::cppu::getCaughtException() ); + } + aRetAny <<= xRet; + unoToSbxValue( pVar, aRetAny ); - // Copy back out parameters? - if( bOutParams ) - { - const Any* pAnyArgs = args.getConstArray(); + // Copy back out parameters? + if( bOutParams ) + { + const Any* pAnyArgs = args.getConstArray(); - for( sal_uInt32 j = 0 ; j < nUnoParamCount ; j++ ) - { - Reference< XParameter > xParam = pParameterSeq[j]; - if( !xParam.is() ) - continue; + for( sal_uInt32 j = 0 ; j < nUnoParamCount ; j++ ) + { + Reference< XParameter > xParam = pParameterSeq[j]; + if( !xParam.is() ) + continue; - if( xParam->isOut() ) - unoToSbxValue( pParams->Get32(j + 1), pAnyArgs[ j ] ); - } + if( xParam->isOut() ) + unoToSbxValue( pParams->Get32(j + 1), pAnyArgs[ j ] ); } } } - else - SbxObject::Notify( rBC, rHint ); } + else + SbxObject::Notify( rBC, rHint ); } @@ -3812,46 +3812,46 @@ void BasicAllListener_Impl::firing_impl( const AllEventObject& Event, Any* pRet { SolarMutexGuard guard; - if( xSbxObj.is() ) - { - OUString aMethodName = aPrefixName + Event.MethodName; + if( !xSbxObj.is() ) + return; + + OUString aMethodName = aPrefixName + Event.MethodName; - SbxVariable * pP = xSbxObj.get(); - while( pP->GetParent() ) + SbxVariable * pP = xSbxObj.get(); + while( pP->GetParent() ) + { + pP = pP->GetParent(); + StarBASIC * pLib = dynamic_cast<StarBASIC*>( pP ); + if( pLib ) { - pP = pP->GetParent(); - StarBASIC * pLib = dynamic_cast<StarBASIC*>( pP ); - if( pLib ) + // Create in a Basic Array + SbxArrayRef xSbxArray = new SbxArray( SbxVARIANT ); + const Any * pArgs = Event.Arguments.getConstArray(); + sal_Int32 nCount = Event.Arguments.getLength(); + for( sal_Int32 i = 0; i < nCount; i++ ) { - // Create in a Basic Array - SbxArrayRef xSbxArray = new SbxArray( SbxVARIANT ); - const Any * pArgs = Event.Arguments.getConstArray(); - sal_Int32 nCount = Event.Arguments.getLength(); - for( sal_Int32 i = 0; i < nCount; i++ ) - { - // Convert elements - SbxVariableRef xVar = new SbxVariable( SbxVARIANT ); - unoToSbxValue( xVar.get(), pArgs[i] ); - xSbxArray->Put32( xVar.get(), i + 1 ); - } + // Convert elements + SbxVariableRef xVar = new SbxVariable( SbxVARIANT ); + unoToSbxValue( xVar.get(), pArgs[i] ); + xSbxArray->Put32( xVar.get(), i + 1 ); + } - pLib->Call( aMethodName, xSbxArray.get() ); + pLib->Call( aMethodName, xSbxArray.get() ); - // get the return value from the Param-Array, if requested - if( pRet ) + // get the return value from the Param-Array, if requested + if( pRet ) + { + SbxVariable* pVar = xSbxArray->Get32( 0 ); + if( pVar ) { - SbxVariable* pVar = xSbxArray->Get32( 0 ); - if( pVar ) - { - // #95792 Avoid a second call - SbxFlagBits nFlags = pVar->GetFlags(); - pVar->SetFlag( SbxFlagBits::NoBroadcast ); - *pRet = sbxToUnoValueImpl( pVar ); - pVar->SetFlags( nFlags ); - } + // #95792 Avoid a second call + SbxFlagBits nFlags = pVar->GetFlags(); + pVar->SetFlag( SbxFlagBits::NoBroadcast ); + *pRet = sbxToUnoValueImpl( pVar ); + pVar->SetFlags( nFlags ); } - break; } + break; } } } @@ -4473,29 +4473,29 @@ void registerComListenerVariableForBasic( SbxVariable* pVar, StarBASIC* pBasic ) void disposeComVariablesForBasic( StarBASIC const * pBasic ) { DisposeItemVector::iterator it = lcl_findItemForBasic( pBasic ); - if( it != GaDisposeItemVector.end() ) - { - StarBasicDisposeItem* pItem = *it; + if( it == GaDisposeItemVector.end() ) + return; - SbxArray* pArray = pItem->m_pRegisteredVariables.get(); - sal_uInt32 nCount = pArray->Count32(); - for( sal_uInt32 i = 0 ; i < nCount ; ++i ) - { - SbxVariable* pVar = pArray->Get32( i ); - pVar->ClearComListener(); - } + StarBasicDisposeItem* pItem = *it; - ComponentRefVector& rv = pItem->m_vComImplementsObjects; - for (auto const& elem : rv) - { - Reference< XComponent > xComponent( elem.get(), UNO_QUERY ); - if (xComponent.is()) - xComponent->dispose(); - } + SbxArray* pArray = pItem->m_pRegisteredVariables.get(); + sal_uInt32 nCount = pArray->Count32(); + for( sal_uInt32 i = 0 ; i < nCount ; ++i ) + { + SbxVariable* pVar = pArray->Get32( i ); + pVar->ClearComListener(); + } - delete pItem; - GaDisposeItemVector.erase( it ); + ComponentRefVector& rv = pItem->m_vComImplementsObjects; + for (auto const& elem : rv) + { + Reference< XComponent > xComponent( elem.get(), UNO_QUERY ); + if (xComponent.is()) + xComponent->dispose(); } + + delete pItem; + GaDisposeItemVector.erase( it ); } @@ -4830,72 +4830,72 @@ void SbUnoStructRefObject::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) if ( !mbMemberCacheInit ) initMemberCache(); const SbxHint* pHint = dynamic_cast<const SbxHint*>(&rHint); - if( pHint ) + if( !pHint ) + return; + + SbxVariable* pVar = pHint->GetVar(); + SbUnoProperty* pProp = dynamic_cast<SbUnoProperty*>( pVar ); + if( pProp ) { - SbxVariable* pVar = pHint->GetVar(); - SbUnoProperty* pProp = dynamic_cast<SbUnoProperty*>( pVar ); - if( pProp ) + StructFieldInfo::iterator it = maFields.find( pProp->GetName() ); + // handle get/set of members of struct + if( pHint->GetId() == SfxHintId::BasicDataWanted ) { - StructFieldInfo::iterator it = maFields.find( pProp->GetName() ); - // handle get/set of members of struct - if( pHint->GetId() == SfxHintId::BasicDataWanted ) + // Test-Properties + sal_Int32 nId = pProp->nId; + if( nId < 0 ) { - // Test-Properties - sal_Int32 nId = pProp->nId; - if( nId < 0 ) + // Id == -1: Display implemented interfaces according the ClassProvider + if( nId == -1 ) // Property ID_DBG_SUPPORTEDINTERFACES" { - // Id == -1: Display implemented interfaces according the ClassProvider - if( nId == -1 ) // Property ID_DBG_SUPPORTEDINTERFACES" - { - OUString aRet = OUStringLiteral( ID_DBG_SUPPORTEDINTERFACES ) - + " not available.\n(TypeClass is not TypeClass_INTERFACE)\n"; + OUString aRet = OUStringLiteral( ID_DBG_SUPPORTEDINTERFACES ) + + " not available.\n(TypeClass is not TypeClass_INTERFACE)\n"; - pVar->PutString( aRet ); - } - // Id == -2: output properties - else if( nId == -2 ) // Property ID_DBG_PROPERTIES - { - // by now all properties must be established - implCreateAll(); - OUString aRetStr = Impl_DumpProperties(); - pVar->PutString( aRetStr ); - } - // Id == -3: output the methods - else if( nId == -3 ) // Property ID_DBG_METHODS - { - // by now all properties must be established - implCreateAll(); - OUString aRet = "Methods of object " - + getDbgObjectName() - + "\nNo methods found\n"; - pVar->PutString( aRet ); - } - return; + pVar->PutString( aRet ); } - - if ( it != maFields.end() ) + // Id == -2: output properties + else if( nId == -2 ) // Property ID_DBG_PROPERTIES { - Any aRetAny = it->second->getValue(); - unoToSbxValue( pVar, aRetAny ); + // by now all properties must be established + implCreateAll(); + OUString aRetStr = Impl_DumpProperties(); + pVar->PutString( aRetStr ); } - else - StarBASIC::Error( ERRCODE_BASIC_PROPERTY_NOT_FOUND ); - } - else if( pHint->GetId() == SfxHintId::BasicDataChanged ) - { - if ( it != maFields.end() ) + // Id == -3: output the methods + else if( nId == -3 ) // Property ID_DBG_METHODS { - // take over the value from Uno to Sbx - Any aAnyValue = sbxToUnoValue( pVar, pProp->aUnoProp.Type, &pProp->aUnoProp ); - it->second->setValue( aAnyValue ); + // by now all properties must be established + implCreateAll(); + OUString aRet = "Methods of object " + + getDbgObjectName() + + "\nNo methods found\n"; + pVar->PutString( aRet ); } - else - StarBASIC::Error( ERRCODE_BASIC_PROPERTY_NOT_FOUND ); + return; + } + + if ( it != maFields.end() ) + { + Any aRetAny = it->second->getValue(); + unoToSbxValue( pVar, aRetAny ); } + else + StarBASIC::Error( ERRCODE_BASIC_PROPERTY_NOT_FOUND ); + } + else if( pHint->GetId() == SfxHintId::BasicDataChanged ) + { + if ( it != maFields.end() ) + { + // take over the value from Uno to Sbx + Any aAnyValue = sbxToUnoValue( pVar, pProp->aUnoProp.Type, &pProp->aUnoProp ); + it->second->setValue( aAnyValue ); + } + else + StarBASIC::Error( ERRCODE_BASIC_PROPERTY_NOT_FOUND ); } - else - SbxObject::Notify( rBC, rHint ); } + else + SbxObject::Notify( rBC, rHint ); } StructRefInfo SbUnoStructRefObject::getStructMember( const OUString& rMemberName ) diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx index 45a83f4ec18b..88ade90a4677 100644 --- a/basic/source/classes/sbxmod.cxx +++ b/basic/source/classes/sbxmod.cxx @@ -122,52 +122,52 @@ public: DocObjectWrapper::DocObjectWrapper( SbModule* pVar ) : m_pMod( pVar ) { SbObjModule* pMod = dynamic_cast<SbObjModule*>( pVar ); - if ( pMod ) + if ( !pMod ) + return; + + if ( pMod->GetModuleType() != ModuleType::DOCUMENT ) + return; + + // Use proxy factory service to create aggregatable proxy. + SbUnoObject* pUnoObj = dynamic_cast<SbUnoObject*>( pMod->GetObject() ); + Reference< XInterface > xIf; + if ( pUnoObj ) + { + Any aObj = pUnoObj->getUnoAny(); + aObj >>= xIf; + if ( xIf.is() ) + { + m_xAggregateTypeProv.set( xIf, UNO_QUERY ); + m_xAggInv.set( xIf, UNO_QUERY ); + } + } + if ( xIf.is() ) { - if ( pMod->GetModuleType() == ModuleType::DOCUMENT ) + try { - // Use proxy factory service to create aggregatable proxy. - SbUnoObject* pUnoObj = dynamic_cast<SbUnoObject*>( pMod->GetObject() ); - Reference< XInterface > xIf; - if ( pUnoObj ) - { - Any aObj = pUnoObj->getUnoAny(); - aObj >>= xIf; - if ( xIf.is() ) - { - m_xAggregateTypeProv.set( xIf, UNO_QUERY ); - m_xAggInv.set( xIf, UNO_QUERY ); - } - } - if ( xIf.is() ) - { - try - { - Reference< XProxyFactory > xProxyFac = ProxyFactory::create( comphelper::getProcessComponentContext() ); - m_xAggProxy = xProxyFac->createProxy( xIf ); - } - catch(const Exception& ) - { - TOOLS_WARN_EXCEPTION( "basic", "DocObjectWrapper::DocObjectWrapper" ); - } - } + Reference< XProxyFactory > xProxyFac = ProxyFactory::create( comphelper::getProcessComponentContext() ); + m_xAggProxy = xProxyFac->createProxy( xIf ); + } + catch(const Exception& ) + { + TOOLS_WARN_EXCEPTION( "basic", "DocObjectWrapper::DocObjectWrapper" ); + } + } - if ( m_xAggProxy.is() ) - { - osl_atomic_increment( &m_refCount ); + if ( !m_xAggProxy.is() ) + return; - /* i35609 - Fix crash on Solaris. The setDelegator call needs - to be in its own block to ensure that all temporary Reference - instances that are acquired during the call are released - before m_refCount is decremented again */ - { - m_xAggProxy->setDelegator( static_cast< cppu::OWeakObject * >( this ) ); - } + osl_atomic_increment( &m_refCount ); - osl_atomic_decrement( &m_refCount ); - } - } + /* i35609 - Fix crash on Solaris. The setDelegator call needs + to be in its own block to ensure that all temporary Reference + instances that are acquired during the call are released + before m_refCount is decremented again */ + { + m_xAggProxy->setDelegator( static_cast< cppu::OWeakObject * >( this ) ); } + + osl_atomic_decrement( &m_refCount ); } Sequence< Type > SAL_CALL DocObjectWrapper::getTypes() @@ -673,126 +673,126 @@ void SbModule::SetParent( SbxObject* p ) void SbModule::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) { const SbxHint* pHint = dynamic_cast<const SbxHint*>(&rHint); - if( pHint ) + if( !pHint ) + return; + + SbxVariable* pVar = pHint->GetVar(); + SbProperty* pProp = dynamic_cast<SbProperty*>( pVar ); + SbMethod* pMeth = dynamic_cast<SbMethod*>( pVar ); + SbProcedureProperty* pProcProperty = dynamic_cast<SbProcedureProperty*>( pVar ); + if( pProcProperty ) { - SbxVariable* pVar = pHint->GetVar(); - SbProperty* pProp = dynamic_cast<SbProperty*>( pVar ); - SbMethod* pMeth = dynamic_cast<SbMethod*>( pVar ); - SbProcedureProperty* pProcProperty = dynamic_cast<SbProcedureProperty*>( pVar ); - if( pProcProperty ) + + if( pHint->GetId() == SfxHintId::BasicDataWanted ) { + OUString aProcName = "Property Get " + + pProcProperty->GetName(); - if( pHint->GetId() == SfxHintId::BasicDataWanted ) + SbxVariable* pMethVar = Find( aProcName, SbxClassType::Method ); + if( pMethVar ) { - OUString aProcName = "Property Get " - + pProcProperty->GetName(); + SbxValues aVals; + aVals.eType = SbxVARIANT; - SbxVariable* pMethVar = Find( aProcName, SbxClassType::Method ); - if( pMethVar ) + SbxArray* pArg = pVar->GetParameters(); + sal_uInt32 nVarParCount = (pArg != nullptr) ? pArg->Count32() : 0; + if( nVarParCount > 1 ) { - SbxValues aVals; - aVals.eType = SbxVARIANT; - - SbxArray* pArg = pVar->GetParameters(); - sal_uInt32 nVarParCount = (pArg != nullptr) ? pArg->Count32() : 0; - if( nVarParCount > 1 ) + auto xMethParameters = tools::make_ref<SbxArray>(); + xMethParameters->Put32( pMethVar, 0 ); // Method as parameter 0 + for( sal_uInt32 i = 1 ; i < nVarParCount ; ++i ) { - auto xMethParameters = tools::make_ref<SbxArray>(); - xMethParameters->Put32( pMethVar, 0 ); // Method as parameter 0 - for( sal_uInt32 i = 1 ; i < nVarParCount ; ++i ) - { - SbxVariable* pPar = pArg->Get32( i ); - xMethParameters->Put32( pPar, i ); - } - - pMethVar->SetParameters( xMethParameters.get() ); - pMethVar->Get( aVals ); - pMethVar->SetParameters( nullptr ); + SbxVariable* pPar = pArg->Get32( i ); + xMethParameters->Put32( pPar, i ); } - else - { - pMethVar->Get( aVals ); - } - - pVar->Put( aVals ); - } - } - else if( pHint->GetId() == SfxHintId::BasicDataChanged ) - { - SbxVariable* pMethVar = nullptr; - - bool bSet = pProcProperty->isSet(); - if( bSet ) - { - pProcProperty->setSet( false ); - OUString aProcName = "Property Set " - + pProcProperty->GetName(); - pMethVar = Find( aProcName, SbxClassType::Method ); - } - if( !pMethVar ) // Let - { - OUString aProcName = "Property Let " - + pProcProperty->GetName(); - pMethVar = Find( aProcName, SbxClassType::Method ); + pMethVar->SetParameters( xMethParameters.get() ); + pMethVar->Get( aVals ); + pMethVar->SetParameters( nullptr ); } - - if( pMethVar ) + else { - // Setup parameters - SbxArrayRef xArray = new SbxArray; - xArray->Put32( pMethVar, 0 ); // Method as parameter 0 - xArray->Put32( pVar, 1 ); - pMethVar->SetParameters( xArray.get() ); - - SbxValues aVals; pMethVar->Get( aVals ); - pMethVar->SetParameters( nullptr ); } + + pVar->Put( aVals ); } } - if( pProp ) - { - if( pProp->GetModule() != this ) - SetError( ERRCODE_BASIC_BAD_ACTION ); - } - else if( pMeth ) + else if( pHint->GetId() == SfxHintId::BasicDataChanged ) { - if( pHint->GetId() == SfxHintId::BasicDataWanted ) + SbxVariable* pMethVar = nullptr; + + bool bSet = pProcProperty->isSet(); + if( bSet ) { - if( pMeth->bInvalid && !Compile() ) - { - // auto compile has not worked! - StarBASIC::Error( ERRCODE_BASIC_BAD_PROP_VALUE ); - } - else - { - // Call of a subprogram - SbModule* pOld = GetSbData()->pMod; - GetSbData()->pMod = this; - Run( static_cast<SbMethod*>(pVar) ); - GetSbData()->pMod = pOld; - } + pProcProperty->setSet( false ); + + OUString aProcName = "Property Set " + + pProcProperty->GetName(); + pMethVar = Find( aProcName, SbxClassType::Method ); + } + if( !pMethVar ) // Let + { + OUString aProcName = "Property Let " + + pProcProperty->GetName(); + pMethVar = Find( aProcName, SbxClassType::Method ); + } + + if( pMethVar ) + { + // Setup parameters + SbxArrayRef xArray = new SbxArray; + xArray->Put32( pMethVar, 0 ); // Method as parameter 0 + xArray->Put32( pVar, 1 ); + pMethVar->SetParameters( xArray.get() ); + + SbxValues aVals; + pMethVar->Get( aVals ); + pMethVar->SetParameters( nullptr ); } } - else + } + if( pProp ) + { + if( pProp->GetModule() != this ) + SetError( ERRCODE_BASIC_BAD_ACTION ); + } + else if( pMeth ) + { + if( pHint->GetId() == SfxHintId::BasicDataWanted ) { - // #i92642: Special handling for name property to avoid - // side effects when using name as variable implicitly - bool bForwardToSbxObject = true; - - const SfxHintId nId = pHint->GetId(); - if( (nId == SfxHintId::BasicDataWanted || nId == SfxHintId::BasicDataChanged) && - pVar->GetName().equalsIgnoreAsciiCase( "name" ) ) + if( pMeth->bInvalid && !Compile() ) { - bForwardToSbxObject = false; + // auto compile has not worked! + StarBASIC::Error( ERRCODE_BASIC_BAD_PROP_VALUE ); } - if( bForwardToSbxObject ) + else { - SbxObject::Notify( rBC, rHint ); + // Call of a subprogram + SbModule* pOld = GetSbData()->pMod; + GetSbData()->pMod = this; + Run( static_cast<SbMethod*>(pVar) ); + GetSbData()->pMod = pOld; } } } + else + { + // #i92642: Special handling for name property to avoid + // side effects when using name as variable implicitly + bool bForwardToSbxObject = true; + + const SfxHintId nId = pHint->GetId(); + if( (nId == SfxHintId::BasicDataWanted || nId == SfxHintId::BasicDataChanged) && + pVar->GetName().equalsIgnoreAsciiCase( "name" ) ) + { + bForwardToSbxObject = false; + } + if( bForwardToSbxObject ) + { + SbxObject::Notify( rBC, rHint ); + } + } } // The setting of the source makes the image invalid @@ -975,19 +975,19 @@ static void ClearUnoObjectsInRTL_Impl( StarBASIC* pBasic ) void SbModule::SetVBACompat( bool bCompat ) { - if( mbVBACompat != bCompat ) + if( mbVBACompat == bCompat ) + return; + + mbVBACompat = bCompat; + // initialize VBA document API + if( mbVBACompat ) try + { + StarBASIC* pBasic = static_cast< StarBASIC* >( GetParent() ); + uno::Reference< lang::XMultiServiceFactory > xFactory( getDocumentModel( pBasic ), uno::UNO_QUERY_THROW ); + xFactory->createInstance( "ooo.vba.VBAGlobals" ); + } + catch( Exception& ) { - mbVBACompat = bCompat; - // initialize VBA document API - if( mbVBACompat ) try - { - StarBASIC* pBasic = static_cast< StarBASIC* >( GetParent() ); - uno::Reference< lang::XMultiServiceFactory > xFactory( getDocumentModel( pBasic ), uno::UNO_QUERY_THROW ); - xFactory->createInstance( "ooo.vba.VBAGlobals" ); - } - catch( Exception& ) - { - } } } @@ -1242,26 +1242,26 @@ void SbModule::Run( SbMethod* pMeth ) // or the compilation void SbModule::RunInit() { - if( pImage + if( !(pImage && !pImage->bInit - && pImage->IsFlag( SbiImageFlags::INITCODE ) ) - { - SbiGlobals* pSbData = GetSbData(); + && pImage->IsFlag( SbiImageFlags::INITCODE )) ) + return; - // Set flag, so that RunInit get active (Testtool) - pSbData->bRunInit = true; + SbiGlobals* pSbData = GetSbData(); - // The init code starts always here - auto xRuntimeGuard(std::make_unique<RunInitGuard>(this, nullptr, 0, pSbData)); - xRuntimeGuard->run(); - xRuntimeGuard.reset(); + // Set flag, so that RunInit get active (Testtool) + pSbData->bRunInit = true; - pImage->bInit = true; - pImage->bFirstInit = false; + // The init code starts always here + auto xRuntimeGuard(std::make_unique<RunInitGuard>(this, nullptr, 0, pSbData)); + xRuntimeGuard->run(); + xRuntimeGuard.reset(); - // RunInit is not active anymore - pSbData->bRunInit = false; - } + pImage->bInit = true; + pImage->bFirstInit = false; + + // RunInit is not active anymore + pSbData->bRunInit = false; } // Delete with private/dim declared variables @@ -1324,22 +1324,22 @@ void SbModule::implClearIfVarDependsOnDeletedBasic( SbxVariable* pVar, StarBASIC return; SbxObject* pObj = dynamic_cast<SbxObject*>( pVar->GetObject() ); - if( pObj != nullptr ) - { - SbxObject* p = pObj; + if( pObj == nullptr ) + return; + + SbxObject* p = pObj; - SbModule* pMod = dynamic_cast<SbModule*>( p ); - if( pMod != nullptr ) - pMod->ClearVarsDependingOnDeletedBasic( pDeletedBasic ); + SbModule* pMod = dynamic_cast<SbModule*>( p ); + if( pMod != nullptr ) + pMod->ClearVarsDependingOnDeletedBasic( pDeletedBasic ); - while( (p = p->GetParent()) != nullptr ) + while( (p = p->GetParent()) != nullptr ) + { + StarBASIC* pBasic = dynamic_cast<StarBASIC*>( p ); + if( pBasic != nullptr && pBasic == pDeletedBasic ) { - StarBASIC* pBasic = dynamic_cast<StarBASIC*>( p ); - if( pBasic != nullptr && pBasic == pDeletedBasic ) - { - pVar->SbxValue::Clear(); - break; - } + pVar->SbxValue::Clear(); + break; } } } @@ -1399,28 +1399,28 @@ void SbModule::GlobalRunInit( bool bBasicStart ) // Parent of the module is a Basic StarBASIC *pBasic = dynamic_cast<StarBASIC*>( GetParent() ); - if( pBasic ) - { - pBasic->InitAllModules(); + if( !pBasic ) + return; - SbxObject* pParent_ = pBasic->GetParent(); - if( pParent_ ) - { - StarBASIC * pParentBasic = dynamic_cast<StarBASIC*>( pParent_ ); - if( pParentBasic ) - { - pParentBasic->InitAllModules( pBasic ); + pBasic->InitAllModules(); - // #109018 Parent can also have a parent (library in doc) - SbxObject* pParentParent = pParentBasic->GetParent(); - if( pParentParent ) - { - StarBASIC * pParentParentBasic = dynamic_cast<StarBASIC*>( pParentParent ); - if( pParentParentBasic ) - pParentParentBasic->InitAllModules( pParentBasic ); - } - } - } + SbxObject* pParent_ = pBasic->GetParent(); + if( !pParent_ ) + return; + + StarBASIC * pParentBasic = dynamic_cast<StarBASIC*>( pParent_ ); + if( !pParentBasic ) + return; + + pParentBasic->InitAllModules( pBasic ); + + // #109018 Parent can also have a parent (library in doc) + SbxObject* pParentParent = pParentBasic->GetParent(); + if( pParentParent ) + { + StarBASIC * pParentParentBasic = dynamic_cast<StarBASIC*>( pParentParent ); + if( pParentParentBasic ) + pParentParentBasic->InitAllModules( pParentBasic ); } } @@ -2081,43 +2081,43 @@ ErrCode SbMethod::Call( SbxValue* pRet, SbxVariable* pCaller ) // #100883 Own Broadcast for SbMethod void SbMethod::Broadcast( SfxHintId nHintId ) { - if( mpBroadcaster && !IsSet( SbxFlagBits::NoBroadcast ) ) - { - // Because the method could be called from outside, test here once again - // the authorisation - if( nHintId == SfxHintId::BasicDataWanted ) - if( !CanRead() ) - return; - if( nHintId == SfxHintId::BasicDataChanged ) - if( !CanWrite() ) - return; - - if( pMod && !pMod->IsCompiled() ) - pMod->Compile(); - - // Block broadcasts while creating new method - std::unique_ptr<SfxBroadcaster> pSaveBroadcaster = std::move(mpBroadcaster); - SbMethod* pThisCopy = new SbMethod( *this ); - SbMethodRef xHolder = pThisCopy; - if( mpPar.is() ) - { - // Enregister this as element 0, but don't reset the parent! - if( GetType() != SbxVOID ) { - mpPar->PutDirect( pThisCopy, 0 ); - } - SetParameters( nullptr ); - } + if( !(mpBroadcaster && !IsSet( SbxFlagBits::NoBroadcast )) ) + return; + + // Because the method could be called from outside, test here once again + // the authorisation + if( nHintId == SfxHintId::BasicDataWanted ) + if( !CanRead() ) + return; + if( nHintId == SfxHintId::BasicDataChanged ) + if( !CanWrite() ) + return; - mpBroadcaster = std::move(pSaveBroadcaster); - mpBroadcaster->Broadcast( SbxHint( nHintId, pThisCopy ) ); + if( pMod && !pMod->IsCompiled() ) + pMod->Compile(); - SbxFlagBits nSaveFlags = GetFlags(); - SetFlag( SbxFlagBits::ReadWrite ); - pSaveBroadcaster = std::move(mpBroadcaster); - Put( pThisCopy->GetValues_Impl() ); - mpBroadcaster = std::move(pSaveBroadcaster); - SetFlags( nSaveFlags ); + // Block broadcasts while creating new method + std::unique_ptr<SfxBroadcaster> pSaveBroadcaster = std::move(mpBroadcaster); + SbMethod* pThisCopy = new SbMethod( *this ); + SbMethodRef xHolder = pThisCopy; + if( mpPar.is() ) + { + // Enregister this as element 0, but don't reset the parent! + if( GetType() != SbxVOID ) { + mpPar->PutDirect( pThisCopy, 0 ); + } + SetParameters( nullptr ); } + + mpBroadcaster = std::move(pSaveBroadcaster); + mpBroadcaster->Broadcast( SbxHint( nHintId, pThisCopy ) ); + + SbxFlagBits nSaveFlags = GetFlags(); + SetFlag( SbxFlagBits::ReadWrite ); + pSaveBroadcaster = std::move(mpBroadcaster); + Put( pThisCopy->GetValues_Impl() ); + mpBroadcaster = std::move(pSaveBroadcaster); + SetFlags( nSaveFlags ); } @@ -2431,39 +2431,39 @@ void SbUserFormModule::triggerMethod( const OUString& aMethodToRun, Sequence< An SAL_INFO("basic", "trigger " << aMethodToRun); // Search method SbxVariable* pMeth = SbObjModule::Find( aMethodToRun, SbxClassType::Method ); - if( pMeth ) + if( !pMeth ) + return; + + if ( aArguments.hasElements() ) // Setup parameters { - if ( aArguments.hasElements() ) // Setup parameters - { - auto xArray = tools::make_ref<SbxArray>(); - xArray->Put32( pMeth, 0 ); // Method as parameter 0 + auto xArray = tools::make_ref<SbxArray>(); + xArray->Put32( pMeth, 0 ); // Method as parameter 0 - for ( sal_Int32 i = 0; i < aArguments.getLength(); ++i ) - { - auto xSbxVar = tools::make_ref<SbxVariable>( SbxVARIANT ); - unoToSbxValue( xSbxVar.get(), aArguments[i] ); - xArray->Put32( xSbxVar.get(), static_cast< sal_uInt32 >( i ) + 1 ); + for ( sal_Int32 i = 0; i < aArguments.getLength(); ++i ) + { + auto xSbxVar = tools::make_ref<SbxVariable>( SbxVARIANT ); + unoToSbxValue( xSbxVar.get(), aArguments[i] ); + xArray->Put32( xSbxVar.get(), static_cast< sal_uInt32 >( i ) + 1 ); - // Enable passing by ref - if ( xSbxVar->GetType() != SbxVARIANT ) - xSbxVar->SetFlag( SbxFlagBits::Fixed ); - } - pMeth->SetParameters( xArray.get() ); + // Enable passing by ref + if ( xSbxVar->GetType() != SbxVARIANT ) + xSbxVar->SetFlag( SbxFlagBits::Fixed ); + } + pMeth->SetParameters( xArray.get() ); - SbxValues aVals; - pMeth->Get( aVals ); + SbxValues aVals; + pMeth->Get( aVals ); - for ( sal_Int32 i = 0; i < aArguments.getLength(); ++i ) - { - aArguments[i] = sbxToUnoValue( xArray->Get32( static_cast< sal_uInt32 >(i) + 1) ); - } - pMeth->SetParameters( nullptr ); - } - else + for ( sal_Int32 i = 0; i < aArguments.getLength(); ++i ) { - SbxValues aVals; - pMeth->Get( aVals ); + aArguments[i] = sbxToUnoValue( xArray->Get32( static_cast< sal_uInt32 >(i) + 1) ); } + pMeth->SetParameters( nullptr ); + } + else + { + SbxValues aVals; + pMeth->Get( aVals ); } } @@ -2562,25 +2562,25 @@ void SbUserFormModule::Unload() } // Search method SbxVariable* pMeth = SbObjModule::Find( "UnloadObject", SbxClassType::Method ); - if( pMeth ) + if( !pMeth ) + return; + + SAL_INFO("basic", "Attempting to run the UnloadObjectMethod"); + m_xDialog.clear(); //release ref to the uno object + SbxValues aVals; + bool bWaitForDispose = true; // assume dialog is showing + if (m_DialogListener) { - SAL_INFO("basic", "Attempting to run the UnloadObjectMethod"); - m_xDialog.clear(); //release ref to the uno object - SbxValues aVals; - bool bWaitForDispose = true; // assume dialog is showing - if (m_DialogListener) - { - bWaitForDispose = m_DialogListener->isShowing(); - SAL_INFO("basic", "Showing " << bWaitForDispose ); - } - pMeth->Get( aVals); - if ( !bWaitForDispose ) - { - // we've either already got a dispose or we are never going to get one - ResetApiObj(); - } // else wait for dispose - SAL_INFO("basic", "UnloadObject completed (we hope)"); + bWaitForDispose = m_DialogListener->isShowing(); + SAL_INFO("basic", "Showing " << bWaitForDispose ); } + pMeth->Get( aVals); + if ( !bWaitForDispose ) + { + // we've either already got a dispose or we are never going to get one + ResetApiObj(); + } // else wait for dispose + SAL_INFO("basic", "UnloadObject completed (we hope)"); } diff --git a/basic/source/comp/buffer.cxx b/basic/source/comp/buffer.cxx index a7dca978b27a..80017fcca354 100644 --- a/basic/source/comp/buffer.cxx +++ b/basic/source/comp/buffer.cxx @@ -124,29 +124,29 @@ void SbiBuffer::Patch( sal_uInt32 off, sal_uInt32 val ) void SbiBuffer::Chain( sal_uInt32 off ) { - if( off && pBuf ) + if( !(off && pBuf) ) + return; + + sal_uInt8 *ip; + sal_uInt32 i = off; + sal_uInt32 val1 = (nOff & 0xFFFF); + sal_uInt32 val2 = (nOff >> 16); + do { - sal_uInt8 *ip; - sal_uInt32 i = off; - sal_uInt32 val1 = (nOff & 0xFFFF); - sal_uInt32 val2 = (nOff >> 16); - do + ip = reinterpret_cast<sal_uInt8*>(pBuf.get()) + i; + sal_uInt8* pTmp = ip; + i = *pTmp++; i |= *pTmp++ << 8; i |= *pTmp++ << 16; i |= *pTmp++ << 24; + + if( i >= nOff ) { - ip = reinterpret_cast<sal_uInt8*>(pBuf.get()) + i; - sal_uInt8* pTmp = ip; - i = *pTmp++; i |= *pTmp++ << 8; i |= *pTmp++ << 16; i |= *pTmp++ << 24; - - if( i >= nOff ) - { - pParser->Error( ERRCODE_BASIC_INTERNAL_ERROR, "BACKCHAIN" ); - break; - } - *ip++ = static_cast<char>( val1 & 0xFF ); - *ip++ = static_cast<char>( val1 >> 8 ); - *ip++ = static_cast<char>( val2 & 0xFF ); - *ip = static_cast<char>( val2 >> 8 ); - } while( i ); - } + pParser->Error( ERRCODE_BASIC_INTERNAL_ERROR, "BACKCHAIN" ); + break; + } + *ip++ = static_cast<char>( val1 & 0xFF ); + *ip++ = static_cast<char>( val1 >> 8 ); + *ip++ = static_cast<char>( val2 & 0xFF ); + *ip = static_cast<char>( val2 >> 8 ); + } while( i ); } void SbiBuffer::operator +=( sal_Int8 n ) diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx index 0689e421e533..211d4e325f5b 100644 --- a/basic/source/comp/dim.cxx +++ b/basic/source/comp/dim.cxx @@ -79,116 +79,116 @@ SbiSymDef* SbiParser::VarDecl( SbiExprListPtr* ppDim, bool bStatic, bool bConst void SbiParser::TypeDecl( SbiSymDef& rDef, bool bAsNewAlreadyParsed ) { SbxDataType eType = rDef.GetType(); - if( bAsNewAlreadyParsed || Peek() == AS ) + if( !(bAsNewAlreadyParsed || Peek() == AS) ) + return; + + short nSize = 0; + if( !bAsNewAlreadyParsed ) + Next(); + rDef.SetDefinedAs(); + SbiToken eTok = Next(); + if( !bAsNewAlreadyParsed && eTok == NEW ) { - short nSize = 0; - if( !bAsNewAlreadyParsed ) - Next(); - rDef.SetDefinedAs(); - SbiToken eTok = Next(); - if( !bAsNewAlreadyParsed && eTok == NEW ) - { - rDef.SetNew(); - eTok = Next(); - } - switch( eTok ) - { - case ANY: - if( rDef.IsNew() ) - Error( ERRCODE_BASIC_SYNTAX ); - eType = SbxVARIANT; break; - case TINTEGER: - case TLONG: - case TSINGLE: - case TDOUBLE: - case TCURRENCY: - case TDATE: - case TSTRING: - case TOBJECT: - case ERROR_: - case TBOOLEAN: - case TVARIANT: - case TBYTE: - if( rDef.IsNew() ) - Error( ERRCODE_BASIC_SYNTAX ); - eType = (eTok==TBYTE) ? SbxBYTE : SbxDataType( eTok - TINTEGER + SbxINTEGER ); - if( eType == SbxSTRING ) - { - // STRING*n ? - if( Peek() == MUL ) - { // fixed size! - Next(); - SbiConstExpression aSize( this ); - nSize = aSize.GetShortValue(); - if( nSize < 0 || (bVBASupportOn && nSize <= 0) ) - Error( ERRCODE_BASIC_OUT_OF_RANGE ); - else - rDef.SetFixedStringLength( nSize ); - } + rDef.SetNew(); + eTok = Next(); + } + switch( eTok ) + { + case ANY: + if( rDef.IsNew() ) + Error( ERRCODE_BASIC_SYNTAX ); + eType = SbxVARIANT; break; + case TINTEGER: + case TLONG: + case TSINGLE: + case TDOUBLE: + case TCURRENCY: + case TDATE: + case TSTRING: + case TOBJECT: + case ERROR_: + case TBOOLEAN: + case TVARIANT: + case TBYTE: + if( rDef.IsNew() ) + Error( ERRCODE_BASIC_SYNTAX ); + eType = (eTok==TBYTE) ? SbxBYTE : SbxDataType( eTok - TINTEGER + SbxINTEGER ); + if( eType == SbxSTRING ) + { + // STRING*n ? + if( Peek() == MUL ) + { // fixed size! + Next(); + SbiConstExpression aSize( this ); + nSize = aSize.GetShortValue(); + if( nSize < 0 || (bVBASupportOn && nSize <= 0) ) + Error( ERRCODE_BASIC_OUT_OF_RANGE ); + else + rDef.SetFixedStringLength( nSize ); } - break; - case SYMBOL: // can only be a TYPE or an object class! - if( eScanType != SbxVARIANT ) - Error( ERRCODE_BASIC_SYNTAX ); - else - { - OUString aCompleteName = aSym; + } + break; + case SYMBOL: // can only be a TYPE or an object class! + if( eScanType != SbxVARIANT ) + Error( ERRCODE_BASIC_SYNTAX ); + else + { + OUString aCompleteName = aSym; - // #52709 DIM AS NEW for Uno with full-qualified name - if( Peek() == DOT ) + // #52709 DIM AS NEW for Uno with full-qualified name + if( Peek() == DOT ) + { + OUString aDotStr( '.' ); + while( Peek() == DOT ) { - OUString aDotStr( '.' ); - while( Peek() == DOT ) + aCompleteName += aDotStr; + Next(); + SbiToken ePeekTok = Peek(); + if( ePeekTok == SYMBOL || IsKwd( ePeekTok ) ) { - aCompleteName += aDotStr; Next(); - SbiToken ePeekTok = Peek(); - if( ePeekTok == SYMBOL || IsKwd( ePeekTok ) ) - { - Next(); - aCompleteName += aSym; - } - else - { - Next(); - Error( ERRCODE_BASIC_UNEXPECTED, SYMBOL ); - break; - } + aCompleteName += aSym; + } + else + { + Next(); + Error( ERRCODE_BASIC_UNEXPECTED, SYMBOL ); + break; } } - else if( rEnumArray->Find( aCompleteName, SbxClassType::Object ) || ( IsVBASupportOn() && VBAConstantHelper::instance().isVBAConstantType( aCompleteName ) ) ) - { - eType = SbxLONG; - break; - } + } + else if( rEnumArray->Find( aCompleteName, SbxClassType::Object ) || ( IsVBASupportOn() && VBAConstantHelper::instance().isVBAConstantType( aCompleteName ) ) ) + { + eType = SbxLONG; + break; + } - // Take over in the string pool - rDef.SetTypeId( aGblStrings.Add( aCompleteName ) ); + // Take over in the string pool + rDef.SetTypeId( aGblStrings.Add( aCompleteName ) ); - if( rDef.IsNew() && pProc == nullptr ) - aRequiredTypes.push_back( aCompleteName ); - } - eType = SbxOBJECT; - break; - case FIXSTRING: // new syntax for complex UNO types - rDef.SetTypeId( aGblStrings.Add( aSym ) ); - eType = SbxOBJECT; - break; - default: - Error( ERRCODE_BASIC_UNEXPECTED, eTok ); - Next(); - } - // The variable could have been declared with a suffix - if( rDef.GetType() != SbxVARIANT ) - { - if( rDef.GetType() != eType ) - Error( ERRCODE_BASIC_VAR_DEFINED, rDef.GetName() ); - else if( eType == SbxSTRING && rDef.GetLen() != nSize ) - Error( ERRCODE_BASIC_VAR_DEFINED, rDef.GetName() ); - } - rDef.SetType( eType ); - rDef.SetLen( nSize ); + if( rDef.IsNew() && pProc == nullptr ) + aRequiredTypes.push_back( aCompleteName ); + } + eType = SbxOBJECT; + break; + case FIXSTRING: // new syntax for complex UNO types + rDef.SetTypeId( aGblStrings.Add( aSym ) ); + eType = SbxOBJECT; + break; + default: + Error( ERRCODE_BASIC_UNEXPECTED, eTok ); + Next(); + } + // The variable could have been declared with a suffix + if( rDef.GetType() != SbxVARIANT ) + { + if( rDef.GetType() != eType ) + Error( ERRCODE_BASIC_VAR_DEFINED, rDef.GetName() ); + else if( eType == SbxSTRING && rDef.GetLen() != nSize ) + Error( ERRCODE_BASIC_VAR_DEFINED, rDef.GetName() ); } + rDef.SetType( eType ); + rDef.SetLen( nSize ); } // Here variables, arrays and structures were defined. diff --git a/basic/source/comp/exprgen.cxx b/basic/source/comp/exprgen.cxx index 6c60c02b0d7e..2baf28a803e3 100644 --- a/basic/source/comp/exprgen.cxx +++ b/basic/source/comp/exprgen.cxx @@ -210,49 +210,49 @@ void SbiExprNode::GenElement( SbiCodeGen& rGen, SbiOpcode eOp ) void SbiExprList::Gen(SbiCodeGen& rGen) { - if( !aData.empty() ) - { - rGen.Gen( SbiOpcode::ARGC_ ); - // Type adjustment at DECLARE + if( aData.empty() ) + return; - for( auto& pExpr: aData ) - { - pExpr->Gen(); - if( !pExpr->GetName().isEmpty() ) - { - // named arg - sal_uInt16 nSid = rGen.GetParser()->aGblStrings.Add( pExpr->GetName() ); - rGen.Gen( SbiOpcode::ARGN_, nSid ); + rGen.Gen( SbiOpcode::ARGC_ ); + // Type adjustment at DECLARE - /* TODO: Check after Declare concept change - // From 1996-01-10: Type adjustment at named -> search suitable parameter - if( pProc ) - { - // For the present: trigger an error - pParser->Error( ERRCODE_BASIC_NO_NAMED_ARGS ); + for( auto& pExpr: aData ) + { + pExpr->Gen(); + if( !pExpr->GetName().isEmpty() ) + { + // named arg + sal_uInt16 nSid = rGen.GetParser()->aGblStrings.Add( pExpr->GetName() ); + rGen.Gen( SbiOpcode::ARGN_, nSid ); - // Later, if Named Args at DECLARE is possible - //for( sal_uInt16 i = 1 ; i < nParAnz ; i++ ) - //{ - // SbiSymDef* pDef = pPool->Get( i ); - // const String& rName = pDef->GetName(); - // if( rName.Len() ) - // { - // if( pExpr->GetName().ICompare( rName ) - // == COMPARE_EQUAL ) ... etc. - the rest is truncated _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits