summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-07-27 18:09:50 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-07-27 18:09:50 +0200
commitab8e55a651f71921406bd216ca30f966db81c691 (patch)
tree78fc12d70ab9def2771f7176818d4231da0e2299
parent4ddcd9f810fa588ccf90442f7b4e5ddf385e85f2 (diff)
parent6b846aa62924df0dea4af78c6333f0bd141bda78 (diff)
downloadcolobot-ab8e55a651f71921406bd216ca30f966db81c691.tar.gz
colobot-ab8e55a651f71921406bd216ca30f966db81c691.tar.bz2
colobot-ab8e55a651f71921406bd216ca30f966db81c691.zip
Merge branch 'dev' into dev-opengl
Pulled changes & resolved conflicts
-rw-r--r--CMakeLists.txt4
-rw-r--r--src/CBot/CBot.cpp5889
-rw-r--r--src/CBot/CBot.h2094
-rw-r--r--src/CBot/CBot.rc279
-rw-r--r--src/CBot/CBotAddExpr.cpp2
-rw-r--r--src/CBot/CBotClass.cpp145
-rw-r--r--src/CBot/CBotCompExpr.cpp2
-rw-r--r--src/CBot/CBotDll.h1707
-rw-r--r--src/CBot/CBotFunction.cpp168
-rw-r--r--src/CBot/CBotIf.cpp24
-rw-r--r--src/CBot/CBotProgram.cpp211
-rw-r--r--src/CBot/CBotStack.cpp1774
-rw-r--r--src/CBot/CBotString.cpp756
-rw-r--r--src/CBot/CBotToken.cpp68
-rw-r--r--src/CBot/CBotToken.h4
-rw-r--r--src/CBot/CBotTwoOpExpr.cpp58
-rw-r--r--src/CBot/CBotVar.cpp2380
-rw-r--r--src/CBot/CBotWhile.cpp216
-rw-r--r--src/CBot/CMakeLists.txt1
-rw-r--r--src/CBot/ClassFILE.cpp14
-rw-r--r--src/CBot/StringFunctions.cpp98
-rw-r--r--src/CBot/idees.txt54
-rw-r--r--src/CBot/old15
-rw-r--r--src/CBot/resource.h206
-rw-r--r--src/CMakeLists.txt5
-rw-r--r--src/sound/sound.h3
26 files changed, 7914 insertions, 8263 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8264ef7..82a6e80 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,8 +16,8 @@ find_package(PNG REQUIRED)
set(CMAKE_BUILD_TYPE debug)
# Global compile flags
-set(CMAKE_CXX_FLAGS_RELEASE "-O2")
-set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -O0")
+set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall -std=gnu++0x")
+set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -std=gnu++0x")
# Subdirectory with sources
add_subdirectory(src bin)
diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp
index e2b01a9..fb25049 100644
--- a/src/CBot/CBot.cpp
+++ b/src/CBot/CBot.cpp
@@ -13,491 +13,483 @@
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.///////////////////////////////////////////////////////////////////////
-// compilation des diverses instructions
-// toutes les routines Compile sont statiques
-// et retournent un object selon ce qui a été trouvé comme instruction
-// principe de compilation:
-// les routines Compile retournent un objet de la classe correspondant à l'opération trouvée
-// il s'agit toujours d'une classe fille de CBotInstr.
-// ( les objets CBotInstr ne sont jamais utilisés directement )
+// compilation of various instructions
+// compile all routines are static
+// and return an object according to what was found as instruction
-// si la routine Compile retourne NULL, c'est que l'instruction est fausse
-// ou incomprise.
-// L'erreur se trouve alors sur la pile CBotCStack::IsOk() est FALSE
+// compiler principle:
+// compile the routines return an object of the class corresponding to the operation found
+// this is always a subclass of CBotInstr.
+// (CBotInstr objects are never used directly)
-#include "CBot.h"
+// compiles if the routine returns NULL is that the statement is false
+// or misunderstood.
+// the error is then on the stack CBotCStack :: Isok () is false
+#include "CBot.h"
-// les divers constructeurs / destructeurs
-// pour libérer tout selon l'arbre établi
CBotInstr::CBotInstr()
{
- name = "CBotInstr";
- m_next = NULL;
- m_next2b = NULL;
- m_next3 = NULL;
- m_next3b = NULL;
+ name = "CBotInstr";
+ m_next = NULL;
+ m_next2b = NULL;
+ m_next3 = NULL;
+ m_next3b = NULL;
}
CBotInstr::~CBotInstr()
{
- delete m_next;
- delete m_next2b;
- delete m_next3;
- delete m_next3b;
+ delete m_next;
+ delete m_next2b;
+ delete m_next3;
+ delete m_next3b;
}
-// compteur de boucles imbriquées,
-// pour détermniner les break et continue valides
-// et liste des labels utilisables
+// counter of nested loops,
+// to determine the break and continue valid
+// list of labels used
+
-int CBotInstr::m_LoopLvl = 0;
-CBotStringArray
- CBotInstr::m_labelLvl = CBotStringArray();
+int CBotInstr::m_LoopLvl = 0;
+CBotStringArray CBotInstr::m_labelLvl = CBotStringArray();
-// ajoute un niveau avec un label
+// adds a level with a label
void CBotInstr::IncLvl(CBotString& label)
{
- m_labelLvl.SetSize(m_LoopLvl+1);
- m_labelLvl[m_LoopLvl] = label;
- m_LoopLvl++;
+ m_labelLvl.SetSize(m_LoopLvl+1);
+ m_labelLvl[m_LoopLvl] = label;
+ m_LoopLvl++;
}
-// ajoute un niveau (instruction switch)
+// adds a level (switch statement)
void CBotInstr::IncLvl()
{
- m_labelLvl.SetSize(m_LoopLvl+1);
- m_labelLvl[m_LoopLvl] = "#SWITCH";
- m_LoopLvl++;
+ m_labelLvl.SetSize(m_LoopLvl+1);
+ m_labelLvl[m_LoopLvl] = "#SWITCH";
+ m_LoopLvl++;
}
-// libère un niveau
+// free a level
void CBotInstr::DecLvl()
{
- m_LoopLvl--;
- m_labelLvl[m_LoopLvl].Empty();
+ m_LoopLvl--;
+ m_labelLvl[m_LoopLvl].Empty();
}
-// controle la validité d'un break ou continu
-BOOL CBotInstr::ChkLvl(const CBotString& label, int type)
+// control validity of break and continue
+bool CBotInstr::ChkLvl(const CBotString& label, int type)
{
- int i = m_LoopLvl;
- while (--i>=0)
- {
- if ( type == ID_CONTINUE && m_labelLvl[i] == "#SWITCH") continue;
- if ( label.IsEmpty() ) return TRUE;
- if ( m_labelLvl[i] == label ) return TRUE;
- }
- return FALSE;
+ int i = m_LoopLvl;
+ while (--i>=0)
+ {
+ if ( type == ID_CONTINUE && m_labelLvl[i] == "#SWITCH") continue;
+ if (label.IsEmpty()) return true;
+ if (m_labelLvl[i] == label) return true;
+ }
+ return false;
}
-BOOL CBotInstr::IsOfClass(CBotString n)
+bool CBotInstr::IsOfClass(CBotString n)
{
- return name == n;
+ return name == n;
}
////////////////////////////////////////////////////////////////////////////
-// gestion de base de la classe CBotInstr
+// database management class CBotInstr
-// définie le token correspondant à l'instruction
+// set the token corresponding to the instruction
void CBotInstr::SetToken(CBotToken* p)
{
- m_token = *p;
-}
-
-void CBotInstr::SetToken(CBotString* name, int start, int end)
-{
- SetToken( &CBotToken( *name, CBotString(), start, end));
+ m_token = *p;
}
-
-// rend le type du token associé à l'instruction
+// return the type of the token assicated with the instruction
int CBotInstr::GivTokenType()
{
- return m_token.GivType();
+ return m_token.GivType();
}
-// rend le token associé
+// return associated token
CBotToken* CBotInstr::GivToken()
{
- return &m_token;
+ return &m_token;
}
-// ajoute une instruction à la suite des autres
+// adds the statement following the other
void CBotInstr::AddNext(CBotInstr* n)
{
- CBotInstr* p = this;
- while ( p->m_next != NULL ) p = p->m_next;
- p->m_next = n;
+ CBotInstr* p = this;
+ while (p->m_next != NULL) p = p->m_next;
+ p->m_next = n;
}
void CBotInstr::AddNext3(CBotInstr* n)
{
- CBotInstr* p = this;
- while ( p->m_next3 != NULL ) p = p->m_next3;
- p->m_next3 = n;
+ CBotInstr* p = this;
+ while (p->m_next3 != NULL) p = p->m_next3;
+ p->m_next3 = n;
}
void CBotInstr::AddNext3b(CBotInstr* n)
{
- CBotInstr* p = this;
- while ( p->m_next3b != NULL ) p = p->m_next3b;
- p->m_next3b = n;
+ CBotInstr* p = this;
+ while (p->m_next3b != NULL) p = p->m_next3b;
+ p->m_next3b = n;
}
-// donne l'instruction suivante
+// returns next statement
CBotInstr* CBotInstr::GivNext()
{
- return m_next;
+ return m_next;
}
CBotInstr* CBotInstr::GivNext3()
{
- return m_next3;
+ return m_next3;
}
CBotInstr* CBotInstr::GivNext3b()
{
- return m_next3b;
+ return m_next3b;
}
///////////////////////////////////////////////////////////////////////////
-// compile une instruction, qui peut être
-// while, do, try, throw, if, for, switch, break, continu, return
-// int, float, boolean, string,
-// déclaration d'une instance d'une classe
-// expression quelconque
+// compile an instruction which can be
+// while, do, try, throw, if, for, switch, break, continue, return
+// int, float, boolean, string,
+// declaration of an instance of a class
+// arbitrary expression
+
CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack)
{
- CBotToken* pp = p;
+ CBotToken* pp = p;
- if ( p == NULL ) return NULL;
-
- int type = p->GivType(); // quel est le prochaine token ?
-
- // y a-t-il un label ?
- if ( IsOfType( pp, TokenTypVar ) &&
- IsOfType( pp, ID_DOTS ) )
- {
- type = pp->GivType();
- // seules ces instructions acceptent un label
- if (!IsOfTypeList( pp, ID_WHILE, ID_FOR, ID_DO, ID_REPEAT, 0 ))
- {
- pStack->SetError(TX_LABEL, pp->GivStart());
- return NULL;
- }
- }
+ if (p == NULL) return NULL;
+
+ int type = p->GivType(); // what is the next token
+
+ // is it a lable?
+ if (IsOfType(pp, TokenTypVar) &&
+ IsOfType(pp, ID_DOTS))
+ {
+ type = pp->GivType();
+ // these instructions accept only lable
+ if (!IsOfTypeList(pp, ID_WHILE, ID_FOR, ID_DO, ID_REPEAT, 0))
+ {
+ pStack->SetError(TX_LABEL, pp->GivStart());
+ return NULL;
+ }
+ }
- // appel la routine de compilation correspondant au token trouvé
- switch (type)
- {
- case ID_WHILE:
- return CBotWhile::Compile(p, pStack);
+ // call routine corresponding to the compilation token found
+ switch (type)
+ {
+ case ID_WHILE:
+ return CBotWhile::Compile(p, pStack);
- case ID_FOR:
- return CBotFor::Compile(p, pStack);
+ case ID_FOR:
+ return CBotFor::Compile(p, pStack);
- case ID_DO:
- return CBotDo::Compile(p, pStack);
+ case ID_DO:
+ return CBotDo::Compile(p, pStack);
- case ID_REPEAT:
- return CBotRepeat::Compile(p, pStack);
+ case ID_REPEAT:
+ return CBotRepeat::Compile(p, pStack);
- case ID_BREAK:
- case ID_CONTINUE:
- return CBotBreak::Compile(p, pStack);
+ case ID_BREAK:
+ case ID_CONTINUE:
+ return CBotBreak::Compile(p, pStack);
- case ID_SWITCH:
- return CBotSwitch::Compile(p, pStack);
+ case ID_SWITCH:
+ return CBotSwitch::Compile(p, pStack);
- case ID_TRY:
- return CBotTry::Compile(p, pStack);
+ case ID_TRY:
+ return CBotTry::Compile(p, pStack);
- case ID_THROW:
- return CBotThrow::Compile(p, pStack);
+ case ID_THROW:
+ return CBotThrow::Compile(p, pStack);
- case ID_DEBUGDD:
- return CBotStartDebugDD::Compile(p, pStack);
+ case ID_DEBUGDD:
+ return CBotStartDebugDD::Compile(p, pStack);
- case ID_INT:
- return CBotInt::Compile(p, pStack);
+ case ID_INT:
+ return CBotInt::Compile(p, pStack);
- case ID_FLOAT:
- return CBotFloat::Compile(p, pStack);
+ case ID_FLOAT:
+ return CBotFloat::Compile(p, pStack);
- case ID_STRING:
- return CBotIString::Compile(p, pStack);
+ case ID_STRING:
+ return CBotIString::Compile(p, pStack);
- case ID_BOOLEAN:
- case ID_BOOL:
- return CBotBoolean::Compile(p, pStack);
+ case ID_BOOLEAN:
+ case ID_BOOL:
+ return CBotBoolean::Compile(p, pStack);
- case ID_IF:
- return CBotIf::Compile(p, pStack);
+ case ID_IF:
+ return CBotIf::Compile(p, pStack);
- case ID_RETURN:
- return CBotReturn::Compile(p, pStack);
+ case ID_RETURN:
+ return CBotReturn::Compile(p, pStack);
- case ID_ELSE:
- pStack->SetStartError(p->GivStart());
- pStack->SetError(TX_ELSEWITHOUTIF, p->GivEnd());
- return NULL;
+ case ID_ELSE:
+ pStack->SetStartError(p->GivStart());
+ pStack->SetError(TX_ELSEWITHOUTIF, p->GivEnd());
+ return NULL;
- case ID_CASE:
- pStack->SetStartError(p->GivStart());
- pStack->SetError(TX_OUTCASE, p->GivEnd());
- return NULL;
- }
+ case ID_CASE:
+ pStack->SetStartError(p->GivStart());
+ pStack->SetError(TX_OUTCASE, p->GivEnd());
+ return NULL;
+ }
- pStack->SetStartError(p->GivStart());
+ pStack->SetStartError(p->GivStart());
- // ne doit pas être un mot réservé par DefineNum
- if ( p->GivType() == TokenTypDef )
- {
- pStack->SetError(TX_RESERVED, p);
- return NULL;
- }
+ // should not be a reserved word DefineNum
+ if (p->GivType() == TokenTypDef)
+ {
+ pStack->SetError(TX_RESERVED, p);
+ return NULL;
+ }
- // ce peut être une définition d'instance de class
- CBotToken* ppp = p;
- if ( IsOfType( ppp, TokenTypVar ) /* && IsOfType( ppp, TokenTypVar )*/ )
- {
- if ( CBotClass::Find(p) != NULL )
- {
- // oui, compile la déclaration de l'instance
- return CBotClassInst::Compile(p, pStack);
- }
- }
+ // this might be an instance of class definnition
+ CBotToken* ppp = p;
+ if (IsOfType(ppp, TokenTypVar))
+ {
+ if (CBotClass::Find(p) != NULL)
+ {
+ // yes, compiles the declaration of the instance
+ return CBotClassInst::Compile(p, pStack);
+ }
+ }
- // ce peut être une instruction arithmétique
- CBotInstr* inst = CBotExpression::Compile(p, pStack);
- if (IsOfType(p, ID_SEP))
- {
- return inst;
- }
- pStack->SetError(TX_ENDOF, p->GivStart());
- delete inst;
- return NULL;
+ // this can be an arythmetic instruction
+ CBotInstr* inst = CBotExpression::Compile(p, pStack);
+ if (IsOfType(p, ID_SEP))
+ {
+ return inst;
+ }
+ pStack->SetError(TX_ENDOF, p->GivStart());
+ delete inst;
+ return NULL;
}
-BOOL CBotInstr::Execute(CBotStack* &pj)
+bool CBotInstr::Execute(CBotStack* &pj)
{
- CBotString ClassManquante = name;
- ASM_TRAP(); // ne doit jamais passer par cette routine
- // mais utiliser les routines des classes filles
- return FALSE;
+ CBotString ClassManquante = name;
+ ASM_TRAP(); // should never go through this routine
+ // but use the routines of the subclasses
+ return false;
}
-BOOL CBotInstr::Execute(CBotStack* &pj, CBotVar* pVar)
+bool CBotInstr::Execute(CBotStack* &pj, CBotVar* pVar)
{
- if ( !Execute(pj) ) return FALSE;
- pVar->SetVal( pj->GivVar() );
- return TRUE;
+ if (!Execute(pj)) return false;
+ pVar->SetVal(pj->GivVar());
+ return true;
}
-void CBotInstr::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotInstr::RestoreState(CBotStack* &pj, bool bMain)
{
- CBotString ClassManquante = name;
- ASM_TRAP(); // ne doit jamais passer par cette routine
- // mais utiliser les routines des classes filles
+ CBotString ClassManquante = name;
+ ASM_TRAP(); // should never go through this routine
+ // but use the routines of the subclasses
}
-BOOL CBotInstr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
+bool CBotInstr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
{
- ASM_TRAP(); // papa sait pas faire, voir les filles
- return FALSE;
+ ASM_TRAP(); // dad do not know, see the girls
+ return false;
}
-BOOL CBotInstr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, BOOL bStep, BOOL bExtend)
+bool CBotInstr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend)
{
- ASM_TRAP(); // papa sait pas faire, voir les filles
- return FALSE;
+ ASM_TRAP(); // dad do not know, see the girls
+ return false;
}
-void CBotInstr::RestoreStateVar(CBotStack* &pile, BOOL bMain)
+void CBotInstr::RestoreStateVar(CBotStack* &pile, bool bMain)
{
- ASM_TRAP(); // papa sait pas faire, voir les filles
+ ASM_TRAP(); // dad do not know, see the girls
}
-// cette routine n'est définie que pour la classe fille CBotCase
-// cela permet de faire l'appel CompCase sur toutes les instructions
-// pour savoir s'il s'agit d'un case pour la valeur désirée.
+// this routine is defined only for the subclass CBotCase
+// this allows to make the call on all instructions CompCase
+// to see if it's a case to the desired value.
-BOOL CBotInstr::CompCase(CBotStack* &pj, int val)
+bool CBotInstr::CompCase(CBotStack* &pj, int val)
{
- return FALSE;
+ return false;
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// compile un bloc d'instruction " { i ; i ; } "
+// compiles a statement block " { i ; i ; } "
-// cette classe n'a pas de constructeur, car il n'y a jamais d'instance de cette classe
-// l'objet retourné par Compile est généralement de type CBotListInstr
+// this class have no constructor because there is never an instance of this
+// class (TODO what about default constructor?)
+// the object returned by Compile is usually of type CBotListInstr
-CBotInstr* CBotBlock::Compile(CBotToken* &p, CBotCStack* pStack, BOOL bLocal)
+CBotInstr* CBotBlock::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal)
{
- pStack->SetStartError(p->GivStart());
+ pStack->SetStartError(p->GivStart());
- if (IsOfType(p, ID_OPBLK))
- {
- CBotInstr* inst = CBotListInstr::Compile( p, pStack, bLocal );
+ if (IsOfType(p, ID_OPBLK))
+ {
+ CBotInstr* inst = CBotListInstr::Compile(p, pStack, bLocal);
- if (IsOfType(p, ID_CLBLK))
- {
- return inst;
- }
+ if (IsOfType(p, ID_CLBLK))
+ {
+ return inst;
+ }
- pStack->SetError(TX_CLOSEBLK, p->GivStart()); // manque la parenthèse
- delete inst;
- return NULL;
- }
+ pStack->SetError(TX_CLOSEBLK, p->GivStart()); // missing parenthesis
+ delete inst;
+ return NULL;
+ }
- pStack->SetError(TX_OPENBLK, p->GivStart());
- return NULL;
+ pStack->SetError(TX_OPENBLK, p->GivStart());
+ return NULL;
}
-CBotInstr* CBotBlock::CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, BOOL bLocal)
+CBotInstr* CBotBlock::CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal)
{
- // est-ce un nouveau bloc ?
- if ( p->GivType() == ID_OPBLK ) return CBotBlock::Compile(p, pStack);
+ // is this a new block
+ if (p->GivType() == ID_OPBLK) return CBotBlock::Compile(p, pStack);
- // sinon, cherche une instruction unique à la place
+ // otherwise, look for a single statement instead
- // pour gérer les cas avec définition local à l'instructin (*)
- CBotCStack* pStk = pStack->TokenStack(p, bLocal);
+ // to handle the case with local definition instruction (*)
+ CBotCStack* pStk = pStack->TokenStack(p, bLocal);
- return pStack->Return( CBotInstr::Compile(p, pStk), // une instruction unique
- pStk);
+ return pStack->Return( CBotInstr::Compile(p, pStk), // a single instruction
+ pStk);
}
-// (*) c'est le cas dans l'instruction suivante
-// if ( 1 == 1 ) int x = 0;
-// où la variable x n'est connue que dans le bloc qui suit le if.
+// (*) is the case in the following statement
+// if (1 == 1) int x = 0;
+// where the variable x is known only in the block following the if
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// compile une liste d'instruction, séparés par des points-virgules
+// compiles a list of instructions separated by semicolons
CBotListInstr::CBotListInstr()
{
- m_Instr = NULL;
- name = "CBotListInstr";
+ m_Instr = NULL;
+ name = "CBotListInstr";
}
CBotListInstr::~CBotListInstr()
{
- delete m_Instr;
+ delete m_Instr;
}
-CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, BOOL bLocal)
+CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal)
{
- CBotCStack* pStk = pStack->TokenStack(p, bLocal); // les variables sont locales
+ CBotCStack* pStk = pStack->TokenStack(p, bLocal); // variables are local
- CBotListInstr* inst = new CBotListInstr();
+ CBotListInstr* inst = new CBotListInstr();
- while (TRUE)
- {
- if ( p == NULL ) break;
+ while (true)
+ {
+ if (p == NULL) break;
- if (IsOfType(p, ID_SEP)) continue; // instruction vide ignorée
- if ( p->GivType() == ID_CLBLK ) break; // déja plus d'instruction
+ if (IsOfType(p, ID_SEP)) continue; // empty statement ignored
+ if (p->GivType() == ID_CLBLK) break;
- if (IsOfType(p, 0))
- {
- pStack->SetError(TX_CLOSEBLK, p->GivStart());
- delete inst;
- return pStack->Return(NULL, pStk);
- }
+ if (IsOfType(p, 0))
+ {
+ pStack->SetError(TX_CLOSEBLK, p->GivStart());
+ delete inst;
+ return pStack->Return(NULL, pStk);
+ }
- CBotInstr* i = CBotBlock::CompileBlkOrInst( p, pStk ); // compile la suivante
+ CBotInstr* i = CBotBlock::CompileBlkOrInst(p, pStk); // compiles next
- if (!pStk->IsOk())
- {
- delete inst;
- return pStack->Return(NULL, pStk);
- }
+ if (!pStk->IsOk())
+ {
+ delete inst;
+ return pStack->Return(NULL, pStk);
+ }
- if ( inst->m_Instr == NULL ) inst->m_Instr = i;
- else inst->m_Instr->AddNext(i); // ajoute à la suite
- }
- return pStack->Return(inst, pStk);
+ if (inst->m_Instr == NULL) inst->m_Instr = i;
+ else inst->m_Instr->AddNext(i); // added a result
+ }
+ return pStack->Return(inst, pStk);
}
-// exécute une liste d'instructions
+// executes a set of instructions
-BOOL CBotListInstr::Execute(CBotStack* &pj)
+bool CBotListInstr::Execute(CBotStack* &pj)
{
- CBotStack* pile = pj->AddStack(this, TRUE);//indispensable pour SetState()
- if ( pile->StackOver() ) return pj->Return( pile );
+ CBotStack* pile = pj->AddStack(this, true); //needed for SetState()
+ if (pile->StackOver() ) return pj->Return( pile);
- CBotInstr* p = m_Instr; // la première expression
+ CBotInstr* p = m_Instr; // the first expression
- int state = pile->GivState();
- while (state-->0) p = p->GivNext(); // revient sur l'opération interrompue
+ int state = pile->GivState();
+ while (state-->0) p = p->GivNext(); // returns to the interrupted operation
- if ( p != NULL ) while (TRUE)
- {
-// DEBUG( "CBotListInstr", pile->GivState(), pile );
+ if (p != NULL) while (true)
+ {
+ if (!p->Execute(pile)) return false;
+ p = p->GivNext();
+ if (p == NULL) break;
+ if (!pile->IncState()) ;//return false; // ready for next
+ }
- if ( !p->Execute(pile) ) return FALSE;
- p = p->GivNext();
- if ( p == NULL ) break;
- if (!pile->IncState()) ;//return FALSE; // prêt pour la suivante
- }
-
- return pj->Return( pile ); // transmet en dessous
+ return pj->Return(pile);
}
-void CBotListInstr::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotListInstr::RestoreState(CBotStack* &pj, bool bMain)
{
- if ( !bMain ) return;
+ if (!bMain) return;
- CBotStack* pile = pj->RestoreStack(this);
- if ( pile == NULL ) return;
+ CBotStack* pile = pj->RestoreStack(this);
+ if (pile == NULL) return;
- CBotInstr* p = m_Instr; // la première expression
+ CBotInstr* p = m_Instr; // the first expression
- int state = pile->GivState();
- while ( p != NULL && state-- > 0)
- {
- p->RestoreState(pile, FALSE);
- p = p->GivNext(); // revient sur l'opération interrompue
- }
+ int state = pile->GivState();
+ while ( p != NULL && state-- > 0)
+ {
+ p->RestoreState(pile, false);
+ p = p->GivNext(); // returns to the interrupted operation
+ }
- if ( p != NULL ) p->RestoreState(pile, TRUE);
+ if (p != NULL) p->RestoreState(pile, true);
}
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// compilation d'un élément se trouvant à gauche d'une assignation
+// compilation of an element to the left of an assignment
CBotLeftExprVar::CBotLeftExprVar()
{
- name = "CBotLeftExprVar";
- m_typevar = -1;
- m_nIdent = 0;
+ name = "CBotLeftExprVar";
+ m_typevar = -1;
+ m_nIdent = 0;
}
CBotLeftExprVar::~CBotLeftExprVar()
@@ -506,44 +498,44 @@ CBotLeftExprVar::~CBotLeftExprVar()
CBotInstr* CBotLeftExprVar::Compile(CBotToken* &p, CBotCStack* pStack)
{
- // vérifie que le token est un nom de variable
- if (p->GivType() != TokenTypVar)
- {
- pStack->SetError( TX_NOVAR, p->GivStart());
- return NULL;
- }
+ // verifies that the token is a variable name
+ if (p->GivType() != TokenTypVar)
+ {
+ pStack->SetError( TX_NOVAR, p->GivStart());
+ return NULL;
+ }
- CBotLeftExprVar* inst = new CBotLeftExprVar();
- inst->SetToken(p);
- p = p->GivNext();
+ CBotLeftExprVar* inst = new CBotLeftExprVar();
+ inst->SetToken(p);
+ p = p->GivNext();
- return inst;
+ return inst;
}
-// crée une variable et lui assigne le résultat de la pile
-BOOL CBotLeftExprVar::Execute(CBotStack* &pj)
+// creates a variable and assigns the result to the stack
+bool CBotLeftExprVar::Execute(CBotStack* &pj)
{
- CBotVar* var1;
- CBotVar* var2;
+ CBotVar* var1;
+ CBotVar* var2;
+
+ var1 = CBotVar::Create(m_token.GivString(), m_typevar);
+ var1->SetUniqNum(m_nIdent); // with the unique identifier
+ pj->AddVar(var1); // place it on the stack
- var1 = CBotVar::Create(m_token.GivString(), m_typevar);
- var1->SetUniqNum(m_nIdent); // avec cet identificateur unique
- pj->AddVar(var1); // la place sur la pile
-
- var2 = pj->GivVar(); // resultat sur la pile
- if ( var2 ) var1->SetVal(var2); // fait l'assignation
+ var2 = pj->GivVar(); // result on the stack
+ if (var2) var1->SetVal(var2); // do the assignment
- return TRUE; // opération faite
+ return true;
}
-void CBotLeftExprVar::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotLeftExprVar::RestoreState(CBotStack* &pj, bool bMain)
{
- CBotVar* var1;
+ CBotVar* var1;
- var1 = pj->FindVar(m_token.GivString());
- if ( var1 == NULL ) ASM_TRAP();
+ var1 = pj->FindVar(m_token.GivString());
+ if (var1 == NULL) ASM_TRAP();
- var1->SetUniqNum(m_nIdent); // avec cet identificateur unique
+ var1->SetUniqNum(m_nIdent); // with the unique identifier
}
//////////////////////////////////////////////////////////////////////////////////////
@@ -551,1006 +543,988 @@ void CBotLeftExprVar::RestoreState(CBotStack* &pj, BOOL bMain)
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// définition d'un tableau de n'importe quel type
+// defining an array of any type
// int a[12];
// point x[];
CBotInstArray::CBotInstArray()
{
- m_var = NULL;
- m_listass = NULL;
- name = "CBotInstArray";
+ m_var = NULL;
+ m_listass = NULL;
+ name = "CBotInstArray";
}
CBotInstArray::~CBotInstArray()
{
- delete m_var;
- delete m_listass;
+ delete m_var;
+ delete m_listass;
}
CBotInstr* CBotInstArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type)
{
- CBotCStack* pStk = pStack->TokenStack(p);
+ CBotCStack* pStk = pStack->TokenStack(p);
- CBotInstArray* inst = new CBotInstArray(); // crée l'objet
+ CBotInstArray* inst = new CBotInstArray();
- CBotToken* vartoken = p;
- inst->SetToken(vartoken);
+ CBotToken* vartoken = p;
+ inst->SetToken(vartoken);
- // détermine l'expression valable pour l'élément gauche
- if ( NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) )
- {
- if (pStk->CheckVarLocal(vartoken)) // redéfinition de la variable ?
- {
- pStk->SetError(TX_REDEFVAR, vartoken);
- goto error;
- }
+ // determinse the expression is valid for the item on the left side
+ if (NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )))
+ {
+ if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable?
+ {
+ pStk->SetError(TX_REDEFVAR, vartoken);
+ goto error;
+ }
- CBotInstr* i;
- while (IsOfType(p, ID_OPBRK)) // avec des indices ?
- {
- if ( p->GivType() != ID_CLBRK )
- i = CBotExpression::Compile( p, pStk ); // expression pour la valeur
- else
- i = new CBotEmpty(); // spécial si pas de formule
+ CBotInstr* i;
+ while (IsOfType(p, ID_OPBRK))
+ {
+ if (p->GivType() != ID_CLBRK)
+ i = CBotExpression::Compile(p, pStk); // expression for the value
+ else
+ i = new CBotEmpty(); // if no special formula
- inst->AddNext3b(i); // construit une liste
- type = CBotTypResult(CBotTypArrayPointer, type);
+ inst->AddNext3b(i); // construct a list
+ type = CBotTypResult(CBotTypArrayPointer, type);
- if (!pStk->IsOk() || !IsOfType( p, ID_CLBRK ) )
- {
- pStk->SetError(TX_CLBRK, p->GivStart());
- goto error;
- }
- }
+ if (!pStk->IsOk() || !IsOfType(p, ID_CLBRK ))
+ {
+ pStk->SetError(TX_CLBRK, p->GivStart());
+ goto error;
+ }
+ }
- CBotVar* var = CBotVar::Create(vartoken, type); // crée avec une instance
- inst->m_typevar = type;
+ CBotVar* var = CBotVar::Create(vartoken, type); // create an instance
+ inst->m_typevar = type;
- var->SetUniqNum(
- ((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum());
- // lui attribut un numéro unique
- pStack->AddVar(var); // la place sur la pile
+ var->SetUniqNum(
+ ((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum());
+ pStack->AddVar(var); // place it on the stack
- if ( IsOfType(p, ID_ASS) ) // avec une assignation
- {
- inst->m_listass = CBotListArray::Compile( p, pStk, type.GivTypElem() );
- }
+ if (IsOfType(p, ID_ASS)) // with an assignment
+ {
+ inst->m_listass = CBotListArray::Compile(p, pStk, type.GivTypElem());
+ }
- if ( pStk->IsOk() ) return pStack->Return(inst, pStk);
- }
+ if (pStk->IsOk()) return pStack->Return(inst, pStk);
+ }
error:
- delete inst;
- return pStack->Return(NULL, pStk);
-}
-
-
-// exécute la définition d'un tableau
-
-BOOL CBotInstArray::Execute(CBotStack* &pj)
-{
- CBotStack* pile1 = pj->AddStack(this);
-// if ( pile1 == EOX ) return TRUE;
-
- CBotStack* pile = pile1;
-
- if ( pile1->GivState() == 0 )
- {
- // cherche les dimensions max du tableau
- CBotInstr* p = GivNext3b(); // les différentes formules
- int nb = 0;
-
- while (p != NULL)
- {
- pile = pile->AddStack(); // petite place pour travailler
- nb++;
- if ( pile->GivState() == 0 )
- {
- if ( !p->Execute(pile) ) return FALSE; // calcul de la taille // interrompu?
- pile->IncState();
- }
- p = p->GivNext3b();
- }
-
- p = GivNext3b();
- pile = pile1; // revient sur la pile
- int n = 0;
- int max[100];
-
- while (p != NULL)
- {
- pile = pile->AddStack(); // récupère la même petite place
- CBotVar* v = pile->GivVar(); // résultat
- max[n] = v->GivValInt(); // valeur
- if (max[n]>MAXARRAYSIZE)
- {
- pile->SetError(TX_OUTARRAY, &m_token);
- return pj->Return ( pile );
- }
- n++;
- p = p->GivNext3b();
- }
- while (n<100) max[n++] = 0;
-
- m_typevar.SetArray( max ); // mémorise les limitations
-
- // crée simplement un pointeur null
- CBotVar* var = CBotVar::Create(m_var->GivToken(), m_typevar);
- var->SetPointer(NULL);
- var->SetUniqNum(((CBotLeftExprVar*)m_var)->m_nIdent);
- pj->AddVar(var); // inscrit le tableau de base sur la pile
-
-#if STACKMEM
- pile1->AddStack()->Delete();
+ delete inst;
+ return pStack->Return(NULL, pStk);
+}
+
+
+// executes the definition of an array
+
+bool CBotInstArray::Execute(CBotStack* &pj)
+{
+ CBotStack* pile1 = pj->AddStack(this);
+
+ CBotStack* pile = pile1;
+
+ if (pile1->GivState() == 0)
+ {
+ // seek the maximum dimension of the table
+ CBotInstr* p = GivNext3b(); // the different formulas
+ int nb = 0;
+
+ while (p != NULL)
+ {
+ pile = pile->AddStack(); // little room to work
+ nb++;
+ if (pile->GivState() == 0)
+ {
+ if (!p->Execute(pile)) return false; // size calculation //interrupted?
+ pile->IncState();
+ }
+ p = p->GivNext3b();
+ }
+
+ p = GivNext3b();
+ pile = pile1; // returns to the stack
+ int n = 0;
+ int max[100];
+
+ while (p != NULL)
+ {
+ pile = pile->AddStack();
+ CBotVar* v = pile->GivVar(); // result
+ max[n] = v->GivValInt(); // value
+ if (max[n]>MAXARRAYSIZE)
+ {
+ pile->SetError(TX_OUTARRAY, &m_token);
+ return pj->Return (pile);
+ }
+ n++;
+ p = p->GivNext3b();
+ }
+ while (n<100) max[n++] = 0;
+
+ m_typevar.SetArray(max); // store the limitations
+
+ // crée simplement un pointeur null
+ CBotVar* var = CBotVar::Create(m_var->GivToken(), m_typevar);
+ var->SetPointer(NULL);
+ var->SetUniqNum(((CBotLeftExprVar*)m_var)->m_nIdent);
+ pj->AddVar(var);
+
+#if STACKMEM
+ pile1->AddStack()->Delete();
#else
- delete pile1->AddStack(); // plus besoin des indices
+ delete pile1->AddStack(); // need more indices
#endif
- pile1->IncState();
- }
+ pile1->IncState();
+ }
- if ( pile1->GivState() == 1 )
- {
- if ( m_listass != NULL ) // il y a des assignation pour ce tableau
- {
- CBotVar* pVar = pj->FindVar(((CBotLeftExprVar*)m_var)->m_nIdent);
+ if (pile1->GivState() == 1)
+ {
+ if (m_listass != NULL) // there is the assignment for this table
+ {
+ CBotVar* pVar = pj->FindVar(((CBotLeftExprVar*)m_var)->m_nIdent);
- if ( !m_listass->Execute(pile1, pVar) ) return FALSE;
- }
- pile1->IncState();
- }
+ if (!m_listass->Execute(pile1, pVar)) return false;
+ }
+ pile1->IncState();
+ }
- if ( pile1->IfStep() ) return FALSE; // montre ce pas ?
+ if (pile1->IfStep()) return false;
- if ( m_next2b &&
- !m_next2b->Execute( pile1 ) ) return FALSE;
+ if ( m_next2b &&
+ !m_next2b->Execute(pile1 )) return false;
- return pj->Return( pile1 ); // transmet en dessous
+ return pj->Return(pile1);
}
-void CBotInstArray::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotInstArray::RestoreState(CBotStack* &pj, bool bMain)
{
- CBotStack* pile1 = pj;
+ CBotStack* pile1 = pj;
- CBotVar* var = pj->FindVar(m_var->GivToken()->GivString());
- if ( var != NULL ) var->SetUniqNum(((CBotLeftExprVar*)m_var)->m_nIdent);
+ CBotVar* var = pj->FindVar(m_var->GivToken()->GivString());
+ if (var != NULL) var->SetUniqNum(((CBotLeftExprVar*)m_var)->m_nIdent);
- if ( bMain )
- {
- pile1 = pj->RestoreStack(this);
- CBotStack* pile = pile1;
- if ( pile == NULL ) return;
+ if (bMain)
+ {
+ pile1 = pj->RestoreStack(this);
+ CBotStack* pile = pile1;
+ if (pile == NULL) return;
- if ( pile1->GivState() == 0 )
- {
- // cherche les dimensions max du tableau
- CBotInstr* p = GivNext3b(); // les différentes formules
+ if (pile1->GivState() == 0)
+ {
+ // seek the maximum dimension of the table
+ CBotInstr* p = GivNext3b();
- while (p != NULL)
- {
- pile = pile->RestoreStack(); // petite place pour travailler
- if ( pile == NULL ) return;
- if ( pile->GivState() == 0 )
- {
- p->RestoreState(pile, bMain); // calcul de la taille // interrompu!
- return;
- }
- p = p->GivNext3b();
- }
- }
- if ( pile1->GivState() == 1 && m_listass != NULL )
- {
- m_listass->RestoreState(pile1, bMain);
- }
+ while (p != NULL)
+ {
+ pile = pile->RestoreStack();
+ if (pile == NULL) return;
+ if (pile->GivState() == 0)
+ {
+ p->RestoreState(pile, bMain);
+ return;
+ }
+ p = p->GivNext3b();
+ }
+ }
+ if (pile1->GivState() == 1 && m_listass != NULL)
+ {
+ m_listass->RestoreState(pile1, bMain);
+ }
- }
+ }
-
- if ( m_next2b ) m_next2b->RestoreState( pile1, bMain );
+ if (m_next2b ) m_next2b->RestoreState( pile1, bMain);
}
-// cas particulier pour les indices vides
-BOOL CBotEmpty :: Execute(CBotStack* &pj)
+// special case for empty indexes
+bool CBotEmpty :: Execute(CBotStack* &pj)
{
- CBotVar* pVar = CBotVar::Create("", CBotTypInt);
- pVar->SetValInt(-1); // met la valeur -1 sur la pile
- pj->SetVar(pVar);
- return TRUE;
+ CBotVar* pVar = CBotVar::Create("", CBotTypInt);
+ pVar->SetValInt(-1);
+ pj->SetVar(pVar);
+ return true;
}
-void CBotEmpty :: RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotEmpty :: RestoreState(CBotStack* &pj, bool bMain)
{
}
//////////////////////////////////////////////////////////////////////////////////////
-// définition d'une liste d'initialisation pour un tableau
-// int [ ] a [ ] = ( ( 1, 2, 3 ) , ( 3, 2, 1 ) ) ;
+// defining a list table initialization
+// int [ ] a [ ] = (( 1, 2, 3 ) , ( 3, 2, 1 )) ;
CBotListArray::CBotListArray()
{
- m_expr = NULL;
- name = "CBotListArray";
+ m_expr = NULL;
+ name = "CBotListArray";
}
CBotListArray::~CBotListArray()
{
- delete m_expr;
+ delete m_expr;
}
CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type)
{
- CBotCStack* pStk = pStack->TokenStack(p);
-
- CBotToken* pp = p;
-
- if ( IsOfType( p, ID_NULL ) )
- {
- CBotInstr* inst = new CBotExprNull ();
- inst->SetToken( pp );
-// CBotVar* var = CBotVar::Create("", CBotTypNullPointer);
-// pStk->SetVar(var);
- return pStack->Return(inst, pStk); // ok avec élément vide
- }
-
- CBotListArray* inst = new CBotListArray(); // crée l'objet
-
- if ( IsOfType( p, ID_OPENPAR ) )
- {
- // prend chaque élément l'un après l'autre
- if ( type.Eq( CBotTypArrayPointer ) )
- {
- type = type.GivTypElem();
-
- pStk->SetStartError(p->GivStart());
- if ( NULL == ( inst->m_expr = CBotListArray::Compile( p, pStk, type ) ) )
- {
- goto error;
- }
-
- while ( IsOfType( p, ID_COMMA ) ) // d'autres éléments ?
- {
- pStk->SetStartError(p->GivStart());
-
- CBotInstr* i = CBotListArray::Compile( p, pStk, type );
- if ( NULL == i )
- {
- goto error;
- }
-
- inst->m_expr->AddNext3(i);
- }
- }
- else
- {
- pStk->SetStartError(p->GivStart());
- if ( NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) )
- {
- goto error;
- }
- CBotVar* pv = pStk->GivVar(); // le résultat de l'expression
-
- if ( pv == NULL || !TypesCompatibles( type, pv->GivTypResult() )) // type compatible ?
- {
- pStk->SetError(TX_BADTYPE, p->GivStart());
- goto error;
- }
-
- while ( IsOfType( p, ID_COMMA ) ) // d'autres éléments ?
- {
- pStk->SetStartError(p->GivStart());
-
- CBotInstr* i = CBotTwoOpExpr::Compile( p, pStk ) ;
- if ( NULL == i )
- {
- goto error;
- }
-
- CBotVar* pv = pStk->GivVar(); // le résultat de l'expression
-
- if ( pv == NULL || !TypesCompatibles( type, pv->GivTypResult() )) // type compatible ?
- {
- pStk->SetError(TX_BADTYPE, p->GivStart());
- goto error;
- }
- inst->m_expr->AddNext3(i);
- }
- }
-
- if (!IsOfType(p, ID_CLOSEPAR) )
- {
- pStk->SetError(TX_CLOSEPAR, p->GivStart());
- goto error;
- }
-
- return pStack->Return(inst, pStk);
- }
+ CBotCStack* pStk = pStack->TokenStack(p);
+
+ CBotToken* pp = p;
+
+ if (IsOfType( p, ID_NULL ))
+ {
+ CBotInstr* inst = new CBotExprNull ();
+ inst->SetToken(pp);
+ return pStack->Return(inst, pStk); // ok with empty element
+ }
+
+ CBotListArray* inst = new CBotListArray();
+
+ if (IsOfType( p, ID_OPENPAR ))
+ {
+ // each element takes the one after the other
+ if (type.Eq( CBotTypArrayPointer ))
+ {
+ type = type.GivTypElem();
+
+ pStk->SetStartError(p->GivStart());
+ if (NULL == ( inst->m_expr = CBotListArray::Compile( p, pStk, type ) ))
+ {
+ goto error;
+ }
+
+ while (IsOfType( p, ID_COMMA )) // other elements?
+ {
+ pStk->SetStartError(p->GivStart());
+
+ CBotInstr* i = CBotListArray::Compile(p, pStk, type);
+ if (NULL == i)
+ {
+ goto error;
+ }
+
+ inst->m_expr->AddNext3(i);
+ }
+ }
+ else
+ {
+ pStk->SetStartError(p->GivStart());
+ if (NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
+ {
+ goto error;
+ }
+ CBotVar* pv = pStk->GivVar(); // result of the expression
+
+ if (pv == NULL || !TypesCompatibles( type, pv->GivTypResult())) // compatible type?
+ {
+ pStk->SetError(TX_BADTYPE, p->GivStart());
+ goto error;
+ }
+
+ while (IsOfType( p, ID_COMMA )) // other elements?
+ {
+ pStk->SetStartError(p->GivStart());
+
+ CBotInstr* i = CBotTwoOpExpr::Compile(p, pStk) ;
+ if (NULL == i)
+ {
+ goto error;
+ }
+
+ CBotVar* pv = pStk->GivVar(); // result of the expression
+
+ if (pv == NULL || !TypesCompatibles( type, pv->GivTypResult())) // compatible type?
+ {
+ pStk->SetError(TX_BADTYPE, p->GivStart());
+ goto error;
+ }
+ inst->m_expr->AddNext3(i);
+ }
+ }
+
+ if (!IsOfType(p, ID_CLOSEPAR) )
+ {
+ pStk->SetError(TX_CLOSEPAR, p->GivStart());
+ goto error;
+ }
+
+ return pStack->Return(inst, pStk);
+ }
error:
- delete inst;
- return pStack->Return(NULL, pStk);
+ delete inst;
+ return pStack->Return(NULL, pStk);
}
-// exécute la définition d'un tableau
+// executes the definition of an array
-BOOL CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar)
+bool CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar)
{
- CBotStack* pile1 = pj->AddStack();
-// if ( pile1 == EOX ) return TRUE;
- CBotVar* pVar2;
+ CBotStack* pile1 = pj->AddStack();
+ CBotVar* pVar2;
- CBotInstr* p = m_expr;
+ CBotInstr* p = m_expr;
- int n = 0;
+ int n = 0;
- for ( ; p != NULL ; n++, p = p->GivNext3() )
- {
- if ( pile1->GivState() > n ) continue;
+ for (; p != NULL ; n++, p = p->GivNext3())
+ {
+ if (pile1->GivState() > n) continue;
- pVar2 = pVar->GivItem(n, TRUE);
+ pVar2 = pVar->GivItem(n, true);
- if ( !p->Execute(pile1, pVar2) ) return FALSE; // évalue l'expression
+ if (!p->Execute(pile1, pVar2)) return false; // evaluate expression
- pile1->IncState();
- }
+ pile1->IncState();
+ }
- return pj->Return( pile1 ); // transmet en dessous
+ return pj->Return(pile1);
}
-void CBotListArray::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotListArray::RestoreState(CBotStack* &pj, bool bMain)
{
- if ( bMain )
- {
- CBotStack* pile = pj->RestoreStack(this);
- if ( pile == NULL ) return;
+ if (bMain)
+ {
+ CBotStack* pile = pj->RestoreStack(this);
+ if (pile == NULL) return;
- CBotInstr* p = m_expr;
+ CBotInstr* p = m_expr;
- int state = pile->GivState();
+ int state = pile->GivState();
- while( state-- > 0 ) p = p->GivNext3() ;
+ while(state-- > 0) p = p->GivNext3() ;
- p->RestoreState(pile, bMain); // calcul de la taille // interrompu!
- }
+ p->RestoreState(pile, bMain); // size calculation //interrupted!
+ }
}
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// définition d'une variable entière
+// definition of an integer variable
// int a, b = 12;
CBotInt::CBotInt()
{
- m_next = NULL; // pour les définitions multiples
- m_var =
- m_expr = NULL;
- name = "CBotInt";
+ m_next = NULL; // for multiple definitions
+ m_var =
+ m_expr = NULL;
+ name = "CBotInt";
}
CBotInt::~CBotInt()
{
- delete m_var;
- delete m_expr;
-// delete m_next; // fait par le destructeur de la classe de base ~CBotInstr()
+ delete m_var;
+ delete m_expr;
}
-CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, BOOL first)
-{
- if ( IsOfType(p, ID_OPBRK) )
- {
- if ( !IsOfType(p, ID_CLBRK) )
- {
- pStack->SetError(TX_CLBRK, p->GivStart());
- return NULL;
- }
-
- CBotInstr* inst = CompileArray(p, pStack, CBotTypResult( CBotTypArrayPointer, type ), FALSE);
- if ( inst != NULL || !pStack->IsOk() ) return inst;
- }
-
- // compile une déclaration de tableau
- if (first) return NULL ;
-
- CBotInstr* inst = CBotInstArray::Compile( p, pStack, type );
- if ( inst == NULL ) return NULL;
-
- if (IsOfType(p, ID_COMMA)) // plusieurs définitions enchaînées
- {
- if ( NULL != ( inst->m_next2b = CBotInstArray::CompileArray(p, pStack, type, FALSE) )) // compile la suivante
- {
- return inst;
- }
- delete inst;
- return NULL;
- }
-
- if (IsOfType(p, ID_SEP)) // instruction terminée
- {
- return inst;
- }
-
- delete inst;
- pStack->SetError(TX_ENDOF, p->GivStart());
- return NULL;
-}
-
-CBotInstr* CBotInt::Compile(CBotToken* &p, CBotCStack* pStack, BOOL cont, BOOL noskip)
-{
- CBotToken* pp = cont ? NULL : p; // pas de répétition du token "int"
-
- if (!cont && !IsOfType(p, ID_INT)) return NULL;
-
- CBotInt* inst = (CBotInt*)CompileArray(p, pStack, CBotTypInt);
- if ( inst != NULL || !pStack->IsOk() ) return inst;
-
- CBotCStack* pStk = pStack->TokenStack(pp);
-
- inst = new CBotInt(); // crée l'objet
-
- inst->m_expr = NULL;
-
- CBotToken* vartoken = p;
- inst->SetToken( vartoken );
-
- // détermine l'expression valable pour l'élément gauche
- if ( NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) )
- {
- ((CBotLeftExprVar*)inst->m_var)->m_typevar = CBotTypInt;
- if (pStk->CheckVarLocal(vartoken)) // redéfinition de la variable
- {
- pStk->SetError(TX_REDEFVAR, vartoken);
- goto error;
- }
-
- if (IsOfType(p, ID_OPBRK)) // avec des indices ?
- {
- delete inst; // n'est pas de type CBotInt
- p = vartoken; // revient sur le nom de la variable
-
- // compile une déclaration de tableau
-
- CBotInstr* inst2 = CBotInstArray::Compile( p, pStk, CBotTypInt );
-
- if (!pStk->IsOk() )
- {
- pStk->SetError(TX_CLBRK, p->GivStart());
- goto error;
- }
-
- if (IsOfType(p, ID_COMMA)) // plusieurs définitions enchaînées
- {
- if ( NULL != ( inst2->m_next2b = CBotInt::Compile(p, pStk, TRUE, noskip) )) // compile la suivante
- {
- return pStack->Return(inst2, pStk);
- }
- }
- inst = (CBotInt*)inst2;
- goto suite; // pas d'assignation, variable déjà créée
- }
-
- if (IsOfType(p, ID_ASS)) // avec une assignation ?
- {
- if ( NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) )
- {
- goto error;
- }
- if ( pStk->GivType() >= CBotTypBoolean ) // type compatible ?
- {
- pStk->SetError(TX_BADTYPE, p->GivStart());
- goto error;
- }
- }
-
- {
- CBotVar* var = CBotVar::Create(vartoken, CBotTypInt);// crée la variable (après l'assignation évaluée)
- var->SetInit(inst->m_expr != NULL); // la marque initialisée si avec assignation
- var->SetUniqNum(
- ((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum());
- // lui attribut un numéro unique
- pStack->AddVar(var); // la place sur la pile
- }
-
- if (IsOfType(p, ID_COMMA)) // plusieurs définitions enchaînées
- {
- if ( NULL != ( inst->m_next2b = CBotInt::Compile(p, pStk, TRUE, noskip) )) // compile la suivante
- {
- return pStack->Return(inst, pStk);
- }
- }
+CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool first)
+{
+ if (IsOfType(p, ID_OPBRK))
+ {
+ if (!IsOfType(p, ID_CLBRK))
+ {
+ pStack->SetError(TX_CLBRK, p->GivStart());
+ return NULL;
+ }
+
+ CBotInstr* inst = CompileArray(p, pStack, CBotTypResult(CBotTypArrayPointer, type), false);
+ if (inst != NULL || !pStack->IsOk()) return inst;
+ }
+
+ // compiles an array declaration
+ if (first) return NULL ;
+
+ CBotInstr* inst = CBotInstArray::Compile(p, pStack, type);
+ if (inst == NULL) return NULL;
+
+ if (IsOfType(p, ID_COMMA)) // several definitions
+ {
+ if (NULL != ( inst->m_next2b = CBotInstArray::CompileArray(p, pStack, type, false))) // compiles next one
+ {
+ return inst;
+ }
+ delete inst;
+ return NULL;
+ }
+
+ if (IsOfType(p, ID_SEP)) // end of instruction
+ {
+ return inst;
+ }
+
+ delete inst;
+ pStack->SetError(TX_ENDOF, p->GivStart());
+ return NULL;
+}
+
+CBotInstr* CBotInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip)
+{
+ CBotToken* pp = cont ? NULL : p; // no repetition of the token "int"
+
+ if (!cont && !IsOfType(p, ID_INT)) return NULL;
+
+ CBotInt* inst = (CBotInt*)CompileArray(p, pStack, CBotTypInt);
+ if (inst != NULL || !pStack->IsOk()) return inst;
+
+ CBotCStack* pStk = pStack->TokenStack(pp);
+
+ inst = new CBotInt();
+
+ inst->m_expr = NULL;
+
+ CBotToken* vartoken = p;
+ inst->SetToken(vartoken);
+
+ // determines the expression is valid for the item on the left side
+ if (NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )))
+ {
+ ((CBotLeftExprVar*)inst->m_var)->m_typevar = CBotTypInt;
+ if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable
+ {
+ pStk->SetError(TX_REDEFVAR, vartoken);
+ goto error;
+ }
+
+ if (IsOfType(p, ID_OPBRK))
+ {
+ delete inst; // type is not CBotInt
+ p = vartoken; // returns the variable name
+
+ // compiles an array declaration
+
+ CBotInstr* inst2 = CBotInstArray::Compile(p, pStk, CBotTypInt);
+
+ if (!pStk->IsOk() )
+ {
+ pStk->SetError(TX_CLBRK, p->GivStart());
+ goto error;
+ }
+
+ if (IsOfType(p, ID_COMMA)) // several definition chained
+ {
+ if (NULL != ( inst2->m_next2b = CBotInt::Compile(p, pStk, true, noskip))) // compile the next one
+ {
+ return pStack->Return(inst2, pStk);
+ }
+ }
+ inst = (CBotInt*)inst2;
+ goto suite; // no assignment, variable already created
+ }
+
+ if (IsOfType(p, ID_ASS)) // with an assignment?
+ {
+ if (NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
+ {
+ goto error;
+ }
+ if (pStk->GivType() >= CBotTypBoolean) // compatible type ?
+ {
+ pStk->SetError(TX_BADTYPE, p->GivStart());
+ goto error;
+ }
+ }
+
+ {
+ CBotVar* var = CBotVar::Create(vartoken, CBotTypInt);// create the variable (evaluated after the assignment)
+ var->SetInit(inst->m_expr != NULL); // if initialized with assignment
+ var->SetUniqNum( //set it with a unique number
+ ((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum());
+ pStack->AddVar(var); // place it on the stack
+ }
+
+ if (IsOfType(p, ID_COMMA)) // chained several definitions
+ {
+ if (NULL != ( inst->m_next2b = CBotInt::Compile(p, pStk, true, noskip))) // compile next one
+ {
+ return pStack->Return(inst, pStk);
+ }
+ }
suite:
- if (noskip || IsOfType(p, ID_SEP)) // instruction terminée
- {
- return pStack->Return(inst, pStk);
- }
+ if (noskip || IsOfType(p, ID_SEP)) // instruction is completed
+ {
+ return pStack->Return(inst, pStk);
+ }
- pStk->SetError(TX_ENDOF, p->GivStart());
- }
+ pStk->SetError(TX_ENDOF, p->GivStart());
+ }
error:
- delete inst;
- return pStack->Return(NULL, pStk);
+ delete inst;
+ return pStack->Return(NULL, pStk);
}
-// exécute la définition de la variable entière
+// execute the definition of the integer variable
-BOOL CBotInt::Execute(CBotStack* &pj)
+bool CBotInt::Execute(CBotStack* &pj)
{
- CBotStack* pile = pj->AddStack(this); //indispensable pour SetState()
-// if ( pile == EOX ) return TRUE;
+ CBotStack* pile = pj->AddStack(this); // essential for SetState()
- if ( pile->GivState()==0)
- {
- if (m_expr && !m_expr->Execute(pile)) return FALSE; // valeur initiale // interrompu?
- m_var->Execute( pile ); // crée et fait l'assigation du résultat
+ if ( pile->GivState()==0)
+ {
+ if (m_expr && !m_expr->Execute(pile)) return false; // initial value // interrupted?
+ m_var->Execute(pile); // creates and assign the result
- if (!pile->SetState(1)) return FALSE;
- }
+ if (!pile->SetState(1)) return false;
+ }
- if ( pile->IfStep() ) return FALSE;
+ if (pile->IfStep()) return false;
- if ( m_next2b &&
- !m_next2b->Execute(pile)) return FALSE; // autre(s) définition(s)
+ if ( m_next2b &&
+ !m_next2b->Execute(pile)) return false; // other(s) definition(s)
- return pj->Return( pile ); // transmet en dessous
+ return pj->Return(pile); // forward below
}
-void CBotInt::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotInt::RestoreState(CBotStack* &pj, bool bMain)
{
- CBotStack* pile = pj;
- if ( bMain )
- {
- pile = pj->RestoreStack(this);
- if ( pile == NULL ) return;
+ CBotStack* pile = pj;
+ if (bMain)
+ {
+ pile = pj->RestoreStack(this);
+ if (pile == NULL) return;
- if ( pile->GivState()==0)
- {
- if (m_expr) m_expr->RestoreState(pile, bMain); // valeur initiale // interrompu!
- return;
- }
- }
+ if ( pile->GivState()==0)
+ {
+ if (m_expr) m_expr->RestoreState(pile, bMain); // initial value // interrupted?
+ return;
+ }
+ }
- m_var->RestoreState(pile, bMain);
+ m_var->RestoreState(pile, bMain);
- if ( m_next2b ) m_next2b->RestoreState(pile, bMain); // autre(s) définition(s)
+ if (m_next2b) m_next2b->RestoreState(pile, bMain); // other(s) definition(s)
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// définition d'une variable booléen
+// defining a boolean variable
// int a, b = false;
CBotBoolean::CBotBoolean()
{
- m_var =
- m_expr = NULL;
- name = "CBotBoolean";
+ m_var =
+ m_expr = NULL;
+ name = "CBotBoolean";
}
CBotBoolean::~CBotBoolean()
{
- delete m_var;
- delete m_expr;
+ delete m_var;
+ delete m_expr;
}
-CBotInstr* CBotBoolean::Compile(CBotToken* &p, CBotCStack* pStack, BOOL cont, BOOL noskip)
+CBotInstr* CBotBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip)
{
- CBotToken* pp = cont ? NULL : p;
+ CBotToken* pp = cont ? NULL : p;
- if (!cont && !IsOfType(p, ID_BOOLEAN, ID_BOOL)) return NULL;
+ if (!cont && !IsOfType(p, ID_BOOLEAN, ID_BOOL)) return NULL;
- CBotBoolean* inst = (CBotBoolean*)CompileArray(p, pStack, CBotTypBoolean);
- if ( inst != NULL || !pStack->IsOk() ) return inst;
+ CBotBoolean* inst = (CBotBoolean*)CompileArray(p, pStack, CBotTypBoolean);
+ if (inst != NULL || !pStack->IsOk()) return inst;
- CBotCStack* pStk = pStack->TokenStack(pp);
+ CBotCStack* pStk = pStack->TokenStack(pp);
- inst = new CBotBoolean();
+ inst = new CBotBoolean();
- inst->m_expr = NULL;
+ inst->m_expr = NULL;
- CBotToken* vartoken = p;
- inst->SetToken( vartoken );
- CBotVar* var = NULL;
+ CBotToken* vartoken = p;
+ inst->SetToken(vartoken);
+ CBotVar* var = NULL;
- if ( NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) )
- {
- ((CBotLeftExprVar*)inst->m_var)->m_typevar = CBotTypBoolean;
- if (pStk->CheckVarLocal(vartoken)) // redéfinition de la variable
- {
- pStk->SetError(TX_REDEFVAR, vartoken);
- goto error;
- }
+ if (NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )))
+ {
+ ((CBotLeftExprVar*)inst->m_var)->m_typevar = CBotTypBoolean;
+ if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable
+ {
+ pStk->SetError(TX_REDEFVAR, vartoken);
+ goto error;
+ }
- if (IsOfType(p, ID_OPBRK)) // avec des indices ?
- {
- delete inst; // n'est pas de type CBotInt
- p = vartoken; // revient sur le nom de la variable
+ if (IsOfType(p, ID_OPBRK))
+ {
+ delete inst; // type is not CBotInt
+ p = vartoken; // resutns to the variable name
- // compile une déclaration de tableau
+ // compiles an array declaration
- inst = (CBotBoolean*)CBotInstArray::Compile( p, pStk, CBotTypBoolean );
+ inst = (CBotBoolean*)CBotInstArray::Compile(p, pStk, CBotTypBoolean);
- if (!pStk->IsOk() )
- {
- pStk->SetError(TX_CLBRK, p->GivStart());
- goto error;
- }
- goto suite; // pas d'assignation, variable déjà créée
- }
+ if (!pStk->IsOk() )
+ {
+ pStk->SetError(TX_CLBRK, p->GivStart());
+ goto error;
+ }
+ goto suite; // no assignment, variable already created
+ }
- if (IsOfType(p, ID_ASS)) // avec une assignation ?
- {
- if ( NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) )
- {
- goto error;
- }
- if ( !pStk->GivTypResult().Eq(CBotTypBoolean) ) // type compatible ?
- {
- pStk->SetError(TX_BADTYPE, p->GivStart());
- goto error;
- }
- }
+ if (IsOfType(p, ID_ASS))
+ {
+ if (NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
+ {
+ goto error;
+ }
+ if (!pStk->GivTypResult().Eq(CBotTypBoolean))
+ {
+ pStk->SetError(TX_BADTYPE, p->GivStart());
+ goto error;
+ }
+ }
- var = CBotVar::Create(vartoken, CBotTypBoolean);// crée la variable (après l'assignation évaluée)
- var->SetInit(inst->m_expr != NULL); // la marque initialisée si avec assignation
- var->SetUniqNum(
- ((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum());
- // lui attribut un numéro unique
- pStack->AddVar(var); // la place sur la pile
+ var = CBotVar::Create(vartoken, CBotTypBoolean);// create the variable (evaluated after the assignment)
+ var->SetInit(inst->m_expr != NULL);
+ var->SetUniqNum(
+ ((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum());
+ pStack->AddVar(var);
suite:
- if (IsOfType(p, ID_COMMA)) // plusieurs définitions enchaînées
- {
- if ( NULL != ( inst->m_next2b = CBotBoolean::Compile(p, pStk, TRUE, noskip) )) // compile la suivante
- {
- return pStack->Return(inst, pStk);
- }
- }
-
- if (noskip || IsOfType(p, ID_SEP)) // instruction terminée
- {
- return pStack->Return(inst, pStk);
- }
-
- pStk->SetError(TX_ENDOF, p->GivStart());
- }
+ if (IsOfType(p, ID_COMMA))
+ {
+ if (NULL != ( inst->m_next2b = CBotBoolean::Compile(p, pStk, true, noskip)))
+ {
+ return pStack->Return(inst, pStk);
+ }
+ }
+
+ if (noskip || IsOfType(p, ID_SEP))
+ {
+ return pStack->Return(inst, pStk);
+ }
+
+ pStk->SetError(TX_ENDOF, p->GivStart());
+ }
error:
- delete inst;
- return pStack->Return(NULL, pStk);
+ delete inst;
+ return pStack->Return(NULL, pStk);
}
-// exécute une définition de variable booléenne
+// executes a boolean variable definition
-BOOL CBotBoolean::Execute(CBotStack* &pj)
+bool CBotBoolean::Execute(CBotStack* &pj)
{
- CBotStack* pile = pj->AddStack(this);//indispensable pour SetState()
-// if ( pile == EOX ) return TRUE;
+ CBotStack* pile = pj->AddStack(this);//essential for SetState()
- if ( pile->GivState()==0)
- {
- if (m_expr && !m_expr->Execute(pile)) return FALSE; // valeur initiale // interrompu?
- m_var->Execute( pile ); // crée et fait l'assigation du résultat
+ if ( pile->GivState()==0)
+ {
+ if (m_expr && !m_expr->Execute(pile)) return false;
+ m_var->Execute(pile);
- if (!pile->SetState(1)) return FALSE;
- }
+ if (!pile->SetState(1)) return false;
+ }
- if ( pile->IfStep() ) return FALSE;
+ if (pile->IfStep()) return false;
- if ( m_next2b &&
- !m_next2b->Execute(pile)) return FALSE; // autre(s) définition(s)
+ if ( m_next2b &&
+ !m_next2b->Execute(pile)) return false;
- return pj->Return( pile ); // transmet en dessous
+ return pj->Return(pile);
}
-void CBotBoolean::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotBoolean::RestoreState(CBotStack* &pj, bool bMain)
{
- CBotStack* pile = pj;
- if ( bMain )
- {
- pile = pj->RestoreStack(this);
- if ( pile == NULL ) return;
+ CBotStack* pile = pj;
+ if (bMain)
+ {
+ pile = pj->RestoreStack(this);
+ if (pile == NULL) return;
- if ( pile->GivState()==0)
- {
- if (m_expr) m_expr->RestoreState(pile, bMain); // valeur initiale interrompu?
- return;
- }
- }
+ if ( pile->GivState()==0)
+ {
+ if (m_expr) m_expr->RestoreState(pile, bMain); // initial value interrupted?
+ return;
+ }
+ }
- m_var->RestoreState( pile, bMain ); //
+ m_var->RestoreState(pile, bMain);
- if ( m_next2b )
- m_next2b->RestoreState(pile, bMain); // autre(s) définition(s)
+ if (m_next2b)
+ m_next2b->RestoreState(pile, bMain); // other(s) definition(s)
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// définition d'une variable réelle
+// definition of a real/float variable
// int a, b = 12.4;
CBotFloat::CBotFloat()
{
- m_var =
- m_expr = NULL;
- name = "CBotFloat";
+ m_var =
+ m_expr = NULL;
+ name = "CBotFloat";
}
CBotFloat::~CBotFloat()
{
- delete m_var;
- delete m_expr;
-}
-
-CBotInstr* CBotFloat::Compile(CBotToken* &p, CBotCStack* pStack, BOOL cont, BOOL noskip)
-{
- CBotToken* pp = cont ? NULL : p;
-
- if (!cont && !IsOfType(p, ID_FLOAT)) return NULL;
-
- CBotFloat* inst = (CBotFloat*)CompileArray(p, pStack, CBotTypFloat);
- if ( inst != NULL || !pStack->IsOk() ) return inst;
-
- CBotCStack* pStk = pStack->TokenStack(pp);
-
- inst = new CBotFloat();
-
- inst->m_expr = NULL;
-
- CBotToken* vartoken = p;
- CBotVar* var = NULL;
- inst->SetToken(vartoken);
-
- if ( NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) )
- {
- ((CBotLeftExprVar*)inst->m_var)->m_typevar = CBotTypFloat;
- if (pStk->CheckVarLocal(vartoken)) // redéfinition de la variable
- {
- pStk->SetStartError(vartoken->GivStart());
- pStk->SetError(TX_REDEFVAR, vartoken->GivEnd());
- goto error;
- }
-
- if (IsOfType(p, ID_OPBRK)) // avec des indices ?
- {
- delete inst; // n'est pas de type CBotInt
- p = vartoken; // revient sur le nom de la variable
-
- // compile une déclaration de tableau
-
- inst = (CBotFloat*)CBotInstArray::Compile( p, pStk, CBotTypFloat );
-
- if (!pStk->IsOk() )
- {
- pStk->SetError(TX_CLBRK, p->GivStart());
- goto error;
- }
- goto suite; // pas d'assignation, variable déjà créée
- }
-
- if (IsOfType(p, ID_ASS)) // avec une assignation ?
- {
- if ( NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) )
- {
- goto error;
- }
- if ( pStk->GivType() >= CBotTypBoolean ) // type compatible ?
- {
- pStk->SetError(TX_BADTYPE, p->GivStart());
- goto error;
- }
- }
-
- var = CBotVar::Create(vartoken, CBotTypFloat); // crée la variable (après l'assignation évaluée)
- var->SetInit(inst->m_expr != NULL); // la marque initialisée si avec assignation
- var->SetUniqNum(
- ((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum());
- // lui attribut un numéro unique
- pStack->AddVar(var); // la place sur la pile
+ delete m_var;
+ delete m_expr;
+}
+
+CBotInstr* CBotFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip)
+{
+ CBotToken* pp = cont ? NULL : p;
+
+ if (!cont && !IsOfType(p, ID_FLOAT)) return NULL;
+
+ CBotFloat* inst = (CBotFloat*)CompileArray(p, pStack, CBotTypFloat);
+ if (inst != NULL || !pStack->IsOk()) return inst;
+
+ CBotCStack* pStk = pStack->TokenStack(pp);
+
+ inst = new CBotFloat();
+
+ inst->m_expr = NULL;
+
+ CBotToken* vartoken = p;
+ CBotVar* var = NULL;
+ inst->SetToken(vartoken);
+
+ if (NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )))
+ {
+ ((CBotLeftExprVar*)inst->m_var)->m_typevar = CBotTypFloat;
+ if (pStk->CheckVarLocal(vartoken)) // redefinition of a variable
+ {
+ pStk->SetStartError(vartoken->GivStart());
+ pStk->SetError(TX_REDEFVAR, vartoken->GivEnd());
+ goto error;
+ }
+
+ if (IsOfType(p, ID_OPBRK))
+ {
+ delete inst;
+ p = vartoken;
+ inst = (CBotFloat*)CBotInstArray::Compile(p, pStk, CBotTypFloat);
+
+ if (!pStk->IsOk() )
+ {
+ pStk->SetError(TX_CLBRK, p->GivStart());
+ goto error;
+ }
+ goto suite; // no assignment, variable already created
+ }
+
+ if (IsOfType(p, ID_ASS))
+ {
+ if (NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
+ {
+ goto error;
+ }
+ if (pStk->GivType() >= CBotTypBoolean)
+ {
+ pStk->SetError(TX_BADTYPE, p->GivStart());
+ goto error;
+ }
+ }
+
+ var = CBotVar::Create(vartoken, CBotTypFloat);
+ var->SetInit(inst->m_expr != NULL);
+ var->SetUniqNum(
+ ((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum());
+ pStack->AddVar(var);
suite:
- if (IsOfType(p, ID_COMMA)) // plusieurs définitions enchaînées
- {
- if ( NULL != ( inst->m_next2b = CBotFloat::Compile(p, pStk, TRUE, noskip) )) // compile la suivante
- {
- return pStack->Return(inst, pStk);
- }
- }
-
- if (noskip || IsOfType(p, ID_SEP)) // instruction terminée
- {
- return pStack->Return(inst, pStk);
- }
-
- pStk->SetError(TX_ENDOF, p->GivStart());
- }
+ if (IsOfType(p, ID_COMMA))
+ {
+ if (NULL != ( inst->m_next2b = CBotFloat::Compile(p, pStk, true, noskip)))
+ {
+ return pStack->Return(inst, pStk);
+ }
+ }
+
+ if (noskip || IsOfType(p, ID_SEP))
+ {
+ return pStack->Return(inst, pStk);
+ }
+
+ pStk->SetError(TX_ENDOF, p->GivStart());
+ }
error:
- delete inst;
- return pStack->Return(NULL, pStk);
+ delete inst;
+ return pStack->Return(NULL, pStk);
}
-// exécute la défintion de la variable réelle
+// executes the definition of a real variable
-BOOL CBotFloat::Execute(CBotStack* &pj)
+bool CBotFloat::Execute(CBotStack* &pj)
{
- CBotStack* pile = pj->AddStack(this);//indispensable pour SetState()
-// if ( pile == EOX ) return TRUE;
+ CBotStack* pile = pj->AddStack(this);
- if ( pile->GivState()==0)
- {
- if (m_expr && !m_expr->Execute(pile)) return FALSE; // valeur initiale // interrompu?
- m_var->Execute( pile ); // crée et fait l'assigation du résultat
+ if ( pile->GivState()==0)
+ {
+ if (m_expr && !m_expr->Execute(pile)) return false;
+ m_var->Execute(pile);
- if (!pile->SetState(1)) return FALSE;
- }
+ if (!pile->SetState(1)) return false;
+ }
- if ( pile->IfStep() ) return FALSE;
+ if (pile->IfStep()) return false;
- if ( m_next2b &&
- !m_next2b->Execute(pile)) return FALSE; // autre(s) définition(s)
+ if ( m_next2b &&
+ !m_next2b->Execute(pile)) return false;
- return pj->Return( pile ); // transmet en dessous
+ return pj->Return(pile);
}
-void CBotFloat::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotFloat::RestoreState(CBotStack* &pj, bool bMain)
{
- CBotStack* pile = pj;
- if ( bMain )
- {
- pile = pj->RestoreStack(this);
- if ( pile == NULL ) return;
+ CBotStack* pile = pj;
+ if (bMain)
+ {
+ pile = pj->RestoreStack(this);
+ if (pile == NULL) return;
- if ( pile->GivState()==0)
- {
- if (m_expr) m_expr->RestoreState(pile, bMain); // valeur initiale interrompu?
- return;
- }
- }
+ if ( pile->GivState()==0)
+ {
+ if (m_expr) m_expr->RestoreState(pile, bMain);
+ return;
+ }
+ }
- m_var->RestoreState( pile, bMain ); //
+ m_var->RestoreState(pile, bMain);
- if ( m_next2b )
- m_next2b->RestoreState(pile, bMain); // autre(s) définition(s)
+ if (m_next2b)
+ m_next2b->RestoreState(pile, bMain);
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// définition d'une variable chaîne de caractères
+// define a string variable
// int a, b = "salut";
CBotIString::CBotIString()
{
- m_var =
- m_expr = NULL;
- name = "CBotIString";
+ m_var =
+ m_expr = NULL;
+ name = "CBotIString";
}
CBotIString::~CBotIString()
{
- delete m_var;
- delete m_expr;
-}
-
-CBotInstr* CBotIString::Compile(CBotToken* &p, CBotCStack* pStack, BOOL cont, BOOL noskip)
-{
- CBotToken* pp = cont ? NULL : p;
-
- if (!cont && !IsOfType(p, ID_STRING)) return NULL;
-
- CBotIString* inst = (CBotIString*)CompileArray(p, pStack, CBotTypString);
- if ( inst != NULL || !pStack->IsOk() ) return inst;
-
- CBotCStack* pStk = pStack->TokenStack(pp);
-
- inst = new CBotIString();
-
- inst->m_expr = NULL;
-
- CBotToken* vartoken = p;
- inst->SetToken( vartoken );
-
- if ( NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) )
- {
- ((CBotLeftExprVar*)inst->m_var)->m_typevar = CBotTypString;
- if (pStk->CheckVarLocal(vartoken)) // redéfinition de la variable
- {
- pStk->SetStartError(vartoken->GivStart());
- pStk->SetError(TX_REDEFVAR, vartoken->GivEnd());
- goto error;
- }
-
- if (IsOfType(p, ID_ASS)) // avec une assignation ?
- {
- if ( NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) )
- {
- goto error;
- }
-/* if ( !pStk->GivTypResult().Eq(CBotTypString) ) // type compatible ?
- {
- pStk->SetError(TX_BADTYPE, p->GivStart());
- goto error;
- }*/
- }
-
- CBotVar* var = CBotVar::Create(vartoken, CBotTypString); // crée la variable (après l'assignation évaluée)
- var->SetInit(inst->m_expr != NULL); // la marque initialisée si avec assignation
- var->SetUniqNum(
- ((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum());
- // lui attribut un numéro unique
- pStack->AddVar(var); // la place sur la pile
-
- if (IsOfType(p, ID_COMMA)) // plusieurs définitions enchaînées
- {
- if ( NULL != ( inst->m_next2b = CBotIString::Compile(p, pStk, TRUE, noskip) )) // compile la suivante
- {
- return pStack->Return(inst, pStk);
- }
- }
-
- if (noskip || IsOfType(p, ID_SEP)) // instruction terminée
- {
- return pStack->Return(inst, pStk);
- }
-
- pStk->SetError(TX_ENDOF, p->GivStart());
- }
+ delete m_var;
+ delete m_expr;
+}
+
+CBotInstr* CBotIString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip)
+{
+ CBotToken* pp = cont ? NULL : p;
+
+ if (!cont && !IsOfType(p, ID_STRING)) return NULL;
+
+ CBotIString* inst = (CBotIString*)CompileArray(p, pStack, CBotTypString);
+ if (inst != NULL || !pStack->IsOk()) return inst;
+
+ CBotCStack* pStk = pStack->TokenStack(pp);
+
+ inst = new CBotIString();
+
+ inst->m_expr = NULL;
+
+ CBotToken* vartoken = p;
+ inst->SetToken(vartoken);
+
+ if (NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )))
+ {
+ ((CBotLeftExprVar*)inst->m_var)->m_typevar = CBotTypString;
+ if (pStk->CheckVarLocal(vartoken))
+ {
+ pStk->SetStartError(vartoken->GivStart());
+ pStk->SetError(TX_REDEFVAR, vartoken->GivEnd());
+ goto error;
+ }
+
+ if (IsOfType(p, ID_ASS))
+ {
+ if (NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
+ {
+ goto error;
+ }
+/* if (!pStk->GivTypResult().Eq(CBotTypString)) // type compatible ?
+ {
+ pStk->SetError(TX_BADTYPE, p->GivStart());
+ goto error;
+ }*/
+ }
+
+ CBotVar* var = CBotVar::Create(vartoken, CBotTypString);
+ var->SetInit(inst->m_expr != NULL);
+ var->SetUniqNum(
+ ((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum());
+ pStack->AddVar(var);
+
+ if (IsOfType(p, ID_COMMA))
+ {
+ if (NULL != ( inst->m_next2b = CBotIString::Compile(p, pStk, true, noskip)))
+ {
+ return pStack->Return(inst, pStk);
+ }
+ }
+
+ if (noskip || IsOfType(p, ID_SEP))
+ {
+ return pStack->Return(inst, pStk);
+ }
+
+ pStk->SetError(TX_ENDOF, p->GivStart());
+ }
error:
- delete inst;
- return pStack->Return(NULL, pStk);
+ delete inst;
+ return pStack->Return(NULL, pStk);
}
-// exécute la définition de la variable string
+// executes the definition of the string variable
-BOOL CBotIString::Execute(CBotStack* &pj)
+bool CBotIString::Execute(CBotStack* &pj)
{
- CBotStack* pile = pj->AddStack(this);//indispensable pour SetState()
-// if ( pile == EOX ) return TRUE;
+ CBotStack* pile = pj->AddStack(this);
- if ( pile->GivState()==0)
- {
- if (m_expr && !m_expr->Execute(pile)) return FALSE; // valeur initiale // interrompu?
- m_var->Execute( pile ); // crée et fait l'assigation du résultat
+ if ( pile->GivState()==0)
+ {
+ if (m_expr && !m_expr->Execute(pile)) return false;
+ m_var->Execute(pile);
- if (!pile->SetState(1)) return FALSE;
- }
+ if (!pile->SetState(1)) return false;
+ }
- if ( pile->IfStep() ) return FALSE;
+ if (pile->IfStep()) return false;
- if ( m_next2b &&
- !m_next2b->Execute(pile)) return FALSE; // autre(s) définition(s)
+ if ( m_next2b &&
+ !m_next2b->Execute(pile)) return false;
- return pj->Return( pile ); // transmet en dessous
+ return pj->Return(pile);
}
-void CBotIString::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotIString::RestoreState(CBotStack* &pj, bool bMain)
{
- CBotStack* pile = pj;
-
- if ( bMain )
- {
- pile = pj->RestoreStack(this);
- if ( pile == NULL ) return;
+ CBotStack* pile = pj;
+
+ if (bMain)
+ {
+ pile = pj->RestoreStack(this);
+ if (pile == NULL) return;
- if ( pile->GivState()==0)
- {
- if (m_expr) m_expr->RestoreState(pile, bMain); // valeur initiale interrompu?
- return;
- }
- }
+ if ( pile->GivState()==0)
+ {
+ if (m_expr) m_expr->RestoreState(pile, bMain);
+ return;
+ }
+ }
- m_var->RestoreState( pile, bMain ); //
+ m_var->RestoreState(pile, bMain);
- if ( m_next2b )
- m_next2b->RestoreState(pile, bMain); // autre(s) définition(s)
+ if (m_next2b)
+ m_next2b->RestoreState(pile, bMain);
}
//////////////////////////////////////////////////////////////////////////////////////////
@@ -1558,840 +1532,830 @@ void CBotIString::RestoreState(CBotStack* &pj, BOOL bMain)
//////////////////////////////////////////////////////////////////////////////////////
-// compile une instruction de type " x = 123 " ou " z * 5 + 4 "
-// avec ou sans assignation donc
+// compiles a statement such as " x = 123 " ou " z * 5 + 4 "
+// with or without assignment
CBotExpression::CBotExpression()
{
- m_leftop = NULL;
- m_rightop = NULL;
- name = "CBotExpression";
+ m_leftop = NULL;
+ m_rightop = NULL;
+ name = "CBotExpression";
}
CBotExpression::~CBotExpression()
{
- delete m_leftop;
- delete m_rightop;
+ delete m_leftop;
+ delete m_rightop;
}
CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack)
{
- CBotToken* pp = p;
-
- CBotExpression* inst = new CBotExpression();
-
- inst->m_leftop = CBotLeftExpr::Compile(p, pStack);
-
- inst->SetToken(p);
- int OpType = p->GivType();
-
- if ( pStack->IsOk() &&
- IsOfTypeList(p, ID_ASS, ID_ASSADD, ID_ASSSUB, ID_ASSMUL, ID_ASSDIV, ID_ASSMODULO,
- ID_ASSAND, ID_ASSXOR, ID_ASSOR,
- ID_ASSSL , ID_ASSSR, ID_ASSASR, 0 ))
- {
- if ( inst->m_leftop == NULL )
- {
- pStack->SetError(TX_BADLEFT, p->GivEnd());
- delete inst;
- return NULL;
- }
-
- inst->m_rightop = CBotExpression::Compile(p, pStack);
- if (inst->m_rightop == NULL)
- {
- delete inst;
- return NULL;
- }
-
- CBotTypResult type1 = pStack->GivTypResult();
-
- // récupère la variable pour la marquer assignée
- CBotVar* var = NULL;
- inst->m_leftop->ExecuteVar(var, pStack);
- if ( var == NULL )
- {
- delete inst;
- return NULL;
- }
-
- if (OpType != ID_ASS && var->GivInit() != IS_DEF)
- {
- pStack->SetError(TX_NOTINIT, pp);
- delete inst;
- return NULL;
- }
-
- CBotTypResult type2 = var->GivTypResult();
-
- // quels sont les types acceptables ?
- switch (OpType)
- {
- case ID_ASS:
- // if (type2 == CBotTypClass) type2 = -1; // pas de classe
- if ( (type1.Eq(CBotTypPointer) && type2.Eq(CBotTypPointer) ) ||
- (type1.Eq(CBotTypClass) && type2.Eq(CBotTypClass) ) )
- {
-/* CBotClass* c1 = type1.GivClass();
- CBotClass* c2 = type2.GivClass();
- if ( !c1->IsChildOf(c2) ) type2.SetType(-1); // pas la même classe
-//- if ( !type1.Eq(CBotTypClass) ) var->SetPointer(pStack->GivVar()->GivPointer());*/
- var->SetInit(2);
- }
- else
- var->SetInit(TRUE);
-
- break;
- case ID_ASSADD:
- if (type2.Eq(CBotTypBoolean) ||
- type2.Eq(CBotTypPointer) ) type2 = -1; // nombres et chaines
- break;
- case ID_ASSSUB:
- case ID_ASSMUL:
- case ID_ASSDIV:
- case ID_ASSMODULO:
- if (type2.GivType() >= CBotTypBoolean) type2 = -1; // nombres uniquement
- break;
- }
-
- if (!TypeCompatible( type1, type2, OpType ))
- {
- pStack->SetError(TX_BADTYPE, &inst->m_token);
- delete inst;
- return NULL;
- }
-
- return inst; // types compatibles ?
- }
-
- delete inst;
-// p = p->GivNext();
- int start, end, error = pStack->GivError(start, end);
-
- p = pp; // revient au début
- pStack->SetError(0,0); // oublie l'erreur
-
-// return CBotTwoOpExpr::Compile(p, pStack); // essaie sans assignation
- CBotInstr* i = CBotTwoOpExpr::Compile(p, pStack); // essaie sans assignation
- if ( i != NULL && error == TX_PRIVATE && p->GivType() == ID_ASS )
- pStack->ResetError( error, start, end );
- return i;
-}
-
-// exécute une expression avec assignation
-
-BOOL CBotExpression::Execute(CBotStack* &pj)
-{
- CBotStack* pile = pj->AddStack(this);
-// if ( pile == EOX ) return TRUE;
-
- CBotToken* pToken = m_leftop->GivToken();
- CBotVar* pVar = NULL;
-
- CBotStack* pile1 = pile;
-
- BOOL IsInit = TRUE;
- CBotVar* result = NULL;
-
- // doit être fait avant pour les indices éventuels (pile peut être changée)
- if ( !m_leftop->ExecuteVar(pVar, pile, NULL, FALSE) ) return FALSE; // variable avant évaluation de la valeur droite
-
-// DEBUG( "CBotExpression::Execute", -1, pj);
- if ( pile1->GivState()==0)
- {
- pile1->SetCopyVar(pVar); // garde une copie sur la pile (si interrompu)
- pile1->IncState();
- }
-
- CBotStack* pile2 = pile->AddStack(); // attention pile et surtout pas pile1
-
- if ( pile2->GivState()==0)
- {
-// DEBUG( "CBotExpression::Execute", -2, pj);
- if (m_rightop && !m_rightop->Execute(pile2)) return FALSE; // valeur initiale // interrompu?
- pile2->IncState();
- }
-
- if ( pile1->GivState() == 1 )
- {
-// DEBUG( "CBotExpression::Execute", -3, pj);
- if ( m_token.GivType() != ID_ASS )
- {
- pVar = pile1->GivVar(); // récupére si interrompu
- IsInit = pVar->GivInit();
- if ( IsInit == IS_NAN )
- {
- pile2->SetError(TX_OPNAN, m_leftop->GivToken());
- return pj->Return(pile2);
- }
- result = CBotVar::Create("", pVar->GivTypResult(2));
- }
-
- switch ( m_token.GivType() )
- {
- case ID_ASS:
- break;
- case ID_ASSADD:
- result->Add(pile1->GivVar(), pile2->GivVar()); // additionne
- pile2->SetVar(result); // re-place le résultat
- break;
- case ID_ASSSUB:
- result->Sub(pile1->GivVar(), pile2->GivVar()); // soustrait
- pile2->SetVar(result); // re-place le résultat
- break;
- case ID_ASSMUL:
- result->Mul(pile1->GivVar(), pile2->GivVar()); // multiplie
- pile2->SetVar(result); // re-place le résultat
- break;
- case ID_ASSDIV:
- if (IsInit &&
- result->Div(pile1->GivVar(), pile2->GivVar())) // divise
- pile2->SetError(TX_DIVZERO, &m_token);
- pile2->SetVar(result); // re-place le résultat
- break;
- case ID_ASSMODULO:
- if (IsInit &&
- result->Modulo(pile1->GivVar(), pile2->GivVar())) // reste de la division
- pile2->SetError(TX_DIVZERO, &m_token);
- pile2->SetVar(result); // re-place le résultat
- break;
- case ID_ASSAND:
- result->And(pile1->GivVar(), pile2->GivVar()); // multiplie
- pile2->SetVar(result); // re-place le résultat
- break;
- case ID_ASSXOR:
- result->XOr(pile1->GivVar(), pile2->GivVar());
- pile2->SetVar(result); // re-place le résultat
- break;
- case ID_ASSOR:
- result->Or(pile1->GivVar(), pile2->GivVar());
- pile2->SetVar(result); // re-place le résultat
- break;
- case ID_ASSSL:
- result->SL(pile1->GivVar(), pile2->GivVar());
- pile2->SetVar(result); // re-place le résultat
- break;
- case ID_ASSSR:
- result->SR(pile1->GivVar(), pile2->GivVar());
- pile2->SetVar(result); // re-place le résultat
- break;
- case ID_ASSASR:
- result->ASR(pile1->GivVar(), pile2->GivVar());
- pile2->SetVar(result); // re-place le résultat
- break;
- default:
- ASM_TRAP();
- }
- if (!IsInit)
- pile2->SetError(TX_NOTINIT, m_leftop->GivToken());
-
- pile1->IncState();
- }
-
-// DEBUG( "CBotExpression::Execute", -4, pj);
- if ( !m_leftop->Execute( pile2, pile1 ) )
- return FALSE; // crée et fait l'assigation du résultat
-
- return pj->Return( pile2 ); // transmet en dessous
-}
-
-
-void CBotExpression::RestoreState(CBotStack* &pj, BOOL bMain)
-{
- if ( bMain )
- {
- CBotToken* pToken = m_leftop->GivToken();
- CBotVar* pVar = NULL;
-
- CBotStack* pile = pj->RestoreStack(this);
- if ( pile == NULL ) return;
-
- CBotStack* pile1 = pile;
-
-
- if ( pile1->GivState()==0)
- {
- m_leftop->RestoreStateVar(pile, TRUE); // variable avant évaluation de la valeur droite
- return;
- }
-
- m_leftop->RestoreStateVar(pile, FALSE); // variable avant évaluation de la valeur droite
-
- CBotStack* pile2 = pile->RestoreStack(); // attention pile et surtout pas pile1
- if ( pile2 == NULL ) return;
-
- if ( pile2->GivState()==0)
- {
- if (m_rightop) m_rightop->RestoreState(pile2, bMain); // valeur initiale // interrompu?
- return;
- }
- }
+ CBotToken* pp = p;
+
+ CBotExpression* inst = new CBotExpression();
+
+ inst->m_leftop = CBotLeftExpr::Compile(p, pStack);
+
+ inst->SetToken(p);
+ int OpType = p->GivType();
+
+ if ( pStack->IsOk() &&
+ IsOfTypeList(p, ID_ASS, ID_ASSADD, ID_ASSSUB, ID_ASSMUL, ID_ASSDIV, ID_ASSMODULO,
+ ID_ASSAND, ID_ASSXOR, ID_ASSOR,
+ ID_ASSSL , ID_ASSSR, ID_ASSASR, 0 ))
+ {
+ if (inst->m_leftop == NULL)
+ {
+ pStack->SetError(TX_BADLEFT, p->GivEnd());
+ delete inst;
+ return NULL;
+ }
+
+ inst->m_rightop = CBotExpression::Compile(p, pStack);
+ if (inst->m_rightop == NULL)
+ {
+ delete inst;
+ return NULL;
+ }
+
+ CBotTypResult type1 = pStack->GivTypResult();
+
+ // get the variable assigned to mark
+ CBotVar* var = NULL;
+ inst->m_leftop->ExecuteVar(var, pStack);
+ if (var == NULL)
+ {
+ delete inst;
+ return NULL;
+ }
+
+ if (OpType != ID_ASS && var->GivInit() != IS_DEF)
+ {
+ pStack->SetError(TX_NOTINIT, pp);
+ delete inst;
+ return NULL;
+ }
+
+ CBotTypResult type2 = var->GivTypResult();
+
+ // what types are acceptable?
+ switch (OpType)
+ {
+ case ID_ASS:
+ // if (type2 == CBotTypClass) type2 = -1;
+ if ((type1.Eq(CBotTypPointer) && type2.Eq(CBotTypPointer)) ||
+ (type1.Eq(CBotTypClass) && type2.Eq(CBotTypClass) ) )
+ {
+/* CBotClass* c1 = type1.GivClass();
+ CBotClass* c2 = type2.GivClass();
+ if (!c1->IsChildOf(c2)) type2.SetType(-1);
+//- if (!type1.Eq(CBotTypClass)) var->SetPointer(pStack->GivVar()->GivPointer());*/
+ var->SetInit(2);
+ }
+ else
+ var->SetInit(true);
+
+ break;
+ case ID_ASSADD:
+ if (type2.Eq(CBotTypBoolean) ||
+ type2.Eq(CBotTypPointer) ) type2 = -1; // numbers and strings
+ break;
+ case ID_ASSSUB:
+ case ID_ASSMUL:
+ case ID_ASSDIV:
+ case ID_ASSMODULO:
+ if (type2.GivType() >= CBotTypBoolean) type2 = -1; // numbers only
+ break;
+ }
+
+ if (!TypeCompatible(type1, type2, OpType))
+ {
+ pStack->SetError(TX_BADTYPE, &inst->m_token);
+ delete inst;
+ return NULL;
+ }
+
+ return inst; // compatible type?
+ }
+
+ delete inst;
+ int start, end, error = pStack->GivError(start, end);
+
+ p = pp; // returns to the top
+ pStack->SetError(0,0); // forget the error
+
+ CBotInstr* i = CBotTwoOpExpr::Compile(p, pStack); // tries without assignment
+ if (i != NULL && error == TX_PRIVATE && p->GivType() == ID_ASS)
+ pStack->ResetError(error, start, end);
+ return i;
+}
+
+// executes an expression with assignment
+
+bool CBotExpression::Execute(CBotStack* &pj)
+{
+ CBotStack* pile = pj->AddStack(this);
+
+ CBotToken* pToken = m_leftop->GivToken();
+ CBotVar* pVar = NULL;
+
+ CBotStack* pile1 = pile;
+
+ bool IsInit = true;
+ CBotVar* result = NULL;
+
+ // must be done before any indexes (stack can be changed)
+ if (!m_leftop->ExecuteVar(pVar, pile, NULL, false)) return false; // variable before accessing the value on the right
+
+ if ( pile1->GivState()==0)
+ {
+ pile1->SetCopyVar(pVar); // keeps the copy on the stack (if interrupted)
+ pile1->IncState();
+ }
+
+ CBotStack* pile2 = pile->AddStack();
+
+ if ( pile2->GivState()==0)
+ {
+ if (m_rightop && !m_rightop->Execute(pile2)) return false; // initial value // interrupted?
+ pile2->IncState();
+ }
+
+ if (pile1->GivState() == 1)
+ {
+ if (m_token.GivType() != ID_ASS)
+ {
+ pVar = pile1->GivVar(); // recovers if interrupted
+ IsInit = pVar->GivInit();
+ if (IsInit == IS_NAN)
+ {
+ pile2->SetError(TX_OPNAN, m_leftop->GivToken());
+ return pj->Return(pile2);
+ }
+ result = CBotVar::Create("", pVar->GivTypResult(2));
+ }
+
+ switch (m_token.GivType())
+ {
+ case ID_ASS:
+ break;
+ case ID_ASSADD:
+ result->Add(pile1->GivVar(), pile2->GivVar());
+ pile2->SetVar(result);
+ break;
+ case ID_ASSSUB:
+ result->Sub(pile1->GivVar(), pile2->GivVar());
+ pile2->SetVar(result);
+ break;
+ case ID_ASSMUL:
+ result->Mul(pile1->GivVar(), pile2->GivVar());
+ pile2->SetVar(result);
+ break;
+ case ID_ASSDIV:
+ if (IsInit &&
+ result->Div(pile1->GivVar(), pile2->GivVar()))
+ pile2->SetError(TX_DIVZERO, &m_token);
+ pile2->SetVar(result);
+ break;
+ case ID_ASSMODULO:
+ if (IsInit &&
+ result->Modulo(pile1->GivVar(), pile2->GivVar()))
+ pile2->SetError(TX_DIVZERO, &m_token);
+ pile2->SetVar(result);
+ break;
+ case ID_ASSAND:
+ result->And(pile1->GivVar(), pile2->GivVar());
+ pile2->SetVar(result);
+ break;
+ case ID_ASSXOR:
+ result->XOr(pile1->GivVar(), pile2->GivVar());
+ pile2->SetVar(result);
+ break;
+ case ID_ASSOR:
+ result->Or(pile1->GivVar(), pile2->GivVar());
+ pile2->SetVar(result);
+ break;
+ case ID_ASSSL:
+ result->SL(pile1->GivVar(), pile2->GivVar());
+ pile2->SetVar(result);
+ break;
+ case ID_ASSSR:
+ result->SR(pile1->GivVar(), pile2->GivVar());
+ pile2->SetVar(result);
+ break;
+ case ID_ASSASR:
+ result->ASR(pile1->GivVar(), pile2->GivVar());
+ pile2->SetVar(result);
+ break;
+ default:
+ ASM_TRAP();
+ }
+ if (!IsInit)
+ pile2->SetError(TX_NOTINIT, m_leftop->GivToken());
+
+ pile1->IncState();
+ }
+
+ if (!m_leftop->Execute( pile2, pile1 ))
+ return false;
+
+ return pj->Return(pile2);
+}
+
+
+void CBotExpression::RestoreState(CBotStack* &pj, bool bMain)
+{
+ if (bMain)
+ {
+ CBotToken* pToken = m_leftop->GivToken();
+ CBotVar* pVar = NULL;
+
+ CBotStack* pile = pj->RestoreStack(this);
+ if (pile == NULL) return;
+
+ CBotStack* pile1 = pile;
+
+ if ( pile1->GivState()==0)
+ {
+ m_leftop->RestoreStateVar(pile, true);
+ return;
+ }
+
+ m_leftop->RestoreStateVar(pile, false);
+
+ CBotStack* pile2 = pile->RestoreStack();
+ if (pile2 == NULL) return;
+
+ if ( pile2->GivState()==0)
+ {
+ if (m_rightop) m_rightop->RestoreState(pile2, bMain);
+ return;
+ }
+ }
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// compile une instruction de type " ( condition ) "
-// la condition doit être de type booléen
+// compile a statement such as "(condition)"
+// the condition must be Boolean
+
+// this class has no constructor, because there is never an instance of this class
+// the object returned by Compile is usually type CBotExpression
-// cette classe n'a pas de constructeur, car il n'y a jamais d'instance de cette classe
-// l'objet retourné par Compile est généralement de type CBotExpression
CBotInstr* CBotCondition::Compile(CBotToken* &p, CBotCStack* pStack)
{
- pStack->SetStartError(p->GivStart());
- if ( IsOfType(p, ID_OPENPAR ))
- {
- CBotInstr* inst = CBotBoolExpr::Compile( p, pStack );
- if ( NULL != inst )
- {
- if ( IsOfType(p, ID_CLOSEPAR ))
- {
- return inst;
- }
- pStack->SetError(TX_CLOSEPAR, p->GivStart()); // manque la parenthèse
- }
- delete inst;
- }
+ pStack->SetStartError(p->GivStart());
+ if (IsOfType(p, ID_OPENPAR))
+ {
+ CBotInstr* inst = CBotBoolExpr::Compile(p, pStack);
+ if (NULL != inst)
+ {
+ if (IsOfType(p, ID_CLOSEPAR))
+ {
+ return inst;
+ }
+ pStack->SetError(TX_CLOSEPAR, p->GivStart()); // missing parenthesis
+ }
+ delete inst;
+ }
- pStack->SetError(TX_OPENPAR, p->GivStart()); // manque la parenthèse
+ pStack->SetError(TX_OPENPAR, p->GivStart()); // missing parenthesis
- return NULL;
+ return NULL;
}
//////////////////////////////////////////////////////////////////////////////////////
-// compile une instruction de type " condition "
-// la condition doit être de type booléen
-
-// cette classe n'a pas de constructeur, car il n'y a jamais d'instance de cette classe
-// l'objet retourné par Compile est généralement de type CBotExpression
+// compile a statement such as "(condition)"
+// the condition must be Boolean
+//
+// this class has no constructor, because there is never an instance of this
+// class
+// the object returned by Compile is usually type CBotExpression
+//
CBotInstr* CBotBoolExpr::Compile(CBotToken* &p, CBotCStack* pStack)
{
- pStack->SetStartError(p->GivStart());
+ pStack->SetStartError(p->GivStart());
- CBotInstr* inst = CBotTwoOpExpr::Compile( p, pStack );
+ CBotInstr* inst = CBotTwoOpExpr::Compile(p, pStack);
- if ( NULL != inst )
- {
- if ( pStack->GivTypResult().Eq(CBotTypBoolean) )
- {
- return inst;
- }
- pStack->SetError(TX_NOTBOOL, p->GivStart()); // n'est pas un booléan
- }
+ if (NULL != inst)
+ {
+ if (pStack->GivTypResult().Eq(CBotTypBoolean))
+ {
+ return inst;
+ }
+ pStack->SetError(TX_NOTBOOL, p->GivStart()); // is not a boolean
+ }
- delete inst;
- return NULL;
+ delete inst;
+ return NULL;
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// compile soit :
-// une instruction entre parenthèses (...)
-// une expression unaire (négatif, not)
-// nom de variable
-// les variables prè et post incrémentées ou décrémentées
-// un nombre donné par DefineNum
-// une constante
-// un appel de procédure
-// l'instruction new
-
-// cette classe n'a pas de constructeur, car il n'y a jamais d'instance de cette classe
-// l'objet retourné par Compile est de la classe correspondant à l'instruction
+// compile either:
+// instruction in parentheses (...)
+// a unary expression (negative, not)
+// variable name
+// variables pre and post-incremented or decremented
+// a given number DefineNum
+// a constant
+// procedure call
+// new statement
+//
+// this class has no constructor, because there is never an instance of this class
+// the object returned by Compile is the class corresponding to the instruction
+
CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack)
{
- CBotCStack* pStk = pStack->TokenStack();
-
- pStk->SetStartError(p->GivStart());
-
- // est-ce une expression entre parenthèse ?
- if (IsOfType(p, ID_OPENPAR))
- {
- CBotInstr* inst = CBotExpression::Compile( p, pStk );
-
- if ( NULL != inst )
- {
- if (IsOfType(p, ID_CLOSEPAR))
- {
- return pStack->Return(inst, pStk);
- }
- pStk->SetError(TX_CLOSEPAR, p->GivStart());
- }
- delete inst;
- return pStack->Return(NULL, pStk);
- }
-
- // est-ce une opération unaire ?
- CBotInstr* inst = CBotExprUnaire::Compile(p, pStk);
- if (inst != NULL || !pStk->IsOk())
- return pStack->Return(inst, pStk);
-
- // est-ce un nom de variable ?
- if (p->GivType() == TokenTypVar)
- {
- // c'est peut-être un appel de méthode sans le "this." devant
- inst = CBotExprVar::CompileMethode(p, pStk);
- if ( inst != NULL ) return pStack->Return(inst, pStk);
-
-
- // est-ce un appel de procédure ?
- inst = CBotInstrCall::Compile(p, pStk);
- if ( inst != NULL || !pStk->IsOk() )
- return pStack->Return(inst, pStk);
-
-
- CBotToken* pvar = p;
- // non, c'est une variable "ordinaire"
- inst = CBotExprVar::Compile(p, pStk);
-
- CBotToken* pp = p;
- // post incrémenté ou décrémenté ?
- if (IsOfType(p, ID_INC, ID_DEC))
- {
- if ( pStk->GivType() >= CBotTypBoolean )
- {
- pStk->SetError(TX_BADTYPE, pp);
- delete inst;
- return pStack->Return(NULL, pStk);
- }
-
- // recompile la variable pour read-only
- delete inst;
- p = pvar;
- inst = CBotExprVar::Compile(p, pStk, PR_READ);
- p = p->GivNext();
-
- CBotPostIncExpr* i = new CBotPostIncExpr();
- i->SetToken(pp);
- i->m_Instr = inst; // instruction associée
- return pStack->Return(i, pStk);
- }
- return pStack->Return(inst, pStk);
- }
-
- // est-ce une variable préincrémentée ou prédécrémentée ?
- CBotToken* pp = p;
- if (IsOfType(p, ID_INC, ID_DEC))
- {
- CBotPreIncExpr* i = new CBotPreIncExpr();
- i->SetToken(pp);
-
- if (p->GivType() == TokenTypVar)
- {
- if (NULL != (i->m_Instr = CBotExprVar::Compile(p, pStk, PR_READ)))
- {
- if ( pStk->GivType() >= CBotTypBoolean )
- {
- pStk->SetError(TX_BADTYPE, pp);
- delete inst;
- return pStack->Return(NULL, pStk);
- }
- return pStack->Return(i, pStk);
- }
- delete i;
- return pStack->Return(NULL, pStk);
- }
- }
-
- // est-ce un nombre ou un DefineNum ?
- if (p->GivType() == TokenTypNum ||
- p->GivType() == TokenTypDef )
- {
- CBotInstr* inst = CBotExprNum::Compile( p, pStk );
- return pStack->Return(inst, pStk);
- }
-
- // est-ce une chaine ?
- if (p->GivType() == TokenTypString)
- {
- CBotInstr* inst = CBotExprAlpha::Compile(p, pStk);
- return pStack->Return(inst, pStk);
- }
-
- // est un élément "true" ou "false"
- if (p->GivType() == ID_TRUE ||
- p->GivType() == ID_FALSE )
- {
- CBotInstr* inst = CBotExprBool::Compile( p, pStk );
- return pStack->Return(inst, pStk);
- }
-
- // est un objet à créer avec new
- if (p->GivType() == ID_NEW)
- {
- CBotInstr* inst = CBotNew::Compile( p, pStk );
- return pStack->Return(inst, pStk);
- }
-
- // est un pointeur nul
- if (IsOfType( p, ID_NULL ))
- {
- CBotInstr* inst = new CBotExprNull ();
- inst->SetToken( pp );
- CBotVar* var = CBotVar::Create("", CBotTypNullPointer);
- pStk->SetVar(var);
- return pStack->Return(inst, pStk);
- }
-
- // est un nombre nan
- if (IsOfType( p, ID_NAN ))
- {
- CBotInstr* inst = new CBotExprNan ();
- inst->SetToken( pp );
- CBotVar* var = CBotVar::Create("", CBotTypInt);
- var->SetInit(IS_NAN);
- pStk->SetVar(var);
- return pStack->Return(inst, pStk);
- }
-
-
- return pStack->Return(NULL, pStk);
+ CBotCStack* pStk = pStack->TokenStack();
+
+ pStk->SetStartError(p->GivStart());
+
+ // is it an expression in parentheses?
+ if (IsOfType(p, ID_OPENPAR))
+ {
+ CBotInstr* inst = CBotExpression::Compile(p, pStk);
+
+ if (NULL != inst)
+ {
+ if (IsOfType(p, ID_CLOSEPAR))
+ {
+ return pStack->Return(inst, pStk);
+ }
+ pStk->SetError(TX_CLOSEPAR, p->GivStart());
+ }
+ delete inst;
+ return pStack->Return(NULL, pStk);
+ }
+
+ // is this a unary operation?
+ CBotInstr* inst = CBotExprUnaire::Compile(p, pStk);
+ if (inst != NULL || !pStk->IsOk())
+ return pStack->Return(inst, pStk);
+
+ // is it a variable name?
+ if (p->GivType() == TokenTypVar)
+ {
+ // this may be a method call without the "this." before
+ inst = CBotExprVar::CompileMethode(p, pStk);
+ if (inst != NULL) return pStack->Return(inst, pStk);
+
+
+ // is it a procedure call?
+ inst = CBotInstrCall::Compile(p, pStk);
+ if (inst != NULL || !pStk->IsOk())
+ return pStack->Return(inst, pStk);
+
+
+ CBotToken* pvar = p;
+ // no, it an "ordinaty" variable
+ inst = CBotExprVar::Compile(p, pStk);
+
+ CBotToken* pp = p;
+ // post incremented or decremented?
+ if (IsOfType(p, ID_INC, ID_DEC))
+ {
+ if (pStk->GivType() >= CBotTypBoolean)
+ {
+ pStk->SetError(TX_BADTYPE, pp);
+ delete inst;
+ return pStack->Return(NULL, pStk);
+ }
+
+ // recompile the variable for read-only
+ delete inst;
+ p = pvar;
+ inst = CBotExprVar::Compile(p, pStk, PR_READ);
+ p = p->GivNext();
+
+ CBotPostIncExpr* i = new CBotPostIncExpr();
+ i->SetToken(pp);
+ i->m_Instr = inst; // associated statement
+ return pStack->Return(i, pStk);
+ }
+ return pStack->Return(inst, pStk);
+ }
+
+ // pre increpemted or pre decremented?
+ CBotToken* pp = p;
+ if (IsOfType(p, ID_INC, ID_DEC))
+ {
+ CBotPreIncExpr* i = new CBotPreIncExpr();
+ i->SetToken(pp);
+
+ if (p->GivType() == TokenTypVar)
+ {
+ if (NULL != (i->m_Instr = CBotExprVar::Compile(p, pStk, PR_READ)))
+ {
+ if (pStk->GivType() >= CBotTypBoolean)
+ {
+ pStk->SetError(TX_BADTYPE, pp);
+ delete inst;
+ return pStack->Return(NULL, pStk);
+ }
+ return pStack->Return(i, pStk);
+ }
+ delete i;
+ return pStack->Return(NULL, pStk);
+ }
+ }
+
+ // is it a number or DefineNum?
+ if (p->GivType() == TokenTypNum ||
+ p->GivType() == TokenTypDef )
+ {
+ CBotInstr* inst = CBotExprNum::Compile(p, pStk);
+ return pStack->Return(inst, pStk);
+ }
+
+ // is this a chaine?
+ if (p->GivType() == TokenTypString)
+ {
+ CBotInstr* inst = CBotExprAlpha::Compile(p, pStk);
+ return pStack->Return(inst, pStk);
+ }
+
+ // is a "true" or "false"
+ if (p->GivType() == ID_TRUE ||
+ p->GivType() == ID_FALSE )
+ {
+ CBotInstr* inst = CBotExprBool::Compile(p, pStk);
+ return pStack->Return(inst, pStk);
+ }
+
+ // is an object to be created with new
+ if (p->GivType() == ID_NEW)
+ {
+ CBotInstr* inst = CBotNew::Compile(p, pStk);
+ return pStack->Return(inst, pStk);
+ }
+
+ // is a null pointer
+ if (IsOfType(p, ID_NULL))
+ {
+ CBotInstr* inst = new CBotExprNull ();
+ inst->SetToken(pp);
+ CBotVar* var = CBotVar::Create("", CBotTypNullPointer);
+ pStk->SetVar(var);
+ return pStack->Return(inst, pStk);
+ }
+
+ // is a number nan
+ if (IsOfType(p, ID_NAN))
+ {
+ CBotInstr* inst = new CBotExprNan ();
+ inst->SetToken(pp);
+ CBotVar* var = CBotVar::Create("", CBotTypInt);
+ var->SetInit(IS_NAN);
+ pStk->SetVar(var);
+ return pStack->Return(inst, pStk);
+ }
+
+
+ return pStack->Return(NULL, pStk);
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// gestion du post et pré- incrément/décrément
+// Management of pre-and post increment / decrement
+// There is no routine Compiles, the object is created directly
+// Compiles in CBotParExpr ::
-// il n'y a pas de routine Compile, l'objet est créé directement
-// dans CBotParExpr::Compile
CBotPostIncExpr::CBotPostIncExpr()
{
- m_Instr = NULL;
- name = "CBotPostIncExpr";
+ m_Instr = NULL;
+ name = "CBotPostIncExpr";
}
CBotPostIncExpr::~CBotPostIncExpr()
{
- delete m_Instr;
+ delete m_Instr;
}
CBotPreIncExpr::CBotPreIncExpr()
{
- m_Instr = NULL;
- name = "CBotPreIncExpr";
+ m_Instr = NULL;
+ name = "CBotPreIncExpr";
}
CBotPreIncExpr::~CBotPreIncExpr()
{
- delete m_Instr;
+ delete m_Instr;
}
-BOOL CBotPostIncExpr::Execute(CBotStack* &pj)
+bool CBotPostIncExpr::Execute(CBotStack* &pj)
{
- CBotStack* pile1 = pj->AddStack(this);
- CBotStack* pile2 = pile1;
+ CBotStack* pile1 = pj->AddStack(this);
+ CBotStack* pile2 = pile1;
- CBotVar* var1 = NULL;
+ CBotVar* var1 = NULL;
- if ( !((CBotExprVar*)m_Instr)->ExecuteVar(var1, pile2, NULL, TRUE) ) return FALSE; // récupère la variable selon champs et index
+ // retrieves the variable fields and indexes according
+ if (!((CBotExprVar*)m_Instr)->ExecuteVar(var1, pile2, NULL, true)) return false;
- pile1->SetState(1);
- pile1->SetCopyVar(var1); // place le résultat (avant incrémentation);
+ pile1->SetState(1);
+ pile1->SetCopyVar(var1); // place le résultat (avant incrémentation);
- CBotStack* pile3 = pile2->AddStack(this);
- if ( pile3->IfStep() ) return FALSE;
+ CBotStack* pile3 = pile2->AddStack(this);
+ if (pile3->IfStep()) return false;
- if ( var1->GivInit() == IS_NAN )
- {
- pile1->SetError( TX_OPNAN, &m_token );
- }
+ if (var1->GivInit() == IS_NAN)
+ {
+ pile1->SetError(TX_OPNAN, &m_token);
+ }
- if ( var1->GivInit() != IS_DEF )
- {
- pile1->SetError( TX_NOTINIT, &m_token );
- }
+ if (var1->GivInit() != IS_DEF)
+ {
+ pile1->SetError(TX_NOTINIT, &m_token);
+ }
- if (GivTokenType() == ID_INC) var1->Inc();
- else var1->Dec();
+ if (GivTokenType() == ID_INC) var1->Inc();
+ else var1->Dec();
- return pj->Return(pile1); // opération faite, résultat sur pile2
+ return pj->Return(pile1); // operation done, result on pile2
}
-void CBotPostIncExpr::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotPostIncExpr::RestoreState(CBotStack* &pj, bool bMain)
{
- if ( !bMain ) return;
+ if (!bMain) return;
- CBotStack* pile1 = pj->RestoreStack(this);
- if ( pile1 == NULL ) return;
+ CBotStack* pile1 = pj->RestoreStack(this);
+ if (pile1 == NULL) return;
- ((CBotExprVar*)m_Instr)->RestoreStateVar(pile1, bMain);
+ ((CBotExprVar*)m_Instr)->RestoreStateVar(pile1, bMain);
- if ( pile1 != NULL ) pile1->RestoreStack(this);
+ if (pile1 != NULL) pile1->RestoreStack(this);
}
-BOOL CBotPreIncExpr::Execute(CBotStack* &pj)
+bool CBotPreIncExpr::Execute(CBotStack* &pj)
{
- CBotStack* pile = pj->AddStack(this);
-// if ( pile == EOX ) return TRUE;
+ CBotStack* pile = pj->AddStack(this);
- if ( pile->IfStep() ) return FALSE;
+ if (pile->IfStep()) return false;
- CBotVar* var1;
+ CBotVar* var1;
- if ( pile->GivState() == 0 )
- {
- CBotStack* pile2 = pile;
- if ( !((CBotExprVar*)m_Instr)->ExecuteVar(var1, pile2, NULL, TRUE) ) return FALSE; // récupère la variable selon champs et index
- // pile2 est modifié en retour
+ if (pile->GivState() == 0)
+ {
+ CBotStack* pile2 = pile;
+ // retrieves the variable fields and indexes according
+ // pile2 is modified on return
+ if (!((CBotExprVar*)m_Instr)->ExecuteVar(var1, pile2, NULL, true)) return false;
- if ( var1->GivInit() == IS_NAN )
- {
- pile->SetError( TX_OPNAN, &m_token );
- return pj->Return(pile); // opération faite
- }
+ if (var1->GivInit() == IS_NAN)
+ {
+ pile->SetError(TX_OPNAN, &m_token);
+ return pj->Return(pile); // operation performed
+ }
- if ( var1->GivInit() != IS_DEF )
- {
- pile->SetError( TX_NOTINIT, &m_token );
- return pj->Return(pile); // opération faite
- }
+ if (var1->GivInit() != IS_DEF)
+ {
+ pile->SetError(TX_NOTINIT, &m_token);
+ return pj->Return(pile); // operation performed
+ }
- if (GivTokenType() == ID_INC) var1->Inc();
- else var1->Dec(); // ((CBotVarInt*)var1)->m_val
+ if (GivTokenType() == ID_INC) var1->Inc();
+ else var1->Dec(); // ((CBotVarInt*)var1)->m_val
- pile->IncState();
- }
+ pile->IncState();
+ }
- if ( !m_Instr->Execute(pile) ) return FALSE;
- return pj->Return(pile); // opération faite
+ if (!m_Instr->Execute(pile)) return false;
+ return pj->Return(pile); // operation performed
}
-void CBotPreIncExpr::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotPreIncExpr::RestoreState(CBotStack* &pj, bool bMain)
{
- if ( !bMain ) return;
+ if (!bMain) return;
- CBotStack* pile = pj->RestoreStack(this);
- if ( pile == NULL ) return;
+ CBotStack* pile = pj->RestoreStack(this);
+ if (pile == NULL) return;
- if ( pile->GivState() == 0 )
- {
- return;
- }
+ if (pile->GivState() == 0)
+ {
+ return;
+ }
- m_Instr->RestoreState(pile, bMain);
+ m_Instr->RestoreState(pile, bMain);
}
//////////////////////////////////////////////////////////////////////////////////////
-// compile une expression unaire
-// +
-// -
-// not
-// !
-// ~
+// compile an unary expression
+// +
+// -
+// not
+// !
+// ~
CBotExprUnaire::CBotExprUnaire()
{
- m_Expr = NULL;
- name = "CBotExprUnaire";
+ m_Expr = NULL;
+ name = "CBotExprUnaire";
}
CBotExprUnaire::~CBotExprUnaire()
{
- delete m_Expr;
+ delete m_Expr;
}
CBotInstr* CBotExprUnaire::Compile(CBotToken* &p, CBotCStack* pStack)
{
- int op = p->GivType();
- CBotToken* pp = p;
- if ( !IsOfTypeList( p, ID_ADD, ID_SUB, ID_LOG_NOT, ID_TXT_NOT, ID_NOT, 0 ) ) return NULL;
+ int op = p->GivType();
+ CBotToken* pp = p;
+ if (!IsOfTypeList( p, ID_ADD, ID_SUB, ID_LOG_NOT, ID_TXT_NOT, ID_NOT, 0 )) return NULL;
- CBotCStack* pStk = pStack->TokenStack(pp);
+ CBotCStack* pStk = pStack->TokenStack(pp);
- CBotExprUnaire* inst = new CBotExprUnaire();
- inst->SetToken(pp);
+ CBotExprUnaire* inst = new CBotExprUnaire();
+ inst->SetToken(pp);
- if ( NULL != (inst->m_Expr = CBotParExpr::Compile( p, pStk )) )
- {
- if ( op == ID_ADD && pStk->GivType() < CBotTypBoolean ) // seulement avec des nombre
- return pStack->Return(inst, pStk);
- if ( op == ID_SUB && pStk->GivType() < CBotTypBoolean ) // seulement avec des nombre
- return pStack->Return(inst, pStk);
- if ( op == ID_NOT && pStk->GivType() < CBotTypFloat ) // seulement avec des entiers
- return pStack->Return(inst, pStk);
- if ( op == ID_LOG_NOT && pStk->GivTypResult().Eq(CBotTypBoolean) )// seulement avec des booléens
- return pStack->Return(inst, pStk);
- if ( op == ID_TXT_NOT && pStk->GivTypResult().Eq(CBotTypBoolean) )// seulement avec des booléens
- return pStack->Return(inst, pStk);
+ if (NULL != (inst->m_Expr = CBotParExpr::Compile( p, pStk )))
+ {
+ if (op == ID_ADD && pStk->GivType() < CBotTypBoolean) // only with the number
+ return pStack->Return(inst, pStk);
+ if (op == ID_SUB && pStk->GivType() < CBotTypBoolean) // only with the numer
+ return pStack->Return(inst, pStk);
+ if (op == ID_NOT && pStk->GivType() < CBotTypFloat) // only with an integer
+ return pStack->Return(inst, pStk);
+ if (op == ID_LOG_NOT && pStk->GivTypResult().Eq(CBotTypBoolean))// only with boolean
+ return pStack->Return(inst, pStk);
+ if (op == ID_TXT_NOT && pStk->GivTypResult().Eq(CBotTypBoolean))// only with boolean
+ return pStack->Return(inst, pStk);
- pStk->SetError(TX_BADTYPE, &inst->m_token);
- }
- delete inst;
- return pStack->Return(NULL, pStk);
+ pStk->SetError(TX_BADTYPE, &inst->m_token);
+ }
+ delete inst;
+ return pStack->Return(NULL, pStk);
}
-// exécute l'expresson unaire
+// executes unary expression
-BOOL CBotExprUnaire::Execute(CBotStack* &pj)
+bool CBotExprUnaire::Execute(CBotStack* &pj)
{
- CBotStack* pile = pj->AddStack(this);
-// if ( pile == EOX ) return TRUE;
+ CBotStack* pile = pj->AddStack(this);
- if ( pile->GivState() == 0 )
- {
- if (!m_Expr->Execute( pile )) return FALSE; // interrompu ?
- pile->IncState();
- }
+ if (pile->GivState() == 0)
+ {
+ if (!m_Expr->Execute(pile)) return false; // interrupted ?
+ pile->IncState();
+ }
- CBotStack* pile2 = pile->AddStack();
- if ( pile2->IfStep() ) return FALSE;
+ CBotStack* pile2 = pile->AddStack();
+ if (pile2->IfStep()) return false;
- CBotVar* var = pile->GivVar(); // récupère le résultat sur la pile
+ CBotVar* var = pile->GivVar(); // get the result on the stack
- switch (GivTokenType())
- {
- case ID_ADD:
- break; // ne fait donc rien
- case ID_SUB:
- var->Neg(); // change le signe
- break;
- case ID_NOT:
- case ID_LOG_NOT:
- case ID_TXT_NOT:
- var->Not();
- break;
- }
- return pj->Return(pile); // transmet en dessous
+ switch (GivTokenType())
+ {
+ case ID_ADD:
+ break;
+ case ID_SUB:
+ var->Neg(); // change the sign
+ break;
+ case ID_NOT:
+ case ID_LOG_NOT:
+ case ID_TXT_NOT:
+ var->Not();
+ break;
+ }
+ return pj->Return(pile); // forwards below
}
-void CBotExprUnaire::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotExprUnaire::RestoreState(CBotStack* &pj, bool bMain)
{
- if ( !bMain ) return;
+ if (!bMain) return;
- CBotStack* pile = pj->RestoreStack(this);
- if ( pile == NULL) return;
+ CBotStack* pile = pj->RestoreStack(this);
+ if ( pile == NULL) return;
- if ( pile->GivState() == 0 )
- {
- m_Expr->RestoreState( pile, bMain ); // interrompu ici !
- return;
- }
+ if (pile->GivState() == 0)
+ {
+ m_Expr->RestoreState(pile, bMain); // interrupted here!
+ return;
+ }
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// gestion des index pour les tableaux
+// index management for arrays
// array [ expression ]
CBotIndexExpr::CBotIndexExpr()
{
- m_expr = NULL;
- name = "CBotIndexExpr";
+ m_expr = NULL;
+ name = "CBotIndexExpr";
}
CBotIndexExpr::~CBotIndexExpr()
{
- delete m_expr;
+ delete m_expr;
}
-// trouve un champ à partir de l'instance à la compilation
+// finds a field from the instance at compile time
-BOOL CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
+bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
{
- if ( pVar->GivType(1) != CBotTypArrayPointer )
- ASM_TRAP();
+ if (pVar->GivType(1) != CBotTypArrayPointer)
+ ASM_TRAP();
- pVar = ((CBotVarArray*)pVar)->GivItem(0, FALSE); // à la compilation rend l'élément [0]
- if ( pVar == NULL )
- {
- pile->SetError(TX_OUTARRAY, m_token.GivEnd());
- return FALSE;
- }
- if ( m_next3 != NULL ) return m_next3->ExecuteVar(pVar, pile);
- return TRUE;
+ pVar = ((CBotVarArray*)pVar)->GivItem(0, false); // at compile time makes the element [0]
+ if (pVar == NULL)
+ {
+ pile->SetError(TX_OUTARRAY, m_token.GivEnd());
+ return false;
+ }
+ if (m_next3 != NULL) return m_next3->ExecuteVar(pVar, pile);
+ return true;
}
-// idem à l'exécution
-// attention, modifie le pointeur à la pile volontairement
-// place les index calculés sur la pile supplémentaire
+// attention, changes the pointer to the stack intentionally
+// place the index calculated on the additional stack
+
-BOOL CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, BOOL bStep, BOOL bExtend)
+bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend)
{
- CBotStack* pj = pile;
-// DEBUG( "CBotIndexExpr::ExecuteVar", -1 , pj);
+ CBotStack* pj = pile;
- if ( pVar->GivType(1) != CBotTypArrayPointer )
- ASM_TRAP();
+ if (pVar->GivType(1) != CBotTypArrayPointer)
+ ASM_TRAP();
- pile = pile->AddStack();
-// if ( pile == EOX ) return TRUE;
+ pile = pile->AddStack();
- if ( pile->GivState() == 0 )
- {
- if ( !m_expr->Execute(pile) ) return FALSE;
- pile->IncState();
- }
- // traite les tableaux
+ if (pile->GivState() == 0)
+ {
+ if (!m_expr->Execute(pile)) return false;
+ pile->IncState();
+ }
+ // handles array
- CBotVar* p = pile->GivVar(); // résultat sur la pile
+ CBotVar* p = pile->GivVar(); // result on the stack
- if ( p == NULL || p->GivType() > CBotTypDouble )
- {
- pile->SetError(TX_BADINDEX, prevToken);
- return pj->Return(pile);
- }
+ if (p == NULL || p->GivType() > CBotTypDouble)
+ {
+ pile->SetError(TX_BADINDEX, prevToken);
+ return pj->Return(pile);
+ }
- int n = p->GivValInt(); // position dans le tableau
-// DEBUG( "CBotIndexExpr::ExecuteVar", n , pj);
+ int n = p->GivValInt(); // position in the table
- pVar = ((CBotVarArray*)pVar)->GivItem(n, bExtend);
- if ( pVar == NULL )
- {
- pile->SetError(TX_OUTARRAY, prevToken);
- return pj->Return(pile);
- }
+ pVar = ((CBotVarArray*)pVar)->GivItem(n, bExtend);
+ if (pVar == NULL)
+ {
+ pile->SetError(TX_OUTARRAY, prevToken);
+ return pj->Return(pile);
+ }
-// DEBUG( "CBotIndexExpr::ExecuteVar", -2 , pj);
- //if ( bUpdate )
- pVar->Maj(pile->GivPUser(), TRUE);
+ pVar->Maj(pile->GivPUser(), true);
-// DEBUG( "CBotIndexExpr::ExecuteVar", -3 , pj);
- if ( m_next3 != NULL &&
- !m_next3->ExecuteVar(pVar, pile, prevToken, bStep, bExtend) ) return FALSE;
+ if ( m_next3 != NULL &&
+ !m_next3->ExecuteVar(pVar, pile, prevToken, bStep, bExtend) ) return false;
-// DEBUG( "CBotIndexExpr::ExecuteVar", -4 , pj);
- return TRUE; // ne libère pas la pile
- // pour éviter de recalculer les index deux fois le cas échéant
+ // does not release the stack
+ // to avoid recalculation of the index twice where appropriate
+ return true;
}
-void CBotIndexExpr::RestoreStateVar(CBotStack* &pile, BOOL bMain)
+void CBotIndexExpr::RestoreStateVar(CBotStack* &pile, bool bMain)
{
- pile = pile->RestoreStack();
- if ( pile == NULL ) return;
+ pile = pile->RestoreStack();
+ if (pile == NULL) return;
- if ( bMain && pile->GivState() == 0 )
- {
- m_expr->RestoreState(pile, TRUE);
- return;
- }
+ if (bMain && pile->GivState() == 0)
+ {
+ m_expr->RestoreState(pile, true);
+ return;
+ }
- if ( m_next3 )
- m_next3->RestoreStateVar(pile, bMain);
+ if (m_next3)
+ m_next3->RestoreStateVar(pile, bMain);
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// gestion des champs dans une instance (opérateur point)
+// field management in an instance (dot operator)
// toto.x
CBotFieldExpr::CBotFieldExpr()
{
- name = "CBotFieldExpr";
- m_nIdent = 0;
+ name = "CBotFieldExpr";
+ m_nIdent = 0;
}
CBotFieldExpr::~CBotFieldExpr()
@@ -2400,111 +2364,105 @@ CBotFieldExpr::~CBotFieldExpr()
void CBotFieldExpr::SetUniqNum(int num)
{
- m_nIdent = num;
+ m_nIdent = num;
}
-// trouve un champ à partir de l'instance à la compilation
+// find a field from the instance at compile
-BOOL CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
+bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
{
- if ( pVar->GivType(1) != CBotTypPointer )
- ASM_TRAP();
+ if (pVar->GivType(1) != CBotTypPointer)
+ ASM_TRAP();
-// pVar = pVar->GivItem(m_token.GivString());
- pVar = pVar->GivItemRef(m_nIdent);
- if ( pVar == NULL )
- {
- pile->SetError(TX_NOITEM, &m_token);
- return FALSE;
- }
+ pVar = pVar->GivItemRef(m_nIdent);
+ if (pVar == NULL)
+ {
+ pile->SetError(TX_NOITEM, &m_token);
+ return false;
+ }
- if ( m_next3 != NULL &&
- !m_next3->ExecuteVar(pVar, pile) ) return FALSE;
+ if ( m_next3 != NULL &&
+ !m_next3->ExecuteVar(pVar, pile) ) return false;
- return TRUE;
+ return true;
}
-// idem à l'exécution
-
-BOOL CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, BOOL bStep, BOOL bExtend)
+bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend)
{
- CBotStack* pj = pile;
- pile = pile->AddStack(this); // modifie pile en sortie
- if ( pile == EOX ) return TRUE;
+ CBotStack* pj = pile;
+ pile = pile->AddStack(this); // changes in output stack
+ if (pile == EOX) return true;
-// DEBUG( "CBotFieldExpre::ExecuteVar "+m_token.GivString(), 0, pj );
- if ( pVar->GivType(1) != CBotTypPointer )
- ASM_TRAP();
+ if (pVar->GivType(1) != CBotTypPointer)
+ ASM_TRAP();
- CBotVarClass* pItem = pVar->GivPointer();
- if ( pItem == NULL )
- {
- pile->SetError(TX_NULLPT, prevToken);
- return pj->Return( pile );
- }
- if ( pItem->GivUserPtr() == OBJECTDELETED )
- {
- pile->SetError(TX_DELETEDPT, prevToken);
- return pj->Return( pile );
- }
+ CBotVarClass* pItem = pVar->GivPointer();
+ if (pItem == NULL)
+ {
+ pile->SetError(TX_NULLPT, prevToken);
+ return pj->Return(pile);
+ }
+ if (pItem->GivUserPtr() == OBJECTDELETED)
+ {
+ pile->SetError(TX_DELETEDPT, prevToken);
+ return pj->Return(pile);
+ }
- if ( bStep && pile->IfStep() ) return FALSE;
+ if (bStep && pile->IfStep()) return false;
-// pVar = pVar->GivItem(m_token.GivString());
- pVar = pVar->GivItemRef(m_nIdent);
- if ( pVar == NULL )
- {
- pile->SetError(TX_NOITEM, &m_token);
- return pj->Return( pile );
- }
+ pVar = pVar->GivItemRef(m_nIdent);
+ if (pVar == NULL)
+ {
+ pile->SetError(TX_NOITEM, &m_token);
+ return pj->Return(pile);
+ }
- if ( pVar->IsStatic() )
- {
-// DEBUG( "IsStatic", 0, pj) ;
- // pour une variable statique, la prend dans la classe elle-même
- CBotClass* pClass = pItem->GivClass();
- pVar = pClass->GivItem(m_token.GivString());
-// DEBUG( "done "+pVar->GivName(), 0, pj) ;
- }
+ if (pVar->IsStatic())
+ {
+ // for a static variable, takes it in the class itself
+ CBotClass* pClass = pItem->GivClass();
+ pVar = pClass->GivItem(m_token.GivString());
+ }
- // demande la mise à jour de l'élément, s'il y a lieu
- pVar->Maj(pile->GivPUser(), TRUE);
+ // request the update of the element, if applicable
+ pVar->Maj(pile->GivPUser(), true);
- if ( m_next3 != NULL &&
- !m_next3->ExecuteVar(pVar, pile, &m_token, bStep, bExtend) ) return FALSE;
+ if ( m_next3 != NULL &&
+ !m_next3->ExecuteVar(pVar, pile, &m_token, bStep, bExtend) ) return false;
- return TRUE; // ne libère pas la pile
- // pour conserver l'état SetState() correspondant à l'étape
+ // does not release the stack
+ // to maintain the state SetState () corresponding to step
+
+ return true;
}
-void CBotFieldExpr::RestoreStateVar(CBotStack* &pj, BOOL bMain)
+void CBotFieldExpr::RestoreStateVar(CBotStack* &pj, bool bMain)
{
- pj = pj->RestoreStack(this); // modifie pj en sortie
- if ( pj == NULL ) return;
+ pj = pj->RestoreStack(this);
+ if (pj == NULL) return;
- if ( m_next3 != NULL )
- m_next3->RestoreStateVar(pj, bMain);
+ if (m_next3 != NULL)
+ m_next3->RestoreStateVar(pj, bMain);
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// compile un opérande gauche pour une assignation
-
+// compile a left operand for an assignment
CBotLeftExpr::CBotLeftExpr()
{
- name = "CBotLeftExpr";
- m_nIdent = 0;
+ name = "CBotLeftExpr";
+ m_nIdent = 0;
}
CBotLeftExpr::~CBotLeftExpr()
{
}
-// compile une expression pour un left-opérande ( à gauche d'une assignation)
-// cela peut être
+// compiles an expression for a left-operand (left of an assignment)
+// this can be
// toto
// toto[ 3 ]
// toto.x
@@ -2515,318 +2473,311 @@ CBotLeftExpr::~CBotLeftExpr()
CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack)
{
- CBotCStack* pStk = pStack->TokenStack();
-
- pStk->SetStartError(p->GivStart());
-
- // est-ce un nom de variable ?
- if (p->GivType() == TokenTypVar)
- {
- CBotLeftExpr* inst = new CBotLeftExpr(); // crée l'objet
-
- inst->SetToken(p);
-
- CBotVar* var;
-
- if ( NULL != (var = pStk->FindVar(p)) ) // cherche si variable connue
- {
- inst->m_nIdent = var->GivUniqNum();
- if (inst->m_nIdent > 0 && inst->m_nIdent < 9000)
- {
- if ( var->IsPrivate(PR_READ) &&
- !pStk->GivBotCall()->m_bCompileClass)
- {
- pStk->SetError( TX_PRIVATE, p );
- goto err;
- }
- // il s'agit d'un élement de la classe courante
- // ajoute l'équivalent d'un this. devant
- CBotToken pthis("this");
- inst->SetToken(&pthis);
- inst->m_nIdent = -2; // ident pour this
-
- CBotFieldExpr* i = new CBotFieldExpr(); // nouvel élément
- i->SetToken( p ); // garde le nom du token
- inst->AddNext3(i); // ajoute à la suite
-
- var = pStk->FindVar(pthis);
- var = var->GivItem(p->GivString());
- i->SetUniqNum(var->GivUniqNum());
- }
- p = p->GivNext(); // token suivant
-
- while (TRUE)
- {
- if ( var->GivType() == CBotTypArrayPointer ) // s'il sagit d'un tableau
- {
- if ( IsOfType( p, ID_OPBRK ) ) // regarde s'il y a un index
- {
- CBotIndexExpr* i = new CBotIndexExpr();
- i->m_expr = CBotExpression::Compile(p, pStk); // compile la formule
- inst->AddNext3(i); // ajoute à la chaine
-
- var = ((CBotVarArray*)var)->GivItem(0,TRUE); // donne le composant [0]
-
- if ( i->m_expr == NULL )
- {
- pStk->SetError( TX_BADINDEX, p->GivStart() );
- goto err;
- }
-
- if ( !pStk->IsOk() || !IsOfType( p, ID_CLBRK ) )
- {
- pStk->SetError( TX_CLBRK, p->GivStart() );
- goto err;
- }
- continue;
- }
- }
-
- if ( var->GivType(1) == CBotTypPointer ) // pour les classes
- {
- if ( IsOfType(p, ID_DOT) )
- {
- CBotToken* pp = p;
-
- CBotFieldExpr* i = new CBotFieldExpr(); // nouvel élément
- i->SetToken( pp ); // garde le nom du token
- inst->AddNext3(i); // ajoute à la suite
-
- if ( p->GivType() == TokenTypVar ) // doit être un nom
- {
- var = var->GivItem(p->GivString()); // récupère l'item correpondant
- if ( var != NULL )
- {
- if ( var->IsPrivate(PR_READ) &&
- !pStk->GivBotCall()->m_bCompileClass)
- {
- pStk->SetError( TX_PRIVATE, pp );
- goto err;
- }
-
- i->SetUniqNum(var->GivUniqNum());
- p = p->GivNext(); // saute le nom
- continue;
- }
- pStk->SetError( TX_NOITEM, p );
- }
- pStk->SetError( TX_DOT, p->GivStart() );
- goto err;
- }
- }
- break;
- }
-
-
- if ( pStk->IsOk() ) return (CBotLeftExpr*) pStack->Return(inst, pStk);
- }
- pStk->SetError(TX_UNDEFVAR, p);
+ CBotCStack* pStk = pStack->TokenStack();
+
+ pStk->SetStartError(p->GivStart());
+
+ // is it a variable name?
+ if (p->GivType() == TokenTypVar)
+ {
+ CBotLeftExpr* inst = new CBotLeftExpr(); // creates the object
+
+ inst->SetToken(p);
+
+ CBotVar* var;
+
+ if (NULL != (var = pStk->FindVar(p))) // seek if known variable
+ {
+ inst->m_nIdent = var->GivUniqNum();
+ if (inst->m_nIdent > 0 && inst->m_nIdent < 9000)
+ {
+ if ( var->IsPrivate(PR_READ) &&
+ !pStk->GivBotCall()->m_bCompileClass)
+ {
+ pStk->SetError(TX_PRIVATE, p);
+ goto err;
+ }
+ // this is an element of the current class
+ // adds the equivalent of this. before
+ CBotToken pthis("this");
+ inst->SetToken(&pthis);
+ inst->m_nIdent = -2; // indent for this
+
+ CBotFieldExpr* i = new CBotFieldExpr(); // new element
+ i->SetToken(p); // keeps the name of the token
+ inst->AddNext3(i); // add after
+
+ var = pStk->FindVar(pthis);
+ var = var->GivItem(p->GivString());
+ i->SetUniqNum(var->GivUniqNum());
+ }
+ p = p->GivNext(); // next token
+
+ while (true)
+ {
+ if (var->GivType() == CBotTypArrayPointer)
+ {
+ if (IsOfType( p, ID_OPBRK ))
+ {
+ CBotIndexExpr* i = new CBotIndexExpr();
+ i->m_expr = CBotExpression::Compile(p, pStk);
+ inst->AddNext3(i); // add to the chain
+
+ var = ((CBotVarArray*)var)->GivItem(0,true); // gets the component [0]
+
+ if (i->m_expr == NULL)
+ {
+ pStk->SetError(TX_BADINDEX, p->GivStart());
+ goto err;
+ }
+
+ if (!pStk->IsOk() || !IsOfType( p, ID_CLBRK ))
+ {
+ pStk->SetError(TX_CLBRK, p->GivStart());
+ goto err;
+ }
+ continue;
+ }
+ }
+
+ if (var->GivType(1) == CBotTypPointer) // for classes
+ {
+ if (IsOfType(p, ID_DOT))
+ {
+ CBotToken* pp = p;
+
+ CBotFieldExpr* i = new CBotFieldExpr(); // new element
+ i->SetToken(pp); // keeps the name of the token
+ inst->AddNext3(i); // adds after
+
+ if (p->GivType() == TokenTypVar) // must be a name
+ {
+ var = var->GivItem(p->GivString()); // get item correspondent
+ if (var != NULL)
+ {
+ if ( var->IsPrivate(PR_READ) &&
+ !pStk->GivBotCall()->m_bCompileClass)
+ {
+ pStk->SetError(TX_PRIVATE, pp);
+ goto err;
+ }
+
+ i->SetUniqNum(var->GivUniqNum());
+ p = p->GivNext(); // skips the name
+ continue;
+ }
+ pStk->SetError(TX_NOITEM, p);
+ }
+ pStk->SetError(TX_DOT, p->GivStart());
+ goto err;
+ }
+ }
+ break;
+ }
+
+
+ if (pStk->IsOk()) return (CBotLeftExpr*) pStack->Return(inst, pStk);
+ }
+ pStk->SetError(TX_UNDEFVAR, p);
err:
- delete inst;
- return (CBotLeftExpr*) pStack->Return(NULL, pStk);
- }
+ delete inst;
+ return (CBotLeftExpr*) pStack->Return(NULL, pStk);
+ }
- return (CBotLeftExpr*) pStack->Return(NULL, pStk);
+ return (CBotLeftExpr*) pStack->Return(NULL, pStk);
}
-// exécute, trouve une variable et lui assigne le résultat de la pile
-
-BOOL CBotLeftExpr::Execute(CBotStack* &pj, CBotStack* array)
+// runs, is a variable and assigns the result to the stack
+bool CBotLeftExpr::Execute(CBotStack* &pj, CBotStack* array)
{
- CBotStack* pile = pj->AddStack();
-// if ( pile == EOX ) return TRUE;
-
-// if ( pile->IfStep() ) return FALSE;
+ CBotStack* pile = pj->AddStack();
- CBotVar* var1 = NULL;
- CBotVar* var2 = NULL;
+ CBotVar* var1 = NULL;
+ CBotVar* var2 = NULL;
+ // fetch a variable (not copy)
+ if (!ExecuteVar(var1, array, NULL, false)) return false;
-// var1 = pile->FindVar(m_token, FALSE, TRUE);
- if (!ExecuteVar( var1, array, NULL, FALSE )) return FALSE;
- // retrouve la variable (et pas la copie)
- if (pile->IfStep()) return FALSE;
+ if (pile->IfStep()) return false;
- if ( var1 )
- {
- var2 = pj->GivVar(); // resultat sur la pile d'entrée
- if ( var2 )
- {
- CBotTypResult t1 = var1->GivTypResult();
- CBotTypResult t2 = var2->GivTypResult();
- if ( t2.Eq(CBotTypPointer) )
- {
- CBotClass* c1 = t1.GivClass();
- CBotClass* c2 = t2.GivClass();
- if ( !c2->IsChildOf(c1))
- {
- CBotToken* pt = &m_token;
- pile->SetError(TX_BADTYPE, pt);
- return pj->Return(pile); // opération faite
- }
- }
- var1->SetVal(var2); // fait l'assignation
- }
- pile->SetCopyVar( var1 ); // remplace sur la pile par une copie de la variable elle-même
- // (pour avoir le nom)
- }
+ if (var1)
+ {
+ var2 = pj->GivVar(); // result on the input stack
+ if (var2)
+ {
+ CBotTypResult t1 = var1->GivTypResult();
+ CBotTypResult t2 = var2->GivTypResult();
+ if (t2.Eq(CBotTypPointer))
+ {
+ CBotClass* c1 = t1.GivClass();
+ CBotClass* c2 = t2.GivClass();
+ if ( !c2->IsChildOf(c1))
+ {
+ CBotToken* pt = &m_token;
+ pile->SetError(TX_BADTYPE, pt);
+ return pj->Return(pile); // operation performed
+ }
+ }
+ var1->SetVal(var2); // do assignment
+ }
+ pile->SetCopyVar(var1); // replace the stack with the copy of the variable
+ // (for name)
+ }
- return pj->Return(pile); // opération faite
+ return pj->Return(pile); // operation performed
}
-// retrouve une variable pendant la compilation
+// fetch a variable during compilation
-BOOL CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
+bool CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
{
- pVar = pile->FindVar(m_token);
- if ( pVar == NULL ) return FALSE;
+ pVar = pile->FindVar(m_token);
+ if (pVar == NULL) return false;
- if ( m_next3 != NULL &&
- !m_next3->ExecuteVar(pVar, pile) ) return FALSE;
+ if ( m_next3 != NULL &&
+ !m_next3->ExecuteVar(pVar, pile) ) return false;
- return TRUE;
+ return true;
}
-// retrouve une variable à l'exécution
+// fetch the variable at runtume
-BOOL CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, BOOL bStep)
+bool CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep)
{
- pile = pile->AddStack( this ); // déplace la pile
+ pile = pile->AddStack(this);
- pVar = pile->FindVar(m_nIdent);
- if ( pVar == NULL )
- {
-#ifdef _DEBUG
- ASM_TRAP();
+ pVar = pile->FindVar(m_nIdent);
+ if (pVar == NULL)
+ {
+#ifdef _DEBUG
+ ASM_TRAP();
#endif
- pile->SetError(2, &m_token);
- return FALSE;
- }
+ pile->SetError(2, &m_token);
+ return false;
+ }
- if ( bStep && m_next3 == NULL && pile->IfStep() ) return FALSE;
+ if (bStep && m_next3 == NULL && pile->IfStep()) return false;
- if ( m_next3 != NULL &&
- !m_next3->ExecuteVar(pVar, pile, &m_token, bStep, TRUE) ) return FALSE;
+ if ( m_next3 != NULL &&
+ !m_next3->ExecuteVar(pVar, pile, &m_token, bStep, true) ) return false;
- return TRUE;
+ return true;
}
-void CBotLeftExpr::RestoreStateVar(CBotStack* &pile, BOOL bMain)
+void CBotLeftExpr::RestoreStateVar(CBotStack* &pile, bool bMain)
{
- pile = pile->RestoreStack( this ); // déplace la pile
- if ( pile == NULL ) return;
+ pile = pile->RestoreStack(this);
+ if (pile == NULL) return;
- if ( m_next3 != NULL )
- m_next3->RestoreStateVar(pile, bMain);
+ if (m_next3 != NULL)
+ m_next3->RestoreStateVar(pile, bMain);
}
//////////////////////////////////////////////////////////////////////////////////////////
-// transforme une chaîne en nombre entier
-// peut être de la forme 0xabc123
-
-long GivNumInt( const char* p )
-{
- long num = 0;
- while (*p >= '0' && *p <= '9')
- {
- num = num * 10 + *p - '0';
- p++;
- }
- if ( *p == 'x' || *p == 'X' )
- {
- while (*++p != 0)
- {
- if ( *p >= '0' && *p <= '9' )
- {
- num = num * 16 + *p - '0';
- continue;
- }
- if ( *p >= 'A' && *p <= 'F' )
- {
- num = num * 16 + *p - 'A' + 10;
- continue;
- }
- if ( *p >= 'a' && *p <= 'f' )
- {
- num = num * 16 + *p - 'a' + 10;
- continue;
- }
- break;
- }
- }
- return num;
-}
-
-// transforme une chaîne en un nombre réel
-
-extern float GivNumFloat( const char* p )
-{
- double num = 0;
- double div = 10;
- BOOL bNeg = FALSE;
-
- if (*p == '-')
- {
- bNeg = TRUE;
- p++;
- }
- while (*p >= '0' && *p <= '9')
- {
- num = num * 10. + (*p - '0');
- p++;
- }
-
- if ( *p == '.' )
- {
- p++;
- while (*p >= '0' && *p <= '9')
- {
- num = num + (*p - '0') / div;
- div = div * 10;
- p++;
- }
- }
-
- int exp = 0;
- if ( *p == 'e' || *p == 'E' )
- {
- char neg = 0;
- p++;
- if ( *p == '-' || *p == '+' ) neg = *p++;
-
- while (*p >= '0' && *p <= '9')
- {
- exp = exp * 10 + (*p - '0');
- p++;
- }
- if ( neg == '-' ) exp = -exp;
- }
-
- while ( exp > 0 )
- {
- num *= 10.0;
- exp--;
- }
-
- while ( exp < 0 )
- {
- num /= 10.0;
- exp++;
- }
-
- if ( bNeg ) num = -num;
- return (float)num;
+// converts a string into integer
+// may be of the form 0xabc123
+
+long GivNumInt(const char* p)
+{
+ long num = 0;
+ while (*p >= '0' && *p <= '9')
+ {
+ num = num * 10 + *p - '0';
+ p++;
+ }
+ if (*p == 'x' || *p == 'X')
+ {
+ while (*++p != 0)
+ {
+ if (*p >= '0' && *p <= '9')
+ {
+ num = num * 16 + *p - '0';
+ continue;
+ }
+ if (*p >= 'A' && *p <= 'F')
+ {
+ num = num * 16 + *p - 'A' + 10;
+ continue;
+ }
+ if (*p >= 'a' && *p <= 'f')
+ {
+ num = num * 16 + *p - 'a' + 10;
+ continue;
+ }
+ break;
+ }
+ }
+ return num;
+}
+
+// converts a string into a float number
+extern float GivNumFloat(const char* p)
+{
+ double num = 0;
+ double div = 10;
+ bool bNeg = false;
+
+ if (*p == '-')
+ {
+ bNeg = true;
+ p++;
+ }
+ while (*p >= '0' && *p <= '9')
+ {
+ num = num * 10. + (*p - '0');
+ p++;
+ }
+
+ if (*p == '.')
+ {
+ p++;
+ while (*p >= '0' && *p <= '9')
+ {
+ num = num + (*p - '0') / div;
+ div = div * 10;
+ p++;
+ }
+ }
+
+ int exp = 0;
+ if (*p == 'e' || *p == 'E')
+ {
+ char neg = 0;
+ p++;
+ if (*p == '-' || *p == '+') neg = *p++;
+
+ while (*p >= '0' && *p <= '9')
+ {
+ exp = exp * 10 + (*p - '0');
+ p++;
+ }
+ if (neg == '-') exp = -exp;
+ }
+
+ while (exp > 0)
+ {
+ num *= 10.0;
+ exp--;
+ }
+
+ while (exp < 0)
+ {
+ num /= 10.0;
+ exp++;
+ }
+
+ if (bNeg) num = -num;
+ return (float)num;
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// compile un token représentant un nombre
-
+// compiles a token representing a number
CBotExprNum::CBotExprNum()
{
- name = "CBotExprNum";
+ name = "CBotExprNum";
}
CBotExprNum::~CBotExprNum()
@@ -2835,88 +2786,87 @@ CBotExprNum::~CBotExprNum()
CBotInstr* CBotExprNum::Compile(CBotToken* &p, CBotCStack* pStack)
{
- CBotCStack* pStk = pStack->TokenStack();
+ CBotCStack* pStk = pStack->TokenStack();
- CBotExprNum* inst = new CBotExprNum();
+ CBotExprNum* inst = new CBotExprNum();
- inst->SetToken(p);
- CBotString s = p->GivString();
+ inst->SetToken(p);
+ CBotString s = p->GivString();
- inst->m_numtype = CBotTypInt;
- if ( p->GivType() == TokenTypDef )
- {
- inst->m_valint = p->GivIdKey();
- }
- else
- {
- if ( s.Find('.') >= 0 || ( s.Find('x') < 0 && ( s.Find('e') >= 0 || s.Find('E') >= 0 ) ) )
- {
- inst->m_numtype = CBotTypFloat;
- inst->m_valfloat = GivNumFloat(s);
- }
- else
- {
- inst->m_valint = GivNumInt(s);
- }
- }
+ inst->m_numtype = CBotTypInt;
+ if (p->GivType() == TokenTypDef)
+ {
+ inst->m_valint = p->GivIdKey();
+ }
+ else
+ {
+ if (s.Find('.') >= 0 || ( s.Find('x') < 0 && ( s.Find('e') >= 0 || s.Find('E') >= 0 ) ))
+ {
+ inst->m_numtype = CBotTypFloat;
+ inst->m_valfloat = GivNumFloat(s);
+ }
+ else
+ {
+ inst->m_valint = GivNumInt(s);
+ }
+ }
- if (pStk->NextToken(p))
- {
- CBotVar* var = CBotVar::Create((CBotToken*)NULL, inst->m_numtype);
- pStk->SetVar(var);
+ if (pStk->NextToken(p))
+ {
+ CBotVar* var = CBotVar::Create((CBotToken*)NULL, inst->m_numtype);
+ pStk->SetVar(var);
- return pStack->Return(inst, pStk);
- }
- delete inst;
- return pStack->Return(NULL, pStk);
+ return pStack->Return(inst, pStk);
+ }
+ delete inst;
+ return pStack->Return(NULL, pStk);
}
-// exécute, retourne le nombre correspondant
+// execute, returns the corresponding number
-BOOL CBotExprNum::Execute(CBotStack* &pj)
+bool CBotExprNum::Execute(CBotStack* &pj)
{
- CBotStack* pile = pj->AddStack(this);
-// if ( pile == EOX ) return TRUE;
+ CBotStack* pile = pj->AddStack(this);
- if ( pile->IfStep() ) return FALSE;
+ if (pile->IfStep()) return false;
- CBotVar* var = CBotVar::Create((CBotToken*)NULL, m_numtype);
+ CBotVar* var = CBotVar::Create((CBotToken*)NULL, m_numtype);
- CBotString nombre ;
- if ( m_token.GivType() == TokenTypDef )
- {
- nombre = m_token.GivString();
- }
+ CBotString nombre ;
+ if (m_token.GivType() == TokenTypDef)
+ {
+ nombre = m_token.GivString();
+ }
- switch (m_numtype)
- {
- case CBotTypShort:
- case CBotTypInt:
- var->SetValInt( m_valint, nombre ); // valeur du nombre
- break;
- case CBotTypFloat:
- var->SetValFloat( m_valfloat ); // valeur du nombre
- break;
- }
- pile->SetVar( var ); // mis sur la pile
+ switch (m_numtype)
+ {
+ case CBotTypShort:
+ case CBotTypInt:
+ var->SetValInt(m_valint, nombre);
+ break;
+ case CBotTypFloat:
+ var->SetValFloat(m_valfloat);
+ break;
+ }
+ pile->SetVar(var); // place on the stack
- return pj->Return(pile); // c'est ok
+ return pj->Return(pile); // it's ok
}
-void CBotExprNum::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotExprNum::RestoreState(CBotStack* &pj, bool bMain)
{
- if ( bMain ) pj->RestoreStack(this);
+ if (bMain) pj->RestoreStack(this);
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// compile un token représentant une chaine de caractères
+// compile a token representing a string
CBotExprAlpha::CBotExprAlpha()
{
- name = "CBotExprAlpha";
+ name = "CBotExprAlpha";
}
CBotExprAlpha::~CBotExprAlpha()
@@ -2925,54 +2875,53 @@ CBotExprAlpha::~CBotExprAlpha()
CBotInstr* CBotExprAlpha::Compile(CBotToken* &p, CBotCStack* pStack)
{
- CBotCStack* pStk = pStack->TokenStack();
+ CBotCStack* pStk = pStack->TokenStack();
- CBotExprAlpha* inst = new CBotExprAlpha();
+ CBotExprAlpha* inst = new CBotExprAlpha();
- inst->SetToken(p);
- p = p->GivNext();
+ inst->SetToken(p);
+ p = p->GivNext();
- CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypString);
- pStk->SetVar(var);
+ CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypString);
+ pStk->SetVar(var);
- return pStack->Return(inst, pStk);
+ return pStack->Return(inst, pStk);
}
-// exécute, retourne la chaîne correspondante
+// execute, returns the corresponding string
-BOOL CBotExprAlpha::Execute(CBotStack* &pj)
+bool CBotExprAlpha::Execute(CBotStack* &pj)
{
- CBotStack* pile = pj->AddStack(this);
-// if ( pile == EOX ) return TRUE;
+ CBotStack* pile = pj->AddStack(this);
- if ( pile->IfStep() ) return FALSE;
+ if (pile->IfStep()) return false;
- CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypString);
+ CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypString);
- CBotString chaine = m_token.GivString();
- chaine = chaine.Mid(1, chaine.GivLength()-2); // enlève les guillemets
+ CBotString chaine = m_token.GivString();
+ chaine = chaine.Mid(1, chaine.GivLength()-2); // removes the quotes
- var->SetValString( chaine ); // valeur du nombre
+ var->SetValString(chaine); // value of the number
- pile->SetVar( var ); // mis sur la pile
+ pile->SetVar(var); // put on the stack
- return pj->Return(pile);
+ return pj->Return(pile);
}
-void CBotExprAlpha::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotExprAlpha::RestoreState(CBotStack* &pj, bool bMain)
{
- if ( bMain ) pj->RestoreStack(this);
+ if (bMain) pj->RestoreStack(this);
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// compile un token représentant true ou false
+// compile a token representing true or false
CBotExprBool::CBotExprBool()
{
- name = "CBotExprBool";
+ name = "CBotExprBool";
}
CBotExprBool::~CBotExprBool()
@@ -2981,121 +2930,118 @@ CBotExprBool::~CBotExprBool()
CBotInstr* CBotExprBool::Compile(CBotToken* &p, CBotCStack* pStack)
{
- CBotCStack* pStk = pStack->TokenStack();
- CBotExprBool* inst = NULL;
+ CBotCStack* pStk = pStack->TokenStack();
+ CBotExprBool* inst = NULL;
- if ( p->GivType() == ID_TRUE ||
- p->GivType() == ID_FALSE )
- {
- inst = new CBotExprBool();
- inst->SetToken(p); // mémorise l'opération false ou true
- p = p->GivNext();
+ if ( p->GivType() == ID_TRUE ||
+ p->GivType() == ID_FALSE )
+ {
+ inst = new CBotExprBool();
+ inst->SetToken(p); // stores the operation false or true
+ p = p->GivNext();
- CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypBoolean);
- pStk->SetVar(var);
- }
+ CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypBoolean);
+ pStk->SetVar(var);
+ }
- return pStack->Return(inst, pStk);
+ return pStack->Return(inst, pStk);
}
-// exécute, retourne true ou false
+// executes, returns true or false
-BOOL CBotExprBool::Execute(CBotStack* &pj)
+bool CBotExprBool::Execute(CBotStack* &pj)
{
- CBotStack* pile = pj->AddStack(this);
-// if ( pile == EOX ) return TRUE;
+ CBotStack* pile = pj->AddStack(this);
- if ( pile->IfStep() ) return FALSE;
+ if (pile->IfStep()) return false;
- CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypBoolean);
+ CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypBoolean);
- if (GivTokenType() == ID_TRUE) var->SetValInt(1);
- else var->SetValInt(0);
+ if (GivTokenType() == ID_TRUE) var->SetValInt(1);
+ else var->SetValInt(0);
- pile->SetVar( var ); // mis sur la pile
- return pj->Return(pile); // transmet en dessous
+ pile->SetVar(var); // put on the stack
+ return pj->Return(pile); // forwards below
}
-void CBotExprBool::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotExprBool::RestoreState(CBotStack* &pj, bool bMain)
{
- if ( bMain ) pj->RestoreStack(this);
+ if (bMain) pj->RestoreStack(this);
}
//////////////////////////////////////////////////////////////////////////////////////////
-// gestion de l'opérande "null"
+// management of the operand "null"
CBotExprNull::CBotExprNull()
{
- name = "CBotExprNull";
+ name = "CBotExprNull";
}
CBotExprNull::~CBotExprNull()
{
}
-// exécute, retourne un pointeur vide
+// executes, returns an empty pointer
-BOOL CBotExprNull::Execute(CBotStack* &pj)
+bool CBotExprNull::Execute(CBotStack* &pj)
{
- CBotStack* pile = pj->AddStack(this);
-// if ( pile == EOX ) return TRUE;
+ CBotStack* pile = pj->AddStack(this);
- if ( pile->IfStep() ) return FALSE;
- CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypNullPointer);
+ if (pile->IfStep()) return false;
+ CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypNullPointer);
- var->SetInit(TRUE); // pointeur null valide
- pile->SetVar( var ); // mis sur la pile
- return pj->Return(pile); // transmet en dessous
+ var->SetInit(true); // null pointer valid
+ pile->SetVar(var); // place on the stack
+ return pj->Return(pile); // forwards below
}
-void CBotExprNull::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotExprNull::RestoreState(CBotStack* &pj, bool bMain)
{
- if ( bMain ) pj->RestoreStack(this);
+ if (bMain) pj->RestoreStack(this);
}
//////////////////////////////////////////////////////////////////////////////////////////
-// gestion de l'opérande "nan"
+// management of the operand "nan"
CBotExprNan::CBotExprNan()
{
- name = "CBotExprNan";
+ name = "CBotExprNan";
}
CBotExprNan::~CBotExprNan()
{
}
-// exécute, retourne un pointeur vide
+// executes, returns null pointer
-BOOL CBotExprNan::Execute(CBotStack* &pj)
+bool CBotExprNan::Execute(CBotStack* &pj)
{
- CBotStack* pile = pj->AddStack(this);
-// if ( pile == EOX ) return TRUE;
+ CBotStack* pile = pj->AddStack(this);
- if ( pile->IfStep() ) return FALSE;
- CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypInt);
+ if (pile->IfStep()) return false;
+ CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypInt);
- var->SetInit(IS_NAN); // nombre nan
- pile->SetVar( var ); // mis sur la pile
- return pj->Return(pile); // transmet en dessous
+ var->SetInit(IS_NAN); // nan
+ pile->SetVar(var); // put on the stack
+ return pj->Return(pile); // forward below
}
-void CBotExprNan::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotExprNan::RestoreState(CBotStack* &pj, bool bMain)
{
- if ( bMain ) pj->RestoreStack(this);
+ if (bMain) pj->RestoreStack(this);
}
//////////////////////////////////////////////////////////////////////////////////////
-// compile un nom de variable
-// vérifie qu'elle est connue sur la pile
-// et qu'elle a été initialisée
+// compile a variable name
+// check that it is known on the stack
+// and it has been initialized
CBotExprVar::CBotExprVar()
{
- name = "CBotExprVar";
- m_nIdent = 0;
+ name = "CBotExprVar";
+ m_nIdent = 0;
}
CBotExprVar::~CBotExprVar()
@@ -3104,605 +3050,591 @@ CBotExprVar::~CBotExprVar()
CBotInstr* CBotExprVar::Compile(CBotToken* &p, CBotCStack* pStack, int privat)
{
- CBotToken* pDebut = p;
- CBotCStack* pStk = pStack->TokenStack();
-
- pStk->SetStartError(p->GivStart());
-
- // est-ce un nom de variable ?
- if (p->GivType() == TokenTypVar)
- {
- CBotInstr* inst = new CBotExprVar(); // crée l'objet
-
- inst->SetToken(p);
-
- CBotVar* var;
-
- if ( NULL != (var = pStk->FindVar(p)) ) // cherche si variable connue
- {
- int ident = var->GivUniqNum();
- ((CBotExprVar*)inst)->m_nIdent = ident; // l'identifie par son numéro
-
- if (ident > 0 && ident < 9000)
- {
- if ( var->IsPrivate(privat) &&
- !pStk->GivBotCall()->m_bCompileClass)
- {
- pStk->SetError( TX_PRIVATE, p );
- goto err;
- }
-
- // il s'agit d'un élement de la classe courante
- // ajoute l'équivalent d'un this. devant
- inst->SetToken(&CBotToken("this"));
- ((CBotExprVar*)inst)->m_nIdent = -2; // ident pour this
-
- CBotFieldExpr* i = new CBotFieldExpr(); // nouvel élément
- i->SetToken( p ); // garde le nom du token
- i->SetUniqNum(ident);
- inst->AddNext3(i); // ajoute à la suite
- }
-
- p = p->GivNext(); // token suivant
-
- while (TRUE)
- {
- if ( var->GivType() == CBotTypArrayPointer ) // s'il sagit d'un tableau
- {
- if ( IsOfType( p, ID_OPBRK ) ) // regarde s'il y a un index
- {
- CBotIndexExpr* i = new CBotIndexExpr();
- i->m_expr = CBotExpression::Compile(p, pStk); // compile la formule
- inst->AddNext3(i); // ajoute à la chaine
-
- var = ((CBotVarArray*)var)->GivItem(0,TRUE); // donne le composant [0]
-
- if ( i->m_expr == NULL )
- {
- pStk->SetError( TX_BADINDEX, p->GivStart() );
- goto err;
- }
- if ( !pStk->IsOk() || !IsOfType( p, ID_CLBRK ) )
- {
- pStk->SetError( TX_CLBRK, p->GivStart() );
- goto err;
- }
- continue;
- }
- //// pStk->SetError( TX_OPBRK, p->GivStart() );
- }
- if ( var->GivType(1) == CBotTypPointer ) // pour les classes
- {
- if ( IsOfType(p, ID_DOT) )
- {
- CBotToken* pp = p;
-
- if ( p->GivType() == TokenTypVar ) // doit être un nom
- {
- if ( p->GivNext()->GivType() == ID_OPENPAR )// un appel de méthode ?
- {
- CBotInstr* i = CBotInstrMethode::Compile(p, pStk, var);
- if ( !pStk->IsOk() ) goto err;
- inst->AddNext3(i); // ajoute à la suite
- return pStack->Return(inst, pStk);
- }
- else
- {
- CBotFieldExpr* i = new CBotFieldExpr(); // nouvel élément
- i->SetToken( pp ); // garde le nom du token
- inst->AddNext3(i); // ajoute à la suite
- var = var->GivItem(p->GivString()); // récupère l'item correpondant
- if ( var != NULL )
- {
- i->SetUniqNum(var->GivUniqNum());
- if ( var->IsPrivate() &&
- !pStk->GivBotCall()->m_bCompileClass)
- {
- pStk->SetError( TX_PRIVATE, pp );
- goto err;
- }
- }
- }
-
-
- if ( var != NULL )
- {
- p = p->GivNext(); // saute le nom
- continue;
- }
- pStk->SetError( TX_NOITEM, p );
- goto err;
- }
- pStk->SetError( TX_DOT, p->GivStart() );
- goto err;
- }
- }
-
- break;
- }
-
- pStk->SetCopyVar(var); // place une copie de la variable sur la pile (pour le type)
- if ( pStk->IsOk() ) return pStack->Return(inst, pStk);
- }
- pStk->SetError(TX_UNDEFVAR, p);
+ CBotToken* pDebut = p;
+ CBotCStack* pStk = pStack->TokenStack();
+
+ pStk->SetStartError(p->GivStart());
+
+ // is it a variable?
+ if (p->GivType() == TokenTypVar)
+ {
+ CBotInstr* inst = new CBotExprVar(); // create the object
+
+ inst->SetToken(p);
+
+ CBotVar* var;
+
+ if (NULL != (var = pStk->FindVar(p))) // seek if known variable
+ {
+ int ident = var->GivUniqNum();
+ ((CBotExprVar*)inst)->m_nIdent = ident; // identifies variable by its number
+
+ if (ident > 0 && ident < 9000)
+ {
+ if ( var->IsPrivate(privat) &&
+ !pStk->GivBotCall()->m_bCompileClass)
+ {
+ pStk->SetError(TX_PRIVATE, p);
+ goto err;
+ }
+
+ // This is an element of the current class
+ // ads the equivalent of this. before
+ /// \TODO need to be fixed revised and fixed after adding unit
+ ///tests
+ CBotToken token("this");
+ inst->SetToken(&token);
+ ((CBotExprVar*)inst)->m_nIdent = -2; // identificator for this
+
+ CBotFieldExpr* i = new CBotFieldExpr(); // new element
+ i->SetToken(p); // keeps the name of the token
+ i->SetUniqNum(ident);
+ inst->AddNext3(i); // added after
+ }
+
+ p = p->GivNext(); // next token
+
+ while (true)
+ {
+ if (var->GivType() == CBotTypArrayPointer)
+ {
+ if (IsOfType( p, ID_OPBRK )) // check if there is an aindex
+ {
+ CBotIndexExpr* i = new CBotIndexExpr();
+ i->m_expr = CBotExpression::Compile(p, pStk); // compile the formula
+ inst->AddNext3(i); // add to the chain
+
+ var = ((CBotVarArray*)var)->GivItem(0,true); // gets the component [0]
+
+ if (i->m_expr == NULL)
+ {
+ pStk->SetError(TX_BADINDEX, p->GivStart());
+ goto err;
+ }
+ if (!pStk->IsOk() || !IsOfType( p, ID_CLBRK ))
+ {
+ pStk->SetError(TX_CLBRK, p->GivStart());
+ goto err;
+ }
+ continue;
+ }
+ }
+ if (var->GivType(1) == CBotTypPointer) // for classes
+ {
+ if (IsOfType(p, ID_DOT))
+ {
+ CBotToken* pp = p;
+
+ if (p->GivType() == TokenTypVar) // must be a name
+ {
+ if (p->GivNext()->GivType() == ID_OPENPAR) // a method call?
+ {
+ CBotInstr* i = CBotInstrMethode::Compile(p, pStk, var);
+ if (!pStk->IsOk()) goto err;
+ inst->AddNext3(i); // added after
+ return pStack->Return(inst, pStk);
+ }
+ else
+ {
+ CBotFieldExpr* i = new CBotFieldExpr(); // new element
+ i->SetToken(pp); // keeps the name of the token
+ inst->AddNext3(i); // add after
+ var = var->GivItem(p->GivString()); // get item correspondent
+ if (var != NULL)
+ {
+ i->SetUniqNum(var->GivUniqNum());
+ if ( var->IsPrivate() &&
+ !pStk->GivBotCall()->m_bCompileClass)
+ {
+ pStk->SetError(TX_PRIVATE, pp);
+ goto err;
+ }
+ }
+ }
+
+
+ if (var != NULL)
+ {
+ p = p->GivNext(); // skips the name
+ continue;
+ }
+ pStk->SetError(TX_NOITEM, p);
+ goto err;
+ }
+ pStk->SetError(TX_DOT, p->GivStart());
+ goto err;
+ }
+ }
+
+ break;
+ }
+
+ pStk->SetCopyVar(var); // place the copy of the variable on the stack (for type)
+ if (pStk->IsOk()) return pStack->Return(inst, pStk);
+ }
+ pStk->SetError(TX_UNDEFVAR, p);
err:
- delete inst;
- return pStack->Return(NULL, pStk);
- }
+ delete inst;
+ return pStack->Return(NULL, pStk);
+ }
- return pStack->Return(NULL, pStk);
+ return pStack->Return(NULL, pStk);
}
CBotInstr* CBotExprVar::CompileMethode(CBotToken* &p, CBotCStack* pStack)
{
- CBotToken* pp = p;
- CBotCStack* pStk = pStack->TokenStack();
+ CBotToken* pp = p;
+ CBotCStack* pStk = pStack->TokenStack();
+
+ pStk->SetStartError(pp->GivStart());
- pStk->SetStartError(pp->GivStart());
+ // is it a variable ?
+ if (pp->GivType() == TokenTypVar)
+ {
+ CBotToken pthis("this");
+ CBotVar* var = pStk->FindVar(pthis);
+ if (var == 0) return pStack->Return(NULL, pStk);
- // est-ce un nom de variable ?
- if (pp->GivType() == TokenTypVar)
- {
- CBotToken pthis("this");
- CBotVar* var = pStk->FindVar(pthis);
- if ( var == 0 ) return pStack->Return(NULL, pStk);
+ CBotInstr* inst = new CBotExprVar();
- CBotInstr* inst = new CBotExprVar(); // crée l'objet
-
- // il s'agit d'un élement de la classe courante
- // ajoute l'équivalent d'un this. devant
- inst->SetToken(&pthis);
- ((CBotExprVar*)inst)->m_nIdent = -2; // ident pour this
+ // this is an element of the current class
+ // adds the equivalent of this. before
- CBotToken* pp = p;
+ inst->SetToken(&pthis);
+ ((CBotExprVar*)inst)->m_nIdent = -2; // ident for this
- if ( pp->GivType() == TokenTypVar ) // doit être un nom
- {
- if ( pp->GivNext()->GivType() == ID_OPENPAR ) // un appel de méthode ?
- {
- CBotInstr* i = CBotInstrMethode::Compile(pp, pStk, var);
- if ( pStk->IsOk() )
- {
- inst->AddNext3(i); // ajoute à la suite
- p = pp; // instructions passées
- return pStack->Return(inst, pStk);
- }
- pStk->SetError(0,0); // l'erreur n'est pas traitée ici
- }
- }
- delete inst;
- }
- return pStack->Return(NULL, pStk);
+ CBotToken* pp = p;
+
+ if (pp->GivType() == TokenTypVar)
+ {
+ if (pp->GivNext()->GivType() == ID_OPENPAR) // a method call?
+ {
+ CBotInstr* i = CBotInstrMethode::Compile(pp, pStk, var);
+ if (pStk->IsOk())
+ {
+ inst->AddNext3(i); // add after
+ p = pp; // previous instruction
+ return pStack->Return(inst, pStk);
+ }
+ pStk->SetError(0,0); // the error is not adressed here
+ }
+ }
+ delete inst;
+ }
+ return pStack->Return(NULL, pStk);
}
-// exécute, rend la valeur d'une variable
+// execute, making the value of a variable
-BOOL CBotExprVar::Execute(CBotStack* &pj)
+bool CBotExprVar::Execute(CBotStack* &pj)
{
- CBotVar* pVar = NULL;
- CBotStack* pile = pj->AddStack(this);
-// if ( pile == EOX ) return TRUE;
-
-// if ( pile->IfStep() ) return FALSE;
+ CBotVar* pVar = NULL;
+ CBotStack* pile = pj->AddStack(this);
- CBotStack* pile1 = pile;
+ CBotStack* pile1 = pile;
- if ( pile1->GivState() == 0 )
- {
- if ( !ExecuteVar(pVar, pile, NULL, TRUE) ) return FALSE; // récupère la variable selon champs et index
-// DEBUG("CBotExprVar::Execute", 1 , pj);
+ if (pile1->GivState() == 0)
+ {
+ if (!ExecuteVar(pVar, pile, NULL, true)) return false; // Get the variable fields and indexes according
- if ( pVar ) pile1->SetCopyVar(pVar); // la place une copie sur la pile
- else
- {
-//-- pile1->SetVar(NULL); // la pile contient déjà le resultat (méthode)
- return pj->Return(pile1);
- }
- pile1->IncState();
- }
+ if (pVar) pile1->SetCopyVar(pVar); // place a copy on the stack
+ else
+ {
+ return pj->Return(pile1);
+ }
+ pile1->IncState();
+ }
- pVar = pile1->GivVar(); // récupère si interrompu
+ pVar = pile1->GivVar();
- if ( pVar == NULL )
- {
-// pile1->SetError(TX_NULLPT, &m_token);
- return pj->Return(pile1);
- }
+ if (pVar == NULL)
+ {
+ return pj->Return(pile1);
+ }
- if ( pVar->GivInit() == IS_UNDEF )
- {
- CBotToken* pt = &m_token;
- while ( pt->GivNext() != NULL ) pt = pt->GivNext();
- pile1->SetError(TX_NOTINIT, pt);
- return pj->Return(pile1);
- }
- return pj->Return(pile1); // opération faite
+ if (pVar->GivInit() == IS_UNDEF)
+ {
+ CBotToken* pt = &m_token;
+ while (pt->GivNext() != NULL) pt = pt->GivNext();
+ pile1->SetError(TX_NOTINIT, pt);
+ return pj->Return(pile1);
+ }
+ return pj->Return(pile1); // operation completed
}
-void CBotExprVar::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotExprVar::RestoreState(CBotStack* &pj, bool bMain)
{
- if ( !bMain ) return;
+ if (!bMain) return;
- CBotStack* pile = pj->RestoreStack(this);
- if ( pile == NULL ) return;
+ CBotStack* pile = pj->RestoreStack(this);
+ if (pile == NULL) return;
- CBotStack* pile1 = pile;
+ CBotStack* pile1 = pile;
- if ( pile1->GivState() == 0 )
- {
- RestoreStateVar(pile, bMain); // récupère la variable selon champs et index
- return;
- }
+ if (pile1->GivState() == 0)
+ {
+ RestoreStateVar(pile, bMain); // retrieves the variable fields and indexes according
+ return;
+ }
}
-// retrouve une variable à l'exécution
+// fetch a variable at runtime
-BOOL CBotExprVar::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, BOOL bStep)
+bool CBotExprVar::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep)
{
- CBotStack* pile = pj;
- pj = pj->AddStack( this );
+ CBotStack* pile = pj;
+ pj = pj->AddStack(this);
- if ( bStep && m_nIdent>0 && pj->IfStep() ) return FALSE;
+ if (bStep && m_nIdent>0 && pj->IfStep()) return false;
- pVar = pj->FindVar(m_nIdent, TRUE); // cherche la variable avec mise à jour si nécessaire
- if ( pVar == NULL )
- {
-#ifdef _DEBUG
- ASM_TRAP();
+ pVar = pj->FindVar(m_nIdent, true); // tries with the variable update if necessary
+ if (pVar == NULL)
+ {
+#ifdef _DEBUG
+ ASM_TRAP();
#endif
- pj->SetError(1, &m_token);
- return FALSE;
- }
- if ( m_next3 != NULL &&
- !m_next3->ExecuteVar(pVar, pj, &m_token, bStep, FALSE) )
- return FALSE; // Champs d'une instance, tableau, méthode ?
+ pj->SetError(1, &m_token);
+ return false;
+ }
+ if ( m_next3 != NULL &&
+ !m_next3->ExecuteVar(pVar, pj, &m_token, bStep, false) )
+ return false; // field of an instance, table, methode
- return pile->ReturnKeep( pj ); // ne rend pas la pile mais récupère le résultat si une méthode a été appelée
+ return pile->ReturnKeep(pj); // does not put on stack but get the result if a method was called
}
-// retrouve une variable à l'exécution
+// fetch variable at runtime
-void CBotExprVar::RestoreStateVar(CBotStack* &pj, BOOL bMain)
+void CBotExprVar::RestoreStateVar(CBotStack* &pj, bool bMain)
{
- pj = pj->RestoreStack( this );
- if ( pj == NULL ) return;
+ pj = pj->RestoreStack(this);
+ if (pj == NULL) return;
- if ( m_next3 != NULL )
- m_next3->RestoreStateVar(pj, bMain);
+ if (m_next3 != NULL)
+ m_next3->RestoreStateVar(pj, bMain);
}
//////////////////////////////////////////////////////////////////////////////////////////
-// compile une liste de paramètres
+// compile a list of parameters
CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars)
{
- BOOL first = TRUE;
- CBotInstr* ret = NULL; // pour la liste à retourner
-
-// pStack->SetStartError(p->GivStart());
- CBotCStack* pile = pStack;
- int i = 0;
-
- if ( IsOfType(p, ID_OPENPAR) )
- {
- int start, end;
- if (!IsOfType(p, ID_CLOSEPAR)) while (TRUE)
- {
- start = p->GivStart();
- pile = pile->TokenStack(); // garde les résultats sur la pile
-
- if ( first ) pStack->SetStartError(start);
- first = FALSE;
-
- CBotInstr* param = CBotExpression::Compile(p, pile);
- end = p->GivStart();
-
- if ( !pile->IsOk() )
- {
- return pStack->Return(NULL, pile);
- }
-
- if ( ret == NULL ) ret = param;
- else ret->AddNext(param); // construit la liste
-
- if ( param != NULL )
- {
- if ( pile->GivTypResult().Eq(99) )
- {
- delete pStack->TokenStack();
- pStack->SetError(TX_VOID, p->GivStart());
- return NULL;
- }
- ppVars[i] = pile->GivVar();
- ppVars[i]->GivToken()->SetPos(start, end);
- i++;
-
- if (IsOfType(p, ID_COMMA)) continue; // saute la virgule
- if (IsOfType(p, ID_CLOSEPAR)) break;
- }
-
- pStack->SetError(TX_CLOSEPAR, p->GivStart());
- delete pStack->TokenStack();
- return NULL;
- }
- }
- ppVars[i] = NULL;
- return ret;
+ bool first = true;
+ CBotInstr* ret = NULL; // to return to the list
+
+ CBotCStack* pile = pStack;
+ int i = 0;
+
+ if (IsOfType(p, ID_OPENPAR))
+ {
+ int start, end;
+ if (!IsOfType(p, ID_CLOSEPAR)) while (true)
+ {
+ start = p->GivStart();
+ pile = pile->TokenStack(); // keeps the result on the stack
+
+ if (first) pStack->SetStartError(start);
+ first = false;
+
+ CBotInstr* param = CBotExpression::Compile(p, pile);
+ end = p->GivStart();
+
+ if (!pile->IsOk())
+ {
+ return pStack->Return(NULL, pile);
+ }
+
+ if (ret == NULL) ret = param;
+ else ret->AddNext(param); // construct the list
+
+ if (param != NULL)
+ {
+ if (pile->GivTypResult().Eq(99))
+ {
+ delete pStack->TokenStack();
+ pStack->SetError(TX_VOID, p->GivStart());
+ return NULL;
+ }
+ ppVars[i] = pile->GivVar();
+ ppVars[i]->GivToken()->SetPos(start, end);
+ i++;
+
+ if (IsOfType(p, ID_COMMA)) continue; // skips the comma
+ if (IsOfType(p, ID_CLOSEPAR)) break;
+ }
+
+ pStack->SetError(TX_CLOSEPAR, p->GivStart());
+ delete pStack->TokenStack();
+ return NULL;
+ }
+ }
+ ppVars[i] = NULL;
+ return ret;
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
-// compile un appel d'une méthode
+// compile a method call
CBotInstrMethode::CBotInstrMethode()
{
- m_Parameters = NULL;
- m_MethodeIdent = 0;
-// m_nThisIdent = 0;
- name = "CBotInstrMethode";
+ m_Parameters = NULL;
+ m_MethodeIdent = 0;
+ name = "CBotInstrMethode";
}
CBotInstrMethode::~CBotInstrMethode()
{
- delete m_Parameters;
+ delete m_Parameters;
}
CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* var)
{
- CBotInstrMethode* inst = new CBotInstrMethode();
- inst->SetToken(p); // token correspondant
-
-// inst->m_nThisIdent = CBotVar::NextUniqNum();
-
- if ( NULL != var )
- {
- CBotToken* pp = p;
- p = p->GivNext();
-
- if ( p->GivType() == ID_OPENPAR )
- {
- inst->m_NomMethod = pp->GivString();
-
- // compile la liste des paramètres
- CBotVar* ppVars[1000];
- inst->m_Parameters = CompileParams(p, pStack, ppVars);
-
- if ( pStack->IsOk() )
- {
- CBotClass* pClass = var->GivClass(); // pointeur à la classe
- inst->m_ClassName = pClass->GivName(); // le nom de la classe
- CBotTypResult r = pClass->CompileMethode(inst->m_NomMethod, var, ppVars,
- pStack, inst->m_MethodeIdent);
- delete pStack->TokenStack(); // libères les paramètres encore sur la pile
- inst->m_typRes = r;
-
- if (inst->m_typRes.GivType() > 20)
- {
- pStack->SetError(inst->m_typRes.GivType(), pp);
- delete inst;
- return NULL;
- }
- // met un résultat sur la pile pour avoir quelque chose
- if (inst->m_typRes.GivType() > 0)
- {
- CBotVar* pResult = CBotVar::Create("", inst->m_typRes);
- if (inst->m_typRes.Eq(CBotTypClass))
- {
-// CBotClass* pClass = CBotClass::Find(inst->m_RetClassName);
- pResult->SetClass(inst->m_typRes.GivClass());
- }
- pStack->SetVar(pResult);
- }
- return inst;
- }
- delete inst;
- return NULL;
- }
- }
- pStack->SetError( 1234, p );
- delete inst;
- return NULL;
-}
-
-// exécute l'appel de méthode
-
-BOOL CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, BOOL bStep, BOOL bExtend)
-{
- CBotVar* ppVars[1000];
- CBotStack* pile1 = pj->AddStack(this, TRUE); // une place pour la copie de This
-// if ( pile1 == EOX ) return TRUE;
-
-// DEBUG( "CBotInstrMethode::ExecuteVar", 0, pj );
-
- if ( pVar->GivPointer() == NULL )
- {
- pj->SetError( TX_NULLPT, prevToken );
- }
-
- if ( pile1->IfStep() ) return FALSE;
-
- CBotStack* pile2 = pile1->AddStack(); // et pour les paramètres à venir
-
- if ( pile1->GivState() == 0)
- {
- CBotVar* pThis = CBotVar::Create(pVar);
- pThis->Copy(pVar);
- // la valeur de This doit être prise avant l'évaluation des paramètres
- // Test.Action( Test = Autre );
- // Action doit agir sur la valeur avant Test = Autre !!
- pThis->SetName("this");
-// pThis->SetUniqNum(m_nThisIdent);
- pThis->SetUniqNum(-2);
- pile1->AddVar(pThis);
- pile1->IncState();
- }
- int i = 0;
-
- CBotInstr* p = m_Parameters;
- // évalue les paramètres
- // et place les valeurs sur la pile
- // pour pouvoir être interrompu n'importe quand
- if ( p != NULL) while ( TRUE )
- {
- if ( pile2->GivState() == 0 )
- {
- if (!p->Execute(pile2)) return FALSE; // interrompu ici ?
- if (!pile2->SetState(1)) return FALSE; // marque spéciale pour reconnaîre les paramètres
- }
- ppVars[i++] = pile2->GivVar(); // construit la liste des pointeurs
- pile2 = pile2->AddStack(); // de la place sur la pile pour les résultats
- p = p->GivNext();
- if ( p == NULL) break;
- }
- ppVars[i] = NULL;
-
- CBotClass* pClass = CBotClass::Find(m_ClassName);
- CBotVar* pThis = pile1->FindVar(-2);
- CBotVar* pResult = NULL;
- if (m_typRes.GivType() > 0) pResult = CBotVar::Create("", m_typRes);
- if (m_typRes.Eq(CBotTypClass))
- {
-// CBotClass* pClass = CBotClass::Find(m_RetClassName);
- pResult->SetClass(m_typRes.GivClass());
- }
- CBotVar* pRes = pResult;
-
- if ( !pClass->ExecuteMethode(m_MethodeIdent, m_NomMethod,
- pThis, ppVars,
- pResult, pile2, GivToken())) return FALSE; // interrompu
- if (pRes != pResult) delete pRes;
-
- pVar = NULL; // ne retourne pas une valeur par cela
- return pj->Return(pile2); // libère toute la pile
-}
-
-void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, BOOL bMain)
-{
- if ( !bMain ) return;
-
- CBotVar* ppVars[1000];
- CBotStack* pile1 = pile->RestoreStack(this); // une place pour la copie de This
- if ( pile1 == NULL ) return;
-
- CBotStack* pile2 = pile1->RestoreStack(); // et pour les paramètres à venir
- if ( pile2 == NULL ) return;
-
- CBotVar* pThis = pile1->FindVar("this");
-// pThis->SetUniqNum(m_nThisIdent);
- pThis->SetUniqNum(-2);
-
- int i = 0;
-
- CBotInstr* p = m_Parameters;
- // évalue les paramètres
- // et place les valeurs sur la pile
- // pour pouvoir être interrompu n'importe quand
- if ( p != NULL) while ( TRUE )
- {
- if ( pile2->GivState() == 0 )
- {
- p->RestoreState(pile2, TRUE); // interrompu ici !
- return;
- }
- ppVars[i++] = pile2->GivVar(); // construit la liste des pointeurs
- pile2 = pile2->RestoreStack();
- if ( pile2 == NULL ) return;
-
- p = p->GivNext();
- if ( p == NULL) break;
- }
- ppVars[i] = NULL;
-
- CBotClass* pClass = CBotClass::Find(m_ClassName);
- CBotVar* pResult = NULL;
-
- CBotVar* pRes = pResult;
-
- pClass->RestoreMethode(m_MethodeIdent, m_NomMethod,
- pThis, ppVars, pile2);
-}
-
-
-BOOL CBotInstrMethode::Execute(CBotStack* &pj)
-{
- CBotVar* ppVars[1000];
- CBotStack* pile1 = pj->AddStack(this, TRUE); // une place pour la copie de This
-// if ( pile1 == EOX ) return TRUE;
-
- if ( pile1->IfStep() ) return FALSE;
-
- CBotStack* pile2 = pile1->AddStack(); // et pour les paramètres à venir
-
- if ( pile1->GivState() == 0)
- {
- CBotVar* pThis = pile1->CopyVar(m_token);
- // la valeur de This doit être prise avant l'évaluation des paramètres
- // Test.Action( Test = Autre );
- // Action doit agir sur la valeur avant Test = Autre !!
- pThis->SetName("this");
- pile1->AddVar(pThis);
- pile1->IncState();
- }
- int i = 0;
-
- CBotInstr* p = m_Parameters;
- // évalue les paramètres
- // et place les valeurs sur la pile
- // pour pouvoir être interrompu n'importe quand
- if ( p != NULL) while ( TRUE )
- {
- if ( pile2->GivState() == 0 )
- {
- if (!p->Execute(pile2)) return FALSE; // interrompu ici ?
- if (!pile2->SetState(1)) return FALSE; // marque spéciale pour reconnaîre les paramètres
- }
- ppVars[i++] = pile2->GivVar(); // construit la liste des pointeurs
- pile2 = pile2->AddStack(); // de la place sur la pile pour les résultats
- p = p->GivNext();
- if ( p == NULL) break;
- }
- ppVars[i] = NULL;
-
- CBotClass* pClass = CBotClass::Find(m_ClassName);
- CBotVar* pThis = pile1->FindVar("this");
- CBotVar* pResult = NULL;
- if (m_typRes.GivType()>0) pResult = CBotVar::Create("", m_typRes);
- if (m_typRes.Eq(CBotTypClass))
- {
-// CBotClass* pClass = CBotClass::Find(m_RetClassName);
- pResult->SetClass(m_typRes.GivClass());
- }
- CBotVar* pRes = pResult;
-
- if ( !pClass->ExecuteMethode(m_MethodeIdent, m_NomMethod,
- pThis, ppVars,
- pResult, pile2, GivToken())) return FALSE; // interrompu
-
- // met la nouvelle valeur de this à la place de l'ancienne variable
- CBotVar* old = pile1->FindVar(m_token);
- old->Copy(pThis, FALSE);
-
- if (pRes != pResult) delete pRes;
-
- return pj->Return(pile2); // libère toute la pile
+ CBotInstrMethode* inst = new CBotInstrMethode();
+ inst->SetToken(p); // corresponding token
+
+ if (NULL != var)
+ {
+ CBotToken* pp = p;
+ p = p->GivNext();
+
+ if (p->GivType() == ID_OPENPAR)
+ {
+ inst->m_NomMethod = pp->GivString();
+
+ // compiles the list of parameters
+ CBotVar* ppVars[1000];
+ inst->m_Parameters = CompileParams(p, pStack, ppVars);
+
+ if (pStack->IsOk())
+ {
+ CBotClass* pClass = var->GivClass(); // pointer to the class
+ inst->m_ClassName = pClass->GivName(); // name of the class
+ CBotTypResult r = pClass->CompileMethode(inst->m_NomMethod, var, ppVars,
+ pStack, inst->m_MethodeIdent);
+ delete pStack->TokenStack(); // release parameters on the stack
+ inst->m_typRes = r;
+
+ if (inst->m_typRes.GivType() > 20)
+ {
+ pStack->SetError(inst->m_typRes.GivType(), pp);
+ delete inst;
+ return NULL;
+ }
+ // put the result on the stack to have something
+ if (inst->m_typRes.GivType() > 0)
+ {
+ CBotVar* pResult = CBotVar::Create("", inst->m_typRes);
+ if (inst->m_typRes.Eq(CBotTypClass))
+ {
+ pResult->SetClass(inst->m_typRes.GivClass());
+ }
+ pStack->SetVar(pResult);
+ }
+ return inst;
+ }
+ delete inst;
+ return NULL;
+ }
+ }
+ pStack->SetError(1234, p);
+ delete inst;
+ return NULL;
+}
+
+// execute the method call
+
+bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep, bool bExtend)
+{
+ CBotVar* ppVars[1000];
+ CBotStack* pile1 = pj->AddStack(this, true); // a place for the copy of This
+
+ if (pVar->GivPointer() == NULL)
+ {
+ pj->SetError(TX_NULLPT, prevToken);
+ }
+
+ if (pile1->IfStep()) return false;
+
+ CBotStack* pile2 = pile1->AddStack(); // for the next parameters
+
+ if ( pile1->GivState() == 0)
+ {
+ CBotVar* pThis = CBotVar::Create(pVar);
+ pThis->Copy(pVar);
+ // this value should be taken before the evaluation parameters
+ // Test.Action (Test = Other);
+ // action must act on the value before test = Other!
+
+ pThis->SetName("this");
+ pThis->SetUniqNum(-2);
+ pile1->AddVar(pThis);
+ pile1->IncState();
+ }
+ int i = 0;
+
+ CBotInstr* p = m_Parameters;
+ // evaluate the parameters
+ // and places the values on the stack
+ // to be interrupted at any time
+
+ if (p != NULL) while ( true)
+ {
+ if (pile2->GivState() == 0)
+ {
+ if (!p->Execute(pile2)) return false; // interrupted here?
+ if (!pile2->SetState(1)) return false; // special mark to recognize parameters
+ }
+ ppVars[i++] = pile2->GivVar(); // construct the list of pointers
+ pile2 = pile2->AddStack(); // space on the stack for the result
+ p = p->GivNext();
+ if ( p == NULL) break;
+ }
+ ppVars[i] = NULL;
+
+ CBotClass* pClass = CBotClass::Find(m_ClassName);
+ CBotVar* pThis = pile1->FindVar(-2);
+ CBotVar* pResult = NULL;
+ if (m_typRes.GivType() > 0) pResult = CBotVar::Create("", m_typRes);
+ if (m_typRes.Eq(CBotTypClass))
+ {
+ pResult->SetClass(m_typRes.GivClass());
+ }
+ CBotVar* pRes = pResult;
+
+ if ( !pClass->ExecuteMethode(m_MethodeIdent, m_NomMethod,
+ pThis, ppVars,
+ pResult, pile2, GivToken())) return false;
+ if (pRes != pResult) delete pRes;
+
+ pVar = NULL; // does not return value for this
+ return pj->Return(pile2); // release the entire stack
+}
+
+void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, bool bMain)
+{
+ if (!bMain) return;
+
+ CBotVar* ppVars[1000];
+ CBotStack* pile1 = pile->RestoreStack(this); // place for the copy of This
+ if (pile1 == NULL) return;
+
+ CBotStack* pile2 = pile1->RestoreStack(); // and for the parameters coming
+ if (pile2 == NULL) return;
+
+ CBotVar* pThis = pile1->FindVar("this");
+ pThis->SetUniqNum(-2);
+
+ int i = 0;
+
+ CBotInstr* p = m_Parameters;
+ // evaluate the parameters
+ // and places the values on the stack
+ // to be interrupted at any time
+
+ if (p != NULL) while ( true)
+ {
+ if (pile2->GivState() == 0)
+ {
+ p->RestoreState(pile2, true); // interrupted here!
+ return;
+ }
+ ppVars[i++] = pile2->GivVar(); // construct the list of pointers
+ pile2 = pile2->RestoreStack();
+ if (pile2 == NULL) return;
+
+ p = p->GivNext();
+ if ( p == NULL) break;
+ }
+ ppVars[i] = NULL;
+
+ CBotClass* pClass = CBotClass::Find(m_ClassName);
+ CBotVar* pResult = NULL;
+
+ CBotVar* pRes = pResult;
+
+ pClass->RestoreMethode(m_MethodeIdent, m_NomMethod,
+ pThis, ppVars, pile2);
+}
+
+
+bool CBotInstrMethode::Execute(CBotStack* &pj)
+{
+ CBotVar* ppVars[1000];
+ CBotStack* pile1 = pj->AddStack(this, true); // place for the copy of This
+
+ if (pile1->IfStep()) return false;
+
+ CBotStack* pile2 = pile1->AddStack(); // and for the parameters coming
+
+ if ( pile1->GivState() == 0)
+ {
+ CBotVar* pThis = pile1->CopyVar(m_token);
+ // this value should be taken before the evaluation parameters
+ // Test.Action (Test = Other);
+ // Action must act on the value before test = Other!
+ pThis->SetName("this");
+ pile1->AddVar(pThis);
+ pile1->IncState();
+ }
+ int i = 0;
+
+ CBotInstr* p = m_Parameters;
+ // evaluate the parameters
+ // and places the values on the stack
+ // to be interrupted at any time
+ if (p != NULL) while ( true)
+ {
+ if (pile2->GivState() == 0)
+ {
+ if (!p->Execute(pile2)) return false; // interrupted here?
+ if (!pile2->SetState(1)) return false; // special mark to recognize parameters
+ }
+ ppVars[i++] = pile2->GivVar(); // construct the list of pointers
+ pile2 = pile2->AddStack(); // space on the stack for the results
+ p = p->GivNext();
+ if ( p == NULL) break;
+ }
+ ppVars[i] = NULL;
+
+ CBotClass* pClass = CBotClass::Find(m_ClassName);
+ CBotVar* pThis = pile1->FindVar("this");
+ CBotVar* pResult = NULL;
+ if (m_typRes.GivType()>0) pResult = CBotVar::Create("", m_typRes);
+ if (m_typRes.Eq(CBotTypClass))
+ {
+ pResult->SetClass(m_typRes.GivClass());
+ }
+ CBotVar* pRes = pResult;
+
+ if ( !pClass->ExecuteMethode(m_MethodeIdent, m_NomMethod,
+ pThis, ppVars,
+ pResult, pile2, GivToken())) return false; // interupted
+
+ // set the new value of this in place of the old variable
+ CBotVar* old = pile1->FindVar(m_token);
+ old->Copy(pThis, false);
+
+ if (pRes != pResult) delete pRes;
+
+ return pj->Return(pile2); // release the entire stack
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
-// compile une instruction "new"
+// compile an instruction "new"
CBotNew::CBotNew()
{
- name = "CBotNew";
- m_Parameters = NULL;
- m_nMethodeIdent = 0;
-// m_nThisIdent = 0;
+ name = "CBotNew";
+ m_Parameters = NULL;
+ m_nMethodeIdent = 0;
}
CBotNew::~CBotNew()
@@ -3711,362 +3643,321 @@ CBotNew::~CBotNew()
CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack)
{
- CBotToken* pp = p;
- if ( !IsOfType(p, ID_NEW) ) return NULL;
-
- // vérifie que le token est un nom de classe
- if (p->GivType() != TokenTypVar) return NULL;
-
- CBotClass* pClass = CBotClass::Find(p);
- if (pClass == NULL)
- {
- pStack->SetError(TX_BADNEW, p);
- return NULL;
- }
-/* if ( !pClass->m_IsDef )
- {
- pStack->SetError(TX_BADNEW, p);
- return NULL;
- }*/
-
- CBotNew* inst = new CBotNew();
- inst->SetToken(pp);
-
- inst->m_vartoken = p;
- p = p->GivNext();
-
- // crée l'objet sur le "tas"
- // avec un pointeur sur cet objet
- CBotVar* pVar = CBotVar::Create("", pClass);
-// inst->m_nThisIdent = CBotVar::NextUniqNum();
-
- // fait l'appel du créateur
- CBotCStack* pStk = pStack->TokenStack();
- {
- // regarde s'il y a des paramètres
- CBotVar* ppVars[1000];
- inst->m_Parameters = CompileParams(p, pStk, ppVars);
- if ( !pStk->IsOk() ) goto error;
-
- // le constructeur existe-il ?
-// CBotString noname;
- CBotTypResult r = pClass->CompileMethode(pClass->GivName(), pVar, ppVars, pStk, inst->m_nMethodeIdent);
- delete pStk->TokenStack(); // libère le supplément de pile
- int typ = r.GivType();
-
- // s'il n'y a pas de constructeur, et pas de paramètres non plus, c'est ok
- if ( typ == TX_UNDEFCALL && inst->m_Parameters == NULL ) typ = 0;
- pVar->SetInit(TRUE); // marque l'instance comme init
-
- if (typ>20)
- {
- pStk->SetError(typ, inst->m_vartoken.GivEnd());
- goto error;
- }
-
- // si le constructeur n'existe pas, mais qu'il y a des paramètres
- if (typ<0 && inst->m_Parameters != NULL)
- {
- pStk->SetError(TX_NOCONST, &inst->m_vartoken);
- goto error;
- }
-
- // rend le pointeur à l'objet sur la pile
- pStk->SetVar(pVar);
- return pStack->Return(inst, pStk);
- }
+ CBotToken* pp = p;
+ if (!IsOfType(p, ID_NEW)) return NULL;
+
+ // verifies that the token is a class name
+ if (p->GivType() != TokenTypVar) return NULL;
+
+ CBotClass* pClass = CBotClass::Find(p);
+ if (pClass == NULL)
+ {
+ pStack->SetError(TX_BADNEW, p);
+ return NULL;
+ }
+
+ CBotNew* inst = new CBotNew();
+ inst->SetToken(pp);
+
+ inst->m_vartoken = p;
+ p = p->GivNext();
+
+ // creates the object on the "job"
+ // with a pointer to the object
+ CBotVar* pVar = CBotVar::Create("", pClass);
+
+ // do the call of the creator
+ CBotCStack* pStk = pStack->TokenStack();
+ {
+ // check if there are parameters
+ CBotVar* ppVars[1000];
+ inst->m_Parameters = CompileParams(p, pStk, ppVars);
+ if (!pStk->IsOk()) goto error;
+
+ // constructor exist?
+ CBotTypResult r = pClass->CompileMethode(pClass->GivName(), pVar, ppVars, pStk, inst->m_nMethodeIdent);
+ delete pStk->TokenStack(); // release extra stack
+ int typ = r.GivType();
+
+ // if there is no constructor, and no parameters either, it's ok
+ if (typ == TX_UNDEFCALL && inst->m_Parameters == NULL) typ = 0;
+ pVar->SetInit(true); // mark the instance as init
+
+ if (typ>20)
+ {
+ pStk->SetError(typ, inst->m_vartoken.GivEnd());
+ goto error;
+ }
+
+ // if the constructor does not exist, but there are parameters
+ if (typ<0 && inst->m_Parameters != NULL)
+ {
+ pStk->SetError(TX_NOCONST, &inst->m_vartoken);
+ goto error;
+ }
+
+ // makes pointer to the object on the stack
+ pStk->SetVar(pVar);
+ return pStack->Return(inst, pStk);
+ }
error:
- delete inst;
- return pStack->Return(NULL, pStk);
+ delete inst;
+ return pStack->Return(NULL, pStk);
}
-// exécute une instruction "new"
+// executes instruction "new"
-BOOL CBotNew::Execute(CBotStack* &pj)
+bool CBotNew::Execute(CBotStack* &pj)
{
- CBotStack* pile = pj->AddStack(this); //pile principale
-// if ( pile == EOX ) return TRUE;
+ CBotStack* pile = pj->AddStack(this); //main stack
- if ( pile->IfStep() ) return FALSE;
+ if (pile->IfStep()) return false;
- CBotStack* pile1 = pj->AddStack2(); //pile secondaire
+ CBotStack* pile1 = pj->AddStack2(); //secondary stack
- CBotVar* pThis = NULL;
+ CBotVar* pThis = NULL;
- CBotToken* pt = &m_vartoken;
- CBotClass* pClass = CBotClass::Find(pt);
+ CBotToken* pt = &m_vartoken;
+ CBotClass* pClass = CBotClass::Find(pt);
- // crée la variable "this" de type pointeur à l'objet
+ // create the variable "this" pointer type to the stack
- if ( pile->GivState()==0)
- {
- // crée une instance de la classe demandée
- // et initialise le pointeur à cet objet
+ if ( pile->GivState()==0)
+ {
+ // create an instance of the requested class
+ // and initialize the pointer to that object
- pThis = CBotVar::Create("this", pClass);
-// pThis->SetUniqNum( m_nThisIdent ) ;
- pThis->SetUniqNum( -2 ) ;
- pile1->SetVar(pThis); // la place sur la pile1
- pile->IncState();
- }
+ pThis = CBotVar::Create("this", pClass);
+ pThis->SetUniqNum(-2) ;
- // retrouve le pointeur this si on a été interrompu
- if ( pThis == NULL)
- {
- pThis = pile1->GivVar(); // retrouve le pointeur
- }
+ pile1->SetVar(pThis); // place on stack1
+ pile->IncState();
+ }
- // y a-t-il une assignation ou des paramètres (constructeur)
- if ( pile->GivState()==1)
- {
- // évalue le constructeur de l'instance
+ // fetch the this pointer if it was interrupted
+ if ( pThis == NULL)
+ {
+ pThis = pile1->GivVar(); // find the pointer
+ }
- CBotVar* ppVars[1000];
- CBotStack* pile2 = pile;
+ // is there an assignment or parameters (constructor)
+ if ( pile->GivState()==1)
+ {
+ // evaluates the constructor of the instance
- int i = 0;
+ CBotVar* ppVars[1000];
+ CBotStack* pile2 = pile;
- CBotInstr* p = m_Parameters;
- // évalue les paramètres
- // et place les valeurs sur la pile
- // pour pouvoir être interrompu n'importe quand
+ int i = 0;
- if ( p != NULL) while ( TRUE )
- {
- pile2 = pile2->AddStack(); // de la place sur la pile pour les résultats
- if ( pile2->GivState() == 0 )
- {
- if (!p->Execute(pile2)) return FALSE; // interrompu ici ?
- pile2->SetState(1);
- }
- ppVars[i++] = pile2->GivVar();
- p = p->GivNext();
- if ( p == NULL) break;
- }
- ppVars[i] = NULL;
+ CBotInstr* p = m_Parameters;
+ // evaluate the parameters
+ // and places the values on the stack
+ // to be interrupted at any time
- // crée une variable pour le résultat
- CBotVar* pResult = NULL; // constructeurs toujours void
+ if (p != NULL) while ( true)
+ {
+ pile2 = pile2->AddStack(); // space on the stack for the result
+ if (pile2->GivState() == 0)
+ {
+ if (!p->Execute(pile2)) return false; // interrupted here?
+ pile2->SetState(1);
+ }
+ ppVars[i++] = pile2->GivVar();
+ p = p->GivNext();
+ if ( p == NULL) break;
+ }
+ ppVars[i] = NULL;
- if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GivName(),
- pThis, ppVars,
- pResult, pile2, GivToken())) return FALSE; // interrompu
+ // create a variable for the result
+ CBotVar* pResult = NULL; // constructos still void
- pThis->ConstructorSet(); // signale que le constructeur a été appelé
-// pile->Return(pile2); // libère un bout de pile
+ if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GivName(),
+ pThis, ppVars,
+ pResult, pile2, GivToken())) return false; // interrupt
-// pile->IncState();
- }
+ pThis->ConstructorSet(); // indicates that the constructor has been called
+ }
- return pj->Return( pile1 ); // transmet en dessous
+ return pj->Return(pile1); // passes below
}
-void CBotNew::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotNew::RestoreState(CBotStack* &pj, bool bMain)
{
- if ( !bMain ) return;
+ if (!bMain) return;
- CBotStack* pile = pj->RestoreStack(this); //pile principale
- if ( pile == NULL ) return;
+ CBotStack* pile = pj->RestoreStack(this); //primary stack
+ if (pile == NULL) return;
- CBotStack* pile1 = pj->AddStack2(); //pile secondaire
+ CBotStack* pile1 = pj->AddStack2(); //secondary stack
- CBotToken* pt = &m_vartoken;
- CBotClass* pClass = CBotClass::Find(pt);
+ CBotToken* pt = &m_vartoken;
+ CBotClass* pClass = CBotClass::Find(pt);
- // crée la variable "this" de type pointeur à l'objet
+ // create the variable "this" pointer type to the object
- if ( pile->GivState()==0)
- {
- return;
- }
+ if ( pile->GivState()==0)
+ {
+ return;
+ }
- CBotVar* pThis = pile1->GivVar(); // retrouve le pointeur
-// pThis->SetUniqNum( m_nThisIdent );
- pThis->SetUniqNum( -2 );
+ CBotVar* pThis = pile1->GivVar(); // find the pointer
+ pThis->SetUniqNum(-2);
- // y a-t-il une assignation ou des paramètres (constructeur)
- if ( pile->GivState()==1)
- {
- // évalue le constructeur de l'instance
+ // is ther an assignment or parameters (constructor)
+ if ( pile->GivState()==1)
+ {
+ // evaluates the constructor of the instance
- CBotVar* ppVars[1000];
- CBotStack* pile2 = pile;
+ CBotVar* ppVars[1000];
+ CBotStack* pile2 = pile;
- int i = 0;
+ int i = 0;
- CBotInstr* p = m_Parameters;
- // évalue les paramètres
- // et place les valeurs sur la pile
- // pour pouvoir être interrompu n'importe quand
+ CBotInstr* p = m_Parameters;
+ // evaluate the parameters
+ // and places the values on the stack
+ // to be interrupted at any time
- if ( p != NULL) while ( TRUE )
- {
- pile2 = pile2->RestoreStack(); // de la place sur la pile pour les résultats
- if ( pile2 == NULL ) return;
+ if (p != NULL) while ( true)
+ {
+ pile2 = pile2->RestoreStack(); // space on the stack for the result
+ if (pile2 == NULL) return;
- if ( pile2->GivState() == 0 )
- {
- p->RestoreState(pile2, bMain); // interrompu ici !
- return;
- }
- ppVars[i++] = pile2->GivVar();
- p = p->GivNext();
- if ( p == NULL) break;
- }
- ppVars[i] = NULL;
+ if (pile2->GivState() == 0)
+ {
+ p->RestoreState(pile2, bMain); // interrupt here!
+ return;
+ }
+ ppVars[i++] = pile2->GivVar();
+ p = p->GivNext();
+ if ( p == NULL) break;
+ }
+ ppVars[i] = NULL;
- pClass->RestoreMethode(m_nMethodeIdent, m_vartoken.GivString(), pThis,
- ppVars, pile2) ; // interrompu ici !
- }
+ pClass->RestoreMethode(m_nMethodeIdent, m_vartoken.GivString(), pThis,
+ ppVars, pile2) ; // interrupt here!
+ }
}
/////////////////////////////////////////////////////////////
-// regarde si deux résultats sont compatibles pour faire une opération
+// check if two results are consistent to make an operation
-BOOL TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op )
+bool TypeCompatible(CBotTypResult& type1, CBotTypResult& type2, int op)
{
- int t1 = type1.GivType();
- int t2 = type2.GivType();
+ int t1 = type1.GivType();
+ int t2 = type2.GivType();
- int max = (t1 > t2) ? t1 : t2;
+ int max = (t1 > t2) ? t1 : t2;
- if ( max == 99 ) return FALSE; // un résultat est void ?
+ if (max == 99) return false; // result is void?
- // cas particulier pour les concaténation de chaînes
- if (op == ID_ADD && max >= CBotTypString) return TRUE;
- if (op == ID_ASSADD && max >= CBotTypString) return TRUE;
- if (op == ID_ASS && t1 == CBotTypString) return TRUE;
+ // special case for strin concatenation
+ if (op == ID_ADD && max >= CBotTypString) return true;
+ if (op == ID_ASSADD && max >= CBotTypString) return true;
+ if (op == ID_ASS && t1 == CBotTypString) return true;
- if ( max >= CBotTypBoolean )
- {
- if ( (op == ID_EQ || op == ID_NE) &&
- (t1 == CBotTypPointer && t2 == CBotTypNullPointer)) return TRUE;
- if ( (op == ID_EQ || op == ID_NE || op == ID_ASS) &&
- (t2 == CBotTypPointer && t1 == CBotTypNullPointer)) return TRUE;
- if ( (op == ID_EQ || op == ID_NE) &&
- (t1 == CBotTypArrayPointer && t2 == CBotTypNullPointer)) return TRUE;
- if ( (op == ID_EQ || op == ID_NE || op == ID_ASS) &&
- (t2 == CBotTypArrayPointer && t1 == CBotTypNullPointer)) return TRUE;
- if (t2 != t1) return FALSE;
- if (t1 == CBotTypArrayPointer) return type1.Compare(type2);
- if (t1 == CBotTypPointer ||
- t1 == CBotTypClass ||
- t1 == CBotTypIntrinsic )
- {
- CBotClass* c1 = type1.GivClass();
- CBotClass* c2 = type2.GivClass();
+ if (max >= CBotTypBoolean)
+ {
+ if ( (op == ID_EQ || op == ID_NE) &&
+ (t1 == CBotTypPointer && t2 == CBotTypNullPointer)) return true;
+ if ( (op == ID_EQ || op == ID_NE || op == ID_ASS) &&
+ (t2 == CBotTypPointer && t1 == CBotTypNullPointer)) return true;
+ if ( (op == ID_EQ || op == ID_NE) &&
+ (t1 == CBotTypArrayPointer && t2 == CBotTypNullPointer)) return true;
+ if ( (op == ID_EQ || op == ID_NE || op == ID_ASS) &&
+ (t2 == CBotTypArrayPointer && t1 == CBotTypNullPointer)) return true;
+ if (t2 != t1) return false;
+ if (t1 == CBotTypArrayPointer) return type1.Compare(type2);
+ if (t1 == CBotTypPointer ||
+ t1 == CBotTypClass ||
+ t1 == CBotTypIntrinsic )
+ {
+ CBotClass* c1 = type1.GivClass();
+ CBotClass* c2 = type2.GivClass();
- return c1->IsChildOf(c2) || c2->IsChildOf(c1);
- // accepte le caste à l'envers,
- // l'opération sera refusée à l'exécution si le pointeur n'est pas compatible
- }
+ return c1->IsChildOf(c2) || c2->IsChildOf(c1);
+ // accept the case in reverse
+ // the transaction will be denied at runtime if the pointer is not
+ // compatible
+ }
- return TRUE;
- }
+ return true;
+ }
- type1.SetType(max);
- type2.SetType(max);
- return TRUE;
+ type1.SetType(max);
+ type2.SetType(max);
+ return true;
}
-// regarde si deux variables sont compatible pour un passage de paramètre
+// check if two variables are compatible for parameter passing
-BOOL TypesCompatibles( const CBotTypResult& type1, const CBotTypResult& type2 )
+bool TypesCompatibles(const CBotTypResult& type1, const CBotTypResult& type2)
{
- int t1 = type1.GivType();
- int t2 = type2.GivType();
+ int t1 = type1.GivType();
+ int t2 = type2.GivType();
- if ( t1 == CBotTypIntrinsic ) t1 = CBotTypClass;
- if ( t2 == CBotTypIntrinsic ) t2 = CBotTypClass;
+ if (t1 == CBotTypIntrinsic) t1 = CBotTypClass;
+ if (t2 == CBotTypIntrinsic) t2 = CBotTypClass;
- int max = (t1 > t2) ? t1 : t2;
+ int max = (t1 > t2) ? t1 : t2;
- if ( max == 99 ) return FALSE; // un résultat est void ?
+ if (max == 99) return false; // result is void?
- if ( max >= CBotTypBoolean )
- {
- if ( t2 != t1 ) return FALSE;
+ if (max >= CBotTypBoolean)
+ {
+ if (t2 != t1) return false;
- if ( max == CBotTypArrayPointer )
- return TypesCompatibles(type1.GivTypElem(), type2.GivTypElem());
+ if (max == CBotTypArrayPointer)
+ return TypesCompatibles(type1.GivTypElem(), type2.GivTypElem());
- if ( max == CBotTypClass || max == CBotTypPointer )
- return type1.GivClass() == type2.GivClass() ;
+ if (max == CBotTypClass || max == CBotTypPointer)
+ return type1.GivClass() == type2.GivClass() ;
- return TRUE ;
- }
- return TRUE;
+ return true ;
+ }
+ return true;
}
/////////////////////////////////////////////////////////////////////////////////////
-// Gestion des fichiers
+// file management
+
+// necessary because it is not possible to do the fopen in the main program
+// fwrite and fread in a dll or using the FILE * returned.
-// nécessaire car il n'est pas possible de faire le fopen dans le programme principal
-// et les fwrite ou fread dans une dll en utilisant le FILE* rendu.
FILE* fOpen(const char* name, const char* mode)
{
- return fopen(name, mode);
+ return fopen(name, mode);
}
int fClose(FILE* filehandle)
{
- return fclose(filehandle);
+ return fclose(filehandle);
}
size_t fWrite(const void *buffer, size_t elemsize, size_t length, FILE* filehandle)
{
- return fwrite(buffer, elemsize, length, filehandle);
+ return fwrite(buffer, elemsize, length, filehandle);
}
size_t fRead(void *buffer, size_t elemsize, size_t length, FILE* filehandle)
{
- return fread(buffer, elemsize, length, filehandle);
+ return fread(buffer, elemsize, length, filehandle);
}
size_t fWrite(const void *buffer, size_t length, FILE* filehandle)
{
- return fwrite(buffer, 1, length, filehandle);
+ return fwrite(buffer, 1, length, filehandle);
}
size_t fRead(void *buffer, size_t length, FILE* filehandle)
{
- return fread(buffer, 1, length, filehandle);
+ return fread(buffer, 1, length, filehandle);
}
////////////////////////////////////////
-
-#if FALSE
-
-CBotString num(int n)
-{
- CBotString s;
- if ( n<0 ) {n = -n; s += "-";}
- if ( n > 9 )
- {
- s += num(n/10);
- }
- s += '0' + n%10;
- return s;
-}
-
-extern void DEBUG( const char* text, int val, CBotStack* pile )
-{
- CBotProgram* p = pile->GivBotCall(TRUE);
- if ( !p->m_bDebugDD ) return;
-
- FILE* pf = fopen("CbotDebug.txt", "a");
-
- fputs( text, pf );
-
- CBotString v = " " + num(val) + "\n";
- fputs( v, pf );
-
- fclose( pf);
-}
-
-#endif
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index e28bbee..3b7d7e8 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -13,195 +13,289 @@
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.////////////////////////////////////////////////////////////////////
-// interpréteur pour le language CBot du jeu COLOBOT
+/**
+ * \file CBot.h
+ * \brief Interpreter of the language CBot for COLOBOT game
+ */
-// dernière révision : 03/10/2002 DD
-
-#define EXTENDS TRUE
#include "resource.h"
-#include "CBotDll.h" // définitions publiques
-#include "CBotToken.h" // gestion des tokens
+#include "CBotDll.h" // public definitions
+#include "CBotToken.h" // token management
-#define STACKRUN TRUE // reprise de l'exécution direct sur une routine suspendue
-#define STACKMEM TRUE // préréserve la mémoire pour la pile d'exécution
-#define MAXSTACK 990 // taille du stack réservé
+#define STACKRUN true /// \def return execution directly on a suspended routine
+#define STACKMEM true /// \def preserve memory for the execution stack
+#define MAXSTACK 990 /// \def stack size reserved
-#define EOX (CBotStack*)-1 // marqueur condition spéciale
+#define EOX (CBotStack*)-1 /// \def tag special condition
// fix for MSVC instruction __asm int 3 (setting a trap)
-#ifdef __MINGW32__
-#define ASM_TRAP() asm("int $3");
+#if defined(__MINGW32__) || defined(__GNUC__)
+#define ASM_TRAP() asm("int $3");
#else
-#define ASM_TRAP() __asm int 3;
+#define ASM_TRAP() __asm int 3;
#endif
/////////////////////////////////////////////////////////////////////
-// résumé des classes utilisées, définies ci-après
-
-class CBotCompExpr; // une expression telle que
- // () <= ()
-class CBotAddExpr; // une expression telle que
- // () + ()
-class CBotParExpr; // un élément de base ou entre parenthèse
- // Toto.truc
- // 12.5
- // "chaine"
- // ( expression )
-class CBotExprVar; // un nom de variable tel que
- // Toto
- // chose.truc.machin
-class CBotWhile; // while (...) {...};
-class CBotIf; // if (...) {...} else {...}
-class CBotDefParam; // liste de paramètres d'une fonction
-class CBotRepeat; // repeat (nb) {...}
+// 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
+class CBotRepeat; // repeat (nb) {...}
////////////////////////////////////////////////////////////////////////
-// Gestion de la pile d'exécution
+// Management of the execution stack
////////////////////////////////////////////////////////////////////////
-// en fait, en externe, la seule chose qu'il est possible de faire
-// c'est de créer une instance d'une pile
-// pour l'utiliser pour la routine CBotProgram::Execute(CBotStack)
+// actually, externally, the only thing he 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
{
-private:
- CBotStack* m_next;
- CBotStack* m_next2;
- CBotStack* m_prev;
- friend class CBotInstArray;
-
-#ifdef _DEBUG
- int m_index;
+public:
+#if STACKMEM
+ /**
+ * \brief FirstStack Allocate first stack
+ * \return pointer to created stack
+ */
+ static CBotStack * FirstStack();
+
+ /** \brief Delete Remove current stack */
+ void Delete();
#endif
- int m_state;
- int m_step;
- static int m_error;
- static int m_start;
- static int m_end;
- static
- CBotVar* m_retvar; // résultat d'un return
-
- CBotVar* m_var; // résultat des opérations
- CBotVar* m_listVar; // les variables déclarées à ce niveau
-
- BOOL m_bBlock; // fait partie d'un bloc (variables sont locales à ce bloc)
- BOOL m_bOver; // limites de la pile ?
-// BOOL m_bDontDelete; // spécial, ne pas détruire les variables au delete
- CBotProgram* m_prog; // les fonctions définies par user
-
- static
- int m_initimer;
- static
- int m_timer;
- static
- CBotString m_labelBreak;
- static
- void* m_pUser;
-
- CBotInstr* m_instr; // l'instruction correspondante
- BOOL m_bFunc; // une entrée d'une fonction ?
- CBotCall* m_call; // point de reprise dans un call extern
- friend class CBotTry;
-public:
-#if STACKMEM
- static
- CBotStack* FirstStack();
- void Delete();
+ /**
+ * \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 GivError Get error number of the stack
+ * \param [out] start beginning of the stack
+ * \param [out] end end of stack
+ * \return error number
+ */
+ int GivError(int& start, int& end);
+
+ /**
+ * \brief GivError Get error number
+ * \return eror number
+ */
+ int GivError();// 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 GivType 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 GivType(int mode = 0);
+
+ /**
+ * \brief Gives 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 GivTypResult(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& Token, 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, NULL if not found
+ */
+ CBotVar* CopyVar(CBotToken& Token, bool bUpdate = false);
+
+
+ CBotStack* AddStack(CBotInstr* instr = NULL, bool bBlock = false); // étend le stack
+ CBotStack* AddStackEOX(CBotCall* instr = NULL, bool bBlock = false); // étend le stack
+ CBotStack* RestoreStack(CBotInstr* instr = NULL);
+ CBotStack* RestoreStackEOX(CBotCall* instr = NULL);
+
+ CBotStack* AddStack2(bool bBlock = false); // étend le stack
+ bool Return(CBotStack* pFils); // transmet le résultat au dessus
+ bool ReturnKeep(CBotStack* pFils); // transmet le résultat sans réduire la pile
+ bool BreakReturn(CBotStack* pfils, const char* name = NULL);
+ // en cas de break éventuel
+ bool IfContinue(int state, const char* name);
+ // ou de "continue"
+
+ bool IsOk();
+
+ bool SetState(int n, int lim = -10); // sélectionne un état
+ int GivState(); // dans quel état j'ère ?
+ bool IncState(int lim = -10); // passe à l'état suivant
+ bool IfStep(); // faire du pas à pas ?
+ bool Execute();
+
+ void SetVar( CBotVar* var );
+ void SetCopyVar( CBotVar* var );
+ CBotVar* GivVar();
+ CBotVar* GivCopyVar();
+ CBotVar* GivPtVar();
+ bool GivRetVar(bool bRet);
+ long GivVal();
+
+ void SetStartError(int pos);
+ void SetError(int n, CBotToken* token = NULL);
+ void SetPosError(CBotToken* token);
+ void ResetError(int n, int start, int end);
+ void SetBreak(int val, const char* name);
+
+ void SetBotCall(CBotProgram* p);
+ CBotProgram* GivBotCall(bool bFirst = false);
+ void* GivPUser();
+ bool GivBlock();
+
+
+ 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* GivStackVars(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
- CBotStack(CBotStack* ppapa);
- ~CBotStack();
- BOOL StackOver();
-
- int GivError(int& start, int& end);
- int GivError(); // rend le numéro d'erreur retourné
-
- void Reset(void* pUser); // plus d'erreur, timer au début
- void SetType(CBotTypResult& type); // détermine le type
- int GivType(int mode = 0); // donne le type de valeur sur le stack
- CBotTypResult GivTypResult(int mode = 0); // donne le type complet de valeur sur le stack
-
-// void AddVar(CBotVar* p, BOOL bDontDelete=FALSE); // ajoute une variable locale
- void AddVar(CBotVar* p); // ajoute une variable locale
-// void RestoreVar(CBotVar* pVar);
-
- CBotVar* FindVar(CBotToken* &p, BOOL bUpdate = FALSE,
- BOOL bModif = FALSE); // trouve une variable
- CBotVar* FindVar(CBotToken& Token, BOOL bUpdate = FALSE,
- BOOL bModif = FALSE);
- CBotVar* FindVar(const char* name);
- CBotVar* FindVar(long ident, BOOL bUpdate = FALSE,
- BOOL bModif = FALSE);
-
- CBotVar* CopyVar(CBotToken& Token, BOOL bUpdate = FALSE); // trouve et rend une copie
-
-
- CBotStack* AddStack(CBotInstr* instr = NULL, BOOL bBlock = FALSE); // étend le stack
- CBotStack* AddStackEOX(CBotCall* instr = NULL, BOOL bBlock = FALSE); // étend le stack
- CBotStack* RestoreStack(CBotInstr* instr = NULL);
- CBotStack* RestoreStackEOX(CBotCall* instr = NULL);
-
- CBotStack* AddStack2(BOOL bBlock = FALSE); // étend le stack
- BOOL Return(CBotStack* pFils); // transmet le résultat au dessus
- BOOL ReturnKeep(CBotStack* pFils); // transmet le résultat sans réduire la pile
- BOOL BreakReturn(CBotStack* pfils, const char* name = NULL);
- // en cas de break éventuel
- BOOL IfContinue(int state, const char* name);
- // ou de "continue"
-
- BOOL IsOk();
-
- BOOL SetState(int n, int lim = -10); // sélectionne un état
- int GivState(); // dans quel état j'ère ?
- BOOL IncState(int lim = -10); // passe à l'état suivant
- BOOL IfStep(); // faire du pas à pas ?
- BOOL Execute();
-
- void SetVar( CBotVar* var );
- void SetCopyVar( CBotVar* var );
- CBotVar* GivVar();
- CBotVar* GivCopyVar();
- CBotVar* GivPtVar();
- BOOL GivRetVar(BOOL bRet);
- long GivVal();
-
- void SetStartError(int pos);
- void SetError(int n, CBotToken* token = NULL);
- void SetPosError(CBotToken* token);
- void ResetError(int n, int start, int end);
- void SetBreak(int val, const char* name);
-
- void SetBotCall(CBotProgram* p);
- CBotProgram* GivBotCall(BOOL bFirst = FALSE);
- void* GivPUser();
- BOOL GivBlock();
-
-
-// BOOL ExecuteCall(CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype);
- 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* GivStackVars(const char* &FunctionName, int level);
-
- int m_temp;
+ int m_state;
+ int m_step;
+ static int m_error;
+ static int m_start;
+ static int m_end;
+ static
+ CBotVar* m_retvar; // résultat d'un return
+
+ CBotVar* m_var; // résultat des opérations
+ CBotVar* m_listVar; // les variables déclarées à ce niveau
+
+ bool m_bBlock; // fait partie d'un bloc (variables sont locales à ce bloc)
+ bool m_bOver; // limites de la pile ?
+// bool m_bDontDelete; // spécial, ne pas détruire les variables au delete
+ CBotProgram* m_prog; // les fonctions définies par user
+
+ static
+ int m_initimer;
+ static
+ int m_timer;
+ static
+ CBotString m_labelBreak;
+ static
+ void* m_pUser;
+
+ CBotInstr* m_instr; // l'instruction correspondante
+ bool m_bFunc; // une entrée d'une fonction ?
+ CBotCall* m_call; // point de reprise dans un call extern
+ friend class CBotTry;
};
// les routines inline doivent être déclarées dans le fichier .h
-inline BOOL CBotStack::IsOk()
+inline bool CBotStack::IsOk()
{
return (m_error == 0);
}
@@ -213,7 +307,7 @@ inline int CBotStack::GivState()
inline int CBotStack::GivError()
{
- return m_error;
+ return m_error;
}
////////////////////////////////////////////////////////////////////////
@@ -224,340 +318,348 @@ inline int CBotStack::GivError()
class CBotCStack
{
private:
- CBotCStack* m_next;
- CBotCStack* m_prev;
+ CBotCStack* m_next;
+ CBotCStack* m_prev;
- static
- int m_error;
- static
- int m_end;
- int m_start;
+ static
+ int m_error;
+ static
+ int m_end;
+ int m_start;
- CBotVar* m_var; // résultat des opérations
+ CBotVar* m_var; // résultat des opérations
- BOOL m_bBlock; // fait partie d'un bloc (variables sont locales à ce bloc)
- CBotVar* m_listVar;
+ bool m_bBlock; // fait partie d'un bloc (variables sont locales à ce bloc)
+ CBotVar* m_listVar;
- static
- CBotProgram* m_prog; // liste des fonctions compilées
- static
- CBotTypResult m_retTyp;
-// static
-// CBotToken* m_retClass;
+ static
+ CBotProgram* m_prog; // liste des fonctions compilées
+ static
+ CBotTypResult m_retTyp;
+// static
+// CBotToken* m_retClass;
public:
- CBotCStack(CBotCStack* ppapa);
- ~CBotCStack();
-
- BOOL IsOk();
- int GivError();
- int GivError(int& start, int& end);
- // rend le numéro d'erreur retourné
-
- void SetType(CBotTypResult& type);// détermine le type
- CBotTypResult GivTypResult(int mode = 0); // donne le type de valeur sur le stack
- int GivType(int mode = 0); // donne le type de valeur sur le stack
- CBotClass* GivClass(); // donne la classe de la valeur sur le stack
-
- void AddVar(CBotVar* p); // ajoute une variable locale
- CBotVar* FindVar(CBotToken* &p); // trouve une variable
- CBotVar* FindVar(CBotToken& Token);
- BOOL CheckVarLocal(CBotToken* &pToken);
- CBotVar* CopyVar(CBotToken& Token); // trouve et rend une copie
-
- CBotCStack* TokenStack(CBotToken* pToken = NULL, BOOL bBlock = FALSE);
- CBotInstr* Return(CBotInstr* p, CBotCStack* pParent); // transmet le résultat au dessus
- CBotFunction* ReturnFunc(CBotFunction* p, CBotCStack* pParent); // transmet le résultat au dessus
-
- void SetVar( CBotVar* var );
- void SetCopyVar( CBotVar* var );
- CBotVar* GivVar();
-
- void SetStartError(int pos);
- void SetError(int n, int pos);
- void SetError(int n, CBotToken* p);
- void ResetError(int n, int start, int end);
-
- void SetRetType(CBotTypResult& type);
- CBotTypResult GivRetType();
-
-// void SetBotCall(CBotFunction* &pFunc);
- void SetBotCall(CBotProgram* p);
- CBotProgram* GivBotCall();
- CBotTypResult CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent);
- BOOL CheckCall(CBotToken* &pToken, CBotDefParam* pParam);
-
- BOOL NextToken(CBotToken* &p);
+ CBotCStack(CBotCStack* ppapa);
+ ~CBotCStack();
+
+ bool IsOk();
+ int GivError();
+ int GivError(int& start, int& end);
+ // rend le numéro d'erreur retourné
+
+ void SetType(CBotTypResult& type);// détermine le type
+ CBotTypResult GivTypResult(int mode = 0); // donne le type de valeur sur le stack
+ int GivType(int mode = 0); // donne le type de valeur sur le stack
+ CBotClass* GivClass(); // donne la classe de la valeur sur le stack
+
+ void AddVar(CBotVar* p); // ajoute une variable locale
+ CBotVar* FindVar(CBotToken* &p); // trouve une variable
+ CBotVar* FindVar(CBotToken& Token);
+ bool CheckVarLocal(CBotToken* &pToken);
+ CBotVar* CopyVar(CBotToken& Token); // trouve et rend une copie
+
+ CBotCStack* TokenStack(CBotToken* pToken = NULL, bool bBlock = false);
+ CBotInstr* Return(CBotInstr* p, CBotCStack* pParent); // transmet le résultat au dessus
+ CBotFunction* ReturnFunc(CBotFunction* p, CBotCStack* pParent); // transmet le résultat au dessus
+
+ void SetVar( CBotVar* var );
+ void SetCopyVar( CBotVar* var );
+ CBotVar* GivVar();
+
+ void SetStartError(int pos);
+ void SetError(int n, int pos);
+ void SetError(int n, CBotToken* p);
+ void ResetError(int n, int start, int end);
+
+ void SetRetType(CBotTypResult& type);
+ CBotTypResult GivRetType();
+
+// void SetBotCall(CBotFunction* &pFunc);
+ void SetBotCall(CBotProgram* p);
+ CBotProgram* GivBotCall();
+ 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);
+extern bool SaveVar(FILE* pf, CBotVar* pVar);
/////////////////////////////////////////////////////////////////////
-// classes définissant une instruction
+// classes defining an instruction
class CBotInstr
{
private:
- static
- CBotStringArray
- m_labelLvl;
+ static
+ CBotStringArray
+ m_labelLvl;
protected:
- CBotToken m_token; // conserve le token
- CBotString name; // debug
- CBotInstr* m_next; // instructions chaînées
- CBotInstr* m_next2b; // seconde liste pour définition en chaîne
- CBotInstr* m_next3; // troisième liste pour les indices et champs
- CBotInstr* m_next3b; // nécessaire pour la déclaration des tableaux
+ 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
/*
- par exemple, le programme suivant
- int x[]; x[1] = 4;
- int y[x[1]][10], z;
- va généré
- 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->...
+ 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;
+ static
+ int m_LoopLvl;
+ friend class CBotClassInst;
+ friend class CBotInt;
+ friend class CBotListArray;
public:
- CBotInstr();
- virtual
- ~CBotInstr();
-
- DllExport//debug
- 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);
- void SetToken(CBotString* name, int start=0, int end=0);
- int GivTokenType();
- CBotToken* GivToken();
-
- void AddNext(CBotInstr* n);
- CBotInstr* GivNext();
- void AddNext3(CBotInstr* n);
- CBotInstr* GivNext3();
- void AddNext3b(CBotInstr* n);
- CBotInstr* GivNext3b();
-
- static
- void IncLvl(CBotString& label);
- static
- void IncLvl();
- static
- void DecLvl();
- static
- BOOL ChkLvl(const CBotString& label, int type);
-
- BOOL IsOfClass(CBotString name);
+ 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);
+ int GivTokenType();
+ CBotToken* GivToken();
+
+ void AddNext(CBotInstr* n);
+ CBotInstr* GivNext();
+ void AddNext3(CBotInstr* n);
+ CBotInstr* GivNext3();
+ void AddNext3b(CBotInstr* n);
+ CBotInstr* GivNext3b();
+
+ 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; // la condition
- CBotInstr* m_Block; // les instructions
- CBotString m_label; // une étiquette s'il y a
+ CBotInstr* m_Condition; // la condition
+ CBotInstr* m_Block; // les instructions
+ CBotString m_label; // une étiquette s'il y a
public:
- CBotWhile();
- ~CBotWhile();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotWhile();
+ ~CBotWhile();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
class CBotRepeat : public CBotInstr
{
private:
- CBotInstr* m_NbIter; // le nombre d'itération
- CBotInstr* m_Block; // les instructions
- CBotString m_label; // une étiquette s'il y a
+ /// Number of iterations
+ CBotInstr* m_NbIter;
+
+ /// Instructions
+ CBotInstr* m_Block;
+
+ /// Label
+ CBotString m_label; // une étiquette s'il y a
public:
- CBotRepeat();
- ~CBotRepeat();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotRepeat();
+ ~CBotRepeat();
+
+ /// Static method used for compilation
+ static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+
+ /// Execute
+ bool Execute(CBotStack* &pj);
+
+ /// Restore state
+ void RestoreState(CBotStack* &pj, bool bMain);
};
class CBotDo : public CBotInstr
{
private:
- CBotInstr* m_Block; // les instructions
- CBotInstr* m_Condition; // la condition
- CBotString m_label; // une étiquette s'il y a
+ CBotInstr* m_Block; // les instructions
+ CBotInstr* m_Condition; // la condition
+ CBotString m_label; // une étiquette s'il y a
public:
- CBotDo();
- ~CBotDo();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotDo();
+ ~CBotDo();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
class CBotFor : public CBotInstr
{
private:
- CBotInstr* m_Init; // intruction initiale
- CBotInstr* m_Test; // la condition de test
- CBotInstr* m_Incr; // instruction pour l'incrément
- CBotInstr* m_Block; // les instructions
- CBotString m_label; // une étiquette s'il y a
+ CBotInstr* m_Init; // intruction initiale
+ CBotInstr* m_Test; // la condition de test
+ CBotInstr* m_Incr; // instruction pour l'incrément
+ CBotInstr* m_Block; // les instructions
+ CBotString m_label; // une étiquette s'il y a
public:
- CBotFor();
- ~CBotFor();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotFor();
+ ~CBotFor();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
class CBotBreak : public CBotInstr
{
private:
- CBotString m_label; // une étiquette s'il y a
+ CBotString m_label; // une étiquette s'il y a
public:
- CBotBreak();
- ~CBotBreak();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotBreak();
+ ~CBotBreak();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
class CBotReturn : public CBotInstr
{
private:
- CBotInstr* m_Instr; // le paramètre à retourner
+ CBotInstr* m_Instr; // le paramètre à retourner
public:
- CBotReturn();
- ~CBotReturn();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotReturn();
+ ~CBotReturn();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
class CBotSwitch : public CBotInstr
{
private:
- CBotInstr* m_Value; // value à chercher
- CBotInstr* m_Block; // les instructions
+ CBotInstr* m_Value; // value à chercher
+ CBotInstr* m_Block; // les instructions
public:
- CBotSwitch();
- ~CBotSwitch();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotSwitch();
+ ~CBotSwitch();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
class CBotCase : public CBotInstr
{
private:
- CBotInstr* m_Value; // valeur à comparer
+ CBotInstr* m_Value; // valeur à comparer
public:
- CBotCase();
- ~CBotCase();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
- BOOL CompCase(CBotStack* &pj, int val);
+ CBotCase();
+ ~CBotCase();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
+ bool CompCase(CBotStack* &pj, int val);
};
class CBotCatch : public CBotInstr
{
private:
- CBotInstr* m_Block; // les instructions
- CBotInstr* m_Cond; // la condition
- CBotCatch* m_next; // le catch suivant
- friend class CBotTry;
+ CBotInstr* m_Block; // les instructions
+ CBotInstr* m_Cond; // la condition
+ CBotCatch* m_next; // le catch suivant
+ friend class CBotTry;
public:
- CBotCatch();
- ~CBotCatch();
- static
- CBotCatch* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL TestCatch(CBotStack* &pj, int val);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
- void RestoreCondState(CBotStack* &pj, BOOL bMain);
+ CBotCatch();
+ ~CBotCatch();
+ static
+ CBotCatch* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool TestCatch(CBotStack* &pj, int val);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
+ void RestoreCondState(CBotStack* &pj, bool bMain);
};
class CBotTry : public CBotInstr
{
private:
- CBotInstr* m_Block; // les instructions
- CBotCatch* m_ListCatch; // les catches
- CBotInstr* m_FinalInst; // instruction finale
+ CBotInstr* m_Block; // les instructions
+ CBotCatch* m_ListCatch; // les catches
+ CBotInstr* m_FinalInst; // instruction finale
public:
- CBotTry();
- ~CBotTry();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotTry();
+ ~CBotTry();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
class CBotThrow : public CBotInstr
{
private:
- CBotInstr* m_Value; // la valeur à envoyer
+ CBotInstr* m_Value; // la valeur à envoyer
public:
- CBotThrow();
- ~CBotThrow();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotThrow();
+ ~CBotThrow();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
@@ -566,28 +668,28 @@ class CBotStartDebugDD : public CBotInstr
private:
public:
- CBotStartDebugDD();
- ~CBotStartDebugDD();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
+ CBotStartDebugDD();
+ ~CBotStartDebugDD();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
};
class CBotIf : public CBotInstr
{
private:
- CBotInstr* m_Condition; // la condition
- CBotInstr* m_Block; // les instructions
- CBotInstr* m_BlockElse; // les instructions
+ CBotInstr* m_Condition; // la condition
+ CBotInstr* m_Block; // les instructions
+ CBotInstr* m_BlockElse; // les instructions
public:
- CBotIf();
- ~CBotIf();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotIf();
+ ~CBotIf();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
@@ -596,17 +698,17 @@ public:
class CBotInt : public CBotInstr
{
private:
- CBotInstr* m_var; // la variable à initialiser
- CBotInstr* m_expr; // la valeur à mettre, s'il y a
-/// CBotInstr* m_next; // plusieurs définitions enchaînées
+ CBotInstr* m_var; // la variable à initialiser
+ CBotInstr* m_expr; // la valeur à mettre, s'il y a
+/// CBotInstr* m_next; // plusieurs définitions enchaînées
public:
- CBotInt();
- ~CBotInt();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, BOOL cont = FALSE, BOOL noskip = FALSE);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotInt();
+ ~CBotInt();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip = false);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
// définition d'un tableau
@@ -614,19 +716,19 @@ public:
class CBotInstArray : public CBotInstr
{
private:
- CBotInstr* m_var; // la variable à initialiser
- CBotInstr* m_listass; // liste d'assignations pour le tableau
- CBotTypResult
- m_typevar; // type d'éléments
-// CBotString m_ClassName;
+ CBotInstr* m_var; // la variable à initialiser
+ CBotInstr* m_listass; // liste d'assignations pour le tableau
+ CBotTypResult
+ m_typevar; // type d'éléments
+// CBotString m_ClassName;
public:
- CBotInstArray();
- ~CBotInstArray();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotInstArray();
+ ~CBotInstArray();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
@@ -636,22 +738,22 @@ public:
class CBotListArray : public CBotInstr
{
private:
- CBotInstr* m_expr; // expression pour un élément
- // les autres sont chaînés avec CBotInstr::m_next3;
+ CBotInstr* m_expr; // expression pour un élément
+ // les autres sont chaînés avec CBotInstr::m_next3;
public:
- CBotListArray();
- ~CBotListArray();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);
- BOOL Execute(CBotStack* &pj, CBotVar* pVar);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotListArray();
+ ~CBotListArray();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);
+ bool Execute(CBotStack* &pj, CBotVar* pVar);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
class CBotEmpty : public CBotInstr
{
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
// définition d'un booléen
@@ -659,16 +761,16 @@ class CBotEmpty : public CBotInstr
class CBotBoolean : public CBotInstr
{
private:
- CBotInstr* m_var; // la variable à initialiser
- CBotInstr* m_expr; // la valeur à mettre, s'il y a
+ CBotInstr* m_var; // la variable à initialiser
+ CBotInstr* m_expr; // la valeur à mettre, s'il y a
public:
- CBotBoolean();
- ~CBotBoolean();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, BOOL cont = FALSE, BOOL noskip=FALSE);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotBoolean();
+ ~CBotBoolean();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
@@ -677,16 +779,16 @@ public:
class CBotFloat : public CBotInstr
{
private:
- CBotInstr* m_var; // la variable à initialiser
- CBotInstr* m_expr; // la valeur à mettre, s'il y a
+ CBotInstr* m_var; // la variable à initialiser
+ CBotInstr* m_expr; // la valeur à mettre, s'il y a
public:
- CBotFloat();
- ~CBotFloat();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, BOOL cont = FALSE, BOOL noskip=FALSE);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotFloat();
+ ~CBotFloat();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
// définition d'un elément string
@@ -694,16 +796,16 @@ public:
class CBotIString : public CBotInstr
{
private:
- CBotInstr* m_var; // la variable à initialiser
- CBotInstr* m_expr; // la valeur à mettre, s'il y a
+ CBotInstr* m_var; // la variable à initialiser
+ CBotInstr* m_expr; // la valeur à mettre, s'il y a
public:
- CBotIString();
- ~CBotIString();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, BOOL cont = FALSE, BOOL noskip=FALSE);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotIString();
+ ~CBotIString();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
// définition d'un elément dans une classe quelconque
@@ -711,20 +813,20 @@ public:
class CBotClassInst : public CBotInstr
{
private:
- CBotInstr* m_var; // la variable à initialiser
- CBotClass* m_pClass; // référence à la classe
- CBotInstr* m_Parameters; // les paramètres à évaluer pour le constructeur
- CBotInstr* m_expr; // la valeur à mettre, s'il y a
- BOOL m_hasParams; // il y a des paramètres ?
- long m_nMethodeIdent;
+ CBotInstr* m_var; // la variable à initialiser
+ CBotClass* m_pClass; // référence à la classe
+ CBotInstr* m_Parameters; // les paramètres à évaluer pour le constructeur
+ CBotInstr* m_expr; // la valeur à mettre, s'il y a
+ bool m_hasParams; // il y a des paramètres ?
+ long m_nMethodeIdent;
public:
- CBotClassInst();
- ~CBotClassInst();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass = NULL);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotClassInst();
+ ~CBotClassInst();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass = NULL);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
class CBotCondition : public CBotInstr
@@ -733,8 +835,8 @@ private:
public:
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
};
@@ -744,18 +846,18 @@ public:
class CBotLeftExpr : public CBotInstr
{
private:
- long m_nIdent;
+ long m_nIdent;
public:
- CBotLeftExpr();
- ~CBotLeftExpr();
- static
- CBotLeftExpr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pStack, CBotStack* array);
-
- BOOL ExecuteVar(CBotVar* &pVar, CBotCStack* &pile);
- BOOL ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, BOOL bStep);
- void RestoreStateVar(CBotStack* &pile, BOOL bMain);
+ CBotLeftExpr();
+ ~CBotLeftExpr();
+ static
+ CBotLeftExpr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pStack, CBotStack* array);
+
+ bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile);
+ bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep);
+ void RestoreStateVar(CBotStack* &pile, bool bMain);
};
@@ -764,18 +866,18 @@ public:
class CBotFieldExpr : public CBotInstr
{
private:
- friend class CBotExpression;
- int m_nIdent;
+ friend class CBotExpression;
+ int m_nIdent;
public:
- CBotFieldExpr();
- ~CBotFieldExpr();
- void SetUniqNum(int num);
-// static
-// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL ExecuteVar(CBotVar* &pVar, CBotCStack* &pile);
- BOOL ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, BOOL bStep, BOOL bExtend);
- void RestoreStateVar(CBotStack* &pj, BOOL bMain);
+ CBotFieldExpr();
+ ~CBotFieldExpr();
+ void SetUniqNum(int num);
+// static
+// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile);
+ bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend);
+ void RestoreStateVar(CBotStack* &pj, bool bMain);
};
// gestion des index dans les tableaux
@@ -783,18 +885,18 @@ public:
class CBotIndexExpr : public CBotInstr
{
private:
- CBotInstr* m_expr; // expression pour le calcul de l'index
- friend class CBotLeftExpr;
- friend class CBotExprVar;
+ CBotInstr* m_expr; // expression pour le calcul de l'index
+ friend class CBotLeftExpr;
+ friend class CBotExprVar;
public:
- CBotIndexExpr();
- ~CBotIndexExpr();
-// static
-// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL ExecuteVar(CBotVar* &pVar, CBotCStack* &pile);
- BOOL ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, BOOL bStep, BOOL bExtend);
- void RestoreStateVar(CBotStack* &pj, BOOL bMain);
+ CBotIndexExpr();
+ ~CBotIndexExpr();
+// static
+// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile);
+ bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend);
+ void RestoreStateVar(CBotStack* &pj, bool bMain);
};
// une expression du genre
@@ -804,47 +906,47 @@ public:
class CBotExpression : public CBotInstr
{
private:
- CBotLeftExpr* m_leftop; // élément de gauche
- CBotInstr* m_rightop; // élément de droite
+ CBotLeftExpr* m_leftop; // élément de gauche
+ CBotInstr* m_rightop; // élément de droite
public:
- CBotExpression();
- ~CBotExpression();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pStack);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotExpression();
+ ~CBotExpression();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pStack);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
class CBotListExpression : public CBotInstr
{
private:
- CBotInstr* m_Expr; // la 1ère expression à évaluer
+ CBotInstr* m_Expr; // la 1ère expression à évaluer
public:
- CBotListExpression();
- ~CBotListExpression();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pStack);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotListExpression();
+ ~CBotListExpression();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pStack);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
class CBotLogicExpr : public CBotInstr
{
private:
- CBotInstr* m_condition; // test à évaluer
- CBotInstr* m_op1; // élément de gauche
- CBotInstr* m_op2; // élément de droite
- friend class CBotTwoOpExpr;
+ CBotInstr* m_condition; // test à évaluer
+ CBotInstr* m_op1; // élément de gauche
+ CBotInstr* m_op2; // élément de droite
+ friend class CBotTwoOpExpr;
public:
- CBotLogicExpr();
- ~CBotLogicExpr();
-// static
-// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pStack);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotLogicExpr();
+ ~CBotLogicExpr();
+// static
+// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pStack);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
@@ -854,8 +956,8 @@ class CBotBoolExpr : public CBotInstr
private:
public:
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
};
@@ -868,22 +970,22 @@ class CBotParExpr : public CBotInstr
private:
public:
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
};
// expression unaire
class CBotExprUnaire : public CBotInstr
{
private:
- CBotInstr* m_Expr; // l'expression à évaluer
+ CBotInstr* m_Expr; // l'expression à évaluer
public:
- CBotExprUnaire();
- ~CBotExprUnaire();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pStack);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotExprUnaire();
+ ~CBotExprUnaire();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pStack);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
// toutes les opérations à 2 opérandes
@@ -891,15 +993,15 @@ public:
class CBotTwoOpExpr : public CBotInstr
{
private:
- CBotInstr* m_leftop; // élément de gauche
- CBotInstr* m_rightop; // élément de droite
+ CBotInstr* m_leftop; // élément de gauche
+ CBotInstr* m_rightop; // élément de droite
public:
- CBotTwoOpExpr();
- ~CBotTwoOpExpr();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations = NULL);
- BOOL Execute(CBotStack* &pStack);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotTwoOpExpr();
+ ~CBotTwoOpExpr();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations = NULL);
+ bool Execute(CBotStack* &pStack);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
@@ -911,10 +1013,10 @@ class CBotBlock : public CBotInstr
private:
public:
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, BOOL bLocal = TRUE);
- static
- CBotInstr* CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, BOOL bLocal = FALSE);
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true);
+ static
+ CBotInstr* CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal = false);
};
@@ -922,35 +1024,35 @@ public:
class CBotListInstr : public CBotInstr
{
private:
- CBotInstr* m_Instr; // les instructions à faire
+ CBotInstr* m_Instr; // les instructions à faire
public:
- CBotListInstr();
- ~CBotListInstr();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, BOOL bLocal = TRUE);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotListInstr();
+ ~CBotListInstr();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
class CBotInstrCall : public CBotInstr
{
private:
- CBotInstr* m_Parameters; // les paramètres à évaluer
-// int m_typeRes; // type du résultat
-// CBotString m_RetClassName; // class du résultat
- CBotTypResult
- m_typRes; // type complet du résultat
- long m_nFuncIdent; // id de la fonction
+ CBotInstr* m_Parameters; // les paramètres à évaluer
+// int m_typeRes; // type du résultat
+// CBotString m_RetClassName; // class du résultat
+ CBotTypResult
+ m_typRes; // type complet du résultat
+ long m_nFuncIdent; // id de la fonction
public:
- CBotInstrCall();
- ~CBotInstrCall();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotInstrCall();
+ ~CBotInstrCall();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
// un appel d'une méthode
@@ -958,79 +1060,79 @@ public:
class CBotInstrMethode : public CBotInstr
{
private:
- CBotInstr* m_Parameters; // les paramètres à évaluer
-// int m_typeRes; // type du résultat
-// CBotString m_RetClassName; // class du résultat
- CBotTypResult
- m_typRes; // type complet du résultat
+ CBotInstr* m_Parameters; // les paramètres à évaluer
+// int m_typeRes; // type du résultat
+// CBotString m_RetClassName; // class du résultat
+ CBotTypResult
+ m_typRes; // type complet du résultat
- CBotString m_NomMethod; // nom de la méthode
- long m_MethodeIdent; // identificateur de la méthode
-// long m_nThisIdent; // identificateur pour "this"
- CBotString m_ClassName; // nom de la classe
+ CBotString m_NomMethod; // nom de la méthode
+ long m_MethodeIdent; // identificateur de la méthode
+// long m_nThisIdent; // identificateur pour "this"
+ CBotString m_ClassName; // nom de la classe
public:
- CBotInstrMethode();
- ~CBotInstrMethode();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* pVar);
- BOOL Execute(CBotStack* &pj);
- BOOL ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, BOOL bStep, BOOL bExtend);
- void RestoreStateVar(CBotStack* &pj, BOOL bMain);
+ CBotInstrMethode();
+ ~CBotInstrMethode();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* pVar);
+ bool Execute(CBotStack* &pj);
+ bool ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep, bool bExtend);
+ void RestoreStateVar(CBotStack* &pj, bool bMain);
};
-// expression donnant un nom de variable
+// expression for the variable name
class CBotExprVar : public CBotInstr
{
private:
- long m_nIdent;
- friend class CBotPostIncExpr;
- friend class CBotPreIncExpr;
+ 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);
-
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
- BOOL ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, BOOL bStep);
- BOOL Execute2Var(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, BOOL bStep);
- void RestoreStateVar(CBotStack* &pj, BOOL bMain);
+ CBotExprVar();
+ ~CBotExprVar();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, int privat=PR_PROTECT);
+ static
+ CBotInstr* CompileMethode(CBotToken* &p, CBotCStack* pStack);
+
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
+ bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep);
+ bool Execute2Var(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep);
+ void RestoreStateVar(CBotStack* &pj, bool bMain);
};
class CBotPostIncExpr : public CBotInstr
{
private:
- CBotInstr* m_Instr;
- friend class CBotParExpr;
+ CBotInstr* m_Instr;
+ friend class CBotParExpr;
public:
- CBotPostIncExpr();
- ~CBotPostIncExpr();
-// static
-// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotPostIncExpr();
+ ~CBotPostIncExpr();
+// static
+// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
class CBotPreIncExpr : public CBotInstr
{
private:
- CBotInstr* m_Instr;
- friend class CBotParExpr;
+ CBotInstr* m_Instr;
+ friend class CBotParExpr;
public:
- CBotPreIncExpr();
- ~CBotPreIncExpr();
-// static
-// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotPreIncExpr();
+ ~CBotPreIncExpr();
+// static
+// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
@@ -1038,17 +1140,17 @@ class CBotLeftExprVar : public CBotInstr
{
private:
public:
- CBotTypResult
- m_typevar; // type de variable déclarée
- long m_nIdent; // identificateur unique pour cette variable
+ CBotTypResult
+ m_typevar; // type de variable déclarée
+ long m_nIdent; // identificateur unique pour cette variable
public:
- CBotLeftExprVar();
- ~CBotLeftExprVar();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotLeftExprVar();
+ ~CBotLeftExprVar();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
@@ -1057,13 +1159,13 @@ class CBotExprBool : public CBotInstr
private:
public:
- CBotExprBool();
- ~CBotExprBool();
+ CBotExprBool();
+ ~CBotExprBool();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
@@ -1072,11 +1174,11 @@ class CBotExprNull : public CBotInstr
private:
public:
- CBotExprNull();
- ~CBotExprNull();
+ CBotExprNull();
+ ~CBotExprNull();
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
class CBotExprNan : public CBotInstr
@@ -1084,29 +1186,29 @@ class CBotExprNan : public CBotInstr
private:
public:
- CBotExprNan();
- ~CBotExprNan();
+ CBotExprNan();
+ ~CBotExprNan();
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
class CBotNew : public CBotInstr
{
private:
- CBotInstr* m_Parameters; // les paramètres à évaluer
- long m_nMethodeIdent;
-// long m_nThisIdent;
- CBotToken m_vartoken;
+ CBotInstr* m_Parameters; // les paramètres à évaluer
+ long m_nMethodeIdent;
+// long m_nThisIdent;
+ CBotToken m_vartoken;
public:
- CBotNew();
- ~CBotNew();
+ CBotNew();
+ ~CBotNew();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
// expression représentant un nombre
@@ -1114,17 +1216,17 @@ public:
class CBotExprNum : public CBotInstr
{
private:
- int m_numtype; // et le type de nombre
- long m_valint; // valeur pour un int
- float m_valfloat; // valeur pour un float
+ int m_numtype; // et le type de nombre
+ long m_valint; // valeur pour un int
+ float m_valfloat; // valeur pour un float
public:
- CBotExprNum();
- ~CBotExprNum();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotExprNum();
+ ~CBotExprNum();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
@@ -1136,68 +1238,68 @@ class CBotExprAlpha : public CBotInstr
private:
public:
- CBotExprAlpha();
- ~CBotExprAlpha();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- BOOL Execute(CBotStack* &pj);
- void RestoreState(CBotStack* &pj, BOOL bMain);
+ CBotExprAlpha();
+ ~CBotExprAlpha();
+ static
+ CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+ bool Execute(CBotStack* &pj);
+ void RestoreState(CBotStack* &pj, bool bMain);
};
-#define MAX(a,b) ((a>b) ? a : b)
+#define MAX(a,b) ((a>b) ? a : b)
// classe pour la gestion des nombres entier (int)
class CBotVarInt : public CBotVar
{
private:
- int m_val; // la valeur
- CBotString m_defnum; // le nom si donné par DefineNum
- friend class CBotVar;
+ int m_val; // la valeur
+ CBotString m_defnum; // le nom si donné par DefineNum
+ friend class CBotVar;
public:
- CBotVarInt( const CBotToken* name );
-// ~CBotVarInt();
+ CBotVarInt( const CBotToken* name );
+// ~CBotVarInt();
- void SetValInt(int val, const char* s = NULL);
- void SetValFloat(float val);
- int GivValInt();
- float GivValFloat();
- CBotString GivValString();
+ void SetValInt(int val, const char* s = NULL);
+ void SetValFloat(float val);
+ int GivValInt();
+ float GivValFloat();
+ CBotString GivValString();
- void Copy(CBotVar* pSrc, BOOL bName=TRUE);
+ void Copy(CBotVar* pSrc, bool bName=true);
- void Add(CBotVar* left, CBotVar* right); // addition
- void Sub(CBotVar* left, CBotVar* right); // soustraction
- void Mul(CBotVar* left, CBotVar* right); // multiplication
- int Div(CBotVar* left, CBotVar* right); // division
- int Modulo(CBotVar* left, CBotVar* right); // reste de division
- void Power(CBotVar* left, CBotVar* right); // puissance
+ void Add(CBotVar* left, CBotVar* right); // addition
+ void Sub(CBotVar* left, CBotVar* right); // soustraction
+ void Mul(CBotVar* left, CBotVar* right); // multiplication
+ int Div(CBotVar* left, CBotVar* right); // division
+ int Modulo(CBotVar* left, CBotVar* right); // reste de division
+ void Power(CBotVar* left, CBotVar* right); // puissance
- BOOL Lo(CBotVar* left, CBotVar* right);
- BOOL Hi(CBotVar* left, CBotVar* right);
- BOOL Ls(CBotVar* left, CBotVar* right);
- BOOL Hs(CBotVar* left, CBotVar* right);
- BOOL Eq(CBotVar* left, CBotVar* right);
- BOOL Ne(CBotVar* left, CBotVar* right);
+ bool Lo(CBotVar* left, CBotVar* right);
+ bool Hi(CBotVar* left, CBotVar* right);
+ bool Ls(CBotVar* left, CBotVar* right);
+ bool Hs(CBotVar* left, CBotVar* right);
+ bool Eq(CBotVar* left, CBotVar* right);
+ bool Ne(CBotVar* left, CBotVar* right);
- void XOr(CBotVar* left, CBotVar* right);
- void Or(CBotVar* left, CBotVar* right);
- void And(CBotVar* left, CBotVar* right);
+ void XOr(CBotVar* left, CBotVar* right);
+ void Or(CBotVar* left, CBotVar* right);
+ void And(CBotVar* left, CBotVar* right);
- void SL(CBotVar* left, CBotVar* right);
- void SR(CBotVar* left, CBotVar* right);
- void ASR(CBotVar* left, CBotVar* right);
+ void SL(CBotVar* left, CBotVar* right);
+ void SR(CBotVar* left, CBotVar* right);
+ void ASR(CBotVar* left, CBotVar* right);
- void Neg();
- void Not();
- void Inc();
- void Dec();
+ void Neg();
+ void Not();
+ void Inc();
+ void Dec();
- BOOL Save0State(FILE* pf);
- BOOL Save1State(FILE* pf);
+ bool Save0State(FILE* pf);
+ bool Save1State(FILE* pf);
};
@@ -1205,40 +1307,40 @@ public:
class CBotVarFloat : public CBotVar
{
private:
- float m_val; // la valeur
+ float m_val; // la valeur
public:
- CBotVarFloat( const CBotToken* name );
-// ~CBotVarFloat();
+ CBotVarFloat( const CBotToken* name );
+// ~CBotVarFloat();
- void SetValInt(int val, const char* s = NULL);
- void SetValFloat(float val);
- int GivValInt();
- float GivValFloat();
- CBotString GivValString();
+ void SetValInt(int val, const char* s = NULL);
+ void SetValFloat(float val);
+ int GivValInt();
+ float GivValFloat();
+ CBotString GivValString();
- void Copy(CBotVar* pSrc, BOOL bName=TRUE);
+ void Copy(CBotVar* pSrc, bool bName=true);
- void Add(CBotVar* left, CBotVar* right); // addition
- void Sub(CBotVar* left, CBotVar* right); // soustraction
- void Mul(CBotVar* left, CBotVar* right); // multiplication
- int Div(CBotVar* left, CBotVar* right); // division
- int Modulo(CBotVar* left, CBotVar* right); // reste de division
- void Power(CBotVar* left, CBotVar* right); // puissance
+ void Add(CBotVar* left, CBotVar* right); // addition
+ void Sub(CBotVar* left, CBotVar* right); // soustraction
+ void Mul(CBotVar* left, CBotVar* right); // multiplication
+ int Div(CBotVar* left, CBotVar* right); // division
+ int Modulo(CBotVar* left, CBotVar* right); // reste de division
+ void Power(CBotVar* left, CBotVar* right); // puissance
- BOOL Lo(CBotVar* left, CBotVar* right);
- BOOL Hi(CBotVar* left, CBotVar* right);
- BOOL Ls(CBotVar* left, CBotVar* right);
- BOOL Hs(CBotVar* left, CBotVar* right);
- BOOL Eq(CBotVar* left, CBotVar* right);
- BOOL Ne(CBotVar* left, CBotVar* right);
+ bool Lo(CBotVar* left, CBotVar* right);
+ bool Hi(CBotVar* left, CBotVar* right);
+ bool Ls(CBotVar* left, CBotVar* right);
+ bool Hs(CBotVar* left, CBotVar* right);
+ bool Eq(CBotVar* left, CBotVar* right);
+ bool Ne(CBotVar* left, CBotVar* right);
- void Neg();
- void Inc();
- void Dec();
+ void Neg();
+ void Inc();
+ void Dec();
- BOOL Save1State(FILE* pf);
+ bool Save1State(FILE* pf);
};
@@ -1246,55 +1348,55 @@ public:
class CBotVarString : public CBotVar
{
private:
- CBotString m_val; // la valeur
+ CBotString m_val; // la valeur
public:
- CBotVarString( const CBotToken* name );
-// ~CBotVarString();
+ CBotVarString( const CBotToken* name );
+// ~CBotVarString();
- void SetValString(const char* p);
- CBotString GivValString();
+ void SetValString(const char* p);
+ CBotString GivValString();
- void Copy(CBotVar* pSrc, BOOL bName=TRUE);
+ void Copy(CBotVar* pSrc, bool bName=true);
- void Add(CBotVar* left, CBotVar* right); // addition
+ void Add(CBotVar* left, CBotVar* right); // addition
- BOOL Lo(CBotVar* left, CBotVar* right);
- BOOL Hi(CBotVar* left, CBotVar* right);
- BOOL Ls(CBotVar* left, CBotVar* right);
- BOOL Hs(CBotVar* left, CBotVar* right);
- BOOL Eq(CBotVar* left, CBotVar* right);
- BOOL Ne(CBotVar* left, CBotVar* right);
+ bool Lo(CBotVar* left, CBotVar* right);
+ bool Hi(CBotVar* left, CBotVar* right);
+ bool Ls(CBotVar* left, CBotVar* right);
+ bool Hs(CBotVar* left, CBotVar* right);
+ bool Eq(CBotVar* left, CBotVar* right);
+ bool Ne(CBotVar* left, CBotVar* right);
- BOOL Save1State(FILE* pf);
+ bool Save1State(FILE* pf);
};
// classe pour la gestion des boolean
class CBotVarBoolean : public CBotVar
{
private:
- BOOL m_val; // la valeur
+ bool m_val; // la valeur
public:
- CBotVarBoolean( const CBotToken* name );
-// ~CBotVarBoolean();
+ CBotVarBoolean( const CBotToken* name );
+// ~CBotVarBoolean();
- void SetValInt(int val, const char* s = NULL);
- void SetValFloat(float val);
- int GivValInt();
- float GivValFloat();
- CBotString GivValString();
+ void SetValInt(int val, const char* s = NULL);
+ void SetValFloat(float val);
+ int GivValInt();
+ float GivValFloat();
+ CBotString GivValString();
- void Copy(CBotVar* pSrc, BOOL bName=TRUE);
+ void Copy(CBotVar* pSrc, bool bName=true);
- void And(CBotVar* left, CBotVar* right);
- void Or(CBotVar* left, CBotVar* right);
- void XOr(CBotVar* left, CBotVar* right);
- void Not();
- BOOL Eq(CBotVar* left, CBotVar* right);
- BOOL Ne(CBotVar* left, CBotVar* right);
+ void And(CBotVar* left, CBotVar* right);
+ void Or(CBotVar* left, CBotVar* right);
+ void XOr(CBotVar* left, CBotVar* right);
+ void Not();
+ bool Eq(CBotVar* left, CBotVar* right);
+ bool Ne(CBotVar* left, CBotVar* right);
- BOOL Save1State(FILE* pf);
+ bool Save1State(FILE* pf);
};
@@ -1302,61 +1404,59 @@ public:
class CBotVarClass : public CBotVar
{
private:
- static
- CBotVarClass* m_ExClass; // liste des instances existantes à un moment donné
- CBotVarClass* m_ExNext; // pour cette liste générale
- CBotVarClass* m_ExPrev; // pour cette liste générale
+ static
+ CBotVarClass* m_ExClass; // liste des instances existantes à un moment donné
+ CBotVarClass* m_ExNext; // pour cette liste générale
+ CBotVarClass* m_ExPrev; // pour cette liste générale
private:
- CBotClass* m_pClass; // la définition de la classe
- CBotVarClass* m_pParent; // l'instance dans la classe parent
- CBotVar* m_pVar; // contenu
- friend class CBotVar; // mon papa est un copain
- friend class CBotVarPointer; // et le pointeur aussi
- int m_CptUse; // compteur d'utilisation
- long m_ItemIdent; // identificateur (unique) de l'instance
- BOOL m_bConstructor; // set si un constructeur a été appelé
+ CBotClass* m_pClass; // la définition de la classe
+ CBotVarClass* m_pParent; // l'instance dans la classe parent
+ CBotVar* m_pVar; // contenu
+ friend class CBotVar; // mon papa est un copain
+ friend class CBotVarPointer; // et le pointeur aussi
+ int m_CptUse; // compteur d'utilisation
+ long m_ItemIdent; // identificateur (unique) de l'instance
+ bool m_bConstructor; // set si un constructeur a été appelé
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 );
+ 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 );
- void Copy(CBotVar* pSrc, BOOL bName=TRUE);
- void SetClass(CBotClass* pClass); //, int &nIdent);
- CBotClass* GivClass();
- CBotVar* GivItem(const char* name); // rend un élément d'une classe selon son nom (*)
- CBotVar* GivItemRef(int nIdent);
+ void Copy(CBotVar* pSrc, bool bName=true);
+ void SetClass(CBotClass* pClass); //, int &nIdent);
+ CBotClass* GivClass();
+ CBotVar* GivItem(const char* name); // rend un élément d'une classe selon son nom (*)
+ CBotVar* GivItemRef(int nIdent);
- CBotVar* GivItem(int n, BOOL bExtend);
- CBotVar* GivItemList();
+ CBotVar* GivItem(int n, bool bExtend);
+ CBotVar* GivItemList();
- CBotString GivValString();
+ CBotString GivValString();
- BOOL Save1State(FILE* pf);
- void Maj(void* pUser, BOOL bContinue);
+ bool Save1State(FILE* pf);
+ void Maj(void* pUser, bool bContinue);
- void IncrementUse(); // une référence en plus
- void DecrementUse(); // une référence en moins
+ void IncrementUse(); // une référence en plus
+ void DecrementUse(); // une référence en moins
- CBotVarClass*
- GivPointer();
- void SetItemList(CBotVar* pVar);
+ CBotVarClass*
+ GivPointer();
+ void SetItemList(CBotVar* pVar);
- void SetIdent(long n);
-
- static
- CBotVarClass*
- CBotVarClass::Find(long id);
+ void SetIdent(long n);
+
+ static CBotVarClass* Find(long id);
-// CBotVar* GivMyThis();
+// CBotVar* GivMyThis();
- BOOL Eq(CBotVar* left, CBotVar* right);
- BOOL Ne(CBotVar* left, CBotVar* right);
+ bool Eq(CBotVar* left, CBotVar* right);
+ bool Ne(CBotVar* left, CBotVar* right);
- void ConstructorSet();
+ void ConstructorSet();
};
@@ -1364,90 +1464,90 @@ public:
class CBotVarPointer : public CBotVar
{
private:
- CBotVarClass*
- m_pVarClass; // contenu
- CBotClass* m_pClass; // la classe prévue pour ce pointeur
- friend class CBotVar; // mon papa est un copain
+ CBotVarClass*
+ m_pVarClass; // contenu
+ CBotClass* m_pClass; // la classe prévue pour ce pointeur
+ friend class CBotVar; // mon papa est un copain
public:
- CBotVarPointer( const CBotToken* name, CBotTypResult& type );
- ~CBotVarPointer();
-
- void Copy(CBotVar* pSrc, BOOL bName=TRUE);
- void SetClass(CBotClass* pClass);
- CBotClass* GivClass();
- CBotVar* GivItem(const char* name); // rend un élément d'une classe selon son nom (*)
- CBotVar* GivItemRef(int nIdent);
- CBotVar* GivItemList();
-
- CBotString GivValString();
- void SetPointer(CBotVar* p);
- CBotVarClass*
- GivPointer();
-
- void SetIdent(long n); // associe un numéro d'identification (unique)
- long GivIdent(); // donne le numéro d'identification associé
- void ConstructorSet();
-
- BOOL Save1State(FILE* pf);
- void Maj(void* pUser, BOOL bContinue);
-
- BOOL Eq(CBotVar* left, CBotVar* right);
- BOOL Ne(CBotVar* left, CBotVar* right);
+ CBotVarPointer( const CBotToken* name, CBotTypResult& type );
+ ~CBotVarPointer();
+
+ void Copy(CBotVar* pSrc, bool bName=true);
+ void SetClass(CBotClass* pClass);
+ CBotClass* GivClass();
+ CBotVar* GivItem(const char* name); // rend un élément d'une classe selon son nom (*)
+ CBotVar* GivItemRef(int nIdent);
+ CBotVar* GivItemList();
+
+ CBotString GivValString();
+ void SetPointer(CBotVar* p);
+ CBotVarClass*
+ GivPointer();
+
+ void SetIdent(long n); // associe un numéro d'identification (unique)
+ long GivIdent(); // donne le numéro d'identification associé
+ void ConstructorSet();
+
+ bool Save1State(FILE* pf);
+ void Maj(void* pUser, bool bContinue);
+
+ bool Eq(CBotVar* left, CBotVar* right);
+ bool Ne(CBotVar* left, CBotVar* right);
};
// classe pour les tableaux
-#define MAXARRAYSIZE 9999
+#define MAXARRAYSIZE 9999
class CBotVarArray : public CBotVar
{
private:
- CBotVarClass*
- m_pInstance; // instance gérant le tableau
+ CBotVarClass*
+ m_pInstance; // instance gérant le tableau
- friend class CBotVar; // papa est un copain
+ friend class CBotVar; // papa est un copain
public:
- CBotVarArray( const CBotToken* name, CBotTypResult& type );
- ~CBotVarArray();
-
- void SetPointer(CBotVar* p);
- CBotVarClass*
- GivPointer();
-
- void Copy(CBotVar* pSrc, BOOL bName=TRUE);
- CBotVar* GivItem(int n, BOOL bGrow=FALSE); // rend un élément selon son index numérique
- // agrandi le tableau si nécessaire si bExtend
-// CBotVar* GivItem(const char* name); // rend un élément selon son index litéral
- CBotVar* GivItemList(); // donne le premier élément de la liste
-
- CBotString GivValString(); // donne le contenu du tableau dans une chaîne
-
- BOOL Save1State(FILE* pf);
+ CBotVarArray( const CBotToken* name, CBotTypResult& type );
+ ~CBotVarArray();
+
+ void SetPointer(CBotVar* p);
+ CBotVarClass*
+ GivPointer();
+
+ void Copy(CBotVar* pSrc, bool bName=true);
+ CBotVar* GivItem(int n, bool bGrow=false); // rend un élément selon son index numérique
+ // agrandi le tableau si nécessaire si bExtend
+// CBotVar* GivItem(const char* name); // rend un élément selon son index litéral
+ CBotVar* GivItemList(); // donne le premier élément de la liste
+
+ CBotString GivValString(); // donne le contenu du tableau dans une chaîne
+
+ bool Save1State(FILE* pf);
};
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 TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op = 0 );
+extern bool TypesCompatibles( const CBotTypResult& type1, const CBotTypResult& type2 );
-extern BOOL WriteWord(FILE* pf, WORD w);
-extern BOOL ReadWord(FILE* pf, WORD& 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);
+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);
extern float GivNumFloat( const char* p );
-#if FALSE
+#if false
extern void DEBUG( const char* text, int val, CBotStack* pile );
#endif
@@ -1457,51 +1557,51 @@ extern void DEBUG( const char* text, int val, CBotStack* pile );
class CBotCall
{
private:
- static
- CBotCall* m_ListCalls;
- static
- void* m_pUser;
- long m_nFuncIdent;
+ 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;
+ 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:
- CBotCall(const char* name,
- BOOL rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
- CBotTypResult rCompile (CBotVar* &pVar, void* pUser));
- ~CBotCall();
-
- static
- BOOL AddFunction(const char* name,
- BOOL rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
- 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);
+ CBotCall(const char* name,
+ bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
+ CBotTypResult rCompile (CBotVar* &pVar, void* pUser));
+ ~CBotCall();
+
+ static
+ bool AddFunction(const char* name,
+ bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
+ 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
- CBotString GivName();
- CBotCall* Next();
-
- static void SetPUser(void* pUser);
- static void Free();
+ CBotString GivName();
+ CBotCall* Next();
+
+ static void SetPUser(void* pUser);
+ static void Free();
};
// classe gérant les méthodes déclarées par AddFunction sur une classe
@@ -1509,31 +1609,31 @@ public:
class CBotCallMethode
{
private:
- CBotString m_name;
- BOOL (*m_rExec) (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception);
- CBotTypResult
- (*m_rComp) (CBotVar* pThis, CBotVar* &pVar);
- CBotCallMethode* m_next;
- friend class CBotClass;
- long m_nFuncIdent;
+ CBotString m_name;
+ bool (*m_rExec) (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception);
+ CBotTypResult
+ (*m_rComp) (CBotVar* pThis, CBotVar* &pVar);
+ CBotCallMethode* m_next;
+ friend class CBotClass;
+ long m_nFuncIdent;
public:
- CBotCallMethode(const char* name,
- BOOL rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception),
- CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar));
- ~CBotCallMethode();
-
- CBotTypResult
- CompileCall(const char* name, CBotVar* pThis,
- CBotVar** ppVars, CBotCStack* pStack,
- long& nIdent);
-
- int DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotVar* &pResult, CBotStack* pStack, CBotToken* pFunc);
-
- CBotString GivName();
- CBotCallMethode* Next();
- void AddNext(CBotCallMethode* p);
-
+ CBotCallMethode(const char* name,
+ bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception),
+ CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar));
+ ~CBotCallMethode();
+
+ CBotTypResult
+ CompileCall(const char* name, CBotVar* pThis,
+ CBotVar** ppVars, CBotCStack* pStack,
+ long& nIdent);
+
+ int DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotVar* &pResult, CBotStack* pStack, CBotToken* pFunc);
+
+ CBotString GivName();
+ CBotCallMethode* Next();
+ void AddNext(CBotCallMethode* p);
+
};
// une liste de paramètres
@@ -1541,26 +1641,26 @@ public:
class CBotDefParam
{
private:
- CBotToken m_token; // nom du paramètre
- CBotString m_typename; // nom du type
- CBotTypResult m_type; // type de paramètre
- CBotDefParam* m_next; // paramètre suivant
- long m_nIdent;
+ CBotToken m_token; // nom du paramètre
+ CBotString m_typename; // nom du type
+ CBotTypResult m_type; // type de paramètre
+ CBotDefParam* m_next; // paramètre suivant
+ 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);
- int GivType();
- CBotTypResult GivTypResult();
- CBotDefParam* GivNext();
-
- CBotString GivParamString();
+ 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);
+ int GivType();
+ CBotTypResult GivTypResult();
+ CBotDefParam* GivNext();
+
+ CBotString GivParamString();
};
@@ -1569,65 +1669,65 @@ public:
class CBotFunction : CBotInstr
{
private:
- // gestion d'une liste (static) de fonctions publiques
- static
- CBotFunction* m_listPublic;
- CBotFunction* m_nextpublic;
- CBotFunction* m_prevpublic;
- friend class CBotCStack;
-// long m_nThisIdent;
- long m_nFuncIdent;
- BOOL m_bSynchro; // méthode synchronisée ?
+ // gestion d'une liste (static) de fonctions publiques
+ static
+ CBotFunction* m_listPublic;
+ CBotFunction* m_nextpublic;
+ CBotFunction* m_prevpublic;
+ friend class CBotCStack;
+// long m_nThisIdent;
+ long m_nFuncIdent;
+ bool m_bSynchro; // méthode synchronisée ?
private:
- CBotDefParam* m_Param; // liste des paramètres
- CBotInstr* m_Block; // le bloc d'instructions
- CBotFunction* m_next;
- CBotToken m_retToken; // si retourne un CBotTypClass
- CBotTypResult m_retTyp; // type complet du résultat
-
- BOOL m_bPublic; // fonction publique
- BOOL m_bExtern; // fonction extern
- CBotString m_MasterClass; // nom de la classe qu'on dérive
- CBotProgram* m_pProg;
- friend class CBotProgram;
- friend class CBotClass;
-
- CBotToken m_extern; // pour la position du mot "extern"
- CBotToken m_openpar;
- CBotToken m_closepar;
- CBotToken m_openblk;
- CBotToken m_closeblk;
+ CBotDefParam* m_Param; // liste des paramètres
+ CBotInstr* m_Block; // le bloc d'instructions
+ CBotFunction* m_next;
+ CBotToken m_retToken; // si retourne un CBotTypClass
+ CBotTypResult m_retTyp; // type complet du résultat
+
+ bool m_bPublic; // fonction publique
+ bool m_bExtern; // fonction extern
+ CBotString m_MasterClass; // nom de la classe qu'on dérive
+ CBotProgram* m_pProg;
+ friend class CBotProgram;
+ friend class CBotClass;
+
+ CBotToken m_extern; // pour la position du mot "extern"
+ CBotToken m_openpar;
+ CBotToken m_closepar;
+ CBotToken m_openblk;
+ CBotToken m_closeblk;
public:
- CBotFunction::CBotFunction();
- CBotFunction::~CBotFunction();
- static
- CBotFunction* Compile(CBotToken* &p, CBotCStack* pStack, CBotFunction* pFunc, BOOL bLocal = TRUE);
- static
- CBotFunction* Compile1(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass);
- BOOL Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance = NULL);
- void RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance = NULL);
-
- 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);
-
- CBotString GivName();
- CBotString GivParams();
- BOOL IsPublic();
- BOOL IsExtern();
- CBotFunction* Next();
-
- BOOL GetPosition(int& start, int& stop, CBotGet modestart, CBotGet modestop);
+ CBotFunction();
+ ~CBotFunction();
+ static
+ CBotFunction* Compile(CBotToken* &p, CBotCStack* pStack, CBotFunction* pFunc, bool bLocal = true);
+ static
+ CBotFunction* Compile1(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass);
+ bool Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance = NULL);
+ void RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance = NULL);
+
+ 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);
+
+ CBotString GivName();
+ CBotString GivParams();
+ bool IsPublic();
+ bool IsExtern();
+ CBotFunction* Next();
+
+ bool GetPosition(int& start, int& stop, CBotGet modestart, CBotGet modestop);
};
diff --git a/src/CBot/CBot.rc b/src/CBot/CBot.rc
deleted file mode 100644
index d8b5b74..0000000
--- a/src/CBot/CBot.rc
+++ /dev/null
@@ -1,279 +0,0 @@
-//Microsoft Developer Studio generated resource script.
-//
-#include "resource.h"
-
-#define APSTUDIO_READONLY_SYMBOLS
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 2 resource.
-//
-#include "afxres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-#undef APSTUDIO_READONLY_SYMBOLS
-
-/////////////////////////////////////////////////////////////////////////////
-// French (France) resources
-
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)
-#ifdef _WIN32
-LANGUAGE LANG_FRENCH, SUBLANG_FRENCH
-#pragma code_page(1252)
-#endif //_WIN32
-
-#ifdef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// TEXTINCLUDE
-//
-
-1 TEXTINCLUDE DISCARDABLE
-BEGIN
- "resource.h\0"
-END
-
-2 TEXTINCLUDE DISCARDABLE
-BEGIN
- "#include ""afxres.h""\r\n"
- "\0"
-END
-
-3 TEXTINCLUDE DISCARDABLE
-BEGIN
- "\r\n"
- "\0"
-END
-
-#endif // APSTUDIO_INVOKED
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// String Table
-//
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_IF "if"
- ID_ELSE "else"
- ID_WHILE "while"
- ID_DO "do"
- ID_FOR "for"
- ID_BREAK "break"
- ID_CONTINUE "continue"
- ID_SWITCH "switch"
- ID_CASE "case"
- ID_DEFAULT "default"
- ID_TRY "try"
- ID_THROW "throw"
- ID_CATCH "catch"
- ID_FINALLY "finally"
- ID_TXT_AND "and"
- ID_TXT_OR "or"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_DEBUGDD "STARTDEBUGDD"
- ID_INT "int"
- ID_FLOAT "float"
- ID_BOOLEAN "boolean"
- ID_STRING "string"
- ID_VOID "void"
- ID_BOOL "bool"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_TXT_NOT "not"
- ID_RETURN "return"
- ID_CLASS "class"
- ID_EXTENDS "extends"
- ID_SYNCHO "synchronized"
- ID_NEW "new"
- ID_PUBLIC "public"
- ID_EXTERN "extern"
- ID_FINAL "final"
- ID_STATIC "static"
- ID_PROTECTED "protected"
- ID_PRIVATE "private"
- ID_REPEAT "repeat"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- TX_OPENPAR "Il manque une parenthèse ouvrante."
- TX_CLOSEPAR "Il manque une parenthèse fermante."
- TX_NOTBOOL "L'expression doit être un boolean."
- TX_UNDEFVAR "Variable non déclarée."
- TX_BADLEFT "Assignation impossible."
- TX_ENDOF "Terminateur point-virgule non trouvé."
- TX_OUTCASE "Instruction ""case"" hors d'un bloc ""switch""."
- TX_NOTERM "Instructions après la fin."
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- TX_CLOSEBLK "Il manque la fin du bloc."
- TX_ELSEWITHOUTIF "Instruction ""else"" sans ""if"" correspondant."
- TX_OPENBLK "Début d'un bloc attendu."
- TX_BADTYPE "Mauvais type de résultat pour l'assignation."
- TX_REDEFVAR "Redéfinition d'une variable."
- TX_BAD2TYPE "Les deux opérandes ne sont pas de types compatibles."
- TX_UNDEFCALL "Routine inconnue."
- TX_MISDOTS "Séparateur "" : "" attendu."
- TX_WHILE "Manque le mot ""while""."
- TX_BREAK "Instruction ""break"" en dehors d'une boucle."
- TX_LABEL "Un label ne peut se placer que devant un ""for"", un ""while"" ou un ""do""."
- TX_NOLABEL "Cette étiquette n'existe pas"
- TX_NOCASE "Manque une instruction ""case""."
- TX_BADNUM "Un nombre est attendu."
- TX_VOID "Paramètre void."
- TX_NOTYP "Déclaration de type attendu."
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- TX_DIVZERO "Division par zéro."
- TX_NOTINIT "Variable non initialisée."
- TX_BADTHROW "Valeur négative refusée pour ""throw""."
- TX_NORETVAL "La fonction n'a pas retourné de résultat"
- TX_NORUN "Pas de fonction en exécution"
- TX_NOCALL "Appel d'une fonction inexistante"
- TX_NOCLASS "Cette classe n'existe pas"
- TX_NULLPT "Pointeur nul."
- TX_OPNAN "Opération sur un ""nan"""
- TX_OUTARRAY "Accès hors du tableau"
- TX_STACKOVER "Dépassement de la pile"
- TX_DELETEDPT "Pointeur à un objet détruit"
- TX_FILEOPEN "Ouverture du fichier impossible"
- TX_NOTOPEN "Fichier pas ouvert"
- TX_ERRREAD "Erreur de lecture"
- TX_ERRWRITE "Erreur d'écriture"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- TX_NOVAR "Nom d'une variable attendu."
- TX_NOFONC "Nom de la fonction attendu."
- TX_OVERPARAM "Trop de paramètres."
- TX_REDEF "Cette fonction existe déjà."
- TX_LOWPARAM "Pas assez de paramètres."
- TX_BADPARAM "Aucune fonction de ce nom n'accepte ce(s) type(s) de paramètre(s)."
- TX_NUMPARAM "Aucune fonction de ce nom n'accepte ce nombre de paramètres."
- TX_NOITEM "Cet élément n'existe pas dans cette classe."
- TX_DOT "L'objet n'est pas une instance d'une classe."
- TX_NOCONST "Il n'y a pas de constructeur approprié."
- TX_REDEFCLASS "Cette classe existe déjà."
- TX_CLBRK """ ] "" attendu."
- TX_RESERVED "Ce mot est réservé."
- TX_BADNEW "Mauvais argument pour ""new""."
- TX_OPBRK """ [ "" attendu."
- TX_BADSTRING "Une chaîne de caractère est attendue."
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- TX_BADINDEX "Mauvais type d'index"
- TX_PRIVATE "Membre privé de la classe"
- TX_NOPUBLIC """public"" manque"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_OPENPAR "("
- ID_CLOSEPAR ")"
- ID_OPBLK "{"
- ID_CLBLK "}"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_SEP ";"
- ID_COMMA ","
- ID_DOTS ":"
- ID_DOT "."
- ID_OPBRK "["
- ID_CLBRK "]"
- ID_DBLDOTS "::"
- ID_LOGIC "?"
- ID_ADD "+"
- ID_SUB "-"
- ID_MUL "*"
- ID_DIV "/"
- ID_ASS "="
- ID_ASSADD "+="
- ID_ASSSUB "-="
- ID_ASSMUL "*="
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_TRUE "true"
- ID_FALSE "false"
- ID_NULL "null"
- ID_NAN "nan"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_ASSDIV "/="
- ID_ASSOR "|="
- ID_ASSAND "&="
- ID_ASSXOR "^="
- ID_ASSSL "<<="
- ID_ASSSR ">>>="
- ID_ASSASR ">>="
- ID_SL "<<"
- ID_SR ">>>"
- ID_ASR ">>"
- ID_INC "++"
- ID_DEC "--"
- ID_LO "<"
- ID_HI ">"
- ID_LS "<="
- ID_HS ">="
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_EQ "=="
- ID_NE "!="
- ID_AND "&"
- ID_XOR "^"
- ID_OR "|"
- ID_LOG_AND "&&"
- ID_LOG_OR "||"
- ID_LOG_NOT "!"
- ID_NOT "~"
- ID_MODULO "%"
- ID_POWER "**"
- ID_ASSMODULO "%="
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- TX_UNDEF "undefined"
- TX_NAN "not a number"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_SUPER "super"
-END
-
-#endif // French (France) resources
-/////////////////////////////////////////////////////////////////////////////
-
-
-
-#ifndef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 3 resource.
-//
-
-
-/////////////////////////////////////////////////////////////////////////////
-#endif // not APSTUDIO_INVOKED
-
diff --git a/src/CBot/CBotAddExpr.cpp b/src/CBot/CBotAddExpr.cpp
index ad87880..d94946e 100644
--- a/src/CBot/CBotAddExpr.cpp
+++ b/src/CBot/CBotAddExpr.cpp
@@ -93,7 +93,7 @@ CBotInstr* CBotAddExpr::Compile(CBotToken* &p, CBotStack* pStack)
// fait l'opération d'addition ou de soustraction
-BOOL CBotAddExpr::Execute(CBotStack* &pStack)
+bool CBotAddExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this); // ajoute un élément à la pile
// ou le retrouve en cas de reprise
diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp
index 7c097af..c99185f 100644
--- a/src/CBot/CBotClass.cpp
+++ b/src/CBot/CBotClass.cpp
@@ -21,7 +21,7 @@
CBotClass* CBotClass::m_ExClass = NULL;
-CBotClass::CBotClass(const char* name, CBotClass* pPapa, BOOL bIntrinsic)
+CBotClass::CBotClass(const char* name, CBotClass* pPapa, bool bIntrinsic)
{
m_pParent = pPapa;
m_name = name;
@@ -30,7 +30,7 @@ CBotClass::CBotClass(const char* name, CBotClass* pPapa, BOOL bIntrinsic)
m_pCalls = NULL;
m_pMethod = NULL;
m_rMaj = NULL;
- m_IsDef = TRUE;
+ m_IsDef = true;
m_bIntrinsic= bIntrinsic;
m_cptLock = 0;
m_cptOne = 0;
@@ -86,7 +86,7 @@ void CBotClass::Purge()
m_pCalls = NULL;
delete m_pMethod;
m_pMethod = NULL;
- m_IsDef = FALSE;
+ m_IsDef = false;
m_nbVar = m_pParent == NULL ? 0 : m_pParent->m_nbVar;
@@ -94,7 +94,7 @@ void CBotClass::Purge()
m_next = NULL; // n'appartient plus à cette chaîne
}
-BOOL CBotClass::Lock(CBotProgram* p)
+bool CBotClass::Lock(CBotProgram* p)
{
int i = m_cptLock++;
@@ -102,13 +102,13 @@ BOOL CBotClass::Lock(CBotProgram* p)
{
m_cptOne = 1;
m_ProgInLock[0] = p;
- return TRUE;
+ return true;
}
if ( p == m_ProgInLock[0] )
{
m_cptOne++;
m_cptLock--; // a déjà été compté
- return TRUE;
+ return true;
}
for ( int j = 1 ; j <= i ; j++)
@@ -116,7 +116,7 @@ BOOL CBotClass::Lock(CBotProgram* p)
if ( p == m_ProgInLock[j] )
{
m_cptLock--;
- return FALSE; // déjà en attente
+ return false; // déjà en attente
}
}
@@ -127,7 +127,7 @@ BOOL CBotClass::Lock(CBotProgram* p)
else
m_cptLock--;
- return FALSE;
+ return false;
}
void CBotClass::Unlock()
@@ -170,7 +170,7 @@ void CBotClass::FreeLock(CBotProgram* p)
-BOOL CBotClass::AddItem(CBotString name, CBotTypResult type, int mPrivate)
+bool CBotClass::AddItem(CBotString name, CBotTypResult type, int mPrivate)
{
CBotToken token(name, CBotString());
CBotClass* pClass = type.GivClass();
@@ -194,14 +194,14 @@ BOOL CBotClass::AddItem(CBotString name, CBotTypResult type, int mPrivate)
}
-BOOL CBotClass::AddItem(CBotVar* pVar)
+bool CBotClass::AddItem(CBotVar* pVar)
{
pVar->SetUniqNum(++m_nbVar);
if ( m_pVar == NULL ) m_pVar = pVar;
else m_pVar->AddNext(pVar);
- return TRUE;
+ return true;
}
void CBotClass::AddNext(CBotClass* pClass)
@@ -223,15 +223,15 @@ CBotClass* CBotClass::GivParent()
return m_pParent;
}
-BOOL CBotClass::IsChildOf(CBotClass* pClass)
+bool CBotClass::IsChildOf(CBotClass* pClass)
{
CBotClass* p = this;
while ( p != NULL )
{
- if ( p == pClass ) return TRUE;
+ if ( p == pClass ) return true;
p = p->m_pParent;
}
- return FALSE;
+ return false;
}
@@ -266,7 +266,7 @@ CBotVar* CBotClass::GivItemRef(int nIdent)
return NULL;
}
-BOOL CBotClass::IsIntrinsic()
+bool CBotClass::IsIntrinsic()
{
return m_bIntrinsic;
}
@@ -289,8 +289,8 @@ CBotClass* CBotClass::Find(const char* name)
return NULL;
}
-BOOL CBotClass::AddFunction(const char* name,
- BOOL rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception),
+bool CBotClass::AddFunction(const char* name,
+ bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception),
CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar))
{
// mémorise les pointeurs aux deux fonctions
@@ -315,13 +315,13 @@ BOOL CBotClass::AddFunction(const char* name,
if (m_pCalls == NULL) m_pCalls = p;
else m_pCalls->AddNext(p); // ajoute à la liste
- return TRUE;
+ return true;
}
-BOOL CBotClass::AddUpdateFunc( void rMaj ( CBotVar* pThis, void* pUser ) )
+bool CBotClass::AddUpdateFunc( void rMaj ( CBotVar* pThis, void* pUser ) )
{
m_rMaj = rMaj;
- return TRUE;
+ return true;
}
// compile une méthode associée à une instance de classe
@@ -348,7 +348,7 @@ CBotTypResult CBotClass::CompileMethode(const char* name,
// exécute une méthode
-BOOL CBotClass::ExecuteMethode(long& nIdent, const char* name,
+bool CBotClass::ExecuteMethode(long& nIdent, const char* name,
CBotVar* pThis, CBotVar** ppParams,
CBotVar* &pResult, CBotStack* &pStack,
CBotToken* pToken)
@@ -371,77 +371,77 @@ void CBotClass::RestoreMethode(long& nIdent, const char* name, CBotVar* pThis,
-BOOL CBotClass::SaveStaticState(FILE* pf)
+bool CBotClass::SaveStaticState(FILE* pf)
{
- if (!WriteWord( pf, CBOTVERSION*2)) return FALSE;
+ if (!WriteWord( pf, CBOTVERSION*2)) return false;
// sauve l'état des variables statiques dans les classes
CBotClass* p = m_ExClass;
while ( p != NULL )
{
- if (!WriteWord( pf, 1)) return FALSE;
+ if (!WriteWord( pf, 1)) return false;
// enregistre le nom de la classe
- if (!WriteString( pf, p->GivName() )) return FALSE;
+ if (!WriteString( pf, p->GivName() )) return false;
CBotVar* pv = p->GivVar();
while( pv != NULL )
{
if ( pv->IsStatic() )
{
- if (!WriteWord( pf, 1)) return FALSE;
- if (!WriteString( pf, pv->GivName() )) return FALSE;
+ if (!WriteWord( pf, 1)) return false;
+ if (!WriteString( pf, pv->GivName() )) return false;
- if ( !pv->Save0State(pf)) return FALSE; // entête commune
- if ( !pv->Save1State(pf) ) return FALSE; // sauve selon la classe fille
- if ( !WriteWord( pf, 0)) return FALSE;
+ if ( !pv->Save0State(pf)) return false; // entête commune
+ if ( !pv->Save1State(pf) ) return false; // sauve selon la classe fille
+ if ( !WriteWord( pf, 0)) return false;
}
pv = pv->GivNext();
}
- if (!WriteWord( pf, 0)) return FALSE;
+ if (!WriteWord( pf, 0)) return false;
p = p->m_ExNext;
}
- if (!WriteWord( pf, 0)) return FALSE;
- return TRUE;
+ if (!WriteWord( pf, 0)) return false;
+ return true;
}
-BOOL CBotClass::RestoreStaticState(FILE* pf)
+bool CBotClass::RestoreStaticState(FILE* pf)
{
CBotString ClassName, VarName;
CBotClass* pClass;
- WORD w;
+ unsigned short w;
- if (!ReadWord( pf, w )) return FALSE;
- if ( w != CBOTVERSION*2 ) return FALSE;
+ if (!ReadWord( pf, w )) return false;
+ if ( w != CBOTVERSION*2 ) return false;
- while (TRUE)
+ while (true)
{
- if (!ReadWord( pf, w )) return FALSE;
- if ( w == 0 ) return TRUE;
+ if (!ReadWord( pf, w )) return false;
+ if ( w == 0 ) return true;
- if (!ReadString( pf, ClassName )) return FALSE;
+ if (!ReadString( pf, ClassName )) return false;
pClass = Find(ClassName);
- while (TRUE)
+ while (true)
{
- if (!ReadWord( pf, w )) return FALSE;
+ if (!ReadWord( pf, w )) return false;
if ( w == 0 ) break;
CBotVar* pVar = NULL;
CBotVar* pv = NULL;
- if (!ReadString( pf, VarName )) return FALSE;
+ if (!ReadString( pf, VarName )) return false;
if ( pClass != NULL ) pVar = pClass->GivItem(VarName);
- if (!CBotVar::RestoreState(pf, pv)) return FALSE; // la variable temp
+ if (!CBotVar::RestoreState(pf, pv)) return false; // la variable temp
if ( pVar != NULL ) pVar->Copy(pv);
delete pv;
}
}
- return TRUE;
+ return true;
}
@@ -453,7 +453,7 @@ CBotClassInst::CBotClassInst()
m_var = NULL;
m_Parameters = NULL;
m_expr = NULL;
- m_hasParams = FALSE;
+ m_hasParams = false;
m_nMethodeIdent = 0;
name = "CBotClassInst";
}
@@ -484,18 +484,17 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass*
p = p->GivNext();
}
- BOOL bIntrinsic = pClass->IsIntrinsic();
- CBotTypResult
- type = CBotTypResult( bIntrinsic ? CBotTypIntrinsic : CBotTypPointer,
- pClass );
+ bool bIntrinsic = pClass->IsIntrinsic();
+ CBotTypResult type = CBotTypResult( bIntrinsic ? CBotTypIntrinsic : CBotTypPointer, pClass );
CBotClassInst* inst = (CBotClassInst*)CompileArray(p, pStack, type);
if ( inst != NULL || !pStack->IsOk() ) return inst;
CBotCStack* pStk = pStack->TokenStack();
inst = new CBotClassInst();
-
- inst->SetToken(&pClass->GivName(), p->GivStart(), p->GivEnd());
+ /// \TODO Need to be revised and fixed after adding unit tests
+ CBotToken token(pClass->GivName(), CBotString(), p->GivStart(), p->GivEnd());
+ inst->SetToken(&token);
CBotToken* vartoken = p;
if ( NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) )
@@ -601,7 +600,7 @@ CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass*
var->SetPointer( pvar ); // var déjà déclarée pointe l'instance
delete pvar; // supprime le second pointeur
}
- var->SetInit(TRUE); // marque le pointeur comme init
+ var->SetInit(true); // marque le pointeur comme init
}
else if (inst->m_hasParams)
{
@@ -640,17 +639,17 @@ error:
// déclaration de l'instance d'une classe, par exemple:
// CPoint A, B;
-BOOL CBotClassInst::Execute(CBotStack* &pj)
+bool CBotClassInst::Execute(CBotStack* &pj)
{
CBotVar* pThis = NULL;
CBotStack* pile = pj->AddStack(this);//indispensable pour SetState()
-// if ( pile == EOX ) return TRUE;
+// if ( pile == EOX ) return true;
CBotToken* pt = &m_token;
CBotClass* pClass = CBotClass::Find(pt);
- BOOL bIntrincic = pClass->IsIntrinsic();
+ bool bIntrincic = pClass->IsIntrinsic();
// crée la variable de type pointeur à l'objet
@@ -682,7 +681,7 @@ BOOL CBotClassInst::Execute(CBotStack* &pj)
if ( m_expr != NULL )
{
// évalue l'expression pour l'assignation
- if (!m_expr->Execute(pile)) return FALSE;
+ if (!m_expr->Execute(pile)) return false;
if ( bIntrincic )
{
@@ -692,7 +691,7 @@ BOOL CBotClassInst::Execute(CBotStack* &pj)
pile->SetError(TX_NULLPT, &m_token);
return pj->Return(pile);
}
- pThis->Copy(pile->GivVar(), FALSE);
+ pThis->Copy(pile->GivVar(), false);
}
else
{
@@ -700,7 +699,7 @@ BOOL CBotClassInst::Execute(CBotStack* &pj)
pInstance = ((CBotVarPointer*)pile->GivVar())->GivPointer(); // valeur pour l'assignation
pThis->SetPointer(pInstance);
}
- pThis->SetInit(TRUE);
+ pThis->SetInit(true);
}
else if ( m_hasParams )
@@ -732,12 +731,12 @@ BOOL CBotClassInst::Execute(CBotStack* &pj)
// et place les valeurs sur la pile
// pour pouvoir être interrompu n'importe quand
- if ( p != NULL) while ( TRUE )
+ if ( p != NULL) while ( true )
{
pile2 = pile2->AddStack(); // de la place sur la pile pour les résultats
if ( pile2->GivState() == 0 )
{
- if (!p->Execute(pile2)) return FALSE; // interrompu ici ?
+ if (!p->Execute(pile2)) return false; // interrompu ici ?
pile2->SetState(1);
}
ppVars[i++] = pile2->GivVar();
@@ -751,9 +750,9 @@ BOOL CBotClassInst::Execute(CBotStack* &pj)
if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GivName(),
pThis, ppVars,
- pResult, pile2, GivToken())) return FALSE; // interrompu
+ pResult, pile2, GivToken())) return false; // interrompu
- pThis->SetInit(TRUE);
+ pThis->SetInit(true);
pThis->ConstructorSet(); // signale que le constructeur a été appelé
pile->Return(pile2); // libère un bout de pile
@@ -766,17 +765,17 @@ BOOL CBotClassInst::Execute(CBotStack* &pj)
pile->SetState(3); // fini cette partie
}
- if ( pile->IfStep() ) return FALSE;
+ if ( pile->IfStep() ) return false;
if ( m_next2b != NULL &&
- !m_next2b->Execute(pile)) return FALSE; // autre(s) définition(s)
+ !m_next2b->Execute(pile)) return false; // autre(s) définition(s)
return pj->Return( pile ); // transmet en dessous
}
-void CBotClassInst::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotClassInst::RestoreState(CBotStack* &pj, bool bMain)
{
CBotVar* pThis = NULL;
@@ -793,7 +792,7 @@ void CBotClassInst::RestoreState(CBotStack* &pj, BOOL bMain)
CBotToken* pt = &m_token;
CBotClass* pClass = CBotClass::Find(pt);
- BOOL bIntrincic = pClass->IsIntrinsic();
+ bool bIntrincic = pClass->IsIntrinsic();
if ( bMain && pile->GivState()<3)
{
@@ -827,7 +826,7 @@ void CBotClassInst::RestoreState(CBotStack* &pj, BOOL bMain)
// et place les valeurs sur la pile
// pour pouvoir être interrompu n'importe quand
- if ( p != NULL) while ( TRUE )
+ if ( p != NULL) while ( true )
{
pile2 = pile2->RestoreStack(); // de la place sur la pile pour les résultats
if ( pile2 == NULL ) return;
@@ -858,11 +857,11 @@ void CBotClassInst::RestoreState(CBotStack* &pj, BOOL bMain)
// test si un nom de procédure est déjà défini quelque part
-BOOL CBotClass::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
+bool CBotClass::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
{
CBotString name = pToken->GivString();
- if ( CBotCall::CheckCall(name) ) return TRUE;
+ if ( CBotCall::CheckCall(name) ) return true;
CBotFunction* pp = m_pMethod;
while ( pp != NULL )
@@ -871,11 +870,11 @@ BOOL CBotClass::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
{
// les paramètres sont-ils exactement les mêmes ?
if ( pp->CheckParam( pParam ) )
- return TRUE;
+ return true;
}
pp = pp->Next();
}
- return FALSE;
+ return false;
}
diff --git a/src/CBot/CBotCompExpr.cpp b/src/CBot/CBotCompExpr.cpp
index 41e7e05..0f296d5 100644
--- a/src/CBot/CBotCompExpr.cpp
+++ b/src/CBot/CBotCompExpr.cpp
@@ -83,7 +83,7 @@ CBotInstr* CBotCompExpr::Compile(CBotToken* &p, CBotCStack* pStack)
// fait l'opération
-BOOL CBotCompExpr::Execute(CBotStack* &pStack)
+bool CBotCompExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this);
// if ( pStk1 == EOX ) return TRUE;
diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h
index 7fa9472..f2e2297 100644
--- a/src/CBot/CBotDll.h
+++ b/src/CBot/CBotDll.h
@@ -13,161 +13,153 @@
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.////////////////////////////////////////////////////////////////////////
-// Librairie pour l'interprétation du language CBOT
-// pour le jeu COLOBOT
-//
-
-//#include "stdafx.h"
+#ifndef _CBOTDLL_H_
+#define _CBOTDLL_H_
+/**
+ * \file CBotDll.h
+ * \brief Library for interpretation of CBOT language
+ */
-#include <windows.h>
#include <stdio.h>
+#include "resource.h"
+#include <map>
+#include <cstring>
-#define DllExport __declspec( dllexport )
-#define CBOTVERSION 104
+#define CBOTVERSION 104
////////////////////////////////////////////////////////////////////////
-// quelques classes définies par ailleurs
-
-class CBotToken; // programme transformé en "jetons"
-class CBotStack; // pile pour l'exécution
-class CBotClass; // classe d'object
-class CBotInstr; // instruction à exécuter
-class CBotFunction; // les fonctions user
-class CBotVar; // les variables
-class CBotVarClass; // une instance de classe
-class CBotVarPointer; // pointeur à une instance de classe
-class CBotCall; // les fonctions
-class CBotCallMethode; // les méthodes
-class CBotDefParam; // liste de paramètres
-class CBotCStack;
+// forward declaration of needed classes
+
+class CBotToken; // program turned into "tokens
+class CBotStack; // for the execution stack
+class CBotClass; // class of object
+class CBotInstr; // instruction to be executed
+class CBotFunction; // user functions
+class CBotVar; // variables
+class CBotVarClass; // instance of class
+class CBotVarPointer; // pointer to an instance of class
+class CBotCall; // fonctions
+class CBotCallMethode; // methods
+class CBotDefParam; // parameter list
+class CBotCStack; // stack
////////////////////////////////////////////////////////////////////////
-// Gestion des variables
+// Variables management
////////////////////////////////////////////////////////////////////////
-// ces types sont calqués sur les types Java
-// ne pas changer l'ordre de ces types
-
+/** \brief CBotType Defines known types. This types are modeled on Java types. Do not change the order of elements */
enum CBotType
{
- CBotTypVoid = 0, // fonction retournant void
- CBotTypByte = 1, //n // nombre entier ( 8 bits)
- CBotTypShort = 2, //n // nombre entier (16 bits)
- CBotTypChar = 3, //n // caractère "unicode" (16 bits)
- CBotTypInt = 4, // nombre entier (32 bits)
- CBotTypLong = 5, //n // nombre entier (64 bits)
- CBotTypFloat = 6, // nombre décimal (32 bits)
- CBotTypDouble = 7, //n // nombre décimal (64 bits)
- CBotTypBoolean = 8, // true ou false exclusivement
- CBotTypString = 9, // chaine de caractère
-
- CBotTypArrayPointer = 10, // un tableau de variables
- CBotTypArrayBody = 11, // idem mais crée l'instance
-
- CBotTypPointer = 12, // pointeur à une instance
- CBotTypNullPointer = 13, // pointeur null est spécial
-
- CBotTypClass = 15, // instance d'une classe
- CBotTypIntrinsic = 16 // instance d'une classe intrinsèque
+ CBotTypVoid = 0,
+ CBotTypByte = 1, //n
+ CBotTypShort = 2, //n
+ CBotTypChar = 3, //n
+ CBotTypInt = 4,
+ CBotTypLong = 5, //n
+ CBotTypFloat = 6,
+ CBotTypDouble = 7, //n
+ CBotTypBoolean = 8,
+ CBotTypString = 9,
+
+ CBotTypArrayPointer = 10, // array of variables
+ CBotTypArrayBody = 11, // same but creates an instance
+
+ CBotTypPointer = 12, // pointer to an instance
+ CBotTypNullPointer = 13, // null pointer is special
+ CBotTypClass = 15,
+ CBotTypIntrinsic = 16 // instance of a class intrinsic
};
- //n = non encore implémenté
+//n = not implemented yet
-// pour SetUserPtr lors de la suppression d'un objet
+// for SetUserPtr when deleting an object
#define OBJECTDELETED ((void*)-1)
-// valeur mise avant initialisation
+// value set before initialization
#define OBJECTCREATED ((void*)-2)
-// classe permettant de définir le type complet d'un résultat
+/** \brief CBotTypResult class to define the complete type of a result*/
class CBotTypResult
{
-private:
- int m_type;
- CBotTypResult* m_pNext; // pour les types de types
- CBotClass* m_pClass; // pour les dérivés de classe
- int m_limite; // limitation des tableaux
- friend class CBotVarClass;
- friend class CBotVarPointer;
-
public:
- // divers constructeurs selon les besoins
- DllExport
- CBotTypResult(int type);
- // pour les types simples (CBotTypInt à CBotTypString)
- DllExport
- CBotTypResult(int type, const char* name);
- // pour les types pointeur et classe intrinsic
- DllExport
- CBotTypResult(int type, CBotClass* pClass);
- // idem à partir de l'instance d'une classe
- DllExport
- CBotTypResult(int type, CBotTypResult elem);
- // pour les tableaux de variables
-
- DllExport
- CBotTypResult(const CBotTypResult& typ);
- // pour les assignations
- DllExport
- CBotTypResult();
- // pour par défaut
- DllExport
- ~CBotTypResult();
-
- DllExport
- int GivType(int mode = 0) const;
- // rend le type CBotTyp* du résultat
-
- void SetType(int n);
- // modifie le type
-
- DllExport
- CBotClass* GivClass() const;
- // rend le pointeur à la classe (pour les CBotTypClass, CBotTypPointer)
-
- DllExport
- int GivLimite() const;
- // rend la taille limite du tableau (CBotTypArray)
-
- DllExport
- void SetLimite(int n);
- // fixe une limite au tableau
-
- void SetArray(int* max );
- // idem avec une liste de dimension (tableaux de tableaux)
-
- DllExport
- CBotTypResult& GivTypElem() const;
- // rend le type des éléments du tableau (CBotTypArray)
-
- DllExport
- BOOL Compare(const CBotTypResult& typ) const;
- // compare si les types sont compatibles
- DllExport
- BOOL Eq(int type) const;
- // compare le type
-
- DllExport
- CBotTypResult&
- operator=(const CBotTypResult& src);
- // copie un type complet dans un autre
+ /**
+ * \brief CBotTypResult constructor of an object
+ * \param type type of created result, see CBotType
+ */
+ CBotTypResult(int type);
+
+ /**
+ * \brief CBotTypResult constructor for simple types (CBotTypInt to CBotTypString)
+ * \param type type of created result, see CBotType
+ * \param name
+ */
+ // pour les types simples (CBotTypInt à CBotTypString)
+ CBotTypResult(int type, const char* name);
+ // pour les types pointeur et classe intrinsic
+ CBotTypResult(int type, CBotClass* pClass);
+ // idem à partir de l'instance d'une classe
+ CBotTypResult(int type, CBotTypResult elem);
+ // pour les tableaux de variables
+
+ CBotTypResult(const CBotTypResult& typ);
+ // pour les assignations
+ CBotTypResult();
+ // pour par défaut
+ ~CBotTypResult();
+
+ int GivType(int mode = 0) const;
+ // rend le type CBotTyp* du résultat
+
+ void SetType(int n);
+ // modifie le type
+
+ CBotClass* GivClass() const;
+ // rend le pointeur à la classe (pour les CBotTypClass, CBotTypPointer)
+
+ int GivLimite() const;
+ // rend la taille limite du tableau (CBotTypArray)
+
+ void SetLimite(int n);
+ // fixe une limite au tableau
+
+ void SetArray(int* max );
+ // idem avec une liste de dimension (tableaux de tableaux)
+
+ CBotTypResult& GivTypElem() const;
+ // rend le type des éléments du tableau (CBotTypArray)
+
+ bool Compare(const CBotTypResult& typ) const;
+ // compare si les types sont compatibles
+ bool Eq(int type) const;
+ // compare le type
+
+ CBotTypResult&
+ operator=(const CBotTypResult& src);
+ // copie un type complet dans un autre
+private:
+ int m_type;
+ CBotTypResult* m_pNext; // pour les types de types
+ CBotClass* m_pClass; // pour les dérivés de classe
+ int m_limite; // limitation des tableaux
+ friend class CBotVarClass;
+ friend class CBotVarPointer;
};
/*
// pour définir un résultat en sortie, utiliser par exemple
- // pour rendre un simple Float
- return CBotTypResult( CBotTypFloat );
+ // pour rendre un simple Float
+ return CBotTypResult( CBotTypFloat );
- // pour rendre un tableau de string
- return CBotTypResult( CBotTypArray, CBotTypResult( CBotTypString ) );
+ // pour rendre un tableau de string
+ return CBotTypResult( CBotTypArray, CBotTypResult( CBotTypString ) );
- // pour rendre un tableau de tableau de "point"
- CBotTypResult typPoint( CBotTypIntrinsic, "point" );
- CBotTypResult arrPoint( CBotTypArray, typPoint );
- return CBotTypResult( CBotTypArray, arrPoint );
+ // pour rendre un tableau de tableau de "point"
+ CBotTypResult typPoint( CBotTypIntrinsic, "point" );
+ CBotTypResult arrPoint( CBotTypArray, typPoint );
+ return CBotTypResult( CBotTypArray, arrPoint );
*/
@@ -178,70 +170,70 @@ public:
// voici la liste des erreurs pouvant être retournées par le module
// pour la compilation
-#define CBotErrOpenPar 5000 // manque la parenthèse ouvrante
-#define CBotErrClosePar 5001 // manque la parenthèse fermante
-#define CBotErrNotBoolean 5002 // l'expression doit être un boolean
-#define CBotErrUndefVar 5003 // variable non déclarée
-#define CBotErrBadLeft 5004 // assignation impossible ( 5 = ... )
-#define CBotErrNoTerminator 5005 // point-virgule attendu
-#define CBotErrCaseOut 5006 // case en dehors d'un switch
-// CBotErrNoTerm 5007, plus utile
-#define CBotErrCloseBlock 5008 // manque " } "
-#define CBotErrElseWhitoutIf 5009 // else sans if correspondant
-#define CBotErrOpenBlock 5010 // manque " { "
-#define CBotErrBadType1 5011 // mauvais type pour l'assignation
-#define CBotErrRedefVar 5012 // redéfinition de la variable
-#define CBotErrBadType2 5013 // 2 opérandes de type incompatibles
-#define CBotErrUndefCall 5014 // routine inconnue
-#define CBotErrNoDoubleDots 5015 // " : " attendu
-// CBotErrWhile 5016, plus utile
-#define CBotErrBreakOutside 5017 // break en dehors d'une boucle
-#define CBotErrUndefLabel 5019 // label inconnu
-#define CBotErrLabel 5018 // label ne peut se mettre ici
-#define CBotErrNoCase 5020 // manque " case "
-#define CBotErrBadNum 5021 // nombre attendu
-#define CBotErrVoid 5022 // " void " pas possible ici
-#define CBotErrNoType 5023 // déclaration de type attendue
-#define CBotErrNoVar 5024 // nom de variable attendu
-#define CBotErrNoFunc 5025 // nom de fonction attendu
-#define CBotErrOverParam 5026 // trop de paramètres
-#define CBotErrRedefFunc 5027 // cette fonction existe déjà
-#define CBotErrLowParam 5028 // pas assez de paramètres
-#define CBotErrBadParam 5029 // mauvais types de paramètres
-#define CBotErrNbParam 5030 // mauvais nombre de paramètres
-#define CBotErrUndefItem 5031 // élément n'existe pas dans la classe
-#define CBotErrUndefClass 5032 // variable n'est pas une classe
-#define CBotErrNoConstruct 5033 // pas de constructeur approprié
-#define CBotErrRedefClass 5034 // classe existe déjà
-#define CBotErrCloseIndex 5035 // " ] " attendu
-#define CBotErrReserved 5036 // mot réservé (par un DefineNum)
-#define CBotErrBadNew 5037 // mauvais paramètre pour new
-#define CBotErrOpenIndex 5038 // " [ " attendu
-#define CBotErrBadString 5039 // chaîne de caractère attendue
-#define CBotErrBadIndex 5040 // mauvais type d'index "[ false ]"
-#define CBotErrPrivate 5041 // élément protégé
-#define CBotErrNoPublic 5042 // manque le mot "public"
+#define CBotErrOpenPar 5000 // manque la parenthèse ouvrante
+#define CBotErrClosePar 5001 // manque la parenthèse fermante
+#define CBotErrNotBoolean 5002 // l'expression doit être un boolean
+#define CBotErrUndefVar 5003 // variable non déclarée
+#define CBotErrBadLeft 5004 // assignation impossible ( 5 = ... )
+#define CBotErrNoTerminator 5005 // point-virgule attendu
+#define CBotErrCaseOut 5006 // case en dehors d'un switch
+// CBotErrNoTerm 5007, plus utile
+#define CBotErrCloseBlock 5008 // manque " } "
+#define CBotErrElseWhitoutIf 5009 // else sans if correspondant
+#define CBotErrOpenBlock 5010 // manque " { "
+#define CBotErrBadType1 5011 // mauvais type pour l'assignation
+#define CBotErrRedefVar 5012 // redéfinition de la variable
+#define CBotErrBadType2 5013 // 2 opérandes de type incompatibles
+#define CBotErrUndefCall 5014 // routine inconnue
+#define CBotErrNoDoubleDots 5015 // " : " attendu
+// CBotErrWhile 5016, plus utile
+#define CBotErrBreakOutside 5017 // break en dehors d'une boucle
+#define CBotErrUndefLabel 5019 // label inconnu
+#define CBotErrLabel 5018 // label ne peut se mettre ici
+#define CBotErrNoCase 5020 // manque " case "
+#define CBotErrBadNum 5021 // nombre attendu
+#define CBotErrVoid 5022 // " void " pas possible ici
+#define CBotErrNoType 5023 // déclaration de type attendue
+#define CBotErrNoVar 5024 // nom de variable attendu
+#define CBotErrNoFunc 5025 // nom de fonction attendu
+#define CBotErrOverParam 5026 // trop de paramètres
+#define CBotErrRedefFunc 5027 // cette fonction existe déjà
+#define CBotErrLowParam 5028 // pas assez de paramètres
+#define CBotErrBadParam 5029 // mauvais types de paramètres
+#define CBotErrNbParam 5030 // mauvais nombre de paramètres
+#define CBotErrUndefItem 5031 // élément n'existe pas dans la classe
+#define CBotErrUndefClass 5032 // variable n'est pas une classe
+#define CBotErrNoConstruct 5033 // pas de constructeur approprié
+#define CBotErrRedefClass 5034 // classe existe déjà
+#define CBotErrCloseIndex 5035 // " ] " attendu
+#define CBotErrReserved 5036 // mot réservé (par un DefineNum)
+#define CBotErrBadNew 5037 // mauvais paramètre pour new
+#define CBotErrOpenIndex 5038 // " [ " attendu
+#define CBotErrBadString 5039 // chaîne de caractère attendue
+#define CBotErrBadIndex 5040 // mauvais type d'index "[ false ]"
+#define CBotErrPrivate 5041 // élément protégé
+#define CBotErrNoPublic 5042 // manque le mot "public"
// voici la liste des erreurs pouvant être retournées par le module
// pour l'exécution
-#define CBotErrZeroDiv 6000 // division par zéro
-#define CBotErrNotInit 6001 // variable non initialisée
-#define CBotErrBadThrow 6002 // throw d'une valeur négative
-#define CBotErrNoRetVal 6003 // fonction n'a pas retourné de résultat
-#define CBotErrNoRun 6004 // Run() sans fonction active
-#define CBotErrUndefFunc 6005 // appel d'une fonction qui n'existe plus
-#define CBotErrNotClass 6006 // cette classe n'existe pas
-#define CBotErrNull 6007 // pointeur null
-#define CBotErrNan 6008 // calcul avec un NAN
-#define CBotErrOutArray 6009 // index hors du tableau
-#define CBotErrStackOver 6010 // dépassement de la pile
-#define CBotErrDeletedPtr 6011 // pointeur à un objet détruit
-
-#define CBotErrFileOpen 6012 // ouverture du fichier impossible
-#define CBotErrNotOpen 6013 // canal pas ouvert
-#define CBotErrRead 6014 // erreur à la lecture
-#define CBotErrWrite 6015 // erreur à l'écriture
+#define CBotErrZeroDiv 6000 // division par zéro
+#define CBotErrNotInit 6001 // variable non initialisée
+#define CBotErrBadThrow 6002 // throw d'une valeur négative
+#define CBotErrNoRetVal 6003 // fonction n'a pas retourné de résultat
+#define CBotErrNoRun 6004 // Run() sans fonction active
+#define CBotErrUndefFunc 6005 // appel d'une fonction qui n'existe plus
+#define CBotErrNotClass 6006 // cette classe n'existe pas
+#define CBotErrNull 6007 // pointeur null
+#define CBotErrNan 6008 // calcul avec un NAN
+#define CBotErrOutArray 6009 // index hors du tableau
+#define CBotErrStackOver 6010 // dépassement de la pile
+#define CBotErrDeletedPtr 6011 // pointeur à un objet détruit
+
+#define CBotErrFileOpen 6012 // ouverture du fichier impossible
+#define CBotErrNotOpen 6013 // canal pas ouvert
+#define CBotErrRead 6014 // erreur à la lecture
+#define CBotErrWrite 6015 // erreur à l'écriture
// d'autres valeurs peuvent être rendues
// par exemple les exceptions rendues par les routines externes
@@ -249,113 +241,82 @@ public:
////////////////////////////////////////////////////////////////////////
-// définie une classe pour l'utilisation des strings
+//
// car CString fait partie de MFC pas utilisé ici.
//
// ( toutes les fonctions ne sont pas encore implémentées )
+/** \brief CBotString Class used to work on strings */
class CBotString
{
+public:
+ CBotString();
+ CBotString(const char* p);
+ CBotString(const CBotString& p);
+ ~CBotString();
+
+ void Empty();
+ bool IsEmpty() const;
+ int GivLength();
+ int Find(const char c);
+ int Find(const char* lpsz);
+ int ReverseFind(const char c);
+ int ReverseFind(const char* lpsz);
+ bool LoadString(unsigned int id);
+ CBotString Mid(int nFirst, int nCount) const;
+ CBotString Mid(int nFirst) const;
+ CBotString Mid(int start, int lg=-1);
+ CBotString Left(int nCount) const;
+ CBotString Right(int nCount) const;
+ int Compare(const char* lpsz) const;
+ void MakeUpper();
+ void MakeLower();
+
+
+ /**
+ * \brief Overloaded oprators to work on CBotString classes
+ */
+ const CBotString& operator=(const CBotString& stringSrc);
+ const CBotString& operator=(const char ch);
+ const CBotString& operator=(const char* pString);
+ const CBotString& operator+(const CBotString& str);
+ friend CBotString operator+(const CBotString& string, const char* lpsz);
+
+ const CBotString& operator+=(const char ch);
+ const CBotString& operator+=(const CBotString& str);
+ bool operator==(const CBotString& str);
+ bool operator==(const char* p);
+ bool operator!=(const CBotString& str);
+ bool operator!=(const char* p);
+ bool operator>(const CBotString& str);
+ bool operator>(const char* p);
+ bool operator>=(const CBotString& str);
+ bool operator>=(const char* p);
+ bool operator<(const CBotString& str);
+ bool operator<(const char* p);
+ bool operator<=(const CBotString& str);
+ bool operator<=(const char* p);
+
+ operator const char*() const; // as a C string
+
+
private:
- char* m_ptr; // pointeur à la chaine
- int m_lg; // longueur de la chaine
- static
- HINSTANCE m_hInstance;
-public:
- DllExport
- CBotString();
- DllExport
- CBotString(const char* p);
- DllExport
- CBotString(const CBotString& p);
- DllExport
- ~CBotString();
-
- DllExport
- void Empty();
- DllExport
- BOOL IsEmpty() const;
- DllExport
- int GivLength();
- DllExport
- int Find(const char c);
- DllExport
- int Find(LPCTSTR lpsz);
- DllExport
- int ReverseFind(const char c);
- DllExport
- int ReverseFind(LPCTSTR lpsz);
- DllExport
- BOOL LoadString(UINT id);
- DllExport
- CBotString Mid(int nFirst, int nCount) const;
- DllExport
- CBotString Mid(int nFirst) const;
- DllExport
- CBotString Left(int nCount) const;
- DllExport
- CBotString Right(int nCount) const;
-
- DllExport
- const CBotString&
- operator=(const CBotString& stringSrc);
- DllExport
- const CBotString&
- operator=(const char ch);
- DllExport
- const CBotString&
- operator=(const char* pString);
- DllExport
- const CBotString&
- operator+(const CBotString& str);
- DllExport
- friend CBotString
- operator+(const CBotString& string, LPCTSTR lpsz);
-
- DllExport
- const CBotString&
- operator+=(const char ch);
- DllExport
- const CBotString&
- operator+=(const CBotString& str);
- DllExport
- BOOL operator==(const CBotString& str);
- DllExport
- BOOL operator==(const char* p);
- DllExport
- BOOL operator!=(const CBotString& str);
- DllExport
- BOOL operator!=(const char* p);
- DllExport
- BOOL operator>(const CBotString& str);
- DllExport
- BOOL operator>(const char* p);
- DllExport
- BOOL operator>=(const CBotString& str);
- DllExport
- BOOL operator>=(const char* p);
- DllExport
- BOOL operator<(const CBotString& str);
- DllExport
- BOOL operator<(const char* p);
- DllExport
- BOOL operator<=(const CBotString& str);
- DllExport
- BOOL operator<=(const char* p);
-
- DllExport
- operator LPCTSTR() const; // as a C string
-
- int Compare(LPCTSTR lpsz) const;
-
- DllExport
- CBotString Mid(int start, int lg=-1);
-
- DllExport
- void MakeUpper();
- DllExport
- void MakeLower();
+ /** \brief Pointer to string */
+ char* m_ptr;
+
+ /** \brief Length of the string */
+ int m_lg;
+
+ /** \brief Keeps the string corresponding to keyword ID */
+ static const std::map<EID, char *> s_keywordString;
+
+ /**
+ * \brief MapIdToString maps given ID to its string equivalent
+ * \param id Provided identifier
+ * \return string if found, else NullString
+ */
+ static const char * MapIdToString(EID id);
};
@@ -364,35 +325,28 @@ public:
class CBotStringArray : public CBotString
{
private:
- int m_nSize; // nombre d'éléments
- int m_nMaxSize; // taille réservée
- CBotString* m_pData; // ^aux données
+ int m_nSize; // nombre d'éléments
+ int m_nMaxSize; // taille réservée
+ CBotString* m_pData; // ^aux données
public:
- DllExport
- CBotStringArray();
- DllExport
- ~CBotStringArray();
- DllExport
- void SetSize(int nb);
- DllExport
- int GivSize();
- DllExport
- void Add(const CBotString& str);
- DllExport
- CBotString& operator[](int nIndex);
-
- DllExport
- CBotString& ElementAt(int nIndex);
+ CBotStringArray();
+ ~CBotStringArray();
+ void SetSize(int nb);
+ int GivSize();
+ void Add(const CBotString& str);
+ CBotString& operator[](int nIndex);
+
+ CBotString& ElementAt(int nIndex);
};
// différents mode pour GetPosition
enum CBotGet
{
- GetPosExtern = 1,
- GetPosNom = 2,
- GetPosParam = 3,
- GetPosBloc = 4
+ GetPosExtern = 1,
+ GetPosNom = 2,
+ GetPosParam = 3,
+ GetPosBloc = 4
};
////////////////////////////////////////////////////////////////////
@@ -402,211 +356,183 @@ enum CBotGet
class CBotProgram
{
private:
- CBotFunction* m_Prog; // les fonctions définies par l'utilisateur
- CBotFunction* m_pRun; // la fonction de base pour l'exécution
- CBotClass* m_pClass; // les classes définies dans cette partie
- CBotStack* m_pStack; // la pile d'exécution
- CBotVar* m_pInstance; // instance de la classe parent
- friend class CBotFunction;
+ CBotFunction* m_Prog; // les fonctions définies par l'utilisateur
+ CBotFunction* m_pRun; // la fonction de base pour l'exécution
+ CBotClass* m_pClass; // les classes définies dans cette partie
+ CBotStack* m_pStack; // la pile d'exécution
+ CBotVar* m_pInstance; // instance de la classe parent
+ friend class CBotFunction;
- int m_ErrorCode;
- int m_ErrorStart;
- int m_ErrorEnd;
+ int m_ErrorCode;
+ int m_ErrorStart;
+ int m_ErrorEnd;
- long m_Ident; // identificateur associé
+ long m_Ident; // identificateur associé
public:
- static
- CBotString m_DebugVarStr; // a fin de debug
- BOOL m_bDebugDD; // idem déclanchable par robot
+ static
+ CBotString m_DebugVarStr; // a fin de debug
+ bool m_bDebugDD; // idem déclanchable par robot
- BOOL m_bCompileClass;
+ bool m_bCompileClass;
public:
- DllExport
- static
- void Init();
- // initialise le module (défini les mots clefs pour les erreurs)
- // doit être fait une fois (et une seule) au tout début
- DllExport
- static
- void Free();
- // libère les zones mémoires statiques
-
- DllExport
- static
- int GivVersion();
- // donne la version de la librairie CBOT
-
-
- DllExport
- CBotProgram();
- DllExport
- CBotProgram(CBotVar* pInstance);
- DllExport
- ~CBotProgram();
-
- DllExport
- BOOL Compile( const char* program, CBotStringArray& ListFonctions, void* pUser = NULL);
- // compile le programme donné en texte
- // retourne FALSE s'il y a une erreur à la compilation
- // voir GetCompileError() pour récupérer l'erreur
- // ListFonctions retourne le nom des fonctions déclarées extern
- // pUser permet de passer un pointeur pour les routines définies par AddFunction
-
- DllExport
- void SetIdent(long n);
- // associe un identificateur avec l'instance CBotProgram
-
- DllExport
- long GivIdent();
- // redonne l'identificateur
-
- DllExport
- int GivError();
- DllExport
- BOOL GetError(int& code, int& start, int& end);
- DllExport
- BOOL GetError(int& code, int& start, int& end, CBotProgram* &pProg);
- // si TRUE
- // donne l'erreur trouvée à la compilation
- // ou à l'exécution
- // start et end délimite le bloc où se trouve l'erreur
- // pProg permet de savoir dans quel "module" s'est produite l'erreur d'exécution
- DllExport
- static
- CBotString GivErrorText(int code);
-
-
- DllExport
- BOOL Start(const char* name);
- // définie quelle fonction doit être exécutée
- // retourne FALSE si la fontion name n'est pas trouvée
- // le programme ne fait rien, il faut appeller Run() pour cela
-
- DllExport
- BOOL Run(void* pUser = NULL, int timer = -1);
- // exécute le programme
- // retourne FALSE si le programme a été suspendu
- // retourne TRUE si le programme s'est terminé avec ou sans erreur
- // timer = 0 permet de faire une avance pas à pas
-
- DllExport
- BOOL GetRunPos(const char* &FunctionName, int &start, int &end);
- // donne la position dans le programme en exécution
- // retourne FALSE si on n'est pas en exécution (programme terminé)
- // FunctionName est un pointeur rendu sur le nom de la fonction
- // start et end la position dans le texte du token en traitement
-
- DllExport
- CBotVar* GivStackVars(const char* &FunctionName, int level);
- // permet d'obtenir le pointeur aux variables sur la pile d'exécution
- // level est un paramètre d'entrée, 0 pour le dernier niveau, -1, -2, etc pour les autres niveau
- // la valeur retournée (CBotVar*) est une liste de variable (ou NULL)
- // qui peut être traité que la liste des paramètres reçu par une routine
- // FunctionName donne le nom de la fonction où se trouvent ces variables
- // FunctionName == NULL signifiant qu'on est plus dans le programme (selon level)
-
- DllExport
- void Stop();
- // arrête l'exécution du programme
- // quitte donc le mode "suspendu"
-
- DllExport
- static
- void SetTimer(int n);
- // défini le nombre de pas (parties d'instructions) à faire
- // dans Run() avant de rendre la main "FALSE"
-
- DllExport
- static
- BOOL AddFunction(const char* name,
- BOOL rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
- CBotTypResult rCompile (CBotVar* &pVar, void* pUser));
- // cet appel permet d'ajouter de manière externe (**)
- // une nouvelle fonction utilisable par le programme CBot
-
- DllExport
- static
- BOOL DefineNum(const char* name, long val);
-
- DllExport
- BOOL SaveState(FILE* pf);
- // sauvegarde l'état d'exécution dans le fichier
- // le fichier doit avoir été ouvert avec l'appel fopen de cette dll
- // sinon le système plante
- DllExport
- BOOL RestoreState(FILE* pf);
- // rétablie l'état de l'exécution depuis le fichier
- // le programme compilé doit évidemment être identique
-
- DllExport
- BOOL GetPosition(const char* name, int& start, int& stop,
- CBotGet modestart = GetPosExtern,
- CBotGet modestop = GetPosBloc);
- // donne la position d'une routine dans le texte d'origine
- // le mode permet de choisir l'élément à trouver pour le début et la fin
- // voir les modes ci-dessus dans CBotGet
-
-
- CBotFunction* GivFunctions();
+ static
+ void Init();
+ // initialise le module (défini les mots clefs pour les erreurs)
+ // doit être fait une fois (et une seule) au tout début
+ static
+ void Free();
+ // libère les zones mémoires statiques
+
+ static
+ int GivVersion();
+ // donne la version de la librairie CBOT
+
+
+ CBotProgram();
+ CBotProgram(CBotVar* pInstance);
+ ~CBotProgram();
+
+ bool Compile( const char* program, CBotStringArray& ListFonctions, void* pUser = NULL);
+ // compile le programme donné en texte
+ // retourne false s'il y a une erreur à la compilation
+ // voir GetCompileError() pour récupérer l'erreur
+ // ListFonctions retourne le nom des fonctions déclarées extern
+ // pUser permet de passer un pointeur pour les routines définies par AddFunction
+
+ void SetIdent(long n);
+ // associe un identificateur avec l'instance CBotProgram
+
+ long GivIdent();
+ // redonne l'identificateur
+
+ int GivError();
+ bool GetError(int& code, int& start, int& end);
+ bool GetError(int& code, int& start, int& end, CBotProgram* &pProg);
+ // si true
+ // donne l'erreur trouvée à la compilation
+ // ou à l'exécution
+ // start et end délimite le bloc où se trouve l'erreur
+ // pProg permet de savoir dans quel "module" s'est produite l'erreur d'exécution
+ static
+ CBotString GivErrorText(int code);
+
+
+ bool Start(const char* name);
+ // définie quelle fonction doit être exécutée
+ // retourne false si la fontion name n'est pas trouvée
+ // le programme ne fait rien, il faut appeller Run() pour cela
+
+ bool Run(void* pUser = NULL, int timer = -1);
+ // exécute le programme
+ // retourne false si le programme a été suspendu
+ // retourne true si le programme s'est terminé avec ou sans erreur
+ // timer = 0 permet de faire une avance pas à pas
+
+ bool GetRunPos(const char* &FunctionName, int &start, int &end);
+ // donne la position dans le programme en exécution
+ // retourne false si on n'est pas en exécution (programme terminé)
+ // FunctionName est un pointeur rendu sur le nom de la fonction
+ // start et end la position dans le texte du token en traitement
+
+ CBotVar* GivStackVars(const char* &FunctionName, int level);
+ // permet d'obtenir le pointeur aux variables sur la pile d'exécution
+ // level est un paramètre d'entrée, 0 pour le dernier niveau, -1, -2, etc pour les autres niveau
+ // la valeur retournée (CBotVar*) est une liste de variable (ou NULL)
+ // qui peut être traité que la liste des paramètres reçu par une routine
+ // FunctionName donne le nom de la fonction où se trouvent ces variables
+ // FunctionName == NULL signifiant qu'on est plus dans le programme (selon level)
+
+ void Stop();
+ // arrête l'exécution du programme
+ // quitte donc le mode "suspendu"
+
+ static
+ void SetTimer(int n);
+ // défini le nombre de pas (parties d'instructions) à faire
+ // dans Run() avant de rendre la main "false"
+
+ static
+ bool AddFunction(const char* name,
+ bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
+ CBotTypResult rCompile (CBotVar* &pVar, void* pUser));
+ // cet appel permet d'ajouter de manière externe (**)
+ // une nouvelle fonction utilisable par le programme CBot
+
+ static
+ bool DefineNum(const char* name, long val);
+
+ bool SaveState(FILE* pf);
+ // sauvegarde l'état d'exécution dans le fichier
+ // le fichier doit avoir été ouvert avec l'appel fopen de cette dll
+ // sinon le système plante
+ bool RestoreState(FILE* pf);
+ // rétablie l'état de l'exécution depuis le fichier
+ // le programme compilé doit évidemment être identique
+
+ bool GetPosition(const char* name, int& start, int& stop,
+ CBotGet modestart = GetPosExtern,
+ CBotGet modestop = GetPosBloc);
+ // donne la position d'une routine dans le texte d'origine
+ // le mode permet de choisir l'élément à trouver pour le début et la fin
+ // voir les modes ci-dessus dans CBotGet
+
+
+ CBotFunction* GivFunctions();
};
///////////////////////////////////////////////////////////////////////////////
// routines pour la gestion d'un fichier (FILE*)
- DllExport
- FILE* fOpen(const char* name, const char* mode);
- DllExport
- int fClose(FILE* filehandle);
- DllExport
- size_t fWrite(const void *buffer, size_t elemsize, size_t length, FILE* filehandle);
- DllExport
- size_t fRead(void *buffer, size_t elemsize, size_t length, FILE* filehandle);
+ FILE* fOpen(const char* name, const char* mode);
+ int fClose(FILE* filehandle);
+ size_t fWrite(const void *buffer, size_t elemsize, size_t length, FILE* filehandle);
+ size_t fRead(void *buffer, size_t elemsize, size_t length, FILE* filehandle);
#if 0
/*
(**) Note:
- Pour définir une fonction externe, il faut procéder ainsi:
+ Pour définir une fonction externe, il faut procéder ainsi:
- a) définir une routine pour la compilation
- cette routine reçois la liste des paramètres (sans valeurs)
- et retourne soit un type de résultat (CBotTyp... ou 0 = void)
- soit un numéro d'erreur
- b) définir une routine pour l'exécution
- cette rourine reCoit la liste des paramètres (avec valeurs),
- une variable pour stocker le résultat (selon le type donné à la compilation)
+ a) définir une routine pour la compilation
+ cette routine reçois la liste des paramètres (sans valeurs)
+ et retourne soit un type de résultat (CBotTyp... ou 0 = void)
+ soit un numéro d'erreur
+ b) définir une routine pour l'exécution
+ cette rourine reCoit la liste des paramètres (avec valeurs),
+ une variable pour stocker le résultat (selon le type donné à la compilation)
- Par exemple, une routine qui calcule la moyenne d'une liste de paramètres */
+ Par exemple, une routine qui calcule la moyenne d'une liste de paramètres */
-int cMoyenne(CBotVar* &pVar, CBotString& ClassName)
+int cMoyenne(CBotVar* &pVar, CBotString& ClassName)
{
- if ( pVar == NULL ) return 6001; // il n'y a aucun paramètre !
+ if ( pVar == NULL ) return 6001; // il n'y a aucun paramètre !
- while ( pVar != NULL )
- {
- if ( pVar->GivType() > CBotTypDouble ) return 6002; // ce n'est pas un nombre
- pVar = pVar -> GivNext();
- }
+ while ( pVar != NULL )
+ {
+ if ( pVar->GivType() > CBotTypDouble ) return 6002; // ce n'est pas un nombre
+ pVar = pVar -> GivNext();
+ }
- return CBotTypFloat; // le type du résultat pourrait dépendre des paramètres !
+ return CBotTypFloat; // le type du résultat pourrait dépendre des paramètres !
}
-BOOL rMoyenne(CBotVar* pVar, CBotVar* pResult, int& Exception)
+bool rMoyenne(CBotVar* pVar, CBotVar* pResult, int& Exception)
{
- float total = 0;
- int nb = 0;
- while (pVar != NULL)
- {
- total += pVar->GivValFloat();
- pVar = pVar->GivNext();
- nb++;
- }
- pResult->SetValFloat(total/nb); // retourne la valeur moyenne
-
- return TRUE; // opération totalement terminée
+ float total = 0;
+ int nb = 0;
+ while (pVar != NULL)
+ {
+ total += pVar->GivValFloat();
+ pVar = pVar->GivNext();
+ nb++;
+ }
+ pResult->SetValFloat(total/nb); // retourne la valeur moyenne
+
+ return true; // opération totalement terminée
}
#endif
@@ -614,256 +540,221 @@ BOOL rMoyenne(CBotVar* pVar, CBotVar* pResult, int& Exception)
/////////////////////////////////////////////////////////////////////////////////
// Classe pour la gestion des variables
-// les méthodes marquées DllExport
// peuvent être utile à l'exterieur du module
// ( il n'est pour l'instant pas prévu de pouvoir créer ces objets en externe )
// résultats pour GivInit()
-#define IS_UNDEF 0 // variable indéfinie
-#define IS_DEF 1 // variable définie
-#define IS_NAN 999 // variable définie comme étant not a number
+#define IS_UNDEF 0 // variable indéfinie
+#define IS_DEF 1 // variable définie
+#define IS_NAN 999 // variable définie comme étant not a number
// type de variable SetPrivate / IsPrivate
-#define PR_PUBLIC 0 // variable publique
-#define PR_READ 1 // read only
-#define PR_PROTECT 2 // protected (héritage)
-#define PR_PRIVATE 3 // strictement privée
+#define PR_PUBLIC 0 // variable publique
+#define PR_READ 1 // read only
+#define PR_PROTECT 2 // protected (héritage)
+#define PR_PRIVATE 3 // strictement privée
class CBotVar
{
protected:
- CBotToken* m_token; // le token correspondant
+ CBotToken* m_token; // le token correspondant
- CBotVar* m_next; // liste de variables
- friend class CBotStack;
- friend class CBotCStack;
- friend class CBotInstrCall;
- friend class CBotProgram;
+ CBotVar* m_next; // liste de variables
+ friend class CBotStack;
+ friend class CBotCStack;
+ friend class CBotInstrCall;
+ friend class CBotProgram;
- CBotTypResult m_type; // type de valeur
+ CBotTypResult m_type; // type de valeur
- int m_binit; // pas initialisée ?
- CBotVarClass* m_pMyThis; // ^élément this correspondant
- void* m_pUserPtr; // ^données user s'il y a lieu
- BOOL m_bStatic; // élément static (dans une classe)
- int m_mPrivate; // élément public, protected ou private ?
+ int m_binit; // pas initialisée ?
+ CBotVarClass* m_pMyThis; // ^élément this correspondant
+ void* m_pUserPtr; // ^données user s'il y a lieu
+ bool m_bStatic; // élément static (dans une classe)
+ int m_mPrivate; // élément public, protected ou private ?
- CBotInstr* m_InitExpr; // expression pour le contenu initial
- CBotInstr* m_LimExpr; // liste des limites pour un tableau
- friend class CBotClass;
- friend class CBotVarClass;
- friend class CBotVarPointer;
- friend class CBotVarArray;
+ CBotInstr* m_InitExpr; // expression pour le contenu initial
+ CBotInstr* m_LimExpr; // liste des limites pour un tableau
+ friend class CBotClass;
+ friend class CBotVarClass;
+ friend class CBotVarPointer;
+ friend class CBotVarArray;
- long m_ident; // identificateur unique
- static long m_identcpt; // compteur
+ long m_ident; // identificateur unique
+ static long m_identcpt; // compteur
public:
- CBotVar();
-virtual ~CBotVar( ); // destructeur
+ CBotVar();
+virtual ~CBotVar( ); // destructeur
+
+ static
+ CBotVar* Create( const char* name, CBotTypResult type);
+ // idem à partir du type complet
+ static
+ CBotVar* Create( const char* name, CBotClass* pClass);
+ // idem pour une instance d'une classe connue
-/* DllExport
- static
- CBotVar* Create( const char* name, int type, const char* ClassName = NULL);
- // crée une variable selon son type,*/
+ static
+ CBotVar* Create( const CBotToken* name, int type );
+ static
+ CBotVar* Create( const CBotToken* name, CBotTypResult type );
- DllExport
- static
- CBotVar* Create( const char* name, CBotTypResult type);
- // idem à partir du type complet
+ static
+ CBotVar* Create( const char* name, int type, CBotClass* pClass);
- DllExport
- static
- CBotVar* Create( const char* name, CBotClass* pClass);
- // idem pour une instance d'une classe connue
+ static
+ CBotVar* Create( CBotVar* pVar );
- static
- CBotVar* Create( const CBotToken* name, int type );
- static
- CBotVar* Create( const CBotToken* name, CBotTypResult type );
- static
- CBotVar* Create( const char* name, int type, CBotClass* pClass);
+ void SetUserPtr(void* pUser);
+ // associe un pointeur utilisateur à une instance
- static
- CBotVar* Create( CBotVar* pVar );
+ virtual void SetIdent(long UniqId);
+ // associe un identificateur unique à une instance
+ // ( c'est à l'utilisateur de s'assurer que l'id est unique)
+ void* GivUserPtr();
+ // rend le pointeur associé à la variable
- DllExport
- void SetUserPtr(void* pUser);
- // associe un pointeur utilisateur à une instance
+ CBotString GivName(); // le nom de la variable, s'il est connu
+ ////////////////////////////////////////////////////////////////////////////////////
+ void SetName(const char* name); // change le nom de la variable
- DllExport
- virtual void SetIdent(long UniqId);
- // associe un identificateur unique à une instance
- // ( c'est à l'utilisateur de s'assurer que l'id est unique)
+ int GivType(int mode = 0); // rend le type de base (int) de la variable
+ ////////////////////////////////////////////////////////////////////////////////////////
- DllExport
- void* GivUserPtr();
- // rend le pointeur associé à la variable
+ CBotTypResult GivTypResult(int mode = 0); // rend le type complet de la variable
- DllExport
- CBotString GivName(); // le nom de la variable, s'il est connu
- ////////////////////////////////////////////////////////////////////////////////////
- void SetName(const char* name); // change le nom de la variable
- DllExport
- int GivType(int mode = 0); // rend le type de base (int) de la variable
- ////////////////////////////////////////////////////////////////////////////////////////
+ CBotToken* GivToken();
+ void SetType(CBotTypResult& type);
- DllExport
- CBotTypResult GivTypResult(int mode = 0); // rend le type complet de la variable
+ void SetInit(int bInit); // met la variable dans l'état IS_UNDEF, IS_DEF, IS_NAN
+ int GivInit(); // donne l'état de la variable
- CBotToken* GivToken();
- void SetType(CBotTypResult& type);
+ void SetStatic(bool bStatic);
+ bool IsStatic();
- DllExport
- void SetInit(int bInit); // met la variable dans l'état IS_UNDEF, IS_DEF, IS_NAN
+ void SetPrivate(int mPrivate);
+ bool IsPrivate(int mode = PR_PROTECT);
+ int GivPrivate();
- DllExport
- int GivInit(); // donne l'état de la variable
+ virtual
+ void ConstructorSet();
- DllExport
- void SetStatic(BOOL bStatic);
- DllExport
- BOOL IsStatic();
+ void SetVal(CBotVar* var); // remprend une valeur
- DllExport
- void SetPrivate(int mPrivate);
- DllExport
- BOOL IsPrivate(int mode = PR_PROTECT);
- DllExport
- int GivPrivate();
+ virtual
+ CBotVar* GivItem(const char* name); // rend un élément d'une classe selon son nom (*)
+ virtual
+ CBotVar* GivItemRef(int nIdent); // idem à partir du n° ref
- virtual
- void ConstructorSet();
+ virtual
+ CBotVar* GivItem(int row, bool bGrow = false);
- void SetVal(CBotVar* var); // remprend une valeur
+ virtual
+ CBotVar* GivItemList(); // donne la liste des éléments
- DllExport
- virtual
- CBotVar* GivItem(const char* name); // rend un élément d'une classe selon son nom (*)
- virtual
- CBotVar* GivItemRef(int nIdent); // idem à partir du n° ref
+ CBotVar* GivStaticVar(); // rend le pointeur à la variable si elle est statique
- DllExport
- virtual
- CBotVar* GivItem(int row, BOOL bGrow = FALSE);
+ bool IsElemOfClass(const char* name);
+ // dit si l'élément appartient à la classe "name"
+ // rend true si l'objet est d'une classe fille
- DllExport
- virtual
- CBotVar* GivItemList(); // donne la liste des éléments
+ CBotVar* GivNext(); // prochaine variable dans la liste (paramètres)
+ ////////////////////////////////////////////////////////////////////////////////////////////
- DllExport
- CBotVar* GivStaticVar(); // rend le pointeur à la variable si elle est statique
+ void AddNext(CBotVar* pVar); // ajoute dans une liste
- DllExport
- BOOL IsElemOfClass(const char* name);
- // dit si l'élément appartient à la classe "name"
- // rend TRUE si l'objet est d'une classe fille
-
- DllExport
- CBotVar* GivNext(); // prochaine variable dans la liste (paramètres)
- ////////////////////////////////////////////////////////////////////////////////////////////
+ virtual
+ void Copy(CBotVar* pSrc, bool bName = true); // fait une copie de la variable
- void AddNext(CBotVar* pVar); // ajoute dans une liste
+ virtual void SetValInt(int val, const char* name = NULL);
+ // initialise avec une valeur entière (#)
+ /////////////////////////////////////////////////////////////////////////////////
- virtual
- void Copy(CBotVar* pSrc, BOOL bName = TRUE); // fait une copie de la variable
+ virtual void SetValFloat(float val); // initialise avec une valeur réelle (#)
+ ////////////////////////////////////////////////////////////////////////////////
- DllExport
- virtual void SetValInt(int val, const char* name = NULL);
- // initialise avec une valeur entière (#)
- /////////////////////////////////////////////////////////////////////////////////
+ virtual void SetValString(const char* p);// initialise avec une valeur chaîne (#)
+ ////////////////////////////////////////////////////////////////////////////////
- DllExport
- virtual void SetValFloat(float val); // initialise avec une valeur réelle (#)
- ////////////////////////////////////////////////////////////////////////////////
+ virtual int GivValInt(); // demande la valeur entière (#)
+ ////////////////////////////////////////////////////////////////////////
- DllExport
- virtual void SetValString(const char* p);// initialise avec une valeur chaîne (#)
- ////////////////////////////////////////////////////////////////////////////////
+ virtual float GivValFloat(); // demande la valeur réelle (#)
+ ///////////////////////////////////////////////////////////////////////
- DllExport
- virtual int GivValInt(); // demande la valeur entière (#)
- ////////////////////////////////////////////////////////////////////////
+ virtual
+ CBotString GivValString(); // demande la valeur chaîne (#)
+ ///////////////////////////////////////////////////////////////////////
- DllExport
- virtual float GivValFloat(); // demande la valeur réelle (#)
- ///////////////////////////////////////////////////////////////////////
+ virtual void SetClass(CBotClass* pClass);
+ virtual
+ CBotClass* GivClass();
- virtual
- CBotString GivValString(); // demande la valeur chaîne (#)
- ///////////////////////////////////////////////////////////////////////
+ virtual void SetPointer(CBotVar* p);
+ virtual
+ CBotVarClass* GivPointer();
+// virtual void SetIndirection(CBotVar* pVar);
- virtual void SetClass(CBotClass* pClass);
- virtual
- CBotClass* GivClass();
+ virtual void Add(CBotVar* left, CBotVar* right); // addition
+ virtual void Sub(CBotVar* left, CBotVar* right); // soustraction
+ virtual void Mul(CBotVar* left, CBotVar* right); // multiplication
+ virtual int Div(CBotVar* left, CBotVar* right); // division
+ virtual int Modulo(CBotVar* left, CBotVar* right); // reste de division
+ virtual void Power(CBotVar* left, CBotVar* right); // puissance
- virtual void SetPointer(CBotVar* p);
- virtual
- CBotVarClass* GivPointer();
-// virtual void SetIndirection(CBotVar* pVar);
+ virtual bool Lo(CBotVar* left, CBotVar* right);
+ virtual bool Hi(CBotVar* left, CBotVar* right);
+ virtual bool Ls(CBotVar* left, CBotVar* right);
+ virtual bool Hs(CBotVar* left, CBotVar* right);
+ virtual bool Eq(CBotVar* left, CBotVar* right);
+ virtual bool Ne(CBotVar* left, CBotVar* right);
- virtual void Add(CBotVar* left, CBotVar* right); // addition
- virtual void Sub(CBotVar* left, CBotVar* right); // soustraction
- virtual void Mul(CBotVar* left, CBotVar* right); // multiplication
- virtual int Div(CBotVar* left, CBotVar* right); // division
- virtual int Modulo(CBotVar* left, CBotVar* right); // reste de division
- virtual void Power(CBotVar* left, CBotVar* right); // puissance
+ virtual void And(CBotVar* left, CBotVar* right);
+ virtual void Or(CBotVar* left, CBotVar* right);
+ virtual void XOr(CBotVar* left, CBotVar* right);
+ virtual void ASR(CBotVar* left, CBotVar* right);
+ virtual void SR(CBotVar* left, CBotVar* right);
+ virtual void SL(CBotVar* left, CBotVar* right);
- virtual BOOL Lo(CBotVar* left, CBotVar* right);
- virtual BOOL Hi(CBotVar* left, CBotVar* right);
- virtual BOOL Ls(CBotVar* left, CBotVar* right);
- virtual BOOL Hs(CBotVar* left, CBotVar* right);
- virtual BOOL Eq(CBotVar* left, CBotVar* right);
- virtual BOOL Ne(CBotVar* left, CBotVar* right);
-
- virtual void And(CBotVar* left, CBotVar* right);
- virtual void Or(CBotVar* left, CBotVar* right);
- virtual void XOr(CBotVar* left, CBotVar* right);
- virtual void ASR(CBotVar* left, CBotVar* right);
- virtual void SR(CBotVar* left, CBotVar* right);
- virtual void SL(CBotVar* left, CBotVar* right);
-
- virtual void Neg();
- virtual void Not();
- virtual void Inc();
- virtual void Dec();
-
-
- virtual BOOL Save0State(FILE* pf);
- virtual BOOL Save1State(FILE* pf);
- static BOOL RestoreState(FILE* pf, CBotVar* &pVar);
-
- DllExport
- void debug();
-
-// virtual
-// CBotVar* GivMyThis();
-
- DllExport
- virtual
- void Maj(void* pUser = NULL, BOOL bContinue = TRUE);
-
- void SetUniqNum(long n);
- long GivUniqNum();
- static long NextUniqNum();
+ virtual void Neg();
+ virtual void Not();
+ virtual void Inc();
+ virtual void Dec();
+
+
+ virtual bool Save0State(FILE* pf);
+ virtual bool Save1State(FILE* pf);
+ static bool RestoreState(FILE* pf, CBotVar* &pVar);
+
+ void debug();
+
+// virtual
+// CBotVar* GivMyThis();
+
+ virtual
+ void Maj(void* pUser = NULL, bool bContinue = true);
+
+ void SetUniqNum(long n);
+ long GivUniqNum();
+ static long NextUniqNum();
};
/* NOTE (#)
- les méthodes SetValInt() SetValFloat() et SetValString()
- ne peuvent êtes appellées qu'avec des objets respectivement entier, réelle ou chaîne
- toujours s'assurer du type de la variable avant d'appeller ces méthodes
+ les méthodes SetValInt() SetValFloat() et SetValString()
+ ne peuvent êtes appellées qu'avec des objets respectivement entier, réelle ou chaîne
+ toujours s'assurer du type de la variable avant d'appeller ces méthodes
- if ( pVar->GivType() == CBotInt() ) pVar->SetValFloat( 3.3 ); // plante !!
+ if ( pVar->GivType() == CBotInt() ) pVar->SetValFloat( 3.3 ); // plante !!
- les méthodes GivValInt(), GivValFloat() et GivValString()
- font des conversions de valeur,
- GivValString() fonctionne sur des nombres (rend la chaîne correspondante)
- par contre il ne faut pas faire de GivValInt() avec une variable de type chaîne !
+ les méthodes GivValInt(), GivValFloat() et GivValString()
+ font des conversions de valeur,
+ GivValString() fonctionne sur des nombres (rend la chaîne correspondante)
+ par contre il ne faut pas faire de GivValInt() avec une variable de type chaîne !
*/
@@ -878,227 +769,205 @@ virtual ~CBotVar( ); // destructeur
class CBotClass
{
private:
- static
- CBotClass* m_ExClass; // liste des classes existante à un moment donné
- CBotClass* m_ExNext; // pour cette liste générale
- CBotClass* m_ExPrev; // pour cette liste générale
+ static
+ CBotClass* m_ExClass; // liste des classes existante à un moment donné
+ CBotClass* m_ExNext; // pour cette liste générale
+ CBotClass* m_ExPrev; // pour cette liste générale
private:
- CBotClass* m_pParent; // classe parent
- CBotString m_name; // nom de cette classe-ci
- int m_nbVar; // nombre de variables dans la chaîne
- CBotVar* m_pVar; // contenu de la classe
- BOOL m_bIntrinsic; // classe intrinsèque
- CBotClass* m_next; // chaine les classe
- CBotCallMethode* m_pCalls; // liste des méthodes définie en externe
- CBotFunction* m_pMethod; // liste des méthodes compilées
- void (*m_rMaj) ( CBotVar* pThis, void* pUser );
- friend class CBotVarClass;
- int m_cptLock; // pour Lock / UnLock
- int m_cptOne; // pour réentrance Lock
- CBotProgram* m_ProgInLock[5];// processus en attente pour synchro
+ CBotClass* m_pParent; // classe parent
+ CBotString m_name; // nom de cette classe-ci
+ int m_nbVar; // nombre de variables dans la chaîne
+ CBotVar* m_pVar; // contenu de la classe
+ bool m_bIntrinsic; // classe intrinsèque
+ CBotClass* m_next; // chaine les classe
+ CBotCallMethode* m_pCalls; // liste des méthodes définie en externe
+ CBotFunction* m_pMethod; // liste des méthodes compilées
+ void (*m_rMaj) ( CBotVar* pThis, void* pUser );
+ friend class CBotVarClass;
+ int m_cptLock; // pour Lock / UnLock
+ int m_cptOne; // pour réentrance Lock
+ CBotProgram* m_ProgInLock[5];// processus en attente pour synchro
public:
- BOOL m_IsDef; // marque si est définie ou pas encore
-
- DllExport
- CBotClass( const char* name,
- CBotClass* pParent, BOOL bIntrinsic = FALSE ); // constructeur
- // Dès qu'une classe est créée, elle est connue
- // partout dans CBot
- // le mode intrinsic donne une classe qui n'est pas gérée par des pointeurs
-
- DllExport
- ~CBotClass( ); // destructeur
-
- DllExport
- BOOL AddFunction(const char* name,
- BOOL rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception),
- CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar));
- // cet appel permet d'ajouter de manière externe (**)
- // une nouvelle méthode utilisable par les objets de cette classe
-
- DllExport
- BOOL AddUpdateFunc( void rMaj ( CBotVar* pThis, void* pUser ) );
- // défini la routine qui sera appellée pour mettre à jour les élements de la classe
-
- DllExport
- BOOL AddItem(CBotString name, CBotTypResult type, int mPrivate = PR_PUBLIC);
- // ajoute un élément à la classe
-// DllExport
-// BOOL AddItem(CBotString name, CBotClass* pClass);
- // idem pour des éléments appartenant à pClass
- DllExport
- BOOL AddItem(CBotVar* pVar);
- // idem en passant le pointeur à une instance d'une variable
- // l'objet est pris tel quel, il ne faut donc pas le détruire
-
-
-
- // idem en donnant un élément de type CBotVar
- void AddNext(CBotClass* pClass);
-
- DllExport
- CBotString GivName(); // rend le nom de la classe
- DllExport
- CBotClass* GivParent(); // donne la classe père (ou NULL)
-
- // dit si une classe est dérivée (Extends) d'une autre
- // rend TRUE aussi si les classes sont identiques
- DllExport
- BOOL IsChildOf(CBotClass* pClass);
-
- static
- CBotClass* Find(CBotToken* &pToken); // trouve une classe d'après son nom
-
- DllExport
- static
- CBotClass* Find(const char* name);
-
- CBotVar* GivVar(); // rend la liste des variables
- CBotVar* GivItem(const char* name); // l'une des variables selon son nom
- CBotVar* GivItemRef(int nIdent);
-
- CBotTypResult CompileMethode(const char* name, CBotVar* pThis, CBotVar** ppParams,
- CBotCStack* pStack, long& nIdent);
-
- BOOL ExecuteMethode(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppParams, CBotVar* &pResult, CBotStack* &pStack, CBotToken* pToken);
- void RestoreMethode(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppParams, CBotStack* &pStack);
-
- // compile une classe déclarée par l'utilisateur
- static
- CBotClass* Compile(CBotToken* &p, CBotCStack* pStack);
- static
- CBotClass* Compile1(CBotToken* &p, CBotCStack* pStack);
-
- BOOL CompileDefItem(CBotToken* &p, CBotCStack* pStack, BOOL bSecond);
-
- BOOL IsIntrinsic();
- void Purge();
- static
- void Free();
-
- DllExport
- static
- BOOL SaveStaticState(FILE* pf);
-
- DllExport
- static
- BOOL RestoreStaticState(FILE* pf);
-
- BOOL Lock(CBotProgram* p);
- void Unlock();
- static
- void FreeLock(CBotProgram* p);
-
- BOOL CheckCall(CBotToken* &pToken, CBotDefParam* pParam);
+ bool m_IsDef; // marque si est définie ou pas encore
+
+ CBotClass( const char* name,
+ CBotClass* pParent, bool bIntrinsic = false ); // constructeur
+ // Dès qu'une classe est créée, elle est connue
+ // partout dans CBot
+ // le mode intrinsic donne une classe qui n'est pas gérée par des pointeurs
+
+ ~CBotClass( ); // destructeur
+
+ bool AddFunction(const char* name,
+ bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception),
+ CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar));
+ // cet appel permet d'ajouter de manière externe (**)
+ // une nouvelle méthode utilisable par les objets de cette classe
+
+ bool AddUpdateFunc( void rMaj ( CBotVar* pThis, void* pUser ) );
+ // défini la routine qui sera appellée pour mettre à jour les élements de la classe
+
+ bool AddItem(CBotString name, CBotTypResult type, int mPrivate = PR_PUBLIC);
+ // ajoute un élément à la classe
+// bool AddItem(CBotString name, CBotClass* pClass);
+ // idem pour des éléments appartenant à pClass
+ bool AddItem(CBotVar* pVar);
+ // idem en passant le pointeur à une instance d'une variable
+ // l'objet est pris tel quel, il ne faut donc pas le détruire
+
+
+
+ // idem en donnant un élément de type CBotVar
+ void AddNext(CBotClass* pClass);
+
+ CBotString GivName(); // rend le nom de la classe
+ CBotClass* GivParent(); // donne la classe père (ou NULL)
+
+ // dit si une classe est dérivée (Extends) d'une autre
+ // rend true aussi si les classes sont identiques
+ bool IsChildOf(CBotClass* pClass);
+
+ static
+ CBotClass* Find(CBotToken* &pToken); // trouve une classe d'après son nom
+
+ static
+ CBotClass* Find(const char* name);
+
+ CBotVar* GivVar(); // rend la liste des variables
+ CBotVar* GivItem(const char* name); // l'une des variables selon son nom
+ CBotVar* GivItemRef(int nIdent);
+
+ CBotTypResult CompileMethode(const char* name, CBotVar* pThis, CBotVar** ppParams,
+ CBotCStack* pStack, long& nIdent);
+
+ bool ExecuteMethode(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppParams, CBotVar* &pResult, CBotStack* &pStack, CBotToken* pToken);
+ void RestoreMethode(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppParams, CBotStack* &pStack);
+
+ // compile une classe déclarée par l'utilisateur
+ static
+ CBotClass* Compile(CBotToken* &p, CBotCStack* pStack);
+ static
+ CBotClass* Compile1(CBotToken* &p, CBotCStack* pStack);
+
+ bool CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond);
+
+ bool IsIntrinsic();
+ void Purge();
+ static
+ void Free();
+
+ static
+ bool SaveStaticState(FILE* pf);
+
+ static
+ bool RestoreStaticState(FILE* pf);
+
+ bool Lock(CBotProgram* p);
+ void Unlock();
+ static
+ void FreeLock(CBotProgram* p);
+
+ bool CheckCall(CBotToken* &pToken, CBotDefParam* pParam);
};
-#define MAXDEFNUM 1000 // nombre limite des DefineNum
+#define MAXDEFNUM 1000 // nombre limite des DefineNum
/////////////////////////////////////////////////////////////////////////////////////
// gestion des jetons (tokens)
-#define TokenTypKeyWord 1 // un mot clef du language (voir TokenKeyWord)
-#define TokenTypNum 2 // un nombre
-#define TokenTypString 3 // une chaine
-#define TokenTypVar 4 // un nom de variable
-#define TokenTypDef 5 // une valeur selon DefineNum
+#define TokenTypKeyWord 1 // un mot clef du language (voir TokenKeyWord)
+#define TokenTypNum 2 // un nombre
+#define TokenTypString 3 // une chaine
+#define TokenTypVar 4 // un nom de variable
+#define TokenTypDef 5 // une valeur selon DefineNum
-#define TokenKeyWord 2000 // les mots clefs du langage
-#define TokenKeyDeclare 2100 // mots clefs pour déclarations (int, float,..)
-#define TokenKeyVal 2200 // les mots représentant une "valeur" (true, false, null, nan)
-#define TokenKeyOp 2300 // les opérateurs
+#define TokenKeyWord 2000 // les mots clefs du langage
+#define TokenKeyDeclare 2100 // mots clefs pour déclarations (int, float,..)
+#define TokenKeyVal 2200 // les mots représentant une "valeur" (true, false, null, nan)
+#define TokenKeyOp 2300 // les opérateurs
class CBotToken
{
private:
- static
- CBotStringArray m_ListKeyWords; // liste des mots clefs du language
- static
- int m_ListIdKeyWords[200]; // les codes correspondants
+ static
+ CBotStringArray m_ListKeyWords; // liste des mots clefs du language
+ static
+ int m_ListIdKeyWords[200]; // les codes correspondants
- static
- CBotStringArray m_ListKeyDefine; // les noms définis par un DefineNum
- static
- long m_ListKeyNums[MAXDEFNUM]; // les valeurs associées
+ static
+ CBotStringArray m_ListKeyDefine; // les noms définis par un DefineNum
+ static
+ long m_ListKeyNums[MAXDEFNUM]; // les valeurs associées
private:
- CBotToken* m_next; // suivant dans la liste
- CBotToken* m_prev;
- int m_type; // type de Token
- long m_IdKeyWord; // numéro du mot clef si c'en est un
- // ou valeur du "define"
+ CBotToken* m_next; // suivant dans la liste
+ CBotToken* m_prev;
+ int m_type; // type de Token
+ long m_IdKeyWord; // numéro du mot clef si c'en est un
+ // ou valeur du "define"
- CBotString m_Text; // mot trouvé comme token
- CBotString m_Sep; // séparateurs qui suivent
+ CBotString m_Text; // mot trouvé comme token
+ CBotString m_Sep; // séparateurs qui suivent
- int m_start; // position dans le texte d'origine (programme)
- int m_end; // itou pour la fin du token
+ int m_start; // position dans le texte d'origine (programme)
+ int m_end; // itou pour la fin du token
- static
- int GivKeyWords(const char* w); // est-ce un mot clef ?
- static
- BOOL GivKeyDefNum(const char* w, CBotToken* &token);
+ static
+ int GivKeyWords(const char* w); // est-ce un mot clef ?
+ static
+ bool GivKeyDefNum(const char* w, CBotToken* &token);
- static
- void LoadKeyWords(); // fait la liste des mots clefs
+ static
+ void LoadKeyWords(); // fait la liste des mots clefs
public:
- CBotToken();
- CBotToken(const CBotToken* pSrc);
- CBotToken(const CBotString& mot, const CBotString& sep, int start=0, int end=0);
- CBotToken(const char* mot, const char* sep = NULL);
- // constructeur
- ~CBotToken(); // destructeur
-
- DllExport
- int GivType(); // rend le type du token
-
- DllExport
- CBotString& GivString(); // rend la chaine correspondant à ce token
-
- DllExport
- CBotString& GivSep(); // rend le séparateur suivant le token
-
- DllExport
- int GivStart(); // position du début dans le texte
- DllExport
- int GivEnd(); // position de fin dans le texte
-
- DllExport
- CBotToken* GivNext(); // rend le suivant dans la liste
- DllExport
- CBotToken* GivPrev(); // rend le Précédent dans la liste
-
- DllExport
- static
- CBotToken* CompileTokens(const char* p, int& error);
- // transforme tout le programme
- DllExport
- static
- void Delete(CBotToken* pToken); // libère la liste
-
-
- // fonctions non utiles en export
- static
- BOOL DefineNum(const char* name, long val);
- void SetString(const char* name);
-
- void SetPos(int start, int end);
- long GivIdKey();
- void AddNext(CBotToken* p); // ajoute un token (une copie)
-
- static
- CBotToken* NextToken(char* &program, int& error, BOOL first = FALSE);
- // trouve le prochain token
- const CBotToken&
- operator=(const CBotToken& src);
-
- static
- void Free();
+ CBotToken();
+ CBotToken(const CBotToken* pSrc);
+ CBotToken(const CBotString& mot, const CBotString& sep, int start=0, int end=0);
+ CBotToken(const char* mot, const char* sep = NULL);
+ // constructeur
+ ~CBotToken(); // destructeur
+
+ int GivType(); // rend le type du token
+
+ CBotString& GivString(); // rend la chaine correspondant à ce token
+
+ CBotString& GivSep(); // rend le séparateur suivant le token
+
+ int GivStart(); // position du début dans le texte
+ int GivEnd(); // position de fin dans le texte
+
+ CBotToken* GivNext(); // rend le suivant dans la liste
+ CBotToken* GivPrev(); // rend le Précédent dans la liste
+
+ static
+ CBotToken* CompileTokens(const char* p, int& error);
+ // transforme tout le programme
+ static
+ void Delete(CBotToken* pToken); // libère la liste
+
+
+ // fonctions non utiles en export
+ static
+ bool DefineNum(const char* name, long val);
+ void SetString(const char* name);
+
+ void SetPos(int start, int end);
+ long GivIdKey();
+ void AddNext(CBotToken* p); // ajoute un token (une copie)
+
+ static
+ CBotToken* NextToken(char* &program, int& error, bool first = false);
+ // trouve le prochain token
+ const CBotToken&
+ operator=(const CBotToken& src);
+
+ static
+ void Free();
};
@@ -1111,90 +980,92 @@ public:
// définie la classe globale CPoint
// --------------------------------
- m_pClassPoint = new CBotClass("CPoint", NULL);
- // ajoute le composant ".x"
- m_pClassPoint->AddItem("x", CBotTypResult(CBotTypFloat));
- // ajoute le composant ".y"
- m_pClassPoint->AddItem("y", CBotTypResult(CBotTypFloat));
- // le joueur peut alors utiliser les instructions
- // CPoint position; position.x = 12; position.y = -13.6
+ m_pClassPoint = new CBotClass("CPoint", NULL);
+ // ajoute le composant ".x"
+ m_pClassPoint->AddItem("x", CBotTypResult(CBotTypFloat));
+ // ajoute le composant ".y"
+ m_pClassPoint->AddItem("y", CBotTypResult(CBotTypFloat));
+ // le joueur peut alors utiliser les instructions
+ // CPoint position; position.x = 12; position.y = -13.6
// définie la classe CColobotObject
// --------------------------------
// cette classe gère tous les objets dans le monde de COLOBOT
// le programme utilisateur "main" appartient à cette classe
- m_pClassObject = new CBotClass("CColobotObject", m_pClassBase);
- // ajoute le composant ".position"
- m_pClassObject->AddItem("position", m_pClassPoint);
- // ajoute le composant ".type"
- m_pClassObject->AddItem("type", CBotTypResult(CBotTypShort));
- // ajoute une définition de constante
- m_pClassObject->AddConst("ROBOT", CBotTypShort, 1); // ROBOT équivalent à la valeur 1
- // ajoute la routine FIND
- m_pClassObject->AddFunction( rCompFind, rDoFind );
- // le joueur peut maintenant utiliser les instructions
- // CColobotObject chose; chose = FIND( ROBOT )
+ m_pClassObject = new CBotClass("CColobotObject", m_pClassBase);
+ // ajoute le composant ".position"
+ m_pClassObject->AddItem("position", m_pClassPoint);
+ // ajoute le composant ".type"
+ m_pClassObject->AddItem("type", CBotTypResult(CBotTypShort));
+ // ajoute une définition de constante
+ m_pClassObject->AddConst("ROBOT", CBotTypShort, 1); // ROBOT équivalent à la valeur 1
+ // ajoute la routine FIND
+ m_pClassObject->AddFunction( rCompFind, rDoFind );
+ // le joueur peut maintenant utiliser les instructions
+ // CColobotObject chose; chose = FIND( ROBOT )
// définie la classe CColobotRobot dérivée de CColobotObject
// ---------------------------------------------------------
// les programmes "main" associés aux robots font partie de cette classe
- m_pClassRobot = new CBotClass("CColobotRobot", m_pClassObject);
- // ajoute la routine GOTO
- m_pClassRobot->AddFunction( rCompGoto, rDoGoto );
- // le joueur peut maintenant faire
- // GOTO( FIND ( ROBOT ) );
+ m_pClassRobot = new CBotClass("CColobotRobot", m_pClassObject);
+ // ajoute la routine GOTO
+ m_pClassRobot->AddFunction( rCompGoto, rDoGoto );
+ // le joueur peut maintenant faire
+ // GOTO( FIND ( ROBOT ) );
// crée une instance de la classe Robot
// ------------------------------------
// par exemple un nouveau robot qui vient d'être fabriqué
- CBotVar* m_pMonRobot = new CBotVar("MonRobot", m_pClassRobot);
+ CBotVar* m_pMonRobot = new CBotVar("MonRobot", m_pClassRobot);
// compile le programme main pour ce robot-là
// ------------------------------------------
- CString LeProgramme( "void main() {GOTO(0, 0); return 0;}" );
- if ( !m_pMonRobot->Compile( LeProgramme ) ) {gestion d'erreur...};
+ CString LeProgramme( "void main() {GOTO(0, 0); return 0;}" );
+ if ( !m_pMonRobot->Compile( LeProgramme ) ) {gestion d'erreur...};
// construit une pile pour l'interpréteur
// --------------------------------------
- CBotStack* pStack = new CBotStack(NULL);
+ CBotStack* pStack = new CBotStack(NULL);
// exécute le programme main
// -------------------------
- while( FALSE = m_pMonRobot->Execute( "main", pStack ))
- {
- // programme suspendu
- // on pourrait passer la main à un autre (en sauvegardant pStack pour ce robot-là)
- };
- // programme "main" terminé !
+ while( false = m_pMonRobot->Execute( "main", pStack ))
+ {
+ // programme suspendu
+ // on pourrait passer la main à un autre (en sauvegardant pStack pour ce robot-là)
+ };
+ // programme "main" terminé !
// routine implémentant l'instruction GOTO( CPoint pos )
-BOOL rDoGoto( CBotVar* pVar, CBotVar* pResult, int& exception )
+bool rDoGoto( CBotVar* pVar, CBotVar* pResult, int& exception )
{
- if (pVar->GivType() != CBotTypeClass ||
- pVar->IsElemOfClas("CPoint") ) { exception = 6522; return FALSE; )
- // le paramètre n'est pas de la bonne classe ?
- // NB en fait ce contrôle est déjà fait par la routine pour la compilation
+ if (pVar->GivType() != CBotTypeClass ||
+ pVar->IsElemOfClas("CPoint") ) { exception = 6522; return false; )
+ // le paramètre n'est pas de la bonne classe ?
+ // NB en fait ce contrôle est déjà fait par la routine pour la compilation
- m_PosToGo.Copy( pVar ); // garde la position à atteindre (object type CBotVar)
+ m_PosToGo.Copy( pVar ); // garde la position à atteindre (object type CBotVar)
- // ou alors
- CBotVar* temp;
- temp = pVar->GivItem("x"); // trouve forcément pour un object de type "CPoint"
- ASSERT (temp != NULL && temp->GivType() == CBotTypFloat);
- m_PosToGo.x = temp->GivValFloat();
+ // ou alors
+ CBotVar* temp;
+ temp = pVar->GivItem("x"); // trouve forcément pour un object de type "CPoint"
+ ASSERT (temp != NULL && temp->GivType() == CBotTypFloat);
+ m_PosToGo.x = temp->GivValFloat();
- temp = pVar->GivItem("y"); // trouve forcément pour un object de type "CPoint"
- ASSERT (temp != NULL && temp->GivType() == CBotTypFloat);
- m_PosToGo.y = temp->GivValFloat();
+ temp = pVar->GivItem("y"); // trouve forcément pour un object de type "CPoint"
+ ASSERT (temp != NULL && temp->GivType() == CBotTypFloat);
+ m_PosToGo.y = temp->GivValFloat();
- return (m_CurentPos == m_PosToGo); // rend TRUE si la position est atteinte
- // rend FALSE s'il faut patienter encore
+ return (m_CurentPos == m_PosToGo); // rend true si la position est atteinte
+ // rend false s'il faut patienter encore
}
-#endif \ No newline at end of file
+#endif
+#endif //_CBOTDLL_H_
+
diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp
index 488061c..363b939 100644
--- a/src/CBot/CBotFunction.cpp
+++ b/src/CBot/CBotFunction.cpp
@@ -25,14 +25,14 @@ CBotFunction::CBotFunction()
m_Param = NULL; // liste des paramètres vide
m_Block = NULL; // le bloc d'instructions
m_next = NULL; // les fonctions peuvent être chaînées
- m_bPublic = FALSE; // fonction non publique
- m_bExtern = FALSE; // fonction non externe
+ m_bPublic = false; // fonction non publique
+ m_bExtern = false; // fonction non externe
m_nextpublic = NULL;
m_prevpublic = NULL;
m_pProg = NULL;
// m_nThisIdent = 0;
m_nFuncIdent = 0;
- m_bSynchro = FALSE;
+ m_bSynchro = false;
}
CBotFunction* CBotFunction::m_listPublic = NULL;
@@ -62,17 +62,17 @@ CBotFunction::~CBotFunction()
}
}
-BOOL CBotFunction::IsPublic()
+bool CBotFunction::IsPublic()
{
return m_bPublic;
}
-BOOL CBotFunction::IsExtern()
+bool CBotFunction::IsExtern()
{
return m_bExtern;
}
-BOOL CBotFunction::GetPosition(int& start, int& stop, CBotGet modestart, CBotGet modestop)
+bool CBotFunction::GetPosition(int& start, int& stop, CBotGet modestart, CBotGet modestop)
{
start = m_extern.GivStart();
stop = m_closeblk.GivEnd();
@@ -110,7 +110,7 @@ BOOL CBotFunction::GetPosition(int& start, int& stop, CBotGet modestart, CBotGet
stop = m_closeblk.GivEnd();
}
- return TRUE;
+ return true;
}
@@ -168,7 +168,7 @@ CBotTypResult TypeParam(CBotToken* &p, CBotCStack* pile)
// compile une nouvelle fonction
// bLocal permet de mettre la déclaration des paramètres au même niveau
// que le éléments appartenant à la classe pour les méthodes
-CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunction* finput, BOOL bLocal)
+CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunction* finput, bool bLocal)
{
CBotToken* pp;
CBotFunction* func = finput;
@@ -178,19 +178,19 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct
// func->m_nFuncIdent = CBotVar::NextUniqNum();
- while (TRUE)
+ while (true)
{
if ( IsOfType(p, ID_PUBLIC) )
{
- func->m_bPublic = TRUE;
+ func->m_bPublic = true;
continue;
}
pp = p;
if ( IsOfType(p, ID_EXTERN) )
{
func->m_extern = pp; // pour la position du mot "extern"
- func->m_bExtern = TRUE;
-// func->m_bPublic = TRUE; // donc aussi publique!
+ func->m_bExtern = true;
+// func->m_bPublic = true; // donc aussi publique!
continue;
}
break;
@@ -260,7 +260,7 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct
// et compile le bloc d'instruction qui suit
func->m_openblk = p;
- func->m_Block = CBotBlock::Compile(p, pStk, FALSE);
+ func->m_Block = CBotBlock::Compile(p, pStk, false);
func->m_closeblk = p->GivPrev();
if ( pStk->IsOk() )
{
@@ -286,18 +286,18 @@ CBotFunction* CBotFunction::Compile1(CBotToken* &p, CBotCStack* pStack, CBotClas
CBotFunction* func = new CBotFunction();
func->m_nFuncIdent = CBotVar::NextUniqNum();
- CBotCStack* pStk = pStack->TokenStack(p, TRUE);
+ CBotCStack* pStk = pStack->TokenStack(p, true);
- while (TRUE)
+ while (true)
{
if ( IsOfType(p, ID_PUBLIC) )
{
- // func->m_bPublic = TRUE; // sera fait en passe 2
+ // func->m_bPublic = true; // sera fait en passe 2
continue;
}
if ( IsOfType(p, ID_EXTERN) )
{
- func->m_bExtern = TRUE;
+ func->m_bExtern = true;
continue;
}
break;
@@ -367,16 +367,16 @@ bad:
static int xx = 0;
#endif
-BOOL CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance)
+bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance)
{
CBotStack* pile = pj->AddStack(this, 2); // un bout de pile local à cette fonction
-// if ( pile == EOX ) return TRUE;
+// if ( pile == EOX ) return true;
pile->SetBotCall(m_pProg); // bases pour les routines
if ( pile->GivState() == 0 )
{
- if ( !m_Param->Execute(ppVars, pile) ) return FALSE; // défini les paramètres
+ if ( !m_Param->Execute(ppVars, pile) ) return false; // défini les paramètres
pile->IncState();
}
@@ -403,14 +403,14 @@ BOOL CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance)
pile->IncState();
}
- if ( pile->IfStep() ) return FALSE;
+ if ( pile->IfStep() ) return false;
if ( !m_Block->Execute(pile) )
{
if ( pile->GivError() < 0 )
pile->SetError( 0 );
else
- return FALSE;
+ return false;
}
return pj->Return(pile);
@@ -433,7 +433,7 @@ void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInst
pile2->Delete();
}
- m_Param->RestoreState(pile2, TRUE); // les paramètres
+ m_Param->RestoreState(pile2, true); // les paramètres
if ( !m_MasterClass.IsEmpty() )
{
@@ -442,7 +442,7 @@ void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInst
pThis->SetUniqNum(-2);
}
- m_Block->RestoreState(pile2, TRUE);
+ m_Block->RestoreState(pile2, true);
}
void CBotFunction::AddNext(CBotFunction* p)
@@ -467,7 +467,7 @@ CBotTypResult CBotFunction::CompileCall(const char* name, CBotVar** ppVars, long
// trouve une fonction selon son identificateur unique
// si l'identificateur n'est pas trouvé, cherche selon le nom et les paramètres
-CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const char* name, CBotVar** ppVars, CBotTypResult& TypeOrError, BOOL bPublic)
+CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const char* name, CBotVar** ppVars, CBotTypResult& TypeOrError, bool bPublic)
{
TypeOrError.SetType(TX_UNDEFCALL); // pas de routine de ce nom
CBotFunction* pt;
@@ -632,13 +632,13 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotS
if ( pt != NULL )
{
CBotStack* pStk1 = pStack->AddStack(pt, 2); // pour mettre "this"
-// if ( pStk1 == EOX ) return TRUE;
+// if ( pStk1 == EOX ) return true;
pStk1->SetBotCall(pt->m_pProg); // on a peut-être changé de module
- if ( pStk1->IfStep() ) return FALSE;
+ if ( pStk1->IfStep() ) return false;
- CBotStack* pStk3 = pStk1->AddStack(NULL, TRUE); // paramètres
+ CBotStack* pStk3 = pStk1->AddStack(NULL, true); // paramètres
// prépare les paramètres sur la pile
@@ -680,11 +680,11 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotS
if ( !pStk3->IsOk() && pt->m_pProg != m_pProg )
{
#ifdef _DEBUG
- if ( m_pProg->GivFunctions()->GivName() == "LaCommande" ) return FALSE;
+ if ( m_pProg->GivFunctions()->GivName() == "LaCommande" ) return false;
#endif
pStk3->SetPosError(pToken); // indique l'erreur sur l'appel de procédure
}
- return FALSE; // interrompu !
+ return false; // interrompu !
}
return pStack->Return( pStk3 );
@@ -738,13 +738,13 @@ void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar** ppVars,
if ( pStk1->GivState() == 0 )
{
- pt->m_Param->RestoreState(pStk3, TRUE);
+ pt->m_Param->RestoreState(pStk3, true);
return;
}
// initialise les variables selon paramètres
- pt->m_Param->RestoreState(pStk3, FALSE);
- pt->m_Block->RestoreState(pStk3, TRUE);
+ pt->m_Param->RestoreState(pStk3, false);
+ pt->m_Block->RestoreState(pStk3, true);
}
}
@@ -758,17 +758,17 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar
CBotTypResult type;
CBotProgram* pProgCurrent = pStack->GivBotCall();
- CBotFunction* pt = FindLocalOrPublic(nIdent, name, ppVars, type, FALSE);
+ CBotFunction* pt = FindLocalOrPublic(nIdent, name, ppVars, type, false);
if ( pt != NULL )
{
// DEBUG( "CBotFunction::DoCall" + pt->GivName(), 0, pStack);
CBotStack* pStk = pStack->AddStack(pt, 2);
-// if ( pStk == EOX ) return TRUE;
+// if ( pStk == EOX ) return true;
pStk->SetBotCall(pt->m_pProg); // on a peut-être changé de module
- CBotStack* pStk3 = pStk->AddStack(NULL, TRUE); // pour mettre les paramètres passés
+ CBotStack* pStk3 = pStk->AddStack(NULL, true); // pour mettre les paramètres passés
// prépare les paramètres sur la pile
@@ -776,7 +776,7 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar
{
// met la variable "this" sur la pile
CBotVar* pthis = CBotVar::Create("this", CBotTypNullPointer);
- pthis->Copy(pThis, FALSE);
+ pthis->Copy(pThis, false);
pthis->SetUniqNum(-2); // valeur spéciale
pStk->AddVar(pthis);
@@ -785,7 +785,7 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar
{
// met la variable "super" sur la pile
CBotVar* psuper = CBotVar::Create("super", CBotTypNullPointer);
- psuper->Copy(pThis, FALSE); // en fait identique à "this"
+ psuper->Copy(pThis, false); // en fait identique à "this"
psuper->SetUniqNum(-3); // valeur spéciale
pStk->AddVar(psuper);
}
@@ -798,8 +798,8 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar
{
if ( pt->m_bSynchro )
{
- CBotProgram* pProgBase = pStk->GivBotCall(TRUE);
- if ( !pClass->Lock(pProgBase) ) return FALSE; // attend de pouvoir
+ CBotProgram* pProgBase = pStk->GivBotCall(true);
+ if ( !pClass->Lock(pProgBase) ) return false; // attend de pouvoir
}
pStk->IncState();
}
@@ -820,7 +820,7 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar
pStk3->SetPosError(pToken); // indique l'erreur sur l'appel de procédure
}
}
- return FALSE; // interrompu !
+ return false; // interrompu !
}
if ( pt->m_bSynchro )
@@ -850,30 +850,30 @@ void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar* pThis, C
CBotStack* pStk3 = pStk->RestoreStack(NULL); // pour mettre les paramètres passés
if ( pStk3 == NULL ) return;
- pt->m_Param->RestoreState(pStk3, TRUE); // les paramètres
+ pt->m_Param->RestoreState(pStk3, true); // les paramètres
if ( pStk->GivState() > 1 && // vérouillage est effectif ?
pt->m_bSynchro )
{
- CBotProgram* pProgBase = pStk->GivBotCall(TRUE);
+ CBotProgram* pProgBase = pStk->GivBotCall(true);
pClass->Lock(pProgBase); // vérouille la classe
}
// finalement appelle la fonction trouvée
- pt->m_Block->RestoreState(pStk3, TRUE); // interrompu !
+ pt->m_Block->RestoreState(pStk3, true); // interrompu !
}
}
// regarde si la "signature" des paramètres est identique
-BOOL CBotFunction::CheckParam(CBotDefParam* pParam)
+bool CBotFunction::CheckParam(CBotDefParam* pParam)
{
CBotDefParam* pp = m_Param;
while ( pp != NULL && pParam != NULL )
{
CBotTypResult type1 = pp->GivType();
CBotTypResult type2 = pParam->GivType();
- if ( !type1.Compare(type2) ) return FALSE;
+ if ( !type1.Compare(type2) ) return false;
pp = pp->GivNext();
pParam = pParam->GivNext();
}
@@ -1005,7 +1005,7 @@ void CBotDefParam::AddNext(CBotDefParam* p)
}
-BOOL CBotDefParam::Execute(CBotVar** ppVars, CBotStack* &pj)
+bool CBotDefParam::Execute(CBotVar** ppVars, CBotStack* &pj)
{
int i = 0;
CBotDefParam* p = this;
@@ -1033,7 +1033,7 @@ BOOL CBotDefParam::Execute(CBotVar** ppVars, CBotStack* &pj)
newvar->SetValInt(ppVars[i]->GivValInt());
break;
case CBotTypIntrinsic:
- ((CBotVarClass*)newvar)->Copy(ppVars[i], FALSE);
+ ((CBotVarClass*)newvar)->Copy(ppVars[i], false);
break;
case CBotTypPointer:
case CBotTypArrayPointer:
@@ -1051,10 +1051,10 @@ BOOL CBotDefParam::Execute(CBotVar** ppVars, CBotStack* &pj)
i++;
}
- return TRUE;
+ return true;
}
-void CBotDefParam::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotDefParam::RestoreState(CBotStack* &pj, bool bMain)
{
int i = 0;
CBotDefParam* p = this;
@@ -1146,25 +1146,25 @@ CBotInstr* CBotReturn::Compile(CBotToken* &p, CBotCStack* pStack)
return NULL; // pas d'objet, l'erreur est sur la pile
}
-BOOL CBotReturn::Execute(CBotStack* &pj)
+bool CBotReturn::Execute(CBotStack* &pj)
{
CBotStack* pile = pj->AddStack(this);
-// if ( pile == EOX ) return TRUE;
+// if ( pile == EOX ) return true;
if ( pile->GivState() == 0 )
{
- if ( m_Instr != NULL && !m_Instr->Execute(pile) ) return FALSE; // évalue le résultat
+ if ( m_Instr != NULL && !m_Instr->Execute(pile) ) return false; // évalue le résultat
// le résultat est sur la pile
pile->IncState();
}
- if ( pile->IfStep() ) return FALSE;
+ if ( pile->IfStep() ) return false;
pile->SetBreak(3, CBotString());
return pj->Return(pile);
}
-void CBotReturn::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotReturn::RestoreState(CBotStack* &pj, bool bMain)
{
if ( !bMain ) return;
CBotStack* pile = pj->RestoreStack(this);
@@ -1211,7 +1211,7 @@ CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack)
inst->SetToken(pp);
// compile la liste des paramètres
- if (!IsOfType(p, ID_CLOSEPAR)) while (TRUE)
+ if (!IsOfType(p, ID_CLOSEPAR)) while (true)
{
start = p->GivStart();
pile = pile->TokenStack(); // garde les résultats sur la pile
@@ -1278,7 +1278,7 @@ CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack)
return NULL;
}
-BOOL CBotInstrCall::Execute(CBotStack* &pj)
+bool CBotInstrCall::Execute(CBotStack* &pj)
{
CBotVar* ppVars[1000];
CBotStack* pile = pj->AddStack(this);
@@ -1292,12 +1292,12 @@ BOOL CBotInstrCall::Execute(CBotStack* &pj)
// évalue les paramètres
// et place les valeurs sur la pile
// pour pouvoir être interrompu n'importe quand
- if ( p != NULL) while ( TRUE )
+ if ( p != NULL) while ( true )
{
pile = pile->AddStack(); // de la place sur la pile pour les résultats
if ( pile->GivState() == 0 )
{
- if (!p->Execute(pile)) return FALSE; // interrompu ici ?
+ if (!p->Execute(pile)) return false; // interrompu ici ?
pile->SetState(1); // marque spéciale pour reconnaîre les paramètres
}
ppVars[i++] = pile->GivVar();
@@ -1307,14 +1307,14 @@ BOOL CBotInstrCall::Execute(CBotStack* &pj)
ppVars[i] = NULL;
CBotStack* pile2 = pile->AddStack();
- if ( pile2->IfStep() ) return FALSE;
+ if ( pile2->IfStep() ) return false;
- if ( !pile2->ExecuteCall(m_nFuncIdent, GivToken(), ppVars, m_typRes)) return FALSE; // interrompu
+ if ( !pile2->ExecuteCall(m_nFuncIdent, GivToken(), ppVars, m_typRes)) return false; // interrompu
return pj->Return(pile2); // libère toute la pile
}
-void CBotInstrCall::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotInstrCall::RestoreState(CBotStack* &pj, bool bMain)
{
if ( !bMain ) return;
@@ -1329,7 +1329,7 @@ void CBotInstrCall::RestoreState(CBotStack* &pj, BOOL bMain)
// évalue les paramètres
// et place les valeurs sur la pile
// pour pouvoir être interrompu n'importe quand
- if ( p != NULL) while ( TRUE )
+ if ( p != NULL) while ( true )
{
pile = pile->RestoreStack(); // de la place sur la pile pour les résultats
if ( pile == NULL ) return;
@@ -1379,7 +1379,6 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack)
if (IsOfType(p, TokenTypVar))
{
CBotClass* pPapa = NULL;
-#if EXTENDS
if ( IsOfType( p, ID_EXTENDS ) )
{
CBotString name = p->GivString();
@@ -1391,10 +1390,9 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack)
return NULL;
}
}
-#endif
CBotClass* classe = (pOld == NULL) ? new CBotClass(name, pPapa) : pOld;
classe->Purge(); // vide les anciennes définitions
- classe->m_IsDef = FALSE; // définition en cours
+ classe->m_IsDef = false; // définition en cours
if ( !IsOfType( p, ID_OPBLK) )
{
@@ -1404,7 +1402,7 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack)
while ( pStack->IsOk() && !IsOfType( p, ID_CLBLK ) )
{
- classe->CompileDefItem(p, pStack, FALSE);
+ classe->CompileDefItem(p, pStack, false);
}
if (pStack->IsOk()) return classe;
@@ -1413,24 +1411,24 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack)
return NULL;
}
-BOOL CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, BOOL bSecond)
+bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
{
- BOOL bStatic = FALSE;
+ bool bStatic = false;
int mProtect = PR_PUBLIC;
- BOOL bSynchro = FALSE;
+ bool bSynchro = false;
while (IsOfType(p, ID_SEP)) ;
CBotTypResult type( -1 );
- if ( IsOfType(p, ID_SYNCHO) ) bSynchro = TRUE;
+ if ( IsOfType(p, ID_SYNCHO) ) bSynchro = true;
CBotToken* pBase = p;
- if ( IsOfType(p, ID_STATIC) ) bStatic = TRUE;
+ if ( IsOfType(p, ID_STATIC) ) bStatic = true;
if ( IsOfType(p, ID_PUBLIC) ) mProtect = PR_PUBLIC;
if ( IsOfType(p, ID_PRIVATE) ) mProtect = PR_PRIVATE;
if ( IsOfType(p, ID_PROTECTED) ) mProtect = PR_PROTECT;
- if ( IsOfType(p, ID_STATIC) ) bStatic = TRUE;
+ if ( IsOfType(p, ID_STATIC) ) bStatic = true;
// CBotClass* pClass = NULL;
type = TypeParam(p, pStack); // type du résultat
@@ -1438,7 +1436,7 @@ BOOL CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, BOOL bSecond)
if ( type.Eq(-1) )
{
pStack->SetError(TX_NOTYP, p);
- return FALSE;
+ return false;
}
while (pStack->IsOk())
@@ -1463,14 +1461,14 @@ BOOL CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, BOOL bSecond)
if (!pStack->IsOk() || !IsOfType( p, ID_CLBRK ) )
{
pStack->SetError(TX_CLBRK, p->GivStart());
- return FALSE;
+ return false;
}
/* CBotVar* pv = pStack->GivVar();
if ( pv->GivType()>= CBotTypBoolean )
{
pStack->SetError(TX_BADTYPE, p->GivStart());
- return FALSE;
+ return false;
}*/
if (limites == NULL) limites = i;
@@ -1485,7 +1483,7 @@ BOOL CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, BOOL bSecond)
CBotFunction* f =
CBotFunction::Compile1(p, pStack, this);
- if ( f == NULL ) return FALSE;
+ if ( f == NULL ) return false;
if (m_pMethod == NULL) m_pMethod = f;
else m_pMethod->AddNext(f);
@@ -1502,8 +1500,8 @@ BOOL CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, BOOL bSecond)
pf = pf->Next();
}
- BOOL bConstructor = (pp->GivString() == GivName());
- CBotCStack* pile = pStack->TokenStack(NULL, TRUE);
+ bool bConstructor = (pp->GivString() == GivName());
+ CBotCStack* pile = pStack->TokenStack(NULL, true);
// rend "this" connu
CBotToken TokenThis(CBotString("this"), CBotString());
@@ -1540,7 +1538,7 @@ BOOL CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, BOOL bSecond)
// compile une méthode
p = pBase;
CBotFunction* f =
- CBotFunction::Compile(p, pile, NULL/*, FALSE*/);
+ CBotFunction::Compile(p, pile, NULL/*, false*/);
if ( f != NULL )
{
@@ -1563,7 +1561,7 @@ BOOL CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, BOOL bSecond)
if (type.Eq(0))
{
pStack->SetError(TX_ENDOF, p);
- return FALSE;
+ return false;
}
CBotInstr* i = NULL;
@@ -1578,7 +1576,7 @@ BOOL CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, BOOL bSecond)
// il y a une assignation à calculer
i = CBotTwoOpExpr::Compile(p, pStack);
}
- if ( !pStack->IsOk() ) return FALSE;
+ if ( !pStack->IsOk() ) return false;
}
@@ -1627,20 +1625,18 @@ CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack)
// la classe à été créée par Compile1
CBotClass* pOld = CBotClass::Find(name);
-#if EXTENDS
if ( IsOfType( p, ID_EXTENDS ) )
{
IsOfType(p, TokenTypVar); // forcément
}
-#endif
IsOfType( p, ID_OPBLK); // forcément
while ( pStack->IsOk() && !IsOfType( p, ID_CLBLK ) )
{
- pOld->CompileDefItem(p, pStack, TRUE);
+ pOld->CompileDefItem(p, pStack, true);
}
- pOld->m_IsDef = TRUE; // définition terminée
+ pOld->m_IsDef = true; // définition terminée
if (pStack->IsOk()) return pOld;
}
pStack->SetError(TX_ENDOF, p);
diff --git a/src/CBot/CBotIf.cpp b/src/CBot/CBotIf.cpp
index 626ef0d..178992e 100644
--- a/src/CBot/CBotIf.cpp
+++ b/src/CBot/CBotIf.cpp
@@ -51,7 +51,7 @@ CBotInstr* CBotIf::Compile(CBotToken* &p, CBotCStack* pStack)
{
// la condition existe bel et bien
- inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, TRUE );
+ inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true );
if ( pStk->IsOk() )
{
// le bloc d'instruction est ok (peut être vide)
@@ -60,7 +60,7 @@ CBotInstr* CBotIf::Compile(CBotToken* &p, CBotCStack* pStack)
if (IsOfType(p, ID_ELSE))
{
// si oui, compile le bloc d'instruction qui suit
- inst->m_BlockElse = CBotBlock::CompileBlkOrInst( p, pStk, TRUE );
+ inst->m_BlockElse = CBotBlock::CompileBlkOrInst( p, pStk, true );
if (!pStk->IsOk())
{
// il n'y a pas de bloc correct après le else
@@ -84,19 +84,19 @@ CBotInstr* CBotIf::Compile(CBotToken* &p, CBotCStack* pStack)
// exécution de l'instruction
-BOOL CBotIf :: Execute(CBotStack* &pj)
+bool CBotIf :: Execute(CBotStack* &pj)
{
CBotStack* pile = pj->AddStack(this); // ajoute un élément à la pile
// ou le retrouve en cas de reprise
-// if ( pile == EOX ) return TRUE;
+// if ( pile == EOX ) return true;
- if ( pile->IfStep() ) return FALSE;
+ if ( pile->IfStep() ) return false;
// selon la reprise, on peut être dans l'un des 2 états
if( pile->GivState() == 0 )
{
// évalue la condition
- if ( !m_Condition->Execute(pile) ) return FALSE; // interrompu ici ?
+ if ( !m_Condition->Execute(pile) ) return false; // interrompu ici ?
// termine s'il y a une erreur
if ( !pile->IsOk() )
@@ -105,21 +105,21 @@ BOOL CBotIf :: Execute(CBotStack* &pj)
}
// passe dans le second état
- if (!pile->SetState(1)) return FALSE; // prêt pour la suite
+ if (!pile->SetState(1)) return false; // prêt pour la suite
}
// second état, évalue les instructions associées
// le résultat de la condition est sur la pile
- if ( pile->GivVal() == TRUE ) // condition était vraie ?
+ if ( pile->GivVal() == true ) // condition était vraie ?
{
if ( m_Block != NULL && // bloc peut être absent
- !m_Block->Execute(pile) ) return FALSE; // interrompu ici ?
+ !m_Block->Execute(pile) ) return false; // interrompu ici ?
}
else
{
if ( m_BlockElse != NULL && // s'il existe un bloc alternatif
- !m_BlockElse->Execute(pile) ) return FALSE; // interrompu ici
+ !m_BlockElse->Execute(pile) ) return false; // interrompu ici
}
// transmet le résultat et libère la pile
@@ -127,7 +127,7 @@ BOOL CBotIf :: Execute(CBotStack* &pj)
}
-void CBotIf :: RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotIf :: RestoreState(CBotStack* &pj, bool bMain)
{
if ( !bMain ) return;
@@ -145,7 +145,7 @@ void CBotIf :: RestoreState(CBotStack* &pj, BOOL bMain)
// second état, évalue les instructions associées
// le résultat de la condition est sur la pile
- if ( pile->GivVal() == TRUE ) // condition était vraie ?
+ if ( pile->GivVal() == true ) // condition était vraie ?
{
if ( m_Block != NULL ) // bloc peut être absent
m_Block->RestoreState(pile, bMain); // interrompu ici !
diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp
index f157c4c..bbdc350 100644
--- a/src/CBot/CBotProgram.cpp
+++ b/src/CBot/CBotProgram.cpp
@@ -62,7 +62,7 @@ CBotProgram::~CBotProgram()
}
-BOOL CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions, void* pUser )
+bool CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions, void* pUser )
{
int error = 0;
Stop();
@@ -81,7 +81,7 @@ BOOL CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions,
// transforme le programme en Tokens
CBotToken* pBaseToken = CBotToken::CompileTokens(program, error);
- if ( pBaseToken == NULL ) return FALSE;
+ if ( pBaseToken == NULL ) return false;
CBotCStack* pStack = new CBotCStack(NULL);
@@ -115,7 +115,7 @@ BOOL CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions,
delete m_Prog;
m_Prog = NULL;
delete pBaseToken;
- return FALSE;
+ return false;
}
// CBotFunction* temp = NULL;
@@ -130,12 +130,12 @@ BOOL CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions,
if ( p->GivType() == ID_CLASS ||
( p->GivType() == ID_PUBLIC && p->GivNext()->GivType() == ID_CLASS ))
{
- m_bCompileClass = TRUE;
+ m_bCompileClass = true;
CBotClass::Compile(p, pStack); // complète la définition de la classe
}
else
{
- m_bCompileClass = FALSE;
+ m_bCompileClass = false;
CBotFunction::Compile(p, pStack, next);
if (next->IsExtern()) ListFonctions.Add(next->GivName()/* + next->GivParams()*/);
next->m_pProg = this; // garde le pointeur au module
@@ -160,7 +160,7 @@ BOOL CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions,
}
-BOOL CBotProgram::Start(const char* name)
+bool CBotProgram::Start(const char* name)
{
#if STACKMEM
m_pStack->Delete();
@@ -179,7 +179,7 @@ BOOL CBotProgram::Start(const char* name)
if ( m_pRun == NULL )
{
m_ErrorCode = TX_NORUN;
- return FALSE;
+ return false;
}
#if STACKMEM
@@ -190,10 +190,10 @@ BOOL CBotProgram::Start(const char* name)
m_pStack->SetBotCall(this); // bases pour les routines
- return TRUE; // on est prêt pour un Run()
+ return true; // on est prêt pour un Run()
}
-BOOL CBotProgram::GetPosition(const char* name, int& start, int& stop, CBotGet modestart, CBotGet modestop)
+bool CBotProgram::GetPosition(const char* name, int& start, int& stop, CBotGet modestart, CBotGet modestop)
{
CBotFunction* p = m_Prog;
while (p != NULL)
@@ -202,15 +202,15 @@ BOOL CBotProgram::GetPosition(const char* name, int& start, int& stop, CBotGet m
p = p->m_next;
}
- if ( p == NULL ) return FALSE;
+ if ( p == NULL ) return false;
p->GetPosition(start, stop, modestart, modestop);
- return TRUE;
+ return true;
}
-BOOL CBotProgram::Run(void* pUser, int timer)
+bool CBotProgram::Run(void* pUser, int timer)
{
- BOOL ok;
+ bool ok;
if (m_pStack == NULL || m_pRun == NULL) goto error;
@@ -253,7 +253,7 @@ BOOL CBotProgram::Run(void* pUser, int timer)
delete m_pStack;
#endif
m_pStack = NULL;
- return TRUE; // exécution terminée !!
+ return true; // exécution terminée !!
}
if ( ok ) m_pRun = NULL; // plus de fonction en exécution
@@ -261,7 +261,7 @@ BOOL CBotProgram::Run(void* pUser, int timer)
error:
m_ErrorCode = TX_NORUN;
- return TRUE;
+ return true;
}
void CBotProgram::Stop()
@@ -277,14 +277,14 @@ void CBotProgram::Stop()
-BOOL CBotProgram::GetRunPos(const char* &FunctionName, int &start, int &end)
+bool CBotProgram::GetRunPos(const char* &FunctionName, int &start, int &end)
{
FunctionName = NULL;
start = end = 0;
- if (m_pStack == NULL) return FALSE;
+ if (m_pStack == NULL) return false;
m_pStack->GetRunPos(FunctionName, start, end);
- return TRUE;
+ return true;
}
CBotVar* CBotProgram::GivStackVars(const char* &FunctionName, int level)
@@ -321,7 +321,7 @@ long CBotProgram::GivIdent()
return m_Ident;
}
-BOOL CBotProgram::GetError(int& code, int& start, int& end)
+bool CBotProgram::GetError(int& code, int& start, int& end)
{
code = m_ErrorCode;
start = m_ErrorStart;
@@ -329,7 +329,7 @@ BOOL CBotProgram::GetError(int& code, int& start, int& end)
return code > 0;
}
-BOOL CBotProgram::GetError(int& code, int& start, int& end, CBotProgram* &pProg)
+bool CBotProgram::GetError(int& code, int& start, int& end, CBotProgram* &pProg)
{
code = m_ErrorCode;
start = m_ErrorStart;
@@ -358,8 +358,8 @@ CBotFunction* CBotProgram::GivFunctions()
return m_Prog;
}
-BOOL CBotProgram::AddFunction(const char* name,
- BOOL rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
+bool CBotProgram::AddFunction(const char* name,
+ bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
CBotTypResult rCompile (CBotVar* &pVar, void* pUser))
{
// mémorise les pointeurs aux deux fonctions
@@ -367,25 +367,25 @@ BOOL CBotProgram::AddFunction(const char* name,
}
-BOOL WriteWord(FILE* pf, WORD w)
+bool WriteWord(FILE* pf, unsigned short w)
{
size_t lg;
- lg = fwrite(&w, sizeof( WORD ), 1, pf );
+ lg = fwrite(&w, sizeof( unsigned short ), 1, pf );
return (lg == 1);
}
-BOOL ReadWord(FILE* pf, WORD& w)
+bool ReadWord(FILE* pf, unsigned short& w)
{
size_t lg;
- lg = fread(&w, sizeof( WORD ), 1, pf );
+ lg = fread(&w, sizeof( unsigned short ), 1, pf );
return (lg == 1);
}
-BOOL WriteFloat(FILE* pf, float w)
+bool WriteFloat(FILE* pf, float w)
{
size_t lg;
@@ -394,7 +394,7 @@ BOOL WriteFloat(FILE* pf, float w)
return (lg == 1);
}
-BOOL ReadFloat(FILE* pf, float& w)
+bool ReadFloat(FILE* pf, float& w)
{
size_t lg;
@@ -403,7 +403,7 @@ BOOL ReadFloat(FILE* pf, float& w)
return (lg == 1);
}
-BOOL WriteLong(FILE* pf, long w)
+bool WriteLong(FILE* pf, long w)
{
size_t lg;
@@ -412,7 +412,7 @@ BOOL WriteLong(FILE* pf, long w)
return (lg == 1);
}
-BOOL ReadLong(FILE* pf, long& w)
+bool ReadLong(FILE* pf, long& w)
{
size_t lg;
@@ -421,24 +421,24 @@ BOOL ReadLong(FILE* pf, long& w)
return (lg == 1);
}
-BOOL WriteString(FILE* pf, CBotString s)
+bool WriteString(FILE* pf, CBotString s)
{
size_t lg1, lg2;
lg1 = s.GivLength();
- if (!WriteWord(pf, lg1)) return FALSE;
+ if (!WriteWord(pf, lg1)) return false;
lg2 = fwrite(s, 1, lg1, pf );
return (lg1 == lg2);
}
-BOOL ReadString(FILE* pf, CBotString& s)
+bool ReadString(FILE* pf, CBotString& s)
{
- WORD w;
+ unsigned short w;
char buf[1000];
size_t lg1, lg2;
- if (!ReadWord(pf, w)) return FALSE;
+ if (!ReadWord(pf, w)) return false;
lg1 = w;
lg2 = fread(buf, 1, lg1, pf );
buf[lg2] = 0;
@@ -447,29 +447,29 @@ BOOL ReadString(FILE* pf, CBotString& s)
return (lg1 == lg2);
}
-BOOL WriteType(FILE* pf, CBotTypResult type)
+bool WriteType(FILE* pf, CBotTypResult type)
{
int typ = type.GivType();
if ( typ == CBotTypIntrinsic ) typ = CBotTypClass;
- if ( !WriteWord(pf, typ) ) return FALSE;
+ if ( !WriteWord(pf, typ) ) return false;
if ( typ == CBotTypClass )
{
CBotClass* p = type.GivClass();
- if ( !WriteString(pf, p->GivName()) ) return FALSE;
+ if ( !WriteString(pf, p->GivName()) ) return false;
}
if ( type.Eq( CBotTypArrayBody ) ||
type.Eq( CBotTypArrayPointer ) )
{
- if ( !WriteWord(pf, type.GivLimite()) ) return FALSE;
- if ( !WriteType(pf, type.GivTypElem()) ) return FALSE;
+ if ( !WriteWord(pf, type.GivLimite()) ) return false;
+ if ( !WriteType(pf, type.GivTypElem()) ) return false;
}
- return TRUE;
+ return true;
}
-BOOL ReadType(FILE* pf, CBotTypResult& type)
+bool ReadType(FILE* pf, CBotTypResult& type)
{
- WORD w, ww;
- if ( !ReadWord(pf, w) ) return FALSE;
+ unsigned short w, ww;
+ if ( !ReadWord(pf, w) ) return false;
type.SetType(w);
if ( type.Eq( CBotTypIntrinsic ) )
@@ -480,7 +480,7 @@ BOOL ReadType(FILE* pf, CBotTypResult& type)
if ( type.Eq( CBotTypClass ) )
{
CBotString s;
- if ( !ReadString(pf, s) ) return FALSE;
+ if ( !ReadString(pf, s) ) return false;
type = CBotTypResult( w, s );
}
@@ -488,54 +488,54 @@ BOOL ReadType(FILE* pf, CBotTypResult& type)
type.Eq( CBotTypArrayBody ) )
{
CBotTypResult r;
- if ( !ReadWord(pf, ww) ) return FALSE;
- if ( !ReadType(pf, r) ) return FALSE;
+ if ( !ReadWord(pf, ww) ) return false;
+ if ( !ReadType(pf, r) ) return false;
type = CBotTypResult( w, r );
type.SetLimite((short)ww);
}
- return TRUE;
+ return true;
}
-BOOL CBotProgram::DefineNum(const char* name, long val)
+bool CBotProgram::DefineNum(const char* name, long val)
{
return CBotToken::DefineNum(name, val);
}
-BOOL CBotProgram::SaveState(FILE* pf)
+bool CBotProgram::SaveState(FILE* pf)
{
- if (!WriteWord( pf, CBOTVERSION)) return FALSE;
+ if (!WriteWord( pf, CBOTVERSION)) return false;
if ( m_pStack != NULL )
{
- if (!WriteWord( pf, 1)) return FALSE;
- if (!WriteString( pf, m_pRun->GivName() )) return FALSE;
- if (!m_pStack->SaveState(pf)) return FALSE;
+ if (!WriteWord( pf, 1)) return false;
+ if (!WriteString( pf, m_pRun->GivName() )) return false;
+ if (!m_pStack->SaveState(pf)) return false;
}
else
{
- if (!WriteWord( pf, 0)) return FALSE;
+ if (!WriteWord( pf, 0)) return false;
}
- return TRUE;
+ return true;
}
-BOOL CBotProgram::RestoreState(FILE* pf)
+bool CBotProgram::RestoreState(FILE* pf)
{
- WORD w;
- CBotString s;
+ unsigned short w;
+ CBotString s;
Stop();
- if (!ReadWord( pf, w )) return FALSE;
- if ( w != CBOTVERSION ) return FALSE;
+ if (!ReadWord( pf, w )) return false;
+ if ( w != CBOTVERSION ) return false;
- if (!ReadWord( pf, w )) return FALSE;
- if ( w == 0 ) return TRUE;
+ if (!ReadWord( pf, w )) return false;
+ if ( w == 0 ) return true;
- if (!ReadString( pf, s )) return FALSE;
+ if (!ReadString( pf, s )) return false;
Start(s); // point de reprise
#if STACKMEM
@@ -547,12 +547,12 @@ BOOL CBotProgram::RestoreState(FILE* pf)
// récupère la pile depuis l'enregistrement
// utilise un pointeur NULL (m_pStack) mais c'est ok comme ça
- if (!m_pStack->RestoreState(pf, m_pStack)) return FALSE;
+ if (!m_pStack->RestoreState(pf, m_pStack)) return false;
m_pStack->SetBotCall(this); // bases pour les routines
// rétabli certains états dans la pile selon la structure
m_pRun->RestoreState(NULL, m_pStack, m_pInstance);
- return TRUE;
+ return true;
}
int CBotProgram::GivVersion()
@@ -566,7 +566,7 @@ int CBotProgram::GivVersion()
CBotCall* CBotCall::m_ListCalls = NULL;
CBotCall::CBotCall(const char* name,
- BOOL rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
+ bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
CBotTypResult rCompile (CBotVar* &pVar, void* pUser))
{
m_name = name;
@@ -587,8 +587,8 @@ void CBotCall::Free()
delete CBotCall::m_ListCalls;
}
-BOOL CBotCall::AddFunction(const char* name,
- BOOL rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
+bool CBotCall::AddFunction(const char* name,
+ bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
CBotTypResult rCompile (CBotVar* &pVar, void* pUser))
{
CBotCall* p = m_ListCalls;
@@ -616,18 +616,18 @@ BOOL CBotCall::AddFunction(const char* name,
if (p) p->m_next = pp;
else m_ListCalls = pp;
- return TRUE;
+ return true;
}
// transforme le tableau de pointeurs aux variables
// en une liste de variables chaînées
-CBotVar* MakeListVars(CBotVar** ppVars, BOOL bSetVal=FALSE)
+CBotVar* MakeListVars(CBotVar** ppVars, bool bSetVal=false)
{
int i = 0;
CBotVar* pVar = NULL;
- while( TRUE )
+ while( true )
{
ppVars[i];
if ( ppVars[i] == NULL ) break;
@@ -686,16 +686,16 @@ void CBotCall::SetPUser(void* pUser)
m_pUser = pUser;
}
-int CBotCall::CheckCall(const char* name)
+bool CBotCall::CheckCall(const char* name)
{
CBotCall* p = m_ListCalls;
while ( p != NULL )
{
- if ( name == p->GivName() ) return TRUE;
+ if ( name == p->GivName() ) return true;
p = p->m_next;
}
- return FALSE;
+ return false;
}
@@ -746,7 +746,7 @@ fund:
#if !STACKRUN
// fait la liste des paramètres selon le contenu de la pile (pStackVar)
- CBotVar* pVar = MakeListVars(ppVar, TRUE);
+ CBotVar* pVar = MakeListVars(ppVar, true);
CBotVar* pVarToDelete = pVar;
// crée une variable pour le résultat
@@ -759,14 +759,14 @@ fund:
if ( pResult != pRes ) delete pRes; // si résultat différent rendu
delete pVarToDelete;
- if (res == FALSE)
+ if (res == false)
{
if (Exception!=0)
{
pStack->SetError(Exception, token);
}
delete pResult;
- return FALSE;
+ return false;
}
pStack->SetVar(pResult);
@@ -775,16 +775,16 @@ fund:
pStack->SetError(TX_NORETVAL, token);
}
nIdent = pt->m_nFuncIdent;
- return TRUE;
+ return true;
#else
CBotStack* pile = pStack->AddStackEOX(pt);
- if ( pile == EOX ) return TRUE;
+ if ( pile == EOX ) return true;
// fait la liste des paramètres selon le contenu de la pile (pStackVar)
- CBotVar* pVar = MakeListVars(ppVar, TRUE);
+ CBotVar* pVar = MakeListVars(ppVar, true);
CBotVar* pVarToDelete = pVar;
// crée une variable pour le résultat
@@ -804,7 +804,7 @@ fund:
#if STACKRUN
-BOOL CBotCall::RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotStack* pStack)
+bool CBotCall::RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotStack* pStack)
{
CBotCall* pt = m_ListCalls;
@@ -817,22 +817,22 @@ BOOL CBotCall::RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBot
nIdent = pt->m_nFuncIdent;
CBotStack* pile = pStack->RestoreStackEOX(pt);
- if ( pile == NULL ) return TRUE;
+ if ( pile == NULL ) return true;
CBotStack* pile2 = pile->RestoreStack();
- return TRUE;
+ return true;
}
pt = pt->m_next;
}
}
- return FALSE;
+ return false;
}
-BOOL CBotCall::Run(CBotStack* pStack)
+bool CBotCall::Run(CBotStack* pStack)
{
CBotStack* pile = pStack->AddStackEOX(this);
- if ( pile == EOX ) return TRUE;
+ if ( pile == EOX ) return true;
CBotVar* pVar = pile->GivVar();
CBotStack* pile2 = pile->AddStack();
@@ -842,20 +842,20 @@ BOOL CBotCall::Run(CBotStack* pStack)
int Exception = 0;
int res = m_rExec(pVar, pResult, Exception, pStack->GivPUser());
- if (res == FALSE)
+ if (res == false)
{
if (Exception!=0)
{
pStack->SetError(Exception);
}
if ( pResult != pRes ) delete pResult; // si résultat différent rendu
- return FALSE;
+ return false;
}
if ( pResult != NULL ) pStack->SetCopyVar( pResult );
if ( pResult != pRes ) delete pResult; // si résultat différent rendu
- return TRUE;
+ return true;
}
#endif
@@ -863,7 +863,7 @@ BOOL CBotCall::Run(CBotStack* pStack)
///////////////////////////////////////////////////////////////////////////////////////
CBotCallMethode::CBotCallMethode(const char* name,
- BOOL rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception),
+ bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception),
CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar))
{
m_name = name;
@@ -893,7 +893,7 @@ CBotTypResult CBotCallMethode::CompileCall(const char* name, CBotVar* pThis,
{
if ( pt->m_name == name )
{
- CBotVar* pVar = MakeListVars(ppVar, TRUE);
+ CBotVar* pVar = MakeListVars(ppVar, true);
CBotVar* pVar2 = pVar;
CBotTypResult r = pt->m_rComp(pThis, pVar2);
int ret = r.GivType();
@@ -942,7 +942,7 @@ int CBotCallMethode::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBot
{
// fait la liste des paramètres selon le contenu de la pile (pStackVar)
- CBotVar* pVar = MakeListVars(ppVars, TRUE);
+ CBotVar* pVar = MakeListVars(ppVars, true);
CBotVar* pVarToDelete = pVar;
// puis appelle la routine externe au module
@@ -951,7 +951,7 @@ int CBotCallMethode::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBot
int res = pt->m_rExec(pThis, pVar, pResult, Exception);
pStack->SetVar(pResult);
- if (res == FALSE)
+ if (res == false)
{
if (Exception!=0)
{
@@ -959,10 +959,10 @@ int CBotCallMethode::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBot
pStack->SetError(Exception, pToken);
}
delete pVarToDelete;
- return FALSE;
+ return false;
}
delete pVarToDelete;
- return TRUE;
+ return true;
}
pt = pt->m_next;
}
@@ -975,14 +975,14 @@ int CBotCallMethode::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBot
{
// fait la liste des paramètres selon le contenu de la pile (pStackVar)
- CBotVar* pVar = MakeListVars(ppVars, TRUE);
+ CBotVar* pVar = MakeListVars(ppVars, true);
CBotVar* pVarToDelete = pVar;
int Exception = 0;
int res = pt->m_rExec(pThis, pVar, pResult, Exception);
pStack->SetVar(pResult);
- if (res == FALSE)
+ if (res == false)
{
if (Exception!=0)
{
@@ -990,11 +990,11 @@ int CBotCallMethode::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBot
pStack->SetError(Exception, pToken);
}
delete pVarToDelete;
- return FALSE;
+ return false;
}
delete pVarToDelete;
nIdent = pt->m_nFuncIdent;
- return TRUE;
+ return true;
}
pt = pt->m_next;
}
@@ -1002,7 +1002,7 @@ int CBotCallMethode::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBot
return -1;
}
-BOOL rSizeOf( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
+bool rSizeOf( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
if ( pVar == NULL ) return TX_LOWPARAM;
@@ -1016,7 +1016,7 @@ BOOL rSizeOf( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
}
pResult->SetValInt(i);
- return TRUE;
+ return true;
}
CBotTypResult cSizeOf( CBotVar* &pVar, void* pUser )
@@ -1030,11 +1030,11 @@ CBotTypResult cSizeOf( CBotVar* &pVar, void* pUser )
CBotString CBotProgram::m_DebugVarStr = "";
-BOOL rCBotDebug( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
+bool rCBotDebug( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
pResult->SetValString( CBotProgram::m_DebugVarStr );
- return TRUE;
+ return true;
}
CBotTypResult cCBotDebug( CBotVar* &pVar, void* pUser )
@@ -1103,7 +1103,8 @@ void CBotProgram::Init()
// une fonction juste pour les debug divers
CBotProgram::AddFunction("CBOTDEBUGDD", rCBotDebug, cCBotDebug);
- DeleteFile("CbotDebug.txt");
+ //TODO implement this deletion
+ // DeleteFile("CbotDebug.txt");
}
diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp
index b5aaba0..419798f 100644
--- a/src/CBot/CBotStack.cpp
+++ b/src/CBot/CBotStack.cpp
@@ -13,222 +13,226 @@
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.//////////////////////////////////////////////////////////////////////
-// gestion de la pile (stack)
+
+//Management of the stack
+
#include "CBot.h"
+#include <cstdlib>
+#include <cstring>
-#define ITIMER 100
+#define ITIMER 100
////////////////////////////////////////////////////////////////////////////
// gestion de la pile d'exécution
////////////////////////////////////////////////////////////////////////////
-int CBotStack::m_initimer = ITIMER; // init la variable statique
-int CBotStack::m_timer = 0; // init la variable statique
-CBotVar* CBotStack::m_retvar = NULL; // init la variable statique
-int CBotStack::m_error = 0; // init la variable statique
-int CBotStack::m_start = 0; // init la variable statique
-int CBotStack::m_end = 0; // init la variable statique
-CBotString CBotStack::m_labelBreak=""; // init la variable statique
-void* CBotStack::m_pUser = NULL;
+int CBotStack::m_initimer = ITIMER;
+int CBotStack::m_timer = 0;
+CBotVar* CBotStack::m_retvar = NULL;
+int CBotStack::m_error = 0;
+int CBotStack::m_start = 0;
+int CBotStack::m_end = 0;
+CBotString CBotStack::m_labelBreak="";
+void* CBotStack::m_pUser = NULL;
-#if STACKMEM
+#if STACKMEM
CBotStack* CBotStack::FirstStack()
{
- CBotStack* p;
-
- long size = sizeof(CBotStack);
- size *= (MAXSTACK+10);
-
- // demande une tranche mémoire pour la pile
- p = (CBotStack*)malloc(size);
-
- // la vide totalement
- memset(p, 0, size);
-
- p-> m_bBlock = TRUE;
- m_timer = m_initimer; // met le timer au début
-
- CBotStack* pp = p;
- pp += MAXSTACK;
- int i;
- for ( i = 0 ; i< 10 ; i++ )
- {
- pp->m_bOver = TRUE;
- pp ++;
- }
-#ifdef _DEBUG
- int n = 1;
- pp = p;
- for ( i = 0 ; i< MAXSTACK+10 ; i++ )
- {
- pp->m_index = n++;
- pp ++;
- }
+ CBotStack* p;
+
+ long size = sizeof(CBotStack);
+ size *= (MAXSTACK+10);
+
+ // demande une tranche mémoire pour la pile
+ p = (CBotStack*)malloc(size);
+
+ // la vide totalement
+ memset(p, 0, size);
+
+ p-> m_bBlock = true;
+ m_timer = m_initimer; // met le timer au début
+
+ CBotStack* pp = p;
+ pp += MAXSTACK;
+ int i;
+ for ( i = 0 ; i< 10 ; i++ )
+ {
+ pp->m_bOver = true;
+ pp ++;
+ }
+#ifdef _DEBUG
+ int n = 1;
+ pp = p;
+ for ( i = 0 ; i< MAXSTACK+10 ; i++ )
+ {
+ pp->m_index = n++;
+ pp ++;
+ }
#endif
- m_error = 0; // évite des blocages car m_error est static
- return p;
+ m_error = 0; // évite des blocages car m_error est static
+ return p;
}
CBotStack::CBotStack(CBotStack* ppapa)
{
- // constructeur doit exister, sinon le destructeur n'est jamais appelé !
- ASM_TRAP();
+ // constructor must exist or the destructor is never called!
+ ASM_TRAP();
}
CBotStack::~CBotStack()
{
- ASM_TRAP(); // utiliser Delete() à la place
+ ASM_TRAP(); // utiliser Delete() à la place
}
void CBotStack::Delete()
{
- if ( this == NULL || this == EOX ) return;
+ if ( this == NULL || this == EOX ) return;
- m_next->Delete();
- m_next2->Delete();
+ m_next->Delete();
+ m_next2->Delete();
- if (m_prev != NULL)
- {
- if ( m_prev->m_next == this )
- m_prev->m_next = NULL; // enlève de la chaîne
+ if (m_prev != NULL)
+ {
+ if ( m_prev->m_next == this )
+ m_prev->m_next = NULL; // enlève de la chaîne
- if ( m_prev->m_next2 == this )
- m_prev->m_next2 = NULL; // enlève de la chaîne
- }
+ if ( m_prev->m_next2 == this )
+ m_prev->m_next2 = NULL; // enlève de la chaîne
+ }
- delete m_var;
- delete m_listVar;
+ delete m_var;
+ delete m_listVar;
- CBotStack* p = m_prev;
- BOOL bOver = m_bOver;
-#ifdef _DEBUG
- int n = m_index;
+ CBotStack* p = m_prev;
+ bool bOver = m_bOver;
+#ifdef _DEBUG
+ int n = m_index;
#endif
- // efface le bloc libéré
- memset(this, 0, sizeof(CBotStack));
- m_bOver = bOver;
-#ifdef _DEBUG
- m_index = n;
+ // efface le bloc libéré
+ memset(this, 0, sizeof(CBotStack));
+ m_bOver = bOver;
+#ifdef _DEBUG
+ m_index = n;
#endif
- if ( p == NULL )
- free( this );
+ if ( p == NULL )
+ free( this );
}
// routine optimisée
-CBotStack* CBotStack::AddStack(CBotInstr* instr, BOOL bBlock)
+CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock)
{
- if (m_next != NULL)
- {
- return m_next; // reprise dans une pile existante
- }
+ if (m_next != NULL)
+ {
+ return m_next; // reprise dans une pile existante
+ }
-#ifdef _DEBUG
- int n = 0;
+#ifdef _DEBUG
+ int n = 0;
#endif
- CBotStack* p = this;
- do
- {
- p ++;
-#ifdef _DEBUG
- n ++;
+ CBotStack* p = this;
+ do
+ {
+ p ++;
+#ifdef _DEBUG
+ n ++;
#endif
- }
- while ( p->m_prev != NULL );
+ }
+ while ( p->m_prev != NULL );
- m_next = p; // chaîne l'élément
- p->m_bBlock = bBlock;
- p->m_instr = instr;
- p->m_prog = m_prog;
- p->m_step = 0;
- p->m_prev = this;
- p->m_state = 0;
- p->m_call = NULL;
- p->m_bFunc = FALSE;
- return p;
+ m_next = p; // chaîne l'élément
+ p->m_bBlock = bBlock;
+ p->m_instr = instr;
+ p->m_prog = m_prog;
+ p->m_step = 0;
+ p->m_prev = this;
+ p->m_state = 0;
+ p->m_call = NULL;
+ p->m_bFunc = false;
+ return p;
}
-CBotStack* CBotStack::AddStackEOX(CBotCall* instr, BOOL bBlock)
+CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock)
{
- if (m_next != NULL)
- {
- if ( m_next == EOX )
- {
- m_next = NULL;
- return EOX;
- }
- return m_next; // reprise dans une pile existante
- }
- CBotStack* p = AddStack(NULL, bBlock);
- p->m_call = instr;
- p->m_bFunc = 2; // spécial
- return p;
+ if (m_next != NULL)
+ {
+ if ( m_next == EOX )
+ {
+ m_next = NULL;
+ return EOX;
+ }
+ return m_next; // reprise dans une pile existante
+ }
+ CBotStack* p = AddStack(NULL, bBlock);
+ p->m_call = instr;
+ p->m_bFunc = 2; // spécial
+ return p;
}
-CBotStack* CBotStack::AddStack2(BOOL bBlock)
+CBotStack* CBotStack::AddStack2(bool bBlock)
{
- if (m_next2 != NULL)
- {
- m_next2->m_prog = m_prog; // spécial évite un RestoreStack2
- return m_next2; // reprise dans une pile existante
- }
+ if (m_next2 != NULL)
+ {
+ m_next2->m_prog = m_prog; // spécial évite un RestoreStack2
+ return m_next2; // reprise dans une pile existante
+ }
- CBotStack* p = this;
- do
- {
- p ++;
- }
- while ( p->m_prev != NULL );
+ CBotStack* p = this;
+ do
+ {
+ p ++;
+ }
+ while ( p->m_prev != NULL );
- m_next2 = p; // chaîne l'élément
- p->m_prev = this;
- p->m_bBlock = bBlock;
- p->m_prog = m_prog;
- p->m_step = 0;
- return p;
+ m_next2 = p; // chaîne l'élément
+ p->m_prev = this;
+ p->m_bBlock = bBlock;
+ p->m_prog = m_prog;
+ p->m_step = 0;
+ return p;
}
-BOOL CBotStack::GivBlock()
+bool CBotStack::GivBlock()
{
- return m_bBlock;
+ return m_bBlock;
}
-BOOL CBotStack::Return(CBotStack* pfils)
+bool CBotStack::Return(CBotStack* pfils)
{
- if ( pfils == this ) return TRUE; // spécial
+ if ( pfils == this ) return true; // spécial
- if (m_var != NULL) delete m_var; // valeur remplacée ?
- m_var = pfils->m_var; // résultat transmis
- pfils->m_var = NULL; // ne pas détruire la variable
+ if (m_var != NULL) delete m_var; // valeur remplacée ?
+ m_var = pfils->m_var; // résultat transmis
+ pfils->m_var = NULL; // ne pas détruire la variable
- m_next->Delete();m_next = NULL; // libère la pile au dessus
- m_next2->Delete();m_next2 = NULL; // aussi la seconde pile (catch)
+ m_next->Delete();m_next = NULL; // libère la pile au dessus
+ m_next2->Delete();m_next2 = NULL; // aussi la seconde pile (catch)
- return (m_error == 0); // interrompu si erreur
+ return (m_error == 0); // interrompu si erreur
}
-BOOL CBotStack::ReturnKeep(CBotStack* pfils)
+bool CBotStack::ReturnKeep(CBotStack* pfils)
{
- if ( pfils == this ) return TRUE; // spécial
+ if ( pfils == this ) return true; // spécial
- if (m_var != NULL) delete m_var; // valeur remplacée ?
- m_var = pfils->m_var; // résultat transmis
- pfils->m_var = NULL; // ne pas détruire la variable
+ if (m_var != NULL) delete m_var; // valeur remplacée ?
+ m_var = pfils->m_var; // résultat transmis
+ pfils->m_var = NULL; // ne pas détruire la variable
- return (m_error == 0); // interrompu si erreur
+ return (m_error == 0); // interrompu si erreur
}
-BOOL CBotStack::StackOver()
+bool CBotStack::StackOver()
{
- if (!m_bOver) return FALSE;
- m_error = TX_STACKOVER;
- return TRUE;
+ if (!m_bOver) return false;
+ m_error = TX_STACKOVER;
+ return true;
}
#else
@@ -239,118 +243,118 @@ CBotStack::CBotStack(CBotStack* ppapa)
m_next2 = NULL;
m_prev = ppapa;
- m_bBlock = (ppapa == NULL) ? TRUE : FALSE;
+ m_bBlock = (ppapa == NULL) ? true : false;
m_state = 0;
- m_step = 1;
+ m_step = 1;
- if (ppapa == NULL) m_timer = m_initimer; // met le timer au début
+ if (ppapa == NULL) m_timer = m_initimer; // met le timer au début
- m_listVar = NULL;
- m_bDontDelete = FALSE;
-
- m_var = NULL;
- m_prog = NULL;
- m_instr = NULL;
- m_call = NULL;
- m_bFunc = FALSE;
+ m_listVar = NULL;
+ m_bDontDelete = false;
+
+ m_var = NULL;
+ m_prog = NULL;
+ m_instr = NULL;
+ m_call = NULL;
+ m_bFunc = false;
}
// destructeur
CBotStack::~CBotStack()
{
- if ( m_next != EOX) delete m_next;
- delete m_next2;
- if (m_prev != NULL && m_prev->m_next == this )
- m_prev->m_next = NULL; // enlève de la chaîne
+ if ( m_next != EOX) delete m_next;
+ delete m_next2;
+ if (m_prev != NULL && m_prev->m_next == this )
+ m_prev->m_next = NULL; // enlève de la chaîne
- delete m_var;
- if ( !m_bDontDelete ) delete m_listVar;
+ delete m_var;
+ if ( !m_bDontDelete ) delete m_listVar;
}
// routine à optimiser
-CBotStack* CBotStack::AddStack(CBotInstr* instr, BOOL bBlock)
+CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock)
{
- if (m_next != NULL)
- {
- return m_next; // reprise dans une pile existante
- }
- CBotStack* p = new CBotStack(this);
- m_next = p; // chaîne l'élément
- p->m_bBlock = bBlock;
- p->m_instr = instr;
- p->m_prog = m_prog;
- p->m_step = 0;
- return p;
+ if (m_next != NULL)
+ {
+ return m_next; // reprise dans une pile existante
+ }
+ CBotStack* p = new CBotStack(this);
+ m_next = p; // chaîne l'élément
+ p->m_bBlock = bBlock;
+ p->m_instr = instr;
+ p->m_prog = m_prog;
+ p->m_step = 0;
+ return p;
}
-CBotStack* CBotStack::AddStackEOX(CBotCall* instr, BOOL bBlock)
+CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock)
{
- if (m_next != NULL)
- {
- if ( m_next == EOX )
- {
- m_next = NULL;
- return EOX;
- }
- return m_next; // reprise dans une pile existante
- }
- CBotStack* p = new CBotStack(this);
- m_next = p; // chaîne l'élément
- p->m_bBlock = bBlock;
- p->m_call = instr;
- p->m_prog = m_prog;
- p->m_step = 0;
- p->m_bFunc = 2; // spécial
- return p;
+ if (m_next != NULL)
+ {
+ if ( m_next == EOX )
+ {
+ m_next = NULL;
+ return EOX;
+ }
+ return m_next; // reprise dans une pile existante
+ }
+ CBotStack* p = new CBotStack(this);
+ m_next = p; // chaîne l'élément
+ p->m_bBlock = bBlock;
+ p->m_call = instr;
+ p->m_prog = m_prog;
+ p->m_step = 0;
+ p->m_bFunc = 2; // spécial
+ return p;
}
-CBotStack* CBotStack::AddStack2(BOOL bBlock)
+CBotStack* CBotStack::AddStack2(bool bBlock)
{
- if (m_next2 != NULL)
- {
- m_next2->m_prog = m_prog; // spécial évite un RestoreStack2
- return m_next2; // reprise dans une pile existante
- }
+ if (m_next2 != NULL)
+ {
+ m_next2->m_prog = m_prog; // spécial évite un RestoreStack2
+ return m_next2; // reprise dans une pile existante
+ }
- CBotStack* p = new CBotStack(this);
- m_next2 = p; // chaîne l'élément
- p->m_bBlock = bBlock;
- p->m_prog = m_prog;
- p->m_step = 0;
+ CBotStack* p = new CBotStack(this);
+ m_next2 = p; // chaîne l'élément
+ p->m_bBlock = bBlock;
+ p->m_prog = m_prog;
+ p->m_step = 0;
- return p;
+ return p;
}
-BOOL CBotStack::Return(CBotStack* pfils)
+bool CBotStack::Return(CBotStack* pfils)
{
- if ( pfils == this ) return TRUE; // spécial
+ if ( pfils == this ) return true; // spécial
- if (m_var != NULL) delete m_var; // valeur remplacée ?
- m_var = pfils->m_var; // résultat transmis
- pfils->m_var = NULL; // ne pas détruite la variable
+ if (m_var != NULL) delete m_var; // valeur remplacée ?
+ m_var = pfils->m_var; // résultat transmis
+ pfils->m_var = NULL; // ne pas détruite la variable
- if ( m_next != EOX ) delete m_next; // libère la pile au dessus
- delete m_next2;m_next2 = NULL; // aussi la seconde pile (catch)
+ if ( m_next != EOX ) delete m_next; // libère la pile au dessus
+ delete m_next2;m_next2 = NULL; // aussi la seconde pile (catch)
- return (m_error == 0); // interrompu si erreur
+ return (m_error == 0); // interrompu si erreur
}
-BOOL CBotStack::StackOver()
+bool CBotStack::StackOver()
{
- return FALSE; // pas de test de débordement dans cette version
+ return false; // pas de test de débordement dans cette version
}
#endif
void CBotStack::Reset(void* pUser)
{
- m_timer = m_initimer; // remet le timer
- m_error = 0;
-// m_start = 0;
-// m_end = 0;
- m_labelBreak.Empty();
- m_pUser = pUser;
+ m_timer = m_initimer; // remet le timer
+ m_error = 0;
+// m_start = 0;
+// m_end = 0;
+ m_labelBreak.Empty();
+ m_pUser = pUser;
}
@@ -358,323 +362,315 @@ void CBotStack::Reset(void* pUser)
CBotStack* CBotStack::RestoreStack(CBotInstr* instr)
{
- if (m_next != NULL)
- {
- m_next->m_instr = instr; // réinit (si reprise après restitution)
- m_next->m_prog = m_prog;
- return m_next; // reprise dans une pile existante
- }
- return NULL;
+ if (m_next != NULL)
+ {
+ m_next->m_instr = instr; // réinit (si reprise après restitution)
+ m_next->m_prog = m_prog;
+ return m_next; // reprise dans une pile existante
+ }
+ return NULL;
}
CBotStack* CBotStack::RestoreStackEOX(CBotCall* instr)
{
- CBotStack* p = RestoreStack();
- p->m_call = instr;
- return p;
+ CBotStack* p = RestoreStack();
+ p->m_call = instr;
+ return p;
}
// routine pour l'exécution pas à pas
-BOOL CBotStack::IfStep()
+bool CBotStack::IfStep()
{
- if ( m_initimer > 0 || m_step++ > 0 ) return FALSE;
- return TRUE;
+ if ( m_initimer > 0 || m_step++ > 0 ) return false;
+ return true;
}
-BOOL CBotStack::BreakReturn(CBotStack* pfils, const char* name)
+bool CBotStack::BreakReturn(CBotStack* pfils, const char* name)
{
- if ( m_error>=0 ) return FALSE; // sortie normale
- if ( m_error==-3 ) return FALSE; // sortie normale (return en cours)
+ if ( m_error>=0 ) return false; // sortie normale
+ if ( m_error==-3 ) return false; // sortie normale (return en cours)
- if (!m_labelBreak.IsEmpty() && (name[0] == 0 || m_labelBreak != name))
- return FALSE; // c'est pas pour moi
+ if (!m_labelBreak.IsEmpty() && (name[0] == 0 || m_labelBreak != name))
+ return false; // c'est pas pour moi
- m_error = 0;
- m_labelBreak.Empty();
- return Return(pfils);
+ m_error = 0;
+ m_labelBreak.Empty();
+ return Return(pfils);
}
-BOOL CBotStack::IfContinue(int state, const char* name)
+bool CBotStack::IfContinue(int state, const char* name)
{
- if ( m_error != -2 ) return FALSE;
+ if ( m_error != -2 ) return false;
- if (!m_labelBreak.IsEmpty() && (name == NULL || m_labelBreak != name))
- return FALSE; // c'est pas pour moi
+ if (!m_labelBreak.IsEmpty() && (name == NULL || m_labelBreak != name))
+ return false; // c'est pas pour moi
- m_state = state; // où reprendre ?
- m_error = 0;
- m_labelBreak.Empty();
- if ( m_next != EOX ) m_next->Delete(); // purge la pile au dessus
- return TRUE;
+ m_state = state; // où reprendre ?
+ m_error = 0;
+ m_labelBreak.Empty();
+ if ( m_next != EOX ) m_next->Delete(); // purge la pile au dessus
+ return true;
}
void CBotStack::SetBreak(int val, const char* name)
{
- m_error = -val; // réagit comme une Exception
- m_labelBreak = name;
- if (val == 3) // pour un return
- {
- m_retvar = m_var;
- m_var = NULL;
- }
+ m_error = -val; // réagit comme une Exception
+ m_labelBreak = name;
+ if (val == 3) // pour un return
+ {
+ m_retvar = m_var;
+ m_var = NULL;
+ }
}
// remet sur la pile la valeur calculée par le dernier CBotReturn
-BOOL CBotStack::GivRetVar(BOOL bRet)
+bool CBotStack::GivRetVar(bool bRet)
{
- if (m_error == -3)
- {
- if ( m_var ) delete m_var;
- m_var = m_retvar;
- m_retvar = NULL;
- m_error = 0;
- return TRUE;
- }
- return bRet; // interrompu par autre chose que return
+ if (m_error == -3)
+ {
+ if ( m_var ) delete m_var;
+ m_var = m_retvar;
+ m_retvar = NULL;
+ m_error = 0;
+ return true;
+ }
+ return bRet; // interrompu par autre chose que return
}
int CBotStack::GivError(int& start, int& end)
{
- start = m_start;
- end = m_end;
- return m_error;
+ start = m_start;
+ end = m_end;
+ return m_error;
}
-// type d'instruction sur la pile
int CBotStack::GivType(int mode)
{
- if (m_var == NULL) return -1;
- return m_var->GivType(mode);
+ if (m_var == NULL) return -1;
+ return m_var->GivType(mode);
}
-// type d'instruction sur la pile
CBotTypResult CBotStack::GivTypResult(int mode)
{
- if (m_var == NULL) return -1;
- return m_var->GivTypResult(mode);
+ if (m_var == NULL) return -1;
+ return m_var->GivTypResult(mode);
}
-// type d'instruction sur la pile
void CBotStack::SetType(CBotTypResult& type)
{
- if (m_var == NULL) return;
- m_var->SetType( type );
+ if (m_var == NULL) return;
+ m_var->SetType( type );
}
-// trouve une variable par son token
-// ce peut être une variable composée avec un point
-CBotVar* CBotStack::FindVar(CBotToken* &pToken, BOOL bUpdate, BOOL bModif)
+CBotVar* CBotStack::FindVar(CBotToken* &pToken, bool bUpdate, bool bModif)
{
- CBotStack* p = this;
- CBotString name = pToken->GivString();
+ CBotStack* p = this;
+ CBotString name = pToken->GivString();
- while (p != NULL)
- {
- CBotVar* pp = p->m_listVar;
- while ( pp != NULL)
- {
- if (pp->GivName() == name)
- {
- if ( bUpdate )
- pp->Maj(m_pUser, FALSE);
+ while (p != NULL)
+ {
+ CBotVar* pp = p->m_listVar;
+ while ( pp != NULL)
+ {
+ if (pp->GivName() == name)
+ {
+ if ( bUpdate )
+ pp->Maj(m_pUser, false);
- return pp;
- }
- pp = pp->m_next;
- }
- p = p->m_prev;
- }
- return NULL;
+ return pp;
+ }
+ pp = pp->m_next;
+ }
+ p = p->m_prev;
+ }
+ return NULL;
}
CBotVar* CBotStack::FindVar(const char* name)
{
- CBotStack* p = this;
- while (p != NULL)
- {
- CBotVar* pp = p->m_listVar;
- while ( pp != NULL)
- {
- if (pp->GivName() == name)
- {
- return pp;
- }
- pp = pp->m_next;
- }
- p = p->m_prev;
- }
- return NULL;
+ CBotStack* p = this;
+ while (p != NULL)
+ {
+ CBotVar* pp = p->m_listVar;
+ while ( pp != NULL)
+ {
+ if (pp->GivName() == name)
+ {
+ return pp;
+ }
+ pp = pp->m_next;
+ }
+ p = p->m_prev;
+ }
+ return NULL;
}
-// retrouve une variable sur la pile selon son numéro d'identification
-// ce qui va plus vite que de comparer les noms.
-
-CBotVar* CBotStack::FindVar(long ident, BOOL bUpdate, BOOL bModif)
+CBotVar* CBotStack::FindVar(long ident, bool bUpdate, bool bModif)
{
- CBotStack* p = this;
- while (p != NULL)
- {
- CBotVar* pp = p->m_listVar;
- while ( pp != NULL)
- {
- if (pp->GivUniqNum() == ident)
- {
- if ( bUpdate )
- pp->Maj(m_pUser, FALSE);
+ CBotStack* p = this;
+ while (p != NULL)
+ {
+ CBotVar* pp = p->m_listVar;
+ while ( pp != NULL)
+ {
+ if (pp->GivUniqNum() == ident)
+ {
+ if ( bUpdate )
+ pp->Maj(m_pUser, false);
- return pp;
- }
- pp = pp->m_next;
- }
- p = p->m_prev;
- }
- return NULL;
+ return pp;
+ }
+ pp = pp->m_next;
+ }
+ p = p->m_prev;
+ }
+ return NULL;
}
-CBotVar* CBotStack::FindVar(CBotToken& Token, BOOL bUpdate, BOOL bModif)
+CBotVar* CBotStack::FindVar(CBotToken& Token, bool bUpdate, bool bModif)
{
- CBotToken* pt = &Token;
- return FindVar(pt, bUpdate, bModif);
+ CBotToken* pt = &Token;
+ return FindVar(pt, bUpdate, bModif);
}
-CBotVar* CBotStack::CopyVar(CBotToken& Token, BOOL bUpdate)
+CBotVar* CBotStack::CopyVar(CBotToken& Token, bool bUpdate)
{
- CBotVar* pVar = FindVar( Token, bUpdate );
+ CBotVar* pVar = FindVar( Token, bUpdate );
- if ( pVar == NULL) return NULL;
+ if ( pVar == NULL) return NULL;
- CBotVar* pCopy = CBotVar::Create(pVar);
- pCopy->Copy(pVar);
- return pCopy;
+ CBotVar* pCopy = CBotVar::Create(pVar);
+ pCopy->Copy(pVar);
+ return pCopy;
}
-BOOL CBotStack::SetState(int n, int limite)
+bool CBotStack::SetState(int n, int limite)
{
m_state = n;
- m_timer--; // décompte les opérations
- return ( m_timer > limite ); // interrompu si timer passé
+ m_timer--; // décompte les opérations
+ return ( m_timer > limite ); // interrompu si timer passé
}
-BOOL CBotStack::IncState(int limite)
+bool CBotStack::IncState(int limite)
{
- m_state++;
+ m_state++;
- m_timer--; // décompte les opérations
- return ( m_timer > limite ); // interrompu si timer passé
+ m_timer--; // décompte les opérations
+ return ( m_timer > limite ); // interrompu si timer passé
}
void CBotStack::SetError(int n, CBotToken* token)
{
- if ( n!= 0 && m_error != 0) return; // ne change pas une erreur déjà existante
- m_error = n;
- if (token != NULL)
- {
- m_start = token->GivStart();
- m_end = token->GivEnd();
- }
+ if ( n!= 0 && m_error != 0) return; // ne change pas une erreur déjà existante
+ m_error = n;
+ if (token != NULL)
+ {
+ m_start = token->GivStart();
+ m_end = token->GivEnd();
+ }
}
void CBotStack::ResetError(int n, int start, int end)
{
- m_error = n;
- m_start = start;
- m_end = end;
+ m_error = n;
+ m_start = start;
+ m_end = end;
}
void CBotStack::SetPosError(CBotToken* token)
{
- m_start = token->GivStart();
- m_end = token->GivEnd();
+ m_start = token->GivStart();
+ m_end = token->GivEnd();
}
void CBotStack::SetTimer(int n)
{
- m_initimer = n;
+ m_initimer = n;
}
-BOOL CBotStack::Execute()
+bool CBotStack::Execute()
{
- CBotCall* instr = NULL; // instruction la plus élevée
- CBotStack* pile;
+ CBotCall* instr = NULL; // instruction la plus élevée
+ CBotStack* pile;
- CBotStack* p = this;
+ CBotStack* p = this;
- while (p != NULL)
- {
- if ( p->m_next2 != NULL ) break;
- if ( p->m_call != NULL )
- {
- instr = p->m_call;
- pile = p->m_prev ;
- }
- p = p->m_next;
- }
+ while (p != NULL)
+ {
+ if ( p->m_next2 != NULL ) break;
+ if ( p->m_call != NULL )
+ {
+ instr = p->m_call;
+ pile = p->m_prev ;
+ }
+ p = p->m_next;
+ }
- if ( instr == NULL ) return TRUE; // exécution normale demandée
+ if ( instr == NULL ) return true; // exécution normale demandée
- if (!instr->Run(pile)) return FALSE; // exécution à partir de là
+ if (!instr->Run(pile)) return false; // exécution à partir de là
-#if STACKMEM
- pile->m_next->Delete();
+#if STACKMEM
+ pile->m_next->Delete();
#else
- delete pile->m_next;
+ delete pile->m_next;
#endif
- pile->m_next = EOX; // spécial pour reprise
- return TRUE;
+ pile->m_next = EOX; // spécial pour reprise
+ return true;
}
// met sur le stack le pointeur à une variable
void CBotStack::SetVar( CBotVar* var )
{
- if (m_var) delete m_var; // remplacement d'une variable
- m_var = var;
+ if (m_var) delete m_var; // remplacement d'une variable
+ m_var = var;
}
// met sur le stack une copie d'une variable
void CBotStack::SetCopyVar( CBotVar* var )
{
- if (m_var) delete m_var; // remplacement d'une variable
+ if (m_var) delete m_var; // remplacement d'une variable
- m_var = CBotVar::Create("", var->GivTypResult(2));
- m_var->Copy( var );
+ m_var = CBotVar::Create("", var->GivTypResult(2));
+ m_var->Copy( var );
}
CBotVar* CBotStack::GivVar()
{
- return m_var;
+ return m_var;
}
CBotVar* CBotStack::GivPtVar()
{
- CBotVar* p = m_var;
- m_var = NULL; // ne sera pas détruit donc
- return p;
+ CBotVar* p = m_var;
+ m_var = NULL; // ne sera pas détruit donc
+ return p;
}
CBotVar* CBotStack::GivCopyVar()
{
- if (m_var == NULL) return NULL;
- CBotVar* v = CBotVar::Create("", m_var->GivType());
- v->Copy( m_var );
- return v;
+ if (m_var == NULL) return NULL;
+ CBotVar* v = CBotVar::Create("", m_var->GivType());
+ v->Copy( m_var );
+ return v;
}
long CBotStack::GivVal()
{
- if (m_var == NULL) return 0;
- return m_var->GivValInt();
+ if (m_var == NULL) return 0;
+ return m_var->GivValInt();
}
@@ -682,431 +678,431 @@ long CBotStack::GivVal()
void CBotStack::AddVar(CBotVar* pVar)
{
- CBotStack* p = this;
+ CBotStack* p = this;
- // revient sur l'élement père
- while (p != NULL && p->m_bBlock == 0) p = p->m_prev;
+ // revient sur l'élement père
+ while (p != NULL && p->m_bBlock == 0) p = p->m_prev;
- if ( p == NULL ) return;
-
-/// p->m_bDontDelete = bDontDelete;
+ if ( p == NULL ) return;
+
+/// p->m_bDontDelete = bDontDelete;
- CBotVar** pp = &p->m_listVar;
- while ( *pp != NULL ) pp = &(*pp)->m_next;
+ CBotVar** pp = &p->m_listVar;
+ while ( *pp != NULL ) pp = &(*pp)->m_next;
- *pp = pVar; // ajoute à la suite
+ *pp = pVar; // ajoute à la suite
-#ifdef _DEBUG
- if ( pVar->GivUniqNum() == 0 ) ASM_TRAP();
+#ifdef _DEBUG
+ if ( pVar->GivUniqNum() == 0 ) ASM_TRAP();
#endif
}
/*void CBotStack::RestoreVar(CBotVar* pVar)
{
- if ( !m_bDontDelete ) __asm int 3;
- delete m_listVar;
- m_listVar = pVar; // remplace directement
+ if ( !m_bDontDelete ) __asm int 3;
+ delete m_listVar;
+ m_listVar = pVar; // remplace directement
}*/
void CBotStack::SetBotCall(CBotProgram* p)
{
- m_prog = p;
- m_bFunc = TRUE;
+ m_prog = p;
+ m_bFunc = true;
}
-CBotProgram* CBotStack::GivBotCall(BOOL bFirst)
+CBotProgram* CBotStack::GivBotCall(bool bFirst)
{
- if ( ! bFirst ) return m_prog;
- CBotStack* p = this;
- while ( p->m_prev != NULL ) p = p->m_prev;
- return p->m_prog;
+ if ( ! bFirst ) return m_prog;
+ CBotStack* p = this;
+ while ( p->m_prev != NULL ) p = p->m_prev;
+ return p->m_prog;
}
void* CBotStack::GivPUser()
{
- return m_pUser;
+ return m_pUser;
}
-BOOL CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype)
+bool CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype)
{
- CBotTypResult res;
+ CBotTypResult res;
- // cherche d'abord selon l'identificateur
+ // cherche d'abord selon l'identificateur
- res = CBotCall::DoCall(nIdent, NULL, ppVar, this, rettype );
- if (res.GivType() >= 0) return res.GivType();
+ res = CBotCall::DoCall(nIdent, NULL, ppVar, this, rettype );
+ if (res.GivType() >= 0) return res.GivType();
- res = m_prog->GivFunctions()->DoCall(nIdent, NULL, ppVar, this, token );
- if (res.GivType() >= 0) return res.GivType();
+ res = m_prog->GivFunctions()->DoCall(nIdent, NULL, ppVar, this, token );
+ if (res.GivType() >= 0) return res.GivType();
- // si pas trouvé (recompilé ?) cherche selon le nom
+ // si pas trouvé (recompilé ?) cherche selon le nom
- nIdent = 0;
- res = CBotCall::DoCall(nIdent, token, ppVar, this, rettype );
- if (res.GivType() >= 0) return res.GivType();
+ nIdent = 0;
+ res = CBotCall::DoCall(nIdent, token, ppVar, this, rettype );
+ if (res.GivType() >= 0) return res.GivType();
- res = m_prog->GivFunctions()->DoCall(nIdent, token->GivString(), ppVar, this, token );
- if (res.GivType() >= 0) return res.GivType();
+ res = m_prog->GivFunctions()->DoCall(nIdent, token->GivString(), ppVar, this, token );
+ if (res.GivType() >= 0) return res.GivType();
- SetError(TX_NOCALL, token);
- return TRUE;
+ SetError(TX_NOCALL, token);
+ return true;
}
void CBotStack::RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar)
{
- if ( m_next == NULL ) return;
+ if ( m_next == NULL ) return;
- if ( !CBotCall::RestoreCall(nIdent, token, ppVar, this) )
- m_prog->GivFunctions()->RestoreCall(nIdent, token->GivString(), ppVar, this );
+ if ( !CBotCall::RestoreCall(nIdent, token, ppVar, this) )
+ m_prog->GivFunctions()->RestoreCall(nIdent, token->GivString(), ppVar, this );
}
-BOOL SaveVar(FILE* pf, CBotVar* pVar)
+bool SaveVar(FILE* pf, CBotVar* pVar)
{
- while ( TRUE )
- {
- if ( pVar == NULL )
- {
- return WriteWord(pf, 0); // met un terminateur
- }
+ while ( true )
+ {
+ if ( pVar == NULL )
+ {
+ return WriteWord(pf, 0); // met un terminateur
+ }
- if ( !pVar->Save0State(pf)) return FALSE; // entête commune
- if ( !pVar->Save1State(pf) ) return FALSE; // sauve selon la classe fille
+ if ( !pVar->Save0State(pf)) return false; // entête commune
+ if ( !pVar->Save1State(pf) ) return false; // sauve selon la classe fille
- pVar = pVar->GivNext();
- }
+ pVar = pVar->GivNext();
+ }
}
void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end)
{
- CBotProgram* prog = m_prog; // programme courrant
+ CBotProgram* prog = m_prog; // programme courrant
- CBotInstr* funct = NULL; // fonction trouvée
- CBotInstr* instr = NULL; // instruction la plus élevée
+ CBotInstr* funct = NULL; // fonction trouvée
+ CBotInstr* instr = NULL; // instruction la plus élevée
- CBotStack* p = this;
+ CBotStack* p = this;
- while (p->m_next != NULL)
- {
- if ( p->m_instr != NULL ) instr = p->m_instr;
- if ( p->m_bFunc == 1 ) funct = p->m_instr;
- if ( p->m_next->m_prog != prog ) break ;
+ while (p->m_next != NULL)
+ {
+ if ( p->m_instr != NULL ) instr = p->m_instr;
+ if ( p->m_bFunc == 1 ) funct = p->m_instr;
+ if ( p->m_next->m_prog != prog ) break ;
- if (p->m_next2 && p->m_next2->m_state != 0) p = p->m_next2 ;
- else p = p->m_next;
- }
+ if (p->m_next2 && p->m_next2->m_state != 0) p = p->m_next2 ;
+ else p = p->m_next;
+ }
- if ( p->m_instr != NULL ) instr = p->m_instr;
- if ( p->m_bFunc == 1 ) funct = p->m_instr;
+ if ( p->m_instr != NULL ) instr = p->m_instr;
+ if ( p->m_bFunc == 1 ) funct = p->m_instr;
- if ( funct == NULL ) return;
+ if ( funct == NULL ) return;
- CBotToken* t = funct->GivToken();
- FunctionName = t->GivString();
+ CBotToken* t = funct->GivToken();
+ FunctionName = t->GivString();
-// if ( p->m_instr != NULL ) instr = p->m_instr;
+// if ( p->m_instr != NULL ) instr = p->m_instr;
- t = instr->GivToken();
- start = t->GivStart();
- end = t->GivEnd();
+ t = instr->GivToken();
+ start = t->GivStart();
+ end = t->GivEnd();
}
CBotVar* CBotStack::GivStackVars(const char* &FunctionName, int level)
{
- CBotProgram* prog = m_prog; // programme courrant
- FunctionName = NULL;
+ CBotProgram* prog = m_prog; // programme courrant
+ FunctionName = NULL;
- // remonte la pile dans le module courant
- CBotStack* p = this;
+ // remonte la pile dans le module courant
+ CBotStack* p = this;
- while (p->m_next != NULL)
- {
- if ( p->m_next->m_prog != prog ) break ;
+ while (p->m_next != NULL)
+ {
+ if ( p->m_next->m_prog != prog ) break ;
- if (p->m_next2 && p->m_next2->m_state != 0) p = p->m_next2 ;
- else p = p->m_next;
- }
+ if (p->m_next2 && p->m_next2->m_state != 0) p = p->m_next2 ;
+ else p = p->m_next;
+ }
- // descend sur les éléments de block
- while ( p != NULL && !p->m_bBlock ) p = p->m_prev;
+ // descend sur les éléments de block
+ while ( p != NULL && !p->m_bBlock ) p = p->m_prev;
- while ( p != NULL && level++ < 0 )
- {
- p = p->m_prev;
- while ( p != NULL && !p->m_bBlock ) p = p->m_prev;
- }
+ while ( p != NULL && level++ < 0 )
+ {
+ p = p->m_prev;
+ while ( p != NULL && !p->m_bBlock ) p = p->m_prev;
+ }
- if ( p == NULL ) return NULL;
+ if ( p == NULL ) return NULL;
- // recherche le nom de la fonction courante
- CBotStack* pp = p;
- while ( pp != NULL )
- {
- if ( pp->m_bFunc == 1 ) break;
- pp = pp->m_prev;
- }
+ // recherche le nom de la fonction courante
+ CBotStack* pp = p;
+ while ( pp != NULL )
+ {
+ if ( pp->m_bFunc == 1 ) break;
+ pp = pp->m_prev;
+ }
- if ( pp == NULL || pp->m_instr == NULL ) return NULL;
+ if ( pp == NULL || pp->m_instr == NULL ) return NULL;
- CBotToken* t = pp->m_instr->GivToken();
- FunctionName = t->GivString();
-
- return p->m_listVar;
+ CBotToken* t = pp->m_instr->GivToken();
+ FunctionName = t->GivString();
+
+ return p->m_listVar;
}
-BOOL CBotStack::SaveState(FILE* pf)
+bool CBotStack::SaveState(FILE* pf)
{
- if ( this == NULL ) // fin de l'arbre ?
- {
- return WriteWord(pf, 0); // met un terminateur
- }
+ if ( this == NULL ) // fin de l'arbre ?
+ {
+ return WriteWord(pf, 0); // met un terminateur
+ }
- if ( m_next2 != NULL )
- {
- if (!WriteWord(pf, 2)) return FALSE; // une marque de poursuite
- if (!m_next2->SaveState(pf)) return FALSE;
- }
- else
- {
- if (!WriteWord(pf, 1)) return FALSE; // une marque de poursuite
- }
- if (!WriteWord(pf, m_bBlock)) return FALSE; // est-ce un bloc local
- if (!WriteWord(pf, m_state)) return FALSE; // dans quel état
- if (!WriteWord(pf, 0)) return FALSE; // par compatibilité m_bDontDelete
- if (!WriteWord(pf, m_step)) return FALSE; // dans quel état
-
-
- if (!SaveVar(pf, m_var)) return FALSE; // le résultat courant
- if (!SaveVar(pf, m_listVar)) return FALSE; // les variables locales
+ if ( m_next2 != NULL )
+ {
+ if (!WriteWord(pf, 2)) return false; // une marque de poursuite
+ if (!m_next2->SaveState(pf)) return false;
+ }
+ else
+ {
+ if (!WriteWord(pf, 1)) return false; // une marque de poursuite
+ }
+ if (!WriteWord(pf, m_bBlock)) return false; // est-ce un bloc local
+ if (!WriteWord(pf, m_state)) return false; // dans quel état
+ if (!WriteWord(pf, 0)) return false; // par compatibilité m_bDontDelete
+ if (!WriteWord(pf, m_step)) return false; // dans quel état
+
+
+ if (!SaveVar(pf, m_var)) return false; // le résultat courant
+ if (!SaveVar(pf, m_listVar)) return false; // les variables locales
- return m_next->SaveState(pf); // enregistre la suite
+ return m_next->SaveState(pf); // enregistre la suite
}
-BOOL CBotStack::RestoreState(FILE* pf, CBotStack* &pStack)
+bool CBotStack::RestoreState(FILE* pf, CBotStack* &pStack)
{
- WORD w;
+ unsigned short w;
- pStack = NULL;
- if (!ReadWord(pf, w)) return FALSE;
- if ( w == 0 ) return TRUE;
+ pStack = NULL;
+ if (!ReadWord(pf, w)) return false;
+ if ( w == 0 ) return true;
-#if STACKMEM
- if ( this == NULL ) pStack = FirstStack();
- else pStack = AddStack();
+#if STACKMEM
+ if ( this == NULL ) pStack = FirstStack();
+ else pStack = AddStack();
#else
- pStack = new CBotStack(this);
+ pStack = new CBotStack(this);
#endif
- if ( w == 2 )
- {
- if (!pStack->RestoreState(pf, pStack->m_next2)) return FALSE;
- }
+ if ( w == 2 )
+ {
+ if (!pStack->RestoreState(pf, pStack->m_next2)) return false;
+ }
- if (!ReadWord(pf, w)) return FALSE; // est-ce un bloc local
- pStack->m_bBlock = w;
+ if (!ReadWord(pf, w)) return false; // est-ce un bloc local
+ pStack->m_bBlock = w;
- if (!ReadWord(pf, w)) return FALSE; // dans quel état j'ère ?
- pStack->SetState((short)w); // dans le bon état
+ if (!ReadWord(pf, w)) return false; // dans quel état j'ère ?
+ pStack->SetState((short)w); // dans le bon état
- if (!ReadWord(pf, w)) return FALSE; // dont delete ?
- // plus utilisé
+ if (!ReadWord(pf, w)) return false; // dont delete ?
+ // plus utilisé
- if (!ReadWord(pf, w)) return FALSE; // pas à pas
- pStack->m_step = w;
+ if (!ReadWord(pf, w)) return false; // pas à pas
+ pStack->m_step = w;
- if (!CBotVar::RestoreState(pf, pStack->m_var)) return FALSE; // la variable temp
- if (!CBotVar::RestoreState(pf, pStack->m_listVar)) return FALSE;// les variables locales
+ if (!CBotVar::RestoreState(pf, pStack->m_var)) return false; // la variable temp
+ if (!CBotVar::RestoreState(pf, pStack->m_listVar)) return false;// les variables locales
- return pStack->RestoreState(pf, pStack->m_next);
+ return pStack->RestoreState(pf, pStack->m_next);
}
-BOOL CBotVar::Save0State(FILE* pf)
-{
- if (!WriteWord(pf, 100+m_mPrivate))return FALSE; // variable privée ?
- if (!WriteWord(pf, m_bStatic))return FALSE; // variable static ?
- if (!WriteWord(pf, m_type.GivType()))return FALSE; // enregiste le type (toujours non nul)
- if (!WriteWord(pf, m_binit))return FALSE; // variable définie ?
- return WriteString(pf, m_token->GivString()); // et le nom de la variable
+bool CBotVar::Save0State(FILE* pf)
+{
+ if (!WriteWord(pf, 100+m_mPrivate))return false; // variable privée ?
+ if (!WriteWord(pf, m_bStatic))return false; // variable static ?
+ if (!WriteWord(pf, m_type.GivType()))return false; // enregiste le type (toujours non nul)
+ if (!WriteWord(pf, m_binit))return false; // variable définie ?
+ return WriteString(pf, m_token->GivString()); // et le nom de la variable
}
-BOOL CBotVarInt::Save0State(FILE* pf)
-{
- if ( !m_defnum.IsEmpty() )
- {
- if(!WriteWord(pf, 200 )) return FALSE; // marqueur spécial
- if(!WriteString(pf, m_defnum)) return FALSE; // nom de la valeur
- }
+bool CBotVarInt::Save0State(FILE* pf)
+{
+ if ( !m_defnum.IsEmpty() )
+ {
+ if(!WriteWord(pf, 200 )) return false; // marqueur spécial
+ if(!WriteString(pf, m_defnum)) return false; // nom de la valeur
+ }
- return CBotVar::Save0State(pf);
+ return CBotVar::Save0State(pf);
}
-BOOL CBotVarInt::Save1State(FILE* pf)
+bool CBotVarInt::Save1State(FILE* pf)
{
- return WriteWord(pf, m_val); // la valeur de la variable
+ return WriteWord(pf, m_val); // la valeur de la variable
}
-BOOL CBotVarBoolean::Save1State(FILE* pf)
+bool CBotVarBoolean::Save1State(FILE* pf)
{
- return WriteWord(pf, m_val); // la valeur de la variable
+ return WriteWord(pf, m_val); // la valeur de la variable
}
-BOOL CBotVarFloat::Save1State(FILE* pf)
+bool CBotVarFloat::Save1State(FILE* pf)
{
- return WriteFloat(pf, m_val); // la valeur de la variable
+ return WriteFloat(pf, m_val); // la valeur de la variable
}
-BOOL CBotVarString::Save1State(FILE* pf)
+bool CBotVarString::Save1State(FILE* pf)
{
- return WriteString(pf, m_val); // la valeur de la variable
+ return WriteString(pf, m_val); // la valeur de la variable
}
-BOOL CBotVarClass::Save1State(FILE* pf)
+bool CBotVarClass::Save1State(FILE* pf)
{
- if ( !WriteType(pf, m_type) ) return FALSE;
- if ( !WriteLong(pf, m_ItemIdent) ) return FALSE;
+ if ( !WriteType(pf, m_type) ) return false;
+ if ( !WriteLong(pf, m_ItemIdent) ) return false;
- return SaveVar(pf, m_pVar); // contenu de l'objet
+ return SaveVar(pf, m_pVar); // contenu de l'objet
}
-BOOL CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
+bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
{
- WORD w, wi, prv, st;
- float ww;
- CBotString name, s;
+ unsigned short w, wi, prv, st;
+ float ww;
+ CBotString name, s;
- delete pVar;
+ delete pVar;
- pVar = NULL;
- CBotVar* pNew = NULL;
- CBotVar* pPrev = NULL;
+ pVar = NULL;
+ CBotVar* pNew = NULL;
+ CBotVar* pPrev = NULL;
- while ( TRUE ) // recupère toute une liste
- {
- if (!ReadWord(pf, w)) return FALSE; // privé ou type ?
- if ( w == 0 ) return TRUE;
+ while ( true ) // recupère toute une liste
+ {
+ if (!ReadWord(pf, w)) return false; // privé ou type ?
+ if ( w == 0 ) return true;
- CBotString defnum;
- if ( w == 200 )
- {
- if (!ReadString(pf, defnum)) return FALSE; // nombre avec un identifiant
- if (!ReadWord(pf, w)) return FALSE; // type
- }
+ CBotString defnum;
+ if ( w == 200 )
+ {
+ if (!ReadString(pf, defnum)) return false; // nombre avec un identifiant
+ if (!ReadWord(pf, w)) return false; // type
+ }
- prv = 100; st = 0;
- if ( w >= 100 )
- {
- prv = w;
- if (!ReadWord(pf, st)) return FALSE; // statique
- if (!ReadWord(pf, w)) return FALSE; // type
- }
+ prv = 100; st = 0;
+ if ( w >= 100 )
+ {
+ prv = w;
+ if (!ReadWord(pf, st)) return false; // statique
+ if (!ReadWord(pf, w)) return false; // type
+ }
- if ( w == CBotTypClass ) w = CBotTypIntrinsic; // forcément intrinsèque
+ if ( w == CBotTypClass ) w = CBotTypIntrinsic; // forcément intrinsèque
- if (!ReadWord(pf, wi)) return FALSE; // init ?
+ if (!ReadWord(pf, wi)) return false; // init ?
- if (!ReadString(pf, name)) return FALSE; // nom de la variable
+ if (!ReadString(pf, name)) return false; // nom de la variable
- CBotToken token(name, CBotString());
+ CBotToken token(name, CBotString());
- switch (w)
- {
- case CBotTypInt:
- case CBotTypBoolean:
- pNew = CBotVar::Create(&token, w); // crée une variable
- if (!ReadWord(pf, w)) return FALSE;
- pNew->SetValInt((short)w, defnum);
- break;
- case CBotTypFloat:
- pNew = CBotVar::Create(&token, w); // crée une variable
- if (!ReadFloat(pf, ww)) return FALSE;
- pNew->SetValFloat(ww);
- break;
- case CBotTypString:
- pNew = CBotVar::Create(&token, w); // crée une variable
- if (!ReadString(pf, s)) return FALSE;
- pNew->SetValString(s);
- break;
+ switch (w)
+ {
+ case CBotTypInt:
+ case CBotTypBoolean:
+ pNew = CBotVar::Create(&token, w); // crée une variable
+ if (!ReadWord(pf, w)) return false;
+ pNew->SetValInt((short)w, defnum);
+ break;
+ case CBotTypFloat:
+ pNew = CBotVar::Create(&token, w); // crée une variable
+ if (!ReadFloat(pf, ww)) return false;
+ pNew->SetValFloat(ww);
+ break;
+ case CBotTypString:
+ pNew = CBotVar::Create(&token, w); // crée une variable
+ if (!ReadString(pf, s)) return false;
+ pNew->SetValString(s);
+ break;
- // restitue un objet intrinsic ou un élément d'un array
- case CBotTypIntrinsic:
- case CBotTypArrayBody:
- {
- CBotTypResult r;
- long id;
- if (!ReadType(pf, r)) return FALSE; // type complet
- if (!ReadLong(pf, id) ) return FALSE;
+ // restitue un objet intrinsic ou un élément d'un array
+ case CBotTypIntrinsic:
+ case CBotTypArrayBody:
+ {
+ CBotTypResult r;
+ long id;
+ if (!ReadType(pf, r)) return false; // type complet
+ if (!ReadLong(pf, id) ) return false;
-// if (!ReadString(pf, s)) return FALSE;
- {
- CBotVar* p = NULL;
- if ( id ) p = CBotVarClass::Find(id) ;
+// if (!ReadString(pf, s)) return false;
+ {
+ CBotVar* p = NULL;
+ if ( id ) p = CBotVarClass::Find(id) ;
- pNew = new CBotVarClass(&token, r); // crée directement une instance
- // attention cptuse = 0
- if ( !RestoreState(pf, ((CBotVarClass*)pNew)->m_pVar)) return FALSE;
- pNew->SetIdent(id);
+ pNew = new CBotVarClass(&token, r); // crée directement une instance
+ // attention cptuse = 0
+ if ( !RestoreState(pf, ((CBotVarClass*)pNew)->m_pVar)) return false;
+ pNew->SetIdent(id);
- if ( p != NULL )
- {
- delete pNew;
- pNew = p; // reprend l'élément connu
- }
- }
- }
- break;
+ if ( p != NULL )
+ {
+ delete pNew;
+ pNew = p; // reprend l'élément connu
+ }
+ }
+ }
+ break;
- case CBotTypPointer:
- case CBotTypNullPointer:
- if (!ReadString(pf, s)) return FALSE;
- {
- pNew = CBotVar::Create(&token, CBotTypResult(w, s));// crée une variable
- CBotVarClass* p = NULL;
- long id;
- ReadLong(pf, id);
-// if ( id ) p = CBotVarClass::Find(id); // retrouve l'instance ( fait par RestoreInstance )
-
- // restitue une copie de l'instance d'origine
- CBotVar* pInstance = NULL;
- if ( !CBotVar::RestoreState( pf, pInstance ) ) return FALSE;
- ((CBotVarPointer*)pNew)->SetPointer( pInstance ); // et pointe dessus
-
-// if ( p != NULL ) ((CBotVarPointer*)pNew)->SetPointer( p ); // plutôt celui-ci !
-
- }
- break;
-
- case CBotTypArrayPointer:
- {
- CBotTypResult r;
- if (!ReadType(pf, r)) return FALSE;
-
- pNew = CBotVar::Create(&token, r); // crée une variable
-
- // restitue une copie de l'instance d'origine
- CBotVar* pInstance = NULL;
- if ( !CBotVar::RestoreState( pf, pInstance ) ) return FALSE;
- ((CBotVarPointer*)pNew)->SetPointer( pInstance ); // et pointe dessus
- }
- break;
- default:
- ASM_TRAP();
- }
-
- if ( pPrev != NULL ) pPrev->m_next = pNew;
- if ( pVar == NULL ) pVar = pNew;
-
- pNew->m_binit = wi; // pNew->SetInit(wi);
- pNew->SetStatic(st);
- pNew->SetPrivate(prv-100);
- pPrev = pNew;
- }
- return TRUE;
+ case CBotTypPointer:
+ case CBotTypNullPointer:
+ if (!ReadString(pf, s)) return false;
+ {
+ pNew = CBotVar::Create(&token, CBotTypResult(w, s));// crée une variable
+ CBotVarClass* p = NULL;
+ long id;
+ ReadLong(pf, id);
+// if ( id ) p = CBotVarClass::Find(id); // retrouve l'instance ( fait par RestoreInstance )
+
+ // restitue une copie de l'instance d'origine
+ CBotVar* pInstance = NULL;
+ if ( !CBotVar::RestoreState( pf, pInstance ) ) return false;
+ ((CBotVarPointer*)pNew)->SetPointer( pInstance ); // et pointe dessus
+
+// if ( p != NULL ) ((CBotVarPointer*)pNew)->SetPointer( p ); // plutôt celui-ci !
+
+ }
+ break;
+
+ case CBotTypArrayPointer:
+ {
+ CBotTypResult r;
+ if (!ReadType(pf, r)) return false;
+
+ pNew = CBotVar::Create(&token, r); // crée une variable
+
+ // restitue une copie de l'instance d'origine
+ CBotVar* pInstance = NULL;
+ if ( !CBotVar::RestoreState( pf, pInstance ) ) return false;
+ ((CBotVarPointer*)pNew)->SetPointer( pInstance ); // et pointe dessus
+ }
+ break;
+ default:
+ ASM_TRAP();
+ }
+
+ if ( pPrev != NULL ) pPrev->m_next = pNew;
+ if ( pVar == NULL ) pVar = pNew;
+
+ pNew->m_binit = wi; // pNew->SetInit(wi);
+ pNew->SetStatic(st);
+ pNew->SetPrivate(prv-100);
+ pPrev = pNew;
+ }
+ return true;
}
@@ -1116,11 +1112,11 @@ BOOL CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
// gestion de la pile à la compilation
////////////////////////////////////////////////////////////////////////////
-CBotProgram* CBotCStack::m_prog = NULL; // init la variable statique
-int CBotCStack::m_error = 0;
-int CBotCStack::m_end = 0;
-CBotTypResult CBotCStack::m_retTyp = CBotTypResult(0);
-//CBotToken* CBotCStack::m_retClass= NULL;
+CBotProgram* CBotCStack::m_prog = NULL; // init la variable statique
+int CBotCStack::m_error = 0;
+int CBotCStack::m_end = 0;
+CBotTypResult CBotCStack::m_retTyp = CBotTypResult(0);
+//CBotToken* CBotCStack::m_retClass= NULL;
CBotCStack::CBotCStack(CBotCStack* ppapa)
@@ -1128,125 +1124,125 @@ CBotCStack::CBotCStack(CBotCStack* ppapa)
m_next = NULL;
m_prev = ppapa;
- if (ppapa == NULL)
- {
- m_error = 0;
- m_start = 0;
- m_end = 0;
- m_bBlock = TRUE;
- }
- else
- {
- m_start = ppapa->m_start;
- m_bBlock = FALSE;
- }
+ if (ppapa == NULL)
+ {
+ m_error = 0;
+ m_start = 0;
+ m_end = 0;
+ m_bBlock = true;
+ }
+ else
+ {
+ m_start = ppapa->m_start;
+ m_bBlock = false;
+ }
- m_listVar = NULL;
- m_var = NULL;
+ m_listVar = NULL;
+ m_var = NULL;
}
// destructeur
CBotCStack::~CBotCStack()
{
- if (m_next != NULL) delete m_next;
- if (m_prev != NULL) m_prev->m_next = NULL; // enlève de la chaîne
+ if (m_next != NULL) delete m_next;
+ if (m_prev != NULL) m_prev->m_next = NULL; // enlève de la chaîne
- delete m_var;
- delete m_listVar;
+ delete m_var;
+ delete m_listVar;
}
// utilisé uniquement à la compilation
-CBotCStack* CBotCStack::TokenStack(CBotToken* pToken, BOOL bBlock)
+CBotCStack* CBotCStack::TokenStack(CBotToken* pToken, bool bBlock)
{
- if (m_next != NULL) return m_next; // reprise dans une pile existante
+ if (m_next != NULL) return m_next; // reprise dans une pile existante
- CBotCStack* p = new CBotCStack(this);
- m_next = p; // chaîne l'élément
- p->m_bBlock = bBlock;
+ CBotCStack* p = new CBotCStack(this);
+ m_next = p; // chaîne l'élément
+ p->m_bBlock = bBlock;
- if (pToken != NULL) p->SetStartError(pToken->GivStart());
+ if (pToken != NULL) p->SetStartError(pToken->GivStart());
- return p;
+ return p;
}
CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils)
-{
- if ( pfils == this ) return inst;
+{
+ if ( pfils == this ) return inst;
- if (m_var != NULL) delete m_var; // valeur remplacée ?
- m_var = pfils->m_var; // résultat transmis
- pfils->m_var = NULL; // ne pas détruire la variable
+ if (m_var != NULL) delete m_var; // valeur remplacée ?
+ m_var = pfils->m_var; // résultat transmis
+ pfils->m_var = NULL; // ne pas détruire la variable
- if (m_error)
- {
- m_start = pfils->m_start; // récupère la position de l'erreur
- m_end = pfils->m_end;
- }
+ if (m_error)
+ {
+ m_start = pfils->m_start; // récupère la position de l'erreur
+ m_end = pfils->m_end;
+ }
- delete pfils;
- return inst;
+ delete pfils;
+ return inst;
}
CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils)
-{
- if (m_var != NULL) delete m_var; // valeur remplacée ?
- m_var = pfils->m_var; // résultat transmis
- pfils->m_var = NULL; // ne pas détruire la variable
+{
+ if (m_var != NULL) delete m_var; // valeur remplacée ?
+ m_var = pfils->m_var; // résultat transmis
+ pfils->m_var = NULL; // ne pas détruire la variable
- if (m_error)
- {
- m_start = pfils->m_start; // récupère la position de l'erreur
- m_end = pfils->m_end;
- }
+ if (m_error)
+ {
+ m_start = pfils->m_start; // récupère la position de l'erreur
+ m_end = pfils->m_end;
+ }
- delete pfils;
- return inst;
+ delete pfils;
+ return inst;
}
int CBotCStack::GivError(int& start, int& end)
{
- start = m_start;
- end = m_end;
- return m_error;
+ start = m_start;
+ end = m_end;
+ return m_error;
}
int CBotCStack::GivError()
{
- return m_error;
+ return m_error;
}
// type d'instruction sur la pile
CBotTypResult CBotCStack::GivTypResult(int mode)
{
- if (m_var == NULL)
- return CBotTypResult(99);
- return m_var->GivTypResult(mode);
+ if (m_var == NULL)
+ return CBotTypResult(99);
+ return m_var->GivTypResult(mode);
}
// type d'instruction sur la pile
int CBotCStack::GivType(int mode)
{
- if (m_var == NULL)
- return 99;
- return m_var->GivType(mode);
+ if (m_var == NULL)
+ return 99;
+ return m_var->GivType(mode);
}
// pointeur sur la pile est de quelle classe ?
CBotClass* CBotCStack::GivClass()
{
- if ( m_var == NULL )
- return NULL;
- if ( m_var->GivType(1) != CBotTypPointer ) return NULL;
+ if ( m_var == NULL )
+ return NULL;
+ if ( m_var->GivType(1) != CBotTypPointer ) return NULL;
- return m_var->GivClass();
+ return m_var->GivClass();
}
// type d'instruction sur la pile
void CBotCStack::SetType(CBotTypResult& type)
{
- if (m_var == NULL) return;
- m_var->SetType( type );
+ if (m_var == NULL) return;
+ m_var->SetType( type );
}
// cherche une variable sur la pile
@@ -1255,43 +1251,43 @@ void CBotCStack::SetType(CBotTypResult& type)
CBotVar* CBotCStack::FindVar(CBotToken* &pToken)
{
- CBotCStack* p = this;
- CBotString name = pToken->GivString();
-
- while (p != NULL)
- {
- CBotVar* pp = p->m_listVar;
- while ( pp != NULL)
- {
- if (name == pp->GivName())
- {
- return pp;
- }
- pp = pp->m_next;
- }
- p = p->m_prev;
- }
- return NULL;
+ CBotCStack* p = this;
+ CBotString name = pToken->GivString();
+
+ while (p != NULL)
+ {
+ CBotVar* pp = p->m_listVar;
+ while ( pp != NULL)
+ {
+ if (name == pp->GivName())
+ {
+ return pp;
+ }
+ pp = pp->m_next;
+ }
+ p = p->m_prev;
+ }
+ return NULL;
}
CBotVar* CBotCStack::FindVar(CBotToken& Token)
{
- CBotToken* pt = &Token;
- return FindVar(pt);
+ CBotToken* pt = &Token;
+ return FindVar(pt);
}
CBotVar* CBotCStack::CopyVar(CBotToken& Token)
{
- CBotVar* pVar = FindVar( Token );
+ CBotVar* pVar = FindVar( Token );
- if ( pVar == NULL) return NULL;
+ if ( pVar == NULL) return NULL;
- CBotVar* pCopy = CBotVar::Create( "", pVar->GivType() );
- pCopy->Copy(pVar);
- return pCopy;
+ CBotVar* pCopy = CBotVar::Create( "", pVar->GivType() );
+ pCopy->Copy(pVar);
+ return pCopy;
}
-BOOL CBotCStack::IsOk()
+bool CBotCStack::IsOk()
{
return (m_error == 0);
}
@@ -1299,177 +1295,177 @@ BOOL CBotCStack::IsOk()
void CBotCStack::SetStartError( int pos )
{
- if ( m_error != 0) return; // ne change pas une erreur déjà existante
- m_start = pos;
+ if ( m_error != 0) return; // ne change pas une erreur déjà existante
+ m_start = pos;
}
void CBotCStack::SetError(int n, int pos)
{
- if ( n!= 0 && m_error != 0) return; // ne change pas une erreur déjà existante
- m_error = n;
- m_end = pos;
+ if ( n!= 0 && m_error != 0) return; // ne change pas une erreur déjà existante
+ m_error = n;
+ m_end = pos;
}
void CBotCStack::SetError(int n, CBotToken* p)
{
- if (m_error) return; // ne change pas une erreur déjà existante
- m_error = n;
- m_start = p->GivStart();
- m_end = p->GivEnd();
+ if (m_error) return; // ne change pas une erreur déjà existante
+ m_error = n;
+ m_start = p->GivStart();
+ m_end = p->GivEnd();
}
void CBotCStack::ResetError(int n, int start, int end)
{
- m_error = n;
- m_start = start;
- m_end = end;
+ m_error = n;
+ m_start = start;
+ m_end = end;
}
-BOOL CBotCStack::NextToken(CBotToken* &p)
+bool CBotCStack::NextToken(CBotToken* &p)
{
- CBotToken* pp = p;
+ CBotToken* pp = p;
- p = p->GivNext();
- if (p!=NULL) return TRUE;
+ p = p->GivNext();
+ if (p!=NULL) return true;
- SetError(TX_ENDOF, pp->GivEnd());
- return FALSE;
+ SetError(TX_ENDOF, pp->GivEnd());
+ return false;
}
void CBotCStack::SetBotCall(CBotProgram* p)
{
- m_prog = p;
+ m_prog = p;
}
CBotProgram* CBotCStack::GivBotCall()
{
- return m_prog;
+ return m_prog;
}
void CBotCStack::SetRetType(CBotTypResult& type)
{
- m_retTyp = type;
+ m_retTyp = type;
}
CBotTypResult CBotCStack::GivRetType()
{
- return m_retTyp;
+ return m_retTyp;
}
void CBotCStack::SetVar( CBotVar* var )
{
- if (m_var) delete m_var; // remplacement d'une variable
- m_var = var;
+ if (m_var) delete m_var; // remplacement d'une variable
+ m_var = var;
}
// met sur le stack une copie d'une variable
void CBotCStack::SetCopyVar( CBotVar* var )
{
- if (m_var) delete m_var; // remplacement d'une variable
+ if (m_var) delete m_var; // remplacement d'une variable
- if ( var == NULL ) return;
- m_var = CBotVar::Create("", var->GivTypResult(2));
- m_var->Copy( var );
+ if ( var == NULL ) return;
+ m_var = CBotVar::Create("", var->GivTypResult(2));
+ m_var->Copy( var );
}
CBotVar* CBotCStack::GivVar()
{
- return m_var;
+ return m_var;
}
void CBotCStack::AddVar(CBotVar* pVar)
{
- CBotCStack* p = this;
+ CBotCStack* p = this;
- // revient sur l'élement père
- while (p != NULL && p->m_bBlock == 0) p = p->m_prev;
+ // revient sur l'élement père
+ while (p != NULL && p->m_bBlock == 0) p = p->m_prev;
- if ( p == NULL ) return;
+ if ( p == NULL ) return;
- CBotVar** pp = &p->m_listVar;
- while ( *pp != NULL ) pp = &(*pp)->m_next;
+ CBotVar** pp = &p->m_listVar;
+ while ( *pp != NULL ) pp = &(*pp)->m_next;
- *pp = pVar; // ajoute à la suite
+ *pp = pVar; // ajoute à la suite
-#ifdef _DEBUG
- if ( pVar->GivUniqNum() == 0 ) ASM_TRAP();
+#ifdef _DEBUG
+ if ( pVar->GivUniqNum() == 0 ) ASM_TRAP();
#endif
}
// test si une variable est déjà définie localement
-BOOL CBotCStack::CheckVarLocal(CBotToken* &pToken)
+bool CBotCStack::CheckVarLocal(CBotToken* &pToken)
{
- CBotCStack* p = this;
- CBotString name = pToken->GivString();
+ CBotCStack* p = this;
+ CBotString name = pToken->GivString();
- while (p != NULL)
- {
- CBotVar* pp = p->m_listVar;
- while ( pp != NULL)
- {
- if (name == pp->GivName())
- return TRUE;
- pp = pp->m_next;
- }
- if ( p->m_bBlock ) return FALSE;
- p = p->m_prev;
- }
- return FALSE;
+ while (p != NULL)
+ {
+ CBotVar* pp = p->m_listVar;
+ while ( pp != NULL)
+ {
+ if (name == pp->GivName())
+ return true;
+ pp = pp->m_next;
+ }
+ if ( p->m_bBlock ) return false;
+ p = p->m_prev;
+ }
+ return false;
}
CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent)
{
- nIdent = 0;
- CBotTypResult val(-1);
+ nIdent = 0;
+ CBotTypResult val(-1);
- val = CBotCall::CompileCall(p, ppVars, this, nIdent);
- if (val.GivType() < 0)
- {
- val = m_prog->GivFunctions()->CompileCall(p->GivString(), ppVars, nIdent);
- if ( val.GivType() < 0 )
- {
- // pVar = NULL; // l'erreur n'est pas sur un paramètre en particulier
- SetError( -val.GivType(), p );
- val.SetType(-val.GivType());
- return val;
- }
- }
- return val;
+ val = CBotCall::CompileCall(p, ppVars, this, nIdent);
+ if (val.GivType() < 0)
+ {
+ val = m_prog->GivFunctions()->CompileCall(p->GivString(), ppVars, nIdent);
+ if ( val.GivType() < 0 )
+ {
+ // pVar = NULL; // l'erreur n'est pas sur un paramètre en particulier
+ SetError( -val.GivType(), p );
+ val.SetType(-val.GivType());
+ return val;
+ }
+ }
+ return val;
}
// test si un nom de procédure est déjà défini quelque part
-BOOL CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
-{
- CBotString name = pToken->GivString();
-
- if ( CBotCall::CheckCall(name) ) return TRUE;
-
- CBotFunction* pp = m_prog->GivFunctions();
- while ( pp != NULL )
- {
- if ( pToken->GivString() == pp->GivName() )
- {
- // les paramètres sont-ils exactement les mêmes ?
- if ( pp->CheckParam( pParam ) )
- return TRUE;
- }
- pp = pp->Next();
- }
-
- pp = CBotFunction::m_listPublic;
- while ( pp != NULL )
- {
- if ( pToken->GivString() == pp->GivName() )
- {
- // les paramètres sont-ils exactement les mêmes ?
- if ( pp->CheckParam( pParam ) )
- return TRUE;
- }
- pp = pp->m_nextpublic;
- }
-
- return FALSE;
+bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
+{
+ CBotString name = pToken->GivString();
+
+ if ( CBotCall::CheckCall(name) ) return true;
+
+ CBotFunction* pp = m_prog->GivFunctions();
+ while ( pp != NULL )
+ {
+ if ( pToken->GivString() == pp->GivName() )
+ {
+ // les paramètres sont-ils exactement les mêmes ?
+ if ( pp->CheckParam( pParam ) )
+ return true;
+ }
+ pp = pp->Next();
+ }
+
+ pp = CBotFunction::m_listPublic;
+ while ( pp != NULL )
+ {
+ if ( pToken->GivString() == pp->GivName() )
+ {
+ // les paramètres sont-ils exactement les mêmes ?
+ if ( pp->CheckParam( pParam ) )
+ return true;
+ }
+ pp = pp->m_nextpublic;
+ }
+
+ return false;
}
diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp
index 53b0f27..9d5d257 100644
--- a/src/CBot/CBotString.cpp
+++ b/src/CBot/CBotString.cpp
@@ -13,51 +13,145 @@
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/./////////////////////////////////////////////////////
-// gestion de chaine
-// basé sur le CString de MFC
-// mais moins complet
-#include "CBot.h"
-
-#include <string.h>
+//strings management
-HINSTANCE CBotString::m_hInstance = (HINSTANCE)LoadLibrary("libCbot.dll"); // comment le récupérer autrement ??
+#include "CBot.h"
+#include <cstdlib>
+#include <cstring>
+#include <algorithm>
+
+//Map is filled with id-string pars that are needed for CBot language parsing
+const std::map<EID, char *> CBotString::s_keywordString =
+{
+ {ID_IF, "if"},
+ {ID_ELSE, "else"},
+ {ID_WHILE, "while"},
+ {ID_DO, "do"},
+ {ID_FOR, "for"},
+ {ID_BREAK, "break"},
+ {ID_CONTINUE, "continue"},
+ {ID_SWITCH, "switch"},
+ {ID_CASE, "case"},
+ {ID_DEFAULT, "default"},
+ {ID_TRY, "try"},
+ {ID_THROW, "throw"},
+ {ID_CATCH, "catch"},
+ {ID_FINALLY, "finally"},
+ {ID_TXT_AND, "and"},
+ {ID_TXT_OR, "or"},
+ {ID_TXT_NOT, "not"},
+ {ID_RETURN, "return"},
+ {ID_CLASS, "class"},
+ {ID_EXTENDS, "extends"},
+ {ID_SYNCHO, "synchronized"},
+ {ID_NEW, "new"},
+ {ID_PUBLIC, "public"},
+ {ID_EXTERN, "extern"},
+ {ID_FINAL, "final"},
+ {ID_STATIC, "static"},
+ {ID_PROTECTED, "protected"},
+ {ID_PRIVATE, "private"},
+ {ID_REPEAT, "repeat"},
+ {ID_DEBUGDD, "STARTDEBUGDD"},
+ {ID_INT, "int"},
+ {ID_FLOAT, "float"},
+ {ID_BOOLEAN, "boolean"},
+ {ID_STRING, "string"},
+ {ID_VOID, "void"},
+ {ID_BOOL, "bool"},
+ {ID_TRUE, "true"},
+ {ID_FALSE, "false"},
+ {ID_NULL, "null"},
+ {ID_NAN, "nan"},
+ {ID_OPENPAR, "("},
+ {ID_CLOSEPAR, ")"},
+ {ID_OPBLK, "{"},
+ {ID_CLBLK, "}"},
+ {ID_SEP, "},"},
+ {ID_COMMA, ","},
+ {ID_DOTS, ":"},
+ {ID_DOT, "."},
+ {ID_OPBRK, "["},
+ {ID_CLBRK, "]"},
+ {ID_DBLDOTS, "::"},
+ {ID_LOGIC, "?"},
+ {ID_ADD, "+"},
+ {ID_SUB, "-"},
+ {ID_MUL, "*"},
+ {ID_DIV, "/"},
+ {ID_ASS, "="},
+ {ID_ASSADD, "+="},
+ {ID_ASSSUB, "-="},
+ {ID_ASSMUL, "*="},
+ {ID_ASSDIV, "/="},
+ {ID_ASSOR, "|="},
+ {ID_ASSAND, "&="},
+ {ID_ASSXOR, "^="},
+ {ID_ASSSL, "<<="},
+ {ID_ASSSR, ">>>="},
+ {ID_ASSASR, ">>="},
+ {ID_SL, "<<"},
+ {ID_SR, ">>"},
+ {ID_ASR, ">>"},
+ {ID_INC, "++"},
+ {ID_DEC, "--"},
+ {ID_LO, "<"},
+ {ID_HI, ">"},
+ {ID_LS, "<<"},
+ {ID_HS, ">="},
+ {ID_EQ, "=="},
+ {ID_NE, "!="},
+ {ID_AND, "&"},
+ {ID_XOR, "^"},
+ {ID_OR, "|"},
+ {ID_LOG_AND, "&&"},
+ {ID_LOG_OR, "||"},
+ {ID_LOG_NOT, "!"},
+ {ID_NOT, "~"},
+ {ID_MODULO, "%"},
+ {ID_POWER, "**"},
+ {ID_ASSMODULO, "%="},
+ {ID_SUPER, "super"},
+ {TX_UNDEF, "undefined"},
+ {TX_NAN, "not a number"}
+};
CBotString::CBotString()
{
- m_ptr = NULL; // chaine vide
- m_lg = 0;
+ m_ptr = NULL;
+ m_lg = 0;
}
CBotString::~CBotString()
{
- if (m_ptr != NULL) free(m_ptr);
+ free(m_ptr); //we can call free on null pointer as it's save
}
CBotString::CBotString(const char* p)
{
- m_lg = lstrlen( p );
+ m_lg = strlen(p);
- m_ptr = NULL;
- if (m_lg>0)
- {
- m_ptr = (char*)malloc(m_lg+1);
- lstrcpy(m_ptr, p);
- }
+ m_ptr = NULL;
+ if (m_lg>0)
+ {
+ m_ptr = (char*)malloc(m_lg+1);
+ strcpy(m_ptr, p);
+ }
}
CBotString::CBotString(const CBotString& srcString)
{
- m_lg = srcString.m_lg;
+ m_lg = srcString.m_lg;
- m_ptr = NULL;
- if (m_lg>0)
- {
- m_ptr = (char*)malloc(m_lg+1);
- lstrcpy(m_ptr, srcString.m_ptr);
- }
+ m_ptr = NULL;
+ if (m_lg>0)
+ {
+ m_ptr = (char*)malloc(m_lg+1);
+ strcpy(m_ptr, srcString.m_ptr);
+ }
}
@@ -65,539 +159,533 @@ CBotString::CBotString(const CBotString& srcString)
int CBotString::GivLength()
{
- if ( m_ptr == NULL ) return 0;
- return lstrlen( m_ptr );
+ if (m_ptr == NULL) return 0;
+ return strlen( m_ptr );
}
CBotString CBotString::Left(int nCount) const
{
- char chaine[2000];
-
- int i;
- for (i = 0; i < m_lg && i < nCount && i < 1999; i++)
- {
- chaine[i] = m_ptr[i];
- }
- chaine[i] = 0 ;
+ char chain[2000];
- return CBotString( chaine );
+ size_t i;
+ for (i = 0; i < m_lg && i < nCount && i < 1999; ++i)
+ {
+ chain[i] = m_ptr[i];
+ }
+ chain[i] = 0 ;
+
+ return CBotString(chain);
}
CBotString CBotString::Right(int nCount) const
{
- char chaine[2000];
-
- int i = m_lg - nCount;
- if ( i < 0 ) i = 0;
+ char chain[2000];
+
+ int i = m_lg - nCount;
+ if ( i < 0 ) i = 0;
- int j;
- for ( j = 0 ; i < m_lg && i < 1999; i++)
- {
- chaine[j++] = m_ptr[i];
- }
- chaine[j] = 0 ;
+ size_t j;
+ for (size_t j = 0 ; i < m_lg && i < 1999; ++i)
+ {
+ chain[j++] = m_ptr[i];
+ }
+ chain[j] = 0 ;
- return CBotString( chaine );
+ return CBotString(chain);
}
CBotString CBotString::Mid(int nFirst, int nCount) const
{
- char chaine[2000];
-
- int i;
+ char chain[2000];
- for ( i = nFirst; i < m_lg && i < 1999 && i <= nFirst + nCount; i++)
- {
- chaine[i] = m_ptr[i];
- }
- chaine[i] = 0 ;
+ size_t i;
+ for (i = nFirst; i < m_lg && i < 1999 && i <= nFirst + nCount; ++i)
+ {
+ chain[i] = m_ptr[i];
+ }
+ chain[i] = 0 ;
- return CBotString( chaine );
+ return CBotString(chain);
}
CBotString CBotString::Mid(int nFirst) const
{
- char chaine[2000];
-
- int i;
+ char chain[2000];
- for ( i = nFirst; i < m_lg && i < 1999 ; i++)
- {
- chaine[i] = m_ptr[i];
- }
- chaine[i] = 0 ;
+ size_t i;
+ for (i = nFirst; i < m_lg && i < 1999 ; ++i)
+ {
+ chain[i] = m_ptr[i];
+ }
+ chain[i] = 0 ;
- return CBotString( chaine );
+ return CBotString(chain);
}
int CBotString::Find(const char c)
{
- int i;
- for (i = 0; i < m_lg; i++)
- {
- if (m_ptr[i] == c) return i;
- }
- return -1;
+ for (size_t i = 0; i < m_lg; ++i)
+ {
+ if (m_ptr[i] == c) return i;
+ }
+ return -1;
}
-int CBotString::Find(LPCTSTR lpsz)
+int CBotString::Find(const char * lpsz)
{
- int i, j;
- int l = lstrlen(lpsz);
+ int l = strlen(lpsz);
- for (i = 0; i <= m_lg-l; i++)
- {
- for (j = 0; j < l; j++)
- {
- if (m_ptr[i+j] != lpsz[j]) goto bad;
- }
- return i;
+ for (size_t i = 0; i <= m_lg-l; ++i)
+ {
+ for (size_t j = 0; j < l; ++j)
+ {
+ if (m_ptr[i+j] != lpsz[j]) goto bad;
+ }
+ return i;
bad:;
- }
- return -1;
+ }
+ return -1;
}
int CBotString::ReverseFind(const char c)
{
- int i;
- for (i = m_lg-1; i >= 0; i--)
- {
- if (m_ptr[i] == c) return i;
- }
- return -1;
+ int i;
+ for (i = m_lg-1; i >= 0; --i)
+ {
+ if (m_ptr[i] == c) return i;
+ }
+ return -1;
}
-int CBotString::ReverseFind(LPCTSTR lpsz)
+int CBotString::ReverseFind(const char * lpsz)
{
- int i, j;
- int l = lstrlen(lpsz);
+ int i, j;
+ int l = strlen(lpsz);
- for (i = m_lg-l; i >= 0; i--)
- {
- for (j = 0; j < l; j++)
- {
- if (m_ptr[i+j] != lpsz[j]) goto bad;
- }
- return i;
+ for (i = m_lg-l; i >= 0; --i)
+ {
+ for (j = 0; j < l; ++j)
+ {
+ if (m_ptr[i+j] != lpsz[j]) goto bad;
+ }
+ return i;
bad:;
- }
- return -1;
+ }
+ return -1;
}
CBotString CBotString::Mid(int start, int lg)
{
- CBotString res;
- if (start >= m_lg) return res;
+ CBotString res;
+ if (start >= m_lg) return res;
- if ( lg < 0 ) lg = m_lg - start;
+ if ( lg < 0 ) lg = m_lg - start;
- char* p = (char*)malloc(m_lg+1);
- lstrcpy(p, m_ptr+start);
- p[lg] = 0;
+ char* p = (char*)malloc(m_lg+1);
+ strcpy(p, m_ptr+start);
+ p[lg] = 0;
- res = p;
- free(p);
- return res;
+ res = p;
+ free(p);
+ return res;
}
void CBotString::MakeUpper()
{
- int i;
-
- for ( i = 0; i < m_lg && i < 1999 ; i++)
- {
- char c = m_ptr[i];
- if ( c >= 'a' && c <= 'z' ) m_ptr[i] = c - 'a' + 'A';
- }
+ for (size_t i = 0; i < m_lg && i < 1999 ; ++i)
+ {
+ char c = m_ptr[i];
+ if ( c >= 'a' && c <= 'z' ) m_ptr[i] = c - 'a' + 'A';
+ }
}
void CBotString::MakeLower()
{
- int i;
-
- for ( i = 0; i < m_lg && i < 1999 ; i++)
- {
- char c = m_ptr[i];
- if ( c >= 'A' && c <= 'Z' ) m_ptr[i] = c - 'A' + 'a';
- }
+ for (size_t i = 0; i < m_lg && i < 1999 ; ++i)
+ {
+ char c = m_ptr[i];
+ if ( c >= 'A' && c <= 'Z' ) m_ptr[i] = c - 'A' + 'a';
+ }
}
-
-
-#define MAXSTRING 256
-
-BOOL CBotString::LoadString(UINT id)
+bool CBotString::LoadString(unsigned int id)
{
- char buffer[MAXSTRING];
-
- m_lg = ::LoadString( m_hInstance, id, buffer, MAXSTRING );
+ const char * str = NULL;
+ str = MapIdToString((EID)id);
+ if (m_ptr != NULL) free(m_ptr);
- if (m_ptr != NULL) free(m_ptr);
-
- m_ptr = NULL;
- if (m_lg > 0)
- {
- m_ptr = (char*)malloc(m_lg+1);
- lstrcpy(m_ptr, buffer);
- return TRUE;
- }
- return FALSE;
+ m_lg = strlen(str);
+ m_ptr = NULL;
+ if (m_lg > 0)
+ {
+ m_ptr = (char*)malloc(m_lg+1);
+ strcpy(m_ptr, str);
+ return true;
+ }
+ return false;
}
-
+
const CBotString& CBotString::operator=(const CBotString& stringSrc)
{
- if (m_ptr != NULL) free(m_ptr);
+ free(m_ptr);
+ m_ptr = NULL;
- m_lg = stringSrc.m_lg;
- m_ptr = NULL;
+ m_lg = stringSrc.m_lg;
- if (m_lg > 0)
- {
- m_ptr = (char*)malloc(m_lg+1);
- lstrcpy(m_ptr, stringSrc.m_ptr);
- }
+ if (m_lg > 0)
+ {
+ m_ptr = (char*)malloc(m_lg+1);
+ strcpy(m_ptr, stringSrc.m_ptr);
+ }
- return *this;
+ return *this;
}
-CBotString operator+(const CBotString& string, LPCTSTR lpsz)
+CBotString operator+(const CBotString& string, const char * lpsz)
{
- CBotString s ( string );
- s += lpsz;
- return s;
+ CBotString s(string);
+ s += lpsz;
+ return s;
}
const CBotString& CBotString::operator+(const CBotString& stringSrc)
{
- char* p = (char*)malloc(m_lg+stringSrc.m_lg+1);
+ char* p = (char*)malloc(m_lg+stringSrc.m_lg+1);
- lstrcpy(p, m_ptr);
- char* pp = p + m_lg;
- lstrcpy(pp, stringSrc.m_ptr);
+ strcpy(p, m_ptr);
+ char* pp = p + m_lg;
+ strcpy(pp, stringSrc.m_ptr);
- if (m_ptr != NULL) free(m_ptr);
- m_ptr = p;
- m_lg += stringSrc.m_lg;
+ free(m_ptr);
+ m_ptr = p;
+ m_lg += stringSrc.m_lg;
- return *this;
+ return *this;
}
const CBotString& CBotString::operator=(const char ch)
{
- if (m_ptr != NULL) free(m_ptr);
+ free(m_ptr);
+
+ m_lg = 1;
- m_lg = 1;
+ m_ptr = (char*)malloc(2);
+ m_ptr[0] = ch;
+ m_ptr[1] = 0;
- m_ptr = (char*)malloc(2);
- m_ptr[0] = ch;
- m_ptr[1] = 0;
-
- return *this;
+ return *this;
}
const CBotString& CBotString::operator=(const char* pString)
{
- if (m_ptr != NULL) free(m_ptr);
- m_ptr = NULL;
+ free(m_ptr);
+ m_ptr = NULL;
- if ( pString != NULL )
- {
- m_lg = lstrlen(pString);
+ if (pString != NULL)
+ {
+ m_lg = strlen(pString);
- if (m_lg != 0)
- {
- m_ptr = (char*)malloc(m_lg+1);
- lstrcpy(m_ptr, pString);
- }
- }
-
- return *this;
+ if (m_lg != 0)
+ {
+ m_ptr = (char*)malloc(m_lg+1);
+ strcpy(m_ptr, pString);
+ }
+ }
+
+ return *this;
}
const CBotString& CBotString::operator+=(const char ch)
{
- char* p = (char*)malloc(m_lg+2);
+ char* p = (char*)malloc(m_lg+2);
- if (m_ptr!=NULL) lstrcpy(p, m_ptr);
- p[m_lg++] = ch;
- p[m_lg] = 0;
+ if (m_ptr!=NULL) strcpy(p, m_ptr);
+ p[m_lg++] = ch;
+ p[m_lg] = 0;
- if (m_ptr != NULL) free(m_ptr);
+ free(m_ptr);
- m_ptr = p;
+ m_ptr = p;
- return *this;
+ return *this;
}
const CBotString& CBotString::operator+=(const CBotString& str)
{
- char* p = (char*)malloc(m_lg+str.m_lg+1);
+ char* p = (char*)malloc(m_lg+str.m_lg+1);
- lstrcpy(p, m_ptr);
- char* pp = p + m_lg;
- lstrcpy(pp, str.m_ptr);
+ strcpy(p, m_ptr);
+ char* pp = p + m_lg;
+ strcpy(pp, str.m_ptr);
- m_lg = m_lg + str.m_lg;
+ m_lg = m_lg + str.m_lg;
- if (m_ptr != NULL) free(m_ptr);
+ free(m_ptr);
- m_ptr = p;
+ m_ptr = p;
- return *this;
+ return *this;
}
-BOOL CBotString::operator==(const CBotString& str)
+bool CBotString::operator==(const CBotString& str)
{
- return Compare(str) == 0;
+ return Compare(str) == 0;
}
-BOOL CBotString::operator==(const char* p)
+bool CBotString::operator==(const char* p)
{
- return Compare(p) == 0;
+ return Compare(p) == 0;
}
-BOOL CBotString::operator!=(const CBotString& str)
+bool CBotString::operator!=(const CBotString& str)
{
- return Compare(str) != 0;
+ return Compare(str) != 0;
}
-BOOL CBotString::operator!=(const char* p)
+bool CBotString::operator!=(const char* p)
{
- return Compare(p) != 0;
+ return Compare(p) != 0;
}
-BOOL CBotString::operator>(const CBotString& str)
+bool CBotString::operator>(const CBotString& str)
{
- return Compare(str) > 0;
+ return Compare(str) > 0;
}
-BOOL CBotString::operator>(const char* p)
+bool CBotString::operator>(const char* p)
{
- return Compare(p) > 0;
+ return Compare(p) > 0;
}
-BOOL CBotString::operator>=(const CBotString& str)
+bool CBotString::operator>=(const CBotString& str)
{
- return Compare(str) >= 0;
+ return Compare(str) >= 0;
}
-BOOL CBotString::operator>=(const char* p)
+bool CBotString::operator>=(const char* p)
{
- return Compare(p) >= 0;
+ return Compare(p) >= 0;
}
-BOOL CBotString::operator<(const CBotString& str)
+bool CBotString::operator<(const CBotString& str)
{
- return Compare(str) < 0;
+ return Compare(str) < 0;
}
-BOOL CBotString::operator<(const char* p)
+bool CBotString::operator<(const char* p)
{
- return Compare(p) < 0;
+ return Compare(p) < 0;
}
-BOOL CBotString::operator<=(const CBotString& str)
+bool CBotString::operator<=(const CBotString& str)
{
- return Compare(str) <= 0;
+ return Compare(str) <= 0;
}
-BOOL CBotString::operator<=(const char* p)
+bool CBotString::operator<=(const char* p)
{
- return Compare(p) <= 0;
+ return Compare(p) <= 0;
}
-BOOL CBotString::IsEmpty() const
+bool CBotString::IsEmpty() const
{
- return (m_lg == 0);
+ return (m_lg == 0);
}
void CBotString::Empty()
{
- if (m_ptr != NULL) free(m_ptr);
- m_ptr = NULL;
- m_lg = 0;
+ free(m_ptr);
+ m_ptr = NULL;
+ m_lg = 0;
}
-static char nilstring[] = {0};
+static char emptyString[] = {0};
-CBotString::operator LPCTSTR() const
+CBotString::operator const char * () const
{
- if (this == NULL || m_ptr == NULL) return nilstring;
- return m_ptr;
+ if (this == NULL || m_ptr == NULL) return emptyString;
+ return m_ptr;
}
-int CBotString::Compare(LPCTSTR lpsz) const
+int CBotString::Compare(const char * lpsz) const
{
- char* p = m_ptr;
- if (lpsz == NULL) lpsz = nilstring;
- if (m_ptr == NULL) p = nilstring;
- return strcmp(p, lpsz); // wcscmp
+ char* p = m_ptr;
+ if (lpsz == NULL) lpsz = emptyString;
+ if (m_ptr == NULL) p = emptyString;
+ return strcmp(p, lpsz); // wcscmp
}
-
+const char * CBotString::MapIdToString(EID id)
+{
+ if (s_keywordString.find(id) != s_keywordString.end())
+ {
+ return s_keywordString.at(id);
+ }
+ else
+ {
+ return emptyString;
+ }
+}
///////////////////////////////////////////////////////////////////////////////////////////
-// tableaux de chaines
+// arrays of strings
CBotStringArray::CBotStringArray()
{
- m_pData = NULL;
- m_nSize = m_nMaxSize = 0;
+ m_pData = NULL;
+ m_nSize = m_nMaxSize = 0;
}
CBotStringArray::~CBotStringArray()
{
- SetSize(0); // détruit les données !
+ SetSize(0); // destroys data !
}
int CBotStringArray::GivSize()
{
- return m_nSize;
+ return m_nSize;
}
void CBotStringArray::Add(const CBotString& str)
{
- SetSize(m_nSize+1);
+ SetSize(m_nSize+1);
- m_pData[m_nSize-1] = str;
+ m_pData[m_nSize-1] = str;
}
-
///////////////////////////////////////////////////////////////////////
-// routines utilitaires
+// utility routines
static inline void ConstructElement(CBotString* pNewData)
{
- memset(pNewData, 0, sizeof(CBotString));
+ memset(pNewData, 0, sizeof(CBotString));
}
static inline void DestructElement(CBotString* pOldData)
{
- pOldData->~CBotString();
+ pOldData->~CBotString();
}
static inline void CopyElement(CBotString* pSrc, CBotString* pDest)
{
- *pSrc = *pDest;
+ *pSrc = *pDest;
}
static void ConstructElements(CBotString* pNewData, int nCount)
{
- while (nCount--)
- {
- ConstructElement(pNewData);
- pNewData++;
- }
+ while (nCount--)
+ {
+ ConstructElement(pNewData);
+ pNewData++;
+ }
}
static void DestructElements(CBotString* pOldData, int nCount)
{
- while (nCount--)
- {
- DestructElement(pOldData);
- pOldData++;
- }
+ while (nCount--)
+ {
+ DestructElement(pOldData);
+ pOldData++;
+ }
}
static void CopyElements(CBotString* pDest, CBotString* pSrc, int nCount)
{
- while (nCount--)
- {
- *pDest = *pSrc;
- ++pDest;
- ++pSrc;
- }
+ while (nCount--)
+ {
+ *pDest = *pSrc;
+ ++pDest;
+ ++pSrc;
+ }
}
-// sélect la taille du tableau
+// set the array size
void CBotStringArray::SetSize(int nNewSize)
{
- if (nNewSize == 0)
- {
- // shrink to nothing
-
- DestructElements(m_pData, m_nSize);
- delete[] (BYTE*)m_pData;
- m_pData = NULL;
- m_nSize = m_nMaxSize = 0;
- }
- else if (m_pData == NULL)
- {
- // create one with exact size
- m_pData = (CBotString*) new BYTE[nNewSize * sizeof(CBotString)];
-
- ConstructElements(m_pData, nNewSize);
-
- m_nSize = m_nMaxSize = nNewSize;
- }
- else if (nNewSize <= m_nMaxSize)
- {
- // it fits
- if (nNewSize > m_nSize)
- {
- // initialize the new elements
-
- ConstructElements(&m_pData[m_nSize], nNewSize-m_nSize);
-
- }
-
- else if (m_nSize > nNewSize) // destroy the old elements
- DestructElements(&m_pData[nNewSize], m_nSize-nNewSize);
-
- m_nSize = nNewSize;
- }
- else
- {
- // otherwise, grow array
- int nGrowBy;
- {
- // heuristically determine growth when nGrowBy == 0
- // (this avoids heap fragmentation in many situations)
- nGrowBy = min(1024, max(4, m_nSize / 8));
- }
- int nNewMax;
- if (nNewSize < m_nMaxSize + nGrowBy)
- nNewMax = m_nMaxSize + nGrowBy; // granularity
- else
- nNewMax = nNewSize; // no slush
-
- CBotString* pNewData = (CBotString*) new BYTE[nNewMax * sizeof(CBotString)];
-
- // copy new data from old
- memcpy(pNewData, m_pData, m_nSize * sizeof(CBotString));
-
- // construct remaining elements
- ConstructElements(&pNewData[m_nSize], nNewSize-m_nSize);
-
-
- // Ret rid of old stuff (note: no destructors called)
- delete[] (BYTE*)m_pData;
- m_pData = pNewData;
- m_nSize = nNewSize;
- m_nMaxSize = nNewMax;
- }
+ if (nNewSize == 0)
+ {
+ // shrink to nothing
+
+ DestructElements(m_pData, m_nSize);
+ delete[] (unsigned char *)m_pData;
+ m_pData = NULL;
+ m_nSize = m_nMaxSize = 0;
+ }
+ else if (m_pData == NULL)
+ {
+ // create one with exact size
+ m_pData = (CBotString*) new unsigned char[nNewSize * sizeof(CBotString)];
+
+ ConstructElements(m_pData, nNewSize);
+
+ m_nSize = m_nMaxSize = nNewSize;
+ }
+ else if (nNewSize <= m_nMaxSize)
+ {
+ // it fits
+ if (nNewSize > m_nSize)
+ {
+ // initialize the new elements
+
+ ConstructElements(&m_pData[m_nSize], nNewSize-m_nSize);
+
+ }
+
+ else if (m_nSize > nNewSize) // destroy the old elements
+ DestructElements(&m_pData[nNewSize], m_nSize-nNewSize);
+
+ m_nSize = nNewSize;
+ }
+ else
+ {
+ // otherwise, grow array
+ int nGrowBy;
+ {
+ // heuristically determine growth when nGrowBy == 0
+ // (this avoids heap fragmentation in many situations)
+ nGrowBy = std::min(1024, std::max(4, m_nSize / 8));
+ }
+ int nNewMax;
+ if (nNewSize < m_nMaxSize + nGrowBy)
+ nNewMax = m_nMaxSize + nGrowBy; // granularity
+ else
+ nNewMax = nNewSize; // no slush
+
+ CBotString* pNewData = (CBotString*) new unsigned char[nNewMax * sizeof(CBotString)];
+
+ // copy new data from old
+ memcpy(pNewData, m_pData, m_nSize * sizeof(CBotString));
+
+ // construct remaining elements
+ ConstructElements(&pNewData[m_nSize], nNewSize-m_nSize);
+
+
+ // Get rid of old stuff (note: no destructors called)
+ delete[] (unsigned char *)m_pData;
+ m_pData = pNewData;
+ m_nSize = nNewSize;
+ m_nMaxSize = nNewMax;
+ }
}
CBotString& CBotStringArray::operator[](int nIndex)
{
- return ElementAt(nIndex);
+ return ElementAt(nIndex);
}
CBotString& CBotStringArray::ElementAt(int nIndex)
{
- return m_pData[nIndex];
+ return m_pData[nIndex];
}
-
-
diff --git a/src/CBot/CBotToken.cpp b/src/CBot/CBotToken.cpp
index fbf6726..03a5337 100644
--- a/src/CBot/CBotToken.cpp
+++ b/src/CBot/CBotToken.cpp
@@ -22,6 +22,7 @@
#include "CBot.h"
+#include <cstdarg>
CBotStringArray CBotToken::m_ListKeyWords;
int CBotToken::m_ListIdKeyWords[200];
@@ -188,27 +189,27 @@ void CBotToken::SetPos(int start, int end)
m_end = end;
}
-BOOL CharInList(const char c, const char* list)
+bool CharInList(const char c, const char* list)
{
int i = 0;
- while (TRUE)
+ while (true)
{
- if (c == list[i++]) return TRUE;
- if (list[i] == 0) return FALSE;
+ if (c == list[i++]) return true;
+ if (list[i] == 0) return false;
}
}
-BOOL Char2InList(const char c, const char cc, const char* list)
+bool Char2InList(const char c, const char cc, const char* list)
{
int i = 0;
- while (TRUE)
+ while (true)
{
if (c == list[i++] &&
- cc == list[i++]) return TRUE;
+ cc == list[i++]) return true;
- if (list[i] == 0) return FALSE;
+ if (list[i] == 0) return false;
}
}
@@ -224,12 +225,12 @@ static char* nch = "\"\r\n\t"; // refusé dans les chaines
// cherche le prochain token dans une phrase
// ne doit pas commencer par des séparateurs
// qui sont pris avec le token précédent
-CBotToken* CBotToken::NextToken(char* &program, int& error, BOOL first)
+CBotToken* CBotToken::NextToken(char* &program, int& error, bool first)
{
CBotString mot; // le mot trouvé
CBotString sep; // les séparateurs qui le suivent
char c;
- BOOL stop = first;
+ bool stop = first;
if (*program == 0) return NULL;
@@ -262,14 +263,14 @@ CBotToken* CBotToken::NextToken(char* &program, int& error, BOOL first)
mot += c; // chaîne complète
c = *(program++); // prochain caractère
}
- stop = TRUE;
+ stop = true;
}
// cas particulier pour les nombres
if ( CharInList(mot[0], num ))
{
- BOOL bdot = FALSE; // trouvé un point ?
- BOOL bexp = FALSE; // trouvé un exposant ?
+ bool bdot = false; // trouvé un point ?
+ bool bexp = false; // trouvé un exposant ?
char* liste = num;
if (mot[0] == '0' && c == 'x') // valeur hexadécimale ?
@@ -286,10 +287,10 @@ cc: mot += c;
}
if ( liste == num ) // pas pour les exadécimaux
{
- if ( !bdot && c == '.' ) { bdot = TRUE; goto cc; }
+ if ( !bdot && c == '.' ) { bdot = true; goto cc; }
if ( !bexp && ( c == 'e' || c == 'E' ) )
{
- bexp = TRUE;
+ bexp = true;
mot += c;
c = *(program++); // prochain caractère
if ( c == '-' ||
@@ -298,7 +299,7 @@ cc: mot += c;
}
}
- stop = TRUE;
+ stop = true;
}
if (CharInList(mot[0], sep3)) // un séparateur opérationnel ?
@@ -310,13 +311,13 @@ cc: mot += c;
c = *(program++); // prochain caractère
}
- stop = TRUE;
+ stop = true;
}
}
- while (TRUE)
+ while (true)
{
if (stop || c == 0 || CharInList(c, sep1))
{
@@ -381,7 +382,7 @@ CBotToken* CBotToken::CompileTokens(const char* program, int& error)
int pos = 0;
error = 0;
- prv = tokenbase = NextToken(p, error, TRUE);
+ prv = tokenbase = NextToken(p, error, true);
if (tokenbase == NULL) return NULL;
@@ -443,7 +444,7 @@ int CBotToken::GivKeyWords(const char* w)
return -1;
}
-BOOL CBotToken::GivKeyDefNum(const char* w, CBotToken* &token)
+bool CBotToken::GivKeyDefNum(const char* w, CBotToken* &token)
{
int i;
int l = m_ListKeyDefine.GivSize();
@@ -454,15 +455,16 @@ BOOL CBotToken::GivKeyDefNum(const char* w, CBotToken* &token)
{
token->m_IdKeyWord = m_ListKeyNums[i];
token->m_type = TokenTypDef;
- return TRUE;
+ return true;
}
}
- return FALSE;
+ return false;
}
// reprend la liste des mots clefs dans les ressources
+/// \todo Fixme Figure out how this should work.
void CBotToken::LoadKeyWords()
{
CBotString s;
@@ -498,36 +500,36 @@ void CBotToken::LoadKeyWords()
}
}
-BOOL CBotToken::DefineNum(const char* name, long val)
+bool CBotToken::DefineNum(const char* name, long val)
{
int i;
int l = m_ListKeyDefine.GivSize();
for (i = 0; i < l; i++)
{
- if (m_ListKeyDefine[i] == name) return FALSE;
+ if (m_ListKeyDefine[i] == name) return false;
}
- if ( i == MAXDEFNUM ) return FALSE;
+ if ( i == MAXDEFNUM ) return false;
m_ListKeyDefine.Add( name );
m_ListKeyNums[i] = val;
- return TRUE;
+ return true;
}
-BOOL IsOfType(CBotToken* &p, int type1, int type2)
+bool IsOfType(CBotToken* &p, int type1, int type2)
{
if (p->GivType() == type1 ||
p->GivType() == type2 )
{
p = p->GivNext();
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
// idem avec un nombre indéfini d'arguments
// il faut mettre un zéro comme dernier argument
-BOOL IsOfTypeList(CBotToken* &p, int type1, ...)
+bool IsOfTypeList(CBotToken* &p, int type1, ...)
{
int i = type1;
int max = 20;
@@ -536,18 +538,18 @@ BOOL IsOfTypeList(CBotToken* &p, int type1, ...)
va_list marker;
va_start( marker, type1 ); /* Initialize variable arguments. */
- while (TRUE)
+ while (true)
{
if (type == i)
{
p = p->GivNext();
va_end( marker ); /* Reset variable arguments. */
- return TRUE;
+ return true;
}
if (--max == 0 || 0 == (i = va_arg( marker, int)))
{
va_end( marker ); /* Reset variable arguments. */
- return FALSE;
+ return false;
}
}
}
diff --git a/src/CBot/CBotToken.h b/src/CBot/CBotToken.h
index 2d92409..62e9bf3 100644
--- a/src/CBot/CBotToken.h
+++ b/src/CBot/CBotToken.h
@@ -33,5 +33,5 @@
// )
-extern BOOL IsOfType(CBotToken* &p, int type1, int type2 = -1);
-extern BOOL IsOfTypeList(CBotToken* &p, int type1, ...);
+extern bool IsOfType(CBotToken* &p, int type1, int type2 = -1);
+extern bool IsOfTypeList(CBotToken* &p, int type1, ...);
diff --git a/src/CBot/CBotTwoOpExpr.cpp b/src/CBot/CBotTwoOpExpr.cpp
index d8f4ee7..e2523b5 100644
--- a/src/CBot/CBotTwoOpExpr.cpp
+++ b/src/CBot/CBotTwoOpExpr.cpp
@@ -95,19 +95,19 @@ static int ListOp[] =
0,
};
-BOOL IsInList( int val, int* list, int& typemasque )
+bool IsInList( int val, int* list, int& typemasque )
{
- while (TRUE)
+ while (true)
{
- if ( *list == 0 ) return FALSE;
+ if ( *list == 0 ) return false;
typemasque = *list++;
- if ( *list++ == val ) return TRUE;
+ if ( *list++ == val ) return true;
}
}
-BOOL TypeOk( int type, int test )
+bool TypeOk( int type, int test )
{
- while (TRUE)
+ while (true)
{
if ( type == 0 ) return (test & 1);
type--; test /= 2;
@@ -279,43 +279,43 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
}
-BOOL IsNan(CBotVar* left, CBotVar* right, int* err = NULL)
+bool IsNan(CBotVar* left, CBotVar* right, int* err = NULL)
{
if ( left ->GivInit() > IS_DEF || right->GivInit() > IS_DEF )
{
if ( err != NULL ) *err = TX_OPNAN ;
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
// fait l'opération sur 2 opérandes
-BOOL CBotTwoOpExpr::Execute(CBotStack* &pStack)
+bool CBotTwoOpExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this); // ajoute un élément à la pile
// ou le retrouve en cas de reprise
-// if ( pStk1 == EOX ) return TRUE;
+// if ( pStk1 == EOX ) return true;
// selon la reprise, on peut être dans l'un des 2 états
if ( pStk1->GivState() == 0 ) // 1er état, évalue l'opérande de gauche
{
- if (!m_leftop->Execute(pStk1) ) return FALSE; // interrompu ici ?
+ if (!m_leftop->Execute(pStk1) ) return false; // interrompu ici ?
// pour les OU et ET logique, n'évalue pas la seconde expression si pas nécessaire
- if ( (GivTokenType() == ID_LOG_AND || GivTokenType() == ID_TXT_AND ) && pStk1->GivVal() == FALSE )
+ if ( (GivTokenType() == ID_LOG_AND || GivTokenType() == ID_TXT_AND ) && pStk1->GivVal() == false )
{
CBotVar* res = CBotVar::Create( (CBotToken*)NULL, CBotTypBoolean);
- res->SetValInt(FALSE);
+ res->SetValInt(false);
pStk1->SetVar(res);
return pStack->Return(pStk1); // transmet le résultat
}
- if ( (GivTokenType() == ID_LOG_OR||GivTokenType() == ID_TXT_OR) && pStk1->GivVal() == TRUE )
+ if ( (GivTokenType() == ID_LOG_OR||GivTokenType() == ID_TXT_OR) && pStk1->GivVal() == true )
{
CBotVar* res = CBotVar::Create( (CBotToken*)NULL, CBotTypBoolean);
- res->SetValInt(TRUE);
+ res->SetValInt(true);
pStk1->SetVar(res);
return pStack->Return(pStk1); // transmet le résultat
}
@@ -334,7 +334,7 @@ BOOL CBotTwoOpExpr::Execute(CBotStack* &pStack)
// 2e état, évalue l'opérande de droite
if ( pStk2->GivState() == 0 )
{
- if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrompu ici ?
+ if ( !m_rightop->Execute(pStk2) ) return false; // interrompu ici ?
pStk2->IncState();
}
@@ -342,7 +342,7 @@ BOOL CBotTwoOpExpr::Execute(CBotStack* &pStack)
CBotTypResult type2 = pStk2->GivTypResult();
CBotStack* pStk3 = pStk2->AddStack(this); // ajoute un élément à la pile
- if ( pStk3->IfStep() ) return FALSE; // montre l'opération si step by step
+ if ( pStk3->IfStep() ) return false; // montre l'opération si step by step
// crée une variable temporaire pour y mettre le résultat
// quel est le type du résultat ?
@@ -475,7 +475,7 @@ BOOL CBotTwoOpExpr::Execute(CBotStack* &pStack)
return pStack->Return(pStk2); // transmet le résultat
}
-void CBotTwoOpExpr::RestoreState(CBotStack* &pStack, BOOL bMain)
+void CBotTwoOpExpr::RestoreState(CBotStack* &pStack, bool bMain)
{
if ( !bMain ) return;
CBotStack* pStk1 = pStack->RestoreStack(this); // ajoute un élément à la pile
@@ -501,31 +501,31 @@ void CBotTwoOpExpr::RestoreState(CBotStack* &pStack, BOOL bMain)
}
-BOOL CBotLogicExpr::Execute(CBotStack* &pStack)
+bool CBotLogicExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this); // ajoute un élément à la pile
// ou le retrouve en cas de reprise
-// if ( pStk1 == EOX ) return TRUE;
+// if ( pStk1 == EOX ) return true;
if ( pStk1->GivState() == 0 )
{
- if ( !m_condition->Execute(pStk1) ) return FALSE;
- if (!pStk1->SetState(1)) return FALSE;
+ if ( !m_condition->Execute(pStk1) ) return false;
+ if (!pStk1->SetState(1)) return false;
}
- if ( pStk1->GivVal() == TRUE )
+ if ( pStk1->GivVal() == true )
{
- if ( !m_op1->Execute(pStk1) ) return FALSE;
+ if ( !m_op1->Execute(pStk1) ) return false;
}
else
{
- if ( !m_op2->Execute(pStk1) ) return FALSE;
+ if ( !m_op2->Execute(pStk1) ) return false;
}
return pStack->Return(pStk1); // transmet le résultat
}
-void CBotLogicExpr::RestoreState(CBotStack* &pStack, BOOL bMain)
+void CBotLogicExpr::RestoreState(CBotStack* &pStack, bool bMain)
{
if ( !bMain ) return;
@@ -538,7 +538,7 @@ void CBotLogicExpr::RestoreState(CBotStack* &pStack, BOOL bMain)
return;
}
- if ( pStk1->GivVal() == TRUE )
+ if ( pStk1->GivVal() == true )
{
m_op1->RestoreState(pStk1, bMain);
}
@@ -557,7 +557,7 @@ void t()
#endif
#if 01
-void t(BOOL t)
+void t(bool t)
{
int x;
x = 1 + t ? 1 : 3 + 4 * 2 ;
diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp
index 37c8fb4..9070298 100644
--- a/src/CBot/CBotVar.cpp
+++ b/src/CBot/CBotVar.cpp
@@ -27,80 +27,80 @@ long CBotVar::m_identcpt = 0;
CBotVar::CBotVar( )
{
- m_next = NULL;
- m_pMyThis = NULL;
- m_pUserPtr = NULL;
- m_InitExpr = NULL;
- m_LimExpr = NULL;
- m_type = -1;
- m_binit = FALSE;
- m_ident = 0;
- m_bStatic = FALSE;
- m_mPrivate = 0;
+ m_next = NULL;
+ m_pMyThis = NULL;
+ m_pUserPtr = NULL;
+ m_InitExpr = NULL;
+ m_LimExpr = NULL;
+ m_type = -1;
+ m_binit = false;
+ m_ident = 0;
+ m_bStatic = false;
+ m_mPrivate = 0;
}
CBotVarInt::CBotVarInt( const CBotToken* name )
{
- m_token = new CBotToken(name);
- m_next = NULL;
- m_pMyThis = NULL;
- m_pUserPtr = NULL;
- m_InitExpr = NULL;
- m_LimExpr = NULL;
- m_type = CBotTypInt;
- m_binit = FALSE;
- m_bStatic = FALSE;
- m_mPrivate = 0;
+ m_token = new CBotToken(name);
+ m_next = NULL;
+ m_pMyThis = NULL;
+ m_pUserPtr = NULL;
+ m_InitExpr = NULL;
+ m_LimExpr = NULL;
+ m_type = CBotTypInt;
+ m_binit = false;
+ m_bStatic = false;
+ m_mPrivate = 0;
- m_val = 0;
+ m_val = 0;
}
CBotVarFloat::CBotVarFloat( const CBotToken* name )
{
- m_token = new CBotToken(name);
- m_next = NULL;
- m_pMyThis = NULL;
- m_pUserPtr = NULL;
- m_InitExpr = NULL;
- m_LimExpr = NULL;
- m_type = CBotTypFloat;
- m_binit = FALSE;
- m_bStatic = FALSE;
- m_mPrivate = 0;
+ m_token = new CBotToken(name);
+ m_next = NULL;
+ m_pMyThis = NULL;
+ m_pUserPtr = NULL;
+ m_InitExpr = NULL;
+ m_LimExpr = NULL;
+ m_type = CBotTypFloat;
+ m_binit = false;
+ m_bStatic = false;
+ m_mPrivate = 0;
- m_val = 0;
+ m_val = 0;
}
CBotVarString::CBotVarString( const CBotToken* name )
{
- m_token = new CBotToken(name);
- m_next = NULL;
- m_pMyThis = NULL;
- m_pUserPtr = NULL;
- m_InitExpr = NULL;
- m_LimExpr = NULL;
- m_type = CBotTypString;
- m_binit = FALSE;
- m_bStatic = FALSE;
- m_mPrivate = 0;
+ m_token = new CBotToken(name);
+ m_next = NULL;
+ m_pMyThis = NULL;
+ m_pUserPtr = NULL;
+ m_InitExpr = NULL;
+ m_LimExpr = NULL;
+ m_type = CBotTypString;
+ m_binit = false;
+ m_bStatic = false;
+ m_mPrivate = 0;
- m_val.Empty();
+ m_val.Empty();
}
CBotVarBoolean::CBotVarBoolean( const CBotToken* name )
{
- m_token = new CBotToken(name);
- m_next = NULL;
- m_pMyThis = NULL;
- m_pUserPtr = NULL;
- m_InitExpr = NULL;
- m_LimExpr = NULL;
- m_type = CBotTypBoolean;
- m_binit = FALSE;
- m_bStatic = FALSE;
- m_mPrivate = 0;
+ m_token = new CBotToken(name);
+ m_next = NULL;
+ m_pMyThis = NULL;
+ m_pUserPtr = NULL;
+ m_InitExpr = NULL;
+ m_LimExpr = NULL;
+ m_type = CBotTypBoolean;
+ m_binit = false;
+ m_bStatic = false;
+ m_mPrivate = 0;
- m_val = 0;
+ m_val = 0;
}
CBotVarClass* CBotVarClass::m_ExClass = NULL;
@@ -108,171 +108,171 @@ CBotVarClass* CBotVarClass::m_ExClass = NULL;
CBotVarClass::CBotVarClass( const CBotToken* name, const CBotTypResult& type)
{
/*
-// int nIdent = 0;
- InitCBotVarClass( name, type ) //, nIdent );
+// int nIdent = 0;
+ InitCBotVarClass( name, type ) //, nIdent );
}
CBotVarClass::CBotVarClass( const CBotToken* name, CBotTypResult& type) //, int &nIdent )
{
- InitCBotVarClass( name, type ); //, nIdent );
+ InitCBotVarClass( name, type ); //, nIdent );
}
void CBotVarClass::InitCBotVarClass( const CBotToken* name, CBotTypResult& type ) //, int &nIdent )
{*/
- if ( !type.Eq(CBotTypClass) &&
- !type.Eq(CBotTypIntrinsic) && // par comodité accepte ces types
- !type.Eq(CBotTypPointer) &&
- !type.Eq(CBotTypArrayPointer) &&
- !type.Eq(CBotTypArrayBody)) ASM_TRAP();
-
- m_token = new CBotToken(name);
- m_next = NULL;
- m_pMyThis = NULL;
- m_pUserPtr = OBJECTCREATED;//NULL;
- m_InitExpr = NULL;
- m_LimExpr = NULL;
- m_pVar = NULL;
- m_type = type;
- if ( type.Eq(CBotTypArrayPointer) ) m_type.SetType( CBotTypArrayBody );
- else if ( !type.Eq(CBotTypArrayBody) ) m_type.SetType( CBotTypClass );
- // type officel pour cet object
-
- m_pClass = NULL;
- m_pParent = NULL;
- m_binit = FALSE;
- m_bStatic = FALSE;
- m_mPrivate = 0;
- m_bConstructor = FALSE;
- m_CptUse = 0;
- m_ItemIdent = type.Eq(CBotTypIntrinsic) ? 0 : CBotVar::NextUniqNum();
-
- // se place tout seul dans la liste
- if (m_ExClass) m_ExClass->m_ExPrev = this;
- m_ExNext = m_ExClass;
- m_ExPrev = NULL;
- m_ExClass = this;
-
- CBotClass* pClass = type.GivClass();
- CBotClass* pClass2 = pClass->GivParent();
- if ( pClass2 != NULL )
- {
- // crée également une instance dans la classe père
- m_pParent = new CBotVarClass(name, CBotTypResult(type.GivType(),pClass2) ); //, nIdent);
- }
-
- SetClass( pClass ); //, nIdent );
+ if ( !type.Eq(CBotTypClass) &&
+ !type.Eq(CBotTypIntrinsic) && // par comodité accepte ces types
+ !type.Eq(CBotTypPointer) &&
+ !type.Eq(CBotTypArrayPointer) &&
+ !type.Eq(CBotTypArrayBody)) ASM_TRAP();
+
+ m_token = new CBotToken(name);
+ m_next = NULL;
+ m_pMyThis = NULL;
+ m_pUserPtr = OBJECTCREATED;//NULL;
+ m_InitExpr = NULL;
+ m_LimExpr = NULL;
+ m_pVar = NULL;
+ m_type = type;
+ if ( type.Eq(CBotTypArrayPointer) ) m_type.SetType( CBotTypArrayBody );
+ else if ( !type.Eq(CBotTypArrayBody) ) m_type.SetType( CBotTypClass );
+ // type officel pour cet object
+
+ m_pClass = NULL;
+ m_pParent = NULL;
+ m_binit = false;
+ m_bStatic = false;
+ m_mPrivate = 0;
+ m_bConstructor = false;
+ m_CptUse = 0;
+ m_ItemIdent = type.Eq(CBotTypIntrinsic) ? 0 : CBotVar::NextUniqNum();
+
+ // se place tout seul dans la liste
+ if (m_ExClass) m_ExClass->m_ExPrev = this;
+ m_ExNext = m_ExClass;
+ m_ExPrev = NULL;
+ m_ExClass = this;
+
+ CBotClass* pClass = type.GivClass();
+ CBotClass* pClass2 = pClass->GivParent();
+ if ( pClass2 != NULL )
+ {
+ // crée également une instance dans la classe père
+ m_pParent = new CBotVarClass(name, CBotTypResult(type.GivType(),pClass2) ); //, nIdent);
+ }
+
+ SetClass( pClass ); //, nIdent );
}
CBotVarClass::~CBotVarClass( )
{
- if ( m_CptUse != 0 )
- ASM_TRAP();
+ if ( m_CptUse != 0 )
+ ASM_TRAP();
- if ( m_pParent ) delete m_pParent;
- m_pParent = NULL;
+ if ( m_pParent ) delete m_pParent;
+ m_pParent = NULL;
- // libère l'objet indirect s'il y a lieu
-// if ( m_Indirect != NULL )
-// m_Indirect->DecrementUse();
+ // libère l'objet indirect s'il y a lieu
+// if ( m_Indirect != NULL )
+// m_Indirect->DecrementUse();
- // retire la classe de la liste
- if ( m_ExPrev ) m_ExPrev->m_ExNext = m_ExNext;
- else m_ExClass = m_ExNext;
+ // retire la classe de la liste
+ if ( m_ExPrev ) m_ExPrev->m_ExNext = m_ExNext;
+ else m_ExClass = m_ExNext;
- if ( m_ExNext ) m_ExNext->m_ExPrev = m_ExPrev;
- m_ExPrev = NULL;
- m_ExNext = NULL;
+ if ( m_ExNext ) m_ExNext->m_ExPrev = m_ExPrev;
+ m_ExPrev = NULL;
+ m_ExNext = NULL;
- delete m_pVar;
+ delete m_pVar;
}
void CBotVarClass::ConstructorSet()
{
- m_bConstructor = TRUE;
+ m_bConstructor = true;
}
CBotVar::~CBotVar( )
{
- delete m_token;
- delete m_next;
+ delete m_token;
+ delete m_next;
}
void CBotVar::debug()
{
- const char* p = (LPCTSTR) m_token->GivString();
- CBotString s = (LPCTSTR) GivValString();
- const char* v = (LPCTSTR) s;
+ const char* p = (const char*) m_token->GivString();
+ CBotString s = (const char*) GivValString();
+ const char* v = (const char*) s;
- if ( m_type.Eq(CBotTypClass) )
- {
- CBotVar* pv = ((CBotVarClass*)this)->m_pVar;
- while (pv != NULL)
- {
- pv->debug();
- pv = pv->GivNext();
- }
- }
+ if ( m_type.Eq(CBotTypClass) )
+ {
+ CBotVar* pv = ((CBotVarClass*)this)->m_pVar;
+ while (pv != NULL)
+ {
+ pv->debug();
+ pv = pv->GivNext();
+ }
+ }
}
void CBotVar::ConstructorSet()
{
- // nop
+ // nop
}
void CBotVar::SetUserPtr(void* pUser)
{
- m_pUserPtr = pUser;
- if (m_type.Eq(CBotTypPointer) &&
- ((CBotVarPointer*)this)->m_pVarClass != NULL )
- ((CBotVarPointer*)this)->m_pVarClass->SetUserPtr(pUser);
+ m_pUserPtr = pUser;
+ if (m_type.Eq(CBotTypPointer) &&
+ ((CBotVarPointer*)this)->m_pVarClass != NULL )
+ ((CBotVarPointer*)this)->m_pVarClass->SetUserPtr(pUser);
}
void CBotVar::SetIdent(long n)
{
- if (m_type.Eq(CBotTypPointer) &&
- ((CBotVarPointer*)this)->m_pVarClass != NULL )
- ((CBotVarPointer*)this)->m_pVarClass->SetIdent(n);
+ if (m_type.Eq(CBotTypPointer) &&
+ ((CBotVarPointer*)this)->m_pVarClass != NULL )
+ ((CBotVarPointer*)this)->m_pVarClass->SetIdent(n);
}
void CBotVar::SetUniqNum(long n)
{
- m_ident = n;
+ m_ident = n;
- if ( n == 0 ) ASM_TRAP();
+ if ( n == 0 ) ASM_TRAP();
}
long CBotVar::NextUniqNum()
{
- if (++m_identcpt < 10000) m_identcpt = 10000;
- return m_identcpt;
+ if (++m_identcpt < 10000) m_identcpt = 10000;
+ return m_identcpt;
}
long CBotVar::GivUniqNum()
{
- return m_ident;
+ return m_ident;
}
void* CBotVar::GivUserPtr()
{
- return m_pUserPtr;
+ return m_pUserPtr;
}
-BOOL CBotVar::Save1State(FILE* pf)
+bool CBotVar::Save1State(FILE* pf)
{
- // cette routine "virtual" ne doit jamais être appellée,
- // il doit y avoir une routine pour chaque classe fille (CBotVarInt, CBotVarFloat, etc)
- // ( voir le type dans m_type )
- ASM_TRAP();
- return FALSE;
+ // cette routine "virtual" ne doit jamais être appellée,
+ // il doit y avoir une routine pour chaque classe fille (CBotVarInt, CBotVarFloat, etc)
+ // ( voir le type dans m_type )
+ ASM_TRAP();
+ return false;
}
-void CBotVar::Maj(void* pUser, BOOL bContinu)
+void CBotVar::Maj(void* pUser, bool bContinu)
{
-/* if (!bContinu && m_pMyThis != NULL)
- m_pMyThis->Maj(pUser, TRUE);*/
+/* if (!bContinu && m_pMyThis != NULL)
+ m_pMyThis->Maj(pUser, true);*/
}
@@ -280,382 +280,382 @@ void CBotVar::Maj(void* pUser, BOOL bContinu)
CBotVar* CBotVar::Create(const CBotToken* name, int type )
{
- CBotTypResult t(type);
- return Create(name, t);
+ CBotTypResult t(type);
+ return Create(name, t);
}
CBotVar* CBotVar::Create(const CBotToken* name, CBotTypResult type)
{
- switch (type.GivType())
- {
- case CBotTypShort:
- case CBotTypInt:
- return new CBotVarInt(name);
- case CBotTypFloat:
- return new CBotVarFloat(name);
- case CBotTypBoolean:
- return new CBotVarBoolean(name);
- case CBotTypString:
- return new CBotVarString(name);
- case CBotTypPointer:
- case CBotTypNullPointer:
- return new CBotVarPointer(name, type);
- case CBotTypIntrinsic:
- return new CBotVarClass(name, type);
-
- case CBotTypClass:
- // crée une nouvelle instance d'une classe
- // et retourne le POINTER sur cette instance
- {
- CBotVarClass* instance = new CBotVarClass(name, type);
- CBotVarPointer* pointer = new CBotVarPointer(name, type);
- pointer->SetPointer( instance );
- return pointer;
- }
-
- case CBotTypArrayPointer:
- return new CBotVarArray(name, type);
-
- case CBotTypArrayBody:
- {
- CBotVarClass* instance = new CBotVarClass(name, type);
- CBotVarArray* array = new CBotVarArray(name, type);
- array->SetPointer( instance );
-
- CBotVar* pv = array;
- while (type.Eq(CBotTypArrayBody))
- {
- type = type.GivTypElem();
- pv = ((CBotVarArray*)pv)->GivItem(0, TRUE); // crée au moins l'élément [0]
- }
-
- return array;
- }
- }
-
- ASM_TRAP();
- return NULL;
+ switch (type.GivType())
+ {
+ case CBotTypShort:
+ case CBotTypInt:
+ return new CBotVarInt(name);
+ case CBotTypFloat:
+ return new CBotVarFloat(name);
+ case CBotTypBoolean:
+ return new CBotVarBoolean(name);
+ case CBotTypString:
+ return new CBotVarString(name);
+ case CBotTypPointer:
+ case CBotTypNullPointer:
+ return new CBotVarPointer(name, type);
+ case CBotTypIntrinsic:
+ return new CBotVarClass(name, type);
+
+ case CBotTypClass:
+ // crée une nouvelle instance d'une classe
+ // et retourne le POINTER sur cette instance
+ {
+ CBotVarClass* instance = new CBotVarClass(name, type);
+ CBotVarPointer* pointer = new CBotVarPointer(name, type);
+ pointer->SetPointer( instance );
+ return pointer;
+ }
+
+ case CBotTypArrayPointer:
+ return new CBotVarArray(name, type);
+
+ case CBotTypArrayBody:
+ {
+ CBotVarClass* instance = new CBotVarClass(name, type);
+ CBotVarArray* array = new CBotVarArray(name, type);
+ array->SetPointer( instance );
+
+ CBotVar* pv = array;
+ while (type.Eq(CBotTypArrayBody))
+ {
+ type = type.GivTypElem();
+ pv = ((CBotVarArray*)pv)->GivItem(0, true); // crée au moins l'élément [0]
+ }
+
+ return array;
+ }
+ }
+
+ ASM_TRAP();
+ return NULL;
}
CBotVar* CBotVar::Create( CBotVar* pVar )
{
- CBotVar* p = Create(pVar->m_token->GivString(), pVar->GivTypResult(2));
- return p;
+ CBotVar* p = Create(pVar->m_token->GivString(), pVar->GivTypResult(2));
+ return p;
}
CBotVar* CBotVar::Create( const char* n, CBotTypResult type)
{
- CBotToken name(n);
-
- switch (type.GivType())
- {
- case CBotTypShort:
- case CBotTypInt:
- return new CBotVarInt(&name);
- case CBotTypFloat:
- return new CBotVarFloat(&name);
- case CBotTypBoolean:
- return new CBotVarBoolean(&name);
- case CBotTypString:
- return new CBotVarString(&name);
- case CBotTypPointer:
- case CBotTypNullPointer:
- {
- CBotVarPointer* p = new CBotVarPointer(&name, type);
-// p->SetClass(type.GivClass());
- return p;
- }
- case CBotTypIntrinsic:
- {
- CBotVarClass* p = new CBotVarClass(&name, type);
-// p->SetClass(type.GivClass());
- return p;
- }
-
- case CBotTypClass:
- // crée une nouvelle instance d'une classe
- // et retourne le POINTER sur cette instance
- {
- CBotVarClass* instance = new CBotVarClass(&name, type);
- CBotVarPointer* pointer = new CBotVarPointer(&name, type);
- pointer->SetPointer( instance );
-// pointer->SetClass( type.GivClass() );
- return pointer;
- }
-
- case CBotTypArrayPointer:
- return new CBotVarArray(&name, type);
-
- case CBotTypArrayBody:
- {
- CBotVarClass* instance = new CBotVarClass(&name, type);
- CBotVarArray* array = new CBotVarArray(&name, type);
- array->SetPointer( instance );
-
- CBotVar* pv = array;
- while (type.Eq(CBotTypArrayBody))
- {
- type = type.GivTypElem();
- pv = ((CBotVarArray*)pv)->GivItem(0, TRUE); // crée au moins l'élément [0]
- }
-
- return array;
- }
- }
-
- ASM_TRAP();
- return NULL;
+ CBotToken name(n);
+
+ switch (type.GivType())
+ {
+ case CBotTypShort:
+ case CBotTypInt:
+ return new CBotVarInt(&name);
+ case CBotTypFloat:
+ return new CBotVarFloat(&name);
+ case CBotTypBoolean:
+ return new CBotVarBoolean(&name);
+ case CBotTypString:
+ return new CBotVarString(&name);
+ case CBotTypPointer:
+ case CBotTypNullPointer:
+ {
+ CBotVarPointer* p = new CBotVarPointer(&name, type);
+// p->SetClass(type.GivClass());
+ return p;
+ }
+ case CBotTypIntrinsic:
+ {
+ CBotVarClass* p = new CBotVarClass(&name, type);
+// p->SetClass(type.GivClass());
+ return p;
+ }
+
+ case CBotTypClass:
+ // crée une nouvelle instance d'une classe
+ // et retourne le POINTER sur cette instance
+ {
+ CBotVarClass* instance = new CBotVarClass(&name, type);
+ CBotVarPointer* pointer = new CBotVarPointer(&name, type);
+ pointer->SetPointer( instance );
+// pointer->SetClass( type.GivClass() );
+ return pointer;
+ }
+
+ case CBotTypArrayPointer:
+ return new CBotVarArray(&name, type);
+
+ case CBotTypArrayBody:
+ {
+ CBotVarClass* instance = new CBotVarClass(&name, type);
+ CBotVarArray* array = new CBotVarArray(&name, type);
+ array->SetPointer( instance );
+
+ CBotVar* pv = array;
+ while (type.Eq(CBotTypArrayBody))
+ {
+ type = type.GivTypElem();
+ pv = ((CBotVarArray*)pv)->GivItem(0, true); // crée au moins l'élément [0]
+ }
+
+ return array;
+ }
+ }
+
+ ASM_TRAP();
+ return NULL;
}
CBotVar* CBotVar::Create( const char* name, int type, CBotClass* pClass)
{
- CBotToken token( name, "" );
- CBotVar* pVar = Create( &token, type );
-
- if ( type == CBotTypPointer && pClass == NULL ) // pointeur "null" ?
- return pVar;
-
- if ( type == CBotTypClass || type == CBotTypPointer ||
- type == CBotTypIntrinsic )
- {
- if (pClass == NULL)
- {
- delete pVar;
- return NULL;
- }
- pVar->SetClass( pClass );
- }
- return pVar;
+ CBotToken token( name, "" );
+ CBotVar* pVar = Create( &token, type );
+
+ if ( type == CBotTypPointer && pClass == NULL ) // pointeur "null" ?
+ return pVar;
+
+ if ( type == CBotTypClass || type == CBotTypPointer ||
+ type == CBotTypIntrinsic )
+ {
+ if (pClass == NULL)
+ {
+ delete pVar;
+ return NULL;
+ }
+ pVar->SetClass( pClass );
+ }
+ return pVar;
}
CBotVar* CBotVar::Create( const char* name, CBotClass* pClass)
{
- CBotToken token( name, "" );
- CBotVar* pVar = Create( &token, CBotTypResult( CBotTypClass, pClass ) );
-// pVar->SetClass( pClass );
- return pVar;
+ CBotToken token( name, "" );
+ CBotVar* pVar = Create( &token, CBotTypResult( CBotTypClass, pClass ) );
+// pVar->SetClass( pClass );
+ return pVar;
}
CBotTypResult CBotVar::GivTypResult(int mode)
{
- CBotTypResult r = m_type;
+ CBotTypResult r = m_type;
- if ( mode == 1 && m_type.Eq(CBotTypClass) )
- r.SetType(CBotTypPointer);
- if ( mode == 2 && m_type.Eq(CBotTypClass) )
- r.SetType(CBotTypIntrinsic);
+ if ( mode == 1 && m_type.Eq(CBotTypClass) )
+ r.SetType(CBotTypPointer);
+ if ( mode == 2 && m_type.Eq(CBotTypClass) )
+ r.SetType(CBotTypIntrinsic);
- return r;
+ return r;
}
int CBotVar::GivType(int mode)
{
- if ( mode == 1 && m_type.Eq(CBotTypClass) )
- return CBotTypPointer;
- if ( mode == 2 && m_type.Eq(CBotTypClass) )
- return CBotTypIntrinsic;
- return m_type.GivType();
+ if ( mode == 1 && m_type.Eq(CBotTypClass) )
+ return CBotTypPointer;
+ if ( mode == 2 && m_type.Eq(CBotTypClass) )
+ return CBotTypIntrinsic;
+ return m_type.GivType();
}
void CBotVar::SetType(CBotTypResult& type)
{
- m_type = type;
+ m_type = type;
}
int CBotVar::GivInit()
{
- if ( m_type.Eq(CBotTypClass) ) return IS_DEF; // toujours défini !
+ if ( m_type.Eq(CBotTypClass) ) return IS_DEF; // toujours défini !
- return m_binit;
+ return m_binit;
}
-void CBotVar::SetInit(BOOL bInit)
+void CBotVar::SetInit(int bInit)
{
- m_binit = bInit;
- if ( bInit == 2 ) m_binit = IS_DEF; // cas spécial
+ m_binit = bInit;
+ if ( bInit == 2 ) m_binit = IS_DEF; // cas spécial
- if ( m_type.Eq(CBotTypPointer) && bInit == 2 )
- {
- CBotVarClass* instance = GivPointer();
- if ( instance == NULL )
- {
- instance = new CBotVarClass(NULL, m_type);
-// instance->SetClass(((CBotVarPointer*)this)->m_pClass);
- SetPointer(instance);
- }
- instance->SetInit(1);
- }
+ if ( m_type.Eq(CBotTypPointer) && bInit == 2 )
+ {
+ CBotVarClass* instance = GivPointer();
+ if ( instance == NULL )
+ {
+ instance = new CBotVarClass(NULL, m_type);
+// instance->SetClass(((CBotVarPointer*)this)->m_pClass);
+ SetPointer(instance);
+ }
+ instance->SetInit(1);
+ }
- if ( m_type.Eq(CBotTypClass) || m_type.Eq(CBotTypIntrinsic) )
- {
- CBotVar* p = ((CBotVarClass*)this)->m_pVar;
- while( p != NULL )
- {
- p->SetInit( bInit );
- p->m_pMyThis = (CBotVarClass*)this;
- p = p->GivNext();
- }
- }
+ if ( m_type.Eq(CBotTypClass) || m_type.Eq(CBotTypIntrinsic) )
+ {
+ CBotVar* p = ((CBotVarClass*)this)->m_pVar;
+ while( p != NULL )
+ {
+ p->SetInit( bInit );
+ p->m_pMyThis = (CBotVarClass*)this;
+ p = p->GivNext();
+ }
+ }
}
CBotString CBotVar::GivName()
{
- return m_token->GivString();
+ return m_token->GivString();
}
void CBotVar::SetName(const char* name)
{
- m_token->SetString(name);
+ m_token->SetString(name);
}
CBotToken* CBotVar::GivToken()
{
- return m_token;
+ return m_token;
}
CBotVar* CBotVar::GivItem(const char* name)
{
- ASM_TRAP();
- return NULL;
+ ASM_TRAP();
+ return NULL;
}
CBotVar* CBotVar::GivItemRef(int nIdent)
{
- ASM_TRAP();
- return NULL;
+ ASM_TRAP();
+ return NULL;
}
CBotVar* CBotVar::GivItemList()
{
- ASM_TRAP();
- return NULL;
+ ASM_TRAP();
+ return NULL;
}
-CBotVar* CBotVar::GivItem(int row, BOOL bGrow)
+CBotVar* CBotVar::GivItem(int row, bool bGrow)
{
- ASM_TRAP();
- return NULL;
+ ASM_TRAP();
+ return NULL;
}
// dit si une variable appartient à une classe donnée
-BOOL CBotVar::IsElemOfClass(const char* name)
+bool CBotVar::IsElemOfClass(const char* name)
{
- CBotClass* pc = NULL;
+ CBotClass* pc = NULL;
- if ( m_type.Eq(CBotTypPointer) )
- {
- pc = ((CBotVarPointer*)this)->m_pClass;
- }
- if ( m_type.Eq(CBotTypClass) )
- {
- pc = ((CBotVarClass*)this)->m_pClass;
- }
+ if ( m_type.Eq(CBotTypPointer) )
+ {
+ pc = ((CBotVarPointer*)this)->m_pClass;
+ }
+ if ( m_type.Eq(CBotTypClass) )
+ {
+ pc = ((CBotVarClass*)this)->m_pClass;
+ }
- while ( pc != NULL )
- {
- if ( pc->GivName() == name ) return TRUE;
- pc = pc->GivParent();
- }
+ while ( pc != NULL )
+ {
+ if ( pc->GivName() == name ) return true;
+ pc = pc->GivParent();
+ }
- return FALSE;
+ return false;
}
CBotVar* CBotVar::GivStaticVar()
{
- // rend le pointeur à la variable si elle est statique
- if ( m_bStatic == 0 || m_pMyThis == NULL ) return this;
+ // rend le pointeur à la variable si elle est statique
+ if ( m_bStatic == 0 || m_pMyThis == NULL ) return this;
- CBotClass* pClass = m_pMyThis->GivClass();
- return pClass->GivItem( m_token->GivString() );
+ CBotClass* pClass = m_pMyThis->GivClass();
+ return pClass->GivItem( m_token->GivString() );
}
CBotVar* CBotVar::GivNext()
{
- return m_next;
+ return m_next;
}
void CBotVar::AddNext(CBotVar* pVar)
{
- CBotVar* p = this;
- while (p->m_next != NULL) p = p->m_next;
+ CBotVar* p = this;
+ while (p->m_next != NULL) p = p->m_next;
- p->m_next = pVar;
+ p->m_next = pVar;
}
void CBotVar::SetVal(CBotVar* var)
{
- switch (/*var->*/GivType())
- {
- case CBotTypBoolean:
- SetValInt(var->GivValInt());
- break;
- case CBotTypInt:
- SetValInt(var->GivValInt(), ((CBotVarInt*)var)->m_defnum);
- break;
- case CBotTypFloat:
- SetValFloat(var->GivValFloat());
- break;
- case CBotTypString:
- SetValString(var->GivValString());
- break;
- case CBotTypPointer:
- case CBotTypNullPointer:
- case CBotTypArrayPointer:
- SetPointer(var->GivPointer());
- break;
- case CBotTypClass:
- {
- delete ((CBotVarClass*)this)->m_pVar;
- ((CBotVarClass*)this)->m_pVar = NULL;
- Copy(var, FALSE);
- }
- break;
- default:
- ASM_TRAP();
- }
-
- m_binit = var->m_binit; // copie l'état nan s'il y a
-}
-
-void CBotVar::SetStatic(BOOL bStatic)
-{
- m_bStatic = bStatic;
+ switch (/*var->*/GivType())
+ {
+ case CBotTypBoolean:
+ SetValInt(var->GivValInt());
+ break;
+ case CBotTypInt:
+ SetValInt(var->GivValInt(), ((CBotVarInt*)var)->m_defnum);
+ break;
+ case CBotTypFloat:
+ SetValFloat(var->GivValFloat());
+ break;
+ case CBotTypString:
+ SetValString(var->GivValString());
+ break;
+ case CBotTypPointer:
+ case CBotTypNullPointer:
+ case CBotTypArrayPointer:
+ SetPointer(var->GivPointer());
+ break;
+ case CBotTypClass:
+ {
+ delete ((CBotVarClass*)this)->m_pVar;
+ ((CBotVarClass*)this)->m_pVar = NULL;
+ Copy(var, false);
+ }
+ break;
+ default:
+ ASM_TRAP();
+ }
+
+ m_binit = var->m_binit; // copie l'état nan s'il y a
+}
+
+void CBotVar::SetStatic(bool bStatic)
+{
+ m_bStatic = bStatic;
}
void CBotVar::SetPrivate(int mPrivate)
{
- m_mPrivate = mPrivate;
+ m_mPrivate = mPrivate;
}
-BOOL CBotVar::IsStatic()
+bool CBotVar::IsStatic()
{
- return m_bStatic;
+ return m_bStatic;
}
-BOOL CBotVar::IsPrivate(int mode)
+bool CBotVar::IsPrivate(int mode)
{
- return m_mPrivate >= mode;
+ return m_mPrivate >= mode;
}
int CBotVar::GivPrivate()
{
- return m_mPrivate;
+ return m_mPrivate;
}
void CBotVar::SetPointer(CBotVar* pVarClass)
{
- ASM_TRAP();
+ ASM_TRAP();
}
CBotVarClass* CBotVar::GivPointer()
{
- ASM_TRAP();
- return NULL;
+ ASM_TRAP();
+ return NULL;
}
// toutes ces fonctions doivent être définies dans les classes filles
@@ -663,195 +663,195 @@ CBotVarClass* CBotVar::GivPointer()
int CBotVar::GivValInt()
{
- ASM_TRAP();
- return 0;
+ ASM_TRAP();
+ return 0;
}
float CBotVar::GivValFloat()
{
- ASM_TRAP();
- return 0;
+ ASM_TRAP();
+ return 0;
}
void CBotVar::SetValInt(int c, const char* s)
{
- ASM_TRAP();
+ ASM_TRAP();
}
void CBotVar::SetValFloat(float c)
{
- ASM_TRAP();
+ ASM_TRAP();
}
void CBotVar::Mul(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
+ ASM_TRAP();
}
void CBotVar::Power(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
+ ASM_TRAP();
}
int CBotVar::Div(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
- return 0;
+ ASM_TRAP();
+ return 0;
}
int CBotVar::Modulo(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
- return 0;
+ ASM_TRAP();
+ return 0;
}
void CBotVar::Add(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
+ ASM_TRAP();
}
void CBotVar::Sub(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
+ ASM_TRAP();
}
-BOOL CBotVar::Lo(CBotVar* left, CBotVar* right)
+bool CBotVar::Lo(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
- return FALSE;
+ ASM_TRAP();
+ return false;
}
-BOOL CBotVar::Hi(CBotVar* left, CBotVar* right)
+bool CBotVar::Hi(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
- return FALSE;
+ ASM_TRAP();
+ return false;
}
-BOOL CBotVar::Ls(CBotVar* left, CBotVar* right)
+bool CBotVar::Ls(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
- return FALSE;
+ ASM_TRAP();
+ return false;
}
-BOOL CBotVar::Hs(CBotVar* left, CBotVar* right)
+bool CBotVar::Hs(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
- return FALSE;
+ ASM_TRAP();
+ return false;
}
-BOOL CBotVar::Eq(CBotVar* left, CBotVar* right)
+bool CBotVar::Eq(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
- return FALSE;
+ ASM_TRAP();
+ return false;
}
-BOOL CBotVar::Ne(CBotVar* left, CBotVar* right)
+bool CBotVar::Ne(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
- return FALSE;
+ ASM_TRAP();
+ return false;
}
void CBotVar::And(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
+ ASM_TRAP();
}
void CBotVar::Or(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
+ ASM_TRAP();
}
void CBotVar::XOr(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
+ ASM_TRAP();
}
void CBotVar::ASR(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
+ ASM_TRAP();
}
void CBotVar::SR(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
+ ASM_TRAP();
}
void CBotVar::SL(CBotVar* left, CBotVar* right)
{
- ASM_TRAP();
+ ASM_TRAP();
}
void CBotVar::Neg()
{
- ASM_TRAP();
+ ASM_TRAP();
}
void CBotVar::Not()
{
- ASM_TRAP();
+ ASM_TRAP();
}
void CBotVar::Inc()
{
- ASM_TRAP();
+ ASM_TRAP();
}
void CBotVar::Dec()
{
- ASM_TRAP();
+ ASM_TRAP();
}
-void CBotVar::Copy(CBotVar* pSrc, BOOL bName)
+void CBotVar::Copy(CBotVar* pSrc, bool bName)
{
- ASM_TRAP();
+ ASM_TRAP();
}
void CBotVar::SetValString(const char* p)
{
- ASM_TRAP();
+ ASM_TRAP();
}
CBotString CBotVar::GivValString()
{
- ASM_TRAP();
- return CBotString();
+ ASM_TRAP();
+ return CBotString();
}
void CBotVar::SetClass(CBotClass* pClass)
{
- ASM_TRAP();
+ ASM_TRAP();
}
CBotClass* CBotVar::GivClass()
{
- ASM_TRAP();
- return NULL;
+ ASM_TRAP();
+ return NULL;
}
/*
void CBotVar::SetIndirection(CBotVar* pVar)
{
- // nop, uniquement pour CBotVarPointer::SetIndirection
+ // nop, uniquement pour CBotVarPointer::SetIndirection
}
*/
//////////////////////////////////////////////////////////////////////////////////////
// copie une variable dans une autre
-void CBotVarInt::Copy(CBotVar* pSrc, BOOL bName)
+void CBotVarInt::Copy(CBotVar* pSrc, bool bName)
{
- CBotVarInt* p = (CBotVarInt*)pSrc;
+ CBotVarInt* p = (CBotVarInt*)pSrc;
- if ( bName) *m_token = *p->m_token;
- m_type = p->m_type;
- m_val = p->m_val;
- m_binit = p->m_binit;
- m_pMyThis = NULL;
- m_pUserPtr = p->m_pUserPtr;
+ if ( bName) *m_token = *p->m_token;
+ m_type = p->m_type;
+ m_val = p->m_val;
+ m_binit = p->m_binit;
+ m_pMyThis = NULL;
+ m_pUserPtr = p->m_pUserPtr;
- // garde le même idendificateur (par défaut)
- if (m_ident == 0 ) m_ident = p->m_ident;
+ // garde le même idendificateur (par défaut)
+ if (m_ident == 0 ) m_ident = p->m_ident;
- m_defnum = p->m_defnum;
+ m_defnum = p->m_defnum;
}
@@ -859,210 +859,210 @@ void CBotVarInt::Copy(CBotVar* pSrc, BOOL bName)
void CBotVarInt::SetValInt(int val, const char* defnum)
{
- m_val = val;
- m_binit = TRUE;
- m_defnum = defnum;
+ m_val = val;
+ m_binit = true;
+ m_defnum = defnum;
}
void CBotVarInt::SetValFloat(float val)
{
- m_val = (int)val;
- m_binit = TRUE;
+ m_val = (int)val;
+ m_binit = true;
}
int CBotVarInt::GivValInt()
{
- return m_val;
+ return m_val;
}
float CBotVarInt::GivValFloat()
{
- return (float)m_val;
+ return (float)m_val;
}
CBotString CBotVarInt::GivValString()
{
- if ( !m_defnum.IsEmpty() ) return m_defnum;
+ if ( !m_defnum.IsEmpty() ) return m_defnum;
- CBotString res;
+ CBotString res;
- if ( !m_binit )
- {
- res.LoadString(TX_UNDEF);
- return res;
- }
- if ( m_binit == IS_NAN )
- {
- res.LoadString(TX_NAN);
- return res;
- }
+ if ( !m_binit )
+ {
+ res.LoadString(TX_UNDEF);
+ return res;
+ }
+ if ( m_binit == IS_NAN )
+ {
+ res.LoadString(TX_NAN);
+ return res;
+ }
- char buffer[300];
- sprintf(buffer, "%d", m_val);
- res = buffer;
+ char buffer[300];
+ sprintf(buffer, "%d", m_val);
+ res = buffer;
- return res;
+ return res;
}
void CBotVarInt::Mul(CBotVar* left, CBotVar* right)
{
- m_val = left->GivValInt() * right->GivValInt();
- m_binit = TRUE;
+ m_val = left->GivValInt() * right->GivValInt();
+ m_binit = true;
}
void CBotVarInt::Power(CBotVar* left, CBotVar* right)
{
- m_val = (int) pow( (double) left->GivValInt() , (double) right->GivValInt() );
- m_binit = TRUE;
+ m_val = (int) pow( (double) left->GivValInt() , (double) right->GivValInt() );
+ m_binit = true;
}
int CBotVarInt::Div(CBotVar* left, CBotVar* right)
{
- int r = right->GivValInt();
- if ( r != 0 )
- {
- m_val = left->GivValInt() / r;
- m_binit = TRUE;
- }
- return ( r == 0 ? TX_DIVZERO : 0 );
+ int r = right->GivValInt();
+ if ( r != 0 )
+ {
+ m_val = left->GivValInt() / r;
+ m_binit = true;
+ }
+ return ( r == 0 ? TX_DIVZERO : 0 );
}
int CBotVarInt::Modulo(CBotVar* left, CBotVar* right)
{
- int r = right->GivValInt();
- if ( r != 0 )
- {
- m_val = left->GivValInt() % r;
- m_binit = TRUE;
- }
- return ( r == 0 ? TX_DIVZERO : 0 );
+ int r = right->GivValInt();
+ if ( r != 0 )
+ {
+ m_val = left->GivValInt() % r;
+ m_binit = true;
+ }
+ return ( r == 0 ? TX_DIVZERO : 0 );
}
void CBotVarInt::Add(CBotVar* left, CBotVar* right)
{
- m_val = left->GivValInt() + right->GivValInt();
- m_binit = TRUE;
+ m_val = left->GivValInt() + right->GivValInt();
+ m_binit = true;
}
void CBotVarInt::Sub(CBotVar* left, CBotVar* right)
{
- m_val = left->GivValInt() - right->GivValInt();
- m_binit = TRUE;
+ m_val = left->GivValInt() - right->GivValInt();
+ m_binit = true;
}
void CBotVarInt::XOr(CBotVar* left, CBotVar* right)
{
- m_val = left->GivValInt() ^ right->GivValInt();
- m_binit = TRUE;
+ m_val = left->GivValInt() ^ right->GivValInt();
+ m_binit = true;
}
void CBotVarInt::And(CBotVar* left, CBotVar* right)
{
- m_val = left->GivValInt() & right->GivValInt();
- m_binit = TRUE;
+ m_val = left->GivValInt() & right->GivValInt();
+ m_binit = true;
}
void CBotVarInt::Or(CBotVar* left, CBotVar* right)
{
- m_val = left->GivValInt() | right->GivValInt();
- m_binit = TRUE;
+ m_val = left->GivValInt() | right->GivValInt();
+ m_binit = true;
}
void CBotVarInt::SL(CBotVar* left, CBotVar* right)
{
- m_val = left->GivValInt() << right->GivValInt();
- m_binit = TRUE;
+ m_val = left->GivValInt() << right->GivValInt();
+ m_binit = true;
}
void CBotVarInt::ASR(CBotVar* left, CBotVar* right)
{
- m_val = left->GivValInt() >> right->GivValInt();
- m_binit = TRUE;
+ m_val = left->GivValInt() >> right->GivValInt();
+ m_binit = true;
}
void CBotVarInt::SR(CBotVar* left, CBotVar* right)
{
- int source = left->GivValInt();
- int shift = right->GivValInt();
- if (shift>=1) source &= 0x7fffffff;
- m_val = source >> shift;
- m_binit = TRUE;
+ int source = left->GivValInt();
+ int shift = right->GivValInt();
+ if (shift>=1) source &= 0x7fffffff;
+ m_val = source >> shift;
+ m_binit = true;
}
void CBotVarInt::Neg()
{
- m_val = -m_val;
+ m_val = -m_val;
}
void CBotVarInt::Not()
{
- m_val = ~m_val;
+ m_val = ~m_val;
}
void CBotVarInt::Inc()
{
- m_val++;
- m_defnum.Empty();
+ m_val++;
+ m_defnum.Empty();
}
void CBotVarInt::Dec()
{
- m_val--;
- m_defnum.Empty();
+ m_val--;
+ m_defnum.Empty();
}
-BOOL CBotVarInt::Lo(CBotVar* left, CBotVar* right)
+bool CBotVarInt::Lo(CBotVar* left, CBotVar* right)
{
- return left->GivValInt() < right->GivValInt();
+ return left->GivValInt() < right->GivValInt();
}
-BOOL CBotVarInt::Hi(CBotVar* left, CBotVar* right)
+bool CBotVarInt::Hi(CBotVar* left, CBotVar* right)
{
- return left->GivValInt() > right->GivValInt();
+ return left->GivValInt() > right->GivValInt();
}
-BOOL CBotVarInt::Ls(CBotVar* left, CBotVar* right)
+bool CBotVarInt::Ls(CBotVar* left, CBotVar* right)
{
- return left->GivValInt() <= right->GivValInt();
+ return left->GivValInt() <= right->GivValInt();
}
-BOOL CBotVarInt::Hs(CBotVar* left, CBotVar* right)
+bool CBotVarInt::Hs(CBotVar* left, CBotVar* right)
{
- return left->GivValInt() >= right->GivValInt();
+ return left->GivValInt() >= right->GivValInt();
}
-BOOL CBotVarInt::Eq(CBotVar* left, CBotVar* right)
+bool CBotVarInt::Eq(CBotVar* left, CBotVar* right)
{
- return left->GivValInt() == right->GivValInt();
+ return left->GivValInt() == right->GivValInt();
}
-BOOL CBotVarInt::Ne(CBotVar* left, CBotVar* right)
+bool CBotVarInt::Ne(CBotVar* left, CBotVar* right)
{
- return left->GivValInt() != right->GivValInt();
+ return left->GivValInt() != right->GivValInt();
}
//////////////////////////////////////////////////////////////////////////////////////
// copie une variable dans une autre
-void CBotVarFloat::Copy(CBotVar* pSrc, BOOL bName)
+void CBotVarFloat::Copy(CBotVar* pSrc, bool bName)
{
- CBotVarFloat* p = (CBotVarFloat*)pSrc;
+ CBotVarFloat* p = (CBotVarFloat*)pSrc;
- if (bName) *m_token = *p->m_token;
- m_type = p->m_type;
- m_val = p->m_val;
- m_binit = p->m_binit;
-//- m_bStatic = p->m_bStatic;
- m_next = NULL;
- m_pMyThis = NULL;//p->m_pMyThis;
- m_pUserPtr = p->m_pUserPtr;
+ if (bName) *m_token = *p->m_token;
+ m_type = p->m_type;
+ m_val = p->m_val;
+ m_binit = p->m_binit;
+//- m_bStatic = p->m_bStatic;
+ m_next = NULL;
+ m_pMyThis = NULL;//p->m_pMyThis;
+ m_pUserPtr = p->m_pUserPtr;
- // garde le même idendificateur (par défaut)
- if (m_ident == 0 ) m_ident = p->m_ident;
+ // garde le même idendificateur (par défaut)
+ if (m_ident == 0 ) m_ident = p->m_ident;
}
@@ -1070,160 +1070,160 @@ void CBotVarFloat::Copy(CBotVar* pSrc, BOOL bName)
void CBotVarFloat::SetValInt(int val, const char* s)
{
- m_val = (float)val;
- m_binit = TRUE;
+ m_val = (float)val;
+ m_binit = true;
}
void CBotVarFloat::SetValFloat(float val)
{
- m_val = val;
- m_binit = TRUE;
+ m_val = val;
+ m_binit = true;
}
int CBotVarFloat::GivValInt()
{
- return (int)m_val;
+ return (int)m_val;
}
float CBotVarFloat::GivValFloat()
{
- return m_val;
+ return m_val;
}
CBotString CBotVarFloat::GivValString()
{
- CBotString res;
+ CBotString res;
- if ( !m_binit )
- {
- res.LoadString(TX_UNDEF);
- return res;
- }
- if ( m_binit == IS_NAN )
- {
- res.LoadString(TX_NAN);
- return res;
- }
+ if ( !m_binit )
+ {
+ res.LoadString(TX_UNDEF);
+ return res;
+ }
+ if ( m_binit == IS_NAN )
+ {
+ res.LoadString(TX_NAN);
+ return res;
+ }
- char buffer[300];
- sprintf(buffer, "%.2f", m_val);
- res = buffer;
+ char buffer[300];
+ sprintf(buffer, "%.2f", m_val);
+ res = buffer;
- return res;
+ return res;
}
void CBotVarFloat::Mul(CBotVar* left, CBotVar* right)
{
- m_val = left->GivValFloat() * right->GivValFloat();
- m_binit = TRUE;
+ m_val = left->GivValFloat() * right->GivValFloat();
+ m_binit = true;
}
void CBotVarFloat::Power(CBotVar* left, CBotVar* right)
{
- m_val = (float)pow( left->GivValFloat() , right->GivValFloat() );
- m_binit = TRUE;
+ m_val = (float)pow( left->GivValFloat() , right->GivValFloat() );
+ m_binit = true;
}
int CBotVarFloat::Div(CBotVar* left, CBotVar* right)
{
- float r = right->GivValFloat();
- if ( r != 0 )
- {
- m_val = left->GivValFloat() / r;
- m_binit = TRUE;
- }
- return ( r == 0 ? TX_DIVZERO : 0 );
+ float r = right->GivValFloat();
+ if ( r != 0 )
+ {
+ m_val = left->GivValFloat() / r;
+ m_binit = true;
+ }
+ return ( r == 0 ? TX_DIVZERO : 0 );
}
int CBotVarFloat::Modulo(CBotVar* left, CBotVar* right)
{
- float r = right->GivValFloat();
- if ( r != 0 )
- {
- m_val = (float)fmod( left->GivValFloat() , r );
- m_binit = TRUE;
- }
- return ( r == 0 ? TX_DIVZERO : 0 );
+ float r = right->GivValFloat();
+ if ( r != 0 )
+ {
+ m_val = (float)fmod( left->GivValFloat() , r );
+ m_binit = true;
+ }
+ return ( r == 0 ? TX_DIVZERO : 0 );
}
void CBotVarFloat::Add(CBotVar* left, CBotVar* right)
{
- m_val = left->GivValFloat() + right->GivValFloat();
- m_binit = TRUE;
+ m_val = left->GivValFloat() + right->GivValFloat();
+ m_binit = true;
}
void CBotVarFloat::Sub(CBotVar* left, CBotVar* right)
{
- m_val = left->GivValFloat() - right->GivValFloat();
- m_binit = TRUE;
+ m_val = left->GivValFloat() - right->GivValFloat();
+ m_binit = true;
}
void CBotVarFloat::Neg()
{
- m_val = -m_val;
+ m_val = -m_val;
}
void CBotVarFloat::Inc()
{
- m_val++;
+ m_val++;
}
void CBotVarFloat::Dec()
{
- m_val--;
+ m_val--;
}
-BOOL CBotVarFloat::Lo(CBotVar* left, CBotVar* right)
+bool CBotVarFloat::Lo(CBotVar* left, CBotVar* right)
{
- return left->GivValFloat() < right->GivValFloat();
+ return left->GivValFloat() < right->GivValFloat();
}
-BOOL CBotVarFloat::Hi(CBotVar* left, CBotVar* right)
+bool CBotVarFloat::Hi(CBotVar* left, CBotVar* right)
{
- return left->GivValFloat() > right->GivValFloat();
+ return left->GivValFloat() > right->GivValFloat();
}
-BOOL CBotVarFloat::Ls(CBotVar* left, CBotVar* right)
+bool CBotVarFloat::Ls(CBotVar* left, CBotVar* right)
{
- return left->GivValFloat() <= right->GivValFloat();
+ return left->GivValFloat() <= right->GivValFloat();
}
-BOOL CBotVarFloat::Hs(CBotVar* left, CBotVar* right)
+bool CBotVarFloat::Hs(CBotVar* left, CBotVar* right)
{
- return left->GivValFloat() >= right->GivValFloat();
+ return left->GivValFloat() >= right->GivValFloat();
}
-BOOL CBotVarFloat::Eq(CBotVar* left, CBotVar* right)
+bool CBotVarFloat::Eq(CBotVar* left, CBotVar* right)
{
- return left->GivValFloat() == right->GivValFloat();
+ return left->GivValFloat() == right->GivValFloat();
}
-BOOL CBotVarFloat::Ne(CBotVar* left, CBotVar* right)
+bool CBotVarFloat::Ne(CBotVar* left, CBotVar* right)
{
- return left->GivValFloat() != right->GivValFloat();
+ return left->GivValFloat() != right->GivValFloat();
}
//////////////////////////////////////////////////////////////////////////////////////
// copie une variable dans une autre
-void CBotVarBoolean::Copy(CBotVar* pSrc, BOOL bName)
+void CBotVarBoolean::Copy(CBotVar* pSrc, bool bName)
{
- CBotVarBoolean* p = (CBotVarBoolean*)pSrc;
+ CBotVarBoolean* p = (CBotVarBoolean*)pSrc;
- if (bName) *m_token = *p->m_token;
- m_type = p->m_type;
- m_val = p->m_val;
- m_binit = p->m_binit;
-//- m_bStatic = p->m_bStatic;
- m_next = NULL;
- m_pMyThis = NULL;//p->m_pMyThis;
- m_pUserPtr = p->m_pUserPtr;
+ if (bName) *m_token = *p->m_token;
+ m_type = p->m_type;
+ m_val = p->m_val;
+ m_binit = p->m_binit;
+//- m_bStatic = p->m_bStatic;
+ m_next = NULL;
+ m_pMyThis = NULL;//p->m_pMyThis;
+ m_pUserPtr = p->m_pUserPtr;
- // garde le même idendificateur (par défaut)
- if (m_ident == 0 ) m_ident = p->m_ident;
+ // garde le même idendificateur (par défaut)
+ if (m_ident == 0 ) m_ident = p->m_ident;
}
@@ -1231,485 +1231,485 @@ void CBotVarBoolean::Copy(CBotVar* pSrc, BOOL bName)
void CBotVarBoolean::SetValInt(int val, const char* s)
{
- m_val = (BOOL)val;
- m_binit = TRUE;
+ m_val = (bool)val;
+ m_binit = true;
}
void CBotVarBoolean::SetValFloat(float val)
{
- m_val = (BOOL)val;
- m_binit = TRUE;
+ m_val = (bool)val;
+ m_binit = true;
}
int CBotVarBoolean::GivValInt()
{
- return m_val;
+ return m_val;
}
float CBotVarBoolean::GivValFloat()
{
- return (float)m_val;
+ return (float)m_val;
}
CBotString CBotVarBoolean::GivValString()
{
- CBotString ret;
+ CBotString ret;
- CBotString res;
+ CBotString res;
- if ( !m_binit )
- {
- res.LoadString(TX_UNDEF);
- return res;
- }
- if ( m_binit == IS_NAN )
- {
- res.LoadString(TX_NAN);
- return res;
- }
+ if ( !m_binit )
+ {
+ res.LoadString(TX_UNDEF);
+ return res;
+ }
+ if ( m_binit == IS_NAN )
+ {
+ res.LoadString(TX_NAN);
+ return res;
+ }
- ret.LoadString( m_val > 0 ? ID_TRUE : ID_FALSE );
- return ret;
+ ret.LoadString( m_val > 0 ? ID_TRUE : ID_FALSE );
+ return ret;
}
void CBotVarBoolean::And(CBotVar* left, CBotVar* right)
{
- m_val = left->GivValInt() && right->GivValInt();
- m_binit = TRUE;
+ m_val = left->GivValInt() && right->GivValInt();
+ m_binit = true;
}
void CBotVarBoolean::Or(CBotVar* left, CBotVar* right)
{
- m_val = left->GivValInt() || right->GivValInt();
- m_binit = TRUE;
+ m_val = left->GivValInt() || right->GivValInt();
+ m_binit = true;
}
void CBotVarBoolean::XOr(CBotVar* left, CBotVar* right)
{
- m_val = left->GivValInt() ^ right->GivValInt();
- m_binit = TRUE;
+ m_val = left->GivValInt() ^ right->GivValInt();
+ m_binit = true;
}
void CBotVarBoolean::Not()
{
- m_val = m_val ? FALSE : TRUE ;
+ m_val = m_val ? false : true ;
}
-BOOL CBotVarBoolean::Eq(CBotVar* left, CBotVar* right)
+bool CBotVarBoolean::Eq(CBotVar* left, CBotVar* right)
{
- return left->GivValInt() == right->GivValInt();
+ return left->GivValInt() == right->GivValInt();
}
-BOOL CBotVarBoolean::Ne(CBotVar* left, CBotVar* right)
+bool CBotVarBoolean::Ne(CBotVar* left, CBotVar* right)
{
- return left->GivValInt() != right->GivValInt();
+ return left->GivValInt() != right->GivValInt();
}
//////////////////////////////////////////////////////////////////////////////////////
// copie une variable dans une autre
-void CBotVarString::Copy(CBotVar* pSrc, BOOL bName)
+void CBotVarString::Copy(CBotVar* pSrc, bool bName)
{
- CBotVarString* p = (CBotVarString*)pSrc;
+ CBotVarString* p = (CBotVarString*)pSrc;
- if (bName) *m_token = *p->m_token;
- m_type = p->m_type;
- m_val = p->m_val;
- m_binit = p->m_binit;
-//- m_bStatic = p->m_bStatic;
- m_next = NULL;
- m_pMyThis = NULL;//p->m_pMyThis;
- m_pUserPtr = p->m_pUserPtr;
+ if (bName) *m_token = *p->m_token;
+ m_type = p->m_type;
+ m_val = p->m_val;
+ m_binit = p->m_binit;
+//- m_bStatic = p->m_bStatic;
+ m_next = NULL;
+ m_pMyThis = NULL;//p->m_pMyThis;
+ m_pUserPtr = p->m_pUserPtr;
- // garde le même idendificateur (par défaut)
- if (m_ident == 0 ) m_ident = p->m_ident;
+ // garde le même idendificateur (par défaut)
+ if (m_ident == 0 ) m_ident = p->m_ident;
}
void CBotVarString::SetValString(const char* p)
{
- m_val = p;
- m_binit = TRUE;
+ m_val = p;
+ m_binit = true;
}
CBotString CBotVarString::GivValString()
{
- if ( !m_binit )
- {
- CBotString res;
- res.LoadString(TX_UNDEF);
- return res;
- }
- if ( m_binit == IS_NAN )
- {
- CBotString res;
- res.LoadString(TX_NAN);
- return res;
- }
+ if ( !m_binit )
+ {
+ CBotString res;
+ res.LoadString(TX_UNDEF);
+ return res;
+ }
+ if ( m_binit == IS_NAN )
+ {
+ CBotString res;
+ res.LoadString(TX_NAN);
+ return res;
+ }
- return m_val;
+ return m_val;
}
void CBotVarString::Add(CBotVar* left, CBotVar* right)
{
- m_val = left->GivValString() + right->GivValString();
- m_binit = TRUE;
+ m_val = left->GivValString() + right->GivValString();
+ m_binit = true;
}
-BOOL CBotVarString::Eq(CBotVar* left, CBotVar* right)
+bool CBotVarString::Eq(CBotVar* left, CBotVar* right)
{
- return (left->GivValString() == right->GivValString());
+ return (left->GivValString() == right->GivValString());
}
-BOOL CBotVarString::Ne(CBotVar* left, CBotVar* right)
+bool CBotVarString::Ne(CBotVar* left, CBotVar* right)
{
- return (left->GivValString() != right->GivValString());
+ return (left->GivValString() != right->GivValString());
}
-BOOL CBotVarString::Lo(CBotVar* left, CBotVar* right)
+bool CBotVarString::Lo(CBotVar* left, CBotVar* right)
{
- return (left->GivValString() == right->GivValString());
+ return (left->GivValString() == right->GivValString());
}
-BOOL CBotVarString::Hi(CBotVar* left, CBotVar* right)
+bool CBotVarString::Hi(CBotVar* left, CBotVar* right)
{
- return (left->GivValString() == right->GivValString());
+ return (left->GivValString() == right->GivValString());
}
-BOOL CBotVarString::Ls(CBotVar* left, CBotVar* right)
+bool CBotVarString::Ls(CBotVar* left, CBotVar* right)
{
- return (left->GivValString() == right->GivValString());
+ return (left->GivValString() == right->GivValString());
}
-BOOL CBotVarString::Hs(CBotVar* left, CBotVar* right)
+bool CBotVarString::Hs(CBotVar* left, CBotVar* right)
{
- return (left->GivValString() == right->GivValString());
+ return (left->GivValString() == right->GivValString());
}
////////////////////////////////////////////////////////////////
// copie une variable dans une autre
-void CBotVarClass::Copy(CBotVar* pSrc, BOOL bName)
+void CBotVarClass::Copy(CBotVar* pSrc, bool bName)
{
- pSrc = pSrc->GivPointer(); // si source donné par un pointeur
+ pSrc = pSrc->GivPointer(); // si source donné par un pointeur
- if ( pSrc->GivType() != CBotTypClass )
- ASM_TRAP();
+ if ( pSrc->GivType() != CBotTypClass )
+ ASM_TRAP();
- CBotVarClass* p = (CBotVarClass*)pSrc;
+ CBotVarClass* p = (CBotVarClass*)pSrc;
- if (bName) *m_token = *p->m_token;
+ if (bName) *m_token = *p->m_token;
- m_type = p->m_type;
- m_binit = p->m_binit;
-//- m_bStatic = p->m_bStatic;
- m_pClass = p->m_pClass;
- if ( p->m_pParent )
- {
- ASM_TRAP(); "que faire du pParent";
- }
+ m_type = p->m_type;
+ m_binit = p->m_binit;
+//- m_bStatic = p->m_bStatic;
+ m_pClass = p->m_pClass;
+ if ( p->m_pParent )
+ {
+ ASM_TRAP(); "que faire du pParent";
+ }
-// m_next = NULL;
- m_pUserPtr = p->m_pUserPtr;
- m_pMyThis = NULL;//p->m_pMyThis;
- m_ItemIdent = p->m_ItemIdent;
+// m_next = NULL;
+ m_pUserPtr = p->m_pUserPtr;
+ m_pMyThis = NULL;//p->m_pMyThis;
+ m_ItemIdent = p->m_ItemIdent;
- // garde le même idendificateur (par défaut)
- if (m_ident == 0 ) m_ident = p->m_ident;
+ // garde le même idendificateur (par défaut)
+ if (m_ident == 0 ) m_ident = p->m_ident;
- delete m_pVar;
- m_pVar = NULL;
+ delete m_pVar;
+ m_pVar = NULL;
- CBotVar* pv = p->m_pVar;
- while( pv != NULL )
- {
- CBotVar* pn = CBotVar::Create(pv);
- pn->Copy( pv );
- if ( m_pVar == NULL ) m_pVar = pn;
- else m_pVar->AddNext(pn);
+ CBotVar* pv = p->m_pVar;
+ while( pv != NULL )
+ {
+ CBotVar* pn = CBotVar::Create(pv);
+ pn->Copy( pv );
+ if ( m_pVar == NULL ) m_pVar = pn;
+ else m_pVar->AddNext(pn);
- pv = pv->GivNext();
- }
+ pv = pv->GivNext();
+ }
}
void CBotVarClass::SetItemList(CBotVar* pVar)
{
- delete m_pVar;
- m_pVar = pVar; // remplace le pointeur existant
+ delete m_pVar;
+ m_pVar = pVar; // remplace le pointeur existant
}
void CBotVarClass::SetIdent(long n)
{
- m_ItemIdent = n;
+ m_ItemIdent = n;
}
void CBotVarClass::SetClass(CBotClass* pClass)//, int &nIdent)
{
- m_type.m_pClass = pClass;
+ m_type.m_pClass = pClass;
- if ( m_pClass == pClass ) return;
+ if ( m_pClass == pClass ) return;
- m_pClass = pClass;
+ m_pClass = pClass;
- // initialise les variables associées à cette classe
- delete m_pVar;
- m_pVar = NULL;
+ // initialise les variables associées à cette classe
+ delete m_pVar;
+ m_pVar = NULL;
- if (pClass == NULL) return;
+ if (pClass == NULL) return;
- CBotVar* pv = pClass->GivVar(); // premier de la liste
- while ( pv != NULL )
- {
- // cherche les dimensions max du tableau
- CBotInstr* p = pv->m_LimExpr; // les différentes formules
- if ( p != NULL )
- {
- CBotStack* pile = CBotStack::FirstStack(); // une pile indépendante
- int n = 0;
- int max[100];
+ CBotVar* pv = pClass->GivVar(); // premier de la liste
+ while ( pv != NULL )
+ {
+ // cherche les dimensions max du tableau
+ CBotInstr* p = pv->m_LimExpr; // les différentes formules
+ if ( p != NULL )
+ {
+ CBotStack* pile = CBotStack::FirstStack(); // une pile indépendante
+ int n = 0;
+ int max[100];
- while (p != NULL)
- {
- while( pile->IsOk() && !p->Execute(pile) ) ; // calcul de la taille sans interruptions
- CBotVar* v = pile->GivVar(); // résultat
- max[n] = v->GivValInt(); // valeur
- n++;
- p = p->GivNext3();
- }
- while (n<100) max[n++] = 0;
+ while (p != NULL)
+ {
+ while( pile->IsOk() && !p->Execute(pile) ) ; // calcul de la taille sans interruptions
+ CBotVar* v = pile->GivVar(); // résultat
+ max[n] = v->GivValInt(); // valeur
+ n++;
+ p = p->GivNext3();
+ }
+ while (n<100) max[n++] = 0;
- pv->m_type.SetArray( max ); // mémorise les limitations
- pile->Delete();
- }
+ pv->m_type.SetArray( max ); // mémorise les limitations
+ pile->Delete();
+ }
- CBotVar* pn = CBotVar::Create( pv ); // une copie
- pn->SetStatic(pv->IsStatic());
- pn->SetPrivate(pv->GivPrivate());
+ CBotVar* pn = CBotVar::Create( pv ); // une copie
+ pn->SetStatic(pv->IsStatic());
+ pn->SetPrivate(pv->GivPrivate());
- if ( pv->m_InitExpr != NULL ) // expression pour l'initialisation ?
- {
-#if STACKMEM
- CBotStack* pile = CBotStack::FirstStack(); // une pile indépendante
+ if ( pv->m_InitExpr != NULL ) // expression pour l'initialisation ?
+ {
+#if STACKMEM
+ CBotStack* pile = CBotStack::FirstStack(); // une pile indépendante
- while(pile->IsOk() && !pv->m_InitExpr->Execute(pile, pn)); // évalue l'expression sans timer
+ while(pile->IsOk() && !pv->m_InitExpr->Execute(pile, pn)); // évalue l'expression sans timer
- pile->Delete();
+ pile->Delete();
#else
- CBotStack* pile = new CBotStack(NULL); // une pile indépendante
- while(!pv->m_InitExpr->Execute(pile)); // évalue l'expression sans timer
- pn->SetVal( pile->GivVar() ) ;
- delete pile;
+ CBotStack* pile = new CBotStack(NULL); // une pile indépendante
+ while(!pv->m_InitExpr->Execute(pile)); // évalue l'expression sans timer
+ pn->SetVal( pile->GivVar() ) ;
+ delete pile;
#endif
- }
+ }
-// pn->SetUniqNum(CBotVar::NextUniqNum()); // numérote les éléments
- pn->SetUniqNum(pv->GivUniqNum()); //++nIdent
- pn->m_pMyThis = this;
+// pn->SetUniqNum(CBotVar::NextUniqNum()); // numérote les éléments
+ pn->SetUniqNum(pv->GivUniqNum()); //++nIdent
+ pn->m_pMyThis = this;
- if ( m_pVar == NULL) m_pVar = pn;
- else m_pVar->AddNext( pn );
- pv = pv->GivNext();
- }
+ if ( m_pVar == NULL) m_pVar = pn;
+ else m_pVar->AddNext( pn );
+ pv = pv->GivNext();
+ }
}
CBotClass* CBotVarClass::GivClass()
{
- return m_pClass;
+ return m_pClass;
}
-void CBotVarClass::Maj(void* pUser, BOOL bContinu)
+void CBotVarClass::Maj(void* pUser, bool bContinu)
{
-/* if (!bContinu && m_pMyThis != NULL)
- m_pMyThis->Maj(pUser, TRUE);*/
+/* if (!bContinu && m_pMyThis != NULL)
+ m_pMyThis->Maj(pUser, true);*/
- // une routine de mise à jour existe-elle ?
+ // une routine de mise à jour existe-elle ?
- if ( m_pClass->m_rMaj == NULL ) return;
+ if ( m_pClass->m_rMaj == NULL ) return;
- // récupère le pointeur user selon la classe
- // ou selon le paramètre passé au CBotProgram::Run()
+ // récupère le pointeur user selon la classe
+ // ou selon le paramètre passé au CBotProgram::Run()
- if ( m_pUserPtr != NULL) pUser = m_pUserPtr;
- if ( pUser == OBJECTDELETED ||
- pUser == OBJECTCREATED ) return;
- m_pClass->m_rMaj( this, pUser );
+ if ( m_pUserPtr != NULL) pUser = m_pUserPtr;
+ if ( pUser == OBJECTDELETED ||
+ pUser == OBJECTCREATED ) return;
+ m_pClass->m_rMaj( this, pUser );
}
CBotVar* CBotVarClass::GivItem(const char* name)
{
- CBotVar* p = m_pVar;
+ CBotVar* p = m_pVar;
- while ( p != NULL )
- {
- if ( p->GivName() == name ) return p;
- p = p->GivNext();
- }
+ while ( p != NULL )
+ {
+ if ( p->GivName() == name ) return p;
+ p = p->GivNext();
+ }
- if ( m_pParent != NULL ) return m_pParent->GivItem(name);
- return NULL;
+ if ( m_pParent != NULL ) return m_pParent->GivItem(name);
+ return NULL;
}
CBotVar* CBotVarClass::GivItemRef(int nIdent)
{
- CBotVar* p = m_pVar;
+ CBotVar* p = m_pVar;
- while ( p != NULL )
- {
- if ( p->GivUniqNum() == nIdent ) return p;
- p = p->GivNext();
- }
+ while ( p != NULL )
+ {
+ if ( p->GivUniqNum() == nIdent ) return p;
+ p = p->GivNext();
+ }
- if ( m_pParent != NULL ) return m_pParent->GivItemRef(nIdent);
- return NULL;
+ if ( m_pParent != NULL ) return m_pParent->GivItemRef(nIdent);
+ return NULL;
}
// pour la gestion d'un tableau
// bExtend permet d'agrandir le tableau, mais pas au dela de la taille fixée par SetArray()
-CBotVar* CBotVarClass::GivItem(int n, BOOL bExtend)
+CBotVar* CBotVarClass::GivItem(int n, bool bExtend)
{
- CBotVar* p = m_pVar;
+ CBotVar* p = m_pVar;
- if ( n < 0 ) return NULL;
- if ( n > MAXARRAYSIZE ) return NULL;
+ if ( n < 0 ) return NULL;
+ if ( n > MAXARRAYSIZE ) return NULL;
- if ( m_type.GivLimite() >= 0 && n >= m_type.GivLimite() ) return NULL;
+ if ( m_type.GivLimite() >= 0 && n >= m_type.GivLimite() ) return NULL;
- if ( p == NULL && bExtend )
- {
- p = CBotVar::Create("", m_type.GivTypElem());
- m_pVar = p;
- }
+ if ( p == NULL && bExtend )
+ {
+ p = CBotVar::Create("", m_type.GivTypElem());
+ m_pVar = p;
+ }
- if ( n == 0 ) return p;
+ if ( n == 0 ) return p;
- while ( n-- > 0 )
- {
- if ( p->m_next == NULL )
- {
- if ( bExtend ) p->m_next = CBotVar::Create("", m_type.GivTypElem());
- if ( p->m_next == NULL ) return NULL;
- }
- p = p->m_next;
- }
+ while ( n-- > 0 )
+ {
+ if ( p->m_next == NULL )
+ {
+ if ( bExtend ) p->m_next = CBotVar::Create("", m_type.GivTypElem());
+ if ( p->m_next == NULL ) return NULL;
+ }
+ p = p->m_next;
+ }
- return p;
+ return p;
}
CBotVar* CBotVarClass::GivItemList()
{
- return m_pVar;
+ return m_pVar;
}
CBotString CBotVarClass::GivValString()
{
-// if ( m_Indirect != NULL) return m_Indirect->GivValString();
-
- CBotString res;
-
- if ( m_pClass != NULL ) // pas utilisé pour un array
- {
- res = m_pClass->GivName() + CBotString("( ");
-
- CBotVarClass* my = this;
- while ( my != NULL )
- {
- CBotVar* pv = my->m_pVar;
- while ( pv != NULL )
- {
- res += pv->GivName() + CBotString("=");
-
- if ( pv->IsStatic() )
- {
- CBotVar* pvv = my->m_pClass->GivItem(pv->GivName());
- res += pvv->GivValString();
- }
- else
- {
- res += pv->GivValString();
- }
- pv = pv->GivNext();
- if ( pv != NULL ) res += ", ";
- }
- my = my->m_pParent;
- if ( my != NULL )
- {
- res += ") extends ";
- res += my->m_pClass->GivName();
- res += " (";
- }
- }
- }
- else
- {
- res = "( ";
-
- CBotVar* pv = m_pVar;
- while ( pv != NULL )
- {
- res += pv->GivValString();
- if ( pv->GivNext() != NULL ) res += ", ";
- pv = pv->GivNext();
- }
- }
-
- res += " )";
- return res;
+// if ( m_Indirect != NULL) return m_Indirect->GivValString();
+
+ CBotString res;
+
+ if ( m_pClass != NULL ) // pas utilisé pour un array
+ {
+ res = m_pClass->GivName() + CBotString("( ");
+
+ CBotVarClass* my = this;
+ while ( my != NULL )
+ {
+ CBotVar* pv = my->m_pVar;
+ while ( pv != NULL )
+ {
+ res += pv->GivName() + CBotString("=");
+
+ if ( pv->IsStatic() )
+ {
+ CBotVar* pvv = my->m_pClass->GivItem(pv->GivName());
+ res += pvv->GivValString();
+ }
+ else
+ {
+ res += pv->GivValString();
+ }
+ pv = pv->GivNext();
+ if ( pv != NULL ) res += ", ";
+ }
+ my = my->m_pParent;
+ if ( my != NULL )
+ {
+ res += ") extends ";
+ res += my->m_pClass->GivName();
+ res += " (";
+ }
+ }
+ }
+ else
+ {
+ res = "( ";
+
+ CBotVar* pv = m_pVar;
+ while ( pv != NULL )
+ {
+ res += pv->GivValString();
+ if ( pv->GivNext() != NULL ) res += ", ";
+ pv = pv->GivNext();
+ }
+ }
+
+ res += " )";
+ return res;
}
void CBotVarClass::IncrementUse()
{
- m_CptUse++;
+ m_CptUse++;
}
void CBotVarClass::DecrementUse()
{
- m_CptUse--;
- if ( m_CptUse == 0 )
- {
- // s'il y en a un, appel le destructeur
- // mais seulement si un constructeur avait été appelé.
- if ( m_bConstructor )
- {
- m_CptUse++; // ne revient pas dans le destructeur
+ m_CptUse--;
+ if ( m_CptUse == 0 )
+ {
+ // s'il y en a un, appel le destructeur
+ // mais seulement si un constructeur avait été appelé.
+ if ( m_bConstructor )
+ {
+ m_CptUse++; // ne revient pas dans le destructeur
- // m_error est static dans le stack
- // sauve la valeur pour la remettre ensuite
- int err, start, end;
- CBotStack* pile = NULL;
- err = pile->GivError(start,end); // pile == NULL ça ne derange pas !!
+ // m_error est static dans le stack
+ // sauve la valeur pour la remettre ensuite
+ int err, start, end;
+ CBotStack* pile = NULL;
+ err = pile->GivError(start,end); // pile == NULL ça ne derange pas !!
- pile = CBotStack::FirstStack(); // efface l'erreur
- CBotVar* ppVars[1];
- ppVars[0] = NULL;
+ pile = CBotStack::FirstStack(); // efface l'erreur
+ CBotVar* ppVars[1];
+ ppVars[0] = NULL;
- CBotVar* pThis = CBotVar::Create("this", CBotTypNullPointer);
- pThis->SetPointer(this);
- CBotVar* pResult = NULL;
+ CBotVar* pThis = CBotVar::Create("this", CBotTypNullPointer);
+ pThis->SetPointer(this);
+ CBotVar* pResult = NULL;
- CBotString nom = "~" + m_pClass->GivName();
- long ident = 0;
+ CBotString nom = "~" + m_pClass->GivName();
+ long ident = 0;
- while ( pile->IsOk() && !m_pClass->ExecuteMethode(ident, nom, pThis, ppVars, pResult, pile, NULL)) ; // attend la fin
+ while ( pile->IsOk() && !m_pClass->ExecuteMethode(ident, nom, pThis, ppVars, pResult, pile, NULL)) ; // attend la fin
- pile->ResetError(err, start,end);
+ pile->ResetError(err, start,end);
- pile->Delete();
- delete pThis;
- m_CptUse--;
- }
+ pile->Delete();
+ delete pThis;
+ m_CptUse--;
+ }
- delete this; // s'auto-détruit !!
- }
+ delete this; // s'auto-détruit !!
+ }
}
CBotVarClass* CBotVarClass::GivPointer()
{
- return this;
+ return this;
}
@@ -1717,47 +1717,47 @@ CBotVarClass* CBotVarClass::GivPointer()
CBotVarClass* CBotVarClass::Find(long id)
{
- CBotVarClass* p = m_ExClass;
+ CBotVarClass* p = m_ExClass;
- while ( p != NULL )
- {
- if ( p->m_ItemIdent == id ) return p;
- p = p->m_ExNext;
- }
+ while ( p != NULL )
+ {
+ if ( p->m_ItemIdent == id ) return p;
+ p = p->m_ExNext;
+ }
- return NULL;
+ return NULL;
}
-BOOL CBotVarClass::Eq(CBotVar* left, CBotVar* right)
+bool CBotVarClass::Eq(CBotVar* left, CBotVar* right)
{
- CBotVar* l = left->GivItemList();
- CBotVar* r = right->GivItemList();
+ CBotVar* l = left->GivItemList();
+ CBotVar* r = right->GivItemList();
- while ( l != NULL && r != NULL )
- {
- if ( l->Ne(l, r) ) return FALSE;
- l = l->GivNext();
- r = r->GivNext();
- }
+ while ( l != NULL && r != NULL )
+ {
+ if ( l->Ne(l, r) ) return false;
+ l = l->GivNext();
+ r = r->GivNext();
+ }
- // devrait toujours arrivé simultanément au bout (mêmes classes)
- return l == r;
+ // devrait toujours arrivé simultanément au bout (mêmes classes)
+ return l == r;
}
-BOOL CBotVarClass::Ne(CBotVar* left, CBotVar* right)
+bool CBotVarClass::Ne(CBotVar* left, CBotVar* right)
{
- CBotVar* l = left->GivItemList();
- CBotVar* r = right->GivItemList();
+ CBotVar* l = left->GivItemList();
+ CBotVar* r = right->GivItemList();
- while ( l != NULL && r != NULL )
- {
- if ( l->Ne(l, r) ) return TRUE;
- l = l->GivNext();
- r = r->GivNext();
- }
+ while ( l != NULL && r != NULL )
+ {
+ if ( l->Ne(l, r) ) return true;
+ l = l->GivNext();
+ r = r->GivNext();
+ }
- // devrait toujours arrivé simultanément au bout (mêmes classes)
- return l != r;
+ // devrait toujours arrivé simultanément au bout (mêmes classes)
+ return l != r;
}
/////////////////////////////////////////////////////////////////////////////
@@ -1765,109 +1765,109 @@ BOOL CBotVarClass::Ne(CBotVar* left, CBotVar* right)
CBotVarArray::CBotVarArray(const CBotToken* name, CBotTypResult& type )
{
- if ( !type.Eq(CBotTypArrayPointer) &&
- !type.Eq(CBotTypArrayBody)) ASM_TRAP();
+ if ( !type.Eq(CBotTypArrayPointer) &&
+ !type.Eq(CBotTypArrayBody)) ASM_TRAP();
- m_token = new CBotToken(name);
- m_next = NULL;
- m_pMyThis = NULL;
- m_pUserPtr = NULL;
+ m_token = new CBotToken(name);
+ m_next = NULL;
+ m_pMyThis = NULL;
+ m_pUserPtr = NULL;
- m_type = type;
- m_type.SetType(CBotTypArrayPointer);
- m_binit = FALSE;
+ m_type = type;
+ m_type.SetType(CBotTypArrayPointer);
+ m_binit = false;
- m_pInstance = NULL; // la liste des éléments du tableau
+ m_pInstance = NULL; // la liste des éléments du tableau
}
CBotVarArray::~CBotVarArray()
{
- if ( m_pInstance != NULL ) m_pInstance->DecrementUse(); // une référence en moins
+ if ( m_pInstance != NULL ) m_pInstance->DecrementUse(); // une référence en moins
}
// copie une variable dans une autre
-void CBotVarArray::Copy(CBotVar* pSrc, BOOL bName)
+void CBotVarArray::Copy(CBotVar* pSrc, bool bName)
{
- if ( pSrc->GivType() != CBotTypArrayPointer )
- ASM_TRAP();
+ if ( pSrc->GivType() != CBotTypArrayPointer )
+ ASM_TRAP();
- CBotVarArray* p = (CBotVarArray*)pSrc;
+ CBotVarArray* p = (CBotVarArray*)pSrc;
- if ( bName) *m_token = *p->m_token;
- m_type = p->m_type;
- m_pInstance = p->GivPointer();
+ if ( bName) *m_token = *p->m_token;
+ m_type = p->m_type;
+ m_pInstance = p->GivPointer();
- if ( m_pInstance != NULL )
- m_pInstance->IncrementUse(); // une référence en plus
+ if ( m_pInstance != NULL )
+ m_pInstance->IncrementUse(); // une référence en plus
- m_binit = p->m_binit;
-//- m_bStatic = p->m_bStatic;
- m_pMyThis = NULL;//p->m_pMyThis;
- m_pUserPtr = p->m_pUserPtr;
+ m_binit = p->m_binit;
+//- m_bStatic = p->m_bStatic;
+ m_pMyThis = NULL;//p->m_pMyThis;
+ m_pUserPtr = p->m_pUserPtr;
- // garde le même idendificateur (par défaut)
- if (m_ident == 0 ) m_ident = p->m_ident;
+ // garde le même idendificateur (par défaut)
+ if (m_ident == 0 ) m_ident = p->m_ident;
}
void CBotVarArray::SetPointer(CBotVar* pVarClass)
{
- m_binit = TRUE; // init, même sur un pointeur null
+ m_binit = true; // init, même sur un pointeur null
- if ( m_pInstance == pVarClass) return; // spécial, ne pas décrémenter et réincrémenter
- // car le décrément peut détruire l'object
+ if ( m_pInstance == pVarClass) return; // spécial, ne pas décrémenter et réincrémenter
+ // car le décrément peut détruire l'object
- if ( pVarClass != NULL )
- {
- if ( pVarClass->GivType() == CBotTypArrayPointer )
- pVarClass = pVarClass->GivPointer(); // le vrai pointeur à l'objet
+ if ( pVarClass != NULL )
+ {
+ if ( pVarClass->GivType() == CBotTypArrayPointer )
+ pVarClass = pVarClass->GivPointer(); // le vrai pointeur à l'objet
- if ( !pVarClass->m_type.Eq(CBotTypClass) &&
- !pVarClass->m_type.Eq(CBotTypArrayBody))
- ASM_TRAP();
+ if ( !pVarClass->m_type.Eq(CBotTypClass) &&
+ !pVarClass->m_type.Eq(CBotTypArrayBody))
+ ASM_TRAP();
- ((CBotVarClass*)pVarClass)->IncrementUse(); // une référence en plus
- }
+ ((CBotVarClass*)pVarClass)->IncrementUse(); // une référence en plus
+ }
- if ( m_pInstance != NULL ) m_pInstance->DecrementUse();
- m_pInstance = (CBotVarClass*)pVarClass;
+ if ( m_pInstance != NULL ) m_pInstance->DecrementUse();
+ m_pInstance = (CBotVarClass*)pVarClass;
}
CBotVarClass* CBotVarArray::GivPointer()
{
- if ( m_pInstance == NULL ) return NULL;
- return m_pInstance->GivPointer();
+ if ( m_pInstance == NULL ) return NULL;
+ return m_pInstance->GivPointer();
}
-CBotVar* CBotVarArray::GivItem(int n, BOOL bExtend)
+CBotVar* CBotVarArray::GivItem(int n, bool bExtend)
{
- if ( m_pInstance == NULL )
- {
- if ( !bExtend ) return NULL;
- // crée une instance pour le tableau
+ if ( m_pInstance == NULL )
+ {
+ if ( !bExtend ) return NULL;
+ // crée une instance pour le tableau
- CBotVarClass* instance = new CBotVarClass(NULL, m_type);
- SetPointer( instance );
- }
- return m_pInstance->GivItem(n, bExtend);
+ CBotVarClass* instance = new CBotVarClass(NULL, m_type);
+ SetPointer( instance );
+ }
+ return m_pInstance->GivItem(n, bExtend);
}
CBotVar* CBotVarArray::GivItemList()
{
- if ( m_pInstance == NULL) return NULL;
- return m_pInstance->GivItemList();
+ if ( m_pInstance == NULL) return NULL;
+ return m_pInstance->GivItemList();
}
CBotString CBotVarArray::GivValString()
{
- if ( m_pInstance == NULL ) return ( CBotString( "Null pointer" ) ) ;
- return m_pInstance->GivValString();
+ if ( m_pInstance == NULL ) return ( CBotString( "Null pointer" ) ) ;
+ return m_pInstance->GivValString();
}
-BOOL CBotVarArray::Save1State(FILE* pf)
+bool CBotVarArray::Save1State(FILE* pf)
{
- if ( !WriteType(pf, m_type) ) return FALSE;
- return SaveVar(pf, m_pInstance); // sauve l'instance qui gère le tableau
+ if ( !WriteType(pf, m_type) ) return false;
+ return SaveVar(pf, m_pInstance); // sauve l'instance qui gère le tableau
}
@@ -1876,204 +1876,204 @@ BOOL CBotVarArray::Save1State(FILE* pf)
CBotVarPointer::CBotVarPointer(const CBotToken* name, CBotTypResult& type )
{
- if ( !type.Eq(CBotTypPointer) &&
- !type.Eq(CBotTypNullPointer) &&
- !type.Eq(CBotTypClass) && // par commodité accepte Class et Intrinsic
- !type.Eq(CBotTypIntrinsic) ) ASM_TRAP();
+ if ( !type.Eq(CBotTypPointer) &&
+ !type.Eq(CBotTypNullPointer) &&
+ !type.Eq(CBotTypClass) && // par commodité accepte Class et Intrinsic
+ !type.Eq(CBotTypIntrinsic) ) ASM_TRAP();
- m_token = new CBotToken(name);
- m_next = NULL;
- m_pMyThis = NULL;
- m_pUserPtr = NULL;
+ m_token = new CBotToken(name);
+ m_next = NULL;
+ m_pMyThis = NULL;
+ m_pUserPtr = NULL;
- m_type = type;
- if ( !type.Eq(CBotTypNullPointer) )
- m_type.SetType(CBotTypPointer); // quoi qu'il en soit, c'est un pointeur
- m_binit = FALSE;
- m_pClass = NULL;
- m_pVarClass = NULL; // sera défini par un SetPointer()
+ m_type = type;
+ if ( !type.Eq(CBotTypNullPointer) )
+ m_type.SetType(CBotTypPointer); // quoi qu'il en soit, c'est un pointeur
+ m_binit = false;
+ m_pClass = NULL;
+ m_pVarClass = NULL; // sera défini par un SetPointer()
- SetClass(type.GivClass() );
+ SetClass(type.GivClass() );
}
CBotVarPointer::~CBotVarPointer()
{
- if ( m_pVarClass != NULL ) m_pVarClass->DecrementUse(); // une référence en moins
+ if ( m_pVarClass != NULL ) m_pVarClass->DecrementUse(); // une référence en moins
}
-void CBotVarPointer::Maj(void* pUser, BOOL bContinu)
+void CBotVarPointer::Maj(void* pUser, bool bContinu)
{
-/* if ( !bContinu && m_pMyThis != NULL )
- m_pMyThis->Maj(pUser, FALSE);*/
+/* if ( !bContinu && m_pMyThis != NULL )
+ m_pMyThis->Maj(pUser, false);*/
- if ( m_pVarClass != NULL) m_pVarClass->Maj(pUser, FALSE);
+ if ( m_pVarClass != NULL) m_pVarClass->Maj(pUser, false);
}
CBotVar* CBotVarPointer::GivItem(const char* name)
{
- if ( m_pVarClass == NULL) // pas d'instance existant ?
- return m_pClass->GivItem(name); // rend le pointeur dans la classe elle-même
+ if ( m_pVarClass == NULL) // pas d'instance existant ?
+ return m_pClass->GivItem(name); // rend le pointeur dans la classe elle-même
- return m_pVarClass->GivItem(name);
+ return m_pVarClass->GivItem(name);
}
CBotVar* CBotVarPointer::GivItemRef(int nIdent)
{
- if ( m_pVarClass == NULL) // pas d'instance existant ?
- return m_pClass->GivItemRef(nIdent);// rend le pointeur dans la classe elle-même
+ if ( m_pVarClass == NULL) // pas d'instance existant ?
+ return m_pClass->GivItemRef(nIdent);// rend le pointeur dans la classe elle-même
- return m_pVarClass->GivItemRef(nIdent);
+ return m_pVarClass->GivItemRef(nIdent);
}
CBotVar* CBotVarPointer::GivItemList()
{
- if ( m_pVarClass == NULL) return NULL;
- return m_pVarClass->GivItemList();
+ if ( m_pVarClass == NULL) return NULL;
+ return m_pVarClass->GivItemList();
}
CBotString CBotVarPointer::GivValString()
{
- CBotString s = "Pointer to ";
- if ( m_pVarClass == NULL ) s = "Null pointer" ;
- else s += m_pVarClass->GivValString();
- return s;
+ CBotString s = "Pointer to ";
+ if ( m_pVarClass == NULL ) s = "Null pointer" ;
+ else s += m_pVarClass->GivValString();
+ return s;
}
void CBotVarPointer::ConstructorSet()
{
- if ( m_pVarClass != NULL) m_pVarClass->ConstructorSet();
+ if ( m_pVarClass != NULL) m_pVarClass->ConstructorSet();
}
// initialise le pointeur vers l'instance d'une classe
void CBotVarPointer::SetPointer(CBotVar* pVarClass)
{
- m_binit = TRUE; // init, même sur un pointeur null
+ m_binit = true; // init, même sur un pointeur null
- if ( m_pVarClass == pVarClass) return; // spécial, ne pas décrémenter et réincrémenter
- // car le décrément peut détruire l'object
+ if ( m_pVarClass == pVarClass) return; // spécial, ne pas décrémenter et réincrémenter
+ // car le décrément peut détruire l'object
- if ( pVarClass != NULL )
- {
- if ( pVarClass->GivType() == CBotTypPointer )
- pVarClass = pVarClass->GivPointer(); // le vrai pointeur à l'objet
+ if ( pVarClass != NULL )
+ {
+ if ( pVarClass->GivType() == CBotTypPointer )
+ pVarClass = pVarClass->GivPointer(); // le vrai pointeur à l'objet
-// if ( pVarClass->GivType() != CBotTypClass )
- if ( !pVarClass->m_type.Eq(CBotTypClass) )
- ASM_TRAP();
+// if ( pVarClass->GivType() != CBotTypClass )
+ if ( !pVarClass->m_type.Eq(CBotTypClass) )
+ ASM_TRAP();
- ((CBotVarClass*)pVarClass)->IncrementUse(); // une référence en plus
- m_pClass = ((CBotVarClass*)pVarClass)->m_pClass;
- m_pUserPtr = pVarClass->m_pUserPtr; // pas vraiment indispensable
- m_type = CBotTypResult(CBotTypPointer, m_pClass); // un pointeur de quel genre
- }
+ ((CBotVarClass*)pVarClass)->IncrementUse(); // une référence en plus
+ m_pClass = ((CBotVarClass*)pVarClass)->m_pClass;
+ m_pUserPtr = pVarClass->m_pUserPtr; // pas vraiment indispensable
+ m_type = CBotTypResult(CBotTypPointer, m_pClass); // un pointeur de quel genre
+ }
- if ( m_pVarClass != NULL ) m_pVarClass->DecrementUse();
- m_pVarClass = (CBotVarClass*)pVarClass;
+ if ( m_pVarClass != NULL ) m_pVarClass->DecrementUse();
+ m_pVarClass = (CBotVarClass*)pVarClass;
}
CBotVarClass* CBotVarPointer::GivPointer()
{
- if ( m_pVarClass == NULL ) return NULL;
- return m_pVarClass->GivPointer();
+ if ( m_pVarClass == NULL ) return NULL;
+ return m_pVarClass->GivPointer();
}
void CBotVarPointer::SetIdent(long n)
{
- if ( m_pVarClass == NULL ) return;
- m_pVarClass->SetIdent( n );
+ if ( m_pVarClass == NULL ) return;
+ m_pVarClass->SetIdent( n );
}
long CBotVarPointer::GivIdent()
{
- if ( m_pVarClass == NULL ) return 0;
- return m_pVarClass->m_ItemIdent;
+ if ( m_pVarClass == NULL ) return 0;
+ return m_pVarClass->m_ItemIdent;
}
void CBotVarPointer::SetClass(CBotClass* pClass)
{
-// int nIdent = 0;
- m_type.m_pClass = m_pClass = pClass;
- if ( m_pVarClass != NULL ) m_pVarClass->SetClass(pClass); //, nIdent);
+// int nIdent = 0;
+ m_type.m_pClass = m_pClass = pClass;
+ if ( m_pVarClass != NULL ) m_pVarClass->SetClass(pClass); //, nIdent);
}
CBotClass* CBotVarPointer::GivClass()
{
- if ( m_pVarClass != NULL ) return m_pVarClass->GivClass();
+ if ( m_pVarClass != NULL ) return m_pVarClass->GivClass();
- return m_pClass;
+ return m_pClass;
}
-BOOL CBotVarPointer::Save1State(FILE* pf)
+bool CBotVarPointer::Save1State(FILE* pf)
{
- if ( m_pClass )
- {
- if (!WriteString(pf, m_pClass->GivName())) return FALSE; // nom de la classe
- }
- else
- {
- if (!WriteString(pf, "")) return FALSE;
- }
+ if ( m_pClass )
+ {
+ if (!WriteString(pf, m_pClass->GivName())) return false; // nom de la classe
+ }
+ else
+ {
+ if (!WriteString(pf, "")) return false;
+ }
- if (!WriteLong(pf, GivIdent())) return FALSE; // la référence unique
+ if (!WriteLong(pf, GivIdent())) return false; // la référence unique
- // sauve aussi une copie de l'instance
- return SaveVar(pf, GivPointer());
+ // sauve aussi une copie de l'instance
+ return SaveVar(pf, GivPointer());
}
// copie une variable dans une autre
-void CBotVarPointer::Copy(CBotVar* pSrc, BOOL bName)
+void CBotVarPointer::Copy(CBotVar* pSrc, bool bName)
{
- if ( pSrc->GivType() != CBotTypPointer &&
- pSrc->GivType() != CBotTypNullPointer)
- ASM_TRAP();
+ if ( pSrc->GivType() != CBotTypPointer &&
+ pSrc->GivType() != CBotTypNullPointer)
+ ASM_TRAP();
- CBotVarPointer* p = (CBotVarPointer*)pSrc;
+ CBotVarPointer* p = (CBotVarPointer*)pSrc;
- if ( bName) *m_token = *p->m_token;
- m_type = p->m_type;
-// m_pVarClass = p->m_pVarClass;
- m_pVarClass = p->GivPointer();
+ if ( bName) *m_token = *p->m_token;
+ m_type = p->m_type;
+// m_pVarClass = p->m_pVarClass;
+ m_pVarClass = p->GivPointer();
- if ( m_pVarClass != NULL )
- m_pVarClass->IncrementUse(); // une référence en plus
+ if ( m_pVarClass != NULL )
+ m_pVarClass->IncrementUse(); // une référence en plus
- m_pClass = p->m_pClass;
- m_binit = p->m_binit;
-//- m_bStatic = p->m_bStatic;
- m_next = NULL;
- m_pMyThis = NULL;//p->m_pMyThis;
- m_pUserPtr = p->m_pUserPtr;
+ m_pClass = p->m_pClass;
+ m_binit = p->m_binit;
+//- m_bStatic = p->m_bStatic;
+ m_next = NULL;
+ m_pMyThis = NULL;//p->m_pMyThis;
+ m_pUserPtr = p->m_pUserPtr;
- // garde le même idendificateur (par défaut)
- if (m_ident == 0 ) m_ident = p->m_ident;
+ // garde le même idendificateur (par défaut)
+ if (m_ident == 0 ) m_ident = p->m_ident;
}
-BOOL CBotVarPointer::Eq(CBotVar* left, CBotVar* right)
+bool CBotVarPointer::Eq(CBotVar* left, CBotVar* right)
{
- CBotVarClass* l = left->GivPointer();
- CBotVarClass* r = right->GivPointer();
+ CBotVarClass* l = left->GivPointer();
+ CBotVarClass* r = right->GivPointer();
- if ( l == r ) return TRUE;
- if ( l == NULL && r->GivUserPtr() == OBJECTDELETED ) return TRUE;
- if ( r == NULL && l->GivUserPtr() == OBJECTDELETED ) return TRUE;
- return FALSE;
+ if ( l == r ) return true;
+ if ( l == NULL && r->GivUserPtr() == OBJECTDELETED ) return true;
+ if ( r == NULL && l->GivUserPtr() == OBJECTDELETED ) return true;
+ return false;
}
-BOOL CBotVarPointer::Ne(CBotVar* left, CBotVar* right)
+bool CBotVarPointer::Ne(CBotVar* left, CBotVar* right)
{
- CBotVarClass* l = left->GivPointer();
- CBotVarClass* r = right->GivPointer();
+ CBotVarClass* l = left->GivPointer();
+ CBotVarClass* r = right->GivPointer();
- if ( l == r ) return FALSE;
- if ( l == NULL && r->GivUserPtr() == OBJECTDELETED ) return FALSE;
- if ( r == NULL && l->GivUserPtr() == OBJECTDELETED ) return FALSE;
- return TRUE;
+ if ( l == r ) return false;
+ if ( l == NULL && r->GivUserPtr() == OBJECTDELETED ) return false;
+ if ( r == NULL && l->GivUserPtr() == OBJECTDELETED ) return false;
+ return true;
}
@@ -2084,162 +2084,162 @@ BOOL CBotVarPointer::Ne(CBotVar* left, CBotVar* right)
CBotTypResult::CBotTypResult(int type)
{
- m_type = type;
- m_pNext = NULL;
- m_pClass = NULL;
- m_limite = -1;
+ m_type = type;
+ m_pNext = NULL;
+ m_pClass = NULL;
+ m_limite = -1;
}
CBotTypResult::CBotTypResult(int type, const char* name)
{
- m_type = type;
- m_pNext = NULL;
- m_pClass = NULL;
- m_limite = -1;
+ m_type = type;
+ m_pNext = NULL;
+ m_pClass = NULL;
+ m_limite = -1;
- if ( type == CBotTypPointer ||
- type == CBotTypClass ||
- type == CBotTypIntrinsic )
- {
- m_pClass = CBotClass::Find(name);
- if ( m_pClass && m_pClass->IsIntrinsic() ) m_type = CBotTypIntrinsic;
- }
+ if ( type == CBotTypPointer ||
+ type == CBotTypClass ||
+ type == CBotTypIntrinsic )
+ {
+ m_pClass = CBotClass::Find(name);
+ if ( m_pClass && m_pClass->IsIntrinsic() ) m_type = CBotTypIntrinsic;
+ }
}
CBotTypResult::CBotTypResult(int type, CBotClass* pClass)
{
- m_type = type;
- m_pNext = NULL;
- m_pClass = pClass;
- m_limite = -1;
+ m_type = type;
+ m_pNext = NULL;
+ m_pClass = pClass;
+ m_limite = -1;
- if ( m_pClass && m_pClass->IsIntrinsic() ) m_type = CBotTypIntrinsic;
+ if ( m_pClass && m_pClass->IsIntrinsic() ) m_type = CBotTypIntrinsic;
}
CBotTypResult::CBotTypResult(int type, CBotTypResult elem)
{
- m_type = type;
- m_pNext = NULL;
- m_pClass = NULL;
- m_limite = -1;
+ m_type = type;
+ m_pNext = NULL;
+ m_pClass = NULL;
+ m_limite = -1;
- if ( type == CBotTypArrayPointer ||
- type == CBotTypArrayBody )
- m_pNext = new CBotTypResult( elem );
+ if ( type == CBotTypArrayPointer ||
+ type == CBotTypArrayBody )
+ m_pNext = new CBotTypResult( elem );
}
CBotTypResult::CBotTypResult(const CBotTypResult& typ)
{
- m_type = typ.m_type;
- m_pClass = typ.m_pClass;
- m_pNext = NULL;
- m_limite = typ.m_limite;
+ m_type = typ.m_type;
+ m_pClass = typ.m_pClass;
+ m_pNext = NULL;
+ m_limite = typ.m_limite;
- if ( typ.m_pNext )
- m_pNext = new CBotTypResult( *typ.m_pNext );
+ if ( typ.m_pNext )
+ m_pNext = new CBotTypResult( *typ.m_pNext );
}
CBotTypResult::CBotTypResult()
{
- m_type = 0;
- m_limite = -1;
- m_pNext = NULL;
- m_pClass = NULL;
+ m_type = 0;
+ m_limite = -1;
+ m_pNext = NULL;
+ m_pClass = NULL;
}
CBotTypResult::~CBotTypResult()
{
- delete m_pNext;
+ delete m_pNext;
}
int CBotTypResult::GivType(int mode) const
{
-#ifdef _DEBUG
- if ( m_type == CBotTypPointer ||
- m_type == CBotTypClass ||
- m_type == CBotTypIntrinsic )
+#ifdef _DEBUG
+ if ( m_type == CBotTypPointer ||
+ m_type == CBotTypClass ||
+ m_type == CBotTypIntrinsic )
- if ( m_pClass == NULL ) ASM_TRAP();
+ if ( m_pClass == NULL ) ASM_TRAP();
-
- if ( m_type == CBotTypArrayPointer )
- if ( m_pNext == NULL ) ASM_TRAP();
+
+ if ( m_type == CBotTypArrayPointer )
+ if ( m_pNext == NULL ) ASM_TRAP();
#endif
- if ( mode == 3 && m_type == CBotTypNullPointer ) return CBotTypPointer;
- return m_type;
+ if ( mode == 3 && m_type == CBotTypNullPointer ) return CBotTypPointer;
+ return m_type;
}
void CBotTypResult::SetType(int n)
{
- m_type = n;
+ m_type = n;
}
CBotClass* CBotTypResult::GivClass() const
{
- return m_pClass;
+ return m_pClass;
}
CBotTypResult& CBotTypResult::GivTypElem() const
{
- return *m_pNext;
+ return *m_pNext;
}
int CBotTypResult::GivLimite() const
{
- return m_limite;
+ return m_limite;
}
void CBotTypResult::SetLimite(int n)
{
- m_limite = n;
+ m_limite = n;
}
void CBotTypResult::SetArray( int* max )
{
- m_limite = *max;
- if (m_limite < 1) m_limite = -1;
+ m_limite = *max;
+ if (m_limite < 1) m_limite = -1;
- if ( m_pNext != NULL ) // dernière dimension ?
- {
- m_pNext->SetArray( max+1 );
- }
+ if ( m_pNext != NULL ) // dernière dimension ?
+ {
+ m_pNext->SetArray( max+1 );
+ }
}
-BOOL CBotTypResult::Compare(const CBotTypResult& typ) const
+bool CBotTypResult::Compare(const CBotTypResult& typ) const
{
- if ( m_type != typ.m_type ) return FALSE;
+ if ( m_type != typ.m_type ) return false;
- if ( m_type == CBotTypArrayPointer ) return m_pNext->Compare(*typ.m_pNext);
+ if ( m_type == CBotTypArrayPointer ) return m_pNext->Compare(*typ.m_pNext);
- if ( m_type == CBotTypPointer ||
- m_type == CBotTypClass ||
- m_type == CBotTypIntrinsic )
- {
- return m_pClass == typ.m_pClass;
- }
+ if ( m_type == CBotTypPointer ||
+ m_type == CBotTypClass ||
+ m_type == CBotTypIntrinsic )
+ {
+ return m_pClass == typ.m_pClass;
+ }
- return TRUE;
+ return true;
}
-BOOL CBotTypResult::Eq(int type) const
+bool CBotTypResult::Eq(int type) const
{
- return m_type == type;
+ return m_type == type;
}
CBotTypResult&
- CBotTypResult::operator=(const CBotTypResult& src)
-{
- m_type = src.m_type;
- m_limite = src.m_limite;
- m_pClass = src.m_pClass;
- m_pNext = NULL;
- if ( src.m_pNext != NULL )
- {
- m_pNext = new CBotTypResult(*src.m_pNext);
- }
- return *this;
+ CBotTypResult::operator=(const CBotTypResult& src)
+{
+ m_type = src.m_type;
+ m_limite = src.m_limite;
+ m_pClass = src.m_pClass;
+ m_pNext = NULL;
+ if ( src.m_pNext != NULL )
+ {
+ m_pNext = new CBotTypResult(*src.m_pNext);
+ }
+ return *this;
}
diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp
index 124fb3d..fcb825c 100644
--- a/src/CBot/CBotWhile.cpp
+++ b/src/CBot/CBotWhile.cpp
@@ -66,7 +66,7 @@ CBotInstr* CBotWhile::Compile(CBotToken* &p, CBotCStack* pStack)
// la condition existe
IncLvl(inst->m_label);
- inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, TRUE );
+ inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true );
DecLvl();
if ( pStk->IsOk() )
@@ -83,31 +83,31 @@ CBotInstr* CBotWhile::Compile(CBotToken* &p, CBotCStack* pStack)
// exécute une instruction "while"
-BOOL CBotWhile :: Execute(CBotStack* &pj)
+bool CBotWhile :: Execute(CBotStack* &pj)
{
CBotStack* pile = pj->AddStack(this); // ajoute un élément à la pile
// ou le retrouve en cas de reprise
-// if ( pile == EOX ) return TRUE;
+// if ( pile == EOX ) return true;
- if ( pile->IfStep() ) return FALSE;
+ if ( pile->IfStep() ) return false;
- while( TRUE ) switch( pile->GivState() ) // exécute la boucle
+ while( true ) switch( pile->GivState() ) // exécute la boucle
{ // il y a 2 états possibles (selon reprise)
case 0:
// évalue la condition
- if ( !m_Condition->Execute(pile) ) return FALSE; // interrompu ici ?
+ if ( !m_Condition->Execute(pile) ) return false; // interrompu ici ?
// le résultat de la condition est sur la pile
// termine s'il y a une erreur ou si la condition est fausse
- if ( !pile->IsOk() || pile->GivVal() != TRUE )
+ if ( !pile->IsOk() || pile->GivVal() != true )
{
return pj->Return(pile); // transmet le résultat et libère la pile
}
// la condition est vrai, passe dans le second mode
- if (!pile->SetState(1)) return FALSE; // prêt pour la suite
+ if (!pile->SetState(1)) return false; // prêt pour la suite
case 1:
// évalue le bloc d'instruction associé
@@ -125,12 +125,12 @@ BOOL CBotWhile :: Execute(CBotStack* &pj)
}
// repasse au test pour recommencer
- if (!pile->SetState(0, 0)) return FALSE;
+ if (!pile->SetState(0, 0)) return false;
continue;
}
}
-void CBotWhile :: RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain)
{
if ( !bMain ) return;
CBotStack* pile = pj->RestoreStack(this); // ajoute un élément à la pile
@@ -196,7 +196,7 @@ CBotInstr* CBotRepeat::Compile(CBotToken* &p, CBotCStack* pStack)
{
IncLvl(inst->m_label);
- inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, TRUE );
+ inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true );
DecLvl();
if ( pStk->IsOk() )
@@ -221,19 +221,19 @@ CBotInstr* CBotRepeat::Compile(CBotToken* &p, CBotCStack* pStack)
// exécute une instruction "repeat"
-BOOL CBotRepeat :: Execute(CBotStack* &pj)
+bool CBotRepeat :: Execute(CBotStack* &pj)
{
CBotStack* pile = pj->AddStack(this); // ajoute un élément à la pile
// ou le retrouve en cas de reprise
-// if ( pile == EOX ) return TRUE;
+// if ( pile == EOX ) return true;
- if ( pile->IfStep() ) return FALSE;
+ if ( pile->IfStep() ) return false;
- while( TRUE ) switch( pile->GivState() ) // exécute la boucle
+ while( true ) switch( pile->GivState() ) // exécute la boucle
{ // il y a 2 états possibles (selon reprise)
case 0:
// évalue le nombre d'itération
- if ( !m_NbIter->Execute(pile) ) return FALSE; // interrompu ici ?
+ if ( !m_NbIter->Execute(pile) ) return false; // interrompu ici ?
// le résultat de la condition est sur la pile
@@ -246,7 +246,7 @@ BOOL CBotRepeat :: Execute(CBotStack* &pj)
// met le nombre d'itération +1 dans le "state"
- if (!pile->SetState(n+1)) return FALSE; // prêt pour la suite
+ if (!pile->SetState(n+1)) return false; // prêt pour la suite
continue; // passe à la suite
case 1:
@@ -269,12 +269,12 @@ BOOL CBotRepeat :: Execute(CBotStack* &pj)
}
// repasse au test pour recommencer
- if (!pile->SetState(pile->GivState()-1, 0)) return FALSE;
+ if (!pile->SetState(pile->GivState()-1, 0)) return false;
continue;
}
}
-void CBotRepeat :: RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotRepeat :: RestoreState(CBotStack* &pj, bool bMain)
{
if ( !bMain ) return;
CBotStack* pile = pj->RestoreStack(this); // ajoute un élément à la pile
@@ -332,7 +332,7 @@ CBotInstr* CBotDo::Compile(CBotToken* &p, CBotCStack* pStack)
// cherche un bloc d'instruction après le do
IncLvl(inst->m_label);
- inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, TRUE );
+ inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true );
DecLvl();
if ( pStk->IsOk() )
@@ -358,15 +358,15 @@ CBotInstr* CBotDo::Compile(CBotToken* &p, CBotCStack* pStack)
// exécute une instruction "do"
-BOOL CBotDo :: Execute(CBotStack* &pj)
+bool CBotDo :: Execute(CBotStack* &pj)
{
CBotStack* pile = pj->AddStack(this); // ajoute un élément à la pile
// ou le retrouve en cas de reprise
-// if ( pile == EOX ) return TRUE;
+// if ( pile == EOX ) return true;
- if ( pile->IfStep() ) return FALSE;
+ if ( pile->IfStep() ) return false;
- while( TRUE ) switch( pile->GivState() ) // exécute la boucle
+ while( true ) switch( pile->GivState() ) // exécute la boucle
{ // il y a 2 états possibles (selon reprise)
case 0:
// évalue le bloc d'instruction associé
@@ -383,27 +383,27 @@ BOOL CBotDo :: Execute(CBotStack* &pj)
return pj->Return(pile); // transmet le résultat et libère la pile
}
- if (!pile->SetState(1)) return FALSE; // prêt pour la suite
+ if (!pile->SetState(1)) return false; // prêt pour la suite
case 1:
// évalue la condition
- if ( !m_Condition->Execute(pile) ) return FALSE; // interrompu ici ?
+ if ( !m_Condition->Execute(pile) ) return false; // interrompu ici ?
// le résultat de la condition est sur la pile
// termine s'il y a une erreur ou si la condition est fausse
- if ( !pile->IsOk() || pile->GivVal() != TRUE )
+ if ( !pile->IsOk() || pile->GivVal() != true )
{
return pj->Return(pile); // transmet le résultat et libère la pile
}
// repasse au bloc d'instruction pour recommencer
- if (!pile->SetState(0, 0)) return FALSE;
+ if (!pile->SetState(0, 0)) return false;
continue;
}
}
-void CBotDo :: RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotDo :: RestoreState(CBotStack* &pj, bool bMain)
{
if ( !bMain ) return;
@@ -467,7 +467,7 @@ CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack)
return NULL;
}
- CBotCStack* pStk = pStack->TokenStack(pp, TRUE); // un petit bout de pile svp
+ CBotCStack* pStk = pStack->TokenStack(pp, true); // un petit bout de pile svp
// compile les instructions pour initialisation
inst->m_Init = CBotListExpression::Compile( p, pStk );
@@ -494,7 +494,7 @@ CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack)
if ( IsOfType(p, ID_CLOSEPAR)) // manque la parenthèse ?
{
IncLvl(inst->m_label);
- inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, TRUE );
+ inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true );
DecLvl();
if ( pStk->IsOk() )
return pStack->Return(inst, pStk);;
@@ -510,39 +510,39 @@ CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack)
// exécute l'instruction "for"
-BOOL CBotFor :: Execute(CBotStack* &pj)
+bool CBotFor :: Execute(CBotStack* &pj)
{
- CBotStack* pile = pj->AddStack(this, TRUE); // ajoute un élément à la pile (variables locales)
+ CBotStack* pile = pj->AddStack(this, true); // ajoute un élément à la pile (variables locales)
// ou le retrouve en cas de reprise
-// if ( pile == EOX ) return TRUE;
+// if ( pile == EOX ) return true;
- if ( pile->IfStep() ) return FALSE;
+ if ( pile->IfStep() ) return false;
- while( TRUE ) switch( pile->GivState() ) // exécute la boucle
+ while( true ) switch( pile->GivState() ) // exécute la boucle
{ // il y a 4 états possibles (selon reprise)
case 0:
// évalue l'initialisation
if ( m_Init != NULL &&
- !m_Init->Execute(pile) ) return FALSE; // interrompu ici ?
- if (!pile->SetState(1)) return FALSE; // prêt pour la suite
+ !m_Init->Execute(pile) ) return false; // interrompu ici ?
+ if (!pile->SetState(1)) return false; // prêt pour la suite
case 1:
// évalue la condition
if ( m_Test != NULL ) // pas de condition ? -> vrai !
{
- if (!m_Test->Execute(pile) ) return FALSE; // interrompu ici ?
+ if (!m_Test->Execute(pile) ) return false; // interrompu ici ?
// le résultat de la condition est sur la pile
// termine s'il y a une erreur ou si la condition est fausse
- if ( !pile->IsOk() || pile->GivVal() != TRUE )
+ if ( !pile->IsOk() || pile->GivVal() != true )
{
return pj->Return(pile); // transmet le résultat et libère la pile
}
}
// la condition est vrai, passe à la suite
- if (!pile->SetState(2)) return FALSE; // prêt pour la suite
+ if (!pile->SetState(2)) return false; // prêt pour la suite
case 2:
// évalue le bloc d'instruction associé
@@ -559,20 +559,20 @@ BOOL CBotFor :: Execute(CBotStack* &pj)
return pj->Return(pile); // transmet le résultat et libère la pile
}
- if (!pile->SetState(3)) return FALSE; // prêt pour la suite
+ if (!pile->SetState(3)) return false; // prêt pour la suite
case 3:
// évalue l'incrémentation
if ( m_Incr != NULL &&
- !m_Incr->Execute(pile) ) return FALSE; // interrompu ici ?
+ !m_Incr->Execute(pile) ) return false; // interrompu ici ?
// repasse au test pour recommencer
- if (!pile->SetState(1, 0)) return FALSE; // revient au test
+ if (!pile->SetState(1, 0)) return false; // revient au test
continue;
}
}
-void CBotFor :: RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotFor :: RestoreState(CBotStack* &pj, bool bMain)
{
if ( !bMain ) return;
@@ -583,28 +583,28 @@ void CBotFor :: RestoreState(CBotStack* &pj, BOOL bMain)
{ // il y a 4 états possibles (selon reprise)
case 0:
// évalue l'initialisation
- if ( m_Init != NULL ) m_Init->RestoreState(pile, TRUE); // interrompu ici !
+ if ( m_Init != NULL ) m_Init->RestoreState(pile, true); // interrompu ici !
return;
case 1:
- if ( m_Init != NULL ) m_Init->RestoreState(pile, FALSE); // définitions variables
+ if ( m_Init != NULL ) m_Init->RestoreState(pile, false); // définitions variables
// évalue la condition
- if ( m_Test != NULL ) m_Test->RestoreState(pile, TRUE); // interrompu ici !
+ if ( m_Test != NULL ) m_Test->RestoreState(pile, true); // interrompu ici !
return;
case 2:
- if ( m_Init != NULL ) m_Init->RestoreState(pile, FALSE); // définitions variables
+ if ( m_Init != NULL ) m_Init->RestoreState(pile, false); // définitions variables
// évalue le bloc d'instruction associé
- if ( m_Block != NULL ) m_Block->RestoreState(pile, TRUE);
+ if ( m_Block != NULL ) m_Block->RestoreState(pile, true);
return;
case 3:
- if ( m_Init != NULL ) m_Init->RestoreState(pile, FALSE); // définitions variables
+ if ( m_Init != NULL ) m_Init->RestoreState(pile, false); // définitions variables
// évalue l'incrémentation
- if ( m_Incr != NULL ) m_Incr->RestoreState(pile, TRUE); // interrompu ici !
+ if ( m_Incr != NULL ) m_Incr->RestoreState(pile, true); // interrompu ici !
return;
}
}
@@ -629,10 +629,10 @@ CBotListExpression::~CBotListExpression()
static CBotInstr* CompileInstrOrDefVar(CBotToken* &p, CBotCStack* pStack)
{
- CBotInstr* i = CBotInt::Compile( p, pStack, FALSE, TRUE ); // est-ce une déclaration d'un entier ?
- if ( i== NULL ) i = CBotFloat::Compile( p, pStack, FALSE, TRUE ); // ou d'un nombre réel ?
- if ( i== NULL ) i = CBotBoolean::Compile( p, pStack, FALSE, TRUE ); // ou d'un booléen ?
- if ( i== NULL ) i = CBotIString::Compile( p, pStack, FALSE, TRUE ); // ou d'une chaîne ?
+ CBotInstr* i = CBotInt::Compile( p, pStack, false, true ); // est-ce une déclaration d'un entier ?
+ if ( i== NULL ) i = CBotFloat::Compile( p, pStack, false, true ); // ou d'un nombre réel ?
+ if ( i== NULL ) i = CBotBoolean::Compile( p, pStack, false, true ); // ou d'un booléen ?
+ if ( i== NULL ) i = CBotIString::Compile( p, pStack, false, true ); // ou d'une chaîne ?
if ( i== NULL ) i = CBotExpression::Compile( p, pStack ); // compile une expression
return i;
}
@@ -660,7 +660,7 @@ CBotInstr* CBotListExpression::Compile(CBotToken* &p, CBotCStack* pStack)
return NULL;
}
-BOOL CBotListExpression::Execute(CBotStack* &pj)
+bool CBotListExpression::Execute(CBotStack* &pj)
{
CBotStack* pile = pj->AddStack();// indispensable
CBotInstr* p = m_Expr; // la première expression
@@ -668,17 +668,17 @@ BOOL CBotListExpression::Execute(CBotStack* &pj)
int state = pile->GivState();
while (state-->0) p = p->GivNext(); // revient sur l'opération interrompue
- if ( p != NULL ) while (TRUE)
+ if ( p != NULL ) while (true)
{
- if ( !p->Execute(pile) ) return FALSE;
+ if ( !p->Execute(pile) ) return false;
p = p->GivNext();
if ( p == NULL ) break;
- if (!pile->IncState()) return FALSE; // prêt pour la suivante
+ if (!pile->IncState()) return false; // prêt pour la suivante
}
return pj->Return(pile);
}
-void CBotListExpression::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotListExpression::RestoreState(CBotStack* &pj, bool bMain)
{
CBotStack* pile = pj;
int state = 0x7000;
@@ -694,7 +694,7 @@ void CBotListExpression::RestoreState(CBotStack* &pj, BOOL bMain)
while (p != NULL && state-->0)
{
- p->RestoreState(pile, FALSE);
+ p->RestoreState(pile, false);
p = p->GivNext(); // revient sur l'opération interrompue
}
@@ -770,7 +770,7 @@ CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack)
return pStack->Return(NULL, pStk);
}
- CBotInstr* i = CBotBlock::CompileBlkOrInst( p, pStk, TRUE );
+ CBotInstr* i = CBotBlock::CompileBlkOrInst( p, pStk, true );
if ( !pStk->IsOk() )
{
delete inst;
@@ -811,21 +811,21 @@ CBotInstr* CBotSwitch::Compile(CBotToken* &p, CBotCStack* pStack)
// exécute une instruction "switch"
-BOOL CBotSwitch :: Execute(CBotStack* &pj)
+bool CBotSwitch :: Execute(CBotStack* &pj)
{
CBotStack* pile1 = pj->AddStack(this); // ajoute un élément à la pile
-// if ( pile1 == EOX ) return TRUE;
+// if ( pile1 == EOX ) return true;
CBotInstr* p = m_Block; // la première expression
int state = pile1->GivState();
if (state == 0)
{
- if ( !m_Value->Execute(pile1) ) return FALSE;
+ if ( !m_Value->Execute(pile1) ) return false;
pile1->SetState(state = -1);
}
- if ( pile1->IfStep() ) return FALSE;
+ if ( pile1->IfStep() ) return false;
if ( state == -1 )
{
@@ -843,7 +843,7 @@ BOOL CBotSwitch :: Execute(CBotStack* &pj)
if ( p == NULL ) return pj->Return(pile1); // terminé si plus rien
- if ( !pile1->SetState(state) ) return FALSE;
+ if ( !pile1->SetState(state) ) return false;
}
p = m_Block; // revient au début
@@ -852,13 +852,13 @@ BOOL CBotSwitch :: Execute(CBotStack* &pj)
while( p != NULL )
{
if ( !p->Execute(pile1) ) return pj->BreakReturn(pile1);
- if ( !pile1->IncState() ) return FALSE;
+ if ( !pile1->IncState() ) return false;
p = p->GivNext();
}
return pj->Return(pile1);
}
-void CBotSwitch :: RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotSwitch :: RestoreState(CBotStack* &pj, bool bMain)
{
if ( !bMain ) return;
@@ -882,13 +882,13 @@ void CBotSwitch :: RestoreState(CBotStack* &pj, BOOL bMain)
// p = m_Block; // revient au début
while ( p != NULL && state-- > 0 )
{
- p->RestoreState(pile1, FALSE);
+ p->RestoreState(pile1, false);
p = p->GivNext(); // avance dans la liste
}
if( p != NULL )
{
- p->RestoreState(pile1, TRUE);
+ p->RestoreState(pile1, true);
return;
}
}
@@ -942,21 +942,21 @@ CBotInstr* CBotCase::Compile(CBotToken* &p, CBotCStack* pStack)
// exécution de l'instruction "case"
-BOOL CBotCase::Execute(CBotStack* &pj)
+bool CBotCase::Execute(CBotStack* &pj)
{
- return TRUE; // l'instruction "case" ne fait rien !
+ return true; // l'instruction "case" ne fait rien !
}
-void CBotCase::RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotCase::RestoreState(CBotStack* &pj, bool bMain)
{
}
// routine permettant de trouver le point d'entrée "case"
// correspondant à la valeur cherchée
-BOOL CBotCase::CompCase(CBotStack* &pile, int val)
+bool CBotCase::CompCase(CBotStack* &pile, int val)
{
- if ( m_Value == NULL ) return TRUE; // cas pour "default"
+ if ( m_Value == NULL ) return true; // cas pour "default"
while (!m_Value->Execute(pile)); // met sur la pile la valeur correpondant (sans interruption)
return (pile->GivVal() == val); // compare avec la valeur cherchée
@@ -1016,18 +1016,18 @@ CBotInstr* CBotBreak::Compile(CBotToken* &p, CBotCStack* pStack)
// exécution l'instructino "break" ou "continu"
-BOOL CBotBreak :: Execute(CBotStack* &pj)
+bool CBotBreak :: Execute(CBotStack* &pj)
{
CBotStack* pile = pj->AddStack(this);
-// if ( pile == EOX ) return TRUE;
+// if ( pile == EOX ) return true;
- if ( pile->IfStep() ) return FALSE;
+ if ( pile->IfStep() ) return false;
pile->SetBreak(m_token.GivType()==ID_BREAK ? 1 : 2, m_label);
return pj->Return(pile);
}
-void CBotBreak :: RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotBreak :: RestoreState(CBotStack* &pj, bool bMain)
{
if ( bMain ) pj->RestoreStack(this);
}
@@ -1092,14 +1092,14 @@ CBotInstr* CBotTry::Compile(CBotToken* &p, CBotCStack* pStack)
// les arrêts par suspension
// et les "finaly"
-BOOL CBotTry :: Execute(CBotStack* &pj)
+bool CBotTry :: Execute(CBotStack* &pj)
{
int val;
CBotStack* pile1 = pj->AddStack(this); // ajoute un élément à la pile
-// if ( pile1 == EOX ) return TRUE;
+// if ( pile1 == EOX ) return true;
- if ( pile1->IfStep() ) return FALSE;
+ if ( pile1->IfStep() ) return false;
// ou le retrouve en cas de reprise
CBotStack* pile0 = pj->AddStack2(); // ajoute un élément à la pile secondaire
CBotStack* pile2 = pile0->AddStack();
@@ -1114,14 +1114,14 @@ BOOL CBotTry :: Execute(CBotStack* &pj)
val = pile1->GivError();
if ( val == 0 && CBotStack::m_initimer == 0 ) // en mode de step ?
- return FALSE; // ne fait pas le catch
+ return false; // ne fait pas le catch
pile1->IncState();
pile2->SetState(val); // mémorise le numéro de l'erreur
pile1->SetError(0); // pour l'instant il n'y a plus d'erreur !
if ( val == 0 && CBotStack::m_initimer < 0 ) // en mode de step ?
- return FALSE; // ne fait pas le catch
+ return false; // ne fait pas le catch
}
// il y a eu une interruption
@@ -1137,16 +1137,16 @@ BOOL CBotTry :: Execute(CBotStack* &pj)
if ( --state <= 0 )
{
// demande au bloc catch s'il se sent concerné
- if ( !pc->TestCatch(pile2, val) ) return FALSE; // suspendu !
+ if ( !pc->TestCatch(pile2, val) ) return false; // suspendu !
pile1->IncState();
}
if ( --state <= 0 )
{
- if ( pile2->GivVal() == TRUE )
+ if ( pile2->GivVal() == true )
{
// pile0->SetState(1);
- if ( !pc->Execute(pile2) ) return FALSE; // exécute l'opération
+ if ( !pc->Execute(pile2) ) return false; // exécute l'opération
if ( m_FinalInst == NULL )
return pj->Return(pile2); // termine le try
@@ -1164,7 +1164,7 @@ BOOL CBotTry :: Execute(CBotStack* &pj)
{
// pile0->SetState(1);
- if (!m_FinalInst->Execute(pile2) && pile2->IsOk()) return FALSE;
+ if (!m_FinalInst->Execute(pile2) && pile2->IsOk()) return false;
if (!pile2->IsOk()) return pj->Return(pile2); // garde cette exception
pile2->SetError(pile1->GivState()==-1 ? val : 0); // remet l'erreur initiale
return pj->Return(pile2);
@@ -1176,11 +1176,11 @@ BOOL CBotTry :: Execute(CBotStack* &pj)
return pj->Return(pile2); // termine le try sans exception aucune
pile1->SetError(val); // remet l'erreur
- return FALSE; // ce n'est pas pour nous
+ return false; // ce n'est pas pour nous
}
-void CBotTry :: RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotTry :: RestoreState(CBotStack* &pj, bool bMain)
{
if ( !bMain ) return;
@@ -1217,7 +1217,7 @@ void CBotTry :: RestoreState(CBotStack* &pj, BOOL bMain)
}
if ( --state <= 0 )
{
- if ( pile2->GivVal() == TRUE )
+ if ( pile2->GivVal() == true )
{
pc->RestoreState(pile2, bMain); // exécute l'opération
return;
@@ -1285,27 +1285,27 @@ CBotCatch* CBotCatch::Compile(CBotToken* &p, CBotCStack* pStack)
// exécution de "catch"
-BOOL CBotCatch :: Execute(CBotStack* &pj)
+bool CBotCatch :: Execute(CBotStack* &pj)
{
- if ( m_Block == NULL ) return TRUE;
+ if ( m_Block == NULL ) return true;
return m_Block->Execute(pj); // exécute le bloc associé
}
-void CBotCatch :: RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotCatch :: RestoreState(CBotStack* &pj, bool bMain)
{
if ( bMain && m_Block != NULL ) m_Block->RestoreState(pj, bMain);
}
-void CBotCatch :: RestoreCondState(CBotStack* &pj, BOOL bMain)
+void CBotCatch :: RestoreCondState(CBotStack* &pj, bool bMain)
{
m_Cond->RestoreState(pj, bMain);
}
// routine pour savoir si le catch est à faire ou non
-BOOL CBotCatch :: TestCatch(CBotStack* &pile, int val)
+bool CBotCatch :: TestCatch(CBotStack* &pile, int val)
{
- if ( !m_Cond->Execute(pile) ) return FALSE;
+ if ( !m_Cond->Execute(pile) ) return false;
if ( val > 0 || pile->GivType() != CBotTypBoolean )
{
@@ -1314,7 +1314,7 @@ BOOL CBotCatch :: TestCatch(CBotStack* &pile, int val)
pile->SetVar(var); // remet sur la pile
}
- return TRUE;
+ return true;
}
///////////////////////////////////////////////////////////////////////////
@@ -1359,18 +1359,18 @@ CBotInstr* CBotThrow::Compile(CBotToken* &p, CBotCStack* pStack)
// exécute l'instruction "throw"
-BOOL CBotThrow :: Execute(CBotStack* &pj)
+bool CBotThrow :: Execute(CBotStack* &pj)
{
CBotStack* pile = pj->AddStack(this);
-// if ( pile == EOX ) return TRUE;
+// if ( pile == EOX ) return true;
if ( pile->GivState() == 0 )
{
- if ( !m_Value->Execute(pile) ) return FALSE;
+ if ( !m_Value->Execute(pile) ) return false;
pile->IncState();
}
- if ( pile->IfStep() ) return FALSE;
+ if ( pile->IfStep() ) return false;
int val = pile->GivVal();
if ( val < 0 ) val = TX_BADTHROW;
@@ -1378,7 +1378,7 @@ BOOL CBotThrow :: Execute(CBotStack* &pj)
return pj->Return( pile );
}
-void CBotThrow :: RestoreState(CBotStack* &pj, BOOL bMain)
+void CBotThrow :: RestoreState(CBotStack* &pj, bool bMain)
{
if ( !bMain ) return;
@@ -1417,11 +1417,11 @@ CBotInstr* CBotStartDebugDD::Compile(CBotToken* &p, CBotCStack* pStack)
// exécute l'instruction "throw"
-BOOL CBotStartDebugDD :: Execute(CBotStack* &pj)
+bool CBotStartDebugDD :: Execute(CBotStack* &pj)
{
CBotProgram* p = pj->GivBotCall();
- p->m_bDebugDD = TRUE;
+ p->m_bDebugDD = true;
- return TRUE;
+ return true;
}
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index 9933e9c..409ef3b 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -10,7 +10,6 @@ CBotToken.cpp
CBotTwoOpExpr.cpp
CBotVar.cpp
CBotWhile.cpp
-CBot.rc
)
add_library(CBot SHARED ${SOURCES})
diff --git a/src/CBot/ClassFILE.cpp b/src/CBot/ClassFILE.cpp
index e4dd578..330e814 100644
--- a/src/CBot/ClassFILE.cpp
+++ b/src/CBot/ClassFILE.cpp
@@ -58,7 +58,7 @@ void PrepareFilename(CBotString &filename) //DD!
// reçois le nom du fichier en paramètre
// exécution
-BOOL rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
+bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
CBotString mode;
@@ -132,7 +132,7 @@ CBotTypResult cfconstruct (CBotVar* pThis, CBotVar* &pVar)
// destructeur de la classe
// exécution
-BOOL rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
+bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// récupère l'élément "handle"
pVar = pThis->GivItem("handle");
@@ -154,7 +154,7 @@ BOOL rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception
// reçois le mode r/w en paramètre
// exécution
-BOOL rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
+bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// il doit y avoir un paramètre
if ( pVar == NULL ) { Exception = CBotErrLowParam; return FALSE; }
@@ -243,7 +243,7 @@ CBotTypResult cfopen (CBotVar* pThis, CBotVar* &pVar)
// méthode FILE :: close
// exécution
-BOOL rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
+bool rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// il ne doit pas y avoir de paramètre
if ( pVar != NULL ) return CBotErrOverParam;
@@ -275,7 +275,7 @@ CBotTypResult cfclose (CBotVar* pThis, CBotVar* &pVar)
// méthode FILE :: writeln
// exécution
-BOOL rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
+bool rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// il doit y avoir un paramètre
if ( pVar == NULL ) { Exception = CBotErrLowParam; return FALSE; }
@@ -319,7 +319,7 @@ CBotTypResult cfwrite (CBotVar* pThis, CBotVar* &pVar)
// méthode FILE :: readln
// exécution
-BOOL rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
+bool rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// il ne doit pas y avoir de paramètre
if ( pVar != NULL ) { Exception = CBotErrOverParam; return FALSE; }
@@ -360,7 +360,7 @@ CBotTypResult cfread (CBotVar* pThis, CBotVar* &pVar)
// exécution
-BOOL rfeof (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
+bool rfeof (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// il ne doit pas y avoir de paramètre
if ( pVar != NULL ) { Exception = CBotErrOverParam; return FALSE; }
diff --git a/src/CBot/StringFunctions.cpp b/src/CBot/StringFunctions.cpp
index 2c3cfc2..27332db 100644
--- a/src/CBot/StringFunctions.cpp
+++ b/src/CBot/StringFunctions.cpp
@@ -18,23 +18,23 @@
// donne la longueur d'une chaîne
// exécution
-BOOL rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
+bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// il faut un paramètre
- if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
+ if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// qui doit être une string
- if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
+ if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// pas de second paramètre
- if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return TRUE; }
+ if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// recupére le contenu de la string
CBotString s = pVar->GivValString();
// met la longueur sur la pile
pResult->SetValInt( s.GivLength() );
- return TRUE;
+ return true;
}
// int xxx ( string )
@@ -60,36 +60,36 @@ CBotTypResult cIntStr( CBotVar* &pVar, void* pUser )
// donne la partie gauche d'une chaîne
// exécution
-BOOL rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
+bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// il faut un paramètre
- if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
+ if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// qui doit être une string
- if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
+ if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// recupére le contenu de la string
CBotString s = pVar->GivValString();
// il faut un second paramètre
pVar = pVar->GivNext();
- if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
+ if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// qui doit être un nombre
- if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return TRUE; }
+ if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
// récupère ce nombre
int n = pVar->GivValInt();
// pas de 3e paramètre
- if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return TRUE; }
+ if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// prend la partie intéressante
s = s.Left( n );
// la met sur la pile
pResult->SetValString( s );
- return TRUE;
+ return true;
}
// string xxx ( string, int )
@@ -122,58 +122,58 @@ CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser )
// donne la partie droite d'une chaîne
// exécution
-BOOL rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
+bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// il faut un paramètre
- if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
+ if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// qui doit être une string
- if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
+ if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// recupére le contenu de la string
CBotString s = pVar->GivValString();
// il faut un second paramètre
pVar = pVar->GivNext();
- if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
+ if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// qui doit être un nombre
- if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return TRUE; }
+ if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
// récupère ce nombre
int n = pVar->GivValInt();
// pas de 3e paramètre
- if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return TRUE; }
+ if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// prend la partie intéressante
s = s.Right( n );
// la met sur la pile
pResult->SetValString( s );
- return TRUE;
+ return true;
}
// donne la partie centrale d'une chaîne
// exécution
-BOOL rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
+bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// il faut un paramètre
- if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
+ if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// qui doit être une string
- if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
+ if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// recupére le contenu de la string
CBotString s = pVar->GivValString();
// il faut un second paramètre
pVar = pVar->GivNext();
- if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
+ if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// qui doit être un nombre
- if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return TRUE; }
+ if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
// récupère ce nombre
int n = pVar->GivValInt();
@@ -184,13 +184,13 @@ BOOL rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
pVar = pVar->GivNext();
// qui doit être un nombre
- if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return TRUE; }
+ if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
// récupère ce nombre
int l = pVar->GivValInt();
// mais pas de 4e paramètre
- if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return TRUE; }
+ if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
// prend la partie intéressante
s = s.Mid( n, l );
@@ -203,7 +203,7 @@ BOOL rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
// la met sur la pile
pResult->SetValString( s );
- return TRUE;
+ return true;
}
// donne la partie centrale d'une chaîne
@@ -247,25 +247,25 @@ CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser )
// donne le nombre contenu dans une chaîne
// exécution
-BOOL rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
+bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// il faut un paramètre
- if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
+ if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// qui doit être une string
- if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
+ if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// recupére le contenu de la string
CBotString s = pVar->GivValString();
// mais pas de 2e paramètre
- if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return TRUE; }
+ if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
float val = GivNumFloat(s);
// la met la valeur sur la pile
pResult->SetValFloat( val );
- return TRUE;
+ return true;
}
// float xxx ( string )
@@ -291,35 +291,35 @@ CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser )
// trouve une chaine dans une autre
// exécution
-BOOL rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
+bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// il faut un paramètre
- if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
+ if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// qui doit être une string
- if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
+ if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// recupére le contenu de la string
CBotString s = pVar->GivValString();
// il faut un second paramètre
pVar = pVar->GivNext();
- if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
+ if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// qui doit être une string
- if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
+ if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// récupère ce nombre
CBotString s2 = pVar->GivValString();
// pas de 3e paramètre
- if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return TRUE; }
+ if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// met le résultat sur la pile
int res = s.Find(s2);
pResult->SetValInt( res );
if ( res < 0 ) pResult->SetInit( IS_NAN );
- return TRUE;
+ return true;
}
// int xxx ( string, string )
@@ -352,51 +352,51 @@ CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser )
// donne une chaine en majuscule
// exécution
-BOOL rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
+bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// il faut un paramètre
- if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
+ if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// qui doit être une string
- if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
+ if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// recupére le contenu de la string
CBotString s = pVar->GivValString();
// mais pas de 2e paramètre
- if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return TRUE; }
+ if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
s.MakeUpper();
// la met la valeur sur la pile
pResult->SetValString( s );
- return TRUE;
+ return true;
}
// donne une chaine en minuscules
// exécution
-BOOL rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
+bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// il faut un paramètre
- if ( pVar == NULL ) { ex = TX_LOWPARAM ; return TRUE; }
+ if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// qui doit être une string
- if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return TRUE; }
+ if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// recupére le contenu de la string
CBotString s = pVar->GivValString();
// mais pas de 2e paramètre
- if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return TRUE; }
+ if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
s.MakeLower();
// la met la valeur sur la pile
pResult->SetValString( s );
- return TRUE;
+ return true;
}
// string xxx ( string )
diff --git a/src/CBot/idees.txt b/src/CBot/idees.txt
index 7153789..3966ee1 100644
--- a/src/CBot/idees.txt
+++ b/src/CBot/idees.txt
@@ -1,39 +1,41 @@
-pour la gestion des instances d'une classe.
-l'objet créé actuellement avec CBotVar::Create(nom, pClasse)
-est a conserver tel quel, en dehors des vars sur la pile
+for managing instances of a class.
-il faut un autre type de variable pour garder les pointeurs
-CBotTypPtClass par exemple
+the object being created with CBotVar :: Create (name, pClasse)
+ is to keep as is, outside the vars on the stack
-L'instance de la classe doit avoir un compteur d'utilisation
-qui est le nombre d'objet de classe CBotTypPtClass qui y réfèrent.
-Le compteur est décrémenté lorsque le pointeur est détruit,
-l'objet supprimé lorsqu'il n'y a plus de pointeurs.
+ we need another type of variable to keep the pointers
+ For example CBotTypPtClass
+ The instance of the class must have a usage count
+ which is the number of class object to which they refer CBotTypPtClass.
+ The counter is decremented when the pointer is destroyed,
+ be deleted when there is more pointers.
-Dans le cas des robots, Daniel crée une instance de sa classe "Object"
-et peut retourner des pointeurs à cette instance par des routines genre FindRobot()
-Object FindRobot(int n) { }
+ In the case of robots, Daniel creates an instance of class "Object"
+ and can return pointers to this proceeding by routines such FindRobot ()
-pResult dans ce cas est un pointeur CBotTypPtClass
-lorsqu'il a trouvé le robot concerné, il lui faudra faire
+ Object FindRobot (int n) {}
-pResult->SetPointeur(InstanceDeLaClassObject);
+ pResult in this case is a pointer CBotTypPtClass
+ when he found the robot concerned, it must make
-cette opération incrémente le compteur des références
+ pResult-> SetPointeur (InstanceDeLaClassObject);
---
+ this operation increments the reference
-lorsque le robot est détruit, l'instance de la classe Object correspondant
-est détruit également.
-s'il reste des pointeurs à cet objet, et l'on risque la planté
+ -
-solution 1:
- garder non pas le pointeur à l'objet directement, mais
- un index dans une tables de pointeurs
+ when the robot is destroyed, the instance of the Object class corresponding
+ is also destroyed.
+ if there are pointers to that object, and we planted the risk
+
+ Solution 1:
+ not keep the pointer to the object directly, but
+ an index into a table of pointers
+
+ Solution 2:
+ not destroy the object when there imédiatement pointers
+ but marked as virtually destroyed
-solution 2:
- ne pas détruire l'objet imédiatement lorsqu'il reste des pointeurs
- mais le marqué comme virtuellement détruit \ No newline at end of file
diff --git a/src/CBot/old b/src/CBot/old
deleted file mode 100644
index ea18736..0000000
--- a/src/CBot/old
+++ /dev/null
@@ -1,15 +0,0 @@
-// * This file is part of the COLOBOT source code
-// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
-// *
-// * 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://www.gnu.org/licenses/. \ No newline at end of file
diff --git a/src/CBot/resource.h b/src/CBot/resource.h
index 7e57d32..6bf48e1 100644
--- a/src/CBot/resource.h
+++ b/src/CBot/resource.h
@@ -13,100 +13,105 @@
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.//{{NO_DEPENDENCIES}}
-// Microsoft Developer Studio generated include file.
-// Used by CBot.rc
-//
-#define ID_KEYWORDS 2000
-#define ID_IF 2000
-#define ID_ELSE 2001
-#define ID_WHILE 2002
-#define ID_DO 2003
-#define ID_FOR 2004
-#define ID_BREAK 2005
-#define ID_CONTINUE 2006
-#define ID_SWITCH 2007
-#define ID_CASE 2008
-#define ID_DEFAULT 2009
-#define ID_TRY 2010
-#define ID_THROW 2011
-#define ID_CATCH 2012
-#define ID_FINALLY 2013
-#define ID_TXT_AND 2014
-#define ID_TXT_OR 2015
-#define ID_TXT_NOT 2016
-#define ID_RETURN 2017
-#define ID_CLASS 2018
-#define ID_EXTENDS 2019
-#define ID_SYNCHO 2020
-#define ID_NEW 2021
-#define ID_PUBLIC 2022
-#define ID_EXTERN 2023
-#define ID_FINAL 2024
-#define ID_STATIC 2025
-#define ID_PROTECTED 2026
-#define ID_PRIVATE 2027
-#define ID_REPEAT 2028
-#define ID_DEBUGDD 2099
-#define ID_INT 2100
-#define ID_FLOAT 2101
-#define ID_BOOLEAN 2102
-#define ID_STRING 2103
-#define ID_VOID 2104
-#define ID_BOOL 2105
-#define ID_TRUE 2200
-#define ID_FALSE 2201
-#define ID_NULL 2202
-#define ID_NAN 2203
-#define ID_OPENPAR 2300
-#define ID_CLOSEPAR 2301
-#define ID_OPBLK 2302
-#define ID_CLBLK 2303
-#define ID_SEP 2304
-#define ID_COMMA 2305
-#define ID_DOTS 2306
-#define ID_DOT 2307
-#define ID_OPBRK 2308
-#define ID_CLBRK 2309
-#define ID_DBLDOTS 2310
-#define ID_LOGIC 2311
-#define ID_ADD 2312
-#define ID_SUB 2313
-#define ID_MUL 2314
-#define ID_DIV 2315
-#define ID_ASS 2316
-#define ID_ASSADD 2317
-#define ID_ASSSUB 2318
-#define ID_ASSMUL 2319
-#define ID_ASSDIV 2320
-#define ID_ASSOR 2321
-#define ID_ASSAND 2322
-#define ID_ASSXOR 2323
-#define ID_ASSSL 2324
-#define ID_ASSSR 2325
-#define ID_ASSASR 2326
-#define ID_SL 2327
-#define ID_SR 2328
-#define ID_ASR 2329
-#define ID_INC 2330
-#define ID_DEC 2331
-#define ID_LO 2332
-#define ID_HI 2333
-#define ID_LS 2334
-#define ID_HS 2335
-#define ID_EQ 2336
-#define ID_NE 2337
-#define ID_AND 2338
-#define ID_XOR 2339
-#define ID_OR 2340
-#define ID_LOG_AND 2341
-#define ID_LOG_OR 2342
-#define ID_LOG_NOT 2343
-#define ID_NOT 2344
-#define ID_MODULO 2345
-#define ID_POWER 2346
-#define ID_ASSMODULO 2347
-#define TX_UNDEF 4000
-#define TX_NAN 4001
+#ifndef _RESOURCE_H_
+#define _RESOURCE_H_
+
+enum EID
+{
+ ID_IF = 2000,
+ ID_ELSE,
+ ID_WHILE,
+ ID_DO,
+ ID_FOR,
+ ID_BREAK,
+ ID_CONTINUE,
+ ID_SWITCH,
+ ID_CASE,
+ ID_DEFAULT,
+ ID_TRY,
+ ID_THROW,
+ ID_CATCH,
+ ID_FINALLY,
+ ID_TXT_AND,
+ ID_TXT_OR,
+ ID_TXT_NOT,
+ ID_RETURN,
+ ID_CLASS,
+ ID_EXTENDS,
+ ID_SYNCHO,
+ ID_NEW,
+ ID_PUBLIC,
+ ID_EXTERN,
+ ID_FINAL,
+ ID_STATIC,
+ ID_PROTECTED,
+ ID_PRIVATE,
+ ID_REPEAT,
+ ID_DEBUGDD,
+ ID_INT,
+ ID_FLOAT,
+ ID_BOOLEAN,
+ ID_STRING,
+ ID_VOID,
+ ID_BOOL,
+
+ ID_TRUE = 2200,
+ ID_FALSE,
+ ID_NULL,
+ ID_NAN,
+
+ ID_OPENPAR = 2300,
+ ID_CLOSEPAR,
+ ID_OPBLK,
+ ID_CLBLK,
+ ID_SEP,
+ ID_COMMA,
+ ID_DOTS,
+ ID_DOT,
+ ID_OPBRK,
+ ID_CLBRK,
+ ID_DBLDOTS,
+ ID_LOGIC,
+ ID_ADD,
+ ID_SUB,
+ ID_MUL,
+ ID_DIV,
+ ID_ASS,
+ ID_ASSADD,
+ ID_ASSSUB,
+ ID_ASSMUL,
+ ID_ASSDIV,
+ ID_ASSOR,
+ ID_ASSAND,
+ ID_ASSXOR,
+ ID_ASSSL,
+ ID_ASSSR,
+ ID_ASSASR,
+ ID_SL,
+ ID_SR,
+ ID_ASR,
+ ID_INC,
+ ID_DEC,
+ ID_LO,
+ ID_HI,
+ ID_LS,
+ ID_HS,
+ ID_EQ,
+ ID_NE,
+ ID_AND,
+ ID_XOR,
+ ID_OR,
+ ID_LOG_AND,
+ ID_LOG_OR,
+ ID_LOG_NOT,
+ ID_NOT,
+ ID_MODULO,
+ ID_POWER,
+ ID_ASSMODULO,
+ TX_UNDEF = 4000,
+ TX_NAN,
+ ID_SUPER = 6000
+};
#define TX_OPENPAR 5000
#define TX_CLOSEPAR 5001
#define TX_NOTBOOL 5002
@@ -166,15 +171,6 @@
#define TX_NOTOPEN 6013
#define TX_ERRREAD 6014
#define TX_ERRWRITE 6015
-#define ID_SUPER 62020
-// Next default values for new objects
-//
-#ifdef APSTUDIO_INVOKED
-#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 101
-#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1000
-#define _APS_NEXT_SYMED_VALUE 101
-#endif
-#endif
+#endif //_RESOURCE_H_
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 76a10e9..da8463b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,5 +1,5 @@
# CBot shared library is built separately
-# add_subdirectory(CBot) -- not yet WinAPI-independent
+add_subdirectory(CBot)
# Configure options
@@ -29,6 +29,7 @@ configure_file(common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common/config.h
# Source files
# Commented out files are still dependent on DirectX or WinAPI
+
set(SOURCES
app/app.cpp
app/main.cpp
@@ -155,8 +156,8 @@ ${SDL_LIBRARY}
${SDLIMAGE_LIBRARY}
${OPENGL_LIBRARY}
${PNG_LIBRARIES}
-#CBot -- not yet WinAPI-independent
${PLATFORM_LIBS}
+CBot
)
include_directories(. ${CMAKE_CURRENT_BINARY_DIR}
diff --git a/src/sound/sound.h b/src/sound/sound.h
index 598ffe3..d27721a 100644
--- a/src/sound/sound.h
+++ b/src/sound/sound.h
@@ -28,6 +28,9 @@
#include <plugins/plugin.h>
+#include <string>
+
+
/*!
* Maximum possible audio volume
*/