2014-10-14 13:11:37 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Colobot: Gold Edition source code
|
2015-08-22 14:40:02 +00:00
|
|
|
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
|
|
|
|
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
|
2014-10-14 13:11:37 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
2015-08-22 15:51:39 +00:00
|
|
|
|
2012-08-07 13:46:04 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
|
|
* \file CBot.h
|
|
|
|
* \brief Interpreter of the language CBot for COLOBOT game
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "resource.h"
|
|
|
|
#include "CBotDll.h" // public definitions
|
|
|
|
#include "CBotToken.h" // token management
|
|
|
|
|
2015-04-27 16:15:29 +00:00
|
|
|
#define STACKRUN 1 /// \def return execution directly on a suspended routine
|
|
|
|
#define STACKMEM 1 /// \def preserve memory for the execution stack
|
2012-08-07 13:46:04 +00:00
|
|
|
#define MAXSTACK 990 /// \def stack size reserved
|
|
|
|
|
2012-08-12 23:26:36 +00:00
|
|
|
#define EOX (reinterpret_cast<CBotStack*>(-1)) /// \def tag special condition
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// forward declaration
|
|
|
|
|
|
|
|
class CBotCompExpr; // an expression like
|
|
|
|
// () <= ()
|
|
|
|
class CBotAddExpr; // an expression like
|
|
|
|
// () + ()
|
|
|
|
class CBotParExpr; // basic type or instruction in parenthesis
|
|
|
|
// Toto.truc
|
|
|
|
// 12.5
|
|
|
|
// "string"
|
|
|
|
// ( expression )
|
|
|
|
class CBotExprVar; // a variable name as
|
|
|
|
// Toto
|
|
|
|
// chose.truc.machin
|
|
|
|
class CBotWhile; // while (...) {...};
|
|
|
|
class CBotIf; // if (...) {...} else {...}
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2013-05-26 15:47:54 +00:00
|
|
|
/**\class CBotStack
|
2012-08-07 13:46:04 +00:00
|
|
|
* \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();
|
|
|
|
|
|
|
|
/**
|
2012-08-11 18:59:35 +00:00
|
|
|
* \brief GetError Get error number of the stack
|
2012-08-07 13:46:04 +00:00
|
|
|
* \param [out] start beginning of the stack
|
|
|
|
* \param [out] end end of stack
|
|
|
|
* \return error number
|
|
|
|
*/
|
2012-08-11 18:59:35 +00:00
|
|
|
int GetError(int& start, int& end);
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
/**
|
2012-08-11 18:59:35 +00:00
|
|
|
* \brief GetError Get error number
|
2012-08-07 13:46:04 +00:00
|
|
|
* \return eror number
|
|
|
|
*/
|
2012-08-11 18:59:35 +00:00
|
|
|
int GetError();// rend le numéro d'erreur retourné
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \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);
|
|
|
|
|
|
|
|
/**
|
2012-08-11 18:59:35 +00:00
|
|
|
* \brief GetType Get the type of value on the stack.
|
2012-08-07 13:46:04 +00:00
|
|
|
* \param [in] mode Used when getting class type (1 gives pointer, 2 gives intrinsic).
|
|
|
|
* \return Type number.
|
|
|
|
*/
|
2012-08-11 18:59:35 +00:00
|
|
|
int GetType(int mode = 0);
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
/**
|
2012-08-11 18:59:35 +00:00
|
|
|
* \brief Getes the type of complete value on the stack.
|
2012-08-07 13:46:04 +00:00
|
|
|
* \param [in] mode Used when getting class type (1 gives pointer, 2 gives intrinsic).
|
|
|
|
* \return Type of an element.
|
|
|
|
*/
|
2012-08-11 18:59:35 +00:00
|
|
|
CBotTypResult GetTypResult(int mode = 0);
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \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
|
|
|
|
*/
|
2015-08-16 22:43:32 +00:00
|
|
|
CBotVar* FindVar(CBotToken& pToken, bool bUpdate = false,
|
2012-08-07 13:46:04 +00:00
|
|
|
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.
|
2015-08-16 10:43:42 +00:00
|
|
|
* \return Found variable, nullptr if not found
|
2012-08-07 13:46:04 +00:00
|
|
|
*/
|
|
|
|
CBotVar* CopyVar(CBotToken& Token, bool bUpdate = false);
|
|
|
|
|
|
|
|
|
2015-08-16 10:43:42 +00:00
|
|
|
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);
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
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
|
2015-08-16 10:43:42 +00:00
|
|
|
bool BreakReturn(CBotStack* pfils, const char* name = nullptr);
|
2012-08-07 13:46:04 +00:00
|
|
|
// in case of eventual break
|
|
|
|
bool IfContinue(int state, const char* name);
|
|
|
|
// or "continue"
|
2013-05-26 15:47:54 +00:00
|
|
|
|
2012-08-07 13:46:04 +00:00
|
|
|
bool IsOk();
|
|
|
|
|
|
|
|
bool SetState(int n, int lim = -10); // select a state
|
2012-08-11 18:59:35 +00:00
|
|
|
int GetState(); // in what state am I?
|
2012-08-07 13:46:04 +00:00
|
|
|
bool IncState(int lim = -10); // passes to the next state
|
|
|
|
bool IfStep(); // do step by step
|
2013-05-26 15:47:54 +00:00
|
|
|
bool Execute();
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
void SetVar( CBotVar* var );
|
|
|
|
void SetCopyVar( CBotVar* var );
|
2012-08-11 18:59:35 +00:00
|
|
|
CBotVar* GetVar();
|
|
|
|
CBotVar* GetCopyVar();
|
|
|
|
CBotVar* GetPtVar();
|
|
|
|
bool GetRetVar(bool bRet);
|
|
|
|
long GetVal();
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-16 10:43:42 +00:00
|
|
|
void SetError(int n, CBotToken* token = nullptr);
|
2012-08-07 13:46:04 +00:00
|
|
|
void SetPosError(CBotToken* token);
|
|
|
|
void ResetError(int n, int start, int end);
|
|
|
|
void SetBreak(int val, const char* name);
|
|
|
|
|
|
|
|
void SetBotCall(CBotProgram* p);
|
2012-08-11 18:59:35 +00:00
|
|
|
CBotProgram* GetBotCall(bool bFirst = false);
|
|
|
|
void* GetPUser();
|
|
|
|
bool GetBlock();
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
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);
|
2012-08-11 18:59:35 +00:00
|
|
|
CBotVar* GetStackVars(const char* &FunctionName, int level);
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
int m_temp;
|
|
|
|
|
|
|
|
private:
|
|
|
|
CBotStack* m_next;
|
|
|
|
CBotStack* m_next2;
|
|
|
|
CBotStack* m_prev;
|
|
|
|
friend class CBotInstArray;
|
|
|
|
|
2013-05-26 15:47:54 +00:00
|
|
|
#ifdef _DEBUG
|
2012-08-07 13:46:04 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:59:35 +00:00
|
|
|
inline int CBotStack::GetState()
|
2012-08-07 13:46:04 +00:00
|
|
|
{
|
|
|
|
return m_state;
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:59:35 +00:00
|
|
|
inline int CBotStack::GetError()
|
2012-08-07 13:46:04 +00:00
|
|
|
{
|
|
|
|
return m_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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();
|
2012-08-11 18:59:35 +00:00
|
|
|
int GetError();
|
|
|
|
int GetError(int& start, int& end);
|
2012-08-07 13:46:04 +00:00
|
|
|
// gives error number
|
|
|
|
|
|
|
|
void SetType(CBotTypResult& type);// determines the type
|
2012-08-11 18:59:35 +00:00
|
|
|
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
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-08-16 10:43:42 +00:00
|
|
|
CBotCStack* TokenStack(CBotToken* pToken = nullptr, bool bBlock = false);
|
2012-08-07 13:46:04 +00:00
|
|
|
CBotInstr* Return(CBotInstr* p, CBotCStack* pParent); // transmits the result upper
|
|
|
|
CBotFunction* ReturnFunc(CBotFunction* p, CBotCStack* pParent); // transmits the result upper
|
2013-05-26 15:47:54 +00:00
|
|
|
|
2012-08-07 13:46:04 +00:00
|
|
|
void SetVar( CBotVar* var );
|
|
|
|
void SetCopyVar( CBotVar* var );
|
2012-08-11 18:59:35 +00:00
|
|
|
CBotVar* GetVar();
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
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);
|
2012-08-11 18:59:35 +00:00
|
|
|
CBotTypResult GetRetType();
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
// void SetBotCall(CBotFunction* &pFunc);
|
|
|
|
void SetBotCall(CBotProgram* p);
|
2012-08-11 18:59:35 +00:00
|
|
|
CBotProgram* GetBotCall();
|
2012-08-07 13:46:04 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// class defining an instruction
|
|
|
|
class CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
static
|
|
|
|
CBotStringArray
|
|
|
|
m_labelLvl;
|
|
|
|
protected:
|
|
|
|
CBotToken m_token; // keeps the token
|
|
|
|
CBotString name; // debug
|
|
|
|
CBotInstr* m_next; // linked command
|
|
|
|
CBotInstr* m_next2b; // second list definition chain
|
|
|
|
CBotInstr* m_next3; // third list for indices and fields
|
|
|
|
CBotInstr* m_next3b; // necessary for reporting tables
|
|
|
|
/*
|
|
|
|
for example, the following program
|
|
|
|
int x[]; x[1] = 4;
|
|
|
|
int y[x[1]][10], z;
|
|
|
|
is generated
|
|
|
|
CBotInstrArray
|
|
|
|
m_next3b-> CBotEmpty
|
|
|
|
m_next->
|
|
|
|
CBotExpression ....
|
|
|
|
m_next->
|
|
|
|
CBotInstrArray
|
|
|
|
m_next3b-> CBotExpression ('x') ( m_next3-> CBotIndexExpr ('1') )
|
|
|
|
m_next3b-> CBotExpression ('10')
|
|
|
|
m_next2-> 'z'
|
|
|
|
m_next->...
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static
|
|
|
|
int m_LoopLvl;
|
|
|
|
friend class CBotClassInst;
|
|
|
|
friend class CBotInt;
|
|
|
|
friend class CBotListArray;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotInstr();
|
|
|
|
virtual
|
|
|
|
~CBotInstr();
|
|
|
|
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
|
|
|
static
|
|
|
|
CBotInstr* CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool first = true);
|
|
|
|
|
|
|
|
virtual
|
|
|
|
bool Execute(CBotStack* &pj);
|
|
|
|
virtual
|
|
|
|
bool Execute(CBotStack* &pj, CBotVar* pVar);
|
|
|
|
virtual
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain);
|
|
|
|
|
|
|
|
virtual
|
|
|
|
bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile);
|
|
|
|
virtual
|
|
|
|
bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend);
|
|
|
|
virtual
|
|
|
|
void RestoreStateVar(CBotStack* &pile, bool bMain);
|
|
|
|
|
|
|
|
virtual
|
|
|
|
bool CompCase(CBotStack* &pj, int val);
|
|
|
|
|
|
|
|
void SetToken(CBotToken* p);
|
2012-08-11 18:59:35 +00:00
|
|
|
int GetTokenType();
|
|
|
|
CBotToken* GetToken();
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
void AddNext(CBotInstr* n);
|
2012-08-11 18:59:35 +00:00
|
|
|
CBotInstr* GetNext();
|
2012-08-07 13:46:04 +00:00
|
|
|
void AddNext3(CBotInstr* n);
|
2012-08-11 18:59:35 +00:00
|
|
|
CBotInstr* GetNext3();
|
2012-08-07 13:46:04 +00:00
|
|
|
void AddNext3b(CBotInstr* n);
|
2012-08-11 18:59:35 +00:00
|
|
|
CBotInstr* GetNext3b();
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
static
|
|
|
|
void IncLvl(CBotString& label);
|
|
|
|
static
|
|
|
|
void IncLvl();
|
|
|
|
static
|
|
|
|
void DecLvl();
|
|
|
|
static
|
|
|
|
bool ChkLvl(const CBotString& label, int type);
|
|
|
|
|
|
|
|
bool IsOfClass(CBotString name);
|
|
|
|
};
|
|
|
|
|
|
|
|
class CBotWhile : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_Condition; // condition
|
|
|
|
CBotInstr* m_Block; // instructions
|
2013-05-26 15:47:54 +00:00
|
|
|
CBotString m_label; // a label if there is
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
CBotWhile();
|
|
|
|
~CBotWhile();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CBotDo : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_Block; // instruction
|
|
|
|
CBotInstr* m_Condition; // conditions
|
2013-05-26 15:47:54 +00:00
|
|
|
CBotString m_label; // a label if there is
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
CBotDo();
|
|
|
|
~CBotDo();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CBotFor : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_Init; // initial intruction
|
|
|
|
CBotInstr* m_Test; // test condition
|
|
|
|
CBotInstr* m_Incr; // instruction for increment
|
|
|
|
CBotInstr* m_Block; // instructions
|
2013-05-26 15:47:54 +00:00
|
|
|
CBotString m_label; // a label if there is
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
CBotFor();
|
|
|
|
~CBotFor();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CBotBreak : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
2013-05-26 15:47:54 +00:00
|
|
|
CBotString m_label; // a label if there is
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
CBotBreak();
|
|
|
|
~CBotBreak();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CBotReturn : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
2013-05-26 15:47:54 +00:00
|
|
|
CBotInstr* m_Instr; // paramter of return
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
CBotReturn();
|
|
|
|
~CBotReturn();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CBotSwitch : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
2013-05-26 15:47:54 +00:00
|
|
|
CBotInstr* m_Value; // value to seek
|
2012-08-07 13:46:04 +00:00
|
|
|
CBotInstr* m_Block; // instructions
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotSwitch();
|
|
|
|
~CBotSwitch();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CBotCase : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_Value; // value to compare
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotCase();
|
|
|
|
~CBotCase();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
|
|
|
bool CompCase(CBotStack* &pj, int val) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CBotCatch : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_Block; // instructions
|
|
|
|
CBotInstr* m_Cond; //condition
|
|
|
|
CBotCatch* m_next; //following catch
|
|
|
|
friend class CBotTry;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotCatch();
|
|
|
|
~CBotCatch();
|
|
|
|
static
|
|
|
|
CBotCatch* Compile(CBotToken* &p, CBotCStack* pStack);
|
|
|
|
bool TestCatch(CBotStack* &pj, int val);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
void RestoreCondState(CBotStack* &pj, bool bMain);
|
|
|
|
};
|
|
|
|
|
|
|
|
class CBotTry : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_Block; // instructions
|
|
|
|
CBotCatch* m_ListCatch; // catches
|
|
|
|
CBotInstr* m_FinalInst; // final instruction
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotTry();
|
|
|
|
~CBotTry();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CBotThrow : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_Value; // the value to send
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotThrow();
|
|
|
|
~CBotThrow();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CBotStartDebugDD : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotStartDebugDD();
|
|
|
|
~CBotStartDebugDD();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CBotIf : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_Condition; // condition
|
|
|
|
CBotInstr* m_Block; // instructions
|
|
|
|
CBotInstr* m_BlockElse; // instructions
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotIf();
|
|
|
|
~CBotIf();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// definition of an integer
|
|
|
|
|
|
|
|
class CBotInt : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_var; // the variable to initialize
|
|
|
|
CBotInstr* m_expr; // a value to put, if there is
|
|
|
|
/// CBotInstr* m_next; // several definitions chained
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotInt();
|
|
|
|
~CBotInt();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip = false);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// definition of an array
|
|
|
|
|
|
|
|
class CBotInstArray : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_var; // the variables to initialize
|
|
|
|
CBotInstr* m_listass; // list of assignments for array
|
|
|
|
CBotTypResult
|
|
|
|
m_typevar; // type of elements
|
|
|
|
// CBotString m_ClassName;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotInstArray();
|
|
|
|
~CBotInstArray();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-05-26 15:47:54 +00:00
|
|
|
// definition of a assignment list for a table
|
2012-08-07 13:46:04 +00:00
|
|
|
// int [ ] a [ ] = ( ( 1, 2, 3 ) , ( 3, 2, 1 ) ) ;
|
|
|
|
|
|
|
|
class CBotListArray : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_expr; // an expression for an element
|
|
|
|
// others are linked with CBotInstr :: m_next3;
|
|
|
|
public:
|
|
|
|
CBotListArray();
|
|
|
|
~CBotListArray();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj, CBotVar* pVar) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CBotEmpty : public CBotInstr
|
|
|
|
{
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// defininition of a boolean
|
|
|
|
|
|
|
|
class CBotBoolean : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_var; // variable to initialise
|
|
|
|
CBotInstr* m_expr; // a value to put, if there is
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotBoolean();
|
|
|
|
~CBotBoolean();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// definition of a real number
|
|
|
|
|
|
|
|
class CBotFloat : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_var; // variable to initialise
|
|
|
|
CBotInstr* m_expr; // a value to put, if there is
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotFloat();
|
|
|
|
~CBotFloat();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// definition of an element string
|
|
|
|
|
|
|
|
class CBotIString : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_var; // variable to initialise
|
|
|
|
CBotInstr* m_expr; // a value to put, if there is
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotIString();
|
|
|
|
~CBotIString();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// definition of an element of any class
|
|
|
|
|
|
|
|
class CBotClassInst : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_var; // variable to initialise
|
|
|
|
CBotClass* m_pClass; // reference to the class
|
|
|
|
CBotInstr* m_Parameters; // parameters to be evaluated for the contructor
|
|
|
|
CBotInstr* m_expr; // a value to put, if there is
|
|
|
|
bool m_hasParams; // has it parameters?
|
|
|
|
long m_nMethodeIdent;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotClassInst();
|
|
|
|
~CBotClassInst();
|
|
|
|
static
|
2015-08-16 10:43:42 +00:00
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass = nullptr);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CBotCondition : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// left operand
|
|
|
|
// accept the expressions that be to the left of assignment
|
|
|
|
|
|
|
|
class CBotLeftExpr : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
long m_nIdent;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotLeftExpr();
|
|
|
|
~CBotLeftExpr();
|
|
|
|
static
|
|
|
|
CBotLeftExpr* Compile(CBotToken* &p, CBotCStack* pStack);
|
|
|
|
bool Execute(CBotStack* &pStack, CBotStack* array);
|
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep);
|
2015-08-17 19:53:28 +00:00
|
|
|
void RestoreStateVar(CBotStack* &pile, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// management of the fields of an instance
|
|
|
|
|
|
|
|
class CBotFieldExpr : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
friend class CBotExpression;
|
|
|
|
int m_nIdent;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotFieldExpr();
|
|
|
|
~CBotFieldExpr();
|
|
|
|
void SetUniqNum(int num);
|
|
|
|
// static
|
|
|
|
// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) override;
|
|
|
|
bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) override;
|
|
|
|
void RestoreStateVar(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// management of indices of the tables
|
|
|
|
|
|
|
|
class CBotIndexExpr : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_expr; // expression for calculating the index
|
|
|
|
friend class CBotLeftExpr;
|
|
|
|
friend class CBotExprVar;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotIndexExpr();
|
|
|
|
~CBotIndexExpr();
|
|
|
|
// static
|
|
|
|
// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) override;
|
|
|
|
bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) override;
|
|
|
|
void RestoreStateVar(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// expressions like
|
|
|
|
// x = a;
|
|
|
|
// x * y + 3;
|
|
|
|
|
|
|
|
class CBotExpression : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotLeftExpr* m_leftop; // left operand
|
|
|
|
CBotInstr* m_rightop; // right operant
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotExpression();
|
|
|
|
~CBotExpression();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pStack) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CBotListExpression : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_Expr; // the first expression to be evaluated
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotListExpression();
|
|
|
|
~CBotListExpression();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pStack) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CBotLogicExpr : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_condition; // test to evaluate
|
|
|
|
CBotInstr* m_op1; // left element
|
|
|
|
CBotInstr* m_op2; // right element
|
|
|
|
friend class CBotTwoOpExpr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotLogicExpr();
|
|
|
|
~CBotLogicExpr();
|
|
|
|
// static
|
|
|
|
// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pStack) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CBotBoolExpr : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// possibly an expression in parentheses ( ... )
|
|
|
|
// there is never an instance of this class
|
|
|
|
// being the object returned inside the parenthesis
|
|
|
|
class CBotParExpr : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
|
|
|
};
|
|
|
|
|
|
|
|
// unary expression
|
|
|
|
class CBotExprUnaire : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_Expr; // expression to be evaluated
|
|
|
|
public:
|
|
|
|
CBotExprUnaire();
|
|
|
|
~CBotExprUnaire();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pStack) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// all operations with two operands
|
|
|
|
|
|
|
|
class CBotTwoOpExpr : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_leftop; // left element
|
|
|
|
CBotInstr* m_rightop; // right element
|
|
|
|
public:
|
|
|
|
CBotTwoOpExpr();
|
|
|
|
~CBotTwoOpExpr();
|
|
|
|
static
|
2015-08-16 10:43:42 +00:00
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations = nullptr);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pStack) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// an instruction block { .... }
|
|
|
|
class CBotBlock : public CBotInstr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true);
|
|
|
|
static
|
|
|
|
CBotInstr* CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal = false);
|
2012-09-20 20:58:00 +00:00
|
|
|
private:
|
2015-09-29 19:35:29 +00:00
|
|
|
CBotBlock() = delete;
|
|
|
|
CBotBlock(const CBotBlock &) = delete;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// the content of a block of instructions ... ; ... ; ... ; ... ;
|
|
|
|
class CBotListInstr : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_Instr; // instructions to do
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotListInstr();
|
|
|
|
~CBotListInstr();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CBotInstrCall : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_Parameters; // the parameters to be evaluated
|
|
|
|
// int m_typeRes; // type of the result
|
|
|
|
// CBotString m_RetClassName; // class of the result
|
|
|
|
CBotTypResult
|
|
|
|
m_typRes; // complete type of the result
|
|
|
|
long m_nFuncIdent; // id of a function
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotInstrCall();
|
|
|
|
~CBotInstrCall();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// a call of method
|
|
|
|
|
|
|
|
class CBotInstrMethode : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_Parameters; // the parameters to be evaluated
|
|
|
|
// int m_typeRes; // type of the result
|
|
|
|
// CBotString m_RetClassName; // class of the result
|
|
|
|
CBotTypResult
|
|
|
|
m_typRes; // complete type of the result
|
|
|
|
|
|
|
|
CBotString m_NomMethod; // name of the method
|
|
|
|
long m_MethodeIdent; // identifier of the method
|
|
|
|
// long m_nThisIdent; // identifier for "this"
|
|
|
|
CBotString m_ClassName; // name of the class
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotInstrMethode();
|
|
|
|
~CBotInstrMethode();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* pVar);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
bool ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep, bool bExtend) override;
|
|
|
|
void RestoreStateVar(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// expression for the variable name
|
|
|
|
|
|
|
|
class CBotExprVar : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
long m_nIdent;
|
|
|
|
friend class CBotPostIncExpr;
|
|
|
|
friend class CBotPreIncExpr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotExprVar();
|
|
|
|
~CBotExprVar();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, int privat=PR_PROTECT);
|
|
|
|
static
|
|
|
|
CBotInstr* CompileMethode(CBotToken* &p, CBotCStack* pStack);
|
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep);
|
2015-08-17 19:53:28 +00:00
|
|
|
void RestoreStateVar(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CBotPostIncExpr : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_Instr;
|
|
|
|
friend class CBotParExpr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotPostIncExpr();
|
|
|
|
~CBotPostIncExpr();
|
|
|
|
// static
|
|
|
|
// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CBotPreIncExpr : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_Instr;
|
|
|
|
friend class CBotParExpr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotPreIncExpr();
|
|
|
|
~CBotPreIncExpr();
|
|
|
|
// static
|
|
|
|
// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CBotLeftExprVar : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
CBotTypResult
|
|
|
|
m_typevar; // type of variable declared
|
|
|
|
long m_nIdent; // unique identifier for that variable
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotLeftExprVar();
|
|
|
|
~CBotLeftExprVar();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CBotExprBool : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotExprBool();
|
|
|
|
~CBotExprBool();
|
|
|
|
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CBotExprNull : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotExprNull();
|
|
|
|
~CBotExprNull();
|
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CBotExprNan : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotExprNan();
|
|
|
|
~CBotExprNan();
|
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CBotNew : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotInstr* m_Parameters; // the parameters to be evaluated
|
|
|
|
long m_nMethodeIdent;
|
|
|
|
// long m_nThisIdent;
|
|
|
|
CBotToken m_vartoken;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotNew();
|
|
|
|
~CBotNew();
|
|
|
|
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// expression representing a number
|
|
|
|
|
|
|
|
class CBotExprNum : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
int m_numtype; // et the type of number
|
|
|
|
long m_valint; // value for an int
|
|
|
|
float m_valfloat; // value for a float
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotExprNum();
|
|
|
|
~CBotExprNum();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// expression representing a string
|
|
|
|
|
|
|
|
class CBotExprAlpha : public CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotExprAlpha();
|
|
|
|
~CBotExprAlpha();
|
|
|
|
static
|
|
|
|
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Execute(CBotStack* &pj) override;
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define MAX(a,b) ((a>b) ? a : b)
|
|
|
|
|
|
|
|
|
|
|
|
// class for the management of integer numbers (int)
|
|
|
|
class CBotVarInt : public CBotVar
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
int m_val; // the value
|
|
|
|
CBotString m_defnum; // the name if given by DefineNum
|
|
|
|
friend class CBotVar;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotVarInt( const CBotToken* name );
|
|
|
|
// ~CBotVarInt();
|
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void SetValInt(int val, const char* s = nullptr) override;
|
|
|
|
void SetValFloat(float val) override;
|
|
|
|
int GetValInt() override;
|
|
|
|
float GetValFloat() override;
|
|
|
|
CBotString GetValString() override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void Copy(CBotVar* pSrc, bool bName=true) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void Add(CBotVar* left, CBotVar* right) override; // addition
|
|
|
|
void Sub(CBotVar* left, CBotVar* right) override; // substraction
|
|
|
|
void Mul(CBotVar* left, CBotVar* right) override; // multiplication
|
|
|
|
int Div(CBotVar* left, CBotVar* right) override; // division
|
|
|
|
int Modulo(CBotVar* left, CBotVar* right) override; // remainder of division
|
|
|
|
void Power(CBotVar* left, CBotVar* right) override; // power
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Lo(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Hi(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Ls(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Hs(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Eq(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Ne(CBotVar* left, CBotVar* right) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void XOr(CBotVar* left, CBotVar* right) override;
|
|
|
|
void Or(CBotVar* left, CBotVar* right) override;
|
|
|
|
void And(CBotVar* left, CBotVar* right) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void SL(CBotVar* left, CBotVar* right) override;
|
|
|
|
void SR(CBotVar* left, CBotVar* right) override;
|
|
|
|
void ASR(CBotVar* left, CBotVar* right) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void Neg() override;
|
|
|
|
void Not() override;
|
|
|
|
void Inc() override;
|
|
|
|
void Dec() override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Save0State(FILE* pf) override;
|
|
|
|
bool Save1State(FILE* pf) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// Class for managing real numbers (float)
|
|
|
|
class CBotVarFloat : public CBotVar
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
float m_val; // the value
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotVarFloat( const CBotToken* name );
|
|
|
|
// ~CBotVarFloat();
|
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void SetValInt(int val, const char* s = nullptr) override;
|
|
|
|
void SetValFloat(float val) override;
|
|
|
|
int GetValInt() override;
|
|
|
|
float GetValFloat() override;
|
|
|
|
CBotString GetValString() override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void Copy(CBotVar* pSrc, bool bName=true) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void Add(CBotVar* left, CBotVar* right) override; // addition
|
|
|
|
void Sub(CBotVar* left, CBotVar* right) override; // substraction
|
|
|
|
void Mul(CBotVar* left, CBotVar* right) override; // multiplication
|
|
|
|
int Div(CBotVar* left, CBotVar* right) override; // division
|
|
|
|
int Modulo(CBotVar* left, CBotVar* right) override; // remainder of division
|
|
|
|
void Power(CBotVar* left, CBotVar* right) override; // power
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Lo(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Hi(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Ls(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Hs(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Eq(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Ne(CBotVar* left, CBotVar* right) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void Neg() override;
|
|
|
|
void Inc() override;
|
|
|
|
void Dec() override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Save1State(FILE* pf) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// class for management of strings (String)
|
|
|
|
class CBotVarString : public CBotVar
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotString m_val; // the value
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotVarString( const CBotToken* name );
|
|
|
|
// ~CBotVarString();
|
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void SetValString(const char* p) override;
|
|
|
|
CBotString GetValString() override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void Copy(CBotVar* pSrc, bool bName=true) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void Add(CBotVar* left, CBotVar* right) override; // addition
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Lo(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Hi(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Ls(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Hs(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Eq(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Ne(CBotVar* left, CBotVar* right) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Save1State(FILE* pf) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// class for the management of boolean
|
|
|
|
class CBotVarBoolean : public CBotVar
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
bool m_val; // the value
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotVarBoolean( const CBotToken* name );
|
|
|
|
// ~CBotVarBoolean();
|
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void SetValInt(int val, const char* s = nullptr) override;
|
|
|
|
void SetValFloat(float val) override;
|
|
|
|
int GetValInt() override;
|
|
|
|
float GetValFloat() override;
|
|
|
|
CBotString GetValString() override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void Copy(CBotVar* pSrc, bool bName=true) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void And(CBotVar* left, CBotVar* right) override;
|
|
|
|
void Or(CBotVar* left, CBotVar* right) override;
|
|
|
|
void XOr(CBotVar* left, CBotVar* right) override;
|
|
|
|
void Not() override;
|
|
|
|
bool Eq(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Ne(CBotVar* left, CBotVar* right) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Save1State(FILE* pf) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// class management class instances
|
|
|
|
class CBotVarClass : public CBotVar
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
static
|
|
|
|
CBotVarClass* m_ExClass; // list of existing instances at some point
|
|
|
|
CBotVarClass* m_ExNext; // for this general list
|
|
|
|
CBotVarClass* m_ExPrev; // for this general list
|
|
|
|
|
|
|
|
private:
|
|
|
|
CBotClass* m_pClass; // the class definition
|
|
|
|
CBotVarClass* m_pParent; // the instance of a parent class
|
|
|
|
CBotVar* m_pVar; // contents
|
|
|
|
friend class CBotVar; // my daddy is a buddy WHAT? :D(\TODO mon papa est un copain )
|
|
|
|
friend class CBotVarPointer; // and also the pointer
|
|
|
|
int m_CptUse; // counter usage
|
|
|
|
long m_ItemIdent; // identifier (unique) of an instance
|
|
|
|
bool m_bConstructor; // set if a constructor has been called
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotVarClass( const CBotToken* name, const CBotTypResult& type );
|
|
|
|
// CBotVarClass( const CBotToken* name, CBotTypResult& type, int &nIdent );
|
|
|
|
~CBotVarClass();
|
|
|
|
// void InitCBotVarClass( const CBotToken* name, CBotTypResult& type, int &nIdent );
|
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void Copy(CBotVar* pSrc, bool bName=true) override;
|
|
|
|
void SetClass(CBotClass* pClass) override; //, int &nIdent);
|
|
|
|
CBotClass* GetClass() override;
|
|
|
|
CBotVar* GetItem(const char* name) override; // return an element of a class according to its name (*)
|
|
|
|
CBotVar* GetItemRef(int nIdent) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
CBotVar* GetItem(int n, bool bExtend) override;
|
|
|
|
CBotVar* GetItemList() override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
CBotString GetValString() override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Save1State(FILE* pf) override;
|
|
|
|
void Maj(void* pUser, bool bContinue) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
void IncrementUse(); // a reference to incrementation
|
|
|
|
void DecrementUse(); // a reference to decrementation
|
|
|
|
|
2013-05-26 15:47:54 +00:00
|
|
|
CBotVarClass*
|
2015-08-17 19:53:28 +00:00
|
|
|
GetPointer() override;
|
2012-08-07 13:46:04 +00:00
|
|
|
void SetItemList(CBotVar* pVar);
|
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void SetIdent(long n) override;
|
2013-05-26 15:47:54 +00:00
|
|
|
|
2012-08-07 13:46:04 +00:00
|
|
|
static CBotVarClass* Find(long id);
|
|
|
|
|
|
|
|
|
2012-08-11 18:59:35 +00:00
|
|
|
// CBotVar* GetMyThis();
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Eq(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Ne(CBotVar* left, CBotVar* right) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void ConstructorSet() override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// class for the management of pointers to a class instances
|
|
|
|
class CBotVarPointer : public CBotVar
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotVarClass*
|
|
|
|
m_pVarClass; // contents
|
|
|
|
CBotClass* m_pClass; // class provided for this pointer
|
|
|
|
friend class CBotVar; // my daddy is a buddy
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotVarPointer( const CBotToken* name, CBotTypResult& type );
|
|
|
|
~CBotVarPointer();
|
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void Copy(CBotVar* pSrc, bool bName=true) override;
|
|
|
|
void SetClass(CBotClass* pClass) override;
|
|
|
|
CBotClass* GetClass() override;
|
|
|
|
CBotVar* GetItem(const char* name) override; // return an element of a class according to its name (*)
|
|
|
|
CBotVar* GetItemRef(int nIdent) override;
|
|
|
|
CBotVar* GetItemList() override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
CBotString GetValString() override;
|
|
|
|
void SetPointer(CBotVar* p) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
CBotVarClass*
|
2015-08-17 19:53:28 +00:00
|
|
|
GetPointer() override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void SetIdent(long n) override; // associates an identification number (unique)
|
2012-08-11 18:59:35 +00:00
|
|
|
long GetIdent(); // gives the identification number associated with
|
2015-08-17 19:53:28 +00:00
|
|
|
void ConstructorSet() override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Save1State(FILE* pf) override;
|
|
|
|
void Maj(void* pUser, bool bContinue) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Eq(CBotVar* left, CBotVar* right) override;
|
|
|
|
bool Ne(CBotVar* left, CBotVar* right) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// classe pour les tableaux
|
|
|
|
|
|
|
|
#define MAXARRAYSIZE 9999
|
|
|
|
|
|
|
|
class CBotVarArray : public CBotVar
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotVarClass*
|
|
|
|
m_pInstance; // instance manager of table
|
|
|
|
|
|
|
|
friend class CBotVar; // my daddy is a buddy
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotVarArray( const CBotToken* name, CBotTypResult& type );
|
|
|
|
~CBotVarArray();
|
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void SetPointer(CBotVar* p) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
CBotVarClass*
|
2015-08-17 19:53:28 +00:00
|
|
|
GetPointer() override;
|
2013-05-26 15:47:54 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
void Copy(CBotVar* pSrc, bool bName=true) override;
|
|
|
|
CBotVar* GetItem(int n, bool bGrow=false) override; // makes an element according to its numeric index
|
2012-08-07 13:46:04 +00:00
|
|
|
// enlarged the table if necessary if bExtend
|
2012-08-11 18:59:35 +00:00
|
|
|
// CBotVar* GetItem(const char* name); // makes a element by literal index
|
2015-08-17 19:53:28 +00:00
|
|
|
CBotVar* GetItemList() override; // gives the first item in the list
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
CBotString GetValString() override; // gets the contents of the array into a string
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-08-17 19:53:28 +00:00
|
|
|
bool Save1State(FILE* pf) override;
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
extern CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars);
|
|
|
|
|
|
|
|
extern bool TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op = 0 );
|
|
|
|
extern bool TypesCompatibles( const CBotTypResult& type1, const CBotTypResult& type2 );
|
|
|
|
|
|
|
|
extern bool WriteWord(FILE* pf, unsigned short w);
|
|
|
|
extern bool ReadWord(FILE* pf, unsigned short& w);
|
|
|
|
extern bool ReadLong(FILE* pf, long& w);
|
|
|
|
extern bool WriteFloat(FILE* pf, float w);
|
|
|
|
extern bool WriteLong(FILE* pf, long w);
|
|
|
|
extern bool ReadFloat(FILE* pf, float& w);
|
|
|
|
extern bool WriteString(FILE* pf, CBotString s);
|
|
|
|
extern bool ReadString(FILE* pf, CBotString& s);
|
|
|
|
extern bool WriteType(FILE* pf, CBotTypResult type);
|
|
|
|
extern bool ReadType(FILE* pf, CBotTypResult& type);
|
|
|
|
|
2012-08-11 18:59:35 +00:00
|
|
|
extern float GetNumFloat( const char* p );
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2015-04-27 16:15:29 +00:00
|
|
|
#if 0
|
2012-08-07 13:46:04 +00:00
|
|
|
extern void DEBUG( const char* text, int val, CBotStack* pile );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
///////////////////////////////////////////
|
|
|
|
// class for routine calls (external)
|
|
|
|
|
|
|
|
class CBotCall
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
static
|
|
|
|
CBotCall* m_ListCalls;
|
|
|
|
static
|
|
|
|
void* m_pUser;
|
|
|
|
long m_nFuncIdent;
|
|
|
|
|
|
|
|
private:
|
|
|
|
CBotString m_name;
|
|
|
|
bool (*m_rExec) (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser) ;
|
|
|
|
CBotTypResult
|
|
|
|
(*m_rComp) (CBotVar* &pVar, void* pUser) ;
|
|
|
|
CBotCall* m_next;
|
|
|
|
|
|
|
|
public:
|
2013-05-26 15:47:54 +00:00
|
|
|
CBotCall(const char* name,
|
|
|
|
bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
|
2012-08-07 13:46:04 +00:00
|
|
|
CBotTypResult rCompile (CBotVar* &pVar, void* pUser));
|
|
|
|
~CBotCall();
|
|
|
|
|
|
|
|
static
|
2013-05-26 15:47:54 +00:00
|
|
|
bool AddFunction(const char* name,
|
|
|
|
bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
|
2012-08-07 13:46:04 +00:00
|
|
|
CBotTypResult rCompile (CBotVar* &pVar, void* pUser));
|
|
|
|
|
|
|
|
static
|
|
|
|
CBotTypResult
|
|
|
|
CompileCall(CBotToken* &p, CBotVar** ppVars, CBotCStack* pStack, long& nIdent);
|
|
|
|
static
|
|
|
|
bool CheckCall(const char* name);
|
|
|
|
|
|
|
|
// static
|
|
|
|
// int DoCall(CBotToken* &p, CBotVar** ppVars, CBotStack* pStack, CBotTypResult& rettype);
|
|
|
|
static
|
|
|
|
int DoCall(long& nIdent, CBotToken* token, CBotVar** ppVars, CBotStack* pStack, CBotTypResult& rettype);
|
|
|
|
#if STACKRUN
|
|
|
|
bool Run(CBotStack* pStack);
|
|
|
|
static
|
|
|
|
bool RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotStack* pStack);
|
|
|
|
#endif
|
|
|
|
|
2012-08-11 18:59:35 +00:00
|
|
|
CBotString GetName();
|
2012-08-07 13:46:04 +00:00
|
|
|
CBotCall* Next();
|
2013-05-26 15:47:54 +00:00
|
|
|
|
2012-08-07 13:46:04 +00:00
|
|
|
static void SetPUser(void* pUser);
|
|
|
|
static void Free();
|
|
|
|
};
|
|
|
|
|
|
|
|
// class managing the methods declared by AddFunction on a class
|
|
|
|
|
|
|
|
class CBotCallMethode
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotString m_name;
|
2015-07-13 16:40:13 +00:00
|
|
|
bool (*m_rExec) (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user);
|
2012-08-07 13:46:04 +00:00
|
|
|
CBotTypResult
|
|
|
|
(*m_rComp) (CBotVar* pThis, CBotVar* &pVar);
|
|
|
|
CBotCallMethode* m_next;
|
|
|
|
friend class CBotClass;
|
|
|
|
long m_nFuncIdent;
|
|
|
|
|
|
|
|
public:
|
2013-05-26 15:47:54 +00:00
|
|
|
CBotCallMethode(const char* name,
|
2015-07-13 16:40:13 +00:00
|
|
|
bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
|
2012-08-07 13:46:04 +00:00
|
|
|
CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar));
|
|
|
|
~CBotCallMethode();
|
|
|
|
|
|
|
|
CBotTypResult
|
2013-05-26 15:47:54 +00:00
|
|
|
CompileCall(const char* name, CBotVar* pThis,
|
2012-08-07 13:46:04 +00:00
|
|
|
CBotVar** ppVars, CBotCStack* pStack,
|
|
|
|
long& nIdent);
|
|
|
|
|
|
|
|
int DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotVar* &pResult, CBotStack* pStack, CBotToken* pFunc);
|
|
|
|
|
2012-08-11 18:59:35 +00:00
|
|
|
CBotString GetName();
|
2012-08-07 13:46:04 +00:00
|
|
|
CBotCallMethode* Next();
|
|
|
|
void AddNext(CBotCallMethode* p);
|
2013-05-26 15:47:54 +00:00
|
|
|
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// a list of parameters
|
|
|
|
|
|
|
|
class CBotDefParam
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CBotToken m_token; // name of the parameter
|
|
|
|
CBotString m_typename; // type name
|
|
|
|
CBotTypResult m_type; // type of paramteter
|
|
|
|
CBotDefParam* m_next; // next parameter
|
|
|
|
long m_nIdent;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CBotDefParam();
|
|
|
|
~CBotDefParam();
|
|
|
|
static
|
|
|
|
CBotDefParam* Compile(CBotToken* &p, CBotCStack* pStack);
|
|
|
|
bool Execute(CBotVar** ppVars, CBotStack* &pj);
|
|
|
|
void RestoreState(CBotStack* &pj, bool bMain);
|
|
|
|
|
|
|
|
void AddNext(CBotDefParam* p);
|
2012-08-11 18:59:35 +00:00
|
|
|
int GetType();
|
|
|
|
CBotTypResult GetTypResult();
|
|
|
|
CBotDefParam* GetNext();
|
2012-08-07 13:46:04 +00:00
|
|
|
|
2012-08-11 18:59:35 +00:00
|
|
|
CBotString GetParamString();
|
2012-08-07 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// a function declaration
|
|
|
|
|
|
|
|
class CBotFunction : CBotInstr
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
// management of list of (static) public functions
|
|
|
|
static
|
|
|
|
CBotFunction* m_listPublic;
|
|
|
|
CBotFunction* m_nextpublic;
|
|
|
|
CBotFunction* m_prevpublic;
|
|
|
|
friend class CBotCStack;
|
|
|
|
// long m_nThisIdent;
|
|
|
|
long m_nFuncIdent;
|
|
|
|
bool m_bSynchro; // synchronized method?
|
|
|
|
|
|
|
|
private:
|
|
|
|
CBotDefParam* m_Param; // parameter list
|
|
|
|
CBotInstr* m_Block; // the instruction block
|
|
|
|
CBotFunction* m_next;
|
|
|
|
CBotToken m_retToken; // if returns CBotTypClass
|
|
|
|
CBotTypResult m_retTyp; // complete type of the result
|
|
|
|
|
|
|
|
bool m_bPublic; // public function
|
|
|
|
bool m_bExtern; // extern function
|
|
|
|
CBotString m_MasterClass; // name of the class we derive
|
|
|
|
CBotProgram* m_pProg;
|
|
|
|
friend class CBotProgram;
|
|
|
|
friend class CBotClass;
|
|
|
|
|
|
|
|
CBotToken m_extern; // for the position of the word "extern"
|
|
|
|
CBotToken m_openpar;
|
|
|
|
CBotToken m_closepar;
|
|
|
|
CBotToken m_openblk;
|
|
|
|
CBotToken m_closeblk;
|
|
|
|
public:
|
|
|
|
CBotFunction();
|
|
|
|
~CBotFunction();
|
|
|
|
static
|
|
|
|
CBotFunction* Compile(CBotToken* &p, CBotCStack* pStack, CBotFunction* pFunc, bool bLocal = true);
|
|
|
|
static
|
|
|
|
CBotFunction* Compile1(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass);
|
2015-08-16 10:43:42 +00:00
|
|
|
bool Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance = nullptr);
|
|
|
|
void RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance = nullptr);
|
2012-08-07 13:46:04 +00:00
|
|
|
|
|
|
|
void AddNext(CBotFunction* p);
|
|
|
|
CBotTypResult CompileCall(const char* name, CBotVar** ppVars, long& nIdent);
|
|
|
|
CBotFunction* FindLocalOrPublic(long& nIdent, const char* name, CBotVar** ppVars, CBotTypResult& TypeOrError, bool bPublic = true);
|
|
|
|
|
|
|
|
int DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken);
|
|
|
|
void RestoreCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack);
|
|
|
|
int DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken, CBotClass* pClass);
|
|
|
|
void RestoreCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotClass* pClass);
|
|
|
|
bool CheckParam(CBotDefParam* pParam);
|
|
|
|
|
|
|
|
static
|
|
|
|
void AddPublic(CBotFunction* pfunc);
|
|
|
|
|
2012-08-11 18:59:35 +00:00
|
|
|
CBotString GetName();
|
|
|
|
CBotString GetParams();
|
2012-08-07 13:46:04 +00:00
|
|
|
bool IsPublic();
|
|
|
|
bool IsExtern();
|
|
|
|
CBotFunction* Next();
|
|
|
|
|
|
|
|
bool GetPosition(int& start, int& stop, CBotGet modestart, CBotGet modestop);
|
|
|
|
};
|