CBot: change more things to unique_ptr
parent
0427924301
commit
1c93f04719
|
@ -214,6 +214,14 @@ public:
|
|||
*/
|
||||
CBotFunction* ReturnFunc(CBotFunction* p, CBotCStack* pChild);
|
||||
|
||||
// TODO remove me?
|
||||
template<class T>
|
||||
T Return(T p, CBotCStack *pChild)
|
||||
{
|
||||
Return(static_cast<CBotInstr*>(nullptr), pChild);
|
||||
return p;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets m_vartype.
|
||||
*
|
||||
|
|
|
@ -38,6 +38,8 @@
|
|||
#include "CBot/CBotUtils.h"
|
||||
#include "CBot/CBotFileUtils.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace CBot
|
||||
|
@ -168,7 +170,7 @@ bool CBotClass::AddItem(std::string name,
|
|||
if ( type.Eq(CBotTypClass) )
|
||||
{
|
||||
// adds a new statement for the object initialization
|
||||
pVar->m_InitExpr = new CBotNew() ;
|
||||
pVar->m_InitExpr = MakeUnique<CBotNew>();
|
||||
CBotToken nom( pClass->GetName() );
|
||||
pVar->m_InitExpr->SetToken(&nom);
|
||||
}
|
||||
|
@ -673,10 +675,10 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
|
|||
return false;
|
||||
}
|
||||
|
||||
CBotInstr* limites = nullptr;
|
||||
std::unique_ptr<CBotInstr> limites = nullptr;
|
||||
while ( IsOfType( p, ID_OPBRK ) ) // an array
|
||||
{
|
||||
CBotInstr* i = nullptr;
|
||||
std::unique_ptr<CBotInstr> i;
|
||||
pStack->SetStartError( p->GetStart() );
|
||||
if ( p->GetType() != ID_CLBRK )
|
||||
{
|
||||
|
@ -687,20 +689,20 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
|
|||
}
|
||||
}
|
||||
else
|
||||
i = new CBotEmpty(); // special if not a formula
|
||||
i = MakeUnique<CBotEmpty>(); // special if not a formula
|
||||
|
||||
type2 = CBotTypResult(CBotTypArrayPointer, type2);
|
||||
|
||||
if (limites == nullptr) limites = i;
|
||||
else limites->AddNext3(i);
|
||||
if (limites == nullptr) limites = move(i);
|
||||
else limites->AddNext3(move(i));
|
||||
// TODO: limites should actually be a vector
|
||||
|
||||
if (pStack->IsOk() && IsOfType(p, ID_CLBRK)) continue;
|
||||
pStack->SetError(CBotErrCloseIndex, p->GetStart());
|
||||
delete limites;
|
||||
return false;
|
||||
}
|
||||
|
||||
CBotInstr* i = nullptr;
|
||||
std::unique_ptr<CBotInstr> i = nullptr;
|
||||
if ( IsOfType(p, ID_ASS ) )
|
||||
{
|
||||
pStack->SetStartError(p->GetStart());
|
||||
|
@ -738,7 +740,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
|
|||
}
|
||||
if ( !pStack->IsOk() ) return false;
|
||||
}
|
||||
else if ( type2.Eq(CBotTypArrayPointer) ) i = new CBotExprLitNull();
|
||||
else if ( type2.Eq(CBotTypArrayPointer) ) i = MakeUnique<CBotExprLitNull>();
|
||||
|
||||
|
||||
if ( !bSecond )
|
||||
|
@ -749,8 +751,8 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
|
|||
|
||||
AddItem( pv );
|
||||
|
||||
pv->m_InitExpr = i;
|
||||
pv->m_LimExpr = limites;
|
||||
pv->m_InitExpr = move(i);
|
||||
pv->m_LimExpr = move(limites);
|
||||
|
||||
|
||||
if ( pv->IsStatic() && pv->m_InitExpr != nullptr )
|
||||
|
@ -768,11 +770,6 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
|
|||
pile->Delete();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete i;
|
||||
delete limites;
|
||||
}
|
||||
|
||||
if ( IsOfType(p, ID_COMMA) ) continue;
|
||||
if ( IsOfType(p, ID_SEP) ) break;
|
||||
|
|
|
@ -41,7 +41,6 @@ CBotDefParam::CBotDefParam()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotDefParam::~CBotDefParam()
|
||||
{
|
||||
delete m_expr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -103,7 +103,7 @@ private:
|
|||
CBotTypResult m_type;
|
||||
|
||||
//! Default value expression for the parameter.
|
||||
CBotInstr* m_expr;
|
||||
std::unique_ptr<CBotInstr> m_expr;
|
||||
};
|
||||
|
||||
} // namespace CBot
|
||||
|
|
|
@ -28,13 +28,13 @@ namespace CBot
|
|||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotBlock::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal)
|
||||
std::unique_ptr<CBotInstr> CBotBlock::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal)
|
||||
{
|
||||
pStack->SetStartError(p->GetStart());
|
||||
|
||||
if (IsOfType(p, ID_OPBLK))
|
||||
{
|
||||
CBotInstr* inst = CBotListInstr::Compile(p, pStack, bLocal);
|
||||
std::unique_ptr<CBotInstr> inst = CBotListInstr::Compile(p, pStack, bLocal);
|
||||
|
||||
if (IsOfType(p, ID_CLBLK))
|
||||
{
|
||||
|
@ -42,7 +42,6 @@ CBotInstr* CBotBlock::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal)
|
|||
}
|
||||
|
||||
pStack->SetError(CBotErrCloseBlock, p->GetStart()); // missing parenthesis
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -51,7 +50,7 @@ CBotInstr* CBotBlock::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotBlock::CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal)
|
||||
std::unique_ptr<CBotInstr> CBotBlock::CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal)
|
||||
{
|
||||
// is this a new block
|
||||
if (p->GetType() == ID_OPBLK) return CBotBlock::Compile(p, pStack);
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
* \param bLocal
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true);
|
||||
|
||||
/**
|
||||
* \brief Compiles a block of instructions or a single instruction
|
||||
|
@ -51,7 +51,7 @@ public:
|
|||
* \param bLocal
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal = false);
|
||||
static std::unique_ptr<CBotInstr> CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal = false);
|
||||
|
||||
private:
|
||||
CBotBlock() = delete;
|
||||
|
|
|
@ -28,11 +28,11 @@ namespace CBot
|
|||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotBoolExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotBoolExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
pStack->SetStartError(p->GetStart());
|
||||
|
||||
CBotInstr* inst = CBotTwoOpExpr::Compile(p, pStack);
|
||||
std::unique_ptr<CBotInstr> inst = CBotTwoOpExpr::Compile(p, pStack);
|
||||
|
||||
if (nullptr != inst)
|
||||
{
|
||||
|
@ -43,7 +43,6 @@ CBotInstr* CBotBoolExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
pStack->SetError(CBotErrNotBoolean, p->GetStart()); // is not a boolean
|
||||
}
|
||||
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
private:
|
||||
CBotBoolExpr() = delete;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "CBot/CBotStack.h"
|
||||
#include "CBot/CBotCStack.h"
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
@ -36,7 +37,7 @@ CBotBreak::~CBotBreak()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotBreak::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotBreak::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotToken* pp = p; // preserves at the ^ token (starting position)
|
||||
int type = p->GetType();
|
||||
|
@ -49,7 +50,7 @@ CBotInstr* CBotBreak::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
return nullptr; // no object, the error is on the stack
|
||||
}
|
||||
|
||||
CBotBreak* inst = new CBotBreak(); // creates the object
|
||||
std::unique_ptr<CBotBreak> inst = MakeUnique<CBotBreak>(); // creates the object
|
||||
inst->SetToken(pp); // keeps the operation
|
||||
|
||||
pp = p;
|
||||
|
@ -58,7 +59,6 @@ CBotInstr* CBotBreak::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
inst->m_label = pp->GetString(); // register the name of label
|
||||
if ( !pStack->CheckLoop(inst->m_label, type ) )
|
||||
{
|
||||
delete inst;
|
||||
pStack->SetError(CBotErrUndefLabel, pp);
|
||||
return nullptr; // no object, the error is on the stack
|
||||
}
|
||||
|
@ -68,7 +68,6 @@ CBotInstr* CBotBreak::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
{
|
||||
return inst; // return what it wants
|
||||
}
|
||||
delete inst;
|
||||
|
||||
pStack->SetError(CBotErrNoTerminator, p->GetStart());
|
||||
return nullptr; // no object, the error is on the stack
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute Execution of statement "break" or "continu"
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include "CBot/CBotStack.h"
|
||||
#include "CBot/CBotCStack.h"
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
@ -36,13 +37,12 @@ CBotCase::CBotCase()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotCase::~CBotCase()
|
||||
{
|
||||
delete m_value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotCase::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotCase::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotCase* inst = new CBotCase(); // creates the object
|
||||
std::unique_ptr<CBotCase> inst = MakeUnique<CBotCase>(); // creates the object
|
||||
CBotToken* pp = p; // preserves at the ^ token (starting position)
|
||||
|
||||
inst->SetToken(p);
|
||||
|
@ -55,14 +55,12 @@ CBotInstr* CBotCase::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
if (inst->m_value == nullptr )
|
||||
{
|
||||
pStack->SetError( CBotErrBadNum, pp );
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
if ( !IsOfType( p, ID_DOTS ))
|
||||
{
|
||||
pStack->SetError( CBotErrNoDoubleDots, p->GetStart() );
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -92,7 +90,7 @@ bool CBotCase::CompCase(CBotStack* &pile, int val)
|
|||
std::map<std::string, CBotInstr*> CBotCase::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_value"] = m_value;
|
||||
links["m_value"] = m_value.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute Execution of instruction "case".
|
||||
|
@ -73,7 +73,7 @@ protected:
|
|||
|
||||
private:
|
||||
//! Value to compare.
|
||||
CBotInstr* m_value;
|
||||
std::unique_ptr<CBotInstr> m_value;
|
||||
};
|
||||
|
||||
} // namespace CBot
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "CBot/CBotCStack.h"
|
||||
|
||||
#include "CBot/CBotVar/CBotVar.h"
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
@ -40,15 +41,12 @@ CBotCatch::CBotCatch()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotCatch::~CBotCatch()
|
||||
{
|
||||
delete m_cond; // frees the list
|
||||
delete m_block; // frees the instruction block
|
||||
delete m_next; // and subsequent
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotCatch* CBotCatch::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotCatch> CBotCatch::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotCatch* inst = new CBotCatch(); // creates the object
|
||||
std::unique_ptr<CBotCatch> inst = MakeUnique<CBotCatch>(); // creates the object
|
||||
pStack->SetStartError(p->GetStart());
|
||||
|
||||
inst->SetToken(p);
|
||||
|
@ -68,11 +66,12 @@ CBotCatch* CBotCatch::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
return inst; // return an object to the application
|
||||
}
|
||||
pStack->SetError(CBotErrClosePar, p->GetStart());
|
||||
// TODO does this return the right error message?
|
||||
}
|
||||
pStack->SetError(CBotErrBadType1, p->GetStart());
|
||||
// TODO does this return the right error message?
|
||||
}
|
||||
pStack->SetError(CBotErrOpenPar, p->GetStart());
|
||||
delete inst; // error, frees up
|
||||
return nullptr; // no object, the error is on the stack
|
||||
}
|
||||
|
||||
|
@ -113,9 +112,9 @@ bool CBotCatch :: TestCatch(CBotStack* &pile, int val)
|
|||
std::map<std::string, CBotInstr*> CBotCatch::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_block"] = m_block;
|
||||
links["m_cond"] = m_cond;
|
||||
links["m_next"] = m_next;
|
||||
links["m_block"] = m_block.get();
|
||||
links["m_cond"] = m_cond.get();
|
||||
links["m_next"] = m_next.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotCatch* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotCatch> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief TestCatch Routine to see if the catch is to do or not.
|
||||
|
@ -78,11 +78,11 @@ protected:
|
|||
|
||||
private:
|
||||
//! Instructions
|
||||
CBotInstr* m_block;
|
||||
std::unique_ptr<CBotInstr> m_block;
|
||||
//! Condition
|
||||
CBotInstr* m_cond;
|
||||
std::unique_ptr<CBotInstr> m_cond;
|
||||
//! Following catch
|
||||
CBotCatch* m_next;
|
||||
std::unique_ptr<CBotCatch> m_next;
|
||||
|
||||
friend class CBotTry;
|
||||
};
|
||||
|
|
|
@ -28,12 +28,12 @@ namespace CBot
|
|||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotCondition::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotCondition::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
pStack->SetStartError(p->GetStart());
|
||||
if (IsOfType(p, ID_OPENPAR))
|
||||
{
|
||||
CBotInstr* inst = CBotBoolExpr::Compile(p, pStack);
|
||||
std::unique_ptr<CBotInstr> inst = CBotBoolExpr::Compile(p, pStack);
|
||||
if (nullptr != inst)
|
||||
{
|
||||
if (IsOfType(p, ID_CLOSEPAR))
|
||||
|
@ -41,8 +41,8 @@ CBotInstr* CBotCondition::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
return inst;
|
||||
}
|
||||
pStack->SetError(CBotErrClosePar, p->GetStart()); // missing parenthesis
|
||||
// TODO does this return the right error message?
|
||||
}
|
||||
delete inst;
|
||||
}
|
||||
|
||||
pStack->SetError(CBotErrOpenPar, p->GetStart()); // missing parenthesis
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
private:
|
||||
CBotCondition() = delete;
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
|
||||
#include "CBot/CBotVar/CBotVar.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace CBot
|
||||
|
@ -46,16 +48,14 @@ CBotDefArray::CBotDefArray()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotDefArray::~CBotDefArray()
|
||||
{
|
||||
delete m_var;
|
||||
delete m_listass;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type)
|
||||
std::unique_ptr<CBotInstr> CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type)
|
||||
{
|
||||
CBotCStack* pStk = pStack->TokenStack(p);
|
||||
|
||||
CBotDefArray* inst = new CBotDefArray();
|
||||
std::unique_ptr<CBotDefArray> inst = MakeUnique<CBotDefArray>();
|
||||
|
||||
CBotToken* vartoken = p;
|
||||
inst->SetToken(vartoken);
|
||||
|
@ -69,7 +69,7 @@ CBotInstr* CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResul
|
|||
goto error;
|
||||
}
|
||||
|
||||
CBotInstr* i;
|
||||
std::unique_ptr<CBotInstr> i;
|
||||
while (IsOfType(p, ID_OPBRK))
|
||||
{
|
||||
pStk->SetStartError(p->GetStart());
|
||||
|
@ -83,9 +83,9 @@ CBotInstr* CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResul
|
|||
}
|
||||
}
|
||||
else
|
||||
i = new CBotEmpty(); // if no special formula
|
||||
i = MakeUnique<CBotEmpty>(); // if no special formula
|
||||
|
||||
inst->AddNext3b(i); // construct a list
|
||||
inst->AddNext3b(move(i)); // construct a list
|
||||
type = CBotTypResult(CBotTypArrayPointer, type);
|
||||
|
||||
if (IsOfType(p, ID_CLBRK)) continue;
|
||||
|
@ -132,11 +132,11 @@ CBotInstr* CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResul
|
|||
}
|
||||
}
|
||||
|
||||
if (pStk->IsOk()) return pStack->Return(inst, pStk);
|
||||
if (pStk->IsOk())
|
||||
return pStack->Return(std::move(inst), pStk);
|
||||
}
|
||||
|
||||
error:
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
|
@ -267,8 +267,8 @@ std::string CBotDefArray::GetDebugData()
|
|||
std::map<std::string, CBotInstr*> CBotDefArray::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_var"] = m_var;
|
||||
links["m_listass"] = m_listass;
|
||||
links["m_var"] = m_var.get();
|
||||
links["m_listass"] = m_listass.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
* \param type
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);
|
||||
|
||||
/*!
|
||||
* \brief Execute Executes the definition of an array.
|
||||
|
@ -70,9 +70,9 @@ protected:
|
|||
|
||||
private:
|
||||
//! The variables to initialize.
|
||||
CBotInstr* m_var;
|
||||
std::unique_ptr<CBotInstr> m_var;
|
||||
//! List of assignments for array.
|
||||
CBotInstr* m_listass;
|
||||
std::unique_ptr<CBotInstr> m_listass;
|
||||
//! Type of elements.
|
||||
CBotTypResult m_typevar;
|
||||
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
#include "CBot/CBotVar/CBotVarPointer.h"
|
||||
#include "CBot/CBotVar/CBotVarClass.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
|
@ -51,14 +53,10 @@ CBotDefClass::CBotDefClass()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotDefClass::~CBotDefClass()
|
||||
{
|
||||
delete m_parameters;
|
||||
delete m_exprRetVar;
|
||||
delete m_expr;
|
||||
delete m_var;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass)
|
||||
std::unique_ptr<CBotInstr> CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass)
|
||||
{
|
||||
// seeks the corresponding classes
|
||||
if ( pClass == nullptr )
|
||||
|
@ -76,20 +74,24 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
|
|||
|
||||
bool bIntrinsic = pClass->IsIntrinsic();
|
||||
CBotTypResult type = CBotTypResult( bIntrinsic ? CBotTypIntrinsic : CBotTypPointer, pClass );
|
||||
CBotDefClass* inst = static_cast<CBotDefClass*>(CompileArray(p, pStack, type));
|
||||
if ( inst != nullptr || !pStack->IsOk() ) return inst;
|
||||
{
|
||||
std::unique_ptr<CBotInstr> inst = CompileArray(p, pStack, type);
|
||||
if ( inst != nullptr || !pStack->IsOk() ) return inst;
|
||||
}
|
||||
|
||||
CBotCStack* pStk = pStack->TokenStack();
|
||||
|
||||
inst = new CBotDefClass();
|
||||
std::unique_ptr<CBotDefClass> instAsClass = MakeUnique<CBotDefClass>();
|
||||
/// TODO Need to be revised and fixed after adding unit tests
|
||||
CBotToken token(pClass->GetName(), std::string(), p->GetStart(), p->GetEnd());
|
||||
inst->SetToken(&token);
|
||||
instAsClass->SetToken(&token);
|
||||
CBotToken* vartoken = p;
|
||||
|
||||
if ( nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) )
|
||||
std::unique_ptr<CBotInstr> inst;
|
||||
|
||||
if ( nullptr != (instAsClass->m_var = CBotLeftExprVar::Compile( p, pStk )) )
|
||||
{
|
||||
(static_cast<CBotLeftExprVar*>(inst->m_var))->m_typevar = type;
|
||||
(static_cast<CBotLeftExprVar*>(instAsClass->m_var.get()))->m_typevar = type;
|
||||
if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable
|
||||
{
|
||||
pStk->SetStartError(vartoken->GetStart());
|
||||
|
@ -99,12 +101,12 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
|
|||
|
||||
if (IsOfType(p, ID_OPBRK)) // with any clues?
|
||||
{
|
||||
delete inst; // is not type CBotDefInt
|
||||
instAsClass.reset(); // is not type CBotDefInt
|
||||
p = vartoken; // returns to the variable name
|
||||
|
||||
// compiles declaration an array
|
||||
|
||||
inst = static_cast<CBotDefClass*>(CBotDefArray::Compile(p, pStk, type ));
|
||||
inst = CBotDefArray::Compile(p, pStk, type);
|
||||
|
||||
}
|
||||
else
|
||||
|
@ -114,10 +116,10 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
|
|||
pStack->AddVar(var); // placed on the stack
|
||||
|
||||
// look if there are parameters
|
||||
inst->m_hasParams = (p->GetType() == ID_OPENPAR);
|
||||
instAsClass->m_hasParams = (p->GetType() == ID_OPENPAR);
|
||||
|
||||
std::vector<CBotTypResult> ppVars;
|
||||
inst->m_parameters = CompileParams(p, pStk, ppVars);
|
||||
instAsClass->m_parameters = CompileParams(p, pStk, ppVars);
|
||||
if ( !pStk->IsOk() ) goto error;
|
||||
|
||||
// if there are parameters, is the equivalent to the stament "new"
|
||||
|
@ -125,18 +127,18 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
|
|||
// CPoint A = new CPoint( 0, 0 )
|
||||
|
||||
// if ( nullptr != inst->m_parameters )
|
||||
if ( inst->m_hasParams )
|
||||
if ( instAsClass->m_hasParams )
|
||||
{
|
||||
// the constructor is there?
|
||||
// std::string noname;
|
||||
CBotTypResult r = pClass->CompileMethode(&token, var->m_value->GetTypResult(), ppVars, pStk, inst->m_nMethodeIdent);
|
||||
CBotTypResult r = pClass->CompileMethode(&token, var->m_value->GetTypResult(), ppVars, pStk, instAsClass->m_nMethodeIdent);
|
||||
pStk->DeleteChildLevels(); // releases the supplement stack
|
||||
int typ = r.GetType();
|
||||
|
||||
if (typ == CBotErrUndefCall)
|
||||
{
|
||||
// si le constructeur n'existe pas
|
||||
if (inst->m_parameters != nullptr) // with parameters
|
||||
if (instAsClass->m_parameters != nullptr) // with parameters
|
||||
{
|
||||
pStk->SetError(CBotErrNoConstruct, vartoken);
|
||||
goto error;
|
||||
|
@ -152,9 +154,9 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
|
|||
|
||||
pStk->SetVarType(var->m_value->GetTypResult());
|
||||
// chained method ?
|
||||
if (nullptr != (inst->m_exprRetVar = CBotExprRetVar::Compile(p, pStk, true, false)))
|
||||
if (nullptr != (instAsClass->m_exprRetVar = CBotExprRetVar::Compile(p, pStk, true, false)))
|
||||
{
|
||||
inst->m_exprRetVar->SetToken(vartoken);
|
||||
instAsClass->m_exprRetVar->SetToken(vartoken);
|
||||
pStk->DeleteChildLevels();
|
||||
}
|
||||
pStk->SetVarType(CBotTypResult());
|
||||
|
@ -165,7 +167,7 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
|
|||
if (IsOfType(p, ID_ASS)) // with a assignment?
|
||||
{
|
||||
pStk->SetStartError(p->GetStart());
|
||||
if (inst->m_hasParams)
|
||||
if (instAsClass->m_hasParams)
|
||||
{
|
||||
pStk->SetError(CBotErrNoTerminator, p->GetStart());
|
||||
goto error;
|
||||
|
@ -177,7 +179,7 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
|
|||
goto error;
|
||||
}
|
||||
|
||||
if ( nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) )
|
||||
if ( nullptr == ( instAsClass->m_expr = CBotTwoOpExpr::Compile( p, pStk )) )
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
@ -204,7 +206,7 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
|
|||
}
|
||||
var->m_value->SetInit(CBotVar::InitType::DEF); // marks the pointer as init
|
||||
}
|
||||
else if (inst->m_hasParams)
|
||||
else if (instAsClass->m_hasParams)
|
||||
{
|
||||
// creates the object on the stack
|
||||
// with a pointer to the object
|
||||
|
@ -215,26 +217,27 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
|
|||
}
|
||||
var->m_value->SetInit(CBotVar::InitType::IS_POINTER); // marks the pointer as init
|
||||
}
|
||||
|
||||
inst = std::move(instAsClass);
|
||||
}
|
||||
|
||||
if (pStk->IsOk() && IsOfType(p, ID_COMMA)) // several chained definitions
|
||||
{
|
||||
if ( nullptr != ( inst->m_next = CBotDefClass::Compile(p, pStk, pClass) )) // compiles the following
|
||||
{
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
}
|
||||
|
||||
if (!pStk->IsOk() || IsOfType(p, ID_SEP)) // complete instruction
|
||||
{
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
|
||||
pStk->SetError(CBotErrNoTerminator, p->GetStart());
|
||||
}
|
||||
|
||||
error:
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
|
@ -350,7 +353,7 @@ bool CBotDefClass::Execute(CBotStack* &pj)
|
|||
|
||||
int i = 0;
|
||||
|
||||
CBotInstr* p = m_parameters;
|
||||
CBotInstr* p = m_parameters.get();
|
||||
// evaluates the parameters
|
||||
// and places the values on the stack
|
||||
// to (can) be interrupted (broken) at any time
|
||||
|
@ -457,7 +460,7 @@ void CBotDefClass::RestoreState(CBotStack* &pj, bool bMain)
|
|||
|
||||
int i = 0;
|
||||
|
||||
CBotInstr* p = m_parameters;
|
||||
CBotInstr* p = m_parameters.get();
|
||||
// evaluates the parameters
|
||||
// and the values an the stack
|
||||
// so that it can be interrupted at any time
|
||||
|
@ -491,9 +494,9 @@ void CBotDefClass::RestoreState(CBotStack* &pj, bool bMain)
|
|||
std::map<std::string, CBotInstr*> CBotDefClass::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_var"] = m_var;
|
||||
links["m_parameters"] = m_parameters;
|
||||
links["m_expr"] = m_expr;
|
||||
links["m_var"] = m_var.get();
|
||||
links["m_parameters"] = m_parameters.get();
|
||||
links["m_expr"] = m_expr.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
* \param pClass
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass = nullptr);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass = nullptr);
|
||||
|
||||
/*!
|
||||
* \brief Execute Declaration of the instance of a class, for example:
|
||||
|
@ -75,18 +75,18 @@ protected:
|
|||
private:
|
||||
|
||||
//! Variable to initialise.
|
||||
CBotInstr* m_var;
|
||||
std::unique_ptr<CBotInstr> m_var;
|
||||
//! Parameters to be evaluated for the contructor.
|
||||
CBotInstr* m_parameters;
|
||||
std::unique_ptr<CBotInstr> m_parameters;
|
||||
//! A value to put, if there is.
|
||||
CBotInstr* m_expr;
|
||||
std::unique_ptr<CBotInstr> m_expr;
|
||||
//! Has it parameters.
|
||||
bool m_hasParams;
|
||||
//! Constructor method unique identifier
|
||||
long m_nMethodeIdent;
|
||||
|
||||
//! Instruction to chain method calls after constructor
|
||||
CBotInstr* m_exprRetVar;
|
||||
std::unique_ptr<CBotInstr> m_exprRetVar;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -29,24 +29,25 @@
|
|||
|
||||
#include "CBot/CBotVar/CBotVar.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotDefVariable::CBotDefVariable()
|
||||
{
|
||||
m_var = m_expr = nullptr;
|
||||
m_var = nullptr;
|
||||
m_expr = nullptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotDefVariable::~CBotDefVariable()
|
||||
{
|
||||
delete m_var;
|
||||
delete m_expr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotDefVariable::CompileAfterType(CBotToken* &p, CBotCStack* pStack, CBotTypResult &baseType, bool noskip)
|
||||
std::unique_ptr<CBotInstr> CBotDefVariable::CompileAfterType(CBotToken* &p, CBotCStack* pStack, CBotTypResult &baseType, bool noskip)
|
||||
{
|
||||
// TODO: if type is a CBotTypArrayPointer then we should make sure this behaves like CBotInstr::CompileArray did
|
||||
// and delete CBotInstr::CompileArray
|
||||
|
@ -56,13 +57,13 @@ CBotInstr* CBotDefVariable::CompileAfterType(CBotToken* &p, CBotCStack* pStack,
|
|||
CBotToken *vartoken = p; // so we can rewind if it's an array
|
||||
|
||||
// TODO: adjust return type so cast isn't needed
|
||||
CBotLeftExprVar *left_var = static_cast<CBotLeftExprVar*>(CBotLeftExprVar::Compile(p, pStk));
|
||||
std::unique_ptr<CBotLeftExprVar> left_var = CBotLeftExprVar::Compile(p, pStk);
|
||||
if (left_var == nullptr)
|
||||
{
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
CBotInstr *inst;
|
||||
std::unique_ptr<CBotInstr> inst;
|
||||
if (IsOfType(p, ID_OPBRK) || baseType.GetType() == CBotTypArrayPointer)
|
||||
{
|
||||
p = vartoken; // return to the variable name and compile as an array declaration instead
|
||||
|
@ -78,8 +79,8 @@ CBotInstr* CBotDefVariable::CompileAfterType(CBotToken* &p, CBotCStack* pStack,
|
|||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
CBotDefVariable *inst_defvar = new CBotDefVariable();
|
||||
inst_defvar->m_var = left_var;
|
||||
std::unique_ptr<CBotDefVariable> inst_defvar = MakeUnique<CBotDefVariable>();
|
||||
inst_defvar->m_var = std::move(left_var);
|
||||
inst_defvar->SetToken(vartoken);
|
||||
|
||||
if (IsOfType(p, ID_ASS))
|
||||
|
@ -88,14 +89,12 @@ CBotInstr* CBotDefVariable::CompileAfterType(CBotToken* &p, CBotCStack* pStack,
|
|||
if ( IsOfType(p, ID_SEP) )
|
||||
{
|
||||
pStk->SetError(CBotErrNoExpression, p->GetStart());
|
||||
delete inst_defvar;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
inst_defvar->m_expr = CBotTwoOpExpr::Compile( p, pStk );
|
||||
if (nullptr == inst_defvar->m_expr)
|
||||
{
|
||||
delete inst_defvar;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
|
@ -103,7 +102,6 @@ CBotInstr* CBotDefVariable::CompileAfterType(CBotToken* &p, CBotCStack* pStack,
|
|||
if (!TypeCompatible(valueType, baseType, ID_ASS)) // first parameter is value type, second is variable type
|
||||
{
|
||||
pStk->SetError(CBotErrBadType1, p->GetStart());
|
||||
delete inst_defvar;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +111,7 @@ CBotInstr* CBotDefVariable::CompileAfterType(CBotToken* &p, CBotCStack* pStack,
|
|||
std::unique_ptr<CBotVariable> var(new CBotVariable(*vartoken, std::move(val)));
|
||||
pStack->AddVar(var.release());
|
||||
|
||||
inst = inst_defvar;
|
||||
inst = std::move(inst_defvar);
|
||||
}
|
||||
|
||||
if (pStk->IsOk() && IsOfType(p, ID_COMMA))
|
||||
|
@ -121,29 +119,27 @@ CBotInstr* CBotDefVariable::CompileAfterType(CBotToken* &p, CBotCStack* pStack,
|
|||
// TODO: is there a bug here? CompileAfterType could return an error, but as long as there's an ID_SEP afterwards
|
||||
// we still return a valid instruction?
|
||||
// TODO: potentially invalid cast, to get around 'protected' modifier!
|
||||
if (nullptr != ( static_cast<CBotDefVariable*>(inst)->m_next2b = CBotDefVariable::CompileAfterType(p, pStk, baseType, noskip)))
|
||||
if (nullptr != ( static_cast<CBotDefVariable*>(inst.get())->m_next2b = CBotDefVariable::CompileAfterType(p, pStk, baseType, noskip)))
|
||||
{
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
if (!noskip)
|
||||
{
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
}
|
||||
|
||||
if (noskip || IsOfType(p, ID_SEP))
|
||||
{
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
|
||||
pStk->SetError(CBotErrNoTerminator, p->GetStart());
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotDefVariable::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip)
|
||||
std::unique_ptr<CBotInstr> CBotDefVariable::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip)
|
||||
{
|
||||
assert(!cont); // unused; TODO remove
|
||||
|
||||
|
@ -236,8 +232,8 @@ void CBotDefVariable::RestoreState(CBotStack* &pj, bool bMain)
|
|||
std::map<std::string, CBotInstr*> CBotDefVariable::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_var"] = m_var;
|
||||
links["m_expr"] = m_expr;
|
||||
links["m_var"] = m_var.get();
|
||||
links["m_expr"] = m_expr.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
* \param noskip
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont=false, bool noskip=false);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack, bool cont=false, bool noskip=false);
|
||||
|
||||
/*!
|
||||
* \brief CompileAfterType
|
||||
|
@ -51,7 +51,7 @@ public:
|
|||
* \param noskip
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* CompileAfterType(CBotToken* &p, CBotCStack* pStack, CBotTypResult &baseType, bool noskip=false);
|
||||
static std::unique_ptr<CBotInstr> CompileAfterType(CBotToken* &p, CBotCStack* pStack, CBotTypResult &baseType, bool noskip=false);
|
||||
|
||||
/*!
|
||||
* \brief Execute Executes a boolean variable definition.
|
||||
|
@ -73,9 +73,9 @@ protected:
|
|||
|
||||
private:
|
||||
//! Variable to initialise.
|
||||
CBotInstr* m_var;
|
||||
std::unique_ptr<CBotInstr> m_var;
|
||||
//! A value to put, if there is.
|
||||
CBotInstr* m_expr;
|
||||
std::unique_ptr<CBotInstr> m_expr;
|
||||
};
|
||||
|
||||
} // namespace CBot
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include "CBot/CBotStack.h"
|
||||
#include "CBot/CBotCStack.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
|
@ -37,14 +39,12 @@ CBotDo::CBotDo()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotDo::~CBotDo()
|
||||
{
|
||||
delete m_condition; // frees the condition
|
||||
delete m_block; // frees the instruction block
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotDo::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotDo::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotDo* inst = new CBotDo(); // creates the object
|
||||
std::unique_ptr<CBotDo> inst = MakeUnique<CBotDo>(); // creates the object
|
||||
|
||||
CBotToken* pp = p; // preserves at the ^ token (starting position)
|
||||
|
||||
|
@ -74,7 +74,7 @@ CBotInstr* CBotDo::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
// the condition exists
|
||||
if (IsOfType(p, ID_SEP))
|
||||
{
|
||||
return pStack->Return(inst, pStk); // return an object to the application
|
||||
return pStack->Return(move(inst), pStk); // return an object to the application
|
||||
}
|
||||
pStk->SetError(CBotErrNoTerminator, p->GetStart());
|
||||
}
|
||||
|
@ -82,7 +82,6 @@ CBotInstr* CBotDo::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
pStk->SetError(CBotErrNoWhile, p->GetStart());
|
||||
}
|
||||
|
||||
delete inst; // error, frees up
|
||||
return pStack->Return(nullptr, pStk); // no object, the error is on the stack
|
||||
}
|
||||
|
||||
|
@ -162,8 +161,8 @@ std::string CBotDo::GetDebugData()
|
|||
std::map<std::string, CBotInstr*> CBotDo::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_block"] = m_block;
|
||||
links["m_condition"] = m_condition;
|
||||
links["m_block"] = m_block.get();
|
||||
links["m_condition"] = m_condition.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute
|
||||
|
@ -62,9 +62,9 @@ protected:
|
|||
|
||||
private:
|
||||
//! Instruction
|
||||
CBotInstr* m_block;
|
||||
std::unique_ptr<CBotInstr> m_block;
|
||||
//! Conditions
|
||||
CBotInstr* m_condition;
|
||||
std::unique_ptr<CBotInstr> m_condition;
|
||||
//! A label if there is
|
||||
std::string m_label;
|
||||
};
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
#include "CBot/CBotVar/CBotVar.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
|
@ -38,22 +40,22 @@ CBotExprLitBool::~CBotExprLitBool()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotExprLitBool::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotExprLitBool::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotCStack* pStk = pStack->TokenStack();
|
||||
CBotExprLitBool* inst = nullptr;
|
||||
std::unique_ptr<CBotExprLitBool> inst = nullptr;
|
||||
|
||||
if ( p->GetType() == ID_TRUE ||
|
||||
p->GetType() == ID_FALSE )
|
||||
{
|
||||
inst = new CBotExprLitBool();
|
||||
inst = MakeUnique<CBotExprLitBool>();
|
||||
inst->SetToken(p); // stores the operation false or true
|
||||
p = p->GetNext();
|
||||
|
||||
pStk->SetVarType(CBotTypResult(CBotTypBoolean));
|
||||
}
|
||||
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute Executes, returns true or false.
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* This file is part of the Colobot: Gold Edition source code
|
||||
* Copyright (C) 2001-2018, Daniel Roux, EPSITEC SA & TerranovaTeam
|
||||
|
@ -25,6 +26,8 @@
|
|||
|
||||
#include "CBot/CBotUtils.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace CBot
|
||||
|
@ -41,11 +44,11 @@ CBotExprLitNum::~CBotExprLitNum()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotExprLitNum::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotExprLitNum::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotCStack* pStk = pStack->TokenStack();
|
||||
|
||||
CBotExprLitNum* inst = new CBotExprLitNum();
|
||||
std::unique_ptr<CBotExprLitNum> inst = MakeUnique<CBotExprLitNum>();
|
||||
|
||||
inst->SetToken(p);
|
||||
std::string s = p->GetString();
|
||||
|
@ -72,9 +75,8 @@ CBotInstr* CBotExprLitNum::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
{
|
||||
pStk->SetVarType(CBotTypResult(inst->m_numtype));
|
||||
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute Execute, returns the corresponding number.
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
#include "CBot/CBotVar/CBotVar.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
|
@ -38,7 +40,7 @@ CBotExprLitString::~CBotExprLitString()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotExprLitString::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotExprLitString::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotCStack* pStk = pStack->TokenStack();
|
||||
|
||||
|
@ -158,14 +160,14 @@ CBotInstr* CBotExprLitString::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
|
||||
if (pStk->IsOk())
|
||||
{
|
||||
CBotExprLitString* inst = new CBotExprLitString();
|
||||
std::unique_ptr<CBotExprLitString> inst = MakeUnique<CBotExprLitString>();
|
||||
inst->m_valstring.swap(valstring);
|
||||
inst->SetToken(p);
|
||||
p = p->GetNext();
|
||||
|
||||
pStk->SetVarType(CBotTypResult(CBotTypString));
|
||||
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute Execute, returns the corresponding string.
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include "CBot/CBotStack.h"
|
||||
#include "CBot/CBotClass.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
|
@ -42,7 +44,7 @@ CBotExprRetVar::~CBotExprRetVar()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotExprRetVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bMethodsOnly, bool bPreviousIsSuper)
|
||||
std::unique_ptr<CBotInstr> CBotExprRetVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bMethodsOnly, bool bPreviousIsSuper)
|
||||
{
|
||||
if (p->GetType() == ID_DOT)
|
||||
{
|
||||
|
@ -51,7 +53,7 @@ CBotInstr* CBotExprRetVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bMeth
|
|||
if (val.GetType() == CBotTypVoid) return nullptr;
|
||||
|
||||
CBotCStack* pStk = pStack->TokenStack();
|
||||
CBotInstr* inst = new CBotExprRetVar();
|
||||
std::unique_ptr<CBotInstr> inst = MakeUnique<CBotExprRetVar>();
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
@ -62,9 +64,8 @@ CBotInstr* CBotExprRetVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bMeth
|
|||
|
||||
if (IsOfType( p, ID_OPBRK ))
|
||||
{
|
||||
CBotIndexExpr* i = new CBotIndexExpr();
|
||||
std::unique_ptr<CBotIndexExpr> i = MakeUnique<CBotIndexExpr>();
|
||||
i->m_expr = CBotExpression::Compile(p, pStk);
|
||||
inst->AddNext3(i);
|
||||
|
||||
val = val.GetTypElem();
|
||||
|
||||
|
@ -78,6 +79,7 @@ CBotInstr* CBotExprRetVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bMeth
|
|||
pStk->SetError(CBotErrCloseIndex, p->GetStart());
|
||||
goto err;
|
||||
}
|
||||
inst->AddNext3(move(i));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -91,10 +93,10 @@ CBotInstr* CBotExprRetVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bMeth
|
|||
{
|
||||
if (p->GetNext()->GetType() == ID_OPENPAR)
|
||||
{
|
||||
CBotInstr* i = CBotInstrMethode::Compile(p, pStk, val, bMethodsOnly, false);
|
||||
std::unique_ptr<CBotInstr> i = CBotInstrMethode::Compile(p, pStk, val, bMethodsOnly, false);
|
||||
if (!pStk->IsOk()) goto err;
|
||||
inst->AddNext3(i);
|
||||
return pStack->Return(inst, pStk);
|
||||
inst->AddNext3(move(i));
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
else if (bMethodsOnly)
|
||||
{
|
||||
|
@ -109,9 +111,9 @@ CBotInstr* CBotExprRetVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bMeth
|
|||
if (var != nullptr)
|
||||
{
|
||||
val = var->m_value->GetTypResult();
|
||||
CBotFieldExpr* i = new CBotFieldExpr(var->GetFieldPosition());
|
||||
std::unique_ptr<CBotFieldExpr> i = MakeUnique<CBotFieldExpr>(var->GetFieldPosition());
|
||||
i->SetToken(pp);
|
||||
inst->AddNext3(i);
|
||||
inst->AddNext3(move(i));
|
||||
// TODO: can "super" accesses occur here? Check for them. (3rd parameter)
|
||||
if (CBotFieldExpr::CheckProtectionError(pStk, preVal, "", var))
|
||||
{
|
||||
|
@ -141,11 +143,10 @@ CBotInstr* CBotExprRetVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bMeth
|
|||
}
|
||||
|
||||
pStk->SetVarType(val);
|
||||
if (pStk->IsOk()) return pStack->Return(inst, pStk);
|
||||
if (pStk->IsOk()) return pStack->Return(move(inst), pStk);
|
||||
|
||||
pStk->SetError(CBotErrUndefVar, p);
|
||||
err:
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
CBotExprRetVar();
|
||||
~CBotExprRetVar();
|
||||
|
||||
static CBotInstr* Compile(CBotToken*& p, CBotCStack* pStack, bool bMethodsOnly, bool bPreviousIsSuper);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken*& p, CBotCStack* pStack, bool bMethodsOnly, bool bPreviousIsSuper);
|
||||
|
||||
/*!
|
||||
* \brief Execute
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "CBot/CBotCStack.h"
|
||||
|
||||
#include "CBot/CBotVar/CBotVar.h"
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
@ -37,11 +38,10 @@ CBotExprUnaire::CBotExprUnaire()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotExprUnaire::~CBotExprUnaire()
|
||||
{
|
||||
delete m_expr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotExprUnaire::Compile(CBotToken* &p, CBotCStack* pStack, bool bLiteral)
|
||||
std::unique_ptr<CBotInstr> CBotExprUnaire::Compile(CBotToken* &p, CBotCStack* pStack, bool bLiteral)
|
||||
{
|
||||
int op = p->GetType();
|
||||
CBotToken* pp = p;
|
||||
|
@ -49,7 +49,7 @@ CBotInstr* CBotExprUnaire::Compile(CBotToken* &p, CBotCStack* pStack, bool bLite
|
|||
|
||||
CBotCStack* pStk = pStack->TokenStack(pp);
|
||||
|
||||
CBotExprUnaire* inst = new CBotExprUnaire();
|
||||
std::unique_ptr<CBotExprUnaire> inst = MakeUnique<CBotExprUnaire>();
|
||||
inst->SetToken(pp);
|
||||
|
||||
if (!bLiteral) inst->m_expr = CBotParExpr::Compile(p, pStk);
|
||||
|
@ -60,20 +60,19 @@ CBotInstr* CBotExprUnaire::Compile(CBotToken* &p, CBotCStack* pStack, bool bLite
|
|||
if (pStk->GetVarType().GetType() != CBotTypVoid)
|
||||
{
|
||||
if (op == ID_ADD && pStk->GetVarType().GetType() < CBotTypBoolean) // only with the number
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
if (op == ID_SUB && pStk->GetVarType().GetType() < CBotTypBoolean) // only with the numer
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
if (op == ID_NOT && pStk->GetVarType().GetType() < CBotTypFloat) // only with an integer
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
if (op == ID_LOG_NOT && pStk->GetVarType().Eq(CBotTypBoolean))// only with boolean
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
if (op == ID_TXT_NOT && pStk->GetVarType().Eq(CBotTypBoolean))// only with boolean
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
|
||||
pStk->SetError(CBotErrBadType1, &inst->m_token);
|
||||
}
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
|
@ -128,7 +127,7 @@ void CBotExprUnaire::RestoreState(CBotStack* &pj, bool bMain)
|
|||
std::map<std::string, CBotInstr*> CBotExprUnaire::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_expr"] = m_expr;
|
||||
links["m_expr"] = m_expr.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
* \param bLiteral If true, compiles only literal expressions Ex: ~11, -4.0, !false, not true
|
||||
* \return The compiled instruction or nullptr
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLiteral = false);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack, bool bLiteral = false);
|
||||
|
||||
/*!
|
||||
* \brief Execute
|
||||
|
@ -62,7 +62,7 @@ protected:
|
|||
|
||||
private:
|
||||
//! Expression to be evaluated.
|
||||
CBotInstr* m_expr;
|
||||
std::unique_ptr<CBotInstr> m_expr;
|
||||
};
|
||||
|
||||
} // namespace CBot
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
|
||||
#include "CBot/CBotVar/CBotVarArray.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
|
@ -44,7 +46,7 @@ CBotExprVar::~CBotExprVar()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotExprVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bCheckReadOnly)
|
||||
std::unique_ptr<CBotInstr> CBotExprVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bCheckReadOnly)
|
||||
{
|
||||
// CBotToken* pDebut = p;
|
||||
CBotCStack* pStk = pStack->TokenStack();
|
||||
|
@ -54,7 +56,7 @@ CBotInstr* CBotExprVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bCheckRe
|
|||
// is it a variable?
|
||||
if (p->GetType() == TokenTypVar)
|
||||
{
|
||||
CBotInstr* inst = new CBotExprVar(); // create the object
|
||||
std::unique_ptr<CBotInstr> inst = MakeUnique<CBotExprVar>(); // create the object
|
||||
|
||||
inst->SetToken(p);
|
||||
|
||||
|
@ -77,9 +79,9 @@ CBotInstr* CBotExprVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bCheckRe
|
|||
token.SetPos(p->GetStart(), p->GetEnd());
|
||||
inst->SetToken(&token);
|
||||
|
||||
CBotFieldExpr* i = new CBotFieldExpr(var->GetFieldPosition()); // new element
|
||||
std::unique_ptr<CBotFieldExpr> i = MakeUnique<CBotFieldExpr>(var->GetFieldPosition()); // new element
|
||||
i->SetToken(p); // keeps the name of the token
|
||||
inst->AddNext3(i); // added after
|
||||
inst->AddNext3(move(i)); // added after
|
||||
}
|
||||
|
||||
p = p->GetNext(); // next token
|
||||
|
@ -90,9 +92,8 @@ CBotInstr* CBotExprVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bCheckRe
|
|||
{
|
||||
if (IsOfType( p, ID_OPBRK )) // check if there is an aindex
|
||||
{
|
||||
CBotIndexExpr* i = new CBotIndexExpr();
|
||||
std::unique_ptr<CBotIndexExpr> i = MakeUnique<CBotIndexExpr>();
|
||||
i->m_expr = CBotExpression::Compile(p, pStk); // compile the formula
|
||||
inst->AddNext3(i); // add to the chain
|
||||
|
||||
var = (static_cast<CBotVarArray*>(var->m_value.get()))->GetItem(0,true); // gets the component [0]
|
||||
|
||||
|
@ -106,6 +107,7 @@ CBotInstr* CBotExprVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bCheckRe
|
|||
pStk->SetError(CBotErrCloseIndex, p->GetStart());
|
||||
goto err;
|
||||
}
|
||||
inst->AddNext3(move(i)); // add to the chain
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -121,11 +123,11 @@ CBotInstr* CBotExprVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bCheckRe
|
|||
{
|
||||
if (bCheckReadOnly) goto err; // don't allow increment a method call "++"
|
||||
|
||||
CBotInstr* i = CBotInstrMethode::Compile(p, pStk, var->m_value->GetTypResult(), false,
|
||||
std::unique_ptr<CBotInstr> i = CBotInstrMethode::Compile(p, pStk, var->m_value->GetTypResult(), false,
|
||||
var->GetContainingClass() == nullptr && var->GetName() == "super");
|
||||
if (!pStk->IsOk()) goto err;
|
||||
inst->AddNext3(i); // added after
|
||||
return pStack->Return(inst, pStk);
|
||||
inst->AddNext3(move(i)); // added after
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -133,9 +135,9 @@ CBotInstr* CBotExprVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bCheckRe
|
|||
var = var->m_value->GetItem(p->GetString()); // get item correspondent
|
||||
if (var != nullptr)
|
||||
{
|
||||
CBotFieldExpr* i = new CBotFieldExpr(var->GetFieldPosition()); // new element
|
||||
std::unique_ptr<CBotFieldExpr> i = MakeUnique<CBotFieldExpr>(var->GetFieldPosition()); // new element
|
||||
i->SetToken(pp); // keeps the name of the token
|
||||
inst->AddNext3(i); // add after
|
||||
inst->AddNext3(move(i)); // add after
|
||||
if (CBotFieldExpr::CheckProtectionError(pStk, preVar->m_value->GetTypResult(), preVar->GetName(), var, bCheckReadOnly))
|
||||
{
|
||||
pStk->SetError(CBotErrPrivate, pp);
|
||||
|
@ -162,11 +164,10 @@ CBotInstr* CBotExprVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bCheckRe
|
|||
}
|
||||
|
||||
pStk->SetVarType(var->m_value->GetTypResult());
|
||||
if (pStk->IsOk()) return pStack->Return(inst, pStk);
|
||||
if (pStk->IsOk()) return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
pStk->SetError(CBotErrUndefVar, p);
|
||||
err:
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
|
@ -174,7 +175,7 @@ err:
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotExprVar::CompileMethode(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotExprVar::CompileMethode(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotToken* pp = p;
|
||||
CBotCStack* pStk = pStack->TokenStack();
|
||||
|
@ -188,7 +189,7 @@ CBotInstr* CBotExprVar::CompileMethode(CBotToken* &p, CBotCStack* pStack)
|
|||
CBotVariable* var = pStk->FindVar(pthis);
|
||||
if (var == nullptr) return pStack->Return(nullptr, pStk);
|
||||
|
||||
CBotInstr* inst = new CBotExprVar();
|
||||
std::unique_ptr<CBotInstr> inst = MakeUnique<CBotExprVar>();
|
||||
|
||||
// this is an element of the current class
|
||||
// adds the equivalent of this. before
|
||||
|
@ -203,18 +204,17 @@ CBotInstr* CBotExprVar::CompileMethode(CBotToken* &p, CBotCStack* pStack)
|
|||
{
|
||||
if (pp->GetNext()->GetType() == ID_OPENPAR) // a method call?
|
||||
{
|
||||
CBotInstr* i = CBotInstrMethode::Compile(pp, pStk, var->m_value->GetTypResult(), false,
|
||||
std::unique_ptr<CBotInstr> i = CBotInstrMethode::Compile(pp, pStk, var->m_value->GetTypResult(), false,
|
||||
var->GetContainingClass() == nullptr && var->GetName() == "super");
|
||||
if (pStk->IsOk())
|
||||
{
|
||||
inst->AddNext3(i); // add after
|
||||
inst->AddNext3(move(i)); // add after
|
||||
p = pp; // previous instruction
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
pStk->SetError(CBotNoErr, 0); // the error is not adressed here
|
||||
}
|
||||
}
|
||||
delete inst;
|
||||
}
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
* \param bCheckReadOnly True for operations that would modify the value of the variable
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken*& p, CBotCStack* pStack, bool bCheckReadOnly = false);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken*& p, CBotCStack* pStack, bool bCheckReadOnly = false);
|
||||
|
||||
/*!
|
||||
* \brief CompileMethode
|
||||
|
@ -54,7 +54,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* CompileMethode(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> CompileMethode(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute Execute, making the value of a variable.
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
#include "CBot/CBotVar/CBotVar.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace CBot
|
||||
|
@ -43,16 +45,14 @@ CBotExpression::CBotExpression()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotExpression::~CBotExpression()
|
||||
{
|
||||
delete m_leftop;
|
||||
delete m_rightop;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotToken* pp = p;
|
||||
|
||||
CBotExpression* inst = new CBotExpression();
|
||||
std::unique_ptr<CBotExpression> inst = MakeUnique<CBotExpression>();
|
||||
|
||||
inst->m_leftop = CBotLeftExpr::Compile(p, pStack);
|
||||
|
||||
|
@ -67,21 +67,18 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
if (inst->m_leftop == nullptr)
|
||||
{
|
||||
pStack->SetError(CBotErrBadLeft, p->GetEnd());
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if ( p->GetType() == ID_SEP )
|
||||
{
|
||||
pStack->SetError(CBotErrNoExpression, p);
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inst->m_rightop = CBotExpression::Compile(p, pStack);
|
||||
if (inst->m_rightop == nullptr)
|
||||
{
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -92,14 +89,12 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
inst->m_leftop->ExecuteVar(var, pStack);
|
||||
if (var == nullptr)
|
||||
{
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (OpType != ID_ASS && !var->IsDefined())
|
||||
{
|
||||
pStack->SetError(CBotErrNotInit, pp);
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -140,21 +135,19 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
if (!TypeCompatible(type1, type2, OpType))
|
||||
{
|
||||
pStack->SetError(CBotErrBadType1, &inst->m_token);
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return inst; // compatible type?
|
||||
}
|
||||
|
||||
delete inst;
|
||||
int start, end;
|
||||
CBotError error = pStack->GetError(start, end);
|
||||
|
||||
p = pp; // returns to the top
|
||||
pStack->SetError(CBotNoErr,0); // forget the error
|
||||
|
||||
CBotInstr* i = CBotTwoOpExpr::Compile(p, pStack); // tries without assignment
|
||||
std::unique_ptr<CBotInstr> i = CBotTwoOpExpr::Compile(p, pStack); // tries without assignment
|
||||
if (i != nullptr && error == CBotErrPrivate && p->GetType() == ID_ASS)
|
||||
pStack->ResetError(error, start, end);
|
||||
return i;
|
||||
|
@ -318,8 +311,8 @@ void CBotExpression::RestoreState(CBotStack* &pj, bool bMain)
|
|||
std::map<std::string, CBotInstr*> CBotExpression::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_leftop"] = m_leftop;
|
||||
links["m_rightop"] = m_rightop;
|
||||
links["m_leftop"] = m_leftop.get();
|
||||
links["m_rightop"] = m_rightop.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute Executes an expression with assignment.
|
||||
|
@ -72,9 +72,9 @@ protected:
|
|||
|
||||
private:
|
||||
//! Left operand
|
||||
CBotLeftExpr* m_leftop;
|
||||
std::unique_ptr<CBotLeftExpr> m_leftop;
|
||||
//! Right operand
|
||||
CBotInstr* m_rightop;
|
||||
std::unique_ptr<CBotInstr> m_rightop;
|
||||
};
|
||||
|
||||
} // namespace CBot
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "CBot/CBotStack.h"
|
||||
#include "CBot/CBotCStack.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
|
@ -40,16 +42,12 @@ CBotFor::CBotFor()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotFor::~CBotFor()
|
||||
{
|
||||
delete m_init;
|
||||
delete m_test;
|
||||
delete m_incr;
|
||||
delete m_block; // frees the instruction block
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotFor::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotFor* inst = new CBotFor(); // creates the object
|
||||
std::unique_ptr<CBotFor> inst = MakeUnique<CBotFor>(); // creates the object
|
||||
CBotToken* pp = p; // preserves at the ^ token (starting position)
|
||||
|
||||
if ( IsOfType( p, TokenTypVar ) &&
|
||||
|
@ -76,7 +74,6 @@ CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
if ( !IsOfType(p, ID_SEP)) // lack the semicolon?
|
||||
{
|
||||
pStack->SetError(CBotErrOpenPar, p->GetStart());
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk); // no object, the error is on the stack
|
||||
}
|
||||
inst->m_test = CBotBoolExpr::Compile(p, pStk );
|
||||
|
@ -85,7 +82,6 @@ CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
if ( !IsOfType(p, ID_SEP)) // lack the semicolon?
|
||||
{
|
||||
pStack->SetError(CBotErrOpenPar, p->GetStart());
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk); // no object, the error is on the stack
|
||||
}
|
||||
inst->m_incr = CBotListExpression::Compile(p, pStk );
|
||||
|
@ -97,14 +93,13 @@ CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
inst->m_block = CBotBlock::CompileBlkOrInst(p, pStk, true );
|
||||
pStk->ClearLoop();
|
||||
if ( pStk->IsOk() )
|
||||
return pStack->Return(inst, pStk);;
|
||||
return pStack->Return(move(inst), pStk);;
|
||||
}
|
||||
pStack->SetError(CBotErrClosePar, p->GetStart());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete inst; // error, frees up
|
||||
return pStack->Return(nullptr, pStk); // no object, the error is on the stack
|
||||
}
|
||||
|
||||
|
@ -218,10 +213,10 @@ std::string CBotFor::GetDebugData()
|
|||
std::map<std::string, CBotInstr*> CBotFor::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_init"] = m_init;
|
||||
links["m_test"] = m_test;
|
||||
links["m_incr"] = m_incr;
|
||||
links["m_block"] = m_block;
|
||||
links["m_init"] = m_init.get();
|
||||
links["m_test"] = m_test.get();
|
||||
links["m_incr"] = m_incr.get();
|
||||
links["m_block"] = m_block.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute
|
||||
|
@ -62,13 +62,13 @@ protected:
|
|||
|
||||
private:
|
||||
//! Initial intruction
|
||||
CBotInstr* m_init;
|
||||
std::unique_ptr<CBotInstr> m_init;
|
||||
//! Test Condition
|
||||
CBotInstr* m_test;
|
||||
std::unique_ptr<CBotInstr> m_test;
|
||||
//! instruction for increment
|
||||
CBotInstr* m_incr;
|
||||
std::unique_ptr<CBotInstr> m_incr;
|
||||
//! Instructions
|
||||
CBotInstr* m_block;
|
||||
std::unique_ptr<CBotInstr> m_block;
|
||||
//! A label if there is
|
||||
std::string m_label;
|
||||
};
|
||||
|
|
|
@ -61,7 +61,6 @@ std::set<CBotFunction*> CBotFunction::m_publicFunctions{};
|
|||
CBotFunction::~CBotFunction()
|
||||
{
|
||||
delete m_param; // empty parameter list
|
||||
delete m_block; // the instruction block
|
||||
|
||||
// remove public list if there is
|
||||
if (m_bPublic)
|
||||
|
@ -1051,7 +1050,7 @@ std::string CBotFunction::GetDebugData()
|
|||
std::map<std::string, CBotInstr*> CBotFunction::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_block"] = m_block;
|
||||
links["m_block"] = m_block.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -260,7 +260,7 @@ private:
|
|||
//! Parameter list.
|
||||
CBotDefParam* m_param;
|
||||
//! The instruction block.
|
||||
CBotInstr* m_block;
|
||||
std::unique_ptr<CBotInstr> m_block;
|
||||
//! If returns CBotTypClass.
|
||||
CBotToken m_retToken;
|
||||
//! Complete type of the result.
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include "CBot/CBotStack.h"
|
||||
#include "CBot/CBotCStack.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
|
@ -38,13 +40,10 @@ CBotIf::CBotIf()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotIf::~CBotIf()
|
||||
{
|
||||
delete m_condition; // frees the condition
|
||||
delete m_block; // frees the block of instruction1
|
||||
delete m_blockElse; // frees the block of instruction2
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotIf::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotIf::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotToken* pp = p; // preserves at the ^ token (starting instruction)
|
||||
|
||||
|
@ -52,7 +51,7 @@ CBotInstr* CBotIf::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
|
||||
CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp
|
||||
|
||||
CBotIf* inst = new CBotIf(); // create the object
|
||||
std::unique_ptr<CBotIf> inst = MakeUnique<CBotIf>(); // create the object
|
||||
inst->SetToken( pp );
|
||||
|
||||
if ( nullptr != (inst->m_condition = CBotCondition::Compile(p, pStk )) )
|
||||
|
@ -72,19 +71,16 @@ CBotInstr* CBotIf::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
if (!pStk->IsOk())
|
||||
{
|
||||
// there is no correct block after the else
|
||||
// frees the object, and transmits the error that is on the stack
|
||||
delete inst;
|
||||
// transmits the error that is on the stack
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
}
|
||||
|
||||
// return the corrent object to the application
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
}
|
||||
|
||||
// error, frees the object
|
||||
delete inst;
|
||||
// and transmits the error that is on the stack.
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
@ -175,9 +171,9 @@ bool CBotIf::HasReturn()
|
|||
std::map<std::string, CBotInstr*> CBotIf::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_condition"] = m_condition;
|
||||
links["m_block"] = m_block;
|
||||
links["m_blockElse"] = m_blockElse;
|
||||
links["m_condition"] = m_condition.get();
|
||||
links["m_block"] = m_block.get();
|
||||
links["m_blockElse"] = m_blockElse.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute Execution of the instruction.
|
||||
|
@ -70,11 +70,11 @@ protected:
|
|||
|
||||
private:
|
||||
//! Condition
|
||||
CBotInstr* m_condition;
|
||||
std::unique_ptr<CBotInstr> m_condition;
|
||||
//! Instruction
|
||||
CBotInstr* m_block;
|
||||
std::unique_ptr<CBotInstr> m_block;
|
||||
//! Instruction
|
||||
CBotInstr* m_blockElse;
|
||||
std::unique_ptr<CBotInstr> m_blockElse;
|
||||
};
|
||||
|
||||
} // namespace CBot
|
||||
|
|
|
@ -38,7 +38,6 @@ CBotIndexExpr::CBotIndexExpr()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotIndexExpr::~CBotIndexExpr()
|
||||
{
|
||||
delete m_expr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -122,7 +121,7 @@ void CBotIndexExpr::RestoreStateVar(CBotStack* &pile, bool bMain)
|
|||
std::map<std::string, CBotInstr*> CBotIndexExpr::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_expr"] = m_expr;
|
||||
links["m_expr"] = m_expr.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ protected:
|
|||
|
||||
private:
|
||||
//! Expression for calculating the index.
|
||||
CBotInstr* m_expr;
|
||||
std::unique_ptr<CBotInstr> m_expr;
|
||||
friend class CBotLeftExpr;
|
||||
friend class CBotExprVar;
|
||||
friend class CBotExprRetVar;
|
||||
|
|
|
@ -38,6 +38,8 @@
|
|||
#include "CBot/CBotClass.h"
|
||||
#include "CBot/CBotStack.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace CBot
|
||||
|
@ -57,10 +59,6 @@ CBotInstr::CBotInstr()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr::~CBotInstr()
|
||||
{
|
||||
delete m_next;
|
||||
delete m_next2b;
|
||||
delete m_next3;
|
||||
delete m_next3b;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -82,49 +80,49 @@ CBotToken* CBotInstr::GetToken()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void CBotInstr::AddNext(CBotInstr* n)
|
||||
void CBotInstr::AddNext(std::unique_ptr<CBotInstr> n)
|
||||
{
|
||||
CBotInstr* p = this;
|
||||
while (p->m_next != nullptr) p = p->m_next;
|
||||
p->m_next = n;
|
||||
while (p->m_next != nullptr) p = p->m_next.get();
|
||||
p->m_next = move(n);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void CBotInstr::AddNext3(CBotInstr* n)
|
||||
void CBotInstr::AddNext3(std::unique_ptr<CBotInstr> n)
|
||||
{
|
||||
CBotInstr* p = this;
|
||||
while (p->m_next3 != nullptr) p = p->m_next3;
|
||||
p->m_next3 = n;
|
||||
while (p->m_next3 != nullptr) p = p->m_next3.get();
|
||||
p->m_next3 = move(n);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void CBotInstr::AddNext3b(CBotInstr* n)
|
||||
void CBotInstr::AddNext3b(std::unique_ptr<CBotInstr> n)
|
||||
{
|
||||
CBotInstr* p = this;
|
||||
while (p->m_next3b != nullptr) p = p->m_next3b;
|
||||
p->m_next3b = n;
|
||||
while (p->m_next3b != nullptr) p = p->m_next3b.get();
|
||||
p->m_next3b = move(n);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotInstr::GetNext()
|
||||
{
|
||||
return m_next;
|
||||
return m_next.get();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotInstr::GetNext3()
|
||||
{
|
||||
return m_next3;
|
||||
return m_next3.get();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotInstr::GetNext3b()
|
||||
{
|
||||
return m_next3b;
|
||||
return m_next3b.get();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotToken* pp = p;
|
||||
|
||||
|
@ -212,13 +210,12 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
}
|
||||
|
||||
// This can be an arithmetic expression
|
||||
CBotInstr* inst = CBotExpression::Compile(p, pStack);
|
||||
std::unique_ptr<CBotInstr> inst = CBotExpression::Compile(p, pStack);
|
||||
if (IsOfType(p, ID_SEP))
|
||||
{
|
||||
return inst;
|
||||
}
|
||||
pStack->SetError(CBotErrNoTerminator, p->GetStart());
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -276,7 +273,7 @@ bool CBotInstr::CompCase(CBotStack* &pj, int val)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool first)
|
||||
std::unique_ptr<CBotInstr> CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool first)
|
||||
{
|
||||
if (IsOfType(p, ID_OPBRK))
|
||||
{
|
||||
|
@ -286,14 +283,14 @@ CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypRes
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
CBotInstr* inst = CompileArray(p, pStack, CBotTypResult(CBotTypArrayPointer, type), false);
|
||||
std::unique_ptr<CBotInstr> inst = CompileArray(p, pStack, CBotTypResult(CBotTypArrayPointer, type), false);
|
||||
if (inst != nullptr || !pStack->IsOk()) return inst;
|
||||
}
|
||||
|
||||
// compiles an array declaration
|
||||
if (first) return nullptr ;
|
||||
|
||||
CBotInstr* inst = CBotDefArray::Compile(p, pStack, type);
|
||||
std::unique_ptr<CBotInstr> inst = CBotDefArray::Compile(p, pStack, type);
|
||||
if (inst == nullptr) return nullptr;
|
||||
|
||||
if (IsOfType(p, ID_COMMA)) // several definitions
|
||||
|
@ -302,7 +299,6 @@ CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypRes
|
|||
{
|
||||
return inst;
|
||||
}
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -311,7 +307,6 @@ CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypRes
|
|||
return inst;
|
||||
}
|
||||
|
||||
delete inst;
|
||||
pStack->SetError(CBotErrNoTerminator, p->GetStart());
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -325,10 +320,10 @@ bool CBotInstr::HasReturn()
|
|||
std::map<std::string, CBotInstr*> CBotInstr::GetDebugLinks()
|
||||
{
|
||||
return {
|
||||
{"m_next", m_next},
|
||||
{"m_next2b", m_next2b},
|
||||
{"m_next3", m_next3},
|
||||
{"m_next3b", m_next3b}
|
||||
{"m_next", m_next.get()},
|
||||
{"m_next2b", m_next2b.get()},
|
||||
{"m_next3", m_next3.get()},
|
||||
{"m_next3b", m_next3b.get()}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ public:
|
|||
* \param pStack Compilation stack
|
||||
* \return Compiled instruction
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/**
|
||||
* \brief CompileArray
|
||||
|
@ -130,7 +130,7 @@ public:
|
|||
* \param first
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* CompileArray(CBotToken* &p,
|
||||
static std::unique_ptr<CBotInstr> CompileArray(CBotToken* &p,
|
||||
CBotCStack* pStack,
|
||||
CBotTypResult type,
|
||||
bool first = true);
|
||||
|
@ -225,7 +225,7 @@ public:
|
|||
* \brief AddNext Adds the statement following the other.
|
||||
* \param n
|
||||
*/
|
||||
void AddNext(CBotInstr* n);
|
||||
void AddNext(std::unique_ptr<CBotInstr> n);
|
||||
|
||||
/**
|
||||
* \brief GetNext Returns next statement.
|
||||
|
@ -237,7 +237,7 @@ public:
|
|||
* \brief AddNext3
|
||||
* \param n
|
||||
*/
|
||||
void AddNext3(CBotInstr* n);
|
||||
void AddNext3(std::unique_ptr<CBotInstr> n);
|
||||
|
||||
/**
|
||||
* \brief GetNext3
|
||||
|
@ -249,7 +249,7 @@ public:
|
|||
* \brief AddNext3b
|
||||
* \param n
|
||||
*/
|
||||
void AddNext3b(CBotInstr* n);
|
||||
void AddNext3b(std::unique_ptr<CBotInstr> n);
|
||||
|
||||
/**
|
||||
* \brief GetNext3b
|
||||
|
@ -285,13 +285,13 @@ protected:
|
|||
//! Keeps the token.
|
||||
CBotToken m_token;
|
||||
//! Linked command.
|
||||
CBotInstr* m_next;
|
||||
std::unique_ptr<CBotInstr> m_next;
|
||||
//! Second list definition chain.
|
||||
CBotInstr* m_next2b;
|
||||
std::unique_ptr<CBotInstr> m_next2b;
|
||||
//! Third list for indices and fields.
|
||||
CBotInstr* m_next3;
|
||||
std::unique_ptr<CBotInstr> m_next3;
|
||||
//! Necessary for reporting tables.
|
||||
CBotInstr* m_next3b;
|
||||
std::unique_ptr<CBotInstr> m_next3b;
|
||||
|
||||
friend class CBotDefClass;
|
||||
friend class CBotDefInt;
|
||||
|
|
|
@ -22,11 +22,12 @@
|
|||
#include "CBot/CBotInstr/CBotInstrUtils.h"
|
||||
|
||||
#include "CBot/CBotStack.h"
|
||||
|
||||
#include "CBot/CBotCStack.h"
|
||||
|
||||
#include "CBot/CBotVar/CBotVar.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace CBot
|
||||
|
@ -43,12 +44,10 @@ CBotInstrCall::CBotInstrCall()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstrCall::~CBotInstrCall()
|
||||
{
|
||||
delete m_parameters;
|
||||
delete m_exprRetVar;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
|
||||
CBotToken* pp = p;
|
||||
|
@ -59,7 +58,7 @@ CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
|
||||
std::vector<CBotTypResult> ppVars;
|
||||
|
||||
CBotInstrCall* inst = new CBotInstrCall();
|
||||
std::unique_ptr<CBotInstrCall> inst = MakeUnique<CBotInstrCall>();
|
||||
inst->SetToken(pp);
|
||||
|
||||
// compile la list of parameters
|
||||
|
@ -67,7 +66,6 @@ CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
|
||||
if ( !pStack->IsOk() )
|
||||
{
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -79,7 +77,6 @@ CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
// if (pVar2!=nullptr) pp = pVar2->RetToken();
|
||||
pStack->SetError( static_cast<CBotError>(inst->m_typRes.GetType()), pp );
|
||||
pStack->DeleteChildLevels();
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -97,7 +94,6 @@ CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
}
|
||||
if ( !pStack->IsOk() )
|
||||
{
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -130,7 +126,7 @@ bool CBotInstrCall::Execute(CBotStack* &pj)
|
|||
|
||||
int i = 0;
|
||||
|
||||
CBotInstr* p = m_parameters;
|
||||
CBotInstr* p = m_parameters.get();
|
||||
// evaluates parameters
|
||||
// and places the values on the stack
|
||||
// for allow of interruption at any time
|
||||
|
@ -186,7 +182,7 @@ void CBotInstrCall::RestoreState(CBotStack* &pj, bool bMain)
|
|||
|
||||
int i = 0;
|
||||
CBotVar* ppVars[1000];
|
||||
CBotInstr* p = m_parameters;
|
||||
CBotInstr* p = m_parameters.get();
|
||||
// evaluate parameters
|
||||
// and place the values on the stack
|
||||
// for allow of interruption at any time
|
||||
|
@ -223,7 +219,7 @@ std::string CBotInstrCall::GetDebugData()
|
|||
std::map<std::string, CBotInstr*> CBotInstrCall::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_parameters"] = m_parameters;
|
||||
links["m_parameters"] = m_parameters.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute
|
||||
|
@ -64,14 +64,14 @@ protected:
|
|||
|
||||
private:
|
||||
//! The parameters to be evaluated.
|
||||
CBotInstr* m_parameters;
|
||||
std::unique_ptr<CBotInstr> m_parameters;
|
||||
//! Complete type of the result.
|
||||
CBotTypResult m_typRes;
|
||||
//! Id of a function.
|
||||
long m_nFuncIdent;
|
||||
|
||||
//! Instruction to return a member of the returned object.
|
||||
CBotInstr* m_exprRetVar;
|
||||
std::unique_ptr<CBotInstr> m_exprRetVar;
|
||||
|
||||
friend class CBotDebug;
|
||||
};
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
|
||||
#include "CBot/CBotVar/CBotVar.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
|
@ -44,14 +46,12 @@ CBotInstrMethode::CBotInstrMethode()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstrMethode::~CBotInstrMethode()
|
||||
{
|
||||
delete m_parameters;
|
||||
delete m_exprRetVar;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult varType, bool bMethodChain, bool bIsSuperCall)
|
||||
std::unique_ptr<CBotInstr> CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult varType, bool bMethodChain, bool bIsSuperCall)
|
||||
{
|
||||
CBotInstrMethode* inst = new CBotInstrMethode();
|
||||
std::unique_ptr<CBotInstrMethode> inst = MakeUnique<CBotInstrMethode>();
|
||||
inst->SetToken(p); // corresponding token
|
||||
|
||||
CBotToken* pp = p;
|
||||
|
@ -77,7 +77,6 @@ CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypR
|
|||
if (inst->m_typRes.GetType() > 20)
|
||||
{
|
||||
pStack->SetError(static_cast<CBotError>(inst->m_typRes.GetType()), pp);
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
// put the result on the stack to have something
|
||||
|
@ -97,7 +96,6 @@ CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypR
|
|||
if ( pStack->IsOk() )
|
||||
return inst;
|
||||
}
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
|
@ -145,7 +143,7 @@ bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre
|
|||
}
|
||||
int i = 0;
|
||||
|
||||
CBotInstr* p = m_parameters;
|
||||
CBotInstr* p = m_parameters.get();
|
||||
// evaluate the parameters
|
||||
// and places the values on the stack
|
||||
// to be interrupted at any time
|
||||
|
@ -215,7 +213,7 @@ void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, bool bMain)
|
|||
|
||||
int i = 0;
|
||||
|
||||
CBotInstr* p = m_parameters;
|
||||
CBotInstr* p = m_parameters.get();
|
||||
// evaluate the parameters
|
||||
// and places the values on the stack
|
||||
// to be interrupted at any time
|
||||
|
@ -272,7 +270,7 @@ bool CBotInstrMethode::Execute(CBotStack* &pj)
|
|||
}
|
||||
int i = 0;
|
||||
|
||||
CBotInstr* p = m_parameters;
|
||||
CBotInstr* p = m_parameters.get();
|
||||
// evaluate the parameters
|
||||
// and places the values on the stack
|
||||
// to be interrupted at any time
|
||||
|
@ -319,7 +317,7 @@ std::string CBotInstrMethode::GetDebugData()
|
|||
std::map<std::string, CBotInstr*> CBotInstrMethode::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_parameters"] = m_parameters;
|
||||
links["m_parameters"] = m_parameters.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
* \param bIsSuperCall If true, don't do a virtual call
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult varType, bool bMethodChain, bool bIsSuperCall);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult varType, bool bMethodChain, bool bIsSuperCall);
|
||||
|
||||
/*!
|
||||
* \brief Execute
|
||||
|
@ -76,7 +76,7 @@ protected:
|
|||
|
||||
private:
|
||||
//! The parameters to be evaluated.
|
||||
CBotInstr* m_parameters;
|
||||
std::unique_ptr<CBotInstr> m_parameters;
|
||||
//! Complete type of the result.
|
||||
CBotTypResult m_typRes;
|
||||
//! Name of the method.
|
||||
|
@ -89,7 +89,7 @@ private:
|
|||
bool m_bNonVirtualCall;
|
||||
|
||||
//! Instruction to return a member of the returned object.
|
||||
CBotInstr* m_exprRetVar;
|
||||
std::unique_ptr<CBotInstr> m_exprRetVar;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -31,10 +31,10 @@ namespace CBot
|
|||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, std::vector<CBotTypResult> &ppVars)
|
||||
std::unique_ptr<CBotInstr> CompileParams(CBotToken* &p, CBotCStack* pStack, std::vector<CBotTypResult> &ppVars)
|
||||
{
|
||||
bool first = true;
|
||||
CBotInstr* ret = nullptr; // to return to the list
|
||||
std::unique_ptr<CBotInstr> ret = nullptr; // to return to the list
|
||||
|
||||
CBotCStack* pile = pStack;
|
||||
|
||||
|
@ -51,7 +51,7 @@ CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, std::vector<CBotTypR
|
|||
if (first) pStack->SetStartError(start);
|
||||
first = false;
|
||||
|
||||
CBotInstr* param = CBotExpression::Compile(p, pile);
|
||||
std::unique_ptr<CBotInstr> param = CBotExpression::Compile(p, pile);
|
||||
end = p->GetStart();
|
||||
|
||||
if (!pile->IsOk())
|
||||
|
@ -59,9 +59,6 @@ CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, std::vector<CBotTypR
|
|||
return pStack->Return(nullptr, pile);
|
||||
}
|
||||
|
||||
if (ret == nullptr) ret = param;
|
||||
else ret->AddNext(param); // construct the list
|
||||
|
||||
if (param != nullptr)
|
||||
{
|
||||
if (pile->GetVarType().Eq(CBotTypVoid))
|
||||
|
@ -74,6 +71,9 @@ CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, std::vector<CBotTypR
|
|||
// TODO: was commented out as part of value/variable refactor. What does this do?
|
||||
(void)end; //ppVars[i]->GetToken()->SetPos(start, end);
|
||||
|
||||
if (ret == nullptr) ret = move(param);
|
||||
else ret->AddNext(move(param)); // construct the list
|
||||
|
||||
if (IsOfType(p, ID_COMMA)) continue; // skips the comma
|
||||
if (IsOfType(p, ID_CLOSEPAR)) break;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
@ -32,12 +33,15 @@ class CBotTypResult;
|
|||
|
||||
/*!
|
||||
* \brief CompileParams Compile a list of parameters.
|
||||
*
|
||||
* TODO: should probably return a vector, to deprecate intrusive linked list
|
||||
*
|
||||
* \param p
|
||||
* \param pStack
|
||||
* \param ppVars [out] types of parameters
|
||||
* \return
|
||||
*/
|
||||
CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, std::vector<CBotTypResult> &ppVars);
|
||||
std::unique_ptr<CBotInstr> CompileParams(CBotToken* &p, CBotCStack* pStack, std::vector<CBotTypResult> &ppVars);
|
||||
|
||||
/*!
|
||||
* \brief TypeCompatible Check if two results are consistent to make an
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
|
||||
#include "CBot/CBotVar/CBotVarArray.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
|
@ -43,7 +45,7 @@ CBotLeftExpr::~CBotLeftExpr()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotLeftExpr> CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotCStack* pStk = pStack->TokenStack();
|
||||
|
||||
|
@ -52,7 +54,7 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
// is it a variable name?
|
||||
if (p->GetType() == TokenTypVar)
|
||||
{
|
||||
CBotLeftExpr* inst = new CBotLeftExpr(); // creates the object
|
||||
std::unique_ptr<CBotLeftExpr> inst = MakeUnique<CBotLeftExpr>(); // creates the object
|
||||
|
||||
inst->SetToken(p);
|
||||
|
||||
|
@ -74,9 +76,9 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
pthis.SetPos(p->GetStart(), p->GetEnd());
|
||||
inst->SetToken(&pthis);
|
||||
|
||||
CBotFieldExpr* i = new CBotFieldExpr(var->GetFieldPosition()); // new element
|
||||
std::unique_ptr<CBotFieldExpr> i = MakeUnique<CBotFieldExpr>(var->GetFieldPosition()); // new element
|
||||
i->SetToken(p); // keeps the name of the token
|
||||
inst->AddNext3(i); // add after
|
||||
inst->AddNext3(move(i)); // add after
|
||||
|
||||
var = pStk->FindVar(pthis);
|
||||
var = var->m_value->GetItem(p->GetString());
|
||||
|
@ -89,9 +91,8 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
{
|
||||
if (IsOfType( p, ID_OPBRK ))
|
||||
{
|
||||
CBotIndexExpr* i = new CBotIndexExpr();
|
||||
std::unique_ptr<CBotIndexExpr> i = MakeUnique<CBotIndexExpr>();
|
||||
i->m_expr = CBotExpression::Compile(p, pStk);
|
||||
inst->AddNext3(i); // add to the chain
|
||||
|
||||
var = (static_cast<CBotVarArray*>(var->m_value.get()))->GetItem(0,true); // gets the component [0]
|
||||
|
||||
|
@ -106,6 +107,8 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
pStk->SetError(CBotErrCloseIndex, p->GetStart());
|
||||
goto err;
|
||||
}
|
||||
|
||||
inst->AddNext3(move(i)); // add to the chain
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -128,9 +131,9 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
goto err;
|
||||
}
|
||||
|
||||
CBotFieldExpr* i = new CBotFieldExpr(var->GetFieldPosition()); // new element
|
||||
std::unique_ptr<CBotFieldExpr> i = MakeUnique<CBotFieldExpr>(var->GetFieldPosition()); // new element
|
||||
i->SetToken(pp); // keeps the name of the token
|
||||
inst->AddNext3(i); // adds after
|
||||
inst->AddNext3(move(i)); // adds after
|
||||
|
||||
p = p->GetNext(); // skips the name
|
||||
continue;
|
||||
|
@ -145,15 +148,14 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
}
|
||||
|
||||
|
||||
if (pStk->IsOk()) return static_cast<CBotLeftExpr*> (pStack->Return(inst, pStk));
|
||||
if (pStk->IsOk()) return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
pStk->SetError(CBotErrUndefVar, p);
|
||||
err:
|
||||
delete inst;
|
||||
return static_cast<CBotLeftExpr*> ( pStack->Return(nullptr, pStk));
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
return static_cast<CBotLeftExpr*> ( pStack->Return(nullptr, pStk));
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotLeftExpr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotLeftExpr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute Runs, is a variable and assigns the result to the stack.
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
#include "CBot/CBotVar/CBotVar.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
|
||||
|
@ -38,7 +40,7 @@ CBotLeftExprVar::~CBotLeftExprVar()
|
|||
{
|
||||
}
|
||||
|
||||
CBotInstr* CBotLeftExprVar::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotLeftExprVar> CBotLeftExprVar::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
// Verifies that the token is a variable name
|
||||
if (p->GetType() != TokenTypVar)
|
||||
|
@ -47,7 +49,7 @@ CBotInstr* CBotLeftExprVar::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
CBotLeftExprVar* inst = new CBotLeftExprVar();
|
||||
std::unique_ptr<CBotLeftExprVar> inst = MakeUnique<CBotLeftExprVar>();
|
||||
inst->SetToken(p);
|
||||
p = p->GetNext();
|
||||
|
||||
|
|
|
@ -29,12 +29,11 @@ namespace CBot
|
|||
*/
|
||||
class CBotLeftExprVar : public CBotInstr
|
||||
{
|
||||
private:
|
||||
CBotLeftExprVar();
|
||||
public:
|
||||
CBotLeftExprVar();
|
||||
~CBotLeftExprVar();
|
||||
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotLeftExprVar> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute Creates a variable and assigns the result to the stack.
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
|
||||
#include "CBot/CBotVar/CBotVar.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
|
@ -41,11 +43,10 @@ CBotListArray::CBotListArray()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotListArray::~CBotListArray()
|
||||
{
|
||||
delete m_expr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type)
|
||||
std::unique_ptr<CBotInstr> CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type)
|
||||
{
|
||||
CBotCStack* pStk = pStack->TokenStack(p);
|
||||
|
||||
|
@ -53,13 +54,13 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu
|
|||
|
||||
if (IsOfType( p, ID_NULL ) || (IsOfType(p, ID_OPBLK) && IsOfType(p, ID_CLBLK)))
|
||||
{
|
||||
CBotInstr* inst = new CBotExprLitNull();
|
||||
std::unique_ptr<CBotInstr> inst = MakeUnique<CBotExprLitNull>();
|
||||
inst->SetToken(pp);
|
||||
return pStack->Return(inst, pStk); // ok with empty element
|
||||
return pStack->Return(move(inst), pStk); // ok with empty element
|
||||
}
|
||||
p = pp;
|
||||
|
||||
CBotListArray* inst = new CBotListArray();
|
||||
std::unique_ptr<CBotListArray> inst = MakeUnique<CBotListArray>();
|
||||
|
||||
if (IsOfType( p, ID_OPBLK ))
|
||||
{
|
||||
|
@ -84,7 +85,7 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu
|
|||
{
|
||||
pStk->SetStartError(p->GetStart());
|
||||
|
||||
CBotInstr* i = nullptr;
|
||||
std::unique_ptr<CBotInstr> i = nullptr;
|
||||
if (nullptr == ( i = CBotListArray::Compile(p, pStk, type.GetTypElem() ) ))
|
||||
{
|
||||
if (pStk->IsOk())
|
||||
|
@ -98,7 +99,7 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu
|
|||
}
|
||||
}
|
||||
|
||||
inst->m_expr->AddNext3b(i);
|
||||
inst->m_expr->AddNext3b(move(i));
|
||||
|
||||
if ( p->GetType() == ID_COMMA ) continue;
|
||||
if ( p->GetType() == ID_CLBLK ) break;
|
||||
|
@ -129,7 +130,7 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu
|
|||
{
|
||||
pStk->SetStartError(p->GetStart());
|
||||
|
||||
CBotInstr* i = CBotTwoOpExpr::Compile(p, pStk) ;
|
||||
std::unique_ptr<CBotInstr> i = CBotTwoOpExpr::Compile(p, pStk) ;
|
||||
if (nullptr == i)
|
||||
{
|
||||
goto error;
|
||||
|
@ -144,7 +145,7 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu
|
|||
pStk->SetError(CBotErrBadType1, p->GetStart());
|
||||
goto error;
|
||||
}
|
||||
inst->m_expr->AddNext3b(i);
|
||||
inst->m_expr->AddNext3b(move(i));
|
||||
|
||||
if (p->GetType() == ID_COMMA) continue;
|
||||
if (p->GetType() == ID_CLBLK) break;
|
||||
|
@ -160,11 +161,10 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu
|
|||
goto error;
|
||||
}
|
||||
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
|
||||
error:
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
|
@ -174,7 +174,7 @@ bool CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar)
|
|||
CBotStack* pile1 = pj->AddStack();
|
||||
CBotVar* pVar2;
|
||||
|
||||
CBotInstr* p = m_expr;
|
||||
CBotInstr* p = m_expr.get();
|
||||
|
||||
int n = 0;
|
||||
|
||||
|
@ -210,7 +210,7 @@ void CBotListArray::RestoreState(CBotStack* &pj, bool bMain)
|
|||
CBotStack* pile = pj->RestoreStack(this);
|
||||
if (pile == nullptr) return;
|
||||
|
||||
CBotInstr* p = m_expr;
|
||||
CBotInstr* p = m_expr.get();
|
||||
|
||||
int state = pile->GetState();
|
||||
|
||||
|
@ -223,7 +223,7 @@ void CBotListArray::RestoreState(CBotStack* &pj, bool bMain)
|
|||
std::map<std::string, CBotInstr*> CBotListArray::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_expr"] = m_expr;
|
||||
links["m_expr"] = m_expr.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
* \param type
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);
|
||||
|
||||
/*!
|
||||
* \brief Execute Executes the definition of an array.
|
||||
|
@ -63,7 +63,7 @@ protected:
|
|||
|
||||
private:
|
||||
//! An expression for an element others are linked with CBotInstr :: m_next3b;
|
||||
CBotInstr* m_expr;
|
||||
std::unique_ptr<CBotInstr> m_expr;
|
||||
};
|
||||
|
||||
} // namespace CBot
|
||||
|
|
|
@ -24,14 +24,16 @@
|
|||
#include "CBot/CBotStack.h"
|
||||
#include "CBot/CBotCStack.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// Seeks a declaration of variable or expression
|
||||
static CBotInstr* CompileInstrOrDefVar(CBotToken* &p, CBotCStack* pStack)
|
||||
static std::unique_ptr<CBotInstr> CompileInstrOrDefVar(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotInstr* i = CBotDefVariable::Compile(p, pStack, false, true ); // Is this a declaration of a primitive?
|
||||
std::unique_ptr<CBotInstr> i = CBotDefVariable::Compile(p, pStack, false, true ); // Is this a declaration of a primitive?
|
||||
// TODO: shouldn't class definitions also be allowed?
|
||||
if ( i== nullptr ) i = CBotExpression::Compile( p, pStack ); // compiles an expression
|
||||
return i;
|
||||
|
@ -49,30 +51,27 @@ CBotListExpression::CBotListExpression()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotListExpression::~CBotListExpression()
|
||||
{
|
||||
delete m_expr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotListExpression::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotListExpression::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotListExpression* inst = new CBotListExpression();
|
||||
std::unique_ptr<CBotListExpression> inst = MakeUnique<CBotListExpression>();
|
||||
|
||||
inst->m_expr = CompileInstrOrDefVar(p, pStack ); // compile the first expression in a list
|
||||
if (pStack->IsOk())
|
||||
{
|
||||
while ( IsOfType(p, ID_COMMA) ) // more instructions?
|
||||
while ( IsOfType(p, ID_COMMA) ) // more instructions?
|
||||
{
|
||||
CBotInstr* i = CompileInstrOrDefVar( p, pStack ); // Is this a declaration of an integer?
|
||||
inst->m_expr->AddNext(i); // added after
|
||||
std::unique_ptr<CBotInstr> i = CompileInstrOrDefVar( p, pStack ); // Is this a declaration of an integer?
|
||||
inst->m_expr->AddNext(move(i)); // added after
|
||||
if ( !pStack->IsOk() )
|
||||
{
|
||||
delete inst;
|
||||
return nullptr; // no object, the error is on the stack
|
||||
return nullptr; // no object, the error is on the stack
|
||||
}
|
||||
}
|
||||
return inst;
|
||||
}
|
||||
delete inst;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -80,7 +79,7 @@ CBotInstr* CBotListExpression::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
bool CBotListExpression::Execute(CBotStack* &pj)
|
||||
{
|
||||
CBotStack* pile = pj->AddStack(); // essential
|
||||
CBotInstr* p = m_expr; // the first expression
|
||||
CBotInstr* p = m_expr.get(); // the first expression
|
||||
|
||||
int state = pile->GetState();
|
||||
while (state-->0) p = p->GetNext(); // returns to the interrupted operation
|
||||
|
@ -108,7 +107,7 @@ void CBotListExpression::RestoreState(CBotStack* &pj, bool bMain)
|
|||
state = pile->GetState();
|
||||
}
|
||||
|
||||
CBotInstr* p = m_expr; // the first expression
|
||||
CBotInstr* p = m_expr.get(); // the first expression
|
||||
|
||||
while (p != nullptr && state-->0)
|
||||
{
|
||||
|
@ -125,7 +124,7 @@ void CBotListExpression::RestoreState(CBotStack* &pj, bool bMain)
|
|||
std::map<std::string, CBotInstr*> CBotListExpression::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_expr"] = m_expr;
|
||||
links["m_expr"] = m_expr.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute
|
||||
|
@ -77,7 +77,7 @@ protected:
|
|||
|
||||
private:
|
||||
//! The first expression to be evaluated
|
||||
CBotInstr* m_expr;
|
||||
std::unique_ptr<CBotInstr> m_expr;
|
||||
};
|
||||
|
||||
} // namespace CBot
|
||||
|
|
|
@ -35,15 +35,14 @@ CBotListInstr::CBotListInstr()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotListInstr::~CBotListInstr()
|
||||
{
|
||||
delete m_instr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal)
|
||||
std::unique_ptr<CBotInstr> CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal)
|
||||
{
|
||||
CBotCStack* pStk = pStack->TokenStack(p, bLocal); // variables are local
|
||||
|
||||
CBotListInstr* inst = new CBotListInstr();
|
||||
std::unique_ptr<CBotListInstr> inst(new CBotListInstr);
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
@ -55,22 +54,21 @@ CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal
|
|||
if (p->GetType() == TokenTypNone)
|
||||
{
|
||||
pStack->SetError(CBotErrCloseBlock, p->GetStart());
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
CBotInstr* i = CBotBlock::CompileBlkOrInst(p, pStk); // compiles next
|
||||
std::unique_ptr<CBotInstr> i = CBotBlock::CompileBlkOrInst(p, pStk); // compiles next
|
||||
|
||||
if (!pStk->IsOk())
|
||||
{
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
if (inst->m_instr == nullptr) inst->m_instr = i;
|
||||
else inst->m_instr->AddNext(i); // added a result
|
||||
if (inst->m_instr == nullptr) inst->m_instr = move(i);
|
||||
else inst->m_instr->AddNext(move(i)); // added a result
|
||||
}
|
||||
return pStack->Return(inst, pStk);
|
||||
pStack->Return(nullptr, pStk);
|
||||
return inst;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -81,10 +79,10 @@ bool CBotListInstr::Execute(CBotStack* &pj)
|
|||
if (pile->StackOver() ) return pj->Return( pile);
|
||||
|
||||
|
||||
CBotInstr* p = m_instr; // the first expression
|
||||
CBotInstr* p = m_instr.get(); // the first expression
|
||||
|
||||
int state = pile->GetState();
|
||||
while (state-->0) p = p->GetNext(); // returns to the interrupted operation
|
||||
while (state-->0) p = p->GetNext(); // returns to the interrupted operation
|
||||
|
||||
if (p != nullptr) while (true)
|
||||
{
|
||||
|
@ -105,7 +103,7 @@ void CBotListInstr::RestoreState(CBotStack* &pj, bool bMain)
|
|||
CBotStack* pile = pj->RestoreStack(this);
|
||||
if (pile == nullptr) return;
|
||||
|
||||
CBotInstr* p = m_instr; // the first expression
|
||||
CBotInstr* p = m_instr.get(); // the first expression
|
||||
|
||||
int state = pile->GetState();
|
||||
while ( p != nullptr && state-- > 0)
|
||||
|
@ -126,7 +124,7 @@ bool CBotListInstr::HasReturn()
|
|||
std::map<std::string, CBotInstr*> CBotListInstr::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_instr"] = m_instr;
|
||||
links["m_instr"] = m_instr.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
* \param bLocal
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true);
|
||||
|
||||
/*!
|
||||
* \brief Execute Executes a set of instructions.
|
||||
|
@ -69,7 +69,7 @@ protected:
|
|||
|
||||
private:
|
||||
//! Instructions to do.
|
||||
CBotInstr* m_instr;
|
||||
std::unique_ptr<CBotInstr> m_instr;
|
||||
};
|
||||
|
||||
} // namespace CBot
|
||||
|
|
|
@ -35,9 +35,6 @@ CBotLogicExpr::CBotLogicExpr()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotLogicExpr::~CBotLogicExpr()
|
||||
{
|
||||
delete m_condition;
|
||||
delete m_op1;
|
||||
delete m_op2;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -92,9 +89,9 @@ void CBotLogicExpr::RestoreState(CBotStack* &pStack, bool bMain)
|
|||
std::map<std::string, CBotInstr*> CBotLogicExpr::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_op1"] = m_op1;
|
||||
links["m_condition"] = m_condition;
|
||||
links["m_op2"] = m_op2;
|
||||
links["m_op1"] = m_op1.get();
|
||||
links["m_condition"] = m_condition.get();
|
||||
links["m_op2"] = m_op2.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,11 +56,11 @@ protected:
|
|||
|
||||
private:
|
||||
//! Test to evaluate
|
||||
CBotInstr* m_condition;
|
||||
std::unique_ptr<CBotInstr> m_condition;
|
||||
//! Left element
|
||||
CBotInstr* m_op1;
|
||||
std::unique_ptr<CBotInstr> m_op1;
|
||||
//! Right element
|
||||
CBotInstr* m_op2;
|
||||
std::unique_ptr<CBotInstr> m_op2;
|
||||
friend class CBotTwoOpExpr;
|
||||
};
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
|
||||
#include "CBot/CBotVar/CBotVar.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
|
@ -43,12 +45,10 @@ CBotNew::CBotNew()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotNew::~CBotNew()
|
||||
{
|
||||
delete m_parameters;
|
||||
delete m_exprRetVar;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotNew::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotToken* pp = p;
|
||||
if (!IsOfType(p, ID_NEW)) return nullptr;
|
||||
|
@ -67,7 +67,7 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
CBotNew* inst = new CBotNew();
|
||||
std::unique_ptr<CBotNew> inst = MakeUnique<CBotNew>();
|
||||
inst->SetToken(pp);
|
||||
|
||||
inst->m_vartoken = *p;
|
||||
|
@ -118,10 +118,9 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
}
|
||||
|
||||
if (pStack->IsOk())
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
error:
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
|
@ -176,7 +175,7 @@ bool CBotNew::Execute(CBotStack* &pj)
|
|||
|
||||
int i = 0;
|
||||
|
||||
CBotInstr* p = m_parameters;
|
||||
CBotInstr* p = m_parameters.get();
|
||||
// evaluate the parameters
|
||||
// and places the values on the stack
|
||||
// to be interrupted at any time
|
||||
|
@ -255,7 +254,7 @@ void CBotNew::RestoreState(CBotStack* &pj, bool bMain)
|
|||
|
||||
int i = 0;
|
||||
|
||||
CBotInstr* p = m_parameters;
|
||||
CBotInstr* p = m_parameters.get();
|
||||
// evaluate the parameters
|
||||
// and places the values on the stack
|
||||
// to be interrupted at any time
|
||||
|
@ -290,7 +289,8 @@ std::string CBotNew::GetDebugData()
|
|||
std::map<std::string, CBotInstr*> CBotNew::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_parameters"] = m_parameters;
|
||||
links["m_parameters"] = m_parameters.get();
|
||||
links["m_exprRetVar"] = m_exprRetVar.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute Executes instruction "new".
|
||||
|
@ -62,12 +62,12 @@ protected:
|
|||
|
||||
private:
|
||||
//! The parameters to be evaluated
|
||||
CBotInstr* m_parameters;
|
||||
std::unique_ptr<CBotInstr> m_parameters;
|
||||
long m_nMethodeIdent;
|
||||
CBotToken m_vartoken;
|
||||
|
||||
//! Instruction to chain method calls after constructor
|
||||
CBotInstr* m_exprRetVar;
|
||||
std::unique_ptr<CBotInstr> m_exprRetVar;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -36,11 +36,13 @@
|
|||
|
||||
#include "CBot/CBotCStack.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotCStack* pStk = pStack->TokenStack();
|
||||
|
||||
|
@ -49,37 +51,36 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
// is it an expression in parentheses?
|
||||
if (IsOfType(p, ID_OPENPAR))
|
||||
{
|
||||
CBotInstr* inst = CBotExpression::Compile(p, pStk);
|
||||
std::unique_ptr<CBotInstr> inst = CBotExpression::Compile(p, pStk);
|
||||
|
||||
if (nullptr != inst)
|
||||
{
|
||||
if (IsOfType(p, ID_CLOSEPAR))
|
||||
{
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
pStk->SetError(CBotErrClosePar, p->GetStart());
|
||||
}
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
// is this a unary operation?
|
||||
CBotInstr* inst = CBotExprUnaire::Compile(p, pStk);
|
||||
std::unique_ptr<CBotInstr> inst = CBotExprUnaire::Compile(p, pStk);
|
||||
if (inst != nullptr || !pStk->IsOk())
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
|
||||
// is it a variable name?
|
||||
if (p->GetType() == TokenTypVar)
|
||||
{
|
||||
// this may be a method call without the "this." before
|
||||
inst = CBotExprVar::CompileMethode(p, pStk);
|
||||
if (inst != nullptr) return pStack->Return(inst, pStk);
|
||||
if (inst != nullptr) return pStack->Return(move(inst), pStk);
|
||||
|
||||
|
||||
// is it a procedure call?
|
||||
inst = CBotInstrCall::Compile(p, pStk);
|
||||
if (inst != nullptr || !pStk->IsOk())
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
|
||||
|
||||
CBotToken* pvar = p;
|
||||
|
@ -91,7 +92,6 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
if (IsOfType(p, ID_INC, ID_DEC))
|
||||
{
|
||||
// recompile the variable for read-only
|
||||
delete inst;
|
||||
p = pvar;
|
||||
inst = CBotExprVar::Compile(p, pStk, true);
|
||||
// TODO: is there a possibility that something like ((((i++)++)++)++)... will recurse exponentially?
|
||||
|
@ -99,17 +99,17 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
if (pStk->GetVarType().GetType() >= CBotTypBoolean || pStk->GetVarType().GetType() == CBotTypVoid)
|
||||
{
|
||||
pStk->SetError(CBotErrBadType1, pp);
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
p = p->GetNext();
|
||||
|
||||
CBotPostIncExpr* i = new CBotPostIncExpr();
|
||||
// TODO: use unique_ptr here
|
||||
std::unique_ptr<CBotPostIncExpr> i = MakeUnique<CBotPostIncExpr>();
|
||||
i->SetToken(pp);
|
||||
i->m_instr = inst; // associated statement
|
||||
return pStack->Return(i, pStk);
|
||||
i->m_instr = move(inst); // associated statement
|
||||
return pStack->Return(move(i), pStk);
|
||||
}
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
|
||||
// pre increpemted or pre decremented?
|
||||
|
@ -122,12 +122,11 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
{
|
||||
if (pStk->GetVarType().GetType() < CBotTypBoolean && pStk->GetVarType().GetType() != CBotTypVoid) // a number ?
|
||||
{
|
||||
CBotPreIncExpr* i = new CBotPreIncExpr();
|
||||
std::unique_ptr<CBotPreIncExpr> i = MakeUnique<CBotPreIncExpr>();
|
||||
i->SetToken(pp);
|
||||
i->m_instr = inst;
|
||||
return pStack->Return(i, pStk);
|
||||
i->m_instr = move(inst);
|
||||
return pStack->Return(move(i), pStk);
|
||||
}
|
||||
delete inst;
|
||||
}
|
||||
}
|
||||
pStk->SetError(CBotErrBadType1, pp);
|
||||
|
@ -139,63 +138,63 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotParExpr::CompileLitExpr(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotParExpr::CompileLitExpr(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotCStack* pStk = pStack->TokenStack();
|
||||
|
||||
CBotToken* pp = p;
|
||||
|
||||
// is this a unary operation?
|
||||
CBotInstr* inst = CBotExprUnaire::Compile(p, pStk, true);
|
||||
std::unique_ptr<CBotInstr> inst = CBotExprUnaire::Compile(p, pStk, true);
|
||||
if (inst != nullptr || !pStk->IsOk())
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
|
||||
// is it a number or DefineNum?
|
||||
if (p->GetType() == TokenTypNum ||
|
||||
p->GetType() == TokenTypDef )
|
||||
{
|
||||
CBotInstr* inst = CBotExprLitNum::Compile(p, pStk);
|
||||
return pStack->Return(inst, pStk);
|
||||
inst = CBotExprLitNum::Compile(p, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
|
||||
// is this a chaine?
|
||||
if (p->GetType() == TokenTypString)
|
||||
{
|
||||
CBotInstr* inst = CBotExprLitString::Compile(p, pStk);
|
||||
return pStack->Return(inst, pStk);
|
||||
inst = CBotExprLitString::Compile(p, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
|
||||
// is a "true" or "false"
|
||||
if (p->GetType() == ID_TRUE ||
|
||||
p->GetType() == ID_FALSE )
|
||||
{
|
||||
CBotInstr* inst = CBotExprLitBool::Compile(p, pStk);
|
||||
return pStack->Return(inst, pStk);
|
||||
inst = CBotExprLitBool::Compile(p, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
|
||||
// is an object to be created with new
|
||||
if (p->GetType() == ID_NEW)
|
||||
{
|
||||
CBotInstr* inst = CBotNew::Compile(p, pStk);
|
||||
return pStack->Return(inst, pStk);
|
||||
inst = CBotNew::Compile(p, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
|
||||
// is a null pointer
|
||||
if (IsOfType(p, ID_NULL))
|
||||
{
|
||||
CBotInstr* inst = new CBotExprLitNull();
|
||||
inst = MakeUnique<CBotExprLitNull>();
|
||||
inst->SetToken(pp);
|
||||
pStk->SetVarType(CBotTypNullPointer);
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
|
||||
// is a number nan
|
||||
if (IsOfType(p, ID_NAN))
|
||||
{
|
||||
CBotInstr* inst = new CBotExprLitNan();
|
||||
inst = MakeUnique<CBotExprLitNan>();
|
||||
inst->SetToken(pp);
|
||||
pStk->SetVarType(CBotTypInt);
|
||||
return pStack->Return(inst, pStk);
|
||||
return pStack->Return(move(inst), pStk);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Compile a literal expression ("string", number, true, false, null, nan, new)
|
||||
|
@ -60,7 +60,7 @@ public:
|
|||
* \param pStack Current compilation stack frame
|
||||
* \return The compiled instruction or nullptr on error
|
||||
*/
|
||||
static CBotInstr* CompileLitExpr(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> CompileLitExpr(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
private:
|
||||
CBotParExpr() = delete;
|
||||
|
|
|
@ -36,7 +36,6 @@ CBotPostIncExpr::CBotPostIncExpr()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotPostIncExpr::~CBotPostIncExpr()
|
||||
{
|
||||
delete m_instr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -48,7 +47,7 @@ bool CBotPostIncExpr::Execute(CBotStack* &pj)
|
|||
CBotVar* var1 = nullptr;
|
||||
|
||||
// retrieves the variable fields and indexes according
|
||||
if (!(static_cast<CBotExprVar*>(m_instr))->ExecuteVar(var1, pile2, nullptr, true)) return false;
|
||||
if (!(static_cast<CBotExprVar*>(m_instr.get()))->ExecuteVar(var1, pile2, nullptr, true)) return false;
|
||||
|
||||
pile1->SetState(1);
|
||||
pile1->SetCopyVar(var1); // places the result (before incrementation);
|
||||
|
@ -80,7 +79,7 @@ void CBotPostIncExpr::RestoreState(CBotStack* &pj, bool bMain)
|
|||
CBotStack* pile1 = pj->RestoreStack(this);
|
||||
if (pile1 == nullptr) return;
|
||||
|
||||
(static_cast<CBotExprVar*>(m_instr))->RestoreStateVar(pile1, bMain);
|
||||
(static_cast<CBotExprVar*>(m_instr.get()))->RestoreStateVar(pile1, bMain);
|
||||
|
||||
if (pile1 != nullptr) pile1->RestoreStack(this);
|
||||
}
|
||||
|
@ -88,7 +87,7 @@ void CBotPostIncExpr::RestoreState(CBotStack* &pj, bool bMain)
|
|||
std::map<std::string, CBotInstr*> CBotPostIncExpr::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_instr"] = m_instr;
|
||||
links["m_instr"] = m_instr.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ protected:
|
|||
virtual std::map<std::string, CBotInstr*> GetDebugLinks() override;
|
||||
|
||||
private:
|
||||
CBotInstr* m_instr;
|
||||
std::unique_ptr<CBotInstr> m_instr;
|
||||
friend class CBotParExpr;
|
||||
};
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ CBotPreIncExpr::CBotPreIncExpr()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotPreIncExpr::~CBotPreIncExpr()
|
||||
{
|
||||
delete m_instr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -53,7 +52,7 @@ bool CBotPreIncExpr::Execute(CBotStack* &pj)
|
|||
CBotStack* pile2 = pile;
|
||||
// retrieves the variable fields and indexes according
|
||||
// pile2 is modified on return
|
||||
if (!(static_cast<CBotExprVar*>(m_instr))->ExecuteVar(var1, pile2, nullptr, true)) return false;
|
||||
if (!(static_cast<CBotExprVar*>(m_instr.get()))->ExecuteVar(var1, pile2, nullptr, true)) return false;
|
||||
|
||||
if (var1->IsNAN())
|
||||
{
|
||||
|
@ -96,7 +95,7 @@ void CBotPreIncExpr::RestoreState(CBotStack* &pj, bool bMain)
|
|||
std::map<std::string, CBotInstr*> CBotPreIncExpr::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_instr"] = m_instr;
|
||||
links["m_instr"] = m_instr.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ protected:
|
|||
virtual std::map<std::string, CBotInstr*> GetDebugLinks() override;
|
||||
|
||||
private:
|
||||
CBotInstr* m_instr;
|
||||
std::unique_ptr<CBotInstr> m_instr;
|
||||
friend class CBotParExpr;
|
||||
};
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include "CBot/CBotStack.h"
|
||||
#include "CBot/CBotCStack.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
|
@ -38,17 +40,16 @@ CBotReturn::CBotReturn()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotReturn::~CBotReturn()
|
||||
{
|
||||
delete m_instr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotReturn::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotReturn::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotToken* pp = p;
|
||||
|
||||
if (!IsOfType(p, ID_RETURN)) return nullptr; // should never happen
|
||||
|
||||
CBotReturn* inst = new CBotReturn(); // creates the object
|
||||
std::unique_ptr<CBotReturn> inst = MakeUnique<CBotReturn>(); // creates the object
|
||||
inst->SetToken( pp );
|
||||
|
||||
CBotTypResult type = pStack->GetRetType();
|
||||
|
@ -76,7 +77,6 @@ CBotInstr* CBotReturn::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
pStack->SetError(CBotErrBadType1, p->GetStart());
|
||||
}
|
||||
|
||||
delete inst;
|
||||
return nullptr; // no object, the error is on the stack
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ bool CBotReturn::HasReturn()
|
|||
std::map<std::string, CBotInstr*> CBotReturn::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_instr"] = m_instr;
|
||||
links["m_instr"] = m_instr.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute
|
||||
|
@ -67,7 +67,7 @@ protected:
|
|||
|
||||
private:
|
||||
//! Parameter of return
|
||||
CBotInstr* m_instr;
|
||||
std::unique_ptr<CBotInstr> m_instr;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "CBot/CBotStack.h"
|
||||
#include "CBot/CBotCStack.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
|
@ -38,14 +40,12 @@ CBotSwitch::CBotSwitch()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotSwitch::~CBotSwitch()
|
||||
{
|
||||
delete m_value; // frees the value
|
||||
delete m_block; // frees the instruction block
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotSwitch* inst = new CBotSwitch(); // creates the object
|
||||
std::unique_ptr<CBotSwitch> inst = MakeUnique<CBotSwitch>(); // creates the object
|
||||
CBotToken* pp = p; // preserves at the ^ token (starting position)
|
||||
|
||||
inst->SetToken(p);
|
||||
|
@ -71,38 +71,34 @@ CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
{
|
||||
CBotCStack* pStk2 = pStk->TokenStack(p); // un petit bout de pile svp
|
||||
|
||||
CBotInstr* i = CBotCase::Compile( p, pStk2 );
|
||||
std::unique_ptr<CBotInstr> i = CBotCase::Compile( p, pStk2 );
|
||||
if (i == nullptr)
|
||||
{
|
||||
delete inst;
|
||||
pStk->Return(nullptr, pStk2);
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
delete pStk2;
|
||||
if (inst->m_block == nullptr ) inst->m_block = i;
|
||||
else inst->m_block->AddNext(i);
|
||||
if (inst->m_block == nullptr ) inst->m_block = move(i);
|
||||
else inst->m_block->AddNext(move(i));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (inst->m_block == nullptr )
|
||||
{
|
||||
pStk->SetError(CBotErrNoCase, p->GetStart());
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
CBotInstr* i = CBotBlock::CompileBlkOrInst( p, pStk, true );
|
||||
std::unique_ptr<CBotInstr> i = CBotBlock::CompileBlkOrInst( p, pStk, true );
|
||||
if ( !pStk->IsOk() )
|
||||
{
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
inst->m_block->AddNext(i);
|
||||
inst->m_block->AddNext(move(i));
|
||||
|
||||
if ( p == nullptr )
|
||||
{
|
||||
pStk->SetError(CBotErrCloseBlock, -1);
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
}
|
||||
|
@ -111,11 +107,10 @@ CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
if (inst->m_block == nullptr )
|
||||
{
|
||||
pStk->SetError(CBotErrNoCase, p->GetStart());
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
// the statement block is ok
|
||||
return pStack->Return(inst, pStk); // return an object to the application
|
||||
return pStack->Return(move(inst), pStk); // return an object to the application
|
||||
}
|
||||
pStk->SetError( CBotErrOpenBlock, p->GetStart() );
|
||||
}
|
||||
|
@ -126,7 +121,6 @@ CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
}
|
||||
pStk->SetError( CBotErrOpenPar, p->GetStart());
|
||||
|
||||
delete inst; // error, frees up
|
||||
return pStack->Return(nullptr, pStk); // no object, the error is on the stack
|
||||
}
|
||||
|
||||
|
@ -136,7 +130,7 @@ bool CBotSwitch :: Execute(CBotStack* &pj)
|
|||
CBotStack* pile1 = pj->AddStack(this); // adds an item to the stack
|
||||
// if ( pile1 == EOX ) return true;
|
||||
|
||||
CBotInstr* p = m_block; // first expression
|
||||
CBotInstr* p = m_block.get(); // first expression
|
||||
|
||||
int state = pile1->GetState();
|
||||
if (state == 0)
|
||||
|
@ -166,7 +160,7 @@ bool CBotSwitch :: Execute(CBotStack* &pj)
|
|||
if ( !pile1->SetState(state) ) return false;
|
||||
}
|
||||
|
||||
p = m_block; // returns to the beginning
|
||||
p = m_block.get(); // returns to the beginning
|
||||
while (state-->0) p = p->GetNext(); // advance in the list
|
||||
|
||||
while( p != nullptr )
|
||||
|
@ -186,7 +180,7 @@ void CBotSwitch :: RestoreState(CBotStack* &pj, bool bMain)
|
|||
CBotStack* pile1 = pj->RestoreStack(this); // adds an item to the stack
|
||||
if ( pile1 == nullptr ) return;
|
||||
|
||||
CBotInstr* p = m_block; // first expression
|
||||
CBotInstr* p = m_block.get(); // first expression
|
||||
|
||||
int state = pile1->GetState();
|
||||
if (state == 0)
|
||||
|
@ -217,8 +211,8 @@ void CBotSwitch :: RestoreState(CBotStack* &pj, bool bMain)
|
|||
std::map<std::string, CBotInstr*> CBotSwitch::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_value"] = m_value;
|
||||
links["m_block"] = m_block;
|
||||
links["m_value"] = m_value.get();
|
||||
links["m_block"] = m_block.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute Executes instruction "switch".
|
||||
|
@ -63,9 +63,9 @@ protected:
|
|||
|
||||
private:
|
||||
//! Value to seek
|
||||
CBotInstr* m_value;
|
||||
std::unique_ptr<CBotInstr> m_value;
|
||||
//! Instructions
|
||||
CBotInstr* m_block;
|
||||
std::unique_ptr<CBotInstr> m_block;
|
||||
};
|
||||
|
||||
} // namespace CBot
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "CBot/CBotStack.h"
|
||||
#include "CBot/CBotCStack.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
|
@ -35,15 +37,14 @@ CBotThrow::CBotThrow()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotThrow::~CBotThrow()
|
||||
{
|
||||
delete m_value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotThrow::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotThrow::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
pStack->SetStartError(p->GetStart());
|
||||
|
||||
CBotThrow* inst = new CBotThrow(); // creates the object
|
||||
std::unique_ptr<CBotThrow> inst = MakeUnique<CBotThrow>(); // creates the object
|
||||
inst->SetToken(p);
|
||||
|
||||
CBotToken* pp = p; // preserves at the ^ token (starting position)
|
||||
|
@ -58,7 +59,6 @@ CBotInstr* CBotThrow::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
}
|
||||
pStack->SetError(CBotErrBadType1, pp);
|
||||
|
||||
delete inst; // error, frees up
|
||||
return nullptr; // no object, the error is on the stack
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ void CBotThrow::RestoreState(CBotStack* &pj, bool bMain)
|
|||
std::map<std::string, CBotInstr*> CBotThrow::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_value"] = m_value;
|
||||
links["m_value"] = m_value.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute Execution of instruction "throw".
|
||||
|
@ -61,7 +61,7 @@ protected:
|
|||
|
||||
private:
|
||||
//! The value to send.
|
||||
CBotInstr* m_value;
|
||||
std::unique_ptr<CBotInstr> m_value;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include "CBot/CBotStack.h"
|
||||
#include "CBot/CBotCStack.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
|
@ -38,30 +40,28 @@ CBotTry::CBotTry()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotTry::~CBotTry()
|
||||
{
|
||||
delete m_catchList; // frees the list
|
||||
delete m_block; // frees the instruction block
|
||||
delete m_finallyBlock;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotTry::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotTry::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotTry* inst = new CBotTry(); // creates the object
|
||||
std::unique_ptr<CBotTry> inst = MakeUnique<CBotTry>(); // creates the object
|
||||
CBotToken* pp = p; // preserves at the ^ token (starting position)
|
||||
|
||||
inst->SetToken(p);
|
||||
if (!IsOfType(p, ID_TRY)) return nullptr; // should never happen
|
||||
if (!IsOfType(p, ID_TRY)) return nullptr; // should never happen
|
||||
|
||||
CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp
|
||||
|
||||
inst->m_block = CBotBlock::CompileBlkOrInst(p, pStk );
|
||||
CBotCatch** pn = &inst->m_catchList;
|
||||
std::unique_ptr<CBotCatch>* pn = &inst->m_catchList;
|
||||
|
||||
while (pStk->IsOk() && p->GetType() == ID_CATCH)
|
||||
{
|
||||
CBotCatch* i = CBotCatch::Compile(p, pStk);
|
||||
*pn = i;
|
||||
pn = &i->m_next;
|
||||
std::unique_ptr<CBotCatch> i = CBotCatch::Compile(p, pStk);
|
||||
std::unique_ptr<CBotCatch>* pn_next = &i->m_next;
|
||||
*pn = move(i);
|
||||
pn = pn_next;
|
||||
}
|
||||
|
||||
if (pStk->IsOk() && IsOfType( p, ID_FINALLY) )
|
||||
|
@ -71,10 +71,9 @@ CBotInstr* CBotTry::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
|
||||
if (pStk->IsOk())
|
||||
{
|
||||
return pStack->Return(inst, pStk); // return an object to the application
|
||||
return pStack->Return(move(inst), pStk); // return an object to the application
|
||||
}
|
||||
|
||||
delete inst; // error, frees up
|
||||
return pStack->Return(nullptr, pStk); // no object, the error is on the stack
|
||||
}
|
||||
|
||||
|
@ -115,7 +114,7 @@ bool CBotTry::Execute(CBotStack* &pj)
|
|||
// there was an interruption
|
||||
// see what it returns
|
||||
|
||||
CBotCatch* pc = m_catchList;
|
||||
CBotCatch* pc = m_catchList.get();
|
||||
int state = static_cast<short>(pile1->GetState()); // where were we?
|
||||
val = pile2->GetState(); // what error?
|
||||
pile0->SetState(1); // marking the GetRunPos
|
||||
|
@ -144,7 +143,7 @@ bool CBotTry::Execute(CBotStack* &pj)
|
|||
}
|
||||
pile1->IncState();
|
||||
}
|
||||
pc = pc->m_next;
|
||||
pc = pc->m_next.get();
|
||||
}
|
||||
if (m_finallyBlock != nullptr &&
|
||||
pile1->GetState() > 0 && val != 0 ) pile1->SetState(-1);// if stop then made the final
|
||||
|
@ -192,7 +191,7 @@ void CBotTry::RestoreState(CBotStack* &pj, bool bMain)
|
|||
// there was an interruption
|
||||
// see what it returns
|
||||
|
||||
CBotCatch* pc = m_catchList;
|
||||
CBotCatch* pc = m_catchList.get();
|
||||
int state = pile1->GetState(); // where were we ?
|
||||
val = pile2->GetState(); // what error ?
|
||||
|
||||
|
@ -213,7 +212,7 @@ void CBotTry::RestoreState(CBotStack* &pj, bool bMain)
|
|||
return;
|
||||
}
|
||||
}
|
||||
pc = pc->m_next;
|
||||
pc = pc->m_next.get();
|
||||
}
|
||||
|
||||
if (pile1->GetState() <= -1)
|
||||
|
@ -226,9 +225,9 @@ void CBotTry::RestoreState(CBotStack* &pj, bool bMain)
|
|||
std::map<std::string, CBotInstr*> CBotTry::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_block"] = m_block;
|
||||
links["m_catchList"] = m_catchList;
|
||||
links["m_finallyBlock"] = m_finallyBlock;
|
||||
links["m_block"] = m_block.get();
|
||||
links["m_catchList"] = m_catchList.get();
|
||||
links["m_finallyBlock"] = m_finallyBlock.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
/*!
|
||||
* \brief Execute Execution of instruction Try manages the return of
|
||||
|
@ -64,11 +64,11 @@ protected:
|
|||
|
||||
private:
|
||||
//! Instructions
|
||||
CBotInstr* m_block;
|
||||
//! Catches
|
||||
CBotCatch* m_catchList;
|
||||
std::unique_ptr<CBotInstr> m_block;
|
||||
//! Catches (TODO: should be a vector<unique_ptr<CBotCatch>>)
|
||||
std::unique_ptr<CBotCatch> m_catchList;
|
||||
//! Final instruction
|
||||
CBotInstr* m_finallyBlock;
|
||||
std::unique_ptr<CBotInstr> m_finallyBlock;
|
||||
};
|
||||
|
||||
} // namespace CBot
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
|
||||
#include "CBot/CBotVar/CBotVar.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -46,8 +48,6 @@ CBotTwoOpExpr::CBotTwoOpExpr()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotTwoOpExpr::~CBotTwoOpExpr()
|
||||
{
|
||||
delete m_leftop;
|
||||
delete m_rightop;
|
||||
}
|
||||
|
||||
// This list contains all possible operations
|
||||
|
@ -134,7 +134,7 @@ static bool TypeOk(int type, int test)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations)
|
||||
std::unique_ptr<CBotInstr> CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations)
|
||||
{
|
||||
int typeMask;
|
||||
|
||||
|
@ -145,7 +145,7 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
|
|||
CBotCStack* pStk = pStack->TokenStack(); // one end of stack please
|
||||
|
||||
// search the intructions that may be suitable to the left of the operation
|
||||
CBotInstr* left = (*pOp == 0) ?
|
||||
std::unique_ptr<CBotInstr> left = (*pOp == 0) ?
|
||||
CBotParExpr::Compile( p, pStk ) : // expression (...) left
|
||||
CBotTwoOpExpr::Compile( p, pStk, pOp ); // expression A * B left
|
||||
|
||||
|
@ -165,8 +165,8 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
|
|||
pStk->SetError( CBotErrBadType1, p);
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
CBotLogicExpr* inst = new CBotLogicExpr();
|
||||
inst->m_condition = left;
|
||||
std::unique_ptr<CBotLogicExpr> inst(new CBotLogicExpr);
|
||||
inst->m_condition = move(left);
|
||||
|
||||
p = p->GetNext(); // skip the token of the operation
|
||||
inst->m_op1 = CBotExpression::Compile(p, pStk);
|
||||
|
@ -174,7 +174,6 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
|
|||
if ( inst->m_op1 == nullptr || !IsOfType( p, ID_DOTS ) )
|
||||
{
|
||||
pStk->SetError( CBotErrNoDoubleDots, p->GetStart());
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
type1 = pStk->GetVarType();
|
||||
|
@ -183,23 +182,22 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
|
|||
if ( inst->m_op2 == nullptr )
|
||||
{
|
||||
pStk->SetError( CBotErrNoTerminator, p->GetStart() );
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
type2 = pStk->GetVarType();
|
||||
if (!TypeCompatible(type1, type2))
|
||||
{
|
||||
pStk->SetError( CBotErrBadType2, pp );
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
pStk->SetVarType(type1); // the greatest of 2 types
|
||||
|
||||
return pStack->Return(inst, pStk);
|
||||
pStack->Return(nullptr, pStk);
|
||||
return inst;
|
||||
}
|
||||
|
||||
CBotTwoOpExpr* inst = new CBotTwoOpExpr(); // element for operation
|
||||
std::unique_ptr<CBotTwoOpExpr> inst(new CBotTwoOpExpr); // element for operation
|
||||
inst->SetToken(p); // stores the operation
|
||||
|
||||
|
||||
|
@ -217,7 +215,6 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
|
|||
if ( type1.Eq(CBotTypVoid) || type2.Eq(CBotTypVoid) ) // operand is void
|
||||
{
|
||||
pStk->SetError(CBotErrBadType2, &inst->m_token);
|
||||
delete inst;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
|
@ -252,15 +249,15 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
|
|||
if ( TypeCompatible (type1, type2, typeOp) ) // the results are compatible
|
||||
{
|
||||
// ok so, saves the operand in the object
|
||||
inst->m_leftop = left;
|
||||
inst->m_leftop = move(left);
|
||||
|
||||
// special for evaluation of the operations of the same level from left to right
|
||||
while ( IsInList(p->GetType(), pOperations, typeMask) ) // same operation(s) follows?
|
||||
{
|
||||
typeOp = p->GetType();
|
||||
CBotTwoOpExpr* i = new CBotTwoOpExpr(); // element for operation
|
||||
std::unique_ptr<CBotTwoOpExpr> i = MakeUnique<CBotTwoOpExpr>(); // element for operation
|
||||
i->SetToken(p); // stores the operation
|
||||
i->m_leftop = inst; // left operand
|
||||
i->m_leftop = move(inst); // left operand
|
||||
type1 = TypeRes;
|
||||
|
||||
p = p->GetNext(); // advance after
|
||||
|
@ -270,13 +267,12 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
|
|||
if ( !TypeCompatible (type1, type2, typeOp) ) // the results are compatible
|
||||
{
|
||||
pStk->SetError(CBotErrBadType2, &i->m_token);
|
||||
delete i;
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
if ( TypeRes != CBotTypString ) // keep string conversion
|
||||
TypeRes = std::max(type1.GetType(), type2.GetType());
|
||||
inst = i;
|
||||
inst = move(i);
|
||||
}
|
||||
|
||||
CBotTypResult t(type1);
|
||||
|
@ -285,22 +281,20 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
|
|||
pStk->SetVarType(t);
|
||||
|
||||
// and returns the requested object
|
||||
return pStack->Return(inst, pStk);
|
||||
pStack->Return(nullptr, pStk);
|
||||
return inst;
|
||||
}
|
||||
pStk->SetError(CBotErrBadType2, &inst->m_token);
|
||||
}
|
||||
|
||||
// in case of error, releases the elements
|
||||
delete left;
|
||||
delete inst;
|
||||
// and transmits the error to the stack
|
||||
// in case of error, transmits the error to the stack
|
||||
return pStack->Return(nullptr, pStk);
|
||||
}
|
||||
|
||||
// if we are not dealing with an operation + or -
|
||||
// goes to that requested, the operand (left) found
|
||||
// instead of the object "addition"
|
||||
return pStack->Return(left, pStk);
|
||||
return pStack->Return(move(left), pStk);
|
||||
}
|
||||
|
||||
|
||||
|
@ -544,8 +538,8 @@ std::string CBotTwoOpExpr::GetDebugData()
|
|||
std::map<std::string, CBotInstr*> CBotTwoOpExpr::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_leftop"] = m_leftop;
|
||||
links["m_rightop"] = m_rightop;
|
||||
links["m_leftop"] = m_leftop.get();
|
||||
links["m_rightop"] = m_rightop.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
* \param pOperations
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations = nullptr);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations = nullptr);
|
||||
|
||||
/*!
|
||||
* \brief Execute Performes the operation on two operands.
|
||||
|
@ -88,9 +88,9 @@ protected:
|
|||
|
||||
private:
|
||||
//! Left element
|
||||
CBotInstr* m_leftop;
|
||||
std::unique_ptr<CBotInstr> m_leftop;
|
||||
//! Right element
|
||||
CBotInstr* m_rightop;
|
||||
std::unique_ptr<CBotInstr> m_rightop;
|
||||
};
|
||||
|
||||
} // namespace CBot
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include "CBot/CBotStack.h"
|
||||
#include "CBot/CBotCStack.h"
|
||||
|
||||
#include "common/make_unique.h"
|
||||
|
||||
namespace CBot
|
||||
{
|
||||
|
||||
|
@ -37,14 +39,12 @@ CBotWhile::CBotWhile()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotWhile::~CBotWhile()
|
||||
{
|
||||
delete m_condition; // frees the condition
|
||||
delete m_block; // releases the block instruction
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotInstr* CBotWhile::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
std::unique_ptr<CBotInstr> CBotWhile::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||
{
|
||||
CBotWhile* inst = new CBotWhile(); // creates the object
|
||||
std::unique_ptr<CBotWhile> inst = MakeUnique<CBotWhile>(); // creates the object
|
||||
CBotToken* pp = p; // preserves at the ^ token (starting position)
|
||||
|
||||
if ( IsOfType( p, TokenTypVar ) &&
|
||||
|
@ -71,12 +71,11 @@ CBotInstr* CBotWhile::Compile(CBotToken* &p, CBotCStack* pStack)
|
|||
{
|
||||
// the statement block is ok (it may be empty!
|
||||
|
||||
return pStack->Return(inst, pStk); // return an object to the application
|
||||
return pStack->Return(move(inst), pStk); // return an object to the application
|
||||
// makes the object to which the application
|
||||
}
|
||||
}
|
||||
|
||||
delete inst; // error, frees the place
|
||||
return pStack->Return(nullptr, pStk); // no object, the error is on the stack
|
||||
}
|
||||
|
||||
|
@ -157,8 +156,8 @@ std::string CBotWhile::GetDebugData()
|
|||
std::map<std::string, CBotInstr*> CBotWhile::GetDebugLinks()
|
||||
{
|
||||
auto links = CBotInstr::GetDebugLinks();
|
||||
links["m_condition"] = m_condition;
|
||||
links["m_block"] = m_block;
|
||||
links["m_condition"] = m_condition.get();
|
||||
links["m_block"] = m_block.get();
|
||||
return links;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
* \param pStack
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
static std::unique_ptr<CBotInstr> Compile(CBotToken* &p, CBotCStack* pStack);
|
||||
|
||||
// executes a "while" instruction
|
||||
/*!
|
||||
|
@ -71,9 +71,9 @@ protected:
|
|||
|
||||
private:
|
||||
//! Condition
|
||||
CBotInstr* m_condition;
|
||||
std::unique_ptr<CBotInstr> m_condition;
|
||||
//! Instructions
|
||||
CBotInstr* m_block;
|
||||
std::unique_ptr<CBotInstr> m_block;
|
||||
//! A label if there is
|
||||
std::string m_label;
|
||||
};
|
||||
|
|
|
@ -232,11 +232,11 @@ public:
|
|||
|
||||
//! Expression describing initial value
|
||||
//! TODO: make private
|
||||
CBotInstr* m_InitExpr;
|
||||
std::unique_ptr<CBotInstr> m_InitExpr;
|
||||
|
||||
//! Expression describing array limit
|
||||
//! TODO: make private
|
||||
CBotInstr* m_LimExpr;
|
||||
std::unique_ptr<CBotInstr> m_LimExpr;
|
||||
|
||||
private:
|
||||
CBotToken m_name;
|
||||
|
|
|
@ -170,7 +170,7 @@ void CBotVarClass::InitFieldsForClass(CBotClass *pClass)
|
|||
for (std::unique_ptr<CBotVariable> &pv : pClass->GetVar())
|
||||
{
|
||||
// seeks the maximum dimensions of the table
|
||||
CBotInstr* p = pv->m_LimExpr; // the different formulas
|
||||
CBotInstr* p = pv->m_LimExpr.get(); // the different formulas
|
||||
if ( p != nullptr )
|
||||
{
|
||||
CBotStack* pile = CBotStack::AllocateStack(); // an independent stack
|
||||
|
@ -180,14 +180,14 @@ void CBotVarClass::InitFieldsForClass(CBotClass *pClass)
|
|||
while (p != nullptr)
|
||||
{
|
||||
while( pile->IsOk() && !p->Execute(pile) ) ; // calculate size without interruptions
|
||||
CBotVar* v = pile->GetVar(); // result
|
||||
CBotVar* v = pile->GetVar(); // result
|
||||
max[n] = v->GetValInt(); // value
|
||||
n++;
|
||||
p = p->GetNext3();
|
||||
}
|
||||
while (n<100) max[n++] = 0;
|
||||
|
||||
pv->m_value->m_type.SetArray(max); // stores the limitations
|
||||
pv->m_value->m_type.SetArray(max); // stores the limitations
|
||||
pile->Delete();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue