From 266b34d578cbbb8ed55c4e8ecdf9c9b195cd7756 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 11 Nov 2016 18:16:12 +0100 Subject: [PATCH] Make CBotFunction implement CBotLinkedList --- src/CBot/CBotCStack.cpp | 2 +- src/CBot/CBotClass.cpp | 4 ++-- src/CBot/CBotDebug.cpp | 4 ++-- src/CBot/CBotInstr/CBotFunction.cpp | 21 ++------------------- src/CBot/CBotInstr/CBotFunction.h | 16 +++------------- src/CBot/CBotProgram.cpp | 6 +++--- 6 files changed, 13 insertions(+), 40 deletions(-) diff --git a/src/CBot/CBotCStack.cpp b/src/CBot/CBotCStack.cpp index 044a473e..ef3c4091 100644 --- a/src/CBot/CBotCStack.cpp +++ b/src/CBot/CBotCStack.cpp @@ -378,7 +378,7 @@ bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam) if ( pp->CheckParam( pParam ) ) return true; } - pp = pp->Next(); + pp = pp->GetNext(); } for (CBotFunction* pp : CBotFunction::m_publicFunctions) diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 0eb86db0..bd956051 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -464,7 +464,7 @@ bool CBotClass::CheckCall(CBotProgram* program, CBotDefParam* pParam, CBotToken* if ( pp->CheckParam( pParam ) ) return true; } - pp = pp->Next(); + pp = pp->GetNext(); } return false; @@ -647,7 +647,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) while ( pf != nullptr ) // search by name and parameters { if (pf->GetName() == pp && pf->CheckParam( params )) break; - pf = pf->Next(); + pf = pf->GetNext(); } bool bConstructor = (pp == GetName()); diff --git a/src/CBot/CBotDebug.cpp b/src/CBot/CBotDebug.cpp index 652bd704..d71eac31 100644 --- a/src/CBot/CBotDebug.cpp +++ b/src/CBot/CBotDebug.cpp @@ -41,7 +41,7 @@ void CBotDebug::DumpCompiledProgram(CBotProgram* program) while (func != nullptr) { funcIdMap[func->m_nFuncIdent] = func; - func = func->Next(); + func = func->GetNext(); } std::set finished; @@ -123,7 +123,7 @@ void CBotDebug::DumpCompiledProgram(CBotProgram* program) prev = GetPointerAsString(func); } - func = func->Next(); + func = func->GetNext(); } ss << "}" << std::endl; diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index 2885f1a9..2d92910a 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -46,7 +46,6 @@ CBotFunction::CBotFunction() { m_param = nullptr; // empty parameter list m_block = nullptr; // the instruction block - m_next = nullptr; // functions can be chained m_bPublic = false; // function not public m_bExtern = false; // function not extern m_pProg = nullptr; @@ -63,7 +62,6 @@ CBotFunction::~CBotFunction() { delete m_param; // empty parameter list delete m_block; // the instruction block - delete m_next; // remove public list if there is if (m_bPublic) @@ -411,15 +409,6 @@ void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInst 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) { @@ -441,7 +430,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(CBotFunction* localFunctionList, l 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 ) { @@ -467,7 +456,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(CBotFunction* localFunctionList, l 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 ) { @@ -906,12 +895,6 @@ std::string CBotFunction::GetParams() return params; } -//////////////////////////////////////////////////////////////////////////////// -CBotFunction* CBotFunction::Next() -{ - return m_next; -} - //////////////////////////////////////////////////////////////////////////////// void CBotFunction::AddPublic(CBotFunction* func) { diff --git a/src/CBot/CBotInstr/CBotFunction.h b/src/CBot/CBotInstr/CBotFunction.h index d2f766c7..6a0180fd 100644 --- a/src/CBot/CBotInstr/CBotFunction.h +++ b/src/CBot/CBotInstr/CBotFunction.h @@ -39,7 +39,7 @@ namespace CBot * void classname::test() { ... } * \endcode */ -class CBotFunction : public CBotInstr +class CBotFunction : public CBotInstr, public CBotLinkedList { public: CBotFunction(); @@ -91,11 +91,8 @@ public: CBotStack* &pj, CBotVar* pInstance = nullptr); - /*! - * \brief AddNext - * \param p - */ - void AddNext(CBotFunction* p); + using CBotLinkedList::GetNext; + using CBotLinkedList::AddNext; /*! * \brief Compile a function call @@ -224,12 +221,6 @@ public: */ bool IsExtern(); - /*! - * \brief Next - * \return - */ - CBotFunction* Next(); - /*! * \brief GetPosition * \param start @@ -257,7 +248,6 @@ private: CBotDefParam* m_param; //! The instruction block. CBotInstr* m_block; - CBotFunction* m_next; //! If returns CBotTypClass. CBotToken m_retToken; //! Complete type of the result. diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 17c5ec0a..6e8b6a69 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -132,7 +132,7 @@ bool CBotProgram::Compile(const std::string& program, std::vector& if (next->IsExtern()) functions.push_back(next->GetName()/* + next->GetParams()*/); if (next->IsPublic()) CBotFunction::AddPublic(next); 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) { if (m_entryPoint->GetName() == name ) break; - m_entryPoint = m_entryPoint->m_next; + m_entryPoint = m_entryPoint->GetNext(); } if (m_entryPoint == nullptr) @@ -178,7 +178,7 @@ bool CBotProgram::GetPosition(const std::string& name, int& start, int& stop, CB while (p != nullptr) { if ( p->GetName() == name ) break; - p = p->m_next; + p = p->GetNext(); } if ( p == nullptr ) return false;