diff options
author | Arnaud Versini <arnaud.versini@gmail.com> | 2016-04-03 16:03:35 +0200 |
---|---|---|
committer | Arnaud Versini <arnaud.versini@libreoffice.org> | 2016-04-03 17:34:04 +0000 |
commit | 917e3656e920caed61f0ecfc156cd2f8e470087e (patch) | |
tree | d3ab2c1bb987e1684db79f761751da4f3f58c1d0 /basic | |
parent | 9b0069c2833313ba9fab91f45edd354ba334f94b (diff) |
BASIC : Use a vector to store the go sub stack.
Change-Id: I80987f3f7c036279a8292a7fbbd2dcd232196226
Reviewed-on: https://gerrit.libreoffice.org/23753
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Arnaud Versini <arnaud.versini@libreoffice.org>
Diffstat (limited to 'basic')
-rw-r--r-- | basic/source/inc/runtime.hxx | 13 | ||||
-rw-r--r-- | basic/source/runtime/runtime.cxx | 48 |
2 files changed, 21 insertions, 40 deletions
diff --git a/basic/source/inc/runtime.hxx b/basic/source/inc/runtime.hxx index ed4cf423558e..6d1a8a01f577 100644 --- a/basic/source/inc/runtime.hxx +++ b/basic/source/inc/runtime.hxx @@ -41,7 +41,7 @@ class SbiInstance; // active StarBASIC process class SbiRuntime; // active StarBASIC procedure instance struct SbiArgvStack; // Argv stack element -struct SbiGosubStack; // GOSUB stack element +struct SbiGosub; // GOSUB stack element class SbiImage; // Code-Image class SbiIoSystem; class SbiDdeControl; @@ -89,12 +89,6 @@ struct SbiForStack { // for/next stack: #define MAXRECURSION 500 -struct SbiGosubStack { // GOSUB-Stack: - SbiGosubStack* pNext; // Chain - const sal_uInt8* pCode; // Return-Pointer - sal_uInt16 nStartForLvl; // #118235: For Level in moment of gosub -}; - enum class SbAttributes { NONE = 0x0000, READONLY = 0x0001, @@ -237,10 +231,8 @@ class SbiRuntime SbxVariableRef xDummyVar; // substitute for variables that weren't found SbxVariable* mpExtCaller; // Caller ( external - e.g. button name, shape, range object etc. - only in vba mode ) SbiArgvStack* pArgvStk; // ARGV-Stack - SbiGosubStack* pGosubStk; // GOSUB stack SbiForStack* pForStk; // FOR/NEXT-Stack sal_uInt16 nExprLvl; // depth of the expr-stack - sal_uInt16 nGosubLvl; // to prevent dead-recursions sal_uInt16 nForLvl; // #118235: Maintain for level const sal_uInt8* pCode; // current Code-Pointer const sal_uInt8* pStmnt; // beginning of the last statement @@ -265,6 +257,8 @@ class SbiRuntime sal_uInt32 m_nLastTime; std::vector<SbxVariableRef> aRefSaved; // #74254 save temporary references + std::vector<SbiGosub> pGosubStk; // GOSUB stack + SbxVariable* FindElement ( SbxObject* pObj, sal_uInt32 nOp1, sal_uInt32 nOp2, SbError, bool bLocal, bool bStatic = false ); @@ -279,7 +273,6 @@ class SbiRuntime void PushGosub( const sal_uInt8* ); void PopGosub(); - void ClearGosubStack(); void PushArgv(); void PopArgv(); diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx index 412f5693f3a8..80815fe279e9 100644 --- a/basic/source/runtime/runtime.cxx +++ b/basic/source/runtime/runtime.cxx @@ -111,13 +111,23 @@ bool StarBASIC::isVBAEnabled() return false; } - struct SbiArgvStack { // Argv stack: SbiArgvStack* pNext; // Stack Chain SbxArrayRef refArgv; // Argv short nArgc; // Argc }; +#define MAXRECURSION 500 //to prevent dead-recursions + +struct SbiGosub { // GOSUB-Stack: + const sal_uInt8* pCode; // Return-Pointer + sal_uInt16 nStartForLvl; // #118235: For Level in moment of gosub + + SbiGosub(const sal_uInt8* pCode_, sal_uInt16 nStartForLvl_) : + pCode(pCode_), + nStartForLvl(nStartForLvl_) {} +}; + SbiRuntime::pStep0 SbiRuntime::aStep0[] = { // all opcodes without operands &SbiRuntime::StepNOP, &SbiRuntime::StepEXP, @@ -568,7 +578,6 @@ SbiRuntime::SbiRuntime( SbModule* pm, SbMethod* pe, sal_uInt32 nStart ) nFlags = pe ? pe->GetDebugFlags() : 0; pIosys = pInst->GetIoSystem(); pArgvStk = nullptr; - pGosubStk = nullptr; pForStk = nullptr; pError = nullptr; pErrCode = @@ -587,7 +596,6 @@ SbiRuntime::SbiRuntime( SbModule* pm, SbMethod* pe, sal_uInt32 nStart ) nExprLvl = 0; nArgc = 0; nError = 0; - nGosubLvl = 0; nForLvl = 0; nOps = 0; refExprStk = new SbxArray; @@ -597,7 +605,6 @@ SbiRuntime::SbiRuntime( SbModule* pm, SbMethod* pe, sal_uInt32 nStart ) SbiRuntime::~SbiRuntime() { - ClearGosubStack(); ClearArgvStack(); ClearForStack(); } @@ -1049,43 +1056,24 @@ void SbiRuntime::TOSMakeTemp() // the GOSUB-stack collects return-addresses for GOSUBs void SbiRuntime::PushGosub( const sal_uInt8* pc ) { - if( ++nGosubLvl > MAXRECURSION ) + if( pGosubStk.size() >= MAXRECURSION ) { StarBASIC::FatalError( ERRCODE_BASIC_STACK_OVERFLOW ); } - SbiGosubStack* p = new SbiGosubStack; - p->pCode = pc; - p->pNext = pGosubStk; - p->nStartForLvl = nForLvl; - pGosubStk = p; + pGosubStk.emplace_back(pc, nForLvl); } void SbiRuntime::PopGosub() { - if( !pGosubStk ) + if( pGosubStk.empty() ) { Error( ERRCODE_BASIC_NO_GOSUB ); } else { - SbiGosubStack* p = pGosubStk; - pCode = p->pCode; - pGosubStk = p->pNext; - delete p; - nGosubLvl--; - } -} - - -void SbiRuntime::ClearGosubStack() -{ - SbiGosubStack* p; - while(( p = pGosubStk ) != nullptr ) - { - pGosubStk = p->pNext; - delete p; + pCode = pGosubStk.back().pCode; + pGosubStk.pop_back(); } - nGosubLvl = 0; } // the Argv-stack collects current argument-vectors @@ -4237,9 +4225,9 @@ void SbiRuntime::StepSTMNT( sal_uInt32 nOp1, sal_uInt32 nOp2 ) { // (there's a difference here in case of a jump out of a loop) sal_uInt16 nExspectedForLevel = static_cast<sal_uInt16>( nOp2 / 0x100 ); - if( pGosubStk ) + if( !pGosubStk.empty() ) { - nExspectedForLevel = nExspectedForLevel + pGosubStk->nStartForLvl; + nExspectedForLevel = nExspectedForLevel + pGosubStk.back().nStartForLvl; } // if the actual for-level is too small it'd jump out |