Make CBotFunction implement CBotLinkedList

dev-buzzingcars
krzys-h 2016-11-11 18:16:12 +01:00
parent 8764d28e9e
commit 266b34d578
6 changed files with 13 additions and 40 deletions

View File

@ -378,7 +378,7 @@ bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
if ( pp->CheckParam( pParam ) ) if ( pp->CheckParam( pParam ) )
return true; return true;
} }
pp = pp->Next(); pp = pp->GetNext();
} }
for (CBotFunction* pp : CBotFunction::m_publicFunctions) for (CBotFunction* pp : CBotFunction::m_publicFunctions)

View File

@ -464,7 +464,7 @@ bool CBotClass::CheckCall(CBotProgram* program, CBotDefParam* pParam, CBotToken*
if ( pp->CheckParam( pParam ) ) if ( pp->CheckParam( pParam ) )
return true; return true;
} }
pp = pp->Next(); pp = pp->GetNext();
} }
return false; return false;
@ -647,7 +647,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
while ( pf != nullptr ) // search by name and parameters while ( pf != nullptr ) // search by name and parameters
{ {
if (pf->GetName() == pp && pf->CheckParam( params )) break; if (pf->GetName() == pp && pf->CheckParam( params )) break;
pf = pf->Next(); pf = pf->GetNext();
} }
bool bConstructor = (pp == GetName()); bool bConstructor = (pp == GetName());

View File

@ -41,7 +41,7 @@ void CBotDebug::DumpCompiledProgram(CBotProgram* program)
while (func != nullptr) while (func != nullptr)
{ {
funcIdMap[func->m_nFuncIdent] = func; funcIdMap[func->m_nFuncIdent] = func;
func = func->Next(); func = func->GetNext();
} }
std::set<CBotInstr*> finished; std::set<CBotInstr*> finished;
@ -123,7 +123,7 @@ void CBotDebug::DumpCompiledProgram(CBotProgram* program)
prev = GetPointerAsString(func); prev = GetPointerAsString(func);
} }
func = func->Next(); func = func->GetNext();
} }
ss << "}" << std::endl; ss << "}" << std::endl;

View File

@ -46,7 +46,6 @@ CBotFunction::CBotFunction()
{ {
m_param = nullptr; // empty parameter list m_param = nullptr; // empty parameter list
m_block = nullptr; // the instruction block m_block = nullptr; // the instruction block
m_next = nullptr; // functions can be chained
m_bPublic = false; // function not public m_bPublic = false; // function not public
m_bExtern = false; // function not extern m_bExtern = false; // function not extern
m_pProg = nullptr; m_pProg = nullptr;
@ -63,7 +62,6 @@ CBotFunction::~CBotFunction()
{ {
delete m_param; // empty parameter list delete m_param; // empty parameter list
delete m_block; // the instruction block delete m_block; // the instruction block
delete m_next;
// remove public list if there is // remove public list if there is
if (m_bPublic) if (m_bPublic)
@ -411,15 +409,6 @@ void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInst
m_block->RestoreState(pile2, true); m_block->RestoreState(pile2, true);
} }
////////////////////////////////////////////////////////////////////////////////
void CBotFunction::AddNext(CBotFunction* p)
{
CBotFunction* pp = this;
while (pp->m_next != nullptr) pp = pp->m_next;
pp->m_next = p;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
CBotTypResult CBotFunction::CompileCall(CBotFunction* localFunctionList, const std::string &name, CBotVar** ppVars, long &nIdent) CBotTypResult CBotFunction::CompileCall(CBotFunction* localFunctionList, const std::string &name, CBotVar** ppVars, long &nIdent)
{ {
@ -441,7 +430,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(CBotFunction* localFunctionList, l
if ( nIdent ) if ( nIdent )
{ {
if ( localFunctionList != nullptr ) for ( pt = localFunctionList ; pt != nullptr ; pt = pt->m_next ) if ( localFunctionList != nullptr ) for ( pt = localFunctionList ; pt != nullptr ; pt = pt->GetNext() )
{ {
if ( pt->m_nFuncIdent == nIdent ) if ( pt->m_nFuncIdent == nIdent )
{ {
@ -467,7 +456,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(CBotFunction* localFunctionList, l
if ( localFunctionList != nullptr ) if ( localFunctionList != nullptr )
{ {
for ( pt = localFunctionList ; pt != nullptr ; pt = pt->m_next ) for ( pt = localFunctionList ; pt != nullptr ; pt = pt->GetNext() )
{ {
if ( pt->m_token.GetString() == name ) if ( pt->m_token.GetString() == name )
{ {
@ -906,12 +895,6 @@ std::string CBotFunction::GetParams()
return params; return params;
} }
////////////////////////////////////////////////////////////////////////////////
CBotFunction* CBotFunction::Next()
{
return m_next;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void CBotFunction::AddPublic(CBotFunction* func) void CBotFunction::AddPublic(CBotFunction* func)
{ {

View File

@ -39,7 +39,7 @@ namespace CBot
* void classname::test() { ... } * void classname::test() { ... }
* \endcode * \endcode
*/ */
class CBotFunction : public CBotInstr class CBotFunction : public CBotInstr, public CBotLinkedList<CBotFunction>
{ {
public: public:
CBotFunction(); CBotFunction();
@ -91,11 +91,8 @@ public:
CBotStack* &pj, CBotStack* &pj,
CBotVar* pInstance = nullptr); CBotVar* pInstance = nullptr);
/*! using CBotLinkedList<CBotFunction>::GetNext;
* \brief AddNext using CBotLinkedList<CBotFunction>::AddNext;
* \param p
*/
void AddNext(CBotFunction* p);
/*! /*!
* \brief Compile a function call * \brief Compile a function call
@ -224,12 +221,6 @@ public:
*/ */
bool IsExtern(); bool IsExtern();
/*!
* \brief Next
* \return
*/
CBotFunction* Next();
/*! /*!
* \brief GetPosition * \brief GetPosition
* \param start * \param start
@ -257,7 +248,6 @@ private:
CBotDefParam* m_param; CBotDefParam* m_param;
//! The instruction block. //! The instruction block.
CBotInstr* m_block; CBotInstr* m_block;
CBotFunction* m_next;
//! If returns CBotTypClass. //! If returns CBotTypClass.
CBotToken m_retToken; CBotToken m_retToken;
//! Complete type of the result. //! Complete type of the result.

View File

@ -132,7 +132,7 @@ bool CBotProgram::Compile(const std::string& program, std::vector<std::string>&
if (next->IsExtern()) functions.push_back(next->GetName()/* + next->GetParams()*/); if (next->IsExtern()) functions.push_back(next->GetName()/* + next->GetParams()*/);
if (next->IsPublic()) CBotFunction::AddPublic(next); if (next->IsPublic()) CBotFunction::AddPublic(next);
next->m_pProg = this; // keeps pointers to the module next->m_pProg = this; // keeps pointers to the module
next = next->Next(); next = next->GetNext();
} }
} }
@ -157,7 +157,7 @@ bool CBotProgram::Start(const std::string& name)
while (m_entryPoint != nullptr) while (m_entryPoint != nullptr)
{ {
if (m_entryPoint->GetName() == name ) break; if (m_entryPoint->GetName() == name ) break;
m_entryPoint = m_entryPoint->m_next; m_entryPoint = m_entryPoint->GetNext();
} }
if (m_entryPoint == nullptr) if (m_entryPoint == nullptr)
@ -178,7 +178,7 @@ bool CBotProgram::GetPosition(const std::string& name, int& start, int& stop, CB
while (p != nullptr) while (p != nullptr)
{ {
if ( p->GetName() == name ) break; if ( p->GetName() == name ) break;
p = p->m_next; p = p->GetNext();
} }
if ( p == nullptr ) return false; if ( p == nullptr ) return false;