[Libreoffice-commits] core.git: basic/source
Arnaud Versini
arnaud.versini at gmail.com
Sun Apr 3 17:34:27 UTC 2016
basic/source/inc/runtime.hxx | 13 ++--------
basic/source/runtime/runtime.cxx | 48 ++++++++++++++-------------------------
2 files changed, 21 insertions(+), 40 deletions(-)
New commits:
commit 917e3656e920caed61f0ecfc156cd2f8e470087e
Author: Arnaud Versini <arnaud.versini at gmail.com>
Date: Sun Apr 3 16:03:35 2016 +0200
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 at gmail.com>
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Arnaud Versini <arnaud.versini at libreoffice.org>
diff --git a/basic/source/inc/runtime.hxx b/basic/source/inc/runtime.hxx
index ed4cf42..6d1a8a0 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 412f569..80815fe 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
More information about the Libreoffice-commits
mailing list