Make all CBotCStack data members non-static

fix-squashed-planets
melex750 2021-06-11 22:47:33 -04:00
parent 309f80b25f
commit a279541198
10 changed files with 111 additions and 125 deletions

View File

@ -31,107 +31,100 @@
namespace CBot namespace CBot
{ {
//////////////////////////////////////////////////////////////////////////////// struct CBotCStack::Data
CBotProgram* CBotCStack::m_prog = nullptr; // init the static variable {
CBotError CBotCStack::m_error = CBotNoErr; //! The program currently being compiled
int CBotCStack::m_end = 0; CBotProgram* prog = nullptr;
CBotTypResult CBotCStack::m_retTyp = CBotTypResult(0); //! The current error state of the compile stack
CBotError error = CBotNoErr;
int errEnd = 0;
//! The return type of the function currently being compiled
CBotTypResult retTyp = CBotTypResult(CBotTypVoid);
};
////////////////////////////////////////////////////////////////////////////////
CBotCStack::CBotCStack(CBotCStack* ppapa) CBotCStack::CBotCStack(CBotCStack* ppapa)
{ {
m_next = nullptr;
m_prev = ppapa; m_prev = ppapa;
if (ppapa == nullptr) if (ppapa == nullptr)
{ {
m_error = CBotNoErr; m_data = new CBotCStack::Data;
m_start = 0; m_errStart = 0;
m_end = 0;
m_bBlock = true; m_bBlock = true;
} }
else else
{ {
m_start = ppapa->m_start; m_data = ppapa->m_data;
m_errStart = ppapa->m_errStart;
m_bBlock = false; m_bBlock = false;
} }
m_listVar = nullptr;
m_var = nullptr;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotCStack::~CBotCStack() CBotCStack::~CBotCStack()
{ {
if (m_next != nullptr) delete m_next; if (m_prev == nullptr) delete m_data;
if (m_prev != nullptr) m_prev->m_next = nullptr; // removes chain
delete m_var;
delete m_listVar;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotCStack* CBotCStack::TokenStack(CBotToken* pToken, bool bBlock) CBotCStack* CBotCStack::TokenStack(CBotToken* pToken, bool bBlock)
{ {
if (m_next != nullptr) return m_next; // include on an existing stack if (m_next) return m_next.get(); // include on an existing stack
CBotCStack* p = new CBotCStack(this); m_next.reset(new CBotCStack(this));
m_next = p; // channel element m_next->m_bBlock = bBlock;
p->m_bBlock = bBlock;
if (pToken != nullptr) p->SetStartError(pToken->GetStart()); if (pToken != nullptr) m_next->SetStartError(pToken->GetStart());
return p; return m_next.get();
}
void CBotCStack::DeleteNext()
{
m_next.reset();
} }
////////////////////////////////////////////////////////////////////////////////
CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils) CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils)
{ {
if ( pfils == this ) return inst; if ( pfils == this ) return inst;
if (m_var != nullptr) delete m_var; // value replaced? m_var = std::move(pfils->m_var); // result transmitted
m_var = pfils->m_var; // result transmitted
pfils->m_var = nullptr; // not to destroy the variable
if (m_error) if (m_data->error != CBotNoErr)
{ {
m_start = pfils->m_start; // retrieves the position of the error m_errStart = pfils->m_errStart; // retrieves the position of the error
m_end = pfils->m_end;
} }
delete pfils; m_next.reset();
return inst; return inst;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils) CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils)
{ {
if (m_var != nullptr) delete m_var; // value replaced? m_var = std::move(pfils->m_var); // result transmitted
m_var = pfils->m_var; // result transmitted
pfils->m_var = nullptr; // not to destroy the variable
if (m_error) if (m_data->error != CBotNoErr)
{ {
m_start = pfils->m_start; // retrieves the position of the error m_errStart = pfils->m_errStart; // retrieves the position of the error
m_end = pfils->m_end;
} }
delete pfils; m_next.reset();
return inst; return inst;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotError CBotCStack::GetError(int& start, int& end) CBotError CBotCStack::GetError(int& start, int& end)
{ {
start = m_start; start = m_errStart;
end = m_end; end = m_data->errEnd;
return m_error; return m_data->error;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotError CBotCStack::GetError() CBotError CBotCStack::GetError()
{ {
return m_error; return m_data->error;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -171,18 +164,13 @@ void CBotCStack::SetType(CBotTypResult& type)
CBotVar* CBotCStack::FindVar(CBotToken* &pToken) CBotVar* CBotCStack::FindVar(CBotToken* &pToken)
{ {
CBotCStack* p = this; CBotCStack* p = this;
std::string name = pToken->GetString(); const auto& name = pToken->GetString();
while (p != nullptr) while (p != nullptr)
{ {
CBotVar* pp = p->m_listVar; if (p->m_bBlock) for (auto& var : p->m_listVar)
while ( pp != nullptr)
{ {
if (name == pp->GetName()) if (name == var->GetName()) return var.get();
{
return pp;
}
pp = pp->m_next;
} }
p = p->m_prev; p = p->m_prev;
} }
@ -211,39 +199,39 @@ CBotVar* CBotCStack::CopyVar(CBotToken& Token)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotCStack::IsOk() bool CBotCStack::IsOk()
{ {
return (m_error == 0); return (m_data->error == CBotNoErr);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotCStack::SetStartError( int pos ) void CBotCStack::SetStartError( int pos )
{ {
if ( m_error != 0) return; // does not change existing error if (m_data->error != CBotNoErr) return; // does not change existing error
m_start = pos; m_errStart = pos;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotCStack::SetError(CBotError n, int pos) void CBotCStack::SetError(CBotError n, int pos)
{ {
if ( n!= 0 && m_error != 0) return; // does not change existing error if (n != CBotNoErr && m_data->error != CBotNoErr) return; // does not change existing error
m_error = n; m_data->error = n;
m_end = pos; m_data->errEnd = pos;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotCStack::SetError(CBotError n, CBotToken* p) void CBotCStack::SetError(CBotError n, CBotToken* p)
{ {
if (m_error) return; // does not change existing error if (m_data->error != CBotNoErr) return; // does not change existing error
m_error = n; m_data->error = n;
m_start = p->GetStart(); m_errStart = p->GetStart();
m_end = p->GetEnd(); m_data->errEnd = p->GetEnd();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotCStack::ResetError(CBotError n, int start, int end) void CBotCStack::ResetError(CBotError n, int start, int end)
{ {
m_error = n; m_data->error = n;
m_start = start; m_errStart = start;
m_end = end; m_data->errEnd = end;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -261,48 +249,47 @@ bool CBotCStack::NextToken(CBotToken* &p)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotCStack::SetProgram(CBotProgram* p) void CBotCStack::SetProgram(CBotProgram* p)
{ {
m_prog = p; m_data->prog = p;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotProgram* CBotCStack::GetProgram() CBotProgram* CBotCStack::GetProgram()
{ {
return m_prog; return m_data->prog;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotCStack::SetRetType(CBotTypResult& type) void CBotCStack::SetRetType(CBotTypResult& type)
{ {
m_retTyp = type; m_data->retTyp = type;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotTypResult CBotCStack::GetRetType() CBotTypResult CBotCStack::GetRetType()
{ {
return m_retTyp; return m_data->retTyp;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotCStack::SetVar( CBotVar* var ) void CBotCStack::SetVar( CBotVar* var )
{ {
if (m_var) delete m_var; // replacement of a variable m_var.reset(var);
m_var = var;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotCStack::SetCopyVar( CBotVar* var ) void CBotCStack::SetCopyVar( CBotVar* var )
{ {
if (m_var) delete m_var; // replacement of a variable m_var.reset();
if ( var == nullptr ) return; if ( var == nullptr ) return;
m_var = CBotVar::Create("", var->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC)); m_var.reset(CBotVar::Create("", var->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC)));
m_var->Copy( var ); m_var->Copy( var );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotCStack::GetVar() CBotVar* CBotCStack::GetVar()
{ {
return m_var; return m_var.get();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -310,15 +297,12 @@ void CBotCStack::AddVar(CBotVar* pVar)
{ {
CBotCStack* p = this; CBotCStack* p = this;
// returns to the father element // find the level of the current block
while (p != nullptr && p->m_bBlock == 0) p = p->m_prev; while (p != nullptr && p->m_bBlock == 0) p = p->m_prev;
if ( p == nullptr ) return; if (p == nullptr || pVar == nullptr) return;
CBotVar** pp = &p->m_listVar; p->m_listVar.emplace_back(pVar);
while ( *pp != nullptr ) pp = &(*pp)->m_next;
*pp = pVar; // added after
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -369,19 +353,14 @@ void CBotCStack::CreateMemberVars(CBotClass* pClass, bool setDefined)
bool CBotCStack::CheckVarLocal(CBotToken* &pToken) bool CBotCStack::CheckVarLocal(CBotToken* &pToken)
{ {
CBotCStack* p = this; CBotCStack* p = this;
std::string name = pToken->GetString(); const auto& name = pToken->GetString();
while (p != nullptr) // find the level of the current block
while (p != nullptr && p->m_bBlock == 0) p = p->m_prev;
if (p != nullptr) for (auto& var : p->m_listVar)
{ {
CBotVar* pp = p->m_listVar; if (name == var->GetName()) return true;
while ( pp != nullptr)
{
if (name == pp->GetName())
return true;
pp = pp->m_next;
}
if ( p->m_bBlock ) return false;
p = p->m_prev;
} }
return false; return false;
} }
@ -392,10 +371,10 @@ CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nId
nIdent = 0; nIdent = 0;
CBotTypResult val(-1); CBotTypResult val(-1);
val = m_prog->GetExternalCalls()->CompileCall(p, nullptr, ppVars, this); val = GetProgram()->GetExternalCalls()->CompileCall(p, nullptr, ppVars, this);
if (val.GetType() < 0) if (val.GetType() < 0)
{ {
val = CBotFunction::CompileCall(p->GetString(), ppVars, nIdent, m_prog); val = CBotFunction::CompileCall(p->GetString(), ppVars, nIdent, GetProgram());
if ( val.GetType() < 0 ) if ( val.GetType() < 0 )
{ {
// pVar = nullptr; // the error is not on a particular parameter // pVar = nullptr; // the error is not on a particular parameter
@ -410,13 +389,13 @@ CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nId
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam, const std::string& className) bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam, const std::string& className)
{ {
std::string name = pToken->GetString(); const auto& name = pToken->GetString();
if ( m_prog->GetExternalCalls()->CheckCall(name) ) return true; if ( GetProgram()->GetExternalCalls()->CheckCall(name) ) return true;
for (CBotFunction* pp : m_prog->GetFunctions()) for (CBotFunction* pp : GetProgram()->GetFunctions())
{ {
if ( pToken->GetString() == pp->GetName() ) if ( name == pp->GetName() )
{ {
// ignore methods for a different class // ignore methods for a different class
if ( className != pp->GetClassName() ) if ( className != pp->GetClassName() )
@ -429,7 +408,7 @@ bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam, const std::
for (CBotFunction* pp : CBotFunction::m_publicFunctions) for (CBotFunction* pp : CBotFunction::m_publicFunctions)
{ {
if ( pToken->GetString() == pp->GetName() ) if ( name == pp->GetName() )
{ {
// ignore methods for a different class // ignore methods for a different class
if ( className != pp->GetClassName() ) if ( className != pp->GetClassName() )
@ -443,4 +422,4 @@ bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam, const std::
return false; return false;
} }
} } // namespace CBot

View File

@ -22,6 +22,9 @@
#include "CBot/CBotVar/CBotVar.h" #include "CBot/CBotVar/CBotVar.h"
#include "CBot/CBotProgram.h" #include "CBot/CBotProgram.h"
#include <list>
#include <memory>
namespace CBot namespace CBot
{ {
@ -157,6 +160,11 @@ public:
*/ */
CBotCStack* TokenStack(CBotToken* pToken = nullptr, bool bBlock = false); CBotCStack* TokenStack(CBotToken* pToken = nullptr, bool bBlock = false);
/*!
* \brief Deletes all subsequent stack frames created by TokenStack.
*/
void DeleteNext();
/*! /*!
* \brief Return Transmits the result upper. * \brief Return Transmits the result upper.
* \param p * \param p
@ -269,21 +277,20 @@ public:
bool NextToken(CBotToken* &p); bool NextToken(CBotToken* &p);
private: private:
CBotCStack* m_next; std::unique_ptr<CBotCStack> m_next;
CBotCStack* m_prev; CBotCStack* m_prev;
static CBotError m_error; int m_errStart = 0;
static int m_end;
int m_start; struct Data;
CBotCStack::Data* m_data;
//! Result of the operations. //! Result of the operations.
CBotVar* m_var; std::unique_ptr<CBotVar> m_var;
//! Is part of a block (variables are local to this block). //! Is part of a block (variables are local to this block).
bool m_bBlock; bool m_bBlock;
CBotVar* m_listVar; std::list<std::unique_ptr<CBotVar>> m_listVar;
//! List of compiled functions.
static CBotProgram* m_prog;
static CBotTypResult m_retTyp;
}; };
} // namespace CBot } // namespace CBot

View File

@ -605,8 +605,8 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
// return a method precompiled in pass 1 // return a method precompiled in pass 1
CBotCStack* pStk = pStack->TokenStack(nullptr, true); CBotCStack* pStk = pStack->TokenStack(nullptr, true);
CBotDefParam* params = CBotDefParam::Compile(p, pStk ); CBotDefParam* params = CBotDefParam::Compile(p, pStk );
delete pStk; pStack->DeleteNext();
std::list<CBotFunction*>::iterator pfIter = std::find_if(m_pMethod.begin(), m_pMethod.end(), [&pp, &params](CBotFunction* x) auto pfIter = std::find_if(m_pMethod.begin(), m_pMethod.end(), [&pp, &params](CBotFunction* x)
{ {
return x->GetName() == pp && x->CheckParam( params ); return x->GetName() == pp && x->CheckParam( params );
}); });
@ -626,7 +626,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
f->m_pProg = pStack->GetProgram(); f->m_pProg = pStack->GetProgram();
f->m_bSynchro = bSynchro; f->m_bSynchro = bSynchro;
} }
pStack->Return(nullptr, pile); pStack->DeleteNext();
} }
return pStack->IsOk(); return pStack->IsOk();

View File

@ -94,7 +94,7 @@ CBotDefParam* CBotDefParam::Compile(CBotToken* &p, CBotCStack* pStack)
prevHasDefault = true; prevHasDefault = true;
} }
else pStack->SetError(CBotErrNoExpression, p); else pStack->SetError(CBotErrNoExpression, p);
delete pStk; pStack->DeleteNext();
} }
else else
if (prevHasDefault) pStack->SetError(CBotErrDefaultValue, p->GetPrev()); if (prevHasDefault) pStack->SetError(CBotErrDefaultValue, p->GetPrev());

View File

@ -135,7 +135,7 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
// the constructor is there? // the constructor is there?
// std::string noname; // std::string noname;
CBotTypResult r = pClass->CompileMethode(&token, var, ppVars, pStk, inst->m_nMethodeIdent); CBotTypResult r = pClass->CompileMethode(&token, var, ppVars, pStk, inst->m_nMethodeIdent);
delete pStk->TokenStack(); // releases the supplement stack pStk->DeleteNext(); // releases the supplement stack
int typ = r.GetType(); int typ = r.GetType();
if (typ == CBotErrUndefCall) if (typ == CBotErrUndefCall)
@ -160,7 +160,7 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
if (nullptr != (inst->m_exprRetVar = CBotExprRetVar::Compile(p, pStk, true))) if (nullptr != (inst->m_exprRetVar = CBotExprRetVar::Compile(p, pStk, true)))
{ {
inst->m_exprRetVar->SetToken(vartoken); inst->m_exprRetVar->SetToken(vartoken);
delete pStk->TokenStack(); pStk->DeleteNext();
} }
pStk->SetVar(nullptr); pStk->SetVar(nullptr);

View File

@ -78,12 +78,12 @@ CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack)
{ {
// if (pVar2!=nullptr) pp = pVar2->RetToken(); // if (pVar2!=nullptr) pp = pVar2->RetToken();
pStack->SetError( static_cast<CBotError>(inst->m_typRes.GetType()), pp ); pStack->SetError( static_cast<CBotError>(inst->m_typRes.GetType()), pp );
delete pStack->TokenStack(); pStack->DeleteNext();
delete inst; delete inst;
return nullptr; return nullptr;
} }
delete pStack->TokenStack(); pStack->DeleteNext();
if ( inst->m_typRes.GetType() > 0 ) if ( inst->m_typRes.GetType() > 0 )
{ {
CBotVar* pRes = CBotVar::Create("", inst->m_typRes); CBotVar* pRes = CBotVar::Create("", inst->m_typRes);
@ -94,7 +94,7 @@ CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack)
if (nullptr != (inst->m_exprRetVar = CBotExprRetVar::Compile(p, pStack))) if (nullptr != (inst->m_exprRetVar = CBotExprRetVar::Compile(p, pStack)))
{ {
inst->m_exprRetVar->SetToken(&inst->m_token); inst->m_exprRetVar->SetToken(&inst->m_token);
delete pStack->TokenStack(); pStack->DeleteNext();
} }
if ( !pStack->IsOk() ) if ( !pStack->IsOk() )
{ {
@ -105,7 +105,7 @@ CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack)
return inst; return inst;
} }
p = pp; p = pp;
delete pStack->TokenStack(); pStack->DeleteNext();
return nullptr; return nullptr;
} }

View File

@ -70,7 +70,7 @@ CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar*
CBotClass* pClass = var->GetClass(); // pointer to the class CBotClass* pClass = var->GetClass(); // pointer to the class
inst->m_className = pClass->GetName(); // name of the class inst->m_className = pClass->GetName(); // name of the class
CBotTypResult r = pClass->CompileMethode(pp, var, ppVars, pStack, inst->m_MethodeIdent); CBotTypResult r = pClass->CompileMethode(pp, var, ppVars, pStack, inst->m_MethodeIdent);
delete pStack->TokenStack(); // release parameters on the stack pStack->DeleteNext(); // release parameters on the stack
inst->m_typRes = r; inst->m_typRes = r;
if (inst->m_typRes.GetType() > 20) if (inst->m_typRes.GetType() > 20)
@ -95,7 +95,7 @@ CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar*
if (nullptr != (inst->m_exprRetVar = CBotExprRetVar::Compile(p, pStack, bMethodChain))) if (nullptr != (inst->m_exprRetVar = CBotExprRetVar::Compile(p, pStack, bMethodChain)))
{ {
inst->m_exprRetVar->SetToken(pp); inst->m_exprRetVar->SetToken(pp);
delete pStack->TokenStack(); pStack->DeleteNext();
} }
if ( pStack->IsOk() ) if ( pStack->IsOk() )

View File

@ -65,7 +65,7 @@ CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars)
{ {
if (pile->GetTypResult().Eq(99)) if (pile->GetTypResult().Eq(99))
{ {
delete pStack->TokenStack(); pStack->DeleteNext();
pStack->SetError(CBotErrVoid, p->GetStart()); pStack->SetError(CBotErrVoid, p->GetStart());
return nullptr; return nullptr;
} }
@ -78,7 +78,7 @@ CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars)
} }
pStack->SetError(CBotErrClosePar, p->GetStart()); pStack->SetError(CBotErrClosePar, p->GetStart());
delete pStack->TokenStack(); pStack->DeleteNext();
return nullptr; return nullptr;
} }
} }

View File

@ -87,7 +87,7 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack)
// constructor exist? // constructor exist?
CBotTypResult r = pClass->CompileMethode(&inst->m_vartoken, pVar, ppVars, pStk, inst->m_nMethodeIdent); CBotTypResult r = pClass->CompileMethode(&inst->m_vartoken, pVar, ppVars, pStk, inst->m_nMethodeIdent);
delete pStk->TokenStack(); // release extra stack pStk->DeleteNext(); // release extra stack
int typ = r.GetType(); int typ = r.GetType();
// if there is no constructor, and no parameters either, it's ok // if there is no constructor, and no parameters either, it's ok
@ -115,7 +115,7 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack)
if (nullptr != (inst->m_exprRetVar = CBotExprRetVar::Compile(p, pStk, true))) if (nullptr != (inst->m_exprRetVar = CBotExprRetVar::Compile(p, pStk, true)))
{ {
inst->m_exprRetVar->SetToken(pp); inst->m_exprRetVar->SetToken(pp);
delete pStk->TokenStack(); pStk->DeleteNext();
} }
if (pStack->IsOk()) if (pStack->IsOk())

View File

@ -71,7 +71,7 @@ CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack)
{ {
if ( p->GetType() == ID_CASE || p->GetType() == ID_DEFAULT) if ( p->GetType() == ID_CASE || p->GetType() == ID_DEFAULT)
{ {
delete pStk2; pStk->DeleteNext();
pStk2 = pStk->TokenStack(p, true); // some space for a stack, plz pStk2 = pStk->TokenStack(p, true); // some space for a stack, plz
caseInst = static_cast<CBotCase*>(CBotCase::Compile(p, pStk2, inst->m_labels)); caseInst = static_cast<CBotCase*>(CBotCase::Compile(p, pStk2, inst->m_labels));