[colobot] 13/74: Fix RestoreMethode when calling inherited methods

Didier Raboud odyx at moszumanska.debian.org
Mon Nov 7 07:50:00 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 d0a8a32a57ca3548258aba67753842b290168391
Author: melex750 <melex750 at users.noreply.github.com>
Date:   Wed Aug 3 18:34:39 2016 -0400

    Fix RestoreMethode when calling inherited methods
---
 src/CBot/CBotClass.cpp              |  9 ++++++++-
 src/CBot/CBotInstr/CBotFunction.cpp | 14 +++++++++++---
 src/CBot/CBotInstr/CBotFunction.h   |  3 ++-
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp
index 70c72ef..17e1651 100644
--- a/src/CBot/CBotClass.cpp
+++ b/src/CBot/CBotClass.cpp
@@ -368,7 +368,14 @@ void CBotClass::RestoreMethode(long& nIdent,
                                CBotVar** ppParams,
                                CBotStack*& pStack)
 {
-    m_pMethod->RestoreCall(nIdent, name, pThis, ppParams, pStack, this);
+    CBotClass* pClass = this;
+    while (pClass != nullptr)
+    {
+        bool ok = pClass->m_pMethod->RestoreCall(nIdent, name, pThis, ppParams, pStack, pClass);
+        if (ok) return;
+        pClass = pClass->m_parent;
+    }
+    assert(false);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp
index 4c15a41..d00e8ea 100644
--- a/src/CBot/CBotInstr/CBotFunction.cpp
+++ b/src/CBot/CBotInstr/CBotFunction.cpp
@@ -801,7 +801,7 @@ int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar* pThis,
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar* pThis, CBotVar** ppVars,
+bool CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar* pThis, CBotVar** ppVars,
                                CBotStack* pStack, CBotClass* pClass)
 {
     CBotTypResult   type;
@@ -810,14 +810,20 @@ void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar* p
     if ( pt != nullptr )
     {
         CBotStack*  pStk = pStack->RestoreStack(pt);
-        if ( pStk == nullptr ) return;
+        if ( pStk == nullptr ) return true;
         pStk->SetProgram(pt->m_pProg);                  // it may have changed module
 
         CBotVar*    pthis = pStk->FindVar("this");
         pthis->SetUniqNum(-2);
 
+        if (pClass->GetParent() != nullptr)
+        {
+            CBotVar* psuper = pStk->FindVar("super");
+            if (psuper != nullptr) psuper->SetUniqNum(-3);
+        }
+
         CBotStack*  pStk3 = pStk->RestoreStack(nullptr);   // to set parameters passed
-        if ( pStk3 == nullptr ) return;
+        if ( pStk3 == nullptr ) return true;
 
         pt->m_param->RestoreState(pStk3, true);                 // parameters
 
@@ -831,7 +837,9 @@ void CBotFunction::RestoreCall(long& nIdent, const std::string& name, CBotVar* p
         // finally calls the found function
 
         pt->m_block->RestoreState(pStk3, true);                 // interrupt !
+        return true;
     }
+    return false;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
diff --git a/src/CBot/CBotInstr/CBotFunction.h b/src/CBot/CBotInstr/CBotFunction.h
index b0bf501..76a02bc 100644
--- a/src/CBot/CBotInstr/CBotFunction.h
+++ b/src/CBot/CBotInstr/CBotFunction.h
@@ -179,8 +179,9 @@ public:
      * \param ppVars
      * \param pStack
      * \param pClass
+     * \return Returns true if the method call was restored.
      */
-    void RestoreCall(long& nIdent,
+    bool RestoreCall(long& nIdent,
                      const std::string& name,
                      CBotVar* pThis,
                      CBotVar** ppVars,

-- 
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