Made CBotExternalCallList not static
parent
8e01a208c1
commit
ae544c71ae
|
@ -351,7 +351,7 @@ CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nId
|
|||
nIdent = 0;
|
||||
CBotTypResult val(-1);
|
||||
|
||||
val = CBotExternalCallList::CompileCall(p, ppVars, this);
|
||||
val = m_prog->GetExternalCalls()->CompileCall(p, ppVars, this);
|
||||
if (val.GetType() < 0)
|
||||
{
|
||||
val = m_prog->GetFunctions()->CompileCall(p->GetString(), ppVars, nIdent);
|
||||
|
@ -371,7 +371,7 @@ bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
|
|||
{
|
||||
std::string name = pToken->GetString();
|
||||
|
||||
if ( CBotExternalCallList::CheckCall(name) ) return true;
|
||||
if ( m_prog->GetExternalCalls()->CheckCall(name) ) return true;
|
||||
|
||||
CBotFunction* pp = m_prog->GetFunctions();
|
||||
while ( pp != nullptr )
|
||||
|
|
|
@ -495,12 +495,11 @@ bool CBotClass::RestoreStaticState(FILE* pf)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool CBotClass::CheckCall(CBotToken* &pToken,
|
||||
CBotDefParam* pParam)
|
||||
bool CBotClass::CheckCall(CBotProgram* program, CBotDefParam* pParam, CBotToken*& pToken)
|
||||
{
|
||||
std::string name = pToken->GetString();
|
||||
|
||||
if ( CBotExternalCallList::CheckCall(name) ) return true;
|
||||
if ( program->GetExternalCalls()->CheckCall(name) ) return true;
|
||||
|
||||
CBotFunction* pp = m_pMethod;
|
||||
while ( pp != nullptr )
|
||||
|
|
|
@ -354,8 +354,7 @@ public:
|
|||
* \param pParam
|
||||
* \return
|
||||
*/
|
||||
bool CheckCall(CBotToken* &pToken,
|
||||
CBotDefParam* pParam);
|
||||
bool CheckCall(CBotProgram* program, CBotDefParam* pParam, CBotToken*& pToken);
|
||||
|
||||
private:
|
||||
//! List of classes existing at a given time.
|
||||
|
|
|
@ -26,10 +26,6 @@
|
|||
|
||||
#include "CBot/CBotVar/CBotVar.h"
|
||||
|
||||
|
||||
std::map<std::string, std::unique_ptr<CBotExternalCall>> CBotExternalCallList::m_list{};
|
||||
void* CBotExternalCallList::m_user = nullptr;
|
||||
|
||||
void CBotExternalCallList::Clear()
|
||||
{
|
||||
m_list.clear();
|
||||
|
|
|
@ -115,7 +115,7 @@ public:
|
|||
* \param call Function to add
|
||||
* \return true
|
||||
*/
|
||||
static bool AddFunction(const std::string& name, std::unique_ptr<CBotExternalCall> call);
|
||||
bool AddFunction(const std::string& name, std::unique_ptr<CBotExternalCall> call);
|
||||
|
||||
/**
|
||||
* \brief Find and call compile function
|
||||
|
@ -127,14 +127,14 @@ public:
|
|||
* \param pStack Compilation stack
|
||||
* \return CBotTypResult representing the return type of the function (::CBotTypVar), or an error (::CBotError)
|
||||
*/
|
||||
static CBotTypResult CompileCall(CBotToken*& p, CBotVar** ppVars, CBotCStack* pStack);
|
||||
CBotTypResult CompileCall(CBotToken*& p, CBotVar** ppVars, CBotCStack* pStack);
|
||||
|
||||
/**
|
||||
* \brief Check if function with given name has been defined
|
||||
* \param name Name to check
|
||||
* \return true if function was defined
|
||||
*/
|
||||
static bool CheckCall(const std::string& name);
|
||||
bool CheckCall(const std::string& name);
|
||||
|
||||
/**
|
||||
* \brief Find and call runtime function
|
||||
|
@ -147,7 +147,7 @@ public:
|
|||
* \param rettype Return type of the function, as returned by CompileCall()
|
||||
* \return -1 if call failed (no such function), 0 if function requested interruption, 1 on success
|
||||
*/
|
||||
static int DoCall(CBotToken* token, CBotVar** ppVars, CBotStack* pStack, const CBotTypResult& rettype);
|
||||
int DoCall(CBotToken* token, CBotVar** ppVars, CBotStack* pStack, const CBotTypResult& rettype);
|
||||
|
||||
/**
|
||||
* \brief Restore execution status after loading saved state
|
||||
|
@ -157,7 +157,7 @@ public:
|
|||
* \param pStack Runtime stack
|
||||
* \return false on failure (e.g. function doesn't exist)
|
||||
*/
|
||||
static bool RestoreCall(CBotToken* token, CBotVar** ppVar, CBotStack* pStack);
|
||||
bool RestoreCall(CBotToken* token, CBotVar** ppVar, CBotStack* pStack);
|
||||
|
||||
/**
|
||||
* \brief Set user pointer to pass to compile functions
|
||||
|
@ -166,14 +166,14 @@ public:
|
|||
*
|
||||
* \param pUser User pointer
|
||||
*/
|
||||
static void SetUserPtr(void* pUser);
|
||||
void SetUserPtr(void* pUser);
|
||||
|
||||
/**
|
||||
* \brief Reset the list of registered functions
|
||||
*/
|
||||
static void Clear();
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
static std::map<std::string, std::unique_ptr<CBotExternalCall>> m_list;
|
||||
static void* m_user;
|
||||
std::map<std::string, std::unique_ptr<CBotExternalCall>> m_list{};
|
||||
void* m_user = nullptr;
|
||||
};
|
|
@ -315,7 +315,7 @@ CBotFunction* CBotFunction::Compile1(CBotToken* &p, CBotCStack* pStack, CBotClas
|
|||
{
|
||||
// looks if the function exists elsewhere
|
||||
if (( pClass != nullptr || !pStack->CheckCall(pp, func->m_Param)) &&
|
||||
( pClass == nullptr || !pClass->CheckCall(pp, func->m_Param)) )
|
||||
( pClass == nullptr || !pClass->CheckCall(pStack->GetProgram(), func->m_Param, pp)) )
|
||||
{
|
||||
if (IsOfType(p, ID_OPBLK))
|
||||
{
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
|
||||
#include "CBot/stdlib/stdlib.h"
|
||||
|
||||
CBotExternalCallList* CBotProgram::m_externalCalls = new CBotExternalCallList();
|
||||
|
||||
CBotProgram::CBotProgram()
|
||||
{
|
||||
}
|
||||
|
@ -77,7 +79,7 @@ bool CBotProgram::Compile(const std::string& program, std::vector<std::string>&
|
|||
CBotToken* p = tokens.get()->GetNext(); // skips the first token (separator)
|
||||
|
||||
pStack->SetProgram(this); // defined used routines
|
||||
CBotExternalCallList::SetUserPtr(pUser);
|
||||
m_externalCalls->SetUserPtr(pUser);
|
||||
|
||||
// Step 2. Find all function and class definitions
|
||||
while ( pStack->IsOk() && p != nullptr && p->GetType() != 0)
|
||||
|
@ -312,7 +314,7 @@ bool CBotProgram::AddFunction(const std::string& name,
|
|||
bool rExec(CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
|
||||
CBotTypResult rCompile(CBotVar*& pVar, void* pUser))
|
||||
{
|
||||
return CBotExternalCallList::AddFunction(name, std::unique_ptr<CBotExternalCall>(new CBotExternalCallDefault(rExec, rCompile)));
|
||||
return m_externalCalls->AddFunction(name, std::unique_ptr<CBotExternalCall>(new CBotExternalCallDefault(rExec, rCompile)));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -435,6 +437,11 @@ void CBotProgram::Init()
|
|||
void CBotProgram::Free()
|
||||
{
|
||||
CBotToken::ClearDefineNum();
|
||||
CBotExternalCallList::Clear();
|
||||
m_externalCalls->Clear();
|
||||
CBotClass::Free();
|
||||
}
|
||||
}
|
||||
|
||||
CBotExternalCallList* CBotProgram::GetExternalCalls()
|
||||
{
|
||||
return m_externalCalls;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ class CBotFunction;
|
|||
class CBotClass;
|
||||
class CBotStack;
|
||||
class CBotVar;
|
||||
class CBotExternalCallList;
|
||||
|
||||
/**
|
||||
* \brief Class that manages a CBot program. This is the main entry point into the CBot engine.
|
||||
|
@ -335,7 +336,14 @@ public:
|
|||
*/
|
||||
bool m_bCompileClass;
|
||||
|
||||
/**
|
||||
* \brief Returns static list of all registered external calls
|
||||
*/
|
||||
static CBotExternalCallList* GetExternalCalls();
|
||||
|
||||
private:
|
||||
//! All external calls
|
||||
static CBotExternalCallList* m_externalCalls;
|
||||
//! All user-defined functions
|
||||
CBotFunction* m_functions = nullptr;
|
||||
//! The entry point function
|
||||
|
|
|
@ -744,7 +744,7 @@ bool CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBo
|
|||
|
||||
// first looks by the identifier
|
||||
|
||||
res = CBotExternalCallList::DoCall(nullptr, ppVar, this, rettype);
|
||||
res = m_prog->GetExternalCalls()->DoCall(nullptr, ppVar, this, rettype);
|
||||
if (res.GetType() >= 0) return res.GetType();
|
||||
|
||||
res = m_prog->GetFunctions()->DoCall(nIdent, "", ppVar, this, token );
|
||||
|
@ -753,7 +753,7 @@ bool CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBo
|
|||
// if not found (recompile?) seeks by name
|
||||
|
||||
nIdent = 0;
|
||||
res = CBotExternalCallList::DoCall(token, ppVar, this, rettype);
|
||||
res = m_prog->GetExternalCalls()->DoCall(token, ppVar, this, rettype);
|
||||
if (res.GetType() >= 0) return res.GetType();
|
||||
|
||||
res = m_prog->GetFunctions()->DoCall(nIdent, token->GetString(), ppVar, this, token );
|
||||
|
@ -766,10 +766,12 @@ bool CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBo
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
void CBotStack::RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar)
|
||||
{
|
||||
if ( m_next == nullptr ) return;
|
||||
if (m_next == nullptr) return;
|
||||
|
||||
if ( !CBotExternalCallList::RestoreCall(token, ppVar, this))
|
||||
m_prog->GetFunctions()->RestoreCall(nIdent, token->GetString(), ppVar, this );
|
||||
if (m_prog->GetExternalCalls()->RestoreCall(token, ppVar, this))
|
||||
return;
|
||||
|
||||
m_prog->GetFunctions()->RestoreCall(nIdent, token->GetString(), ppVar, this);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue