[colobot] 18/100: Refactor CBotCallMethode -> CBotExternalCall
Didier Raboud
odyx at moszumanska.debian.org
Thu Jun 1 18:10:14 UTC 2017
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch debian/master
in repository colobot.
commit 48f703282ea73c82db611a403d09edf8aee5dc79
Author: krzys-h <krzys_h at interia.pl>
Date: Fri Nov 11 21:49:27 2016 +0100
Refactor CBotCallMethode -> CBotExternalCall
---
src/CBot/CBotCallMethode.cpp | 113 --------------------------------
src/CBot/CBotCallMethode.h | 88 -------------------------
src/CBot/CBotClass.cpp | 58 +++++-----------
src/CBot/CBotClass.h | 33 ++++------
src/CBot/CBotExternalCall.cpp | 44 +++++++++++++
src/CBot/CBotExternalCall.h | 30 +++++++++
src/CBot/CBotInstr/CBotDefClass.cpp | 12 +---
src/CBot/CBotInstr/CBotInstrMethode.cpp | 33 ++--------
src/CBot/CBotInstr/CBotNew.cpp | 12 +---
src/CBot/CBotVar/CBotVarClass.cpp | 5 +-
src/CBot/CMakeLists.txt | 2 -
11 files changed, 117 insertions(+), 313 deletions(-)
diff --git a/src/CBot/CBotCallMethode.cpp b/src/CBot/CBotCallMethode.cpp
deleted file mode 100644
index 582ce7b..0000000
--- a/src/CBot/CBotCallMethode.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * This file is part of the Colobot: Gold Edition source code
- * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
- * http://epsitec.ch; http://colobot.info; http://github.com/colobot
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see http://gnu.org/licenses
- */
-
-#include "CBot/CBotCallMethode.h"
-
-#include "CBot/CBotUtils.h"
-#include "CBot/CBotStack.h"
-#include "CBot/CBotCStack.h"
-
-#include "CBot/CBotVar/CBotVar.h"
-
-namespace CBot
-{
-
-
-////////////////////////////////////////////////////////////////////////////////
-CBotCallMethode::CBotCallMethode(const std::string& name,
- bool rExec(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
- CBotTypResult rCompile(CBotVar* pThis, CBotVar*& pVar))
-{
- m_name = name;
- m_rExec = rExec;
- m_rComp = rCompile;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-CBotCallMethode::~CBotCallMethode()
-{
-}
-
-////////////////////////////////////////////////////////////////////////////////
-CBotTypResult CBotCallMethode::CompileCall(const std::string& name, CBotVar* pThis, CBotVar** ppVar,
- CBotCStack* pStack)
-{
- CBotCallMethode* pt = this;
-
- while ( pt != nullptr )
- {
- if ( pt->m_name == name )
- {
- CBotVar* pVar = MakeListVars(ppVar, true);
- CBotVar* pVar2 = pVar;
- CBotTypResult r = pt->m_rComp(pThis, pVar2);
- int ret = r.GetType();
- if ( ret > 20 )
- {
- if (pVar2) pStack->SetError(static_cast<CBotError>(ret), pVar2->GetToken());
- }
- delete pVar;
- return r;
- }
- pt = pt->m_next;
- }
- return CBotTypResult(-1);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-int CBotCallMethode::DoCall(const std::string& name, CBotVar* pThis, CBotVar** ppVars, CBotVar*& pResult,
- CBotStack* pStack, CBotToken* pToken)
-{
- CBotCallMethode* pt = this;
-
- // search by name
-
- while ( pt != nullptr )
- {
- if ( pt->m_name == name )
- {
- // lists the parameters depending on the contents of the stack (pStackVar)
-
- CBotVar* pVar = MakeListVars(ppVars, true);
- CBotVar* pVarToDelete = pVar;
-
- int Exception = 0; // TODO: Change this to CBotError
- int res = pt->m_rExec(pThis, pVar, pResult, Exception, pStack->GetUserPtr());
- pStack->SetVar(pResult);
-
- if (res == false)
- {
- if (Exception!=0)
- {
-// pStack->SetError(Exception, pVar->GetToken());
- pStack->SetError(static_cast<CBotError>(Exception), pToken);
- }
- delete pVarToDelete;
- return false;
- }
- delete pVarToDelete;
- return true;
- }
- pt = pt->m_next;
- }
-
- return -1;
-}
-
-} // namespace CBot
diff --git a/src/CBot/CBotCallMethode.h b/src/CBot/CBotCallMethode.h
deleted file mode 100644
index 4d0e167..0000000
--- a/src/CBot/CBotCallMethode.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * This file is part of the Colobot: Gold Edition source code
- * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
- * http://epsitec.ch; http://colobot.info; http://github.com/colobot
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see http://gnu.org/licenses
- */
-
-#pragma once
-
-#include "CBot/CBotTypResult.h"
-#include "CBot/CBotUtils.h"
-
-namespace CBot
-{
-
-class CBotVar;
-class CBotCStack;
-class CBotStack;
-class CBotToken;
-
-/*!
- * \brief The CBotCallMethode class Class managing the methods declared by
- * AddFunction on a class.
- */
-class CBotCallMethode : public CBotLinkedList<CBotCallMethode>
-{
-public:
-
- /*!
- * \brief CBotCallMethode
- * \param name
- * \param rExec
- * \param rCompile
- */
- CBotCallMethode(const std::string& name,
- bool rExec(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
- CBotTypResult rCompile(CBotVar* pThis, CBotVar*& pVar));
-
- /*!
- * \brief ~CBotCallMethode
- */
- ~CBotCallMethode();
-
- /*!
- * \brief CompileCall Is acceptable by a call procedure name and given
- * parameters.
- * \param name
- * \param pThis
- * \param ppVars
- * \param pStack
- * \return
- */
- CBotTypResult CompileCall(const std::string& name, CBotVar* pThis, CBotVar** ppVars,
- CBotCStack* pStack);
-
- /*!
- * \brief DoCall
- * \param name
- * \param pThis
- * \param ppVars
- * \param pResult
- * \param pStack
- * \param pFunc
- * \return
- */
- int DoCall(const std::string& name, CBotVar* pThis, CBotVar** ppVars, CBotVar*& pResult,
- CBotStack* pStack, CBotToken* pFunc);
-
-private:
- std::string m_name;
- bool (*m_rExec) (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user);
- CBotTypResult (*m_rComp) (CBotVar* pThis, CBotVar* &pVar);
- friend class CBotClass;
-};
-
-} // namespace CBot
diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp
index 77998b3..d93d7f5 100644
--- a/src/CBot/CBotClass.cpp
+++ b/src/CBot/CBotClass.cpp
@@ -37,7 +37,6 @@
#include "CBot/CBotDefParam.h"
#include "CBot/CBotUtils.h"
#include "CBot/CBotFileUtils.h"
-#include "CBot/CBotCallMethode.h"
#include <algorithm>
@@ -55,7 +54,7 @@ CBotClass::CBotClass(const std::string& name,
m_parent = parent;
m_name = name;
m_pVar = nullptr;
- m_pCalls = nullptr;
+ m_externalMethods = new CBotExternalCallList();
m_rUpdate = nullptr;
m_IsDef = true;
m_bIntrinsic= bIntrinsic;
@@ -70,7 +69,7 @@ CBotClass::~CBotClass()
m_publicClasses.erase(this);
delete m_pVar;
- delete m_pCalls;
+ delete m_externalMethods;
}
////////////////////////////////////////////////////////////////////////////////
@@ -94,8 +93,7 @@ void CBotClass::Purge()
delete m_pVar;
m_pVar = nullptr;
- delete m_pCalls;
- m_pCalls = nullptr;
+ m_externalMethods->Clear();
for (CBotFunction* f : m_pMethod) delete f;
m_pMethod.clear();
m_IsDef = false;
@@ -278,29 +276,7 @@ bool CBotClass::AddFunction(const std::string& name,
bool rExec(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
CBotTypResult rCompile(CBotVar* pThis, CBotVar*& pVar))
{
- // stores pointers to the two functions
- CBotCallMethode* p = m_pCalls;
- CBotCallMethode* pp = nullptr;
-
- while ( p != nullptr )
- {
- if ( name == p->m_name )
- {
- if ( pp == nullptr ) m_pCalls = p->m_next;
- else pp->m_next = p->m_next;
- delete p;
- break;
- }
- pp = p;
- p = p->m_next;
- }
-
- p = new CBotCallMethode(name, rExec, rCompile);
-
- if (m_pCalls == nullptr) m_pCalls = p;
- else m_pCalls->AddNext(p); // added to the list
-
- return true;
+ return m_externalMethods->AddFunction(name, std::unique_ptr<CBotExternalCall>(new CBotExternalCallClass(rExec, rCompile)));
}
////////////////////////////////////////////////////////////////////////////////
@@ -311,22 +287,22 @@ bool CBotClass::SetUpdateFunc(void rUpdate(CBotVar* thisVar, void* user))
}
////////////////////////////////////////////////////////////////////////////////
-CBotTypResult CBotClass::CompileMethode(const std::string& name,
+CBotTypResult CBotClass::CompileMethode(CBotToken* name,
CBotVar* pThis,
CBotVar** ppParams,
CBotCStack* pStack,
- long& nIdent)
+ long &nIdent)
{
nIdent = 0; // forget the previous one if necessary
// find the methods declared by AddFunction
- CBotTypResult r = m_pCalls->CompileCall(name, pThis, ppParams, pStack);
+ CBotTypResult r = m_externalMethods->CompileCall(name, pThis, ppParams, pStack);
if ( r.GetType() >= 0) return r;
// find the methods declared by user
- r = CBotFunction::CompileCall(m_pMethod, name, ppParams, nIdent);
+ r = CBotFunction::CompileCall(m_pMethod, name->GetString(), ppParams, nIdent);
if ( r.Eq(CBotErrUndefCall) && m_parent != nullptr )
return m_parent->CompileMethode(name, pThis, ppParams, pStack, nIdent);
return r;
@@ -334,37 +310,39 @@ CBotTypResult CBotClass::CompileMethode(const std::string& name,
////////////////////////////////////////////////////////////////////////////////
bool CBotClass::ExecuteMethode(long& nIdent,
- const std::string& name,
CBotVar* pThis,
CBotVar** ppParams,
- CBotVar*& pResult,
+ CBotTypResult pResultType,
CBotStack*& pStack,
CBotToken* pToken)
{
- int ret = m_pCalls->DoCall(name, pThis, ppParams, pResult, pStack, pToken);
- if (ret>=0) return ret;
+ int ret = m_externalMethods->DoCall(pToken, pThis, ppParams, pStack, pResultType);
+ if (ret >= 0) return ret;
- ret = CBotFunction::DoCall(m_pMethod, nIdent, name, pThis, ppParams, pStack, pToken, this);
+ ret = CBotFunction::DoCall(m_pMethod, nIdent, pToken->GetString(), pThis, ppParams, pStack, pToken, this);
if (ret >= 0) return ret;
if (m_parent != nullptr)
{
- ret = m_parent->ExecuteMethode(nIdent, name, pThis, ppParams, pResult, pStack, pToken);
+ ret = m_parent->ExecuteMethode(nIdent, pThis, ppParams, pResultType, pStack, pToken);
}
return ret;
}
////////////////////////////////////////////////////////////////////////////////
void CBotClass::RestoreMethode(long& nIdent,
- const std::string& name,
+ CBotToken* name,
CBotVar* pThis,
CBotVar** ppParams,
CBotStack*& pStack)
{
+ if (m_externalMethods->RestoreCall(name, pThis, ppParams, pStack))
+ return;
+
CBotClass* pClass = this;
while (pClass != nullptr)
{
- bool ok = CBotFunction::RestoreCall(pClass->m_pMethod, nIdent, name, pThis, ppParams, pStack, pClass);
+ bool ok = CBotFunction::RestoreCall(pClass->m_pMethod, nIdent, name->GetString(), pThis, ppParams, pStack, pClass);
if (ok) return;
pClass = pClass->m_parent;
}
diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h
index 94ab341..10bb83c 100644
--- a/src/CBot/CBotClass.h
+++ b/src/CBot/CBotClass.h
@@ -38,6 +38,7 @@ class CBotStack;
class CBotDefParam;
class CBotToken;
class CBotCStack;
+class CBotExternalCallList;
/**
* \brief A CBot class definition
@@ -134,13 +135,8 @@ public:
bool intrinsic = false);
/*!
- * \brief AddFunction This call allows to add as external new method
- * used by the objects of this class. See (**) at end of this file for
- * more details.
- * \param name
- * \param rExec
- * \param rCompile
- * \return
+ * \brief Add a function that can be called from CBot
+ * \see CBotProgram::AddFunction
*/
bool AddFunction(const std::string& name,
bool rExec(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
@@ -235,11 +231,11 @@ public:
* \param nIdent
* \return
*/
- CBotTypResult CompileMethode(const std::string& name,
+ CBotTypResult CompileMethode(CBotToken* name,
CBotVar* pThis,
CBotVar** ppParams,
CBotCStack* pStack,
- long& nIdent);
+ long &nIdent);
/*!
* \brief ExecuteMethode Executes a method.
@@ -247,18 +243,13 @@ public:
* \param name
* \param pThis
* \param ppParams
- * \param pResult
+ * \param pResultType
* \param pStack
* \param pToken
* \return
*/
- bool ExecuteMethode(long& nIdent,
- const std::string& name,
- CBotVar* pThis,
- CBotVar** ppParams,
- CBotVar*& pResult,
- CBotStack*& pStack,
- CBotToken* pToken);
+ bool ExecuteMethode(long &nIdent, CBotVar* pThis, CBotVar** ppParams, CBotTypResult pResultType,
+ CBotStack*&pStack, CBotToken* pToken);
/*!
* \brief RestoreMethode Restored the execution stack.
@@ -268,11 +259,11 @@ public:
* \param ppParams
* \param pStack
*/
- void RestoreMethode(long& nIdent,
- const std::string& name,
+ void RestoreMethode(long &nIdent,
+ CBotToken* name,
CBotVar* pThis,
CBotVar** ppParams,
- CBotStack*& pStack);
+ CBotStack*&pStack);
/*!
* \brief Compile Compiles a class declared by the user.
@@ -389,7 +380,7 @@ private:
//! Linked list of all class fields
CBotVar* m_pVar;
//! Linked list of all class external calls
- CBotCallMethode* m_pCalls;
+ CBotExternalCallList* m_externalMethods;
//! List of all class methods
std::list<CBotFunction*> m_pMethod{};
void (*m_rUpdate)(CBotVar* thisVar, void* user);
diff --git a/src/CBot/CBotExternalCall.cpp b/src/CBot/CBotExternalCall.cpp
index dcf7222..be7aa67 100644
--- a/src/CBot/CBotExternalCall.cpp
+++ b/src/CBot/CBotExternalCall.cpp
@@ -168,4 +168,48 @@ bool CBotExternalCallDefault::Run(CBotVar* thisVar, CBotStack* pStack)
return true;
}
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+CBotExternalCallClass::CBotExternalCallClass(RuntimeFunc rExec, CompileFunc rCompile)
+{
+ m_rExec = rExec;
+ m_rComp = rCompile;
+}
+
+CBotExternalCallClass::~CBotExternalCallClass()
+{
+}
+
+CBotTypResult CBotExternalCallClass::Compile(CBotVar* thisVar, CBotVar* args, void* user)
+{
+ return m_rComp(thisVar, args);
+}
+
+bool CBotExternalCallClass::Run(CBotVar* thisVar, CBotStack* pStack)
+{
+ if (pStack->IsCallFinished()) return true;
+ CBotStack* pile = pStack->AddStackExternalCall(this);
+ CBotVar* args = pile->GetVar();
+
+ CBotStack* pile2 = pile->AddStack();
+
+ CBotVar* result = pile2->GetVar();
+
+ int exception = CBotNoErr; // TODO: Change to CBotError
+ bool res = m_rExec(thisVar, args, result, exception, pStack->GetUserPtr());
+
+ if (!res)
+ {
+ if (exception != CBotNoErr)
+ {
+ pStack->SetError(static_cast<CBotError>(exception));
+ }
+ return false;
+ }
+
+ if (result != nullptr) pStack->SetCopyVar(result);
+
+ return true;
+}
+
}
diff --git a/src/CBot/CBotExternalCall.h b/src/CBot/CBotExternalCall.h
index 5bef80a..5432aad 100644
--- a/src/CBot/CBotExternalCall.h
+++ b/src/CBot/CBotExternalCall.h
@@ -105,6 +105,36 @@ private:
CompileFunc m_rComp;
};
+/**
+ * \brief Implementation of CBot external call for class methods, using compilation and runtime functions
+ */
+class CBotExternalCallClass : public CBotExternalCall
+{
+public:
+ typedef bool (*RuntimeFunc)(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user);
+ typedef CBotTypResult (*CompileFunc)(CBotVar* pThis, CBotVar*& pVar);
+
+ /**
+ * \brief Constructor
+ * \param rExec Runtime function
+ * \param rCompile Compilation function
+ * \see CBotProgram::AddFunction()
+ */
+ CBotExternalCallClass(RuntimeFunc rExec, CompileFunc rCompile);
+
+ /**
+ * \brief Destructor
+ */
+ virtual ~CBotExternalCallClass();
+
+ virtual CBotTypResult Compile(CBotVar* thisVar, CBotVar* args, void* user) override;
+ virtual bool Run(CBotVar* thisVar, CBotStack* pStack) override;
+
+private:
+ RuntimeFunc m_rExec;
+ CompileFunc m_rComp;
+};
+
/**
* \brief Class for mangaging CBot external calls
diff --git a/src/CBot/CBotInstr/CBotDefClass.cpp b/src/CBot/CBotInstr/CBotDefClass.cpp
index cd73d9c..3fe832e 100644
--- a/src/CBot/CBotInstr/CBotDefClass.cpp
+++ b/src/CBot/CBotInstr/CBotDefClass.cpp
@@ -131,7 +131,7 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
{
// the constructor is there?
// std::string noname;
- CBotTypResult r = pClass->CompileMethode(pClass->GetName(), var, ppVars, pStk, inst->m_nMethodeIdent);
+ CBotTypResult r = pClass->CompileMethode(&token, var, ppVars, pStk, inst->m_nMethodeIdent);
delete pStk->TokenStack(); // releases the supplement stack
int typ = r.GetType();
@@ -369,11 +369,7 @@ bool CBotDefClass::Execute(CBotStack* &pj)
ppVars[i] = nullptr;
// creates a variable for the result
- CBotVar* pResult = nullptr; // constructor still void
-
- if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GetName(),
- pThis, ppVars,
- pResult, pile2, GetToken())) return false; // interrupt
+ if ( !pClass->ExecuteMethode(m_nMethodeIdent, pThis, ppVars, CBotTypResult(CBotTypVoid), pile2, GetToken())) return false; // interrupt
pThis->SetInit(CBotVar::InitType::DEF);
pThis->ConstructorSet(); // indicates that the constructor has been called
@@ -483,9 +479,7 @@ void CBotDefClass::RestoreState(CBotStack* &pj, bool bMain)
ppVars[i] = nullptr;
// creates a variable for the result
-// CBotVar* pResult = nullptr; // constructor still void
-
- pClass->RestoreMethode(m_nMethodeIdent, pClass->GetName(), pThis, ppVars, pile2);
+ pClass->RestoreMethode(m_nMethodeIdent, pt, pThis, ppVars, pile2);
return;
}
}
diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp
index bf4ec41..3a41802 100644
--- a/src/CBot/CBotInstr/CBotInstrMethode.cpp
+++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp
@@ -67,8 +67,7 @@ CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar*
inst->m_thisIdent = var->GetUniqNum();
CBotClass* pClass = var->GetClass(); // pointer to the class
inst->m_className = pClass->GetName(); // name of the class
- CBotTypResult r = pClass->CompileMethode(inst->m_methodName, var, ppVars,
- pStack, inst->m_MethodeIdent);
+ CBotTypResult r = pClass->CompileMethode(pp, var, ppVars, pStack, inst->m_MethodeIdent);
delete pStack->TokenStack(); // release parameters on the stack
inst->m_typRes = r;
@@ -176,18 +175,7 @@ bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre
else
pClass = pThis->GetClass();
- CBotVar* pResult = nullptr;
- if (m_typRes.GetType() > 0) pResult = CBotVar::Create("", m_typRes);
- if (m_typRes.Eq(CBotTypClass))
- {
- pResult->SetClass(m_typRes.GetClass());
- }
- CBotVar* pRes = pResult;
-
- if ( !pClass->ExecuteMethode(m_MethodeIdent, m_methodName,
- pThis, ppVars,
- pResult, pile2, GetToken())) return false;
- if (pRes != pResult) delete pRes;
+ if ( !pClass->ExecuteMethode(m_MethodeIdent, pThis, ppVars, m_typRes, pile2, GetToken())) return false;
if (m_exprRetVar != nullptr) // .func().member
{
@@ -264,8 +252,7 @@ void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, bool bMain)
// CBotVar* pRes = pResult;
- pClass->RestoreMethode(m_MethodeIdent, m_methodName,
- pThis, ppVars, pile2);
+ pClass->RestoreMethode(m_MethodeIdent, &m_token, pThis, ppVars, pile2);
}
////////////////////////////////////////////////////////////////////////////////
@@ -316,24 +303,12 @@ bool CBotInstrMethode::Execute(CBotStack* &pj)
else
pClass = pThis->GetClass();
- CBotVar* pResult = nullptr;
- if (m_typRes.GetType()>0) pResult = CBotVar::Create("", m_typRes);
- if (m_typRes.Eq(CBotTypClass))
- {
- pResult->SetClass(m_typRes.GetClass());
- }
- CBotVar* pRes = pResult;
-
- if ( !pClass->ExecuteMethode(m_MethodeIdent, m_methodName,
- pThis, ppVars,
- pResult, pile2, GetToken())) return false; // interupted
+ if ( !pClass->ExecuteMethode(m_MethodeIdent, pThis, ppVars, m_typRes, pile2, GetToken())) return false; // interupted
// set the new value of this in place of the old variable
CBotVar* old = pile1->FindVar(m_token, false);
old->Copy(pThis, false);
- if (pRes != pResult) delete pRes;
-
return pj->Return(pile2); // release the entire stack
}
diff --git a/src/CBot/CBotInstr/CBotNew.cpp b/src/CBot/CBotInstr/CBotNew.cpp
index e7d973c..ddd50c6 100644
--- a/src/CBot/CBotInstr/CBotNew.cpp
+++ b/src/CBot/CBotInstr/CBotNew.cpp
@@ -83,7 +83,7 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack)
if (!pStk->IsOk()) goto error;
// constructor exist?
- CBotTypResult r = pClass->CompileMethode(pClass->GetName(), pVar, ppVars, pStk, inst->m_nMethodeIdent);
+ CBotTypResult r = pClass->CompileMethode(&inst->m_vartoken, pVar, ppVars, pStk, inst->m_nMethodeIdent);
delete pStk->TokenStack(); // release extra stack
int typ = r.GetType();
@@ -197,12 +197,7 @@ bool CBotNew::Execute(CBotStack* &pj)
}
ppVars[i] = nullptr;
- // create a variable for the result
- CBotVar* pResult = nullptr; // constructos still void
-
- if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GetName(),
- pThis, ppVars,
- pResult, pile2, GetToken())) return false; // interrupt
+ if ( !pClass->ExecuteMethode(m_nMethodeIdent, pThis, ppVars, CBotTypResult(CBotTypVoid), pile2, GetToken())) return false; // interrupt
pThis->ConstructorSet(); // indicates that the constructor has been called
}
@@ -284,8 +279,7 @@ void CBotNew::RestoreState(CBotStack* &pj, bool bMain)
}
ppVars[i] = nullptr;
- pClass->RestoreMethode(m_nMethodeIdent, m_vartoken.GetString(), pThis,
- ppVars, pile2) ; // interrupt here!
+ pClass->RestoreMethode(m_nMethodeIdent, &m_vartoken, pThis, ppVars, pile2); // interrupt here!
}
}
diff --git a/src/CBot/CBotVar/CBotVarClass.cpp b/src/CBot/CBotVar/CBotVarClass.cpp
index 4da99b2..de3d274 100644
--- a/src/CBot/CBotVar/CBotVarClass.cpp
+++ b/src/CBot/CBotVar/CBotVarClass.cpp
@@ -394,12 +394,13 @@ void CBotVarClass::DecrementUse()
CBotVar* pThis = CBotVar::Create("this", CBotTypNullPointer);
pThis->SetPointer(this);
- CBotVar* pResult = nullptr;
std::string nom = std::string("~") + m_pClass->GetName();
long ident = 0;
- while ( pile->IsOk() && !m_pClass->ExecuteMethode(ident, nom, pThis, ppVars, pResult, pile, nullptr)) ; // waits for the end
+ CBotToken token(nom); // TODO
+
+ while ( pile->IsOk() && !m_pClass->ExecuteMethode(ident, pThis, ppVars, CBotTypResult(CBotTypVoid), pile, &token)) ; // waits for the end
pile->ResetError(err, start,end);
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index 6ac4d13..dcb39e1 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -2,8 +2,6 @@ set(SOURCES
CBot.h
CBotCStack.cpp
CBotCStack.h
- CBotCallMethode.cpp
- CBotCallMethode.h
CBotClass.cpp
CBotClass.h
CBotDebug.cpp
--
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