[colobot] 103/377: Moving CBotStack class in its own header and source files.
Didier Raboud
odyx at moszumanska.debian.org
Wed Mar 30 13:34:03 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 e54d8f1ebc6baa2d2eedd3e5a4fe9954554c8d8b
Author: Grunaka <dev at romainbreton.fr>
Date: Sat Nov 14 12:56:16 2015 +0100
Moving CBotStack class in its own header and source files.
---
src/CBot/CBot.cpp | 2 +
src/CBot/CBot.h | 247 ---------------------------
src/CBot/CBotFunction.cpp | 2 +
src/CBot/CBotInstr/CBotBoolean.cpp | 2 +
src/CBot/CBotInstr/CBotBreak.cpp | 2 +
src/CBot/CBotInstr/CBotCase.cpp | 2 +
src/CBot/CBotInstr/CBotCatch.cpp | 2 +
src/CBot/CBotInstr/CBotClassInst.cpp | 2 +
src/CBot/CBotInstr/CBotDo.cpp | 2 +
src/CBot/CBotInstr/CBotEmpty.cpp | 2 +
src/CBot/CBotInstr/CBotExprAlpha.cpp | 2 +
src/CBot/CBotInstr/CBotExprBool.cpp | 2 +
src/CBot/CBotInstr/CBotExprNan.cpp | 2 +
src/CBot/CBotInstr/CBotExprNull.cpp | 2 +
src/CBot/CBotInstr/CBotExprNum.cpp | 2 +
src/CBot/CBotInstr/CBotExprUnaire.cpp | 2 +
src/CBot/CBotInstr/CBotExprVar.cpp | 2 +
src/CBot/CBotInstr/CBotExpression.cpp | 2 +
src/CBot/CBotInstr/CBotFieldExpr.cpp | 2 +
src/CBot/CBotInstr/CBotFloat.cpp | 2 +
src/CBot/CBotInstr/CBotFor.cpp | 2 +
src/CBot/CBotInstr/CBotIString.cpp | 2 +
src/CBot/CBotInstr/CBotIf.cpp | 2 +
src/CBot/CBotInstr/CBotIndexExpr.cpp | 2 +
src/CBot/CBotInstr/CBotInstArray.cpp | 2 +
src/CBot/CBotInstr/CBotInstrCall.cpp | 2 +
src/CBot/CBotInstr/CBotInstrMethode.cpp | 2 +
src/CBot/CBotInstr/CBotInt.cpp | 2 +
src/CBot/CBotInstr/CBotLeftExpr.cpp | 2 +
src/CBot/CBotInstr/CBotLeftExprVar.cpp | 2 +
src/CBot/CBotInstr/CBotListArray.cpp | 2 +
src/CBot/CBotInstr/CBotListExpression.cpp | 2 +
src/CBot/CBotInstr/CBotListInstr.cpp | 2 +
src/CBot/CBotInstr/CBotLogicExpr.cpp | 2 +
src/CBot/CBotInstr/CBotNew.cpp | 2 +
src/CBot/CBotInstr/CBotParExpr.h | 2 +
src/CBot/CBotInstr/CBotPostIncExpr.cpp | 2 +
src/CBot/CBotInstr/CBotPreIncExpr.cpp | 2 +
src/CBot/CBotInstr/CBotReturn.cpp | 2 +
src/CBot/CBotInstr/CBotSwitch.cpp | 2 +
src/CBot/CBotInstr/CBotThrow.cpp | 2 +
src/CBot/CBotInstr/CBotTry.cpp | 2 +
src/CBot/CBotInstr/CBotTwoOpExpr.cpp | 3 +-
src/CBot/CBotInstr/CBotWhile.cpp | 2 +
src/CBot/CBotProgram.cpp | 3 +
src/CBot/CBotStack.cpp | 145 +++++++++++-----
src/CBot/CBotStack.h | 270 ++++++++++++++++++++++++++++++
src/CBot/CBotVar.cpp | 2 +
48 files changed, 463 insertions(+), 291 deletions(-)
diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp
index a7b8cc4..30f2246 100644
--- a/src/CBot/CBot.cpp
+++ b/src/CBot/CBot.cpp
@@ -72,6 +72,8 @@
#include "CBotInstr/CBotInstArray.h"
#include "CBotInstr/CBotInt.h"
+#include "CBotStack.h"
+
// Local include
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index db9c109..15c870e 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -53,254 +53,7 @@ class CBotDefParam; // paramerer list of a function
-////////////////////////////////////////////////////////////////////////
-// Management of the execution stack
-////////////////////////////////////////////////////////////////////////
-
-// actually, externally, the only thing it can do
-// is to create an instance of a stack
-// to use for routine CBotProgram :: Execute (CBotStack)
-
-
-/**\class CBotStack
- * \brief Management of the execution stack.
- * \brief Actually the only thing it can do is to create an instance of a stack
- * \brief to use for routine CBotProgram :: Execute(CBotStack)*/
-class CBotStack
-{
-public:
-#if STACKMEM
- /**
- * \brief FirstStack Allocate first stack
- * \return pointer to created stack
- */
- static CBotStack * FirstStack();
-
- /** \brief Delete Remove current stack */
- void Delete();
-#endif
-
- /**
- * \brief CBotStack Constructor of the stack
- * \param ppapa Not used.
- */
- CBotStack(CBotStack* ppapa);
-
-
- /** \brief ~CBotStack Destructor */
- ~CBotStack();
-
- /**
- * \brief StackOver Check if end of stack is reached
- * \return true if end of stack
- */
- bool StackOver();
-
- /**
- * \brief GetError Get error number of the stack
- * \param [out] start beginning of the stack
- * \param [out] end end of stack
- * \return error number
- */
- int GetError(int& start, int& end);
-
- /**
- * \brief GetError Get error number
- * \return eror number
- */
- int GetError();// rend le numéro d'erreur retourné
-
- /**
- * \brief Reset Reset error at and set user
- * \param [in] pUser User of stack
- */
- void Reset(void* pUser);
-
- /**
- * \brief SetType Determines the type.
- * \param type Type of instruction on the stack.
- */
- void SetType(CBotTypResult& type);
-
- /**
- * \brief GetType Get the type of value on the stack.
- * \param [in] mode Used when getting class type (1 gives pointer, 2 gives intrinsic).
- * \return Type number.
- */
- int GetType(int mode = 0);
-
- /**
- * \brief Getes the type of complete value on the stack.
- * \param [in] mode Used when getting class type (1 gives pointer, 2 gives intrinsic).
- * \return Type of an element.
- */
- CBotTypResult GetTypResult(int mode = 0);
-
- /**
- * \brief Adds a local variable.
- * \param [in] p Variable to be added.
- */
- void AddVar(CBotVar* p);
-
- /**
- * \brief Fetch a variable by its token.
- * \brief This may be a composite variable
- * \param [in] pToken Token upon which search is performed
- * \param [in] bUpdate Not used. Probably need to be removed
- * \param [in] bModif Not used. Probably need to be removed
- * \return Found variable
- */
- CBotVar* FindVar(CBotToken* &pToken, bool bUpdate = false,
- bool bModif = false);
-
- /**
- * \brief Fetch a variable by its token.
- * \brief This may be a composite variable
- * \param [in] pToken Token upon which search is performed
- * \param [in] bUpdate Not used. Probably need to be removed
- * \param [in] bModif Not used. Probably need to be removed
- * \return Found variable
- */
- CBotVar* FindVar(CBotToken& pToken, bool bUpdate = false,
- bool bModif = false);
-
- /**
- * \brief Fetch variable by its name
- * \param [in] name Name of variable to find
- * \return Found variable
- */
- CBotVar* FindVar(const char* name);
-
- /**
- * \brief Fetch a variable on the stack according to its identification number
- * \brief This is faster than comparing names
- * \param [in] ident Identifier of a variable
- * \param [in] bUpdate Not used. Probably need to be removed
- * \param [in] bModif Not used. Probably need to be removed
- * \return Found variable
- */
- CBotVar* FindVar(long ident, bool bUpdate = false,
- bool bModif = false);
-
- /**
- * \brief Find variable by its token and returns a copy of it.
- * \param Token Token upon which search is performed
- * \param bUpdate Not used.
- * \return Found variable, nullptr if not found
- */
- CBotVar* CopyVar(CBotToken& Token, bool bUpdate = false);
-
-
- CBotStack* AddStack(CBotInstr* instr = nullptr, bool bBlock = false); // extends the stack
- CBotStack* AddStackEOX(CBotCall* instr = nullptr, bool bBlock = false); // extends the stack
- CBotStack* RestoreStack(CBotInstr* instr = nullptr);
- CBotStack* RestoreStackEOX(CBotCall* instr = nullptr);
-
- CBotStack* AddStack2(bool bBlock = false); // extends the stack
- bool Return(CBotStack* pFils); // transmits the result over
- bool ReturnKeep(CBotStack* pFils); // transmits the result without reducing the stack
- bool BreakReturn(CBotStack* pfils, const char* name = nullptr);
- // in case of eventual break
- bool IfContinue(int state, const char* name);
- // or "continue"
-
- bool IsOk();
-
- bool SetState(int n, int lim = -10); // select a state
- int GetState(); // in what state am I?
- bool IncState(int lim = -10); // passes to the next state
- bool IfStep(); // do step by step
- bool Execute();
-
- void SetVar( CBotVar* var );
- void SetCopyVar( CBotVar* var );
- CBotVar* GetVar();
- CBotVar* GetCopyVar();
- CBotVar* GetPtVar();
- bool GetRetVar(bool bRet);
- long GetVal();
-
- void SetError(int n, CBotToken* token = nullptr);
- void SetPosError(CBotToken* token);
- void ResetError(int n, int start, int end);
- void SetBreak(int val, const char* name);
-
- void SetBotCall(CBotProgram* p);
- CBotProgram* GetBotCall(bool bFirst = false);
- void* GetPUser();
- bool GetBlock();
-
-
- bool ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype);
- void RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar);
-
- bool SaveState(FILE* pf);
- bool RestoreState(FILE* pf, CBotStack* &pStack);
-
- static
- void SetTimer(int n);
- void GetRunPos(const char* &FunctionName, int &start, int &end);
- CBotVar* GetStackVars(const char* &FunctionName, int level);
-
- int m_temp;
-
-private:
- CBotStack* m_next;
- CBotStack* m_next2;
- CBotStack* m_prev;
- friend class CBotInstArray;
-
-#ifdef _DEBUG
- int m_index;
-#endif
- int m_state;
- int m_step;
- static int m_error;
- static int m_start;
- static int m_end;
- static
- CBotVar* m_retvar; // result of a return
-
- CBotVar* m_var; // result of the operations
- CBotVar* m_listVar; // variables declared at this level
-
- bool m_bBlock; // is part of a block (variables are local to this block)
- bool m_bOver; // stack limits?
-// bool m_bDontDelete; // special, not to destroy the variable during delete
- CBotProgram* m_prog; // user-defined functions
-
- static
- int m_initimer;
- static
- int m_timer;
- static
- CBotString m_labelBreak;
- static
- void* m_pUser;
-
- CBotInstr* m_instr; // the corresponding instruction
- bool m_bFunc; // an input of a function?
- CBotCall* m_call; // recovery point in a extern call
- friend class CBotTry;
-};
-
-// inline routinees must be declared in file.h
-
-inline bool CBotStack::IsOk()
-{
- return (m_error == 0);
-}
-
-inline int CBotStack::GetState()
-{
- return m_state;
-}
-
-inline int CBotStack::GetError()
-{
- return m_error;
-}
////////////////////////////////////////////////////////////////////////
// Management of the stack of compilation
diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp
index 88bfabd..64b85fd 100644
--- a/src/CBot/CBotFunction.cpp
+++ b/src/CBot/CBotFunction.cpp
@@ -29,6 +29,8 @@
#include "CBotInstr/CBotEmpty.h"
#include "CBotInstr/CBotListArray.h"
+#include "CBotStack.h"
+
#include <cassert>
diff --git a/src/CBot/CBotInstr/CBotBoolean.cpp b/src/CBot/CBotInstr/CBotBoolean.cpp
index e2d2ad2..6fda2db 100644
--- a/src/CBot/CBotInstr/CBotBoolean.cpp
+++ b/src/CBot/CBotInstr/CBotBoolean.cpp
@@ -23,6 +23,8 @@
#include "CBotTwoOpExpr.h"
#include "CBotInstArray.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotBreak.cpp b/src/CBot/CBotInstr/CBotBreak.cpp
index 06f53ae..5879f0f 100644
--- a/src/CBot/CBotInstr/CBotBreak.cpp
+++ b/src/CBot/CBotInstr/CBotBreak.cpp
@@ -20,6 +20,8 @@
// Modules inlcude
#include "CBotBreak.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotCase.cpp b/src/CBot/CBotInstr/CBotCase.cpp
index a2b68c4..f188f8e 100644
--- a/src/CBot/CBotInstr/CBotCase.cpp
+++ b/src/CBot/CBotInstr/CBotCase.cpp
@@ -21,6 +21,8 @@
#include "CBotCase.h"
#include "CBotExprNum.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotCatch.cpp b/src/CBot/CBotInstr/CBotCatch.cpp
index e4d9bb4c..77b5294 100644
--- a/src/CBot/CBotInstr/CBotCatch.cpp
+++ b/src/CBot/CBotInstr/CBotCatch.cpp
@@ -22,6 +22,8 @@
#include "CBotBlock.h"
#include "CBotExpression.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp
index dfbd47b..e02328d 100644
--- a/src/CBot/CBotInstr/CBotClassInst.cpp
+++ b/src/CBot/CBotInstr/CBotClassInst.cpp
@@ -23,6 +23,8 @@
#include "CBotTwoOpExpr.h"
#include "CBotInstArray.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotDo.cpp b/src/CBot/CBotInstr/CBotDo.cpp
index 3bf3aef..9cfeddb 100644
--- a/src/CBot/CBotInstr/CBotDo.cpp
+++ b/src/CBot/CBotInstr/CBotDo.cpp
@@ -22,6 +22,8 @@
#include "CBotBlock.h"
#include "CBotCondition.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotEmpty.cpp b/src/CBot/CBotInstr/CBotEmpty.cpp
index 4f3cb5a..0f0ad7c 100644
--- a/src/CBot/CBotInstr/CBotEmpty.cpp
+++ b/src/CBot/CBotInstr/CBotEmpty.cpp
@@ -20,6 +20,8 @@
// Modules inlcude
#include "CBotEmpty.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotExprAlpha.cpp b/src/CBot/CBotInstr/CBotExprAlpha.cpp
index c412ac0..d0edb1d 100644
--- a/src/CBot/CBotInstr/CBotExprAlpha.cpp
+++ b/src/CBot/CBotInstr/CBotExprAlpha.cpp
@@ -20,6 +20,8 @@
// Modules inlcude
#include "CBotExprAlpha.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotExprBool.cpp b/src/CBot/CBotInstr/CBotExprBool.cpp
index 17c09e5..3a25267 100644
--- a/src/CBot/CBotInstr/CBotExprBool.cpp
+++ b/src/CBot/CBotInstr/CBotExprBool.cpp
@@ -20,6 +20,8 @@
// Modules inlcude
#include "CBotExprBool.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotExprNan.cpp b/src/CBot/CBotInstr/CBotExprNan.cpp
index 3eebb74..7335219 100644
--- a/src/CBot/CBotInstr/CBotExprNan.cpp
+++ b/src/CBot/CBotInstr/CBotExprNan.cpp
@@ -20,6 +20,8 @@
// Modules inlcude
#include "CBotExprNan.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotExprNull.cpp b/src/CBot/CBotInstr/CBotExprNull.cpp
index 0324d50..d80ef03 100644
--- a/src/CBot/CBotInstr/CBotExprNull.cpp
+++ b/src/CBot/CBotInstr/CBotExprNull.cpp
@@ -20,6 +20,8 @@
// Modules inlcude
#include "CBotExprNull.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotExprNum.cpp b/src/CBot/CBotInstr/CBotExprNum.cpp
index 61cf3ea..24ba0ac 100644
--- a/src/CBot/CBotInstr/CBotExprNum.cpp
+++ b/src/CBot/CBotInstr/CBotExprNum.cpp
@@ -20,6 +20,8 @@
// Modules inlcude
#include "CBotExprNum.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotExprUnaire.cpp b/src/CBot/CBotInstr/CBotExprUnaire.cpp
index e1a18e7..2b7c0d6 100644
--- a/src/CBot/CBotInstr/CBotExprUnaire.cpp
+++ b/src/CBot/CBotInstr/CBotExprUnaire.cpp
@@ -21,6 +21,8 @@
#include "CBotExprUnaire.h"
#include "CBotParExpr.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp
index 3c03da9..0e531fa 100644
--- a/src/CBot/CBotInstr/CBotExprVar.cpp
+++ b/src/CBot/CBotInstr/CBotExprVar.cpp
@@ -24,6 +24,8 @@
#include "CBotIndexExpr.h"
#include "CBotFieldExpr.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotExpression.cpp b/src/CBot/CBotInstr/CBotExpression.cpp
index cb47103..3637049 100644
--- a/src/CBot/CBotInstr/CBotExpression.cpp
+++ b/src/CBot/CBotInstr/CBotExpression.cpp
@@ -21,6 +21,8 @@
#include "CBotExpression.h"
#include "CBotTwoOpExpr.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotFieldExpr.cpp b/src/CBot/CBotInstr/CBotFieldExpr.cpp
index 6453bc3..ae8e583 100644
--- a/src/CBot/CBotInstr/CBotFieldExpr.cpp
+++ b/src/CBot/CBotInstr/CBotFieldExpr.cpp
@@ -20,6 +20,8 @@
// Modules inlcude
#include "CBotFieldExpr.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotFloat.cpp b/src/CBot/CBotInstr/CBotFloat.cpp
index acc29ff..70a2c97 100644
--- a/src/CBot/CBotInstr/CBotFloat.cpp
+++ b/src/CBot/CBotInstr/CBotFloat.cpp
@@ -23,6 +23,8 @@
#include "CBotTwoOpExpr.h"
#include "CBotInstArray.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotFor.cpp b/src/CBot/CBotInstr/CBotFor.cpp
index d83650c..7cbca51 100644
--- a/src/CBot/CBotInstr/CBotFor.cpp
+++ b/src/CBot/CBotInstr/CBotFor.cpp
@@ -23,6 +23,8 @@
#include "CBotBlock.h"
#include "CBotBoolExpr.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotIString.cpp b/src/CBot/CBotInstr/CBotIString.cpp
index b0e8a6a..91e1a92 100644
--- a/src/CBot/CBotInstr/CBotIString.cpp
+++ b/src/CBot/CBotInstr/CBotIString.cpp
@@ -22,6 +22,8 @@
#include "CBotLeftExprVar.h"
#include "CBotTwoOpExpr.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotIf.cpp b/src/CBot/CBotInstr/CBotIf.cpp
index 2ae5acf..b0cdbc8 100644
--- a/src/CBot/CBotInstr/CBotIf.cpp
+++ b/src/CBot/CBotInstr/CBotIf.cpp
@@ -22,6 +22,8 @@
#include "CBotInstr/CBotBlock.h"
#include "CBotInstr/CBotCondition.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotIndexExpr.cpp b/src/CBot/CBotInstr/CBotIndexExpr.cpp
index 2d3d6d2..f4882c0 100644
--- a/src/CBot/CBotInstr/CBotIndexExpr.cpp
+++ b/src/CBot/CBotInstr/CBotIndexExpr.cpp
@@ -20,6 +20,8 @@
// Modules inlcude
#include "CBotIndexExpr.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotInstArray.cpp b/src/CBot/CBotInstr/CBotInstArray.cpp
index b97e2b5..e1327a5 100644
--- a/src/CBot/CBotInstr/CBotInstArray.cpp
+++ b/src/CBot/CBotInstr/CBotInstArray.cpp
@@ -25,6 +25,8 @@
#include "CBotListArray.h"
#include "CBotEmpty.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotInstrCall.cpp b/src/CBot/CBotInstr/CBotInstrCall.cpp
index 615f041..cec9810 100644
--- a/src/CBot/CBotInstr/CBotInstrCall.cpp
+++ b/src/CBot/CBotInstr/CBotInstrCall.cpp
@@ -21,6 +21,8 @@
#include "CBotInstrCall.h"
#include "CBotExpression.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp
index e35c0f2..1ec9906 100644
--- a/src/CBot/CBotInstr/CBotInstrMethode.cpp
+++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp
@@ -20,6 +20,8 @@
// Modules inlcude
#include "CBotInstrMethode.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotInt.cpp b/src/CBot/CBotInstr/CBotInt.cpp
index ed4dbdd..f94d53c 100644
--- a/src/CBot/CBotInstr/CBotInt.cpp
+++ b/src/CBot/CBotInstr/CBotInt.cpp
@@ -24,6 +24,8 @@
#include "CBotInstArray.h"
#include "CBotTwoOpExpr.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotLeftExpr.cpp b/src/CBot/CBotInstr/CBotLeftExpr.cpp
index 66e0dce..84c7b73 100644
--- a/src/CBot/CBotInstr/CBotLeftExpr.cpp
+++ b/src/CBot/CBotInstr/CBotLeftExpr.cpp
@@ -23,6 +23,8 @@
#include "CBotIndexExpr.h"
#include "CBotExpression.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotLeftExprVar.cpp b/src/CBot/CBotInstr/CBotLeftExprVar.cpp
index 43ed496..ff0bbf1 100644
--- a/src/CBot/CBotInstr/CBotLeftExprVar.cpp
+++ b/src/CBot/CBotInstr/CBotLeftExprVar.cpp
@@ -20,6 +20,8 @@
// Modules inlcude
#include "CBotLeftExprVar.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp
index 8ab3207..dc6e2b2 100644
--- a/src/CBot/CBotInstr/CBotListArray.cpp
+++ b/src/CBot/CBotInstr/CBotListArray.cpp
@@ -23,6 +23,8 @@
#include "CBotExprNull.h"
#include "CBotTwoOpExpr.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotListExpression.cpp b/src/CBot/CBotInstr/CBotListExpression.cpp
index 1c45ec1..afa5f87 100644
--- a/src/CBot/CBotInstr/CBotListExpression.cpp
+++ b/src/CBot/CBotInstr/CBotListExpression.cpp
@@ -25,6 +25,8 @@
#include "CBotBoolean.h"
#include "CBotInt.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotListInstr.cpp b/src/CBot/CBotInstr/CBotListInstr.cpp
index b2fcf49..fde2103 100644
--- a/src/CBot/CBotInstr/CBotListInstr.cpp
+++ b/src/CBot/CBotInstr/CBotListInstr.cpp
@@ -21,6 +21,8 @@
#include "CBotListInstr.h"
#include "CBotBlock.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotLogicExpr.cpp b/src/CBot/CBotInstr/CBotLogicExpr.cpp
index bfa6af1..d332d18 100644
--- a/src/CBot/CBotInstr/CBotLogicExpr.cpp
+++ b/src/CBot/CBotInstr/CBotLogicExpr.cpp
@@ -20,6 +20,8 @@
// Modules inlcude
#include "CBotLogicExpr.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotNew.cpp b/src/CBot/CBotInstr/CBotNew.cpp
index d89a8ca..fef5c07 100644
--- a/src/CBot/CBotInstr/CBotNew.cpp
+++ b/src/CBot/CBotInstr/CBotNew.cpp
@@ -20,6 +20,8 @@
// Modules inlcude
#include "CBotNew.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotParExpr.h b/src/CBot/CBotInstr/CBotParExpr.h
index de0df45..60c0993 100644
--- a/src/CBot/CBotInstr/CBotParExpr.h
+++ b/src/CBot/CBotInstr/CBotParExpr.h
@@ -22,6 +22,8 @@
// Modules inlcude
#include "CBot.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotPostIncExpr.cpp b/src/CBot/CBotInstr/CBotPostIncExpr.cpp
index cb146ca..f7fbdda 100644
--- a/src/CBot/CBotInstr/CBotPostIncExpr.cpp
+++ b/src/CBot/CBotInstr/CBotPostIncExpr.cpp
@@ -21,6 +21,8 @@
#include "CBotPostIncExpr.h"
#include "CBotExprVar.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotPreIncExpr.cpp b/src/CBot/CBotInstr/CBotPreIncExpr.cpp
index 073e0d4..5fe3d36 100644
--- a/src/CBot/CBotInstr/CBotPreIncExpr.cpp
+++ b/src/CBot/CBotInstr/CBotPreIncExpr.cpp
@@ -21,6 +21,8 @@
#include "CBotPreIncExpr.h"
#include "CBotExprVar.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotReturn.cpp b/src/CBot/CBotInstr/CBotReturn.cpp
index d64326c..3837b26 100644
--- a/src/CBot/CBotInstr/CBotReturn.cpp
+++ b/src/CBot/CBotInstr/CBotReturn.cpp
@@ -21,6 +21,8 @@
#include "CBotReturn.h"
#include "CBotExpression.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotSwitch.cpp b/src/CBot/CBotInstr/CBotSwitch.cpp
index 45558dc..0a527d2 100644
--- a/src/CBot/CBotInstr/CBotSwitch.cpp
+++ b/src/CBot/CBotInstr/CBotSwitch.cpp
@@ -25,6 +25,8 @@
#include "CBotBlock.h"
#include "CBotExpression.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotThrow.cpp b/src/CBot/CBotInstr/CBotThrow.cpp
index a4a1831..c02f221 100644
--- a/src/CBot/CBotInstr/CBotThrow.cpp
+++ b/src/CBot/CBotInstr/CBotThrow.cpp
@@ -21,6 +21,8 @@
#include "CBotThrow.h"
#include "CBotExpression.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotTry.cpp b/src/CBot/CBotInstr/CBotTry.cpp
index 89b689e..2ac2ae6 100644
--- a/src/CBot/CBotInstr/CBotTry.cpp
+++ b/src/CBot/CBotInstr/CBotTry.cpp
@@ -21,6 +21,8 @@
#include "CBotTry.h"
#include "CBotBlock.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp
index 275730a..816efef 100644
--- a/src/CBot/CBotInstr/CBotTwoOpExpr.cpp
+++ b/src/CBot/CBotInstr/CBotTwoOpExpr.cpp
@@ -22,7 +22,8 @@
#include "CBotParExpr.h"
#include "CBotLogicExpr.h"
#include "CBotExpression.h"
-#include "CBot.h"
+
+#include "CBotStack.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotWhile.cpp b/src/CBot/CBotInstr/CBotWhile.cpp
index c24084b..bfc2061 100644
--- a/src/CBot/CBotInstr/CBotWhile.cpp
+++ b/src/CBot/CBotInstr/CBotWhile.cpp
@@ -22,6 +22,8 @@
#include "CBotBlock.h"
#include "CBotCondition.h"
+#include "CBotStack.h"
+
// Local include
// Global include
diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp
index cda190c..f1862c1 100644
--- a/src/CBot/CBotProgram.cpp
+++ b/src/CBot/CBotProgram.cpp
@@ -21,6 +21,9 @@
// database management of CBoT program
#include "CBot.h"
+
+#include "CBotStack.h"
+
#include <stdio.h>
CBotProgram::CBotProgram()
diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp
index bbc01d8..b1715e1 100644
--- a/src/CBot/CBotStack.cpp
+++ b/src/CBot/CBotStack.cpp
@@ -17,11 +17,12 @@
* along with this program. If not, see http://gnu.org/licenses
*/
-//Management of the stack
+// Modules inlcude
+#include "CBotStack.h"
+// Local include
-#include "CBot.h"
-
+// Global include
#include <cassert>
#include <cstdlib>
#include <cstring>
@@ -29,10 +30,6 @@
#define ITIMER 100
-////////////////////////////////////////////////////////////////////////////
-// management of a execution of a stack
-////////////////////////////////////////////////////////////////////////////
-
int CBotStack::m_initimer = ITIMER;
int CBotStack::m_timer = 0;
CBotVar* CBotStack::m_retvar = nullptr;
@@ -44,6 +41,7 @@ void* CBotStack::m_pUser = nullptr;
#if STACKMEM
+////////////////////////////////////////////////////////////////////////////////
CBotStack* CBotStack::FirstStack()
{
CBotStack* p;
@@ -82,17 +80,20 @@ CBotStack* CBotStack::FirstStack()
return p;
}
+////////////////////////////////////////////////////////////////////////////////
CBotStack::CBotStack(CBotStack* ppapa)
{
// constructor must exist or the destructor is never called!
assert(0);
}
+////////////////////////////////////////////////////////////////////////////////
CBotStack::~CBotStack()
{
assert(0); // use Delete () instead
}
+////////////////////////////////////////////////////////////////////////////////
void CBotStack::Delete()
{
if ( this == nullptr || this == EOX ) return;
@@ -129,8 +130,8 @@ void CBotStack::Delete()
free( this );
}
-
// routine improved
+////////////////////////////////////////////////////////////////////////////////
CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock)
{
if (m_next != nullptr)
@@ -163,6 +164,7 @@ CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock)
return p;
}
+////////////////////////////////////////////////////////////////////////////////
CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock)
{
if (m_next != nullptr)
@@ -180,6 +182,7 @@ CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock)
return p;
}
+////////////////////////////////////////////////////////////////////////////////
CBotStack* CBotStack::AddStack2(bool bBlock)
{
if (m_next2 != nullptr)
@@ -203,11 +206,13 @@ CBotStack* CBotStack::AddStack2(bool bBlock)
return p;
}
+////////////////////////////////////////////////////////////////////////////////
bool CBotStack::GetBlock()
{
return m_bBlock;
}
+////////////////////////////////////////////////////////////////////////////////
bool CBotStack::Return(CBotStack* pfils)
{
if ( pfils == this ) return true; // special
@@ -222,6 +227,7 @@ bool CBotStack::Return(CBotStack* pfils)
return (m_error == 0); // interrupted if error
}
+////////////////////////////////////////////////////////////////////////////////
bool CBotStack::ReturnKeep(CBotStack* pfils)
{
if ( pfils == this ) return true; // special
@@ -233,6 +239,7 @@ bool CBotStack::ReturnKeep(CBotStack* pfils)
return (m_error == 0); // interrupted if error
}
+////////////////////////////////////////////////////////////////////////////////
bool CBotStack::StackOver()
{
if (!m_bOver) return false;
@@ -242,6 +249,7 @@ bool CBotStack::StackOver()
#else
+////////////////////////////////////////////////////////////////////////////////
CBotStack::CBotStack(CBotStack* ppapa)
{
m_next = nullptr;
@@ -265,6 +273,7 @@ CBotStack::CBotStack(CBotStack* ppapa)
m_bFunc = false;
}
+////////////////////////////////////////////////////////////////////////////////
// destructor
CBotStack::~CBotStack()
{
@@ -277,6 +286,7 @@ CBotStack::~CBotStack()
if ( !m_bDontDelete ) delete m_listVar;
}
+////////////////////////////////////////////////////////////////////////////////
// \TODO routine has/to optimize
CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock)
{
@@ -293,6 +303,7 @@ CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock)
return p;
}
+////////////////////////////////////////////////////////////////////////////////
CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock)
{
if (m_next != nullptr)
@@ -314,6 +325,7 @@ CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock)
return p;
}
+////////////////////////////////////////////////////////////////////////////////
CBotStack* CBotStack::AddStack2(bool bBlock)
{
if (m_next2 != nullptr)
@@ -331,6 +343,7 @@ CBotStack* CBotStack::AddStack2(bool bBlock)
return p;
}
+////////////////////////////////////////////////////////////////////////////////
bool CBotStack::Return(CBotStack* pfils)
{
if ( pfils == this ) return true; // special
@@ -345,6 +358,7 @@ bool CBotStack::Return(CBotStack* pfils)
return (m_error == 0); // interrupted if error
}
+////////////////////////////////////////////////////////////////////////////////
bool CBotStack::StackOver()
{
return false; // no overflow check in this version
@@ -352,6 +366,7 @@ bool CBotStack::StackOver()
#endif
+////////////////////////////////////////////////////////////////////////////////
void CBotStack::Reset(void* pUser)
{
m_timer = m_initimer; // resets the timer
@@ -362,9 +377,7 @@ void CBotStack::Reset(void* pUser)
m_pUser = pUser;
}
-
-
-
+////////////////////////////////////////////////////////////////////////////////
CBotStack* CBotStack::RestoreStack(CBotInstr* instr)
{
if (m_next != nullptr)
@@ -376,6 +389,7 @@ CBotStack* CBotStack::RestoreStack(CBotInstr* instr)
return nullptr;
}
+////////////////////////////////////////////////////////////////////////////////
CBotStack* CBotStack::RestoreStackEOX(CBotCall* instr)
{
CBotStack* p = RestoreStack();
@@ -383,8 +397,7 @@ CBotStack* CBotStack::RestoreStackEOX(CBotCall* instr)
return p;
}
-
-
+////////////////////////////////////////////////////////////////////////////////
// routine for execution step by step
bool CBotStack::IfStep()
{
@@ -392,7 +405,7 @@ bool CBotStack::IfStep()
return true;
}
-
+////////////////////////////////////////////////////////////////////////////////
bool CBotStack::BreakReturn(CBotStack* pfils, const char* name)
{
if ( m_error>=0 ) return false; // normal output
@@ -406,6 +419,7 @@ bool CBotStack::BreakReturn(CBotStack* pfils, const char* name)
return Return(pfils);
}
+////////////////////////////////////////////////////////////////////////////////
bool CBotStack::IfContinue(int state, const char* name)
{
if ( m_error != -2 ) return false;
@@ -420,6 +434,7 @@ bool CBotStack::IfContinue(int state, const char* name)
return true;
}
+////////////////////////////////////////////////////////////////////////////////
void CBotStack::SetBreak(int val, const char* name)
{
m_error = -val; // reacts as an Exception
@@ -432,7 +447,7 @@ void CBotStack::SetBreak(int val, const char* name)
}
// gives on the stack value calculated by the last CBotReturn
-
+////////////////////////////////////////////////////////////////////////////////
bool CBotStack::GetRetVar(bool bRet)
{
if (m_error == -3)
@@ -446,6 +461,7 @@ bool CBotStack::GetRetVar(bool bRet)
return bRet; // interrupted by something other than return
}
+////////////////////////////////////////////////////////////////////////////////
int CBotStack::GetError(int& start, int& end)
{
start = m_start;
@@ -453,26 +469,28 @@ int CBotStack::GetError(int& start, int& end)
return m_error;
}
-
+////////////////////////////////////////////////////////////////////////////////
int CBotStack::GetType(int mode)
{
if (m_var == nullptr) return -1;
return m_var->GetType(mode);
}
+////////////////////////////////////////////////////////////////////////////////
CBotTypResult CBotStack::GetTypResult(int mode)
{
if (m_var == nullptr) return -1;
return m_var->GetTypResult(mode);
}
+////////////////////////////////////////////////////////////////////////////////
void CBotStack::SetType(CBotTypResult& type)
{
if (m_var == nullptr) return;
m_var->SetType( type );
}
-
+////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotStack::FindVar(CBotToken* &pToken, bool bUpdate, bool bModif)
{
CBotStack* p = this;
@@ -497,6 +515,7 @@ CBotVar* CBotStack::FindVar(CBotToken* &pToken, bool bUpdate, bool bModif)
return nullptr;
}
+////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotStack::FindVar(const char* name)
{
CBotStack* p = this;
@@ -516,6 +535,7 @@ CBotVar* CBotStack::FindVar(const char* name)
return nullptr;
}
+////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotStack::FindVar(long ident, bool bUpdate, bool bModif)
{
CBotStack* p = this;
@@ -538,14 +558,14 @@ CBotVar* CBotStack::FindVar(long ident, bool bUpdate, bool bModif)
return nullptr;
}
-
+////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotStack::FindVar(CBotToken& pToken, bool bUpdate, bool bModif)
{
CBotToken* pt = &pToken;
return FindVar(pt, bUpdate, bModif);
}
-
+////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotStack::CopyVar(CBotToken& Token, bool bUpdate)
{
CBotVar* pVar = FindVar( Token, bUpdate );
@@ -557,7 +577,7 @@ CBotVar* CBotStack::CopyVar(CBotToken& Token, bool bUpdate)
return pCopy;
}
-
+////////////////////////////////////////////////////////////////////////////////
bool CBotStack::SetState(int n, int limite)
{
m_state = n;
@@ -566,6 +586,7 @@ bool CBotStack::SetState(int n, int limite)
return ( m_timer > limite ); // interrupted if timer pass
}
+////////////////////////////////////////////////////////////////////////////////
bool CBotStack::IncState(int limite)
{
m_state++;
@@ -574,7 +595,7 @@ bool CBotStack::IncState(int limite)
return ( m_timer > limite ); // interrupted if timer pass
}
-
+////////////////////////////////////////////////////////////////////////////////
void CBotStack::SetError(int n, CBotToken* token)
{
if ( n!= 0 && m_error != 0) return; // does not change existing error
@@ -586,6 +607,7 @@ void CBotStack::SetError(int n, CBotToken* token)
}
}
+////////////////////////////////////////////////////////////////////////////////
void CBotStack::ResetError(int n, int start, int end)
{
m_error = n;
@@ -593,17 +615,20 @@ void CBotStack::ResetError(int n, int start, int end)
m_end = end;
}
+////////////////////////////////////////////////////////////////////////////////
void CBotStack::SetPosError(CBotToken* token)
{
m_start = token->GetStart();
m_end = token->GetEnd();
}
+////////////////////////////////////////////////////////////////////////////////
void CBotStack::SetTimer(int n)
{
m_initimer = n;
}
+////////////////////////////////////////////////////////////////////////////////
bool CBotStack::Execute()
{
CBotCall* instr = nullptr; // the most highest instruction
@@ -637,6 +662,7 @@ bool CBotStack::Execute()
}
// puts on the stack pointer to a variable
+////////////////////////////////////////////////////////////////////////////////
void CBotStack::SetVar( CBotVar* var )
{
if (m_var) delete m_var; // replacement of a variable
@@ -644,6 +670,7 @@ void CBotStack::SetVar( CBotVar* var )
}
// puts on the stack a copy of a variable
+////////////////////////////////////////////////////////////////////////////////
void CBotStack::SetCopyVar( CBotVar* var )
{
if (m_var) delete m_var; // replacement of a variable
@@ -652,11 +679,13 @@ void CBotStack::SetCopyVar( CBotVar* var )
m_var->Copy( var );
}
+////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotStack::GetVar()
{
return m_var;
}
+////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotStack::GetPtVar()
{
CBotVar* p = m_var;
@@ -664,6 +693,7 @@ CBotVar* CBotStack::GetPtVar()
return p;
}
+////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotStack::GetCopyVar()
{
if (m_var == nullptr) return nullptr;
@@ -672,15 +702,14 @@ CBotVar* CBotStack::GetCopyVar()
return v;
}
+////////////////////////////////////////////////////////////////////////////////
long CBotStack::GetVal()
{
if (m_var == nullptr) return 0;
return m_var->GetValInt();
}
-
-
-
+////////////////////////////////////////////////////////////////////////////////
void CBotStack::AddVar(CBotVar* pVar)
{
CBotStack* p = this;
@@ -702,19 +731,14 @@ void CBotStack::AddVar(CBotVar* pVar)
#endif
}
-/*void CBotStack::RestoreVar(CBotVar* pVar)
-{
- if ( !m_bDontDelete ) __asm int 3;
- delete m_listVar;
- m_listVar = pVar; // direct replacement
-}*/
-
+////////////////////////////////////////////////////////////////////////////////
void CBotStack::SetBotCall(CBotProgram* p)
{
m_prog = p;
m_bFunc = true;
}
+////////////////////////////////////////////////////////////////////////////////
CBotProgram* CBotStack::GetBotCall(bool bFirst)
{
if ( ! bFirst ) return m_prog;
@@ -723,12 +747,13 @@ CBotProgram* CBotStack::GetBotCall(bool bFirst)
return p->m_prog;
}
+////////////////////////////////////////////////////////////////////////////////
void* CBotStack::GetPUser()
{
return m_pUser;
}
-
+////////////////////////////////////////////////////////////////////////////////
bool CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype)
{
CBotTypResult res;
@@ -754,6 +779,7 @@ bool CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBo
return true;
}
+////////////////////////////////////////////////////////////////////////////////
void CBotStack::RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar)
{
if ( m_next == nullptr ) return;
@@ -762,7 +788,7 @@ void CBotStack::RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar)
m_prog->GetFunctions()->RestoreCall(nIdent, token->GetString(), ppVar, this );
}
-
+////////////////////////////////////////////////////////////////////////////////
bool SaveVar(FILE* pf, CBotVar* pVar)
{
while ( true )
@@ -779,6 +805,7 @@ bool SaveVar(FILE* pf, CBotVar* pVar)
}
}
+////////////////////////////////////////////////////////////////////////////////
void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end)
{
CBotProgram* prog = m_prog; // Current program
@@ -813,6 +840,7 @@ void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end)
end = t->GetEnd();
}
+////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotStack::GetStackVars(const char* &FunctionName, int level)
{
CBotProgram* prog = m_prog; // current program
@@ -860,6 +888,7 @@ CBotVar* CBotStack::GetStackVars(const char* &FunctionName, int level)
return p->m_listVar;
}
+////////////////////////////////////////////////////////////////////////////////
bool CBotStack::SaveState(FILE* pf)
{
if ( this == nullptr ) // end of the tree?
@@ -888,7 +917,7 @@ bool CBotStack::SaveState(FILE* pf)
return m_next->SaveState(pf); // saves the following
}
-
+////////////////////////////////////////////////////////////////////////////////
bool CBotStack::RestoreState(FILE* pf, CBotStack* &pStack)
{
unsigned short w;
@@ -927,7 +956,7 @@ bool CBotStack::RestoreState(FILE* pf, CBotStack* &pStack)
return pStack->RestoreState(pf, pStack->m_next);
}
-
+////////////////////////////////////////////////////////////////////////////////
bool CBotVar::Save0State(FILE* pf)
{
if (!WriteWord(pf, 100+m_mPrivate))return false; // private variable?
@@ -937,6 +966,7 @@ bool CBotVar::Save0State(FILE* pf)
return WriteString(pf, m_token->GetString()); // and variable name
}
+////////////////////////////////////////////////////////////////////////////////
bool CBotVarInt::Save0State(FILE* pf)
{
if ( !m_defnum.IsEmpty() )
@@ -948,28 +978,31 @@ bool CBotVarInt::Save0State(FILE* pf)
return CBotVar::Save0State(pf);
}
+////////////////////////////////////////////////////////////////////////////////
bool CBotVarInt::Save1State(FILE* pf)
{
return WriteWord(pf, m_val); // the value of the variable
}
+////////////////////////////////////////////////////////////////////////////////
bool CBotVarBoolean::Save1State(FILE* pf)
{
return WriteWord(pf, m_val); // the value of the variable
}
+////////////////////////////////////////////////////////////////////////////////
bool CBotVarFloat::Save1State(FILE* pf)
{
return WriteFloat(pf, m_val); // the value of the variable
}
+////////////////////////////////////////////////////////////////////////////////
bool CBotVarString::Save1State(FILE* pf)
{
return WriteString(pf, m_val); // the value of the variable
}
-
-
+////////////////////////////////////////////////////////////////////////////////
bool CBotVarClass::Save1State(FILE* pf)
{
if ( !WriteType(pf, m_type) ) return false;
@@ -1004,6 +1037,7 @@ bool ParseInitType(int rawInitType, CBotVar::InitType* initType)
}
}
+////////////////////////////////////////////////////////////////////////////////
bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
{
unsigned short w, wi, prv, st;
@@ -1152,7 +1186,7 @@ int CBotCStack::m_end = 0;
CBotTypResult CBotCStack::m_retTyp = CBotTypResult(0);
//CBotToken* CBotCStack::m_retClass= nullptr;
-
+////////////////////////////////////////////////////////////////////////////////
CBotCStack::CBotCStack(CBotCStack* ppapa)
{
m_next = nullptr;
@@ -1175,6 +1209,7 @@ CBotCStack::CBotCStack(CBotCStack* ppapa)
m_var = nullptr;
}
+////////////////////////////////////////////////////////////////////////////////
// destructor
CBotCStack::~CBotCStack()
{
@@ -1185,6 +1220,7 @@ CBotCStack::~CBotCStack()
delete m_listVar;
}
+////////////////////////////////////////////////////////////////////////////////
// used only at compile
CBotCStack* CBotCStack::TokenStack(CBotToken* pToken, bool bBlock)
{
@@ -1199,7 +1235,7 @@ CBotCStack* CBotCStack::TokenStack(CBotToken* pToken, bool bBlock)
return p;
}
-
+////////////////////////////////////////////////////////////////////////////////
CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils)
{
if ( pfils == this ) return inst;
@@ -1218,6 +1254,7 @@ CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils)
return inst;
}
+////////////////////////////////////////////////////////////////////////////////
CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils)
{
if (m_var != nullptr) delete m_var; // value replaced?
@@ -1234,6 +1271,7 @@ CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils)
return inst;
}
+////////////////////////////////////////////////////////////////////////////////
int CBotCStack::GetError(int& start, int& end)
{
start = m_start;
@@ -1241,11 +1279,13 @@ int CBotCStack::GetError(int& start, int& end)
return m_error;
}
+////////////////////////////////////////////////////////////////////////////////
int CBotCStack::GetError()
{
return m_error;
}
+////////////////////////////////////////////////////////////////////////////////
// type of instruction on the stack
CBotTypResult CBotCStack::GetTypResult(int mode)
{
@@ -1254,6 +1294,7 @@ CBotTypResult CBotCStack::GetTypResult(int mode)
return m_var->GetTypResult(mode);
}
+////////////////////////////////////////////////////////////////////////////////
// type of instruction on the stack
int CBotCStack::GetType(int mode)
{
@@ -1262,6 +1303,7 @@ int CBotCStack::GetType(int mode)
return m_var->GetType(mode);
}
+////////////////////////////////////////////////////////////////////////////////
// pointer on the stack is in what class?
CBotClass* CBotCStack::GetClass()
{
@@ -1272,6 +1314,7 @@ CBotClass* CBotCStack::GetClass()
return m_var->GetClass();
}
+////////////////////////////////////////////////////////////////////////////////
// type of instruction on the stack
void CBotCStack::SetType(CBotTypResult& type)
{
@@ -1282,7 +1325,7 @@ void CBotCStack::SetType(CBotTypResult& 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;
@@ -1304,12 +1347,14 @@ CBotVar* CBotCStack::FindVar(CBotToken* &pToken)
return nullptr;
}
+////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotCStack::FindVar(CBotToken& Token)
{
CBotToken* pt = &Token;
return FindVar(pt);
}
+////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotCStack::CopyVar(CBotToken& Token)
{
CBotVar* pVar = FindVar( Token );
@@ -1321,18 +1366,20 @@ CBotVar* CBotCStack::CopyVar(CBotToken& Token)
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
@@ -1340,6 +1387,7 @@ void CBotCStack::SetError(int n, int pos)
m_end = pos;
}
+////////////////////////////////////////////////////////////////////////////////
void CBotCStack::SetError(int n, CBotToken* p)
{
if (m_error) return; // does not change existing error
@@ -1348,6 +1396,7 @@ void CBotCStack::SetError(int n, CBotToken* p)
m_end = p->GetEnd();
}
+////////////////////////////////////////////////////////////////////////////////
void CBotCStack::ResetError(int n, int start, int end)
{
m_error = n;
@@ -1355,6 +1404,7 @@ void CBotCStack::ResetError(int n, int start, int end)
m_end = end;
}
+////////////////////////////////////////////////////////////////////////////////
bool CBotCStack::NextToken(CBotToken* &p)
{
CBotToken* pp = p;
@@ -1366,32 +1416,38 @@ bool CBotCStack::NextToken(CBotToken* &p)
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 )
{
@@ -1402,11 +1458,13 @@ void CBotCStack::SetCopyVar( CBotVar* var )
m_var->Copy( var );
}
+////////////////////////////////////////////////////////////////////////////////
CBotVar* CBotCStack::GetVar()
{
return m_var;
}
+////////////////////////////////////////////////////////////////////////////////
void CBotCStack::AddVar(CBotVar* pVar)
{
CBotCStack* p = this;
@@ -1427,7 +1485,7 @@ void CBotCStack::AddVar(CBotVar* pVar)
}
// test whether a variable is already defined locally
-
+////////////////////////////////////////////////////////////////////////////////
bool CBotCStack::CheckVarLocal(CBotToken* &pToken)
{
CBotCStack* p = this;
@@ -1448,6 +1506,7 @@ bool CBotCStack::CheckVarLocal(CBotToken* &pToken)
return false;
}
+////////////////////////////////////////////////////////////////////////////////
CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent)
{
nIdent = 0;
@@ -1469,7 +1528,7 @@ CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nId
}
// test if a procedure name is already defined somewhere
-
+////////////////////////////////////////////////////////////////////////////////
bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
{
CBotString name = pToken->GetString();
diff --git a/src/CBot/CBotStack.h b/src/CBot/CBotStack.h
new file mode 100644
index 0000000..df69a0d
--- /dev/null
+++ b/src/CBot/CBotStack.h
@@ -0,0 +1,270 @@
+/*
+ * 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 "CBot.h"
+
+// Local include
+
+// Global include
+
+
+/*!
+ * \class CBotStack
+ * \brief The CBotStack class Management of the execution stack. Actually the
+ * only thing it can do is to create an instance of a stack. To use for routine
+ * CBotProgram :: Execute(CBotStack)
+ */
+class CBotStack
+{
+public:
+#if STACKMEM
+ /**
+ * \brief FirstStack Allocate first stack
+ * \return pointer to created stack
+ */
+ static CBotStack * FirstStack();
+
+ /** \brief Delete Remove current stack */
+ void Delete();
+#endif
+
+ /**
+ * \brief CBotStack Constructor of the stack
+ * \param ppapa Not used.
+ */
+ CBotStack(CBotStack* ppapa);
+
+
+ /** \brief ~CBotStack Destructor */
+ ~CBotStack();
+
+ /**
+ * \brief StackOver Check if end of stack is reached
+ * \return true if end of stack
+ */
+ bool StackOver();
+
+ /**
+ * \brief GetError Get error number of the stack
+ * \param [out] start beginning of the stack
+ * \param [out] end end of stack
+ * \return error number
+ */
+ int GetError(int& start, int& end);
+
+ /**
+ * \brief GetError Get error number
+ * \return eror number
+ */
+ int GetError();// rend le numéro d'erreur retourné
+
+ /**
+ * \brief Reset Reset error at and set user
+ * \param [in] pUser User of stack
+ */
+ void Reset(void* pUser);
+
+ /**
+ * \brief SetType Determines the type.
+ * \param type Type of instruction on the stack.
+ */
+ void SetType(CBotTypResult& type);
+
+ /**
+ * \brief GetType Get the type of value on the stack.
+ * \param [in] mode Used when getting class type (1 gives pointer, 2 gives intrinsic).
+ * \return Type number.
+ */
+ int GetType(int mode = 0);
+
+ /**
+ * \brief Getes the type of complete value on the stack.
+ * \param [in] mode Used when getting class type (1 gives pointer, 2 gives intrinsic).
+ * \return Type of an element.
+ */
+ CBotTypResult GetTypResult(int mode = 0);
+
+ /**
+ * \brief Adds a local variable.
+ * \param [in] p Variable to be added.
+ */
+ void AddVar(CBotVar* p);
+
+ /**
+ * \brief Fetch a variable by its token.
+ * \brief This may be a composite variable
+ * \param [in] pToken Token upon which search is performed
+ * \param [in] bUpdate Not used. Probably need to be removed
+ * \param [in] bModif Not used. Probably need to be removed
+ * \return Found variable
+ */
+ CBotVar* FindVar(CBotToken* &pToken, bool bUpdate = false,
+ bool bModif = false);
+
+ /**
+ * \brief Fetch a variable by its token.
+ * \brief This may be a composite variable
+ * \param [in] pToken Token upon which search is performed
+ * \param [in] bUpdate Not used. Probably need to be removed
+ * \param [in] bModif Not used. Probably need to be removed
+ * \return Found variable
+ */
+ CBotVar* FindVar(CBotToken& pToken, bool bUpdate = false,
+ bool bModif = false);
+
+ /**
+ * \brief Fetch variable by its name
+ * \param [in] name Name of variable to find
+ * \return Found variable
+ */
+ CBotVar* FindVar(const char* name);
+
+ /**
+ * \brief Fetch a variable on the stack according to its identification number
+ * \brief This is faster than comparing names
+ * \param [in] ident Identifier of a variable
+ * \param [in] bUpdate Not used. Probably need to be removed
+ * \param [in] bModif Not used. Probably need to be removed
+ * \return Found variable
+ */
+ CBotVar* FindVar(long ident, bool bUpdate = false,
+ bool bModif = false);
+
+ /**
+ * \brief Find variable by its token and returns a copy of it.
+ * \param Token Token upon which search is performed
+ * \param bUpdate Not used.
+ * \return Found variable, nullptr if not found
+ */
+ CBotVar* CopyVar(CBotToken& Token, bool bUpdate = false);
+
+
+ CBotStack* AddStack(CBotInstr* instr = nullptr, bool bBlock = false); // extends the stack
+ CBotStack* AddStackEOX(CBotCall* instr = nullptr, bool bBlock = false); // extends the stack
+ CBotStack* RestoreStack(CBotInstr* instr = nullptr);
+ CBotStack* RestoreStackEOX(CBotCall* instr = nullptr);
+
+ CBotStack* AddStack2(bool bBlock = false); // extends the stack
+ bool Return(CBotStack* pFils); // transmits the result over
+ bool ReturnKeep(CBotStack* pFils); // transmits the result without reducing the stack
+ bool BreakReturn(CBotStack* pfils, const char* name = nullptr);
+ // in case of eventual break
+ bool IfContinue(int state, const char* name);
+ // or "continue"
+
+ bool IsOk();
+
+ bool SetState(int n, int lim = -10); // select a state
+ int GetState(); // in what state am I?
+ bool IncState(int lim = -10); // passes to the next state
+ bool IfStep(); // do step by step
+ bool Execute();
+
+ void SetVar( CBotVar* var );
+ void SetCopyVar( CBotVar* var );
+ CBotVar* GetVar();
+ CBotVar* GetCopyVar();
+ CBotVar* GetPtVar();
+ bool GetRetVar(bool bRet);
+ long GetVal();
+
+ void SetError(int n, CBotToken* token = nullptr);
+ void SetPosError(CBotToken* token);
+ void ResetError(int n, int start, int end);
+ void SetBreak(int val, const char* name);
+
+ void SetBotCall(CBotProgram* p);
+ CBotProgram* GetBotCall(bool bFirst = false);
+ void* GetPUser();
+ bool GetBlock();
+
+
+ bool ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype);
+ void RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar);
+
+ bool SaveState(FILE* pf);
+ bool RestoreState(FILE* pf, CBotStack* &pStack);
+
+ static
+ void SetTimer(int n);
+
+ void GetRunPos(const char* &FunctionName, int &start, int &end);
+ CBotVar* GetStackVars(const char* &FunctionName, int level);
+
+ int m_temp;
+
+private:
+ CBotStack* m_next;
+ CBotStack* m_next2;
+ CBotStack* m_prev;
+ friend class CBotInstArray;
+
+#ifdef _DEBUG
+ int m_index;
+#endif
+ int m_state;
+ int m_step;
+ static int m_error;
+ static int m_start;
+ static int m_end;
+ static
+ CBotVar* m_retvar; // result of a return
+
+ CBotVar* m_var; // result of the operations
+ CBotVar* m_listVar; // variables declared at this level
+
+ bool m_bBlock; // is part of a block (variables are local to this block)
+ bool m_bOver; // stack limits?
+// bool m_bDontDelete; // special, not to destroy the variable during delete
+ CBotProgram* m_prog; // user-defined functions
+
+ static
+ int m_initimer;
+ static
+ int m_timer;
+ static
+ CBotString m_labelBreak;
+ static
+ void* m_pUser;
+
+ CBotInstr* m_instr; // the corresponding instruction
+ bool m_bFunc; // an input of a function?
+ CBotCall* m_call; // recovery point in a extern call
+ friend class CBotTry;
+};
+
+// inline routinees must be declared in file.h
+
+inline bool CBotStack::IsOk()
+{
+ return (m_error == 0);
+}
+
+inline int CBotStack::GetState()
+{
+ return m_state;
+}
+
+inline int CBotStack::GetError()
+{
+ return m_error;
+}
diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp
index 2898a92..75e26e6 100644
--- a/src/CBot/CBotVar.cpp
+++ b/src/CBot/CBotVar.cpp
@@ -25,6 +25,8 @@
#include "CBot.h"
+#include "CBotStack.h"
+
#include <cassert>
#include <cmath>
#include <cstdio>
--
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