[colobot] 196/377: Made CBotExternalCallList not static

Didier Raboud odyx at moszumanska.debian.org
Wed Mar 30 13:34:15 UTC 2016


This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch debian/master
in repository colobot.

commit ae544c71ae2ee2691da289801a2ee1be7731baf4
Author: krzys-h <krzys_h at interia.pl>
Date:   Thu Dec 24 12:36:09 2015 +0100

    Made CBotExternalCallList not static
---
 src/CBot/CBotCStack.cpp             |  4 ++--
 src/CBot/CBotClass.cpp              |  5 ++---
 src/CBot/CBotClass.h                |  3 +--
 src/CBot/CBotExternalCall.cpp       |  4 ----
 src/CBot/CBotExternalCall.h         | 18 +++++++++---------
 src/CBot/CBotInstr/CBotFunction.cpp |  2 +-
 src/CBot/CBotProgram.cpp            | 15 +++++++++++----
 src/CBot/CBotProgram.h              |  8 ++++++++
 src/CBot/CBotStack.cpp              | 12 +++++++-----
 9 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/src/CBot/CBotCStack.cpp b/src/CBot/CBotCStack.cpp
index 4866abb..c8bf457 100644
--- a/src/CBot/CBotCStack.cpp
+++ b/src/CBot/CBotCStack.cpp
@@ -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 )
diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp
index 32ce167..4de2d2e 100644
--- a/src/CBot/CBotClass.cpp
+++ b/src/CBot/CBotClass.cpp
@@ -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 )
diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h
index 262369a..6233de3 100644
--- a/src/CBot/CBotClass.h
+++ b/src/CBot/CBotClass.h
@@ -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.
diff --git a/src/CBot/CBotExternalCall.cpp b/src/CBot/CBotExternalCall.cpp
index 864c26a..1d88c3b 100644
--- a/src/CBot/CBotExternalCall.cpp
+++ b/src/CBot/CBotExternalCall.cpp
@@ -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();
diff --git a/src/CBot/CBotExternalCall.h b/src/CBot/CBotExternalCall.h
index 62b25b2..95ff4b6 100644
--- a/src/CBot/CBotExternalCall.h
+++ b/src/CBot/CBotExternalCall.h
@@ -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;
 };
\ No newline at end of file
diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp
index 5df2212..8d6c8d5 100644
--- a/src/CBot/CBotInstr/CBotFunction.cpp
+++ b/src/CBot/CBotInstr/CBotFunction.cpp
@@ -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))
                     {
diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp
index 19c629e..884e2e1 100644
--- a/src/CBot/CBotProgram.cpp
+++ b/src/CBot/CBotProgram.cpp
@@ -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();
-}
\ No newline at end of file
+}
+
+CBotExternalCallList* CBotProgram::GetExternalCalls()
+{
+    return m_externalCalls;
+}
diff --git a/src/CBot/CBotProgram.h b/src/CBot/CBotProgram.h
index 8cc5dc8..80236ea 100644
--- a/src/CBot/CBotProgram.h
+++ b/src/CBot/CBotProgram.h
@@ -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
diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp
index 62accc2..2b2672b 100644
--- a/src/CBot/CBotStack.cpp
+++ b/src/CBot/CBotStack.cpp
@@ -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);
 }
 
 ////////////////////////////////////////////////////////////////////////////////

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git



More information about the Pkg-games-commits mailing list