[colobot] 120/377: Moving CBotCStack class in its own header and source files.
Didier Raboud
odyx at moszumanska.debian.org
Wed Mar 30 13:34:05 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 013be673ce18ef139b5b3a4580c0eae3b5c883d5
Author: Grunaka <dev at romainbreton.fr>
Date: Sun Nov 15 23:41:24 2015 +0100
Moving CBotCStack class in its own header and source files.
---
src/CBot/CBot.cpp | 1 +
src/CBot/CBot.h | 76 ------
src/CBot/CBotCStack.cpp | 405 ++++++++++++++++++++++++++++++
src/CBot/CBotCStack.h | 267 ++++++++++++++++++++
src/CBot/CBotCall.cpp | 3 +-
src/CBot/CBotCallMethode.cpp | 1 +
src/CBot/CBotClass.cpp | 1 +
src/CBot/CBotDefParam.cpp | 1 +
src/CBot/CBotInstr/CBotBlock.cpp | 2 +
src/CBot/CBotInstr/CBotBoolExpr.cpp | 2 +
src/CBot/CBotInstr/CBotBoolean.cpp | 1 +
src/CBot/CBotInstr/CBotBreak.cpp | 1 +
src/CBot/CBotInstr/CBotCase.cpp | 1 +
src/CBot/CBotInstr/CBotCatch.cpp | 1 +
src/CBot/CBotInstr/CBotClassInst.cpp | 1 +
src/CBot/CBotInstr/CBotCondition.cpp | 2 +
src/CBot/CBotInstr/CBotDo.cpp | 1 +
src/CBot/CBotInstr/CBotExprAlpha.cpp | 1 +
src/CBot/CBotInstr/CBotExprBool.cpp | 1 +
src/CBot/CBotInstr/CBotExprNum.cpp | 1 +
src/CBot/CBotInstr/CBotExprUnaire.cpp | 1 +
src/CBot/CBotInstr/CBotExprVar.cpp | 1 +
src/CBot/CBotInstr/CBotExpression.cpp | 1 +
src/CBot/CBotInstr/CBotFieldExpr.cpp | 1 +
src/CBot/CBotInstr/CBotFloat.cpp | 1 +
src/CBot/CBotInstr/CBotFor.cpp | 1 +
src/CBot/CBotInstr/CBotFunction.cpp | 1 +
src/CBot/CBotInstr/CBotIString.cpp | 1 +
src/CBot/CBotInstr/CBotIf.cpp | 1 +
src/CBot/CBotInstr/CBotIndexExpr.cpp | 1 +
src/CBot/CBotInstr/CBotInstArray.cpp | 1 +
src/CBot/CBotInstr/CBotInstrCall.cpp | 1 +
src/CBot/CBotInstr/CBotInstrMethode.cpp | 1 +
src/CBot/CBotInstr/CBotInt.cpp | 1 +
src/CBot/CBotInstr/CBotLeftExpr.cpp | 1 +
src/CBot/CBotInstr/CBotLeftExprVar.cpp | 1 +
src/CBot/CBotInstr/CBotListArray.cpp | 1 +
src/CBot/CBotInstr/CBotListExpression.cpp | 1 +
src/CBot/CBotInstr/CBotListInstr.cpp | 1 +
src/CBot/CBotInstr/CBotNew.cpp | 1 +
src/CBot/CBotInstr/CBotParExpr.cpp | 2 +
src/CBot/CBotInstr/CBotReturn.cpp | 1 +
src/CBot/CBotInstr/CBotSwitch.cpp | 1 +
src/CBot/CBotInstr/CBotThrow.cpp | 1 +
src/CBot/CBotInstr/CBotTry.cpp | 1 +
src/CBot/CBotInstr/CBotTwoOpExpr.cpp | 1 +
src/CBot/CBotInstr/CBotWhile.cpp | 1 +
src/CBot/CBotProgram.cpp | 1 +
src/CBot/CBotStack.cpp | 389 ----------------------------
src/CBot/CBotUtils.cpp | 1 +
src/CBot/CMakeLists.txt | 1 +
51 files changed, 724 insertions(+), 466 deletions(-)
diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp
index d528d1f..1c8b437 100644
--- a/src/CBot/CBot.cpp
+++ b/src/CBot/CBot.cpp
@@ -73,6 +73,7 @@
#include "CBotInstr/CBotInt.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotClass.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index 98d3f9c..e42d185 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -52,82 +52,6 @@ class CBotIf; // if (...) {...} else {...}
class CBotDefParam; // paramerer list of a function
-
-
-
-////////////////////////////////////////////////////////////////////////
-// Management of the stack of compilation
-////////////////////////////////////////////////////////////////////////
-
-
-class CBotCStack
-{
-private:
- CBotCStack* m_next;
- CBotCStack* m_prev;
-
- static int m_error;
- static int m_end;
- int m_start;
-
- CBotVar* m_var; // result of the operations
-
- bool m_bBlock; // is part of a block (variables are local to this block)
- CBotVar* m_listVar;
-
- static
- CBotProgram* m_prog; // list of compiled functions
- static
- CBotTypResult m_retTyp;
-// static
-// CBotToken* m_retClass;
-
-public:
- CBotCStack(CBotCStack* ppapa);
- ~CBotCStack();
-
- bool IsOk();
- int GetError();
- int GetError(int& start, int& end);
- // gives error number
-
- void SetType(CBotTypResult& type);// determines the type
- CBotTypResult GetTypResult(int mode = 0); // gives the type of value on the stack
- int GetType(int mode = 0); // gives the type of value on the stack
- CBotClass* GetClass(); // gives the class of the value on the stack
-
- void AddVar(CBotVar* p); // adds a local variable
- CBotVar* FindVar(CBotToken* &p); // finds a variable
- CBotVar* FindVar(CBotToken& Token);
- bool CheckVarLocal(CBotToken* &pToken);
- CBotVar* CopyVar(CBotToken& Token); // finds and makes a copy
-
- CBotCStack* TokenStack(CBotToken* pToken = nullptr, bool bBlock = false);
- CBotInstr* Return(CBotInstr* p, CBotCStack* pParent); // transmits the result upper
- CBotFunction* ReturnFunc(CBotFunction* p, CBotCStack* pParent); // transmits the result upper
-
- void SetVar( CBotVar* var );
- void SetCopyVar( CBotVar* var );
- CBotVar* GetVar();
-
- void SetStartError(int pos);
- void SetError(int n, int pos);
- void SetError(int n, CBotToken* p);
- void ResetError(int n, int start, int end);
-
- void SetRetType(CBotTypResult& type);
- CBotTypResult GetRetType();
-
-// void SetBotCall(CBotFunction* &pFunc);
- void SetBotCall(CBotProgram* p);
- CBotProgram* GetBotCall();
- CBotTypResult CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent);
- bool CheckCall(CBotToken* &pToken, CBotDefParam* pParam);
-
- bool NextToken(CBotToken* &p);
-};
-
-
extern bool SaveVar(FILE* pf, CBotVar* pVar);
diff --git a/src/CBot/CBotCStack.cpp b/src/CBot/CBotCStack.cpp
new file mode 100644
index 0000000..6d9b820
--- /dev/null
+++ b/src/CBot/CBotCStack.cpp
@@ -0,0 +1,405 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2015, 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
+ */
+
+
+// Modules inlcude
+#include "CBotCStack.h"
+
+#include "CBotToken.h"
+#include "CBotCall.h"
+
+#include "CBotVar/CBotVar.h"
+
+#include "CBotInstr/CBotFunction.h"
+
+// Local include
+
+// Global include
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+CBotProgram* CBotCStack::m_prog = nullptr; // init the static variable
+int CBotCStack::m_error = 0;
+int CBotCStack::m_end = 0;
+CBotTypResult CBotCStack::m_retTyp = CBotTypResult(0);
+
+////////////////////////////////////////////////////////////////////////////////
+CBotCStack::CBotCStack(CBotCStack* ppapa)
+{
+ m_next = nullptr;
+ m_prev = ppapa;
+
+ if (ppapa == nullptr)
+ {
+ m_error = 0;
+ m_start = 0;
+ m_end = 0;
+ m_bBlock = true;
+ }
+ else
+ {
+ m_start = ppapa->m_start;
+ m_bBlock = false;
+ }
+
+ m_listVar = nullptr;
+ m_var = nullptr;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotCStack::~CBotCStack()
+{
+ if (m_next != nullptr) delete m_next;
+ if (m_prev != nullptr) m_prev->m_next = nullptr; // removes chain
+
+ delete m_var;
+ delete m_listVar;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotCStack* CBotCStack::TokenStack(CBotToken* pToken, bool bBlock)
+{
+ if (m_next != nullptr) return m_next; // include on an existing stack
+
+ CBotCStack* p = new CBotCStack(this);
+ m_next = p; // channel element
+ p->m_bBlock = bBlock;
+
+ if (pToken != nullptr) p->SetStartError(pToken->GetStart());
+
+ return p;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils)
+{
+ if ( pfils == this ) return inst;
+
+ if (m_var != nullptr) delete m_var; // value replaced?
+ m_var = pfils->m_var; // result transmitted
+ pfils->m_var = nullptr; // not to destroy the variable
+
+ if (m_error)
+ {
+ m_start = pfils->m_start; // retrieves the position of the error
+ m_end = pfils->m_end;
+ }
+
+ delete pfils;
+ return inst;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils)
+{
+ if (m_var != nullptr) delete m_var; // value replaced?
+ m_var = pfils->m_var; // result transmitted
+ pfils->m_var = nullptr; // not to destroy the variable
+
+ if (m_error)
+ {
+ m_start = pfils->m_start; // retrieves the position of the error
+ m_end = pfils->m_end;
+ }
+
+ delete pfils;
+ return inst;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int CBotCStack::GetError(int& start, int& end)
+{
+ start = m_start;
+ end = m_end;
+ return m_error;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int CBotCStack::GetError()
+{
+ return m_error;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotTypResult CBotCStack::GetTypResult(int mode)
+{
+ if (m_var == nullptr)
+ return CBotTypResult(99);
+ return m_var->GetTypResult(mode);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int CBotCStack::GetType(int mode)
+{
+ if (m_var == nullptr)
+ return 99;
+ return m_var->GetType(mode);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotClass* CBotCStack::GetClass()
+{
+ if ( m_var == nullptr )
+ return nullptr;
+ if ( m_var->GetType(1) != CBotTypPointer ) return nullptr;
+
+ return m_var->GetClass();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotCStack::SetType(CBotTypResult& type)
+{
+ if (m_var == nullptr) return;
+ m_var->SetType( type );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotVar* CBotCStack::FindVar(CBotToken* &pToken)
+{
+ CBotCStack* p = this;
+ CBotString name = pToken->GetString();
+
+ while (p != nullptr)
+ {
+ CBotVar* pp = p->m_listVar;
+ while ( pp != nullptr)
+ {
+ if (name == pp->GetName())
+ {
+ return pp;
+ }
+ pp = pp->m_next;
+ }
+ p = p->m_prev;
+ }
+ return nullptr;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotVar* CBotCStack::FindVar(CBotToken& Token)
+{
+ CBotToken* pt = &Token;
+ return FindVar(pt);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotVar* CBotCStack::CopyVar(CBotToken& Token)
+{
+ CBotVar* pVar = FindVar( Token );
+
+ if ( pVar == nullptr) return nullptr;
+
+ CBotVar* pCopy = CBotVar::Create( "", pVar->GetType() );
+ pCopy->Copy(pVar);
+ return pCopy;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotCStack::IsOk()
+{
+ return (m_error == 0);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotCStack::SetStartError( int pos )
+{
+ if ( m_error != 0) return; // does not change existing error
+ m_start = pos;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotCStack::SetError(int n, int pos)
+{
+ if ( n!= 0 && m_error != 0) return; // does not change existing error
+ m_error = n;
+ m_end = pos;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotCStack::SetError(int n, CBotToken* p)
+{
+ if (m_error) return; // does not change existing error
+ m_error = n;
+ m_start = p->GetStart();
+ m_end = p->GetEnd();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotCStack::ResetError(int n, int start, int end)
+{
+ m_error = n;
+ m_start = start;
+ m_end = end;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotCStack::NextToken(CBotToken* &p)
+{
+ CBotToken* pp = p;
+
+ p = p->GetNext();
+ if (p!=nullptr) return true;
+
+ SetError(TX_ENDOF, pp->GetEnd());
+ return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotCStack::SetBotCall(CBotProgram* p)
+{
+ m_prog = p;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotProgram* CBotCStack::GetBotCall()
+{
+ return m_prog;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotCStack::SetRetType(CBotTypResult& type)
+{
+ m_retTyp = type;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotTypResult CBotCStack::GetRetType()
+{
+ return m_retTyp;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotCStack::SetVar( CBotVar* var )
+{
+ if (m_var) delete m_var; // replacement of a variable
+ m_var = var;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotCStack::SetCopyVar( CBotVar* var )
+{
+ if (m_var) delete m_var; // replacement of a variable
+
+ if ( var == nullptr ) return;
+ m_var = CBotVar::Create("", var->GetTypResult(2));
+ m_var->Copy( var );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotVar* CBotCStack::GetVar()
+{
+ return m_var;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotCStack::AddVar(CBotVar* pVar)
+{
+ CBotCStack* p = this;
+
+ // returns to the father element
+ while (p != nullptr && p->m_bBlock == 0) p = p->m_prev;
+
+ if ( p == nullptr ) return;
+
+ CBotVar** pp = &p->m_listVar;
+ while ( *pp != nullptr ) pp = &(*pp)->m_next;
+
+ *pp = pVar; // added after
+
+#ifdef _DEBUG
+ if ( pVar->GetUniqNum() == 0 ) assert(0);
+#endif
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotCStack::CheckVarLocal(CBotToken* &pToken)
+{
+ CBotCStack* p = this;
+ CBotString name = pToken->GetString();
+
+ while (p != nullptr)
+ {
+ CBotVar* pp = p->m_listVar;
+ while ( pp != nullptr)
+ {
+ if (name == pp->GetName())
+ return true;
+ pp = pp->m_next;
+ }
+ if ( p->m_bBlock ) return false;
+ p = p->m_prev;
+ }
+ return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent)
+{
+ nIdent = 0;
+ CBotTypResult val(-1);
+
+ val = CBotCall::CompileCall(p, ppVars, this, nIdent);
+ if (val.GetType() < 0)
+ {
+ val = m_prog->GetFunctions()->CompileCall(p->GetString(), ppVars, nIdent);
+ if ( val.GetType() < 0 )
+ {
+ // pVar = nullptr; // the error is not on a particular parameter
+ SetError( -val.GetType(), p );
+ val.SetType(-val.GetType());
+ return val;
+ }
+ }
+ return val;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
+{
+ CBotString name = pToken->GetString();
+
+ if ( CBotCall::CheckCall(name) ) return true;
+
+ CBotFunction* pp = m_prog->GetFunctions();
+ while ( pp != nullptr )
+ {
+ if ( pToken->GetString() == pp->GetName() )
+ {
+ // are parameters exactly the same?
+ if ( pp->CheckParam( pParam ) )
+ return true;
+ }
+ pp = pp->Next();
+ }
+
+ pp = CBotFunction::m_listPublic;
+ while ( pp != nullptr )
+ {
+ if ( pToken->GetString() == pp->GetName() )
+ {
+ // are parameters exactly the same?
+ if ( pp->CheckParam( pParam ) )
+ return true;
+ }
+ pp = pp->m_nextpublic;
+ }
+
+ return false;
+}
diff --git a/src/CBot/CBotCStack.h b/src/CBot/CBotCStack.h
new file mode 100644
index 0000000..28e9e88
--- /dev/null
+++ b/src/CBot/CBotCStack.h
@@ -0,0 +1,267 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2015, 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
+
+// Modules inlcude
+#include "CBotDll.h"
+
+#include "CBotProgram.h"
+
+// Local include
+
+// Global include
+
+
+/*!
+ * \brief The CBotCStack class Management of the stack of compilation.
+ */
+class CBotCStack
+{
+public:
+
+ /*!
+ * \brief CBotCStack
+ * \param ppapa
+ */
+ CBotCStack(CBotCStack* ppapa);
+
+ /*!
+ * \brief CBotCStack Destructor.
+ */
+ ~CBotCStack();
+
+ /*!
+ * \brief IsOk
+ * \return
+ */
+ bool IsOk();
+
+ /*!
+ * \brief GetError
+ * \return
+ */
+ int GetError();
+
+ /*!
+ * \brief GetError Gives error number
+ * \param start
+ * \param end
+ * \return
+ */
+ int GetError(int& start, int& end);
+
+ /*!
+ * \brief SetType Set the type of instruction on the stack.
+ * \param type
+ */
+ void SetType(CBotTypResult& type);
+
+ /*!
+ * \brief GetTypResult Gives the type of value on the stack. Type of
+ * instruction on the stack.
+ * \param mode
+ * \return
+ */
+ CBotTypResult GetTypResult(int mode = 0);
+
+ /*!
+ * \brief GetType Gives the type of value on the stack.
+ * \param mode
+ * \return
+ */
+ int GetType(int mode = 0);
+
+ /*!
+ * \brief GetClass Gives the class of the value on the stack.
+ * \return
+ */
+ CBotClass* GetClass();
+
+ /*!
+ * \brief AddVar Adds a local variable.
+ * \param p
+ */
+ void AddVar(CBotVar* p);
+
+ /*!
+ * \brief FindVar Finds a variable. Seeks a variable on the stack the token
+ * may be a result of TokenTypVar (object of a class) or a pointer in the
+ * source.
+ * \param p
+ * \return
+ */
+ CBotVar* FindVar(CBotToken* &p);
+
+ /*!
+ * \brief FindVar
+ * \param Token
+ * \return
+ */
+ CBotVar* FindVar(CBotToken& Token);
+
+ /*!
+ * \brief CheckVarLocal Test whether a variable is already defined locally.
+ * \param pToken
+ * \return
+ */
+ bool CheckVarLocal(CBotToken* &pToken);
+
+ /*!
+ * \brief CopyVar Finds and makes a copy.
+ * \param Token
+ * \return
+ */
+ CBotVar* CopyVar(CBotToken& Token);
+
+ /*!
+ * \brief TokenStack Used only at compile.
+ * \param pToken
+ * \param bBlock
+ * \return
+ */
+ CBotCStack* TokenStack(CBotToken* pToken = nullptr, bool bBlock = false);
+
+ /*!
+ * \brief Return Transmits the result upper.
+ * \param p
+ * \param pParent
+ * \return
+ */
+ CBotInstr* Return(CBotInstr* p, CBotCStack* pParent);
+
+ /*!
+ * \brief ReturnFunc Transmits the result upper.
+ * \param p
+ * \param pParent
+ * \return
+ */
+ CBotFunction* ReturnFunc(CBotFunction* p, CBotCStack* pParent);
+
+ /*!
+ * \brief SetVar
+ * \param var
+ */
+ void SetVar( CBotVar* var );
+
+ /*!
+ * \brief SetCopyVar Puts on the stack a copy of a variable.
+ * \param var
+ */
+ void SetCopyVar( CBotVar* var );
+
+ /*!
+ * \brief GetVar
+ * \return
+ */
+ CBotVar* GetVar();
+
+ /*!
+ * \brief SetStartError
+ * \param pos
+ */
+ void SetStartError(int pos);
+
+ /*!
+ * \brief SetError
+ * \param n
+ * \param pos
+ */
+ void SetError(int n, int pos);
+
+ /*!
+ * \brief SetError
+ * \param n
+ * \param p
+ */
+ void SetError(int n, CBotToken* p);
+
+ /*!
+ * \brief ResetError
+ * \param n
+ * \param start
+ * \param end
+ */
+ void ResetError(int n, int start, int end);
+
+ /*!
+ * \brief SetRetType
+ * \param type
+ */
+ void SetRetType(CBotTypResult& type);
+
+ /*!
+ * \brief GetRetType
+ * \return
+ */
+ CBotTypResult GetRetType();
+
+ /*!
+ * \brief SetBotCall
+ * \param p
+ */
+ void SetBotCall(CBotProgram* p);
+
+ /*!
+ * \brief GetBotCall
+ * \return
+ */
+ CBotProgram* GetBotCall();
+
+ /*!
+ * \brief CompileCall
+ * \param p
+ * \param ppVars
+ * \param nIdent
+ * \return
+ */
+ CBotTypResult CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent);
+
+ /*!
+ * \brief CheckCall Test if a procedure name is already defined somewhere.
+ * \param pToken
+ * \param pParam
+ * \return
+ */
+ bool CheckCall(CBotToken* &pToken, CBotDefParam* pParam);
+
+ /*!
+ * \brief NextToken
+ * \param p
+ * \return
+ */
+ bool NextToken(CBotToken* &p);
+
+private:
+ CBotCStack* m_next;
+ CBotCStack* m_prev;
+
+ static int m_error;
+ static int m_end;
+ int m_start;
+
+ //! Result of the operations.
+ CBotVar* m_var;
+ //! Is part of a block (variables are local to this block).
+ bool m_bBlock;
+ CBotVar* m_listVar;
+ //! List of compiled functions.
+ static CBotProgram* m_prog;
+ static CBotTypResult m_retTyp;
+};
diff --git a/src/CBot/CBotCall.cpp b/src/CBot/CBotCall.cpp
index 75beb6f..ee853d8 100644
--- a/src/CBot/CBotCall.cpp
+++ b/src/CBot/CBotCall.cpp
@@ -22,11 +22,12 @@
#include "CBotToken.h"
#include "CBotStack.h"
-
+#include "CBotCStack.h"
#include "CBotUtils.h"
#include "CBotVar/CBotVar.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotCallMethode.cpp b/src/CBot/CBotCallMethode.cpp
index 2bcc41c..da915df 100644
--- a/src/CBot/CBotCallMethode.cpp
+++ b/src/CBot/CBotCallMethode.cpp
@@ -22,6 +22,7 @@
#include "CBotUtils.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp
index 9e20d66..94a0534 100644
--- a/src/CBot/CBotClass.cpp
+++ b/src/CBot/CBotClass.cpp
@@ -30,6 +30,7 @@
#include "CBotCall.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotUtils.h"
#include "CBotCallMethode.h"
diff --git a/src/CBot/CBotDefParam.cpp b/src/CBot/CBotDefParam.cpp
index 601e567..9af6043 100644
--- a/src/CBot/CBotDefParam.cpp
+++ b/src/CBot/CBotDefParam.cpp
@@ -23,6 +23,7 @@
#include "CBot.h"
#include "CBotUtils.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVarClass.h"
diff --git a/src/CBot/CBotInstr/CBotBlock.cpp b/src/CBot/CBotInstr/CBotBlock.cpp
index ed87b53..ba2b5ce 100644
--- a/src/CBot/CBotInstr/CBotBlock.cpp
+++ b/src/CBot/CBotInstr/CBotBlock.cpp
@@ -19,6 +19,8 @@
// Modules inlcude
#include "CBotBlock.h"
+
+#include "CBotCStack.h"
#include "CBotListInstr.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotBoolExpr.cpp b/src/CBot/CBotInstr/CBotBoolExpr.cpp
index 2815c8e..db6b36b 100644
--- a/src/CBot/CBotInstr/CBotBoolExpr.cpp
+++ b/src/CBot/CBotInstr/CBotBoolExpr.cpp
@@ -21,6 +21,8 @@
#include "CBotBoolExpr.h"
#include "CBotTwoOpExpr.h"
+#include "CBotCStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotBoolean.cpp b/src/CBot/CBotInstr/CBotBoolean.cpp
index ea0103e..64c4d3d 100644
--- a/src/CBot/CBotInstr/CBotBoolean.cpp
+++ b/src/CBot/CBotInstr/CBotBoolean.cpp
@@ -24,6 +24,7 @@
#include "CBotInstArray.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotInstr/CBotBreak.cpp b/src/CBot/CBotInstr/CBotBreak.cpp
index 5879f0f..9d4100c 100644
--- a/src/CBot/CBotInstr/CBotBreak.cpp
+++ b/src/CBot/CBotInstr/CBotBreak.cpp
@@ -21,6 +21,7 @@
#include "CBotBreak.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotCase.cpp b/src/CBot/CBotInstr/CBotCase.cpp
index f188f8e..3ae5b70 100644
--- a/src/CBot/CBotInstr/CBotCase.cpp
+++ b/src/CBot/CBotInstr/CBotCase.cpp
@@ -22,6 +22,7 @@
#include "CBotExprNum.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotCatch.cpp b/src/CBot/CBotInstr/CBotCatch.cpp
index fdbc1d4..26f7d17 100644
--- a/src/CBot/CBotInstr/CBotCatch.cpp
+++ b/src/CBot/CBotInstr/CBotCatch.cpp
@@ -23,6 +23,7 @@
#include "CBotExpression.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp
index 8426422..5d2e0a6 100644
--- a/src/CBot/CBotInstr/CBotClassInst.cpp
+++ b/src/CBot/CBotInstr/CBotClassInst.cpp
@@ -24,6 +24,7 @@
#include "CBotInstArray.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotClass.h"
#include "CBotVar/CBotVarPointer.h"
diff --git a/src/CBot/CBotInstr/CBotCondition.cpp b/src/CBot/CBotInstr/CBotCondition.cpp
index d87c451..453e26c 100644
--- a/src/CBot/CBotInstr/CBotCondition.cpp
+++ b/src/CBot/CBotInstr/CBotCondition.cpp
@@ -21,6 +21,8 @@
#include "CBotCondition.h"
#include "CBotBoolExpr.h"
+#include "CBotCStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotDo.cpp b/src/CBot/CBotInstr/CBotDo.cpp
index 9cfeddb..c24baff 100644
--- a/src/CBot/CBotInstr/CBotDo.cpp
+++ b/src/CBot/CBotInstr/CBotDo.cpp
@@ -23,6 +23,7 @@
#include "CBotCondition.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotExprAlpha.cpp b/src/CBot/CBotInstr/CBotExprAlpha.cpp
index 6092375..1f93b89 100644
--- a/src/CBot/CBotInstr/CBotExprAlpha.cpp
+++ b/src/CBot/CBotInstr/CBotExprAlpha.cpp
@@ -21,6 +21,7 @@
#include "CBotExprAlpha.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotInstr/CBotExprBool.cpp b/src/CBot/CBotInstr/CBotExprBool.cpp
index ebefa6d..3df5095 100644
--- a/src/CBot/CBotInstr/CBotExprBool.cpp
+++ b/src/CBot/CBotInstr/CBotExprBool.cpp
@@ -21,6 +21,7 @@
#include "CBotExprBool.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotInstr/CBotExprNum.cpp b/src/CBot/CBotInstr/CBotExprNum.cpp
index 6082c0e..65dbd78 100644
--- a/src/CBot/CBotInstr/CBotExprNum.cpp
+++ b/src/CBot/CBotInstr/CBotExprNum.cpp
@@ -21,6 +21,7 @@
#include "CBotExprNum.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotInstr/CBotExprUnaire.cpp b/src/CBot/CBotInstr/CBotExprUnaire.cpp
index 4732eda..31056bb 100644
--- a/src/CBot/CBotInstr/CBotExprUnaire.cpp
+++ b/src/CBot/CBotInstr/CBotExprUnaire.cpp
@@ -22,6 +22,7 @@
#include "CBotParExpr.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp
index 344ce85..ee4a748 100644
--- a/src/CBot/CBotInstr/CBotExprVar.cpp
+++ b/src/CBot/CBotInstr/CBotExprVar.cpp
@@ -25,6 +25,7 @@
#include "CBotFieldExpr.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVarArray.h"
diff --git a/src/CBot/CBotInstr/CBotExpression.cpp b/src/CBot/CBotInstr/CBotExpression.cpp
index bdf096a..b6b9783 100644
--- a/src/CBot/CBotInstr/CBotExpression.cpp
+++ b/src/CBot/CBotInstr/CBotExpression.cpp
@@ -22,6 +22,7 @@
#include "CBotTwoOpExpr.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotInstr/CBotFieldExpr.cpp b/src/CBot/CBotInstr/CBotFieldExpr.cpp
index bad06d9..7c4ff58 100644
--- a/src/CBot/CBotInstr/CBotFieldExpr.cpp
+++ b/src/CBot/CBotInstr/CBotFieldExpr.cpp
@@ -21,6 +21,7 @@
#include "CBotFieldExpr.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotClass.h"
#include "CBotVar/CBotVarClass.h"
diff --git a/src/CBot/CBotInstr/CBotFloat.cpp b/src/CBot/CBotInstr/CBotFloat.cpp
index 1a72145..df69b07 100644
--- a/src/CBot/CBotInstr/CBotFloat.cpp
+++ b/src/CBot/CBotInstr/CBotFloat.cpp
@@ -24,6 +24,7 @@
#include "CBotInstArray.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotInstr/CBotFor.cpp b/src/CBot/CBotInstr/CBotFor.cpp
index 7cbca51..2a97b86 100644
--- a/src/CBot/CBotInstr/CBotFor.cpp
+++ b/src/CBot/CBotInstr/CBotFor.cpp
@@ -24,6 +24,7 @@
#include "CBotBoolExpr.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp
index 6700fab..d325020 100644
--- a/src/CBot/CBotInstr/CBotFunction.cpp
+++ b/src/CBot/CBotInstr/CBotFunction.cpp
@@ -30,6 +30,7 @@
#include "CBotInstr/CBotListArray.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotClass.h"
#include "CBotDefParam.h"
#include "CBotUtils.h"
diff --git a/src/CBot/CBotInstr/CBotIString.cpp b/src/CBot/CBotInstr/CBotIString.cpp
index 3c34811..6feefc4 100644
--- a/src/CBot/CBotInstr/CBotIString.cpp
+++ b/src/CBot/CBotInstr/CBotIString.cpp
@@ -23,6 +23,7 @@
#include "CBotTwoOpExpr.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotInstr/CBotIf.cpp b/src/CBot/CBotInstr/CBotIf.cpp
index b0cdbc8..1075f65 100644
--- a/src/CBot/CBotInstr/CBotIf.cpp
+++ b/src/CBot/CBotInstr/CBotIf.cpp
@@ -23,6 +23,7 @@
#include "CBotInstr/CBotCondition.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotIndexExpr.cpp b/src/CBot/CBotInstr/CBotIndexExpr.cpp
index 2bc37f1..471089c 100644
--- a/src/CBot/CBotInstr/CBotIndexExpr.cpp
+++ b/src/CBot/CBotInstr/CBotIndexExpr.cpp
@@ -21,6 +21,7 @@
#include "CBotIndexExpr.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVarArray.h"
diff --git a/src/CBot/CBotInstr/CBotInstArray.cpp b/src/CBot/CBotInstr/CBotInstArray.cpp
index f53cb65..7d2a441 100644
--- a/src/CBot/CBotInstr/CBotInstArray.cpp
+++ b/src/CBot/CBotInstr/CBotInstArray.cpp
@@ -26,6 +26,7 @@
#include "CBotEmpty.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotDefines.h"
diff --git a/src/CBot/CBotInstr/CBotInstrCall.cpp b/src/CBot/CBotInstr/CBotInstrCall.cpp
index c2c33b0..ca21b87 100644
--- a/src/CBot/CBotInstr/CBotInstrCall.cpp
+++ b/src/CBot/CBotInstr/CBotInstrCall.cpp
@@ -22,6 +22,7 @@
#include "CBotExpression.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp
index dabcd46..46adf72 100644
--- a/src/CBot/CBotInstr/CBotInstrMethode.cpp
+++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp
@@ -21,6 +21,7 @@
#include "CBotInstrMethode.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotClass.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotInstr/CBotInt.cpp b/src/CBot/CBotInstr/CBotInt.cpp
index 1649de5..7ea8cbf 100644
--- a/src/CBot/CBotInstr/CBotInt.cpp
+++ b/src/CBot/CBotInstr/CBotInt.cpp
@@ -25,6 +25,7 @@
#include "CBotTwoOpExpr.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotInstr/CBotLeftExpr.cpp b/src/CBot/CBotInstr/CBotLeftExpr.cpp
index 468854a..e09a226 100644
--- a/src/CBot/CBotInstr/CBotLeftExpr.cpp
+++ b/src/CBot/CBotInstr/CBotLeftExpr.cpp
@@ -24,6 +24,7 @@
#include "CBotExpression.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotClass.h"
#include "CBotVar/CBotVarArray.h"
diff --git a/src/CBot/CBotInstr/CBotLeftExprVar.cpp b/src/CBot/CBotInstr/CBotLeftExprVar.cpp
index d0c3482..18af17c 100644
--- a/src/CBot/CBotInstr/CBotLeftExprVar.cpp
+++ b/src/CBot/CBotInstr/CBotLeftExprVar.cpp
@@ -21,6 +21,7 @@
#include "CBotLeftExprVar.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp
index 682505b..6ac0d6a 100644
--- a/src/CBot/CBotInstr/CBotListArray.cpp
+++ b/src/CBot/CBotInstr/CBotListArray.cpp
@@ -24,6 +24,7 @@
#include "CBotTwoOpExpr.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotInstr/CBotListExpression.cpp b/src/CBot/CBotInstr/CBotListExpression.cpp
index afa5f87..670f3fb 100644
--- a/src/CBot/CBotInstr/CBotListExpression.cpp
+++ b/src/CBot/CBotInstr/CBotListExpression.cpp
@@ -26,6 +26,7 @@
#include "CBotInt.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotListInstr.cpp b/src/CBot/CBotInstr/CBotListInstr.cpp
index fde2103..576012b 100644
--- a/src/CBot/CBotInstr/CBotListInstr.cpp
+++ b/src/CBot/CBotInstr/CBotListInstr.cpp
@@ -22,6 +22,7 @@
#include "CBotBlock.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotNew.cpp b/src/CBot/CBotInstr/CBotNew.cpp
index 094e5a0..6f7d860 100644
--- a/src/CBot/CBotInstr/CBotNew.cpp
+++ b/src/CBot/CBotInstr/CBotNew.cpp
@@ -21,6 +21,7 @@
#include "CBotNew.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotClass.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotInstr/CBotParExpr.cpp b/src/CBot/CBotInstr/CBotParExpr.cpp
index fc34b51..21b40d1 100644
--- a/src/CBot/CBotInstr/CBotParExpr.cpp
+++ b/src/CBot/CBotInstr/CBotParExpr.cpp
@@ -34,6 +34,8 @@
#include "CBotVar/CBotVar.h"
+#include "CBotCStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotReturn.cpp b/src/CBot/CBotInstr/CBotReturn.cpp
index 3837b26..70c849d 100644
--- a/src/CBot/CBotInstr/CBotReturn.cpp
+++ b/src/CBot/CBotInstr/CBotReturn.cpp
@@ -22,6 +22,7 @@
#include "CBotExpression.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotSwitch.cpp b/src/CBot/CBotInstr/CBotSwitch.cpp
index 0a527d2..ef53fd7 100644
--- a/src/CBot/CBotInstr/CBotSwitch.cpp
+++ b/src/CBot/CBotInstr/CBotSwitch.cpp
@@ -26,6 +26,7 @@
#include "CBotExpression.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotThrow.cpp b/src/CBot/CBotInstr/CBotThrow.cpp
index c02f221..4fc8cdd 100644
--- a/src/CBot/CBotInstr/CBotThrow.cpp
+++ b/src/CBot/CBotInstr/CBotThrow.cpp
@@ -22,6 +22,7 @@
#include "CBotExpression.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotTry.cpp b/src/CBot/CBotInstr/CBotTry.cpp
index 2ac2ae6..d3aecf8 100644
--- a/src/CBot/CBotInstr/CBotTry.cpp
+++ b/src/CBot/CBotInstr/CBotTry.cpp
@@ -22,6 +22,7 @@
#include "CBotBlock.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp
index 4ad5ad0..ab5bc65 100644
--- a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp
+++ b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp
@@ -24,6 +24,7 @@
#include "CBotExpression.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CBotInstr/CBotWhile.cpp b/src/CBot/CBotInstr/CBotWhile.cpp
index bfc2061..eb38aea 100644
--- a/src/CBot/CBotInstr/CBotWhile.cpp
+++ b/src/CBot/CBotInstr/CBotWhile.cpp
@@ -23,6 +23,7 @@
#include "CBotCondition.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
// Local include
diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp
index 44eaca5..4e3f2c4 100644
--- a/src/CBot/CBotProgram.cpp
+++ b/src/CBot/CBotProgram.cpp
@@ -22,6 +22,7 @@
#include "CBotCall.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotClass.h"
#include "CBotUtils.h"
diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp
index 87aa0bb..91f91a9 100644
--- a/src/CBot/CBotStack.cpp
+++ b/src/CBot/CBotStack.cpp
@@ -1133,392 +1133,3 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
}
return true;
}
-
-
-
-
-////////////////////////////////////////////////////////////////////////////
-// management of the compile stack
-////////////////////////////////////////////////////////////////////////////
-
-CBotProgram* CBotCStack::m_prog = nullptr; // init the static variable
-int CBotCStack::m_error = 0;
-int CBotCStack::m_end = 0;
-CBotTypResult CBotCStack::m_retTyp = CBotTypResult(0);
-//CBotToken* CBotCStack::m_retClass= nullptr;
-
-////////////////////////////////////////////////////////////////////////////////
-CBotCStack::CBotCStack(CBotCStack* ppapa)
-{
- m_next = nullptr;
- m_prev = ppapa;
-
- if (ppapa == nullptr)
- {
- m_error = 0;
- m_start = 0;
- m_end = 0;
- m_bBlock = true;
- }
- else
- {
- m_start = ppapa->m_start;
- m_bBlock = false;
- }
-
- m_listVar = nullptr;
- m_var = nullptr;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// destructor
-CBotCStack::~CBotCStack()
-{
- if (m_next != nullptr) delete m_next;
- if (m_prev != nullptr) m_prev->m_next = nullptr; // removes chain
-
- delete m_var;
- delete m_listVar;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// used only at compile
-CBotCStack* CBotCStack::TokenStack(CBotToken* pToken, bool bBlock)
-{
- if (m_next != nullptr) return m_next; // include on an existing stack
-
- CBotCStack* p = new CBotCStack(this);
- m_next = p; // channel element
- p->m_bBlock = bBlock;
-
- if (pToken != nullptr) p->SetStartError(pToken->GetStart());
-
- return p;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils)
-{
- if ( pfils == this ) return inst;
-
- if (m_var != nullptr) delete m_var; // value replaced?
- m_var = pfils->m_var; // result transmitted
- pfils->m_var = nullptr; // not to destroy the variable
-
- if (m_error)
- {
- m_start = pfils->m_start; // retrieves the position of the error
- m_end = pfils->m_end;
- }
-
- delete pfils;
- return inst;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils)
-{
- if (m_var != nullptr) delete m_var; // value replaced?
- m_var = pfils->m_var; // result transmitted
- pfils->m_var = nullptr; // not to destroy the variable
-
- if (m_error)
- {
- m_start = pfils->m_start; // retrieves the position of the error
- m_end = pfils->m_end;
- }
-
- delete pfils;
- return inst;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-int CBotCStack::GetError(int& start, int& end)
-{
- start = m_start;
- end = m_end;
- return m_error;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-int CBotCStack::GetError()
-{
- return m_error;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// type of instruction on the stack
-CBotTypResult CBotCStack::GetTypResult(int mode)
-{
- if (m_var == nullptr)
- return CBotTypResult(99);
- return m_var->GetTypResult(mode);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// type of instruction on the stack
-int CBotCStack::GetType(int mode)
-{
- if (m_var == nullptr)
- return 99;
- return m_var->GetType(mode);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// pointer on the stack is in what class?
-CBotClass* CBotCStack::GetClass()
-{
- if ( m_var == nullptr )
- return nullptr;
- if ( m_var->GetType(1) != CBotTypPointer ) return nullptr;
-
- return m_var->GetClass();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// type of instruction on the stack
-void CBotCStack::SetType(CBotTypResult& type)
-{
- if (m_var == nullptr) return;
- m_var->SetType( type );
-}
-
-// seeks a variable on the stack
-// the token may be a result of TokenTypVar (object of a class)
-// or a pointer in the source
-////////////////////////////////////////////////////////////////////////////////
-CBotVar* CBotCStack::FindVar(CBotToken* &pToken)
-{
- CBotCStack* p = this;
- CBotString name = pToken->GetString();
-
- while (p != nullptr)
- {
- CBotVar* pp = p->m_listVar;
- while ( pp != nullptr)
- {
- if (name == pp->GetName())
- {
- return pp;
- }
- pp = pp->m_next;
- }
- p = p->m_prev;
- }
- return nullptr;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-CBotVar* CBotCStack::FindVar(CBotToken& Token)
-{
- CBotToken* pt = &Token;
- return FindVar(pt);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-CBotVar* CBotCStack::CopyVar(CBotToken& Token)
-{
- CBotVar* pVar = FindVar( Token );
-
- if ( pVar == nullptr) return nullptr;
-
- CBotVar* pCopy = CBotVar::Create( "", pVar->GetType() );
- pCopy->Copy(pVar);
- return pCopy;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-bool CBotCStack::IsOk()
-{
- return (m_error == 0);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-void CBotCStack::SetStartError( int pos )
-{
- if ( m_error != 0) return; // does not change existing error
- m_start = pos;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-void CBotCStack::SetError(int n, int pos)
-{
- if ( n!= 0 && m_error != 0) return; // does not change existing error
- m_error = n;
- m_end = pos;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-void CBotCStack::SetError(int n, CBotToken* p)
-{
- if (m_error) return; // does not change existing error
- m_error = n;
- m_start = p->GetStart();
- m_end = p->GetEnd();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-void CBotCStack::ResetError(int n, int start, int end)
-{
- m_error = n;
- m_start = start;
- m_end = end;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-bool CBotCStack::NextToken(CBotToken* &p)
-{
- CBotToken* pp = p;
-
- p = p->GetNext();
- if (p!=nullptr) return true;
-
- SetError(TX_ENDOF, pp->GetEnd());
- return false;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-void CBotCStack::SetBotCall(CBotProgram* p)
-{
- m_prog = p;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-CBotProgram* CBotCStack::GetBotCall()
-{
- return m_prog;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-void CBotCStack::SetRetType(CBotTypResult& type)
-{
- m_retTyp = type;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-CBotTypResult CBotCStack::GetRetType()
-{
- return m_retTyp;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-void CBotCStack::SetVar( CBotVar* var )
-{
- if (m_var) delete m_var; // replacement of a variable
- m_var = var;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// puts on the stack a copy of a variable
-void CBotCStack::SetCopyVar( CBotVar* var )
-{
- if (m_var) delete m_var; // replacement of a variable
-
- if ( var == nullptr ) return;
- m_var = CBotVar::Create("", var->GetTypResult(2));
- m_var->Copy( var );
-}
-
-////////////////////////////////////////////////////////////////////////////////
-CBotVar* CBotCStack::GetVar()
-{
- return m_var;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-void CBotCStack::AddVar(CBotVar* pVar)
-{
- CBotCStack* p = this;
-
- // returns to the father element
- while (p != nullptr && p->m_bBlock == 0) p = p->m_prev;
-
- if ( p == nullptr ) return;
-
- CBotVar** pp = &p->m_listVar;
- while ( *pp != nullptr ) pp = &(*pp)->m_next;
-
- *pp = pVar; // added after
-
-#ifdef _DEBUG
- if ( pVar->GetUniqNum() == 0 ) assert(0);
-#endif
-}
-
-// test whether a variable is already defined locally
-////////////////////////////////////////////////////////////////////////////////
-bool CBotCStack::CheckVarLocal(CBotToken* &pToken)
-{
- CBotCStack* p = this;
- CBotString name = pToken->GetString();
-
- while (p != nullptr)
- {
- CBotVar* pp = p->m_listVar;
- while ( pp != nullptr)
- {
- if (name == pp->GetName())
- return true;
- pp = pp->m_next;
- }
- if ( p->m_bBlock ) return false;
- p = p->m_prev;
- }
- return false;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent)
-{
- nIdent = 0;
- CBotTypResult val(-1);
-
- val = CBotCall::CompileCall(p, ppVars, this, nIdent);
- if (val.GetType() < 0)
- {
- val = m_prog->GetFunctions()->CompileCall(p->GetString(), ppVars, nIdent);
- if ( val.GetType() < 0 )
- {
- // pVar = nullptr; // the error is not on a particular parameter
- SetError( -val.GetType(), p );
- val.SetType(-val.GetType());
- return val;
- }
- }
- return val;
-}
-
-// test if a procedure name is already defined somewhere
-////////////////////////////////////////////////////////////////////////////////
-bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
-{
- CBotString name = pToken->GetString();
-
- if ( CBotCall::CheckCall(name) ) return true;
-
- CBotFunction* pp = m_prog->GetFunctions();
- while ( pp != nullptr )
- {
- if ( pToken->GetString() == pp->GetName() )
- {
- // are parameters exactly the same?
- if ( pp->CheckParam( pParam ) )
- return true;
- }
- pp = pp->Next();
- }
-
- pp = CBotFunction::m_listPublic;
- while ( pp != nullptr )
- {
- if ( pToken->GetString() == pp->GetName() )
- {
- // are parameters exactly the same?
- if ( pp->CheckParam( pParam ) )
- return true;
- }
- pp = pp->m_nextpublic;
- }
-
- return false;
-}
diff --git a/src/CBot/CBotUtils.cpp b/src/CBot/CBotUtils.cpp
index b5f9c23..2df62cc 100644
--- a/src/CBot/CBotUtils.cpp
+++ b/src/CBot/CBotUtils.cpp
@@ -23,6 +23,7 @@
#include "CBotToken.h"
#include "CBotClass.h"
#include "CBotStack.h"
+#include "CBotCStack.h"
#include "CBotVar/CBotVar.h"
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index 87303c4..e69beae 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -3,6 +3,7 @@ set(SOURCES
CBotClass.cpp
CBotProgram.cpp
CBotStack.cpp
+ CBotCStack.cpp
CBotString.cpp
CBotToken.cpp
CBotCall.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