From 544300697974b7888ba79ad7505b1c8120c7ad64 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 24 Dec 2015 15:07:40 +0100 Subject: [PATCH] Refactor public function list --- src/CBot/CBotCStack.cpp | 4 +--- src/CBot/CBotInstr/CBotFunction.cpp | 34 ++++++----------------------- src/CBot/CBotInstr/CBotFunction.h | 7 +++--- src/CBot/CBotVar/CBotVar.h | 14 ++++++++++-- 4 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/CBot/CBotCStack.cpp b/src/CBot/CBotCStack.cpp index a024bb34..98bee9f0 100644 --- a/src/CBot/CBotCStack.cpp +++ b/src/CBot/CBotCStack.cpp @@ -385,8 +385,7 @@ bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam) pp = pp->Next(); } - pp = CBotFunction::m_listPublic; - while ( pp != nullptr ) + for (CBotFunction* pp : CBotFunction::m_publicFunctions) { if ( pToken->GetString() == pp->GetName() ) { @@ -394,7 +393,6 @@ bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam) if ( pp->CheckParam( pParam ) ) return true; } - pp = pp->m_nextpublic; } return false; diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index 4f4df63a..59da2d44 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -51,8 +51,6 @@ CBotFunction::CBotFunction() m_next = nullptr; // functions can be chained m_bPublic = false; // function not public m_bExtern = false; // function not extern - m_nextpublic = nullptr; - m_prevpublic = nullptr; m_pProg = nullptr; // m_nThisIdent = 0; m_nFuncIdent = 0; @@ -60,7 +58,7 @@ CBotFunction::CBotFunction() } //////////////////////////////////////////////////////////////////////////////// -CBotFunction* CBotFunction::m_listPublic = nullptr; +std::set CBotFunction::m_publicFunctions{}; //////////////////////////////////////////////////////////////////////////////// CBotFunction::~CBotFunction() @@ -70,21 +68,9 @@ CBotFunction::~CBotFunction() delete m_next; // remove public list if there is - if ( m_bPublic ) + if (m_bPublic) { - if ( m_nextpublic != nullptr ) - { - m_nextpublic->m_prevpublic = m_prevpublic; - } - if ( m_prevpublic != nullptr) - { - m_prevpublic->m_nextpublic = m_nextpublic; - } - else - { - // if prev = next = null may not be in the list! - if ( m_listPublic == this ) m_listPublic = m_nextpublic; - } + m_publicFunctions.erase(this); } } @@ -463,10 +449,9 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const std::string& n } // search the list of public functions - - for ( pt = m_listPublic ; pt != nullptr ; pt = pt->m_nextpublic ) + for (CBotFunction* pt : m_publicFunctions) { - if ( pt->m_nFuncIdent == nIdent ) + if (pt->m_nFuncIdent == nIdent) { TypeOrError = pt->m_retTyp; return pt; @@ -536,7 +521,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const std::string& n if ( bPublic ) { - for ( pt = m_listPublic ; pt != nullptr ; pt = pt->m_nextpublic ) + for (CBotFunction* pt : m_publicFunctions) { if ( pt->m_token.GetString() == name ) { @@ -887,10 +872,5 @@ CBotFunction* CBotFunction::Next() //////////////////////////////////////////////////////////////////////////////// void CBotFunction::AddPublic(CBotFunction* func) { - if ( m_listPublic != nullptr ) - { - func->m_nextpublic = m_listPublic; - m_listPublic->m_prevpublic = func; - } - m_listPublic = func; + m_publicFunctions.insert(func); } diff --git a/src/CBot/CBotInstr/CBotFunction.h b/src/CBot/CBotInstr/CBotFunction.h index dbf96763..216e19a5 100644 --- a/src/CBot/CBotInstr/CBotFunction.h +++ b/src/CBot/CBotInstr/CBotFunction.h @@ -25,6 +25,7 @@ // Local include // Global include +#include /*! @@ -243,8 +244,6 @@ public: CBotGet modestop); private: - CBotFunction* m_nextpublic; - CBotFunction* m_prevpublic; long m_nFuncIdent; //! Synchronized method. bool m_bSynchro; @@ -272,8 +271,8 @@ private: CBotToken m_openblk; CBotToken m_closeblk; - //! Management of list of (static) public functions. - static CBotFunction* m_listPublic; + //! List of public functions + static std::set m_publicFunctions; friend class CBotProgram; friend class CBotClass; diff --git a/src/CBot/CBotVar/CBotVar.h b/src/CBot/CBotVar/CBotVar.h index 3bb7c5ad..aee738d9 100644 --- a/src/CBot/CBotVar/CBotVar.h +++ b/src/CBot/CBotVar/CBotVar.h @@ -179,13 +179,23 @@ public: /** * \brief GetType Returns the base type of the variable (::CBotType) - * \param mode TODO: document this param + * \param mode + * \parblock + * * mode = 0 Return type normally + * * mode = 1 Treat classes as pointers + * * mode = 2 Treat classes as intrinsic + * \endparblock */ CBotType GetType(int mode = 0); /** * \brief Returns the complete type of the variable (CBotTypResult) - * \param mode TODO: document this param + * \param mode + * \parblock + * * mode = 0 Return type normally + * * mode = 1 Treat classes as pointers + * * mode = 2 Treat classes as intrinsic + * \endparblock */ CBotTypResult GetTypResult(int mode = 0);