summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorArnaud Versini <arnaud.versini@gmail.com>2015-12-19 15:18:01 +0100
committerMichael Stahl <mstahl@redhat.com>2016-01-07 12:18:40 +0000
commit5e0d36adc3f7f245edfc79230d0871017ba15d5d (patch)
treeb26f52373a20adb65041a79da23803503abad030 /basic
parenta8b10c2841bf38e0f4393594de9b61d9bd3cd842 (diff)
BASIC : use std::vector instead of SbArray for Modules.
Change-Id: I9594efb13b3dccc637ccd61eea4b42255c2a775c Reviewed-on: https://gerrit.libreoffice.org/20817 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Michael Stahl <mstahl@redhat.com>
Diffstat (limited to 'basic')
-rw-r--r--basic/source/basmgr/basmgr.cxx34
-rw-r--r--basic/source/classes/sb.cxx78
-rw-r--r--basic/source/classes/sbxmod.cxx7
-rw-r--r--basic/source/comp/exprnode.cxx5
4 files changed, 47 insertions, 77 deletions
diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx
index 2742a2476e02..8ce26ae27e53 100644
--- a/basic/source/basmgr/basmgr.cxx
+++ b/basic/source/basmgr/basmgr.cxx
@@ -580,12 +580,8 @@ void copyToLibraryContainer( StarBASIC* pBasic, const LibraryContainerInfo& rInf
if ( !xLib.is() )
return;
- sal_uInt16 nModCount = pBasic->GetModules()->Count();
- for ( sal_uInt16 nMod = 0 ; nMod < nModCount ; nMod++ )
+ for ( const auto& pModule: pBasic->GetModules() )
{
- SbModule* pModule = static_cast<SbModule*>(pBasic->GetModules()->Get( nMod ));
- DBG_ASSERT( pModule, "Module not received!" );
-
OUString aModName = pModule->GetName();
if( !xLib->hasByName( aModName ) )
{
@@ -917,14 +913,10 @@ bool BasicManager::HasExeCode( const OUString& sLib )
StarBASIC* pLib = GetLib(sLib);
if ( pLib )
{
- SbxArray* pMods = pLib->GetModules();
- sal_uInt16 nMods = pMods ? pMods->Count() : 0;
- for( sal_uInt16 i = 0; i < nMods; i++ )
+ for (const auto& pModule: pLib->GetModules())
{
- SbModule* p = static_cast<SbModule*>( pMods->Get( i ) );
- if ( p )
- if ( p->HasExeCode() )
- return true;
+ if (pModule->HasExeCode())
+ return true;
}
}
return false;
@@ -1114,9 +1106,8 @@ void BasicManager::CheckModules( StarBASIC* pLib, bool bReference )
}
bool bModified = pLib->IsModified();
- for ( sal_uInt16 nMod = 0; nMod < pLib->GetModules()->Count(); nMod++ )
+ for ( const auto& pModule: pLib->GetModules() )
{
- SbModule* pModule = static_cast<SbModule*>(pLib->GetModules()->Get( nMod ));
DBG_ASSERT( pModule, "Module not received!" );
if ( !pModule->IsCompiled() && !StarBASIC::GetErrorCode() )
{
@@ -1601,11 +1592,9 @@ namespace
if( pLib )
{
- sal_uInt16 nModCount = pLib->GetModules()->Count();
- for( sal_uInt16 nMod = 0; nMod < nModCount; ++nMod )
+ for ( const auto& pMod: pLib->GetModules() )
{
- SbModule* pMod = static_cast<SbModule*>(pLib->GetModules()->Get( nMod ));
- if ( pMod && rTransliteration.isEqual( pMod->GetName(), sModule ) )
+ if ( rTransliteration.isEqual( pMod->GetName(), sModule ) )
{
SbMethod* pMethod = static_cast<SbMethod*>(pMod->Find( sMacro, SbxCLASS_METHOD ));
if( pMethod )
@@ -1827,8 +1816,7 @@ uno::Type ModuleContainer_Impl::getElementType()
sal_Bool ModuleContainer_Impl::hasElements()
throw(uno::RuntimeException, std::exception)
{
- SbxArray* pMods = mpLib ? mpLib->GetModules() : nullptr;
- return pMods && pMods->Count() > 0;
+ return mpLib && !mpLib->GetModules().empty();
}
// Methods XNameAccess
@@ -1848,14 +1836,12 @@ uno::Any ModuleContainer_Impl::getByName( const OUString& aName )
uno::Sequence< OUString > ModuleContainer_Impl::getElementNames()
throw(uno::RuntimeException, std::exception)
{
- SbxArray* pMods = mpLib ? mpLib->GetModules() : nullptr;
- sal_uInt16 nMods = pMods ? pMods->Count() : 0;
+ sal_uInt16 nMods = mpLib ? mpLib->GetModules().size() : 0;
uno::Sequence< OUString > aRetSeq( nMods );
OUString* pRetSeq = aRetSeq.getArray();
for( sal_uInt16 i = 0 ; i < nMods ; i++ )
{
- SbxVariable* pMod = pMods->Get( i );
- pRetSeq[i] = OUString( pMod->GetName() );
+ pRetSeq[i] = mpLib->GetModules()[i]->GetName();
}
return aRetSeq;
}
diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx
index 41e9ab0c12e2..6b2a78db441e 100644
--- a/basic/source/classes/sb.cxx
+++ b/basic/source/classes/sb.cxx
@@ -924,7 +924,6 @@ StarBASIC::StarBASIC( StarBASIC* p, bool bIsDocBasic )
pLibInfo = nullptr;
bNoRtl = bBreak = false;
bVBAEnabled = false;
- pModules = new SbxArray;
if( !GetSbData()->nInst++ )
{
@@ -1018,10 +1017,9 @@ void StarBASIC::implClearDependingVarsOnDelete( StarBASIC* pDeletedBasic )
{
if( this != pDeletedBasic )
{
- for( sal_uInt16 i = 0; i < pModules->Count(); i++ )
+ for( const auto& pModule: pModules)
{
- SbModule* p = static_cast<SbModule*>(pModules->Get( i ));
- p->ClearVarsDependingOnDeletedBasic( pDeletedBasic );
+ pModule->ClearVarsDependingOnDeletedBasic( pDeletedBasic );
}
}
@@ -1082,7 +1080,7 @@ SbModule* StarBASIC::MakeModule32( const OUString& rName, const ModuleInfo& mInf
}
p->SetSource32( rSrc );
p->SetParent( this );
- pModules->Insert( p, pModules->Count() );
+ pModules.push_back(p);
SetModified( true );
return p;
}
@@ -1091,7 +1089,7 @@ void StarBASIC::Insert( SbxVariable* pVar )
{
if( dynamic_cast<const SbModule*>(pVar) != nullptr)
{
- pModules->Insert( pVar, pModules->Count() );
+ pModules.push_back(static_cast<SbModule*>(pVar));
pVar->SetParent( this );
StartListening( pVar->GetBroadcaster(), true );
}
@@ -1112,7 +1110,7 @@ void StarBASIC::Remove( SbxVariable* pVar )
{
// #87540 Can be last reference!
SbxVariableRef xVar = pVar;
- pModules->Remove( pVar );
+ pModules.erase(std::remove(pModules.begin(), pModules.end(), pVar));
pVar->SetParent( nullptr );
EndListening( pVar->GetBroadcaster() );
}
@@ -1129,20 +1127,16 @@ bool StarBASIC::Compile( SbModule* pMod )
void StarBASIC::Clear()
{
- while( pModules->Count() )
- {
- pModules->Remove( pModules->Count() - 1 );
- }
+ pModules.clear();
}
SbModule* StarBASIC::FindModule( const OUString& rName )
{
- for( sal_uInt16 i = 0; i < pModules->Count(); i++ )
+ for (const auto& pModule: pModules)
{
- SbModule* p = static_cast<SbModule*>( pModules->Get( i ) );
- if( p->GetName().equalsIgnoreAsciiCase( rName ) )
+ if( pModule->GetName().equalsIgnoreAsciiCase( rName ) )
{
- return p;
+ return pModule.get();
}
}
return nullptr;
@@ -1218,13 +1212,9 @@ void StarBASIC::InitAllModules( StarBASIC* pBasicNotToInit )
SolarMutexGuard guard;
// Init own modules
- for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
+ for (const auto& pModule: pModules)
{
- SbModule* pModule = static_cast<SbModule*>( pModules->Get( nMod ) );
- if( !pModule->IsCompiled() )
- {
- pModule->Compile();
- }
+ pModule->Compile();
}
// compile modules first then RunInit ( otherwise there is
// can be order dependency, e.g. classmodule A has a member
@@ -1233,13 +1223,12 @@ void StarBASIC::InitAllModules( StarBASIC* pBasicNotToInit )
// Consider required types to init in right order. Class modules
// that are required by other modules have to be initialized first.
ModuleInitDependencyMap aMIDMap;
- for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
+ for (const auto& pModule: pModules)
{
- SbModule* pModule = static_cast<SbModule*>(pModules->Get( nMod ));
OUString aModuleName = pModule->GetName();
if( pModule->isProxyModule() )
{
- aMIDMap[aModuleName] = ClassModuleRunInitItem( pModule );
+ aMIDMap[aModuleName] = ClassModuleRunInitItem( pModule.get() );
}
}
@@ -1251,9 +1240,8 @@ void StarBASIC::InitAllModules( StarBASIC* pBasicNotToInit )
}
// Call RunInit on standard modules
- for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
+ for (const auto& pModule: pModules)
{
- SbModule* pModule = static_cast<SbModule*>(pModules->Get( nMod ));
if( !pModule->isProxyModule() )
{
pModule->RunInit();
@@ -1278,10 +1266,9 @@ void StarBASIC::InitAllModules( StarBASIC* pBasicNotToInit )
void StarBASIC::DeInitAllModules()
{
// Deinit own modules
- for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
+ for (const auto& pModule: pModules)
{
- SbModule* pModule = static_cast<SbModule*>(pModules->Get( nMod ));
- if( pModule->pImage && !pModule->isProxyModule() && nullptr == dynamic_cast<const SbObjModule*>( pModule) )
+ if( pModule->pImage && !pModule->isProxyModule() && nullptr == dynamic_cast<SbObjModule*>( pModule.get()) )
{
pModule->pImage->bInit = false;
}
@@ -1331,34 +1318,33 @@ SbxVariable* StarBASIC::Find( const OUString& rName, SbxClassType t )
// Search module
if( !pRes )
{
- for( sal_uInt16 i = 0; i < pModules->Count(); i++ )
+ for (const auto& pModule: pModules)
{
- SbModule* p = static_cast<SbModule*>( pModules->Get( i ) );
- if( p->IsVisible() )
+ if( pModule->IsVisible() )
{
// Remember modul fpr Main() call
// or is the name equal?!?
- if( p->GetName().equalsIgnoreAsciiCase( rName ) )
+ if( pModule->GetName().equalsIgnoreAsciiCase( rName ) )
{
if( t == SbxCLASS_OBJECT || t == SbxCLASS_DONTCARE )
{
- pRes = p; break;
+ pRes = pModule.get(); break;
}
- pNamed = p;
+ pNamed = pModule.get();
}
// Only variables qualified by the Module Name e.g. Sheet1.foo
// should work for Document && Class type Modules
- sal_Int32 nType = p->GetModuleType();
+ sal_Int32 nType = pModule->GetModuleType();
if ( nType == ModuleType::DOCUMENT || nType == ModuleType::FORM )
{
continue;
}
// otherwise check if the element is available
// unset GBLSEARCH-Flag (due to Rekursion)
- SbxFlagBits nGblFlag = p->GetFlags() & SbxFlagBits::GlobalSearch;
- p->ResetFlag( SbxFlagBits::GlobalSearch );
- pRes = p->Find( rName, t );
- p->SetFlag( nGblFlag );
+ SbxFlagBits nGblFlag = pModule->GetFlags() & SbxFlagBits::GlobalSearch;
+ pModule->ResetFlag( SbxFlagBits::GlobalSearch );
+ pRes = pModule->Find( rName, t );
+ pModule->SetFlag( nGblFlag );
if( pRes )
{
break;
@@ -1887,7 +1873,7 @@ bool StarBASIC::LoadData( SvStream& r, sal_uInt16 nVer )
ppDeleteTab.reset();
sal_uInt16 nMod(0);
- pModules->Clear();
+ pModules.clear();
r.ReadUInt16( nMod );
const size_t nMinSbxSize(14);
const size_t nMaxPossibleEntries = r.remainingSize() / nMinSbxSize;
@@ -1913,7 +1899,7 @@ bool StarBASIC::LoadData( SvStream& r, sal_uInt16 nVer )
else
{
pMod->SetParent( this );
- pModules->Put( pMod, i );
+ pModules.push_back( pMod );
}
}
// HACK for SFX-Bullshit!
@@ -1940,11 +1926,11 @@ bool StarBASIC::StoreData( SvStream& r ) const
{
return false;
}
- r.WriteUInt16( pModules->Count() );
- for( sal_uInt16 i = 0; i < pModules->Count(); i++ )
+ assert(pModules.size() < SAL_MAX_UINT16);
+ r.WriteUInt16( static_cast<sal_uInt16>(pModules.size()));
+ for( const auto& rpModule: pModules )
{
- SbModule* p = static_cast<SbModule*>( pModules->Get( i ) );
- if( !p->Store( r ) )
+ if( !rpModule->Store( r ) )
{
return false;
}
diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx
index 2834dd23a6b0..c025a9c80a1b 100644
--- a/basic/source/classes/sbxmod.cxx
+++ b/basic/source/classes/sbxmod.cxx
@@ -1400,12 +1400,11 @@ void SbModule::ClearVarsDependingOnDeletedBasic( StarBASIC* pDeletedBasic )
void StarBASIC::ClearAllModuleVars()
{
// Initialise the own module
- for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
+ for (const auto& rModule: pModules)
{
- SbModule* pModule = static_cast<SbModule*>(pModules->Get( nMod ));
// Initialise only, if the startcode was already executed
- if( pModule->pImage && pModule->pImage->bInit && !pModule->isProxyModule() && nullptr == dynamic_cast<const SbObjModule*>( pModule) )
- pModule->ClearPrivateVars();
+ if( rModule->pImage && rModule->pImage->bInit && !rModule->isProxyModule() && nullptr == dynamic_cast<const SbObjModule*>( rModule.get()) )
+ rModule->ClearPrivateVars();
}
}
diff --git a/basic/source/comp/exprnode.cxx b/basic/source/comp/exprnode.cxx
index 9d77f6dba071..19272dc3da6a 100644
--- a/basic/source/comp/exprnode.cxx
+++ b/basic/source/comp/exprnode.cxx
@@ -19,6 +19,7 @@
#include <math.h>
+#include <algorithm>
#include <rtl/math.hxx>
#include "codegen.hxx"
@@ -191,9 +192,7 @@ short SbiExprNode::GetDepth()
if( IsOperand() ) return 0;
else
{
- short d1 = pLeft->GetDepth();
- short d2 = pRight->GetDepth();
- return( (d1 < d2 ) ? d2 : d1 ) + 1;
+ return std::max(pLeft->GetDepth(), pRight->GetDepth()) + 1;
}
}