[colobot] 47/74: Fix finding in-class methods when searching by ID

Didier Raboud odyx at moszumanska.debian.org
Mon Nov 7 07:50:04 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 3debfb918288ebc17621cb15139eabe0d849f28d
Author: melex750 <melex750 at users.noreply.github.com>
Date:   Sat Sep 17 07:59:34 2016 -0400

    Fix finding in-class methods when searching by ID
---
 src/CBot/CBotClass.cpp              | 10 +---------
 src/CBot/CBotInstr/CBotFunction.cpp |  4 ----
 src/CBot/CBotProgram.cpp            |  1 +
 test/unit/CBot/CBot_test.cpp        | 30 ++++++++++++++++++++++++++++++
 4 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp
index a0ec640..b342ab4 100644
--- a/src/CBot/CBotClass.cpp
+++ b/src/CBot/CBotClass.cpp
@@ -639,7 +639,6 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
                 {
                     // return a method precompiled in pass 1
                     CBotFunction*   pf = m_pMethod;
-                    CBotFunction*   prev = nullptr;
                     CBotToken* ppp = p;
                     CBotCStack* pStk = pStack->TokenStack(nullptr, true);
                     CBotDefParam* params = CBotDefParam::Compile(p, pStk );
@@ -648,7 +647,6 @@ 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;
-                        prev = pf;
                         pf = pf->Next();
                     }
 
@@ -693,18 +691,12 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
                     // compiles a method
                     p = pBase;
                     CBotFunction* f =
-                    CBotFunction::Compile(p, pile, nullptr/*, false*/);
+                    CBotFunction::Compile(p, pile, pf/*, false*/);
 
                     if ( f != nullptr )
                     {
                         f->m_pProg = pStack->GetProgram();
                         f->m_bSynchro = bSynchro;
-                        // replaces the element in the chain
-                        f->m_next = pf->m_next;
-                        pf->m_next = nullptr;
-                        delete pf;
-                        if (prev == nullptr) m_pMethod = f;
-                        else prev->m_next = f;
                     }
                     pStack->Return(nullptr, pile);
                 }
diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp
index 1e7e0b9..0b1e05b 100644
--- a/src/CBot/CBotInstr/CBotFunction.cpp
+++ b/src/CBot/CBotInstr/CBotFunction.cpp
@@ -224,10 +224,6 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct
                 func->m_closeblk = (p != nullptr && p->GetPrev() != nullptr) ? *(p->GetPrev()) : CBotToken();
                 if ( pStk->IsOk() )
                 {
-                    if ( func->m_bPublic )  // public function, return known for all
-                    {
-                        CBotFunction::AddPublic(func);
-                    }
                     return pStack->ReturnFunc(func, pStk);
                 }
             }
diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp
index 77dac39..c406a01 100644
--- a/src/CBot/CBotProgram.cpp
+++ b/src/CBot/CBotProgram.cpp
@@ -132,6 +132,7 @@ bool CBotProgram::Compile(const std::string& program, std::vector<std::string>&
             m_bCompileClass = false;
             CBotFunction::Compile(p, pStack.get(), next);
             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();
         }
diff --git a/test/unit/CBot/CBot_test.cpp b/test/unit/CBot/CBot_test.cpp
index 2a112d7..fb63ed9 100644
--- a/test/unit/CBot/CBot_test.cpp
+++ b/test/unit/CBot/CBot_test.cpp
@@ -1874,3 +1874,33 @@ TEST_F(CBotUT, AmbiguousCallWithNumbers)
         "}\n"
     );
 }
+
+TEST_F(CBotUT, ClassMethodWithPublicKeyword)
+{
+    auto publicProgram = ExecuteTest(
+        "public class TestClass {\n"
+        "    public int Test() { return 1; }\n"
+        "}\n"
+    );
+
+    ExecuteTest(
+        "int Test() { return 2; }\n"
+        "\n"
+        "extern void DontCallMethodInTestClass()\n"
+        "{\n"
+        "    ASSERT(2 == Test());\n"
+        "}\n"
+    );
+
+    ExecuteTest(
+        "int Test() { return 2; }\n"
+        "\n"
+        "public class OtherClass {}\n"
+        "\n"
+        "extern void OtherClass::TestCallWithThis()\n"
+        "{\n"
+        "    this.Test();\n"
+        "}\n",
+        CBotErrUndefCall
+    );
+}

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