From fd6147bea012093ce0f70d843eb6732c581d2a4f Mon Sep 17 00:00:00 2001 From: Zaba999 Date: Mon, 2 Jul 2012 21:41:24 +0200 Subject: translations plus small fixes --- src/CBot/CBot.cpp | 26 ++++++++++++++------------ src/CBot/CBot.h | 8 +++----- src/CBot/idees.txt | 54 ++++++++++++++++++++++++++++-------------------------- 3 files changed, 45 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index e2b01a9..1344efd 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -13,18 +13,20 @@ // * // * 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 ) - -// 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 +// Compilation of various instructions +// Compile all routines are static +// And return an object according to what was found as instruction + +// 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) + + +// 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" diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index e28bbee..7e15f65 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -1346,9 +1346,7 @@ public: void SetIdent(long n); - static - CBotVarClass* - CBotVarClass::Find(long id); + static CBotVarClass* Find(long id); // CBotVar* GivMyThis(); @@ -1599,8 +1597,8 @@ private: CBotToken m_openblk; CBotToken m_closeblk; public: - CBotFunction::CBotFunction(); - CBotFunction::~CBotFunction(); + CBotFunction(); + ~CBotFunction(); static CBotFunction* Compile(CBotToken* &p, CBotCStack* pStack, CBotFunction* pFunc, BOOL bLocal = TRUE); static 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 -- cgit v1.2.3-1-g7c22 From dbd62c96aa351dc1c21e3392348edda2eb012e09 Mon Sep 17 00:00:00 2001 From: Zaba999 Date: Wed, 4 Jul 2012 22:14:28 +0200 Subject: Fixed code compilation without fpermissive flag. Removed Winapi, but now library don't work - work in progress. Some translations. --- src/CBot/CBot.cpp | 885 +++++++++++++++++++++---------------------- src/CBot/CBot.h | 522 ++++++++++++------------- src/CBot/CBotAddExpr.cpp | 2 +- src/CBot/CBotClass.cpp | 145 ++++--- src/CBot/CBotCompExpr.cpp | 2 +- src/CBot/CBotDll.h | 472 +++++++++++------------ src/CBot/CBotFunction.cpp | 164 ++++---- src/CBot/CBotIf.cpp | 24 +- src/CBot/CBotProgram.cpp | 211 ++++++----- src/CBot/CBotStack.cpp | 288 +++++++------- src/CBot/CBotString.cpp | 104 ++--- src/CBot/CBotToken.cpp | 67 ++-- src/CBot/CBotToken.h | 4 +- src/CBot/CBotTwoOpExpr.cpp | 58 +-- src/CBot/CBotVar.cpp | 278 +++++++------- src/CBot/CBotWhile.cpp | 216 +++++------ src/CBot/ClassFILE.cpp | 14 +- src/CBot/StringFunctions.cpp | 98 ++--- src/CBot/old | 15 - src/CMakeLists.txt | 5 +- 20 files changed, 1786 insertions(+), 1788 deletions(-) delete mode 100644 src/CBot/old (limited to 'src') diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 1344efd..6cb2e5d 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -25,7 +25,7 @@ // 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 +// The error is then on the stack CBotCStack :: Isok () is false @@ -85,19 +85,19 @@ void CBotInstr::DecLvl() } // controle la validité d'un break ou continu -BOOL CBotInstr::ChkLvl(const CBotString& label, int type) +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; + if ( label.IsEmpty() ) return true; + if ( m_labelLvl[i] == label ) return true; } - return FALSE; + return false; } -BOOL CBotInstr::IsOfClass(CBotString n) +bool CBotInstr::IsOfClass(CBotString n) { return name == n; } @@ -113,12 +113,6 @@ void CBotInstr::SetToken(CBotToken* p) m_token = *p; } -void CBotInstr::SetToken(CBotString* name, int start, int end) -{ - SetToken( &CBotToken( *name, CBotString(), start, end)); -} - - // rend le type du token associé à l'instruction int CBotInstr::GivTokenType() @@ -293,22 +287,22 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) 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; + return false; } -BOOL CBotInstr::Execute(CBotStack* &pj, CBotVar* pVar) +bool CBotInstr::Execute(CBotStack* &pj, CBotVar* pVar) { - if ( !Execute(pj) ) return FALSE; + if ( !Execute(pj) ) return false; pVar->SetVal( pj->GivVar() ); - return TRUE; + 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 @@ -316,19 +310,19 @@ void CBotInstr::RestoreState(CBotStack* &pj, BOOL bMain) } -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; + 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; + 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 } @@ -337,9 +331,9 @@ void CBotInstr::RestoreStateVar(CBotStack* &pile, BOOL bMain) // 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. -BOOL CBotInstr::CompCase(CBotStack* &pj, int val) +bool CBotInstr::CompCase(CBotStack* &pj, int val) { - return FALSE; + return false; } ////////////////////////////////////////////////////////////////////////////////////////// @@ -352,7 +346,7 @@ BOOL CBotInstr::CompCase(CBotStack* &pj, int val) // l'objet retourné par Compile est généralement de type CBotListInstr -CBotInstr* CBotBlock::Compile(CBotToken* &p, CBotCStack* pStack, BOOL bLocal) +CBotInstr* CBotBlock::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal) { pStack->SetStartError(p->GivStart()); @@ -374,7 +368,7 @@ CBotInstr* CBotBlock::Compile(CBotToken* &p, CBotCStack* pStack, BOOL bLocal) 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); @@ -410,13 +404,13 @@ CBotListInstr::~CBotListInstr() 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 CBotListInstr* inst = new CBotListInstr(); - while (TRUE) + while (true) { if ( p == NULL ) break; @@ -446,10 +440,10 @@ CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, BOOL bLocal // exécute une liste d'instructions -BOOL CBotListInstr::Execute(CBotStack* &pj) +bool CBotListInstr::Execute(CBotStack* &pj) { - CBotStack* pile = pj->AddStack(this, TRUE);//indispensable pour SetState() + CBotStack* pile = pj->AddStack(this, true);//indispensable pour SetState() if ( pile->StackOver() ) return pj->Return( pile ); @@ -458,20 +452,20 @@ BOOL CBotListInstr::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) { // DEBUG( "CBotListInstr", pile->GivState(), pile ); - 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 ); // transmet en dessous } -void CBotListInstr::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotListInstr::RestoreState(CBotStack* &pj, bool bMain) { if ( !bMain ) return; @@ -483,11 +477,11 @@ void CBotListInstr::RestoreState(CBotStack* &pj, BOOL bMain) int state = pile->GivState(); while ( p != NULL && state-- > 0) { - p->RestoreState(pile, FALSE); + p->RestoreState(pile, false); p = p->GivNext(); // revient sur l'opération interrompue } - if ( p != NULL ) p->RestoreState(pile, TRUE); + if ( p != NULL ) p->RestoreState(pile, true); } ////////////////////////////////////////////////////////////////////////////////////// @@ -523,7 +517,7 @@ CBotInstr* CBotLeftExprVar::Compile(CBotToken* &p, CBotCStack* pStack) } // crée une variable et lui assigne le résultat de la pile -BOOL CBotLeftExprVar::Execute(CBotStack* &pj) +bool CBotLeftExprVar::Execute(CBotStack* &pj) { CBotVar* var1; CBotVar* var2; @@ -535,10 +529,10 @@ BOOL CBotLeftExprVar::Execute(CBotStack* &pj) var2 = pj->GivVar(); // resultat sur la pile if ( var2 ) var1->SetVal(var2); // fait l'assignation - return TRUE; // opération faite + return true; // opération faite } -void CBotLeftExprVar::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotLeftExprVar::RestoreState(CBotStack* &pj, bool bMain) { CBotVar* var1; @@ -631,10 +625,10 @@ error: // exécute la définition d'un tableau -BOOL CBotInstArray::Execute(CBotStack* &pj) +bool CBotInstArray::Execute(CBotStack* &pj) { CBotStack* pile1 = pj->AddStack(this); -// if ( pile1 == EOX ) return TRUE; +// if ( pile1 == EOX ) return true; CBotStack* pile = pile1; @@ -650,7 +644,7 @@ BOOL CBotInstArray::Execute(CBotStack* &pj) nb++; if ( pile->GivState() == 0 ) { - if ( !p->Execute(pile) ) return FALSE; // calcul de la taille // interrompu? + if ( !p->Execute(pile) ) return false; // calcul de la taille // interrompu? pile->IncState(); } p = p->GivNext3b(); @@ -698,20 +692,20 @@ BOOL CBotInstArray::Execute(CBotStack* &pj) { CBotVar* pVar = pj->FindVar(((CBotLeftExprVar*)m_var)->m_nIdent); - if ( !m_listass->Execute(pile1, pVar) ) return FALSE; + if ( !m_listass->Execute(pile1, pVar) ) return false; } pile1->IncState(); } - if ( pile1->IfStep() ) return FALSE; // montre ce pas ? + if ( pile1->IfStep() ) return false; // montre ce pas ? if ( m_next2b && - !m_next2b->Execute( pile1 ) ) return FALSE; + !m_next2b->Execute( pile1 ) ) return false; return pj->Return( pile1 ); // transmet en dessous } -void CBotInstArray::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotInstArray::RestoreState(CBotStack* &pj, bool bMain) { CBotStack* pile1 = pj; @@ -753,15 +747,15 @@ void CBotInstArray::RestoreState(CBotStack* &pj, BOOL bMain) } // cas particulier pour les indices vides -BOOL CBotEmpty :: Execute(CBotStack* &pj) +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; + return true; } -void CBotEmpty :: RestoreState(CBotStack* &pj, BOOL bMain) +void CBotEmpty :: RestoreState(CBotStack* &pj, bool bMain) { } @@ -878,10 +872,10 @@ error: // exécute la définition d'un tableau -BOOL CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar) +bool CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar) { CBotStack* pile1 = pj->AddStack(); -// if ( pile1 == EOX ) return TRUE; +// if ( pile1 == EOX ) return true; CBotVar* pVar2; CBotInstr* p = m_expr; @@ -892,9 +886,9 @@ BOOL CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar) { 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; // évalue l'expression pile1->IncState(); } @@ -902,7 +896,7 @@ BOOL CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar) return pj->Return( pile1 ); // transmet en dessous } -void CBotListArray::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotListArray::RestoreState(CBotStack* &pj, bool bMain) { if ( bMain ) { @@ -940,7 +934,7 @@ CBotInt::~CBotInt() // delete m_next; // fait par le destructeur de la classe de base ~CBotInstr() } -CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, BOOL first) +CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool first) { if ( IsOfType(p, ID_OPBRK) ) { @@ -950,7 +944,7 @@ CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypRes return NULL; } - CBotInstr* inst = CompileArray(p, pStack, CBotTypResult( CBotTypArrayPointer, type ), FALSE); + CBotInstr* inst = CompileArray(p, pStack, CBotTypResult( CBotTypArrayPointer, type ), false); if ( inst != NULL || !pStack->IsOk() ) return inst; } @@ -962,7 +956,7 @@ CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypRes 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 + if ( NULL != ( inst->m_next2b = CBotInstArray::CompileArray(p, pStack, type, false) )) // compile la suivante { return inst; } @@ -980,7 +974,7 @@ CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypRes return NULL; } -CBotInstr* CBotInt::Compile(CBotToken* &p, CBotCStack* pStack, BOOL cont, BOOL noskip) +CBotInstr* CBotInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip) { CBotToken* pp = cont ? NULL : p; // pas de répétition du token "int" @@ -1025,7 +1019,7 @@ CBotInstr* CBotInt::Compile(CBotToken* &p, CBotCStack* pStack, BOOL cont, BOOL n 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 + if ( NULL != ( inst2->m_next2b = CBotInt::Compile(p, pStk, true, noskip) )) // compile la suivante { return pStack->Return(inst2, pStk); } @@ -1058,7 +1052,7 @@ CBotInstr* CBotInt::Compile(CBotToken* &p, CBotCStack* pStack, BOOL cont, BOOL n 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 + if ( NULL != ( inst->m_next2b = CBotInt::Compile(p, pStk, true, noskip) )) // compile la suivante { return pStack->Return(inst, pStk); } @@ -1079,28 +1073,28 @@ error: // exécute la définition de la variable entière -BOOL CBotInt::Execute(CBotStack* &pj) +bool CBotInt::Execute(CBotStack* &pj) { CBotStack* pile = pj->AddStack(this); //indispensable pour SetState() -// if ( pile == EOX ) return TRUE; +// if ( pile == EOX ) return true; if ( pile->GivState()==0) { - if (m_expr && !m_expr->Execute(pile)) return FALSE; // valeur initiale // interrompu? + 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->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) + !m_next2b->Execute(pile)) return false; // autre(s) définition(s) return pj->Return( pile ); // transmet en dessous } -void CBotInt::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotInt::RestoreState(CBotStack* &pj, bool bMain) { CBotStack* pile = pj; if ( bMain ) @@ -1140,7 +1134,7 @@ CBotBoolean::~CBotBoolean() 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; @@ -1207,7 +1201,7 @@ CBotInstr* CBotBoolean::Compile(CBotToken* &p, CBotCStack* pStack, BOOL cont, BO 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 + if ( NULL != ( inst->m_next2b = CBotBoolean::Compile(p, pStk, true, noskip) )) // compile la suivante { return pStack->Return(inst, pStk); } @@ -1228,28 +1222,28 @@ error: // exécute une définition de variable booléenne -BOOL CBotBoolean::Execute(CBotStack* &pj) +bool CBotBoolean::Execute(CBotStack* &pj) { CBotStack* pile = pj->AddStack(this);//indispensable pour SetState() -// if ( pile == EOX ) return TRUE; +// if ( pile == EOX ) return true; if ( pile->GivState()==0) { - if (m_expr && !m_expr->Execute(pile)) return FALSE; // valeur initiale // interrompu? + 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->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) + !m_next2b->Execute(pile)) return false; // autre(s) définition(s) return pj->Return( pile ); // transmet en dessous } -void CBotBoolean::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotBoolean::RestoreState(CBotStack* &pj, bool bMain) { CBotStack* pile = pj; if ( bMain ) @@ -1290,7 +1284,7 @@ CBotFloat::~CBotFloat() delete m_expr; } -CBotInstr* CBotFloat::Compile(CBotToken* &p, CBotCStack* pStack, BOOL cont, BOOL noskip) +CBotInstr* CBotFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip) { CBotToken* pp = cont ? NULL : p; @@ -1358,7 +1352,7 @@ CBotInstr* CBotFloat::Compile(CBotToken* &p, CBotCStack* pStack, BOOL cont, BOOL 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 + if ( NULL != ( inst->m_next2b = CBotFloat::Compile(p, pStk, true, noskip) )) // compile la suivante { return pStack->Return(inst, pStk); } @@ -1379,28 +1373,28 @@ error: // exécute la défintion de la variable réelle -BOOL CBotFloat::Execute(CBotStack* &pj) +bool CBotFloat::Execute(CBotStack* &pj) { CBotStack* pile = pj->AddStack(this);//indispensable pour SetState() -// if ( pile == EOX ) return TRUE; +// if ( pile == EOX ) return true; if ( pile->GivState()==0) { - if (m_expr && !m_expr->Execute(pile)) return FALSE; // valeur initiale // interrompu? + 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->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) + !m_next2b->Execute(pile)) return false; // autre(s) définition(s) return pj->Return( pile ); // transmet en dessous } -void CBotFloat::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotFloat::RestoreState(CBotStack* &pj, bool bMain) { CBotStack* pile = pj; if ( bMain ) @@ -1441,7 +1435,7 @@ CBotIString::~CBotIString() delete m_expr; } -CBotInstr* CBotIString::Compile(CBotToken* &p, CBotCStack* pStack, BOOL cont, BOOL noskip) +CBotInstr* CBotIString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip) { CBotToken* pp = cont ? NULL : p; @@ -1491,7 +1485,7 @@ CBotInstr* CBotIString::Compile(CBotToken* &p, CBotCStack* pStack, BOOL cont, BO 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 + if ( NULL != ( inst->m_next2b = CBotIString::Compile(p, pStk, true, noskip) )) // compile la suivante { return pStack->Return(inst, pStk); } @@ -1512,28 +1506,28 @@ error: // exécute la définition de la variable string -BOOL CBotIString::Execute(CBotStack* &pj) +bool CBotIString::Execute(CBotStack* &pj) { CBotStack* pile = pj->AddStack(this);//indispensable pour SetState() -// if ( pile == EOX ) return TRUE; +// if ( pile == EOX ) return true; if ( pile->GivState()==0) { - if (m_expr && !m_expr->Execute(pile)) return FALSE; // valeur initiale // interrompu? + 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->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) + !m_next2b->Execute(pile)) return false; // autre(s) définition(s) return pj->Return( pile ); // transmet en dessous } -void CBotIString::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotIString::RestoreState(CBotStack* &pj, bool bMain) { CBotStack* pile = pj; @@ -1641,7 +1635,7 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) var->SetInit(2); } else - var->SetInit(TRUE); + var->SetInit(true); break; case ID_ASSADD: @@ -1682,21 +1676,21 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) // exécute une expression avec assignation -BOOL CBotExpression::Execute(CBotStack* &pj) +bool CBotExpression::Execute(CBotStack* &pj) { CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return TRUE; +// if ( pile == EOX ) return true; CBotToken* pToken = m_leftop->GivToken(); CBotVar* pVar = NULL; CBotStack* pile1 = pile; - BOOL IsInit = TRUE; + 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 + 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) @@ -1710,7 +1704,7 @@ BOOL CBotExpression::Execute(CBotStack* &pj) if ( pile2->GivState()==0) { // DEBUG( "CBotExpression::Execute", -2, pj); - if (m_rightop && !m_rightop->Execute(pile2)) return FALSE; // valeur initiale // interrompu? + if (m_rightop && !m_rightop->Execute(pile2)) return false; // valeur initiale // interrompu? pile2->IncState(); } @@ -1792,13 +1786,13 @@ BOOL CBotExpression::Execute(CBotStack* &pj) // DEBUG( "CBotExpression::Execute", -4, pj); if ( !m_leftop->Execute( pile2, pile1 ) ) - return FALSE; // crée et fait l'assigation du résultat + 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) +void CBotExpression::RestoreState(CBotStack* &pj, bool bMain) { if ( bMain ) { @@ -1813,11 +1807,11 @@ void CBotExpression::RestoreState(CBotStack* &pj, BOOL bMain) if ( pile1->GivState()==0) { - m_leftop->RestoreStateVar(pile, TRUE); // variable avant évaluation de la valeur droite + 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 + 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; @@ -2086,20 +2080,20 @@ CBotPreIncExpr::~CBotPreIncExpr() delete m_Instr; } -BOOL CBotPostIncExpr::Execute(CBotStack* &pj) +bool CBotPostIncExpr::Execute(CBotStack* &pj) { CBotStack* pile1 = pj->AddStack(this); CBotStack* pile2 = pile1; CBotVar* var1 = NULL; - if ( !((CBotExprVar*)m_Instr)->ExecuteVar(var1, pile2, NULL, TRUE) ) return FALSE; // récupère la variable selon champs et index + if ( !((CBotExprVar*)m_Instr)->ExecuteVar(var1, pile2, NULL, true) ) return false; // récupère la variable selon champs et index pile1->SetState(1); pile1->SetCopyVar(var1); // place le résultat (avant incrémentation); CBotStack* pile3 = pile2->AddStack(this); - if ( pile3->IfStep() ) return FALSE; + if ( pile3->IfStep() ) return false; if ( var1->GivInit() == IS_NAN ) { @@ -2117,7 +2111,7 @@ BOOL CBotPostIncExpr::Execute(CBotStack* &pj) return pj->Return(pile1); // opération faite, résultat sur pile2 } -void CBotPostIncExpr::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotPostIncExpr::RestoreState(CBotStack* &pj, bool bMain) { if ( !bMain ) return; @@ -2129,19 +2123,19 @@ void CBotPostIncExpr::RestoreState(CBotStack* &pj, BOOL bMain) 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; +// if ( pile == EOX ) return true; - if ( pile->IfStep() ) return FALSE; + if ( pile->IfStep() ) return false; 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 + 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 ( var1->GivInit() == IS_NAN ) @@ -2162,12 +2156,12 @@ BOOL CBotPreIncExpr::Execute(CBotStack* &pj) pile->IncState(); } - if ( !m_Instr->Execute(pile) ) return FALSE; + if ( !m_Instr->Execute(pile) ) return false; return pj->Return(pile); // opération faite } -void CBotPreIncExpr::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotPreIncExpr::RestoreState(CBotStack* &pj, bool bMain) { if ( !bMain ) return; @@ -2234,19 +2228,19 @@ CBotInstr* CBotExprUnaire::Compile(CBotToken* &p, CBotCStack* pStack) // exécute l'expresson unaire -BOOL CBotExprUnaire::Execute(CBotStack* &pj) +bool CBotExprUnaire::Execute(CBotStack* &pj) { CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return TRUE; +// if ( pile == EOX ) return true; if ( pile->GivState() == 0 ) { - if (!m_Expr->Execute( pile )) return FALSE; // interrompu ? + if (!m_Expr->Execute( pile )) return false; // interrompu ? pile->IncState(); } CBotStack* pile2 = pile->AddStack(); - if ( pile2->IfStep() ) return FALSE; + if ( pile2->IfStep() ) return false; CBotVar* var = pile->GivVar(); // récupère le résultat sur la pile @@ -2266,7 +2260,7 @@ BOOL CBotExprUnaire::Execute(CBotStack* &pj) return pj->Return(pile); // transmet en dessous } -void CBotExprUnaire::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotExprUnaire::RestoreState(CBotStack* &pj, bool bMain) { if ( !bMain ) return; @@ -2300,26 +2294,26 @@ CBotIndexExpr::~CBotIndexExpr() // trouve un champ à partir de l'instance à la compilation -BOOL CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) +bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) { if ( pVar->GivType(1) != CBotTypArrayPointer ) ASM_TRAP(); - pVar = ((CBotVarArray*)pVar)->GivItem(0, FALSE); // à la compilation rend l'élément [0] + 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; + return false; } if ( m_next3 != NULL ) return m_next3->ExecuteVar(pVar, pile); - return TRUE; + return true; } // idem à l'exécution // attention, modifie le pointeur à la pile volontairement // place les index calculés sur la pile supplémentaire -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); @@ -2328,11 +2322,11 @@ BOOL CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prev ASM_TRAP(); pile = pile->AddStack(); -// if ( pile == EOX ) return TRUE; +// if ( pile == EOX ) return true; if ( pile->GivState() == 0 ) { - if ( !m_expr->Execute(pile) ) return FALSE; + if ( !m_expr->Execute(pile) ) return false; pile->IncState(); } // traite les tableaux @@ -2357,25 +2351,25 @@ BOOL CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prev // 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; + !m_next3->ExecuteVar(pVar, pile, prevToken, bStep, bExtend) ) return false; // DEBUG( "CBotIndexExpr::ExecuteVar", -4 , pj); - return TRUE; // ne libère pas la pile + return true; // ne libère pas la pile // pour éviter de recalculer les index deux fois le cas échéant } -void CBotIndexExpr::RestoreStateVar(CBotStack* &pile, BOOL bMain) +void CBotIndexExpr::RestoreStateVar(CBotStack* &pile, bool bMain) { pile = pile->RestoreStack(); if ( pile == NULL ) return; if ( bMain && pile->GivState() == 0 ) { - m_expr->RestoreState(pile, TRUE); + m_expr->RestoreState(pile, true); return; } @@ -2408,7 +2402,7 @@ void CBotFieldExpr::SetUniqNum(int num) // trouve un champ à partir de l'instance à la compilation -BOOL CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) +bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) { if ( pVar->GivType(1) != CBotTypPointer ) ASM_TRAP(); @@ -2418,22 +2412,22 @@ BOOL CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) if ( pVar == NULL ) { pile->SetError(TX_NOITEM, &m_token); - return FALSE; + return false; } if ( m_next3 != NULL && - !m_next3->ExecuteVar(pVar, pile) ) return FALSE; + !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; + if ( pile == EOX ) return true; // DEBUG( "CBotFieldExpre::ExecuteVar "+m_token.GivString(), 0, pj ); @@ -2452,7 +2446,7 @@ BOOL CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prev 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); @@ -2472,16 +2466,16 @@ BOOL CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prev } // demande la mise à jour de l'élément, s'il y a lieu - pVar->Maj(pile->GivPUser(), TRUE); + pVar->Maj(pile->GivPUser(), true); if ( m_next3 != NULL && - !m_next3->ExecuteVar(pVar, pile, &m_token, bStep, bExtend) ) return FALSE; + !m_next3->ExecuteVar(pVar, pile, &m_token, bStep, bExtend) ) return false; - return TRUE; // ne libère pas la pile + return true; // ne libère pas la pile // pour conserver l'état SetState() correspondant à l'étape } -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; @@ -2505,8 +2499,8 @@ 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 @@ -2517,78 +2511,78 @@ 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; + 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; + } + // 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 @@ -2633,20 +2627,20 @@ err: // exécute, trouve une variable et lui assigne le résultat de la pile -BOOL CBotLeftExpr::Execute(CBotStack* &pj, CBotStack* array) +bool CBotLeftExpr::Execute(CBotStack* &pj, CBotStack* array) { CBotStack* pile = pj->AddStack(); -// if ( pile == EOX ) return TRUE; +// if ( pile == EOX ) return true; -// if ( pile->IfStep() ) return FALSE; +// if ( pile->IfStep() ) return false; CBotVar* var1 = NULL; CBotVar* var2 = NULL; -// var1 = pile->FindVar(m_token, FALSE, TRUE); - 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 ) { @@ -2677,20 +2671,20 @@ BOOL CBotLeftExpr::Execute(CBotStack* &pj, CBotStack* array) // retrouve une variable pendant la 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; + if ( pVar == NULL ) return false; if ( m_next3 != NULL && - !m_next3->ExecuteVar(pVar, pile) ) return FALSE; + !m_next3->ExecuteVar(pVar, pile) ) return false; - return TRUE; + return true; } // retrouve une variable à l'exécution -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 @@ -2701,18 +2695,18 @@ BOOL CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevT ASM_TRAP(); #endif pile->SetError(2, &m_token); - return FALSE; + 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; + !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; @@ -2765,11 +2759,11 @@ extern float GivNumFloat( const char* p ) { double num = 0; double div = 10; - BOOL bNeg = FALSE; + bool bNeg = false; if (*p == '-') { - bNeg = TRUE; + bNeg = true; p++; } while (*p >= '0' && *p <= '9') @@ -2875,12 +2869,12 @@ CBotInstr* CBotExprNum::Compile(CBotToken* &p, CBotCStack* pStack) // exécute, retourne le nombre correspondant -BOOL CBotExprNum::Execute(CBotStack* &pj) +bool CBotExprNum::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; CBotVar* var = CBotVar::Create((CBotToken*)NULL, m_numtype); @@ -2905,7 +2899,7 @@ BOOL CBotExprNum::Execute(CBotStack* &pj) return pj->Return(pile); // c'est ok } -void CBotExprNum::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotExprNum::RestoreState(CBotStack* &pj, bool bMain) { if ( bMain ) pj->RestoreStack(this); } @@ -2942,12 +2936,12 @@ CBotInstr* CBotExprAlpha::Compile(CBotToken* &p, CBotCStack* pStack) // exécute, retourne la chaîne correspondante -BOOL CBotExprAlpha::Execute(CBotStack* &pj) +bool CBotExprAlpha::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; CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypString); @@ -2961,7 +2955,7 @@ BOOL CBotExprAlpha::Execute(CBotStack* &pj) return pj->Return(pile); } -void CBotExprAlpha::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotExprAlpha::RestoreState(CBotStack* &pj, bool bMain) { if ( bMain ) pj->RestoreStack(this); } @@ -3002,12 +2996,12 @@ CBotInstr* CBotExprBool::Compile(CBotToken* &p, CBotCStack* pStack) // exécute, retourne true ou false -BOOL CBotExprBool::Execute(CBotStack* &pj) +bool CBotExprBool::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; CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypBoolean); @@ -3018,7 +3012,7 @@ BOOL CBotExprBool::Execute(CBotStack* &pj) return pj->Return(pile); // transmet en dessous } -void CBotExprBool::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotExprBool::RestoreState(CBotStack* &pj, bool bMain) { if ( bMain ) pj->RestoreStack(this); } @@ -3038,20 +3032,20 @@ CBotExprNull::~CBotExprNull() // exécute, retourne un pointeur vide -BOOL CBotExprNull::Execute(CBotStack* &pj) +bool CBotExprNull::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; CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypNullPointer); - var->SetInit(TRUE); // pointeur null valide + var->SetInit(true); // pointeur null valide pile->SetVar( var ); // mis sur la pile return pj->Return(pile); // transmet en dessous } -void CBotExprNull::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotExprNull::RestoreState(CBotStack* &pj, bool bMain) { if ( bMain ) pj->RestoreStack(this); } @@ -3071,12 +3065,12 @@ CBotExprNan::~CBotExprNan() // exécute, retourne un pointeur vide -BOOL CBotExprNan::Execute(CBotStack* &pj) +bool CBotExprNan::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; CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypInt); var->SetInit(IS_NAN); // nombre nan @@ -3084,7 +3078,7 @@ BOOL CBotExprNan::Execute(CBotStack* &pj) return pj->Return(pile); // transmet en dessous } -void CBotExprNan::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotExprNan::RestoreState(CBotStack* &pj, bool bMain) { if ( bMain ) pj->RestoreStack(this); } @@ -3106,133 +3100,136 @@ 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 ) // 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); 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) @@ -3280,19 +3277,19 @@ CBotInstr* CBotExprVar::CompileMethode(CBotToken* &p, CBotCStack* pStack) // exécute, rend la valeur d'une 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 == EOX ) return true; -// if ( pile->IfStep() ) return FALSE; +// if ( pile->IfStep() ) return false; CBotStack* pile1 = pile; if ( pile1->GivState() == 0 ) { - if ( !ExecuteVar(pVar, pile, NULL, TRUE) ) return FALSE; // récupère la variable selon champs et index + if ( !ExecuteVar(pVar, pile, NULL, true) ) return false; // récupère la variable selon champs et index // DEBUG("CBotExprVar::Execute", 1 , pj); if ( pVar ) pile1->SetCopyVar(pVar); // la place une copie sur la pile @@ -3322,7 +3319,7 @@ BOOL CBotExprVar::Execute(CBotStack* &pj) return pj->Return(pile1); // opération faite } -void CBotExprVar::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotExprVar::RestoreState(CBotStack* &pj, bool bMain) { if ( !bMain ) return; @@ -3340,25 +3337,25 @@ void CBotExprVar::RestoreState(CBotStack* &pj, BOOL bMain) // retrouve une variable à l'exécution -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 ); - 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 + pVar = pj->FindVar(m_nIdent, true); // cherche la variable avec mise à jour si nécessaire if ( pVar == NULL ) { #ifdef _DEBUG ASM_TRAP(); #endif pj->SetError(1, &m_token); - return FALSE; + return false; } if ( m_next3 != NULL && - !m_next3->ExecuteVar(pVar, pj, &m_token, bStep, FALSE) ) - return FALSE; // Champs d'une instance, tableau, méthode ? + !m_next3->ExecuteVar(pVar, pj, &m_token, bStep, false) ) + return false; // Champs d'une instance, tableau, méthode ? return pile->ReturnKeep( pj ); // ne rend pas la pile mais récupère le résultat si une méthode a été appelée } @@ -3366,7 +3363,7 @@ BOOL CBotExprVar::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToke // retrouve une variable à l'exécution -void CBotExprVar::RestoreStateVar(CBotStack* &pj, BOOL bMain) +void CBotExprVar::RestoreStateVar(CBotStack* &pj, bool bMain) { pj = pj->RestoreStack( this ); if ( pj == NULL ) return; @@ -3381,7 +3378,7 @@ void CBotExprVar::RestoreStateVar(CBotStack* &pj, BOOL bMain) CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars) { - BOOL first = TRUE; + bool first = true; CBotInstr* ret = NULL; // pour la liste à retourner // pStack->SetStartError(p->GivStart()); @@ -3391,13 +3388,13 @@ CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars) if ( IsOfType(p, ID_OPENPAR) ) { int start, end; - 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 if ( first ) pStack->SetStartError(start); - first = FALSE; + first = false; CBotInstr* param = CBotExpression::Compile(p, pile); end = p->GivStart(); @@ -3513,11 +3510,11 @@ CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* // exécute l'appel de méthode -BOOL CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, BOOL bStep, BOOL bExtend) +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; + CBotStack* pile1 = pj->AddStack(this, true); // une place pour la copie de This +// if ( pile1 == EOX ) return true; // DEBUG( "CBotInstrMethode::ExecuteVar", 0, pj ); @@ -3526,7 +3523,7 @@ BOOL CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre pj->SetError( TX_NULLPT, prevToken ); } - if ( pile1->IfStep() ) return FALSE; + if ( pile1->IfStep() ) return false; CBotStack* pile2 = pile1->AddStack(); // et pour les paramètres à venir @@ -3549,12 +3546,12 @@ BOOL CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre // é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 ) { 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 + 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 @@ -3576,14 +3573,14 @@ BOOL CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre if ( !pClass->ExecuteMethode(m_MethodeIdent, m_NomMethod, pThis, ppVars, - pResult, pile2, GivToken())) return FALSE; // interrompu + 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) +void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, bool bMain) { if ( !bMain ) return; @@ -3604,11 +3601,11 @@ void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, 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 ) { if ( pile2->GivState() == 0 ) { - p->RestoreState(pile2, TRUE); // interrompu ici ! + p->RestoreState(pile2, true); // interrompu ici ! return; } ppVars[i++] = pile2->GivVar(); // construit la liste des pointeurs @@ -3630,13 +3627,13 @@ void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, BOOL bMain) } -BOOL CBotInstrMethode::Execute(CBotStack* &pj) +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; + CBotStack* pile1 = pj->AddStack(this, true); // une place pour la copie de This +// if ( pile1 == EOX ) return true; - if ( pile1->IfStep() ) return FALSE; + if ( pile1->IfStep() ) return false; CBotStack* pile2 = pile1->AddStack(); // et pour les paramètres à venir @@ -3656,12 +3653,12 @@ BOOL CBotInstrMethode::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 ) { 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 + 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 @@ -3683,11 +3680,11 @@ BOOL CBotInstrMethode::Execute(CBotStack* &pj) if ( !pClass->ExecuteMethode(m_MethodeIdent, m_NomMethod, pThis, ppVars, - pResult, pile2, GivToken())) return FALSE; // interrompu + 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); + old->Copy(pThis, false); if (pRes != pResult) delete pRes; @@ -3758,7 +3755,7 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack) // 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 + pVar->SetInit(true); // marque l'instance comme init if (typ>20) { @@ -3784,12 +3781,12 @@ error: // exécute une instruction "new" -BOOL CBotNew::Execute(CBotStack* &pj) +bool CBotNew::Execute(CBotStack* &pj) { CBotStack* pile = pj->AddStack(this); //pile principale -// if ( pile == EOX ) return TRUE; +// if ( pile == EOX ) return true; - if ( pile->IfStep() ) return FALSE; + if ( pile->IfStep() ) return false; CBotStack* pile1 = pj->AddStack2(); //pile secondaire @@ -3834,12 +3831,12 @@ BOOL CBotNew::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(); @@ -3853,7 +3850,7 @@ BOOL CBotNew::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->ConstructorSet(); // signale que le constructeur a été appelé // pile->Return(pile2); // libère un bout de pile @@ -3864,7 +3861,7 @@ BOOL CBotNew::Execute(CBotStack* &pj) return pj->Return( pile1 ); // transmet en dessous } -void CBotNew::RestoreState(CBotStack* &pj, BOOL bMain) +void CBotNew::RestoreState(CBotStack* &pj, bool bMain) { if ( !bMain ) return; @@ -3902,7 +3899,7 @@ void CBotNew::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; @@ -3926,31 +3923,31 @@ void CBotNew::RestoreState(CBotStack* &pj, BOOL bMain) ///////////////////////////////////////////////////////////// // regarde si deux résultats sont compatibles pour faire une opération -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 max = (t1 > t2) ? t1 : t2; - if ( max == 99 ) return FALSE; // un résultat est void ? + if ( max == 99 ) return false; // un résultat est 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; + 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; + (t1 == CBotTypPointer && t2 == CBotTypNullPointer)) return true; if ( (op == ID_EQ || op == ID_NE || op == ID_ASS) && - (t2 == CBotTypPointer && t1 == CBotTypNullPointer)) return TRUE; + (t2 == CBotTypPointer && t1 == CBotTypNullPointer)) return true; if ( (op == ID_EQ || op == ID_NE) && - (t1 == CBotTypArrayPointer && t2 == CBotTypNullPointer)) return TRUE; + (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; + (t2 == CBotTypArrayPointer && t1 == CBotTypNullPointer)) return true; + if (t2 != t1) return false; if (t1 == CBotTypArrayPointer) return type1.Compare(type2); if (t1 == CBotTypPointer || t1 == CBotTypClass || @@ -3964,17 +3961,17 @@ BOOL TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op ) // l'opération sera refusée à l'exécution si le pointeur n'est pas compatible } - return TRUE; + return true; } type1.SetType(max); type2.SetType(max); - return TRUE; + return true; } // regarde si deux variables sont compatible pour un passage de paramètre -BOOL TypesCompatibles( const CBotTypResult& type1, const CBotTypResult& type2 ) +bool TypesCompatibles( const CBotTypResult& type1, const CBotTypResult& type2 ) { int t1 = type1.GivType(); int t2 = type2.GivType(); @@ -3984,11 +3981,11 @@ BOOL TypesCompatibles( const CBotTypResult& type1, const CBotTypResult& type2 ) int max = (t1 > t2) ? t1 : t2; - if ( max == 99 ) return FALSE; // un résultat est void ? + if ( max == 99 ) return false; // un résultat est void ? if ( max >= CBotTypBoolean ) { - if ( t2 != t1 ) return FALSE; + if ( t2 != t1 ) return false; if ( max == CBotTypArrayPointer ) return TypesCompatibles(type1.GivTypElem(), type2.GivTypElem()); @@ -3996,9 +3993,9 @@ BOOL TypesCompatibles( const CBotTypResult& type1, const CBotTypResult& type2 ) if ( max == CBotTypClass || max == CBotTypPointer ) return type1.GivClass() == type2.GivClass() ; - return TRUE ; + return true ; } - return TRUE; + return true; } @@ -4042,7 +4039,7 @@ size_t fRead(void *buffer, size_t length, FILE* filehandle) //////////////////////////////////////// -#if FALSE +#if false CBotString num(int n) { @@ -4058,7 +4055,7 @@ CBotString num(int n) extern void DEBUG( const char* text, int val, CBotStack* pile ) { - CBotProgram* p = pile->GivBotCall(TRUE); + CBotProgram* p = pile->GivBotCall(true); if ( !p->m_bDebugDD ) return; FILE* pf = fopen("CbotDebug.txt", "a"); diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 7e15f65..6f18be8 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -17,15 +17,15 @@ // dernière révision : 03/10/2002 DD -#define EXTENDS TRUE +#define EXTENDS true #include "resource.h" #include "CBotDll.h" // définitions publiques #include "CBotToken.h" // gestion des tokens -#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 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 EOX (CBotStack*)-1 // marqueur condition spéciale @@ -61,12 +61,13 @@ 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 +// this is to create an instance of a stack +// to use for routine CBotProgram :: Execute (CBotStack) + class CBotStack { @@ -90,9 +91,9 @@ private: 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 + 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 @@ -105,7 +106,7 @@ private: void* m_pUser; CBotInstr* m_instr; // l'instruction correspondante - BOOL m_bFunc; // une entrée d'une fonction ? + bool m_bFunc; // une entrée d'une fonction ? CBotCall* m_call; // point de reprise dans un call extern friend class CBotTry; @@ -117,7 +118,7 @@ public: #endif CBotStack(CBotStack* ppapa); ~CBotStack(); - BOOL StackOver(); + bool StackOver(); int GivError(int& start, int& end); int GivError(); // rend le numéro d'erreur retourné @@ -127,48 +128,48 @@ public: 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, 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(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* FindVar(long ident, bool bUpdate = false, + bool bModif = false); - CBotVar* CopyVar(CBotToken& Token, BOOL bUpdate = FALSE); // trouve et rend une copie + 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* 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); + 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); + bool IfContinue(int state, const char* name); // ou de "continue" - BOOL IsOk(); + bool IsOk(); - BOOL SetState(int n, int lim = -10); // sélectionne un état + 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(); + 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); + bool GivRetVar(bool bRet); long GivVal(); void SetStartError(int pos); @@ -178,17 +179,17 @@ public: void SetBreak(int val, const char* name); void SetBotCall(CBotProgram* p); - CBotProgram* GivBotCall(BOOL bFirst = FALSE); + CBotProgram* GivBotCall(bool bFirst = false); void* GivPUser(); - BOOL GivBlock(); + bool GivBlock(); -// BOOL ExecuteCall(CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype); - BOOL ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype); +// 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); + bool SaveState(FILE* pf); + bool RestoreState(FILE* pf, CBotStack* &pStack); static void SetTimer(int n); @@ -201,7 +202,7 @@ public: // les routines inline doivent être déclarées dans le fichier .h -inline BOOL CBotStack::IsOk() +inline bool CBotStack::IsOk() { return (m_error == 0); } @@ -235,7 +236,7 @@ private: CBotVar* m_var; // résultat des opérations - BOOL m_bBlock; // fait partie d'un bloc (variables sont locales à ce bloc) + bool m_bBlock; // fait partie d'un bloc (variables sont locales à ce bloc) CBotVar* m_listVar; static @@ -249,7 +250,7 @@ public: CBotCStack(CBotCStack* ppapa); ~CBotCStack(); - BOOL IsOk(); + bool IsOk(); int GivError(); int GivError(int& start, int& end); // rend le numéro d'erreur retourné @@ -262,10 +263,10 @@ public: void AddVar(CBotVar* p); // ajoute une variable locale CBotVar* FindVar(CBotToken* &p); // trouve une variable CBotVar* FindVar(CBotToken& Token); - BOOL CheckVarLocal(CBotToken* &pToken); + bool CheckVarLocal(CBotToken* &pToken); CBotVar* CopyVar(CBotToken& Token); // trouve et rend une copie - CBotCStack* TokenStack(CBotToken* pToken = NULL, BOOL bBlock = FALSE); + 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 @@ -285,17 +286,17 @@ public: void SetBotCall(CBotProgram* p); CBotProgram* GivBotCall(); CBotTypResult CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent); - BOOL CheckCall(CBotToken* &pToken, CBotDefParam* pParam); + bool CheckCall(CBotToken* &pToken, CBotDefParam* pParam); - BOOL NextToken(CBotToken* &p); + 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: @@ -303,17 +304,17 @@ private: CBotStringArray m_labelLvl; protected: - CBotToken m_token; // conserve le token + CBotToken m_token; // keeps the 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 + 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 + for example, the following program int x[]; x[1] = 4; int y[x[1]][10], z; - va généré + is generated CBotInstrArray m_next3b-> CBotEmpty m_next-> @@ -338,31 +339,30 @@ public: virtual ~CBotInstr(); - DllExport//debug +// DllExport//debug static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); static - CBotInstr* CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, BOOL first = TRUE); + CBotInstr* CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool first = true); virtual - BOOL Execute(CBotStack* &pj); + bool Execute(CBotStack* &pj); virtual - BOOL Execute(CBotStack* &pj, CBotVar* pVar); + bool Execute(CBotStack* &pj, CBotVar* pVar); virtual - void RestoreState(CBotStack* &pj, BOOL bMain); + void RestoreState(CBotStack* &pj, bool bMain); virtual - BOOL ExecuteVar(CBotVar* &pVar, CBotCStack* &pile); + bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile); virtual - BOOL ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, BOOL bStep, BOOL bExtend); + bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend); virtual - void RestoreStateVar(CBotStack* &pile, BOOL bMain); + void RestoreStateVar(CBotStack* &pile, bool bMain); virtual - BOOL CompCase(CBotStack* &pj, int val); + bool CompCase(CBotStack* &pj, int val); void SetToken(CBotToken* p); - void SetToken(CBotString* name, int start=0, int end=0); int GivTokenType(); CBotToken* GivToken(); @@ -380,9 +380,9 @@ public: static void DecLvl(); static - BOOL ChkLvl(const CBotString& label, int type); + bool ChkLvl(const CBotString& label, int type); - BOOL IsOfClass(CBotString name); + bool IsOfClass(CBotString name); }; class CBotWhile : public CBotInstr @@ -397,24 +397,34 @@ public: ~CBotWhile(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + 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 @@ -429,8 +439,8 @@ public: ~CBotDo(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; class CBotFor : public CBotInstr @@ -447,8 +457,8 @@ public: ~CBotFor(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; class CBotBreak : public CBotInstr @@ -461,8 +471,8 @@ public: ~CBotBreak(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; class CBotReturn : public CBotInstr @@ -475,8 +485,8 @@ public: ~CBotReturn(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; @@ -491,8 +501,8 @@ public: ~CBotSwitch(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; @@ -506,9 +516,9 @@ public: ~CBotCase(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); - BOOL CompCase(CBotStack* &pj, int val); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); + bool CompCase(CBotStack* &pj, int val); }; class CBotCatch : public CBotInstr @@ -524,10 +534,10 @@ public: ~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); + 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 @@ -542,8 +552,8 @@ public: ~CBotTry(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; class CBotThrow : public CBotInstr @@ -556,8 +566,8 @@ public: ~CBotThrow(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; @@ -570,7 +580,7 @@ public: ~CBotStartDebugDD(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); + bool Execute(CBotStack* &pj); }; @@ -586,8 +596,8 @@ public: ~CBotIf(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; @@ -604,9 +614,9 @@ 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); + 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 @@ -625,8 +635,8 @@ public: ~CBotInstArray(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; @@ -643,15 +653,15 @@ public: ~CBotListArray(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type); - BOOL Execute(CBotStack* &pj, CBotVar* pVar); - void RestoreState(CBotStack* &pj, BOOL bMain); + 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 @@ -666,9 +676,9 @@ 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); + CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; @@ -684,9 +694,9 @@ 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); + 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 @@ -701,9 +711,9 @@ 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); + 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 @@ -715,7 +725,7 @@ private: 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 ? + bool m_hasParams; // il y a des paramètres ? long m_nMethodeIdent; public: @@ -723,8 +733,8 @@ public: ~CBotClassInst(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass = NULL); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; class CBotCondition : public CBotInstr @@ -751,11 +761,11 @@ public: ~CBotLeftExpr(); static CBotLeftExpr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pStack, CBotStack* array); + 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); + bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile); + bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep); + void RestoreStateVar(CBotStack* &pile, bool bMain); }; @@ -773,9 +783,9 @@ public: 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); + 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 @@ -792,9 +802,9 @@ public: ~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); + 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 @@ -812,8 +822,8 @@ public: ~CBotExpression(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pStack); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pStack); + void RestoreState(CBotStack* &pj, bool bMain); }; class CBotListExpression : public CBotInstr @@ -826,8 +836,8 @@ public: ~CBotListExpression(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pStack); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pStack); + void RestoreState(CBotStack* &pj, bool bMain); }; class CBotLogicExpr : public CBotInstr @@ -843,8 +853,8 @@ public: ~CBotLogicExpr(); // static // CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pStack); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pStack); + void RestoreState(CBotStack* &pj, bool bMain); }; @@ -882,8 +892,8 @@ public: ~CBotExprUnaire(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pStack); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pStack); + void RestoreState(CBotStack* &pj, bool bMain); }; // toutes les opérations à 2 opérandes @@ -898,8 +908,8 @@ public: ~CBotTwoOpExpr(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations = NULL); - BOOL Execute(CBotStack* &pStack); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pStack); + void RestoreState(CBotStack* &pj, bool bMain); }; @@ -912,9 +922,9 @@ private: public: static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, BOOL bLocal = TRUE); + CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true); static - CBotInstr* CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, BOOL bLocal = FALSE); + CBotInstr* CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal = false); }; @@ -928,9 +938,9 @@ public: CBotListInstr(); ~CBotListInstr(); static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, BOOL bLocal = TRUE); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; @@ -949,8 +959,8 @@ public: ~CBotInstrCall(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; // un appel d'une méthode @@ -974,12 +984,12 @@ public: ~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); + 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 { @@ -996,11 +1006,11 @@ public: 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); + 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 @@ -1014,8 +1024,8 @@ public: ~CBotPostIncExpr(); // static // CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; class CBotPreIncExpr : public CBotInstr @@ -1029,8 +1039,8 @@ public: ~CBotPreIncExpr(); // static // CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; @@ -1047,8 +1057,8 @@ public: ~CBotLeftExprVar(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; @@ -1062,8 +1072,8 @@ public: static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; @@ -1075,8 +1085,8 @@ public: 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 @@ -1087,8 +1097,8 @@ public: 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 @@ -1105,8 +1115,8 @@ public: static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; // expression représentant un nombre @@ -1123,8 +1133,8 @@ public: ~CBotExprNum(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; @@ -1140,8 +1150,8 @@ public: ~CBotExprAlpha(); static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); }; @@ -1166,7 +1176,7 @@ public: 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 @@ -1176,12 +1186,12 @@ public: 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); @@ -1196,8 +1206,8 @@ public: void Inc(); void Dec(); - BOOL Save0State(FILE* pf); - BOOL Save1State(FILE* pf); + bool Save0State(FILE* pf); + bool Save1State(FILE* pf); }; @@ -1217,7 +1227,7 @@ public: 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 @@ -1227,18 +1237,18 @@ public: 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(); - BOOL Save1State(FILE* pf); + bool Save1State(FILE* pf); }; @@ -1255,25 +1265,25 @@ public: 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 - 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 ); @@ -1285,16 +1295,16 @@ public: 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); + bool Eq(CBotVar* left, CBotVar* right); + bool Ne(CBotVar* left, CBotVar* right); - BOOL Save1State(FILE* pf); + bool Save1State(FILE* pf); }; @@ -1315,7 +1325,7 @@ private: 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é + bool m_bConstructor; // set si un constructeur a été appelé public: CBotVarClass( const CBotToken* name, const CBotTypResult& type ); @@ -1323,19 +1333,19 @@ public: ~CBotVarClass(); // void InitCBotVarClass( const CBotToken* name, CBotTypResult& type, int &nIdent ); - void Copy(CBotVar* pSrc, BOOL bName=TRUE); + 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* GivItem(int n, bool bExtend); CBotVar* GivItemList(); 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 @@ -1351,8 +1361,8 @@ public: // 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(); }; @@ -1371,7 +1381,7 @@ public: CBotVarPointer( const CBotToken* name, CBotTypResult& type ); ~CBotVarPointer(); - void Copy(CBotVar* pSrc, BOOL bName=TRUE); + 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 (*) @@ -1387,11 +1397,11 @@ public: long GivIdent(); // donne le numéro d'identification associé void ConstructorSet(); - BOOL Save1State(FILE* pf); - void Maj(void* pUser, BOOL bContinue); + bool Save1State(FILE* pf); + void Maj(void* pUser, bool bContinue); - BOOL Eq(CBotVar* left, CBotVar* right); - BOOL Ne(CBotVar* left, CBotVar* right); + bool Eq(CBotVar* left, CBotVar* right); + bool Ne(CBotVar* left, CBotVar* right); }; @@ -1415,37 +1425,37 @@ public: 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 + 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); + 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 @@ -1463,36 +1473,36 @@ private: private: CBotString m_name; - BOOL (*m_rExec) (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser) ; + 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), + 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), + 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); + 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); + bool Run(CBotStack* pStack); static - BOOL RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotStack* pStack); + bool RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotStack* pStack); #endif CBotString GivName(); @@ -1508,7 +1518,7 @@ class CBotCallMethode { private: CBotString m_name; - BOOL (*m_rExec) (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception); + bool (*m_rExec) (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception); CBotTypResult (*m_rComp) (CBotVar* pThis, CBotVar* &pVar); CBotCallMethode* m_next; @@ -1517,7 +1527,7 @@ private: public: 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)); ~CBotCallMethode(); @@ -1550,8 +1560,8 @@ public: ~CBotDefParam(); static CBotDefParam* Compile(CBotToken* &p, CBotCStack* pStack); - BOOL Execute(CBotVar** ppVars, CBotStack* &pj); - void RestoreState(CBotStack* &pj, BOOL bMain); + bool Execute(CBotVar** ppVars, CBotStack* &pj); + void RestoreState(CBotStack* &pj, bool bMain); void AddNext(CBotDefParam* p); int GivType(); @@ -1575,7 +1585,7 @@ private: friend class CBotCStack; // long m_nThisIdent; long m_nFuncIdent; - BOOL m_bSynchro; // méthode synchronisée ? + bool m_bSynchro; // méthode synchronisée ? private: CBotDefParam* m_Param; // liste des paramètres @@ -1584,8 +1594,8 @@ private: 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 + 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; @@ -1600,32 +1610,32 @@ public: CBotFunction(); ~CBotFunction(); static - CBotFunction* Compile(CBotToken* &p, CBotCStack* pStack, CBotFunction* pFunc, BOOL bLocal = TRUE); + 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); + 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); + 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); + bool CheckParam(CBotDefParam* pParam); static void AddPublic(CBotFunction* pfunc); CBotString GivName(); CBotString GivParams(); - BOOL IsPublic(); - BOOL IsExtern(); + bool IsPublic(); + bool IsExtern(); CBotFunction* Next(); - BOOL GetPosition(int& start, int& stop, CBotGet modestart, CBotGet modestop); + bool GetPosition(int& start, int& stop, CBotGet modestart, CBotGet modestop); }; 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..f0d7fef 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -19,10 +19,10 @@ //#include "stdafx.h" -#include +// #include #include -#define DllExport __declspec( dllexport ) +// #define DllExport __declspec( dllexport ) #define CBOTVERSION 104 @@ -93,62 +93,62 @@ private: public: // divers constructeurs selon les besoins - DllExport + //DllExport CBotTypResult(int type); // pour les types simples (CBotTypInt à CBotTypString) - DllExport + //DllExport CBotTypResult(int type, const char* name); // pour les types pointeur et classe intrinsic - DllExport + //DllExport CBotTypResult(int type, CBotClass* pClass); // idem à partir de l'instance d'une classe - DllExport + //DllExport CBotTypResult(int type, CBotTypResult elem); // pour les tableaux de variables - DllExport + //DllExport CBotTypResult(const CBotTypResult& typ); // pour les assignations - DllExport + //DllExport CBotTypResult(); // pour par défaut - DllExport + //DllExport ~CBotTypResult(); - DllExport + //DllExport int GivType(int mode = 0) const; // rend le type CBotTyp* du résultat void SetType(int n); // modifie le type - DllExport + //DllExport CBotClass* GivClass() const; // rend le pointeur à la classe (pour les CBotTypClass, CBotTypPointer) - DllExport + //DllExport int GivLimite() const; // rend la taille limite du tableau (CBotTypArray) - DllExport + //DllExport void SetLimite(int n); // fixe une limite au tableau void SetArray(int* max ); // idem avec une liste de dimension (tableaux de tableaux) - DllExport + //DllExport CBotTypResult& GivTypElem() const; // rend le type des éléments du tableau (CBotTypArray) - DllExport - BOOL Compare(const CBotTypResult& typ) const; + //DllExport + bool Compare(const CBotTypResult& typ) const; // compare si les types sont compatibles - DllExport - BOOL Eq(int type) const; + //DllExport + bool Eq(int type) const; // compare le type - DllExport + //DllExport CBotTypResult& operator=(const CBotTypResult& src); // copie un type complet dans un autre @@ -259,102 +259,102 @@ class CBotString private: char* m_ptr; // pointeur à la chaine int m_lg; // longueur de la chaine - static - HINSTANCE m_hInstance; + // static + // HINSTANCE m_hInstance; public: - DllExport + //DllExport CBotString(); - DllExport + //DllExport CBotString(const char* p); - DllExport + //DllExport CBotString(const CBotString& p); - DllExport + //DllExport ~CBotString(); - DllExport + //DllExport void Empty(); - DllExport - BOOL IsEmpty() const; - DllExport + //DllExport + bool IsEmpty() const; + //DllExport int GivLength(); - DllExport + //DllExport int Find(const char c); - DllExport - int Find(LPCTSTR lpsz); - DllExport + //DllExport + int Find(const char* lpsz); + //DllExport int ReverseFind(const char c); - DllExport - int ReverseFind(LPCTSTR lpsz); - DllExport - BOOL LoadString(UINT id); - DllExport + //DllExport + int ReverseFind(const char* lpsz); + //DllExport + bool LoadString(unsigned int id); + //DllExport CBotString Mid(int nFirst, int nCount) const; - DllExport + //DllExport CBotString Mid(int nFirst) const; - DllExport + //DllExport CBotString Left(int nCount) const; - DllExport + //DllExport CBotString Right(int nCount) const; - DllExport + //DllExport const CBotString& operator=(const CBotString& stringSrc); - DllExport + //DllExport const CBotString& operator=(const char ch); - DllExport + //DllExport const CBotString& operator=(const char* pString); - DllExport + //DllExport const CBotString& operator+(const CBotString& str); - DllExport + //DllExport friend CBotString - operator+(const CBotString& string, LPCTSTR lpsz); + operator+(const CBotString& string, const char* lpsz); - DllExport + //DllExport const CBotString& operator+=(const char ch); - DllExport + //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 + //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 const char*() const; // as a C string + + int Compare(const char* lpsz) const; + + //DllExport CBotString Mid(int start, int lg=-1); - DllExport + //DllExport void MakeUpper(); - DllExport + //DllExport void MakeLower(); }; @@ -369,20 +369,20 @@ private: CBotString* m_pData; // ^aux données public: - DllExport + //DllExport CBotStringArray(); - DllExport + //DllExport ~CBotStringArray(); - DllExport + //DllExport void SetSize(int nb); - DllExport + //DllExport int GivSize(); - DllExport + //DllExport void Add(const CBotString& str); - DllExport + //DllExport CBotString& operator[](int nIndex); - DllExport + //DllExport CBotString& ElementAt(int nIndex); }; @@ -418,87 +418,87 @@ private: public: static CBotString m_DebugVarStr; // a fin de debug - BOOL m_bDebugDD; // idem déclanchable par robot + bool m_bDebugDD; // idem déclanchable par robot - BOOL m_bCompileClass; + bool m_bCompileClass; public: - DllExport + //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 + //DllExport static void Free(); // libère les zones mémoires statiques - DllExport + //DllExport static int GivVersion(); // donne la version de la librairie CBOT - DllExport + //DllExport CBotProgram(); - DllExport + //DllExport CBotProgram(CBotVar* pInstance); - DllExport + //DllExport ~CBotProgram(); - DllExport - BOOL Compile( const char* program, CBotStringArray& ListFonctions, void* pUser = NULL); + //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 + // 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 + //DllExport void SetIdent(long n); // associe un identificateur avec l'instance CBotProgram - DllExport + //DllExport long GivIdent(); // redonne l'identificateur - DllExport + //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 + //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 + //DllExport static CBotString GivErrorText(int code); - DllExport - BOOL Start(const char* name); + //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 + // 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); + //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 + // 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); + //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é) + // 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 + //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 @@ -507,41 +507,41 @@ public: // 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 + //DllExport void Stop(); // arrête l'exécution du programme // quitte donc le mode "suspendu" - DllExport + //DllExport static void SetTimer(int n); // défini le nombre de pas (parties d'instructions) à faire - // dans Run() avant de rendre la main "FALSE" + // dans Run() avant de rendre la main "false" - DllExport + //DllExport static - BOOL AddFunction(const char* name, - BOOL rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), + 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 + //DllExport static - BOOL DefineNum(const char* name, long val); + bool DefineNum(const char* name, long val); - DllExport - BOOL SaveState(FILE* pf); + //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); + //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, + //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 @@ -555,13 +555,13 @@ public: /////////////////////////////////////////////////////////////////////////////// // routines pour la gestion d'un fichier (FILE*) - DllExport + //DllExport FILE* fOpen(const char* name, const char* mode); - DllExport + //DllExport int fClose(FILE* filehandle); - DllExport + //DllExport size_t fWrite(const void *buffer, size_t elemsize, size_t length, FILE* filehandle); - DllExport + //DllExport size_t fRead(void *buffer, size_t elemsize, size_t length, FILE* filehandle); @@ -594,7 +594,7 @@ int cMoyenne(CBotVar* &pVar, CBotString& ClassName) } -BOOL rMoyenne(CBotVar* pVar, CBotVar* pResult, int& Exception) +bool rMoyenne(CBotVar* pVar, CBotVar* pResult, int& Exception) { float total = 0; int nb = 0; @@ -606,7 +606,7 @@ BOOL rMoyenne(CBotVar* pVar, CBotVar* pResult, int& Exception) } pResult->SetValFloat(total/nb); // retourne la valeur moyenne - return TRUE; // opération totalement terminée + return true; // opération totalement terminée } #endif @@ -645,7 +645,7 @@ protected: 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) + 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 @@ -663,17 +663,17 @@ public: virtual ~CBotVar( ); // destructeur -/* DllExport +/* //DllExport static CBotVar* Create( const char* name, int type, const char* ClassName = NULL); // crée une variable selon son type,*/ - DllExport + //DllExport static CBotVar* Create( const char* name, CBotTypResult type); // idem à partir du type complet - DllExport + //DllExport static CBotVar* Create( const char* name, CBotClass* pClass); // idem pour une instance d'une classe connue @@ -690,51 +690,51 @@ virtual ~CBotVar( ); // destructeur CBotVar* Create( CBotVar* pVar ); - DllExport + //DllExport void SetUserPtr(void* pUser); // associe un pointeur utilisateur à une instance - DllExport + //DllExport virtual void SetIdent(long UniqId); // associe un identificateur unique à une instance // ( c'est à l'utilisateur de s'assurer que l'id est unique) - DllExport + //DllExport void* GivUserPtr(); // rend le pointeur associé à la variable - DllExport + //DllExport CBotString GivName(); // le nom de la variable, s'il est connu //////////////////////////////////////////////////////////////////////////////////// void SetName(const char* name); // change le nom de la variable - DllExport + //DllExport int GivType(int mode = 0); // rend le type de base (int) de la variable //////////////////////////////////////////////////////////////////////////////////////// - DllExport + //DllExport CBotTypResult GivTypResult(int mode = 0); // rend le type complet de la variable CBotToken* GivToken(); void SetType(CBotTypResult& type); - DllExport + //DllExport void SetInit(int bInit); // met la variable dans l'état IS_UNDEF, IS_DEF, IS_NAN - DllExport + //DllExport int GivInit(); // donne l'état de la variable - DllExport - void SetStatic(BOOL bStatic); - DllExport - BOOL IsStatic(); + //DllExport + void SetStatic(bool bStatic); + //DllExport + bool IsStatic(); - DllExport + //DllExport void SetPrivate(int mPrivate); - DllExport - BOOL IsPrivate(int mode = PR_PROTECT); - DllExport + //DllExport + bool IsPrivate(int mode = PR_PROTECT); + //DllExport int GivPrivate(); virtual @@ -742,55 +742,55 @@ virtual ~CBotVar( ); // destructeur void SetVal(CBotVar* var); // remprend une valeur - DllExport + //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 - DllExport + //DllExport virtual - CBotVar* GivItem(int row, BOOL bGrow = FALSE); + CBotVar* GivItem(int row, bool bGrow = false); - DllExport + //DllExport virtual CBotVar* GivItemList(); // donne la liste des éléments - DllExport + //DllExport CBotVar* GivStaticVar(); // rend le pointeur à la variable si elle est statique - DllExport - BOOL IsElemOfClass(const char* name); + //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 + // rend true si l'objet est d'une classe fille - DllExport + //DllExport CBotVar* GivNext(); // prochaine variable dans la liste (paramètres) //////////////////////////////////////////////////////////////////////////////////////////// void AddNext(CBotVar* pVar); // ajoute dans une liste virtual - void Copy(CBotVar* pSrc, BOOL bName = TRUE); // fait une copie de la variable + void Copy(CBotVar* pSrc, bool bName = true); // fait une copie de la variable - DllExport + //DllExport virtual void SetValInt(int val, const char* name = NULL); // initialise avec une valeur entière (#) ///////////////////////////////////////////////////////////////////////////////// - DllExport + //DllExport virtual void SetValFloat(float val); // initialise avec une valeur réelle (#) //////////////////////////////////////////////////////////////////////////////// - DllExport + //DllExport virtual void SetValString(const char* p);// initialise avec une valeur chaîne (#) //////////////////////////////////////////////////////////////////////////////// - DllExport + //DllExport virtual int GivValInt(); // demande la valeur entière (#) //////////////////////////////////////////////////////////////////////// - DllExport + //DllExport virtual float GivValFloat(); // demande la valeur réelle (#) /////////////////////////////////////////////////////////////////////// @@ -814,12 +814,12 @@ virtual ~CBotVar( ); // destructeur virtual int Modulo(CBotVar* left, CBotVar* right); // reste de division virtual void Power(CBotVar* left, CBotVar* right); // puissance - 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 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); @@ -834,19 +834,19 @@ virtual ~CBotVar( ); // destructeur virtual void Dec(); - virtual BOOL Save0State(FILE* pf); - virtual BOOL Save1State(FILE* pf); - static BOOL RestoreState(FILE* pf, CBotVar* &pVar); + virtual bool Save0State(FILE* pf); + virtual bool Save1State(FILE* pf); + static bool RestoreState(FILE* pf, CBotVar* &pVar); - DllExport + //DllExport void debug(); // virtual // CBotVar* GivMyThis(); - DllExport + //DllExport virtual - void Maj(void* pUser = NULL, BOOL bContinue = TRUE); + void Maj(void* pUser = NULL, bool bContinue = true); void SetUniqNum(long n); long GivUniqNum(); @@ -888,7 +888,7 @@ private: 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 + 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 @@ -899,37 +899,37 @@ private: CBotProgram* m_ProgInLock[5];// processus en attente pour synchro public: - BOOL m_IsDef; // marque si est définie ou pas encore + bool m_IsDef; // marque si est définie ou pas encore - DllExport + //DllExport CBotClass( const char* name, - CBotClass* pParent, BOOL bIntrinsic = FALSE ); // constructeur + 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 + //DllExport ~CBotClass( ); // destructeur - DllExport - BOOL AddFunction(const char* name, - BOOL rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception), + //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 ) ); + //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); + //DllExport + bool AddItem(CBotString name, CBotTypResult type, int mPrivate = PR_PUBLIC); // ajoute un élément à la classe -// DllExport -// BOOL AddItem(CBotString name, CBotClass* pClass); +// //DllExport +// bool AddItem(CBotString name, CBotClass* pClass); // idem pour des éléments appartenant à pClass - DllExport - BOOL AddItem(CBotVar* pVar); + //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 @@ -938,20 +938,20 @@ public: // idem en donnant un élément de type CBotVar void AddNext(CBotClass* pClass); - DllExport + //DllExport CBotString GivName(); // rend le nom de la classe - DllExport + //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); + // 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 + //DllExport static CBotClass* Find(const char* name); @@ -962,7 +962,7 @@ public: 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); + 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 @@ -971,27 +971,27 @@ public: static CBotClass* Compile1(CBotToken* &p, CBotCStack* pStack); - BOOL CompileDefItem(CBotToken* &p, CBotCStack* pStack, BOOL bSecond); + bool CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond); - BOOL IsIntrinsic(); + bool IsIntrinsic(); void Purge(); static void Free(); - DllExport + //DllExport static - BOOL SaveStaticState(FILE* pf); + bool SaveStaticState(FILE* pf); - DllExport + //DllExport static - BOOL RestoreStaticState(FILE* pf); + bool RestoreStaticState(FILE* pf); - BOOL Lock(CBotProgram* p); + bool Lock(CBotProgram* p); void Unlock(); static void FreeLock(CBotProgram* p); - BOOL CheckCall(CBotToken* &pToken, CBotDefParam* pParam); + bool CheckCall(CBotToken* &pToken, CBotDefParam* pParam); }; @@ -1041,7 +1041,7 @@ private: static int GivKeyWords(const char* w); // est-ce un mot clef ? static - BOOL GivKeyDefNum(const char* w, CBotToken* &token); + bool GivKeyDefNum(const char* w, CBotToken* &token); static void LoadKeyWords(); // fait la liste des mots clefs @@ -1054,37 +1054,37 @@ public: // constructeur ~CBotToken(); // destructeur - DllExport + //DllExport int GivType(); // rend le type du token - DllExport + //DllExport CBotString& GivString(); // rend la chaine correspondant à ce token - DllExport + //DllExport CBotString& GivSep(); // rend le séparateur suivant le token - DllExport + //DllExport int GivStart(); // position du début dans le texte - DllExport + //DllExport int GivEnd(); // position de fin dans le texte - DllExport + //DllExport CBotToken* GivNext(); // rend le suivant dans la liste - DllExport + //DllExport CBotToken* GivPrev(); // rend le Précédent dans la liste - DllExport + //DllExport static CBotToken* CompileTokens(const char* p, int& error); // transforme tout le programme - DllExport + //DllExport static void Delete(CBotToken* pToken); // libère la liste // fonctions non utiles en export static - BOOL DefineNum(const char* name, long val); + bool DefineNum(const char* name, long val); void SetString(const char* name); void SetPos(int start, int end); @@ -1092,7 +1092,7 @@ public: void AddNext(CBotToken* p); // ajoute un token (une copie) static - CBotToken* NextToken(char* &program, int& error, BOOL first = FALSE); + CBotToken* NextToken(char* &program, int& error, bool first = false); // trouve le prochain token const CBotToken& operator=(const CBotToken& src); @@ -1163,7 +1163,7 @@ public: // exécute le programme main // ------------------------- - while( FALSE = m_pMonRobot->Execute( "main", pStack )) + while( false = m_pMonRobot->Execute( "main", pStack )) { // programme suspendu // on pourrait passer la main à un autre (en sauvegardant pStack pour ce robot-là) @@ -1174,10 +1174,10 @@ public: // 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; ) + 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 @@ -1193,8 +1193,8 @@ BOOL rDoGoto( CBotVar* pVar, CBotVar* pResult, int& exception ) 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 diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp index 488061c..784e647 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; @@ -1394,7 +1394,7 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack) #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 +1404,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 +1413,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 +1438,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 +1463,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 +1485,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 +1502,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 +1540,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 +1563,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 +1578,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; } @@ -1637,10 +1637,10 @@ CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack) 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..77ed7d7 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -16,6 +16,8 @@ // gestion de la pile (stack) #include "CBot.h" +#include +#include #define ITIMER 100 @@ -24,14 +26,14 @@ // 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 @@ -48,7 +50,7 @@ CBotStack* CBotStack::FirstStack() // la vide totalement memset(p, 0, size); - p-> m_bBlock = TRUE; + p-> m_bBlock = true; m_timer = m_initimer; // met le timer au début CBotStack* pp = p; @@ -56,7 +58,7 @@ CBotStack* CBotStack::FirstStack() int i; for ( i = 0 ; i< 10 ; i++ ) { - pp->m_bOver = TRUE; + pp->m_bOver = true; pp ++; } #ifdef _DEBUG @@ -75,8 +77,8 @@ CBotStack* CBotStack::FirstStack() 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() @@ -104,7 +106,7 @@ void CBotStack::Delete() delete m_listVar; CBotStack* p = m_prev; - BOOL bOver = m_bOver; + bool bOver = m_bOver; #ifdef _DEBUG int n = m_index; #endif @@ -122,7 +124,7 @@ void CBotStack::Delete() // routine optimisée -CBotStack* CBotStack::AddStack(CBotInstr* instr, BOOL bBlock) +CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock) { if (m_next != NULL) { @@ -150,11 +152,11 @@ CBotStack* CBotStack::AddStack(CBotInstr* instr, BOOL bBlock) p->m_prev = this; p->m_state = 0; p->m_call = NULL; - p->m_bFunc = FALSE; + p->m_bFunc = false; return p; } -CBotStack* CBotStack::AddStackEOX(CBotCall* instr, BOOL bBlock) +CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock) { if (m_next != NULL) { @@ -171,7 +173,7 @@ CBotStack* CBotStack::AddStackEOX(CBotCall* instr, BOOL bBlock) return p; } -CBotStack* CBotStack::AddStack2(BOOL bBlock) +CBotStack* CBotStack::AddStack2(bool bBlock) { if (m_next2 != NULL) { @@ -194,14 +196,14 @@ CBotStack* CBotStack::AddStack2(BOOL bBlock) return p; } -BOOL CBotStack::GivBlock() +bool CBotStack::GivBlock() { 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 @@ -213,9 +215,9 @@ BOOL CBotStack::Return(CBotStack* pfils) 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 @@ -224,11 +226,11 @@ BOOL CBotStack::ReturnKeep(CBotStack* pfils) return (m_error == 0); // interrompu si erreur } -BOOL CBotStack::StackOver() +bool CBotStack::StackOver() { - if (!m_bOver) return FALSE; + if (!m_bOver) return false; m_error = TX_STACKOVER; - return TRUE; + return true; } #else @@ -239,7 +241,7 @@ 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; @@ -247,13 +249,13 @@ CBotStack::CBotStack(CBotStack* ppapa) if (ppapa == NULL) m_timer = m_initimer; // met le timer au début m_listVar = NULL; - m_bDontDelete = FALSE; + m_bDontDelete = false; m_var = NULL; m_prog = NULL; m_instr = NULL; m_call = NULL; - m_bFunc = FALSE; + m_bFunc = false; } // destructeur @@ -269,7 +271,7 @@ CBotStack::~CBotStack() } // routine à optimiser -CBotStack* CBotStack::AddStack(CBotInstr* instr, BOOL bBlock) +CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock) { if (m_next != NULL) { @@ -284,7 +286,7 @@ CBotStack* CBotStack::AddStack(CBotInstr* instr, BOOL bBlock) return p; } -CBotStack* CBotStack::AddStackEOX(CBotCall* instr, BOOL bBlock) +CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock) { if (m_next != NULL) { @@ -305,7 +307,7 @@ CBotStack* CBotStack::AddStackEOX(CBotCall* instr, BOOL bBlock) return p; } -CBotStack* CBotStack::AddStack2(BOOL bBlock) +CBotStack* CBotStack::AddStack2(bool bBlock) { if (m_next2 != NULL) { @@ -322,9 +324,9 @@ CBotStack* CBotStack::AddStack2(BOOL bBlock) 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 @@ -336,9 +338,9 @@ BOOL CBotStack::Return(CBotStack* pfils) 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 @@ -377,38 +379,38 @@ CBotStack* CBotStack::RestoreStackEOX(CBotCall* instr) // 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 + return false; // c'est pas pour moi 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 + 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; + return true; } void CBotStack::SetBreak(int val, const char* name) @@ -424,7 +426,7 @@ void CBotStack::SetBreak(int val, const char* name) // 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) { @@ -432,7 +434,7 @@ BOOL CBotStack::GivRetVar(BOOL bRet) m_var = m_retvar; m_retvar = NULL; m_error = 0; - return TRUE; + return true; } return bRet; // interrompu par autre chose que return } @@ -469,7 +471,7 @@ void CBotStack::SetType(CBotTypResult& 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(); @@ -482,7 +484,7 @@ CBotVar* CBotStack::FindVar(CBotToken* &pToken, BOOL bUpdate, BOOL bModif) if (pp->GivName() == name) { if ( bUpdate ) - pp->Maj(m_pUser, FALSE); + pp->Maj(m_pUser, false); return pp; } @@ -515,7 +517,7 @@ CBotVar* CBotStack::FindVar(const char* name) // 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) @@ -526,7 +528,7 @@ CBotVar* CBotStack::FindVar(long ident, BOOL bUpdate, BOOL bModif) if (pp->GivUniqNum() == ident) { if ( bUpdate ) - pp->Maj(m_pUser, FALSE); + pp->Maj(m_pUser, false); return pp; } @@ -538,14 +540,14 @@ CBotVar* CBotStack::FindVar(long ident, BOOL bUpdate, BOOL bModif) } -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); } -CBotVar* CBotStack::CopyVar(CBotToken& Token, BOOL bUpdate) +CBotVar* CBotStack::CopyVar(CBotToken& Token, bool bUpdate) { CBotVar* pVar = FindVar( Token, bUpdate ); @@ -557,7 +559,7 @@ CBotVar* CBotStack::CopyVar(CBotToken& Token, BOOL bUpdate) } -BOOL CBotStack::SetState(int n, int limite) +bool CBotStack::SetState(int n, int limite) { m_state = n; @@ -565,7 +567,7 @@ BOOL CBotStack::SetState(int n, int limite) return ( m_timer > limite ); // interrompu si timer passé } -BOOL CBotStack::IncState(int limite) +bool CBotStack::IncState(int limite) { m_state++; @@ -603,7 +605,7 @@ void CBotStack::SetTimer(int n) m_initimer = n; } -BOOL CBotStack::Execute() +bool CBotStack::Execute() { CBotCall* instr = NULL; // instruction la plus élevée CBotStack* pile; @@ -621,9 +623,9 @@ BOOL CBotStack::Execute() 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(); @@ -632,7 +634,7 @@ BOOL CBotStack::Execute() #endif pile->m_next = EOX; // spécial pour reprise - return TRUE; + return true; } // met sur le stack le pointeur à une variable @@ -711,10 +713,10 @@ void CBotStack::AddVar(CBotVar* pVar) void CBotStack::SetBotCall(CBotProgram* p) { m_prog = p; - m_bFunc = TRUE; + m_bFunc = true; } -CBotProgram* CBotStack::GivBotCall(BOOL bFirst) +CBotProgram* CBotStack::GivBotCall(bool bFirst) { if ( ! bFirst ) return m_prog; CBotStack* p = this; @@ -728,7 +730,7 @@ void* CBotStack::GivPUser() } -BOOL CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype) +bool CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype) { CBotTypResult res; @@ -750,7 +752,7 @@ BOOL CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBo if (res.GivType() >= 0) return res.GivType(); SetError(TX_NOCALL, token); - return TRUE; + return true; } void CBotStack::RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar) @@ -762,17 +764,17 @@ void CBotStack::RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar) } -BOOL SaveVar(FILE* pf, CBotVar* pVar) +bool SaveVar(FILE* pf, CBotVar* pVar) { - while ( TRUE ) + 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(); } @@ -856,7 +858,7 @@ CBotVar* CBotStack::GivStackVars(const char* &FunctionName, int level) return p->m_listVar; } -BOOL CBotStack::SaveState(FILE* pf) +bool CBotStack::SaveState(FILE* pf) { if ( this == NULL ) // fin de l'arbre ? { @@ -865,33 +867,33 @@ BOOL CBotStack::SaveState(FILE* pf) if ( m_next2 != NULL ) { - if (!WriteWord(pf, 2)) return FALSE; // une marque de poursuite - if (!m_next2->SaveState(pf)) return FALSE; + 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, 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 (!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 (!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 } -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; + if (!ReadWord(pf, w)) return false; + if ( w == 0 ) return true; #if STACKMEM if ( this == NULL ) pStack = FirstStack(); @@ -902,81 +904,81 @@ BOOL CBotStack::RestoreState(FILE* pf, CBotStack* &pStack) if ( w == 2 ) { - if (!pStack->RestoreState(pf, pStack->m_next2)) return FALSE; + if (!pStack->RestoreState(pf, pStack->m_next2)) return false; } - if (!ReadWord(pf, w)) return FALSE; // est-ce un bloc local + 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 ? + 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 ? + if (!ReadWord(pf, w)) return false; // dont delete ? // plus utilisé - if (!ReadWord(pf, w)) return FALSE; // pas à pas + 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); } -BOOL CBotVar::Save0State(FILE* pf) +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 ? + 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) +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 + if(!WriteWord(pf, 200 )) return false; // marqueur spécial + if(!WriteString(pf, m_defnum)) return false; // nom de la valeur } return CBotVar::Save0State(pf); } -BOOL CBotVarInt::Save1State(FILE* pf) +bool CBotVarInt::Save1State(FILE* pf) { 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 } -BOOL CBotVarFloat::Save1State(FILE* pf) +bool CBotVarFloat::Save1State(FILE* pf) { 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 } -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 } -BOOL CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) +bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) { - WORD w, wi, prv, st; + unsigned short w, wi, prv, st; float ww; CBotString name, s; @@ -986,31 +988,31 @@ BOOL CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) CBotVar* pNew = NULL; CBotVar* pPrev = NULL; - while ( TRUE ) // recupère toute une liste + while ( true ) // recupère toute une liste { - if (!ReadWord(pf, w)) return FALSE; // privé ou type ? - if ( w == 0 ) return TRUE; + 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 + 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 + if (!ReadWord(pf, st)) return false; // statique + if (!ReadWord(pf, w)) return false; // type } 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()); @@ -1019,17 +1021,17 @@ BOOL CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) case CBotTypInt: case CBotTypBoolean: pNew = CBotVar::Create(&token, w); // crée une variable - if (!ReadWord(pf, w)) return FALSE; + 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; + 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; + if (!ReadString(pf, s)) return false; pNew->SetValString(s); break; @@ -1039,17 +1041,17 @@ BOOL CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) { CBotTypResult r; long id; - if (!ReadType(pf, r)) return FALSE; // type complet - if (!ReadLong(pf, id) ) return FALSE; + if (!ReadType(pf, r)) return false; // type complet + if (!ReadLong(pf, id) ) return false; -// if (!ReadString(pf, s)) return FALSE; +// 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; + if ( !RestoreState(pf, ((CBotVarClass*)pNew)->m_pVar)) return false; pNew->SetIdent(id); if ( p != NULL ) @@ -1063,7 +1065,7 @@ BOOL CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) case CBotTypPointer: case CBotTypNullPointer: - if (!ReadString(pf, s)) return FALSE; + if (!ReadString(pf, s)) return false; { pNew = CBotVar::Create(&token, CBotTypResult(w, s));// crée une variable CBotVarClass* p = NULL; @@ -1073,7 +1075,7 @@ BOOL CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) // restitue une copie de l'instance d'origine CBotVar* pInstance = NULL; - if ( !CBotVar::RestoreState( pf, pInstance ) ) return FALSE; + 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 ! @@ -1084,13 +1086,13 @@ BOOL CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) case CBotTypArrayPointer: { CBotTypResult r; - if (!ReadType(pf, r)) return FALSE; + 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; + if ( !CBotVar::RestoreState( pf, pInstance ) ) return false; ((CBotVarPointer*)pNew)->SetPointer( pInstance ); // et pointe dessus } break; @@ -1106,7 +1108,7 @@ BOOL CBotVar::RestoreState(FILE* pf, CBotVar* &pVar) pNew->SetPrivate(prv-100); pPrev = pNew; } - return TRUE; + return true; } @@ -1133,12 +1135,12 @@ CBotCStack::CBotCStack(CBotCStack* ppapa) m_error = 0; m_start = 0; m_end = 0; - m_bBlock = TRUE; + m_bBlock = true; } else { m_start = ppapa->m_start; - m_bBlock = FALSE; + m_bBlock = false; } m_listVar = NULL; @@ -1156,7 +1158,7 @@ CBotCStack::~CBotCStack() } // 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 @@ -1291,7 +1293,7 @@ CBotVar* CBotCStack::CopyVar(CBotToken& Token) return pCopy; } -BOOL CBotCStack::IsOk() +bool CBotCStack::IsOk() { return (m_error == 0); } @@ -1325,15 +1327,15 @@ void CBotCStack::ResetError(int n, int start, int end) m_end = end; } -BOOL CBotCStack::NextToken(CBotToken* &p) +bool CBotCStack::NextToken(CBotToken* &p) { CBotToken* pp = p; p = p->GivNext(); - if (p!=NULL) return TRUE; + if (p!=NULL) return true; SetError(TX_ENDOF, pp->GivEnd()); - return FALSE; + return false; } void CBotCStack::SetBotCall(CBotProgram* p) @@ -1398,7 +1400,7 @@ void CBotCStack::AddVar(CBotVar* pVar) // 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(); @@ -1409,13 +1411,13 @@ BOOL CBotCStack::CheckVarLocal(CBotToken* &pToken) while ( pp != NULL) { if (name == pp->GivName()) - return TRUE; + return true; pp = pp->m_next; } - if ( p->m_bBlock ) return FALSE; + if ( p->m_bBlock ) return false; p = p->m_prev; } - return FALSE; + return false; } CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nIdent) @@ -1440,11 +1442,11 @@ CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nId // test si un nom de procédure est déjà défini quelque part -BOOL CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam) +bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam) { CBotString name = pToken->GivString(); - if ( CBotCall::CheckCall(name) ) return TRUE; + if ( CBotCall::CheckCall(name) ) return true; CBotFunction* pp = m_prog->GivFunctions(); while ( pp != NULL ) @@ -1453,7 +1455,7 @@ BOOL CBotCStack::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(); } @@ -1465,11 +1467,11 @@ BOOL CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam) { // les paramètres sont-ils exactement les mêmes ? if ( pp->CheckParam( pParam ) ) - return TRUE; + return true; } pp = pp->m_nextpublic; } - return FALSE; + return false; } diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index 53b0f27..5f35337 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -19,9 +19,11 @@ #include "CBot.h" -#include - -HINSTANCE CBotString::m_hInstance = (HINSTANCE)LoadLibrary("libCbot.dll"); // comment le récupérer autrement ?? +#include +#include +#include +/// TODO need to be implemented to be able to load library +// HINSTANCE CBotString::m_hInstance = (HINSTANCE)LoadLibrary("libCbot.dll"); // how to retrieve it otherwise ?? CBotString::CBotString() @@ -38,13 +40,13 @@ CBotString::~CBotString() 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); + strcpy(m_ptr, p); } } @@ -56,7 +58,7 @@ CBotString::CBotString(const CBotString& srcString) if (m_lg>0) { m_ptr = (char*)malloc(m_lg+1); - lstrcpy(m_ptr, srcString.m_ptr); + strcpy(m_ptr, srcString.m_ptr); } } @@ -66,7 +68,7 @@ CBotString::CBotString(const CBotString& srcString) int CBotString::GivLength() { if ( m_ptr == NULL ) return 0; - return lstrlen( m_ptr ); + return strlen( m_ptr ); } @@ -143,10 +145,10 @@ int CBotString::Find(const char c) 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++) { @@ -170,10 +172,10 @@ int CBotString::ReverseFind(const char c) return -1; } -int CBotString::ReverseFind(LPCTSTR lpsz) +int CBotString::ReverseFind(const char * lpsz) { int i, j; - int l = lstrlen(lpsz); + int l = strlen(lpsz); for (i = m_lg-l; i >= 0; i--) { @@ -195,7 +197,7 @@ CBotString CBotString::Mid(int start, int lg) if ( lg < 0 ) lg = m_lg - start; char* p = (char*)malloc(m_lg+1); - lstrcpy(p, m_ptr+start); + strcpy(p, m_ptr+start); p[lg] = 0; res = p; @@ -229,11 +231,11 @@ void CBotString::MakeLower() #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 ); + /// \TODO implement loading strings from resources. Figure out how to do it + // m_lg = ::LoadString( m_hInstance, id, buffer, MAXSTRING ); if (m_ptr != NULL) free(m_ptr); @@ -241,10 +243,10 @@ BOOL CBotString::LoadString(UINT id) if (m_lg > 0) { m_ptr = (char*)malloc(m_lg+1); - lstrcpy(m_ptr, buffer); - return TRUE; + strcpy(m_ptr, buffer); + return true; } - return FALSE; + return false; } @@ -258,13 +260,13 @@ const CBotString& CBotString::operator=(const CBotString& stringSrc) if (m_lg > 0) { m_ptr = (char*)malloc(m_lg+1); - lstrcpy(m_ptr, stringSrc.m_ptr); + strcpy(m_ptr, stringSrc.m_ptr); } return *this; } -CBotString operator+(const CBotString& string, LPCTSTR lpsz) +CBotString operator+(const CBotString& string, const char * lpsz) { CBotString s ( string ); s += lpsz; @@ -275,9 +277,9 @@ const CBotString& CBotString::operator+(const CBotString& stringSrc) { char* p = (char*)malloc(m_lg+stringSrc.m_lg+1); - lstrcpy(p, m_ptr); + strcpy(p, m_ptr); char* pp = p + m_lg; - lstrcpy(pp, stringSrc.m_ptr); + strcpy(pp, stringSrc.m_ptr); if (m_ptr != NULL) free(m_ptr); m_ptr = p; @@ -306,12 +308,12 @@ const CBotString& CBotString::operator=(const char* pString) if ( pString != NULL ) { - m_lg = lstrlen(pString); + m_lg = strlen(pString); if (m_lg != 0) { m_ptr = (char*)malloc(m_lg+1); - lstrcpy(m_ptr, pString); + strcpy(m_ptr, pString); } } @@ -323,7 +325,7 @@ const CBotString& CBotString::operator+=(const char ch) { char* p = (char*)malloc(m_lg+2); - if (m_ptr!=NULL) lstrcpy(p, m_ptr); + if (m_ptr!=NULL) strcpy(p, m_ptr); p[m_lg++] = ch; p[m_lg] = 0; @@ -338,9 +340,9 @@ const CBotString& CBotString::operator+=(const CBotString& str) { char* p = (char*)malloc(m_lg+str.m_lg+1); - lstrcpy(p, m_ptr); + strcpy(p, m_ptr); char* pp = p + m_lg; - lstrcpy(pp, str.m_ptr); + strcpy(pp, str.m_ptr); m_lg = m_lg + str.m_lg; @@ -351,67 +353,67 @@ const CBotString& CBotString::operator+=(const CBotString& str) return *this; } -BOOL CBotString::operator==(const CBotString& str) +bool CBotString::operator==(const CBotString& str) { return Compare(str) == 0; } -BOOL CBotString::operator==(const char* p) +bool CBotString::operator==(const char* p) { return Compare(p) == 0; } -BOOL CBotString::operator!=(const CBotString& str) +bool CBotString::operator!=(const CBotString& str) { return Compare(str) != 0; } -BOOL CBotString::operator!=(const char* p) +bool CBotString::operator!=(const char* p) { return Compare(p) != 0; } -BOOL CBotString::operator>(const CBotString& str) +bool CBotString::operator>(const CBotString& str) { return Compare(str) > 0; } -BOOL CBotString::operator>(const char* p) +bool CBotString::operator>(const char* p) { return Compare(p) > 0; } -BOOL CBotString::operator>=(const CBotString& str) +bool CBotString::operator>=(const CBotString& str) { return Compare(str) >= 0; } -BOOL CBotString::operator>=(const char* p) +bool CBotString::operator>=(const char* p) { return Compare(p) >= 0; } -BOOL CBotString::operator<(const CBotString& str) +bool CBotString::operator<(const CBotString& str) { return Compare(str) < 0; } -BOOL CBotString::operator<(const char* p) +bool CBotString::operator<(const char* p) { return Compare(p) < 0; } -BOOL CBotString::operator<=(const CBotString& str) +bool CBotString::operator<=(const CBotString& str) { return Compare(str) <= 0; } -BOOL CBotString::operator<=(const char* p) +bool CBotString::operator<=(const char* p) { return Compare(p) <= 0; } -BOOL CBotString::IsEmpty() const +bool CBotString::IsEmpty() const { return (m_lg == 0); } @@ -423,20 +425,20 @@ void CBotString::Empty() 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; + 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; + if (lpsz == NULL) lpsz = emptyString; + if (m_ptr == NULL) p = emptyString; return strcmp(p, lpsz); // wcscmp } @@ -527,14 +529,14 @@ void CBotStringArray::SetSize(int nNewSize) // shrink to nothing DestructElements(m_pData, m_nSize); - delete[] (BYTE*)m_pData; + 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 BYTE[nNewSize * sizeof(CBotString)]; + m_pData = (CBotString*) new unsigned char[nNewSize * sizeof(CBotString)]; ConstructElements(m_pData, nNewSize); @@ -563,7 +565,7 @@ void CBotStringArray::SetSize(int nNewSize) { // heuristically determine growth when nGrowBy == 0 // (this avoids heap fragmentation in many situations) - nGrowBy = min(1024, max(4, m_nSize / 8)); + nGrowBy = std::min(1024, std::max(4, m_nSize / 8)); } int nNewMax; if (nNewSize < m_nMaxSize + nGrowBy) @@ -571,7 +573,7 @@ void CBotStringArray::SetSize(int nNewSize) else nNewMax = nNewSize; // no slush - CBotString* pNewData = (CBotString*) new BYTE[nNewMax * sizeof(CBotString)]; + CBotString* pNewData = (CBotString*) new unsigned char[nNewMax * sizeof(CBotString)]; // copy new data from old memcpy(pNewData, m_pData, m_nSize * sizeof(CBotString)); @@ -581,7 +583,7 @@ void CBotStringArray::SetSize(int nNewSize) // Ret rid of old stuff (note: no destructors called) - delete[] (BYTE*)m_pData; + delete[] (unsigned char *)m_pData; m_pData = pNewData; m_nSize = nNewSize; m_nMaxSize = nNewMax; diff --git a/src/CBot/CBotToken.cpp b/src/CBot/CBotToken.cpp index fbf6726..1b6392c 100644 --- a/src/CBot/CBotToken.cpp +++ b/src/CBot/CBotToken.cpp @@ -22,6 +22,7 @@ #include "CBot.h" +#include 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 // 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,11 +455,11 @@ 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 @@ -498,36 +499,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 +537,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..79ba021 100644 --- a/src/CBot/CBotVar.cpp +++ b/src/CBot/CBotVar.cpp @@ -33,9 +33,9 @@ CBotVar::CBotVar( ) m_InitExpr = NULL; m_LimExpr = NULL; m_type = -1; - m_binit = FALSE; + m_binit = false; m_ident = 0; - m_bStatic = FALSE; + m_bStatic = false; m_mPrivate = 0; } @@ -48,8 +48,8 @@ CBotVarInt::CBotVarInt( const CBotToken* name ) m_InitExpr = NULL; m_LimExpr = NULL; m_type = CBotTypInt; - m_binit = FALSE; - m_bStatic = FALSE; + m_binit = false; + m_bStatic = false; m_mPrivate = 0; m_val = 0; @@ -64,8 +64,8 @@ CBotVarFloat::CBotVarFloat( const CBotToken* name ) m_InitExpr = NULL; m_LimExpr = NULL; m_type = CBotTypFloat; - m_binit = FALSE; - m_bStatic = FALSE; + m_binit = false; + m_bStatic = false; m_mPrivate = 0; m_val = 0; @@ -80,8 +80,8 @@ CBotVarString::CBotVarString( const CBotToken* name ) m_InitExpr = NULL; m_LimExpr = NULL; m_type = CBotTypString; - m_binit = FALSE; - m_bStatic = FALSE; + m_binit = false; + m_bStatic = false; m_mPrivate = 0; m_val.Empty(); @@ -96,8 +96,8 @@ CBotVarBoolean::CBotVarBoolean( const CBotToken* name ) m_InitExpr = NULL; m_LimExpr = NULL; m_type = CBotTypBoolean; - m_binit = FALSE; - m_bStatic = FALSE; + m_binit = false; + m_bStatic = false; m_mPrivate = 0; m_val = 0; @@ -139,10 +139,10 @@ void CBotVarClass::InitCBotVarClass( const CBotToken* name, CBotTypResult& type m_pClass = NULL; m_pParent = NULL; - m_binit = FALSE; - m_bStatic = FALSE; + m_binit = false; + m_bStatic = false; m_mPrivate = 0; - m_bConstructor = FALSE; + m_bConstructor = false; m_CptUse = 0; m_ItemIdent = type.Eq(CBotTypIntrinsic) ? 0 : CBotVar::NextUniqNum(); @@ -189,7 +189,7 @@ CBotVarClass::~CBotVarClass( ) void CBotVarClass::ConstructorSet() { - m_bConstructor = TRUE; + m_bConstructor = true; } @@ -201,9 +201,9 @@ CBotVar::~CBotVar( ) 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) ) { @@ -260,19 +260,19 @@ void* CBotVar::GivUserPtr() 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; + 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);*/ + m_pMyThis->Maj(pUser, true);*/ } @@ -326,7 +326,7 @@ CBotVar* CBotVar::Create(const CBotToken* name, CBotTypResult type) while (type.Eq(CBotTypArrayBody)) { type = type.GivTypElem(); - pv = ((CBotVarArray*)pv)->GivItem(0, TRUE); // crée au moins l'élément [0] + pv = ((CBotVarArray*)pv)->GivItem(0, true); // crée au moins l'élément [0] } return array; @@ -397,7 +397,7 @@ CBotVar* CBotVar::Create( const char* n, CBotTypResult type) while (type.Eq(CBotTypArrayBody)) { type = type.GivTypElem(); - pv = ((CBotVarArray*)pv)->GivItem(0, TRUE); // crée au moins l'élément [0] + pv = ((CBotVarArray*)pv)->GivItem(0, true); // crée au moins l'élément [0] } return array; @@ -471,7 +471,7 @@ int CBotVar::GivInit() 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 @@ -533,14 +533,14 @@ CBotVar* CBotVar::GivItemList() return NULL; } -CBotVar* CBotVar::GivItem(int row, BOOL bGrow) +CBotVar* CBotVar::GivItem(int row, bool bGrow) { 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; @@ -555,11 +555,11 @@ BOOL CBotVar::IsElemOfClass(const char* name) while ( pc != NULL ) { - if ( pc->GivName() == name ) return TRUE; + if ( pc->GivName() == name ) return true; pc = pc->GivParent(); } - return FALSE; + return false; } @@ -611,7 +611,7 @@ void CBotVar::SetVal(CBotVar* var) { delete ((CBotVarClass*)this)->m_pVar; ((CBotVarClass*)this)->m_pVar = NULL; - Copy(var, FALSE); + Copy(var, false); } break; default: @@ -621,7 +621,7 @@ void CBotVar::SetVal(CBotVar* var) m_binit = var->m_binit; // copie l'état nan s'il y a } -void CBotVar::SetStatic(BOOL bStatic) +void CBotVar::SetStatic(bool bStatic) { m_bStatic = bStatic; } @@ -631,12 +631,12 @@ void CBotVar::SetPrivate(int mPrivate) m_mPrivate = mPrivate; } -BOOL CBotVar::IsStatic() +bool CBotVar::IsStatic() { return m_bStatic; } -BOOL CBotVar::IsPrivate(int mode) +bool CBotVar::IsPrivate(int mode) { return m_mPrivate >= mode; } @@ -715,40 +715,40 @@ void CBotVar::Sub(CBotVar* left, CBotVar* right) ASM_TRAP(); } -BOOL CBotVar::Lo(CBotVar* left, CBotVar* right) +bool CBotVar::Lo(CBotVar* left, CBotVar* right) { ASM_TRAP(); - return FALSE; + return false; } -BOOL CBotVar::Hi(CBotVar* left, CBotVar* right) +bool CBotVar::Hi(CBotVar* left, CBotVar* right) { ASM_TRAP(); - return FALSE; + return false; } -BOOL CBotVar::Ls(CBotVar* left, CBotVar* right) +bool CBotVar::Ls(CBotVar* left, CBotVar* right) { ASM_TRAP(); - return FALSE; + return false; } -BOOL CBotVar::Hs(CBotVar* left, CBotVar* right) +bool CBotVar::Hs(CBotVar* left, CBotVar* right) { ASM_TRAP(); - return FALSE; + return false; } -BOOL CBotVar::Eq(CBotVar* left, CBotVar* right) +bool CBotVar::Eq(CBotVar* left, CBotVar* right) { ASM_TRAP(); - return FALSE; + return false; } -BOOL CBotVar::Ne(CBotVar* left, CBotVar* right) +bool CBotVar::Ne(CBotVar* left, CBotVar* right) { ASM_TRAP(); - return FALSE; + return false; } void CBotVar::And(CBotVar* left, CBotVar* right) @@ -800,7 +800,7 @@ void CBotVar::Dec() ASM_TRAP(); } -void CBotVar::Copy(CBotVar* pSrc, BOOL bName) +void CBotVar::Copy(CBotVar* pSrc, bool bName) { ASM_TRAP(); } @@ -837,7 +837,7 @@ void CBotVar::SetIndirection(CBotVar* pVar) ////////////////////////////////////////////////////////////////////////////////////// // copie une variable dans une autre -void CBotVarInt::Copy(CBotVar* pSrc, BOOL bName) +void CBotVarInt::Copy(CBotVar* pSrc, bool bName) { CBotVarInt* p = (CBotVarInt*)pSrc; @@ -860,7 +860,7 @@ void CBotVarInt::Copy(CBotVar* pSrc, BOOL bName) void CBotVarInt::SetValInt(int val, const char* defnum) { m_val = val; - m_binit = TRUE; + m_binit = true; m_defnum = defnum; } @@ -869,7 +869,7 @@ void CBotVarInt::SetValInt(int val, const char* defnum) void CBotVarInt::SetValFloat(float val) { m_val = (int)val; - m_binit = TRUE; + m_binit = true; } int CBotVarInt::GivValInt() @@ -910,13 +910,13 @@ CBotString CBotVarInt::GivValString() void CBotVarInt::Mul(CBotVar* left, CBotVar* right) { m_val = left->GivValInt() * right->GivValInt(); - m_binit = TRUE; + m_binit = true; } void CBotVarInt::Power(CBotVar* left, CBotVar* right) { m_val = (int) pow( (double) left->GivValInt() , (double) right->GivValInt() ); - m_binit = TRUE; + m_binit = true; } int CBotVarInt::Div(CBotVar* left, CBotVar* right) @@ -925,7 +925,7 @@ int CBotVarInt::Div(CBotVar* left, CBotVar* right) if ( r != 0 ) { m_val = left->GivValInt() / r; - m_binit = TRUE; + m_binit = true; } return ( r == 0 ? TX_DIVZERO : 0 ); } @@ -936,7 +936,7 @@ int CBotVarInt::Modulo(CBotVar* left, CBotVar* right) if ( r != 0 ) { m_val = left->GivValInt() % r; - m_binit = TRUE; + m_binit = true; } return ( r == 0 ? TX_DIVZERO : 0 ); } @@ -944,43 +944,43 @@ int CBotVarInt::Modulo(CBotVar* left, CBotVar* right) void CBotVarInt::Add(CBotVar* left, CBotVar* right) { m_val = left->GivValInt() + right->GivValInt(); - m_binit = TRUE; + m_binit = true; } void CBotVarInt::Sub(CBotVar* left, CBotVar* right) { m_val = left->GivValInt() - right->GivValInt(); - m_binit = TRUE; + m_binit = true; } void CBotVarInt::XOr(CBotVar* left, CBotVar* right) { m_val = left->GivValInt() ^ right->GivValInt(); - m_binit = TRUE; + m_binit = true; } void CBotVarInt::And(CBotVar* left, CBotVar* right) { m_val = left->GivValInt() & right->GivValInt(); - m_binit = TRUE; + m_binit = true; } void CBotVarInt::Or(CBotVar* left, CBotVar* right) { m_val = left->GivValInt() | right->GivValInt(); - m_binit = TRUE; + m_binit = true; } void CBotVarInt::SL(CBotVar* left, CBotVar* right) { m_val = left->GivValInt() << right->GivValInt(); - m_binit = TRUE; + m_binit = true; } void CBotVarInt::ASR(CBotVar* left, CBotVar* right) { m_val = left->GivValInt() >> right->GivValInt(); - m_binit = TRUE; + m_binit = true; } void CBotVarInt::SR(CBotVar* left, CBotVar* right) @@ -989,7 +989,7 @@ void CBotVarInt::SR(CBotVar* left, CBotVar* right) int shift = right->GivValInt(); if (shift>=1) source &= 0x7fffffff; m_val = source >> shift; - m_binit = TRUE; + m_binit = true; } void CBotVarInt::Neg() @@ -1014,32 +1014,32 @@ void CBotVarInt::Dec() m_defnum.Empty(); } -BOOL CBotVarInt::Lo(CBotVar* left, CBotVar* right) +bool CBotVarInt::Lo(CBotVar* left, CBotVar* right) { return left->GivValInt() < right->GivValInt(); } -BOOL CBotVarInt::Hi(CBotVar* left, CBotVar* right) +bool CBotVarInt::Hi(CBotVar* left, CBotVar* right) { return left->GivValInt() > right->GivValInt(); } -BOOL CBotVarInt::Ls(CBotVar* left, CBotVar* right) +bool CBotVarInt::Ls(CBotVar* left, CBotVar* right) { return left->GivValInt() <= right->GivValInt(); } -BOOL CBotVarInt::Hs(CBotVar* left, CBotVar* right) +bool CBotVarInt::Hs(CBotVar* left, CBotVar* right) { return left->GivValInt() >= right->GivValInt(); } -BOOL CBotVarInt::Eq(CBotVar* left, CBotVar* right) +bool CBotVarInt::Eq(CBotVar* left, CBotVar* right) { return left->GivValInt() == right->GivValInt(); } -BOOL CBotVarInt::Ne(CBotVar* left, CBotVar* right) +bool CBotVarInt::Ne(CBotVar* left, CBotVar* right) { return left->GivValInt() != right->GivValInt(); } @@ -1048,7 +1048,7 @@ BOOL CBotVarInt::Ne(CBotVar* left, CBotVar* right) ////////////////////////////////////////////////////////////////////////////////////// // copie une variable dans une autre -void CBotVarFloat::Copy(CBotVar* pSrc, BOOL bName) +void CBotVarFloat::Copy(CBotVar* pSrc, bool bName) { CBotVarFloat* p = (CBotVarFloat*)pSrc; @@ -1071,13 +1071,13 @@ void CBotVarFloat::Copy(CBotVar* pSrc, BOOL bName) void CBotVarFloat::SetValInt(int val, const char* s) { m_val = (float)val; - m_binit = TRUE; + m_binit = true; } void CBotVarFloat::SetValFloat(float val) { m_val = val; - m_binit = TRUE; + m_binit = true; } int CBotVarFloat::GivValInt() @@ -1116,13 +1116,13 @@ CBotString CBotVarFloat::GivValString() void CBotVarFloat::Mul(CBotVar* left, CBotVar* right) { m_val = left->GivValFloat() * right->GivValFloat(); - m_binit = TRUE; + m_binit = true; } void CBotVarFloat::Power(CBotVar* left, CBotVar* right) { m_val = (float)pow( left->GivValFloat() , right->GivValFloat() ); - m_binit = TRUE; + m_binit = true; } int CBotVarFloat::Div(CBotVar* left, CBotVar* right) @@ -1131,7 +1131,7 @@ int CBotVarFloat::Div(CBotVar* left, CBotVar* right) if ( r != 0 ) { m_val = left->GivValFloat() / r; - m_binit = TRUE; + m_binit = true; } return ( r == 0 ? TX_DIVZERO : 0 ); } @@ -1142,7 +1142,7 @@ int CBotVarFloat::Modulo(CBotVar* left, CBotVar* right) if ( r != 0 ) { m_val = (float)fmod( left->GivValFloat() , r ); - m_binit = TRUE; + m_binit = true; } return ( r == 0 ? TX_DIVZERO : 0 ); } @@ -1150,13 +1150,13 @@ int CBotVarFloat::Modulo(CBotVar* left, CBotVar* right) void CBotVarFloat::Add(CBotVar* left, CBotVar* right) { m_val = left->GivValFloat() + right->GivValFloat(); - m_binit = TRUE; + m_binit = true; } void CBotVarFloat::Sub(CBotVar* left, CBotVar* right) { m_val = left->GivValFloat() - right->GivValFloat(); - m_binit = TRUE; + m_binit = true; } void CBotVarFloat::Neg() @@ -1175,32 +1175,32 @@ void CBotVarFloat::Dec() } -BOOL CBotVarFloat::Lo(CBotVar* left, CBotVar* right) +bool CBotVarFloat::Lo(CBotVar* left, CBotVar* right) { return left->GivValFloat() < right->GivValFloat(); } -BOOL CBotVarFloat::Hi(CBotVar* left, CBotVar* right) +bool CBotVarFloat::Hi(CBotVar* left, CBotVar* right) { return left->GivValFloat() > right->GivValFloat(); } -BOOL CBotVarFloat::Ls(CBotVar* left, CBotVar* right) +bool CBotVarFloat::Ls(CBotVar* left, CBotVar* right) { return left->GivValFloat() <= right->GivValFloat(); } -BOOL CBotVarFloat::Hs(CBotVar* left, CBotVar* right) +bool CBotVarFloat::Hs(CBotVar* left, CBotVar* right) { return left->GivValFloat() >= right->GivValFloat(); } -BOOL CBotVarFloat::Eq(CBotVar* left, CBotVar* right) +bool CBotVarFloat::Eq(CBotVar* left, CBotVar* right) { return left->GivValFloat() == right->GivValFloat(); } -BOOL CBotVarFloat::Ne(CBotVar* left, CBotVar* right) +bool CBotVarFloat::Ne(CBotVar* left, CBotVar* right) { return left->GivValFloat() != right->GivValFloat(); } @@ -1209,7 +1209,7 @@ BOOL CBotVarFloat::Ne(CBotVar* left, CBotVar* right) ////////////////////////////////////////////////////////////////////////////////////// // copie une variable dans une autre -void CBotVarBoolean::Copy(CBotVar* pSrc, BOOL bName) +void CBotVarBoolean::Copy(CBotVar* pSrc, bool bName) { CBotVarBoolean* p = (CBotVarBoolean*)pSrc; @@ -1231,14 +1231,14 @@ 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() @@ -1275,31 +1275,31 @@ CBotString CBotVarBoolean::GivValString() void CBotVarBoolean::And(CBotVar* left, CBotVar* right) { m_val = left->GivValInt() && right->GivValInt(); - m_binit = TRUE; + m_binit = true; } void CBotVarBoolean::Or(CBotVar* left, CBotVar* right) { m_val = left->GivValInt() || right->GivValInt(); - m_binit = TRUE; + m_binit = true; } void CBotVarBoolean::XOr(CBotVar* left, CBotVar* right) { m_val = left->GivValInt() ^ right->GivValInt(); - m_binit = TRUE; + 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(); } -BOOL CBotVarBoolean::Ne(CBotVar* left, CBotVar* right) +bool CBotVarBoolean::Ne(CBotVar* left, CBotVar* right) { return left->GivValInt() != right->GivValInt(); } @@ -1307,7 +1307,7 @@ BOOL CBotVarBoolean::Ne(CBotVar* left, CBotVar* right) ////////////////////////////////////////////////////////////////////////////////////// // copie une variable dans une autre -void CBotVarString::Copy(CBotVar* pSrc, BOOL bName) +void CBotVarString::Copy(CBotVar* pSrc, bool bName) { CBotVarString* p = (CBotVarString*)pSrc; @@ -1328,7 +1328,7 @@ void CBotVarString::Copy(CBotVar* pSrc, BOOL bName) void CBotVarString::SetValString(const char* p) { m_val = p; - m_binit = TRUE; + m_binit = true; } CBotString CBotVarString::GivValString() @@ -1353,36 +1353,36 @@ CBotString CBotVarString::GivValString() void CBotVarString::Add(CBotVar* left, CBotVar* right) { m_val = left->GivValString() + right->GivValString(); - m_binit = TRUE; + m_binit = true; } -BOOL CBotVarString::Eq(CBotVar* left, CBotVar* right) +bool CBotVarString::Eq(CBotVar* left, CBotVar* right) { return (left->GivValString() == right->GivValString()); } -BOOL CBotVarString::Ne(CBotVar* left, CBotVar* right) +bool CBotVarString::Ne(CBotVar* left, CBotVar* right) { return (left->GivValString() != right->GivValString()); } -BOOL CBotVarString::Lo(CBotVar* left, CBotVar* right) +bool CBotVarString::Lo(CBotVar* left, CBotVar* right) { return (left->GivValString() == right->GivValString()); } -BOOL CBotVarString::Hi(CBotVar* left, CBotVar* right) +bool CBotVarString::Hi(CBotVar* left, CBotVar* right) { return (left->GivValString() == right->GivValString()); } -BOOL CBotVarString::Ls(CBotVar* left, CBotVar* right) +bool CBotVarString::Ls(CBotVar* left, CBotVar* right) { return (left->GivValString() == right->GivValString()); } -BOOL CBotVarString::Hs(CBotVar* left, CBotVar* right) +bool CBotVarString::Hs(CBotVar* left, CBotVar* right) { return (left->GivValString() == right->GivValString()); } @@ -1391,7 +1391,7 @@ BOOL CBotVarString::Hs(CBotVar* left, CBotVar* right) //////////////////////////////////////////////////////////////// // 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 @@ -1520,10 +1520,10 @@ CBotClass* CBotVarClass::GivClass() } -void CBotVarClass::Maj(void* pUser, BOOL bContinu) +void CBotVarClass::Maj(void* pUser, bool bContinu) { /* if (!bContinu && m_pMyThis != NULL) - m_pMyThis->Maj(pUser, TRUE);*/ + m_pMyThis->Maj(pUser, true);*/ // une routine de mise à jour existe-elle ? @@ -1569,7 +1569,7 @@ CBotVar* CBotVarClass::GivItemRef(int nIdent) // 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; @@ -1728,14 +1728,14 @@ CBotVarClass* CBotVarClass::Find(long id) return NULL; } -BOOL CBotVarClass::Eq(CBotVar* left, CBotVar* right) +bool CBotVarClass::Eq(CBotVar* left, CBotVar* right) { CBotVar* l = left->GivItemList(); CBotVar* r = right->GivItemList(); while ( l != NULL && r != NULL ) { - if ( l->Ne(l, r) ) return FALSE; + if ( l->Ne(l, r) ) return false; l = l->GivNext(); r = r->GivNext(); } @@ -1744,14 +1744,14 @@ BOOL CBotVarClass::Eq(CBotVar* left, CBotVar* right) 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(); while ( l != NULL && r != NULL ) { - if ( l->Ne(l, r) ) return TRUE; + if ( l->Ne(l, r) ) return true; l = l->GivNext(); r = r->GivNext(); } @@ -1775,7 +1775,7 @@ CBotVarArray::CBotVarArray(const CBotToken* name, CBotTypResult& type ) m_type = type; m_type.SetType(CBotTypArrayPointer); - m_binit = FALSE; + m_binit = false; m_pInstance = NULL; // la liste des éléments du tableau } @@ -1786,7 +1786,7 @@ CBotVarArray::~CBotVarArray() } // 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(); @@ -1811,7 +1811,7 @@ void CBotVarArray::Copy(CBotVar* pSrc, BOOL bName) 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 @@ -1839,7 +1839,7 @@ CBotVarClass* CBotVarArray::GivPointer() return m_pInstance->GivPointer(); } -CBotVar* CBotVarArray::GivItem(int n, BOOL bExtend) +CBotVar* CBotVarArray::GivItem(int n, bool bExtend) { if ( m_pInstance == NULL ) { @@ -1864,9 +1864,9 @@ CBotString CBotVarArray::GivValString() return m_pInstance->GivValString(); } -BOOL CBotVarArray::Save1State(FILE* pf) +bool CBotVarArray::Save1State(FILE* pf) { - if ( !WriteType(pf, m_type) ) return FALSE; + if ( !WriteType(pf, m_type) ) return false; return SaveVar(pf, m_pInstance); // sauve l'instance qui gère le tableau } @@ -1889,7 +1889,7 @@ CBotVarPointer::CBotVarPointer(const CBotToken* name, CBotTypResult& type ) m_type = type; if ( !type.Eq(CBotTypNullPointer) ) m_type.SetType(CBotTypPointer); // quoi qu'il en soit, c'est un pointeur - m_binit = FALSE; + m_binit = false; m_pClass = NULL; m_pVarClass = NULL; // sera défini par un SetPointer() @@ -1902,12 +1902,12 @@ CBotVarPointer::~CBotVarPointer() } -void CBotVarPointer::Maj(void* pUser, BOOL bContinu) +void CBotVarPointer::Maj(void* pUser, bool bContinu) { /* if ( !bContinu && m_pMyThis != NULL ) - m_pMyThis->Maj(pUser, FALSE);*/ + 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) @@ -1950,7 +1950,7 @@ void CBotVarPointer::ConstructorSet() 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 @@ -2009,25 +2009,25 @@ CBotClass* CBotVarPointer::GivClass() } -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 + if (!WriteString(pf, m_pClass->GivName())) return false; // nom de la classe } else { - if (!WriteString(pf, "")) return FALSE; + 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()); } // 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) @@ -2054,26 +2054,26 @@ void CBotVarPointer::Copy(CBotVar* pSrc, BOOL bName) 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(); - 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(); - 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; } @@ -2207,9 +2207,9 @@ void CBotTypResult::SetArray( int* max ) -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); @@ -2220,10 +2220,10 @@ BOOL CBotTypResult::Compare(const CBotTypResult& typ) const 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; } 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/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/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/CMakeLists.txt b/src/CMakeLists.txt index 1be7a59..250120c 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 @@ -25,6 +25,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 @@ -150,7 +151,7 @@ set(LIBS ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${OPENGL_LIBRARY} -#CBot -- not yet WinAPI-independent +CBot ) include_directories(. ${CMAKE_CURRENT_BINARY_DIR}) -- cgit v1.2.3-1-g7c22 From 1910219518afb26edf7329e0945b9ddba8061a08 Mon Sep 17 00:00:00 2001 From: Zaba999 Date: Tue, 10 Jul 2012 22:58:52 +0200 Subject: Dependency on WINAPI completely removed. --- src/CBot/CBot.cpp | 5201 +++++++++++++++++++++++------------------------ src/CBot/CBot.rc | 279 --- src/CBot/CBotDll.h | 1677 +++++++-------- src/CBot/CBotStack.cpp | 7 +- src/CBot/CBotString.cpp | 710 ++++--- src/CBot/CBotToken.cpp | 1 + src/CBot/CMakeLists.txt | 1 - src/CBot/resource.h | 204 +- 8 files changed, 3876 insertions(+), 4204 deletions(-) delete mode 100644 src/CBot/CBot.rc (limited to 'src') diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 6cb2e5d..e73eea0 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -13,318 +13,315 @@ // * // * 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 of various instructions -// Compile all routines are static -// And return an object according to what was found as instruction -// Compiler principle: +// compilation of various instructions +// compile all routines are static +// and return an object according to what was found as instruction + +// compiler principle: // compile the routines return an object of the class corresponding to the operation found -// This is always a subclass of CBotInstr. +// this is always a subclass of CBotInstr. // (CBotInstr objects are never used directly) -// 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 +// 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(); -// ajoute un niveau avec un label +int CBotInstr::m_LoopLvl = 0; +CBotStringArray CBotInstr::m_labelLvl = CBotStringArray(); + +// 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 +// 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) { - 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; + 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(); // 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; + } + } + + // 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_DO: + return CBotDo::Compile(p, pStack); + + case ID_REPEAT: + return CBotRepeat::Compile(p, pStack); + + case ID_BREAK: + case ID_CONTINUE: + return CBotBreak::Compile(p, pStack); + + case ID_SWITCH: + return CBotSwitch::Compile(p, pStack); + + case ID_TRY: + return CBotTry::Compile(p, pStack); + + case ID_THROW: + return CBotThrow::Compile(p, pStack); + + case ID_DEBUGDD: + return CBotStartDebugDD::Compile(p, pStack); + + case ID_INT: + return CBotInt::Compile(p, pStack); + + case ID_FLOAT: + return CBotFloat::Compile(p, pStack); + + case ID_STRING: + return CBotIString::Compile(p, pStack); + + case ID_BOOLEAN: + case ID_BOOL: + return CBotBoolean::Compile(p, pStack); + + case ID_IF: + return CBotIf::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_CASE: + pStack->SetStartError(p->GivStart()); + pStack->SetError(TX_OUTCASE, p->GivEnd()); + return NULL; + } - 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; - } - } - - // appel la routine de compilation correspondant au token trouvé - switch (type) - { - case ID_WHILE: - return CBotWhile::Compile(p, pStack); - - case ID_FOR: - return CBotFor::Compile(p, pStack); - - case ID_DO: - return CBotDo::Compile(p, pStack); - - case ID_REPEAT: - return CBotRepeat::Compile(p, pStack); - - case ID_BREAK: - case ID_CONTINUE: - return CBotBreak::Compile(p, pStack); - - case ID_SWITCH: - return CBotSwitch::Compile(p, pStack); - - case ID_TRY: - return CBotTry::Compile(p, pStack); - - case ID_THROW: - return CBotThrow::Compile(p, pStack); - - case ID_DEBUGDD: - return CBotStartDebugDD::Compile(p, pStack); - - case ID_INT: - return CBotInt::Compile(p, pStack); - - case ID_FLOAT: - return CBotFloat::Compile(p, pStack); - - case ID_STRING: - return CBotIString::Compile(p, pStack); - - case ID_BOOLEAN: - case ID_BOOL: - return CBotBoolean::Compile(p, pStack); - - case ID_IF: - return CBotIf::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_CASE: - pStack->SetStartError(p->GivStart()); - pStack->SetError(TX_OUTCASE, p->GivEnd()); - return NULL; - } - - 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; - } - - // 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); - } - } - - // 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; + 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; + } + + // this might be an instance of class definnition + CBotToken* ppp = p; + if (IsOfType( ppp, TokenTypVar )) + { + if ( CBotClass::Find(p) != NULL ) + { + // oui, compile la déclaration de l'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; } 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(); // ne doit jamais passer par cette routine + // mais utiliser les routines des classes filles + return false; } 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) { - CBotString ClassManquante = name; - ASM_TRAP(); // ne doit jamais passer par cette routine - // mais utiliser les routines des classes filles + CBotString ClassManquante = name; + ASM_TRAP(); // ne doit jamais passer par cette routine + // mais utiliser les routines des classes filles } bool CBotInstr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) { - ASM_TRAP(); // papa sait pas faire, voir les filles - return false; + ASM_TRAP(); // papa sait pas faire, voir les filles + return false; } 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(); // papa sait pas faire, voir les filles + return false; } void CBotInstr::RestoreStateVar(CBotStack* &pile, bool bMain) { - ASM_TRAP(); // papa sait pas faire, voir les filles + ASM_TRAP(); // papa sait pas faire, voir les filles } // cette routine n'est définie que pour la classe fille CBotCase @@ -333,7 +330,7 @@ void CBotInstr::RestoreStateVar(CBotStack* &pile, bool bMain) bool CBotInstr::CompCase(CBotStack* &pj, int val) { - return false; + return false; } ////////////////////////////////////////////////////////////////////////////////////////// @@ -348,38 +345,38 @@ bool CBotInstr::CompCase(CBotStack* &pj, int val) 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()); // manque la parenthèse + 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) { - // est-ce un nouveau bloc ? - if ( p->GivType() == ID_OPBLK ) return CBotBlock::Compile(p, pStack); + // est-ce un nouveau bloc ? + if ( p->GivType() == ID_OPBLK ) return CBotBlock::Compile(p, pStack); - // sinon, cherche une instruction unique à la place + // sinon, cherche une instruction unique à la place - // pour gérer les cas avec définition local à l'instructin (*) - CBotCStack* pStk = pStack->TokenStack(p, bLocal); + // pour gérer les cas avec définition local à l'instructin (*) + CBotCStack* pStk = pStack->TokenStack(p, bLocal); - return pStack->Return( CBotInstr::Compile(p, pStk), // une instruction unique - pStk); + return pStack->Return( CBotInstr::Compile(p, pStk), // une instruction unique + pStk); } // (*) c'est le cas dans l'instruction suivante @@ -395,47 +392,47 @@ CBotInstr* CBotBlock::CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool b 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) { - CBotCStack* pStk = pStack->TokenStack(p, bLocal); // les variables sont locales + CBotCStack* pStk = pStack->TokenStack(p, bLocal); // les variables sont locales - 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; // instruction vide ignorée + if ( p->GivType() == ID_CLBLK ) break; // déja plus d'instruction - 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 ); // compile la suivante - 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); // ajoute à la suite + } + return pStack->Return(inst, pStk); } // exécute une liste d'instructions @@ -443,45 +440,45 @@ CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal 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);//indispensable pour SetState() + if ( pile->StackOver() ) return pj->Return( pile ); - CBotInstr* p = m_Instr; // la première expression + CBotInstr* p = m_Instr; // la première 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(); // revient sur l'opération interrompue - if ( p != NULL ) while (true) - { -// DEBUG( "CBotListInstr", pile->GivState(), pile ); + if ( p != NULL ) while (true) + { +// DEBUG( "CBotListInstr", pile->GivState(), pile ); - if ( !p->Execute(pile) ) return false; - p = p->GivNext(); - if ( p == NULL ) break; - if (!pile->IncState()) ;//return false; // prêt pour la suivante - } + 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 ); // transmet en dessous } 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; // la première 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(); // revient sur l'opération interrompue + } - if ( p != NULL ) p->RestoreState(pile, true); + if ( p != NULL ) p->RestoreState(pile, true); } ////////////////////////////////////////////////////////////////////////////////////// @@ -491,9 +488,9 @@ void CBotListInstr::RestoreState(CBotStack* &pj, bool bMain) CBotLeftExprVar::CBotLeftExprVar() { - name = "CBotLeftExprVar"; - m_typevar = -1; - m_nIdent = 0; + name = "CBotLeftExprVar"; + m_typevar = -1; + m_nIdent = 0; } CBotLeftExprVar::~CBotLeftExprVar() @@ -502,44 +499,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; - } + // vérifie que le token est un nom de variable + 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) { - CBotVar* var1; - CBotVar* var2; + CBotVar* var1; + CBotVar* var2; - 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 + 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 - return true; // opération faite + return true; // opération faite } 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); // avec cet identificateur unique } ////////////////////////////////////////////////////////////////////////////////////// @@ -553,73 +550,73 @@ void CBotLeftExprVar::RestoreState(CBotStack* &pj, bool bMain) 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(); // crée l'objet - 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; - } + // 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; + } - 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)) // 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 - inst->AddNext3b(i); // construit une liste - type = CBotTypResult(CBotTypArrayPointer, type); + inst->AddNext3b(i); // construit une liste + 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); // crée avec une 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()); + // lui attribut un numéro unique + pStack->AddVar(var); // la place sur la pile - if ( IsOfType(p, ID_ASS) ) // avec une assignation - { - inst->m_listass = CBotListArray::Compile( p, pStk, type.GivTypElem() ); - } + if ( IsOfType(p, ID_ASS) ) // avec une assignation + { + 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); + delete inst; + return pStack->Return(NULL, pStk); } @@ -627,132 +624,132 @@ error: 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(); + 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(); #else - delete pile1->AddStack(); // plus besoin des indices + delete pile1->AddStack(); // plus besoin des 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 ) // il y a des assignation pour ce tableau + { + 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; // montre ce pas ? - 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 ); // transmet en dessous } 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 ) + { + // cherche les dimensions max du tableau + CBotInstr* p = GivNext3b(); // les différentes formules - 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(); // 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); + } - } + } - 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) { - 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); // met la valeur -1 sur la pile + pj->SetVar(pVar); + return true; } void CBotEmpty :: RestoreState(CBotStack* &pj, bool bMain) @@ -766,107 +763,107 @@ void CBotEmpty :: RestoreState(CBotStack* &pj, bool bMain) 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 ); +// 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); + } error: - delete inst; - return pStack->Return(NULL, pStk); + delete inst; + return pStack->Return(NULL, pStk); } @@ -874,43 +871,43 @@ error: bool CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar) { - CBotStack* pile1 = pj->AddStack(); -// if ( pile1 == EOX ) return true; - CBotVar* pVar2; + CBotStack* pile1 = pj->AddStack(); +// if ( pile1 == EOX ) return true; + 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; // évalue l'expression - pile1->IncState(); - } + pile1->IncState(); + } - return pj->Return( pile1 ); // transmet en dessous + return pj->Return( pile1 ); // transmet en dessous } 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); // calcul de la taille // interrompu! + } } ////////////////////////////////////////////////////////////////////////////////////// @@ -921,197 +918,197 @@ void CBotListArray::RestoreState(CBotStack* &pj, bool bMain) CBotInt::CBotInt() { - m_next = NULL; // pour les définitions multiples - m_var = - m_expr = NULL; - name = "CBotInt"; + m_next = NULL; // pour les définitions multiples + 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; +// delete m_next; // fait par le destructeur de la classe de base ~CBotInstr() } 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; - } + 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; - } + 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 ; + // compile une déclaration de tableau + if (first) return NULL ; - CBotInstr* inst = CBotInstArray::Compile( p, pStack, type ); - if ( inst == NULL ) 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_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; - } + if (IsOfType(p, ID_SEP)) // instruction terminée + { + return inst; + } - delete inst; - pStack->SetError(TX_ENDOF, p->GivStart()); - return NULL; + 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); - } - } + 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); + } + } suite: - if (noskip || IsOfType(p, ID_SEP)) // instruction terminée - { - 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()); - } + 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 bool CBotInt::Execute(CBotStack* &pj) { - CBotStack* pile = pj->AddStack(this); //indispensable pour SetState() -// if ( pile == EOX ) return true; + CBotStack* pile = pj->AddStack(this); //indispensable pour SetState() +// if ( pile == EOX ) return true; - 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; // valeur initiale // interrompu? + m_var->Execute( pile ); // crée et fait l'assigation du résultat - 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; // autre(s) définition(s) - return pj->Return( pile ); // transmet en dessous + return pj->Return( pile ); // transmet en dessous } 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); // valeur initiale // interrompu! + 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); // autre(s) définition(s) } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1123,145 +1120,145 @@ void CBotInt::RestoreState(CBotStack* &pj, bool bMain) 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) { - CBotToken* pp = cont ? NULL : p; - - if (!cont && !IsOfType(p, ID_BOOLEAN, ID_BOOL)) return NULL; - - CBotBoolean* inst = (CBotBoolean*)CompileArray(p, pStack, CBotTypBoolean); - if ( inst != NULL || !pStack->IsOk() ) return inst; - - CBotCStack* pStk = pStack->TokenStack(pp); - - inst = new CBotBoolean(); - - inst->m_expr = 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 (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 = (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 (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; - } - } - - 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 + CBotToken* pp = cont ? NULL : p; + + if (!cont && !IsOfType(p, ID_BOOLEAN, ID_BOOL)) return NULL; + + CBotBoolean* inst = (CBotBoolean*)CompileArray(p, pStack, CBotTypBoolean); + if ( inst != NULL || !pStack->IsOk() ) return inst; + + CBotCStack* pStk = pStack->TokenStack(pp); + + inst = new CBotBoolean(); + + inst->m_expr = 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 (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 = (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 (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; + } + } + + 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 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)) // 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()); + } error: - delete inst; - return pStack->Return(NULL, pStk); + delete inst; + return pStack->Return(NULL, pStk); } // exécute une définition de variable booléenne bool CBotBoolean::Execute(CBotStack* &pj) { - CBotStack* pile = pj->AddStack(this);//indispensable pour SetState() -// if ( pile == EOX ) return true; + CBotStack* pile = pj->AddStack(this);//indispensable pour SetState() +// if ( pile == EOX ) return true; - 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; // valeur initiale // interrompu? + m_var->Execute( pile ); // crée et fait l'assigation du résultat - 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; // autre(s) définition(s) - return pj->Return( pile ); // transmet en dessous + return pj->Return( pile ); // transmet en dessous } 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); // valeur initiale interrompu? + 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); // autre(s) définition(s) } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1273,146 +1270,146 @@ void CBotBoolean::RestoreState(CBotStack* &pj, bool bMain) CBotFloat::CBotFloat() { - m_var = - m_expr = NULL; - name = "CBotFloat"; + m_var = + m_expr = NULL; + name = "CBotFloat"; } CBotFloat::~CBotFloat() { - delete m_var; - delete m_expr; + 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 + 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 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)) // 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()); + } 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 bool CBotFloat::Execute(CBotStack* &pj) { - CBotStack* pile = pj->AddStack(this);//indispensable pour SetState() -// if ( pile == EOX ) return true; + CBotStack* pile = pj->AddStack(this);//indispensable pour SetState() +// if ( pile == EOX ) return true; - 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; // valeur initiale // interrompu? + m_var->Execute( pile ); // crée et fait l'assigation du résultat - 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; // autre(s) définition(s) - return pj->Return( pile ); // transmet en dessous + return pj->Return( pile ); // transmet en dessous } 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); // valeur initiale interrompu? + 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); // autre(s) définition(s) } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1424,129 +1421,129 @@ void CBotFloat::RestoreState(CBotStack* &pj, bool bMain) CBotIString::CBotIString() { - m_var = - m_expr = NULL; - name = "CBotIString"; + m_var = + m_expr = NULL; + name = "CBotIString"; } CBotIString::~CBotIString() { - delete m_var; - delete m_expr; + 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()); - } + 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()); + } error: - delete inst; - return pStack->Return(NULL, pStk); + delete inst; + return pStack->Return(NULL, pStk); } // exécute la définition de la variable string bool CBotIString::Execute(CBotStack* &pj) { - CBotStack* pile = pj->AddStack(this);//indispensable pour SetState() -// if ( pile == EOX ) return true; + CBotStack* pile = pj->AddStack(this);//indispensable pour SetState() +// if ( pile == EOX ) return true; - 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; // valeur initiale // interrompu? + m_var->Execute( pile ); // crée et fait l'assigation du résultat - 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; // autre(s) définition(s) - return pj->Return( pile ); // transmet en dessous + return pj->Return( pile ); // transmet en dessous } 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); // valeur initiale interrompu? + 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); // autre(s) définition(s) } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1559,269 +1556,269 @@ void CBotIString::RestoreState(CBotStack* &pj, bool bMain) 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; + 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 + 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; + if ( bMain ) + { + CBotToken* pToken = m_leftop->GivToken(); + CBotVar* pVar = NULL; - 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) - { - m_leftop->RestoreStateVar(pile, true); // variable avant évaluation de la valeur droite - return; - } + 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 + 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; + 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; - } - } + if ( pile2->GivState()==0) + { + if (m_rightop) m_rightop->RestoreState(pile2, bMain); // valeur initiale // interrompu? + return; + } + } } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1836,24 +1833,24 @@ void CBotExpression::RestoreState(CBotStack* &pj, bool bMain) 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()); // manque la parenthèse + } + delete inst; + } - pStack->SetError(TX_OPENPAR, p->GivStart()); // manque la parenthèse + pStack->SetError(TX_OPENPAR, p->GivStart()); // manque la parenthèse - return NULL; + return NULL; } @@ -1866,21 +1863,21 @@ CBotInstr* CBotCondition::Compile(CBotToken* &p, CBotCStack* pStack) 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()); // n'est pas un booléan + } - delete inst; - return NULL; + delete inst; + return NULL; } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1888,166 +1885,166 @@ CBotInstr* CBotBoolExpr::Compile(CBotToken* &p, CBotCStack* pStack) ////////////////////////////////////////////////////////////////////////////////////// // 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 +// 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 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()); + + // 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); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -2060,218 +2057,218 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack) 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) { - 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 + if ( !((CBotExprVar*)m_Instr)->ExecuteVar(var1, pile2, NULL, true) ) return false; // récupère la variable selon champs et index - 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); // opération faite, résultat sur pile2 } 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) { - CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; + CBotStack* pile = pj->AddStack(this); +// if ( pile == EOX ) return true; - 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; + 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 ( 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); // opération faite + } - 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); // opération faite + } - 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); // opération faite } 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 -// ! -// ~ +// + +// - +// 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); - - pStk->SetError(TX_BADTYPE, &inst->m_token); - } - delete inst; - return pStack->Return(NULL, pStk); + 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); + + pStk->SetError(TX_BADTYPE, &inst->m_token); + } + delete inst; + return pStack->Return(NULL, pStk); } // exécute l'expresson unaire bool CBotExprUnaire::Execute(CBotStack* &pj) { - CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; + CBotStack* pile = pj->AddStack(this); +// if ( pile == EOX ) return true; - 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; // interrompu ? + 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(); // récupère le résultat sur la pile - 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; // 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 } 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 ); // interrompu ici ! + return; + } } ////////////////////////////////////////////////////////////////////////////////////////// @@ -2283,30 +2280,30 @@ void CBotExprUnaire::RestoreState(CBotStack* &pj, bool bMain) 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 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); // à 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; } // idem à l'exécution @@ -2315,66 +2312,66 @@ bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) { - CBotStack* pj = pile; -// DEBUG( "CBotIndexExpr::ExecuteVar", -1 , pj); + CBotStack* pj = pile; +// DEBUG( "CBotIndexExpr::ExecuteVar", -1 , pj); - 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 == EOX ) return true; - 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(); + } + // traite les tableaux - CBotVar* p = pile->GivVar(); // résultat sur la pile + CBotVar* p = pile->GivVar(); // résultat sur la pile - 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 dans le tableau +// DEBUG( "CBotIndexExpr::ExecuteVar", n , pj); - 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); +// DEBUG( "CBotIndexExpr::ExecuteVar", -2 , pj); + //if ( bUpdate ) + pVar->Maj(pile->GivPUser(), true); -// DEBUG( "CBotIndexExpr::ExecuteVar", -3 , pj); - if ( m_next3 != NULL && - !m_next3->ExecuteVar(pVar, pile, prevToken, bStep, bExtend) ) return false; +// DEBUG( "CBotIndexExpr::ExecuteVar", -3 , pj); + 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 +// 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 } 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); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -2386,8 +2383,8 @@ void CBotIndexExpr::RestoreStateVar(CBotStack* &pile, bool bMain) CBotFieldExpr::CBotFieldExpr() { - name = "CBotFieldExpr"; - m_nIdent = 0; + name = "CBotFieldExpr"; + m_nIdent = 0; } CBotFieldExpr::~CBotFieldExpr() @@ -2396,7 +2393,7 @@ CBotFieldExpr::~CBotFieldExpr() void CBotFieldExpr::SetUniqNum(int num) { - m_nIdent = num; + m_nIdent = num; } @@ -2404,84 +2401,84 @@ void CBotFieldExpr::SetUniqNum(int num) 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->GivItem(m_token.GivString()); + 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) { - CBotStack* pj = pile; - pile = pile->AddStack(this); // modifie pile en sortie - if ( pile == EOX ) return true; + CBotStack* pj = pile; + pile = pile->AddStack(this); // modifie pile en sortie + if ( pile == EOX ) return true; -// DEBUG( "CBotFieldExpre::ExecuteVar "+m_token.GivString(), 0, pj ); +// 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->GivItem(m_token.GivString()); + 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() ) + { +// 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) ; + } - // demande la mise à jour de l'élément, s'il y a lieu - pVar->Maj(pile->GivPUser(), true); + // demande la mise à jour de l'élément, s'il y a lieu + 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 + return true; // ne libère pas la pile + // pour conserver l'état SetState() correspondant à l'étape } void CBotFieldExpr::RestoreStateVar(CBotStack* &pj, bool bMain) { - pj = pj->RestoreStack(this); // modifie pj en sortie - if ( pj == NULL ) return; + pj = pj->RestoreStack(this); // modifie pj en sortie + if ( pj == NULL ) return; - if ( m_next3 != NULL ) - m_next3->RestoreStateVar(pj, bMain); + if ( m_next3 != NULL ) + m_next3->RestoreStateVar(pj, bMain); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -2491,8 +2488,8 @@ void CBotFieldExpr::RestoreStateVar(CBotStack* &pj, bool bMain) CBotLeftExpr::CBotLeftExpr() { - name = "CBotLeftExpr"; - m_nIdent = 0; + name = "CBotLeftExpr"; + m_nIdent = 0; } CBotLeftExpr::~CBotLeftExpr() @@ -2584,135 +2581,135 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack) { 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); + 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); 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) { - CBotStack* pile = pj->AddStack(); -// if ( pile == EOX ) return true; - -// if ( pile->IfStep() ) return false; - - CBotVar* var1 = NULL; - CBotVar* var2 = NULL; - -// 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 ( 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) - } - - return pj->Return(pile); // opération faite + CBotStack* pile = pj->AddStack(); +// if ( pile == EOX ) return true; + +// if ( pile->IfStep() ) return false; + + CBotVar* var1 = NULL; + CBotVar* var2 = NULL; + +// 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 ( 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) + } + + return pj->Return(pile); // opération faite } // retrouve une variable pendant la compilation 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 bool CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep) { - pile = pile->AddStack( this ); // déplace la pile + pile = pile->AddStack( this ); // déplace la pile - 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) { - pile = pile->RestoreStack( this ); // déplace la pile - if ( pile == NULL ) return; + pile = pile->RestoreStack( this ); // déplace la pile + if ( pile == NULL ) return; - if ( m_next3 != NULL ) - m_next3->RestoreStateVar(pile, bMain); + if ( m_next3 != NULL ) + m_next3->RestoreStateVar(pile, bMain); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -2722,96 +2719,96 @@ void CBotLeftExpr::RestoreStateVar(CBotStack* &pile, bool bMain) 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; + 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; + 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; } ////////////////////////////////////////////////////////////////////////////////////////// @@ -2822,7 +2819,7 @@ extern float GivNumFloat( const char* p ) CBotExprNum::CBotExprNum() { - name = "CBotExprNum"; + name = "CBotExprNum"; } CBotExprNum::~CBotExprNum() @@ -2831,77 +2828,77 @@ CBotExprNum::~CBotExprNum() CBotInstr* CBotExprNum::Compile(CBotToken* &p, CBotCStack* pStack) { - CBotCStack* pStk = pStack->TokenStack(); - - CBotExprNum* inst = new CBotExprNum(); - - 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); - } - } - - 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); + CBotCStack* pStk = pStack->TokenStack(); + + CBotExprNum* inst = new CBotExprNum(); + + 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); + } + } + + 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); } // exécute, retourne le nombre correspondant bool CBotExprNum::Execute(CBotStack* &pj) { - CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; + CBotStack* pile = pj->AddStack(this); +// if ( pile == EOX ) return true; - 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 ); // valeur du nombre + break; + case CBotTypFloat: + var->SetValFloat( m_valfloat ); // valeur du nombre + break; + } + pile->SetVar( var ); // mis sur la pile - return pj->Return(pile); // c'est ok + return pj->Return(pile); // c'est ok } void CBotExprNum::RestoreState(CBotStack* &pj, bool bMain) { - if ( bMain ) pj->RestoreStack(this); + if ( bMain ) pj->RestoreStack(this); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -2912,7 +2909,7 @@ void CBotExprNum::RestoreState(CBotStack* &pj, bool bMain) CBotExprAlpha::CBotExprAlpha() { - name = "CBotExprAlpha"; + name = "CBotExprAlpha"; } CBotExprAlpha::~CBotExprAlpha() @@ -2921,43 +2918,43 @@ 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 bool CBotExprAlpha::Execute(CBotStack* &pj) { - CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; + CBotStack* pile = pj->AddStack(this); +// if ( pile == EOX ) return true; - 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); // enlève les guillemets - var->SetValString( chaine ); // valeur du nombre + var->SetValString( chaine ); // valeur du nombre - pile->SetVar( var ); // mis sur la pile + pile->SetVar( var ); // mis sur la pile - return pj->Return(pile); + return pj->Return(pile); } void CBotExprAlpha::RestoreState(CBotStack* &pj, bool bMain) { - if ( bMain ) pj->RestoreStack(this); + if ( bMain ) pj->RestoreStack(this); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -2968,7 +2965,7 @@ void CBotExprAlpha::RestoreState(CBotStack* &pj, bool bMain) CBotExprBool::CBotExprBool() { - name = "CBotExprBool"; + name = "CBotExprBool"; } CBotExprBool::~CBotExprBool() @@ -2977,44 +2974,44 @@ 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); // mémorise l'opération false ou 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 bool CBotExprBool::Execute(CBotStack* &pj) { - CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; + CBotStack* pile = pj->AddStack(this); +// if ( pile == EOX ) return true; - 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 ); // mis sur la pile + return pj->Return(pile); // transmet en dessous } void CBotExprBool::RestoreState(CBotStack* &pj, bool bMain) { - if ( bMain ) pj->RestoreStack(this); + if ( bMain ) pj->RestoreStack(this); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -3023,7 +3020,7 @@ void CBotExprBool::RestoreState(CBotStack* &pj, bool bMain) CBotExprNull::CBotExprNull() { - name = "CBotExprNull"; + name = "CBotExprNull"; } CBotExprNull::~CBotExprNull() @@ -3034,20 +3031,20 @@ CBotExprNull::~CBotExprNull() bool CBotExprNull::Execute(CBotStack* &pj) { - CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; + CBotStack* pile = pj->AddStack(this); +// if ( pile == EOX ) return true; - 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); // pointeur null valide + pile->SetVar( var ); // mis sur la pile + return pj->Return(pile); // transmet en dessous } void CBotExprNull::RestoreState(CBotStack* &pj, bool bMain) { - if ( bMain ) pj->RestoreStack(this); + if ( bMain ) pj->RestoreStack(this); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -3056,7 +3053,7 @@ void CBotExprNull::RestoreState(CBotStack* &pj, bool bMain) CBotExprNan::CBotExprNan() { - name = "CBotExprNan"; + name = "CBotExprNan"; } CBotExprNan::~CBotExprNan() @@ -3067,20 +3064,20 @@ CBotExprNan::~CBotExprNan() bool CBotExprNan::Execute(CBotStack* &pj) { - CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; + CBotStack* pile = pj->AddStack(this); +// if ( pile == EOX ) return true; - 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); // nombre nan + pile->SetVar( var ); // mis sur la pile + return pj->Return(pile); // transmet en dessous } void CBotExprNan::RestoreState(CBotStack* &pj, bool bMain) { - if ( bMain ) pj->RestoreStack(this); + if ( bMain ) pj->RestoreStack(this); } ////////////////////////////////////////////////////////////////////////////////////// @@ -3090,8 +3087,8 @@ void CBotExprNan::RestoreState(CBotStack* &pj, bool bMain) CBotExprVar::CBotExprVar() { - name = "CBotExprVar"; - m_nIdent = 0; + name = "CBotExprVar"; + m_nIdent = 0; } CBotExprVar::~CBotExprVar() @@ -3131,7 +3128,7 @@ CBotInstr* CBotExprVar::Compile(CBotToken* &p, CBotCStack* pStack, int privat) // 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 + ///tests CBotToken token("this"); inst->SetToken(&token); ((CBotExprVar*)inst)->m_nIdent = -2; // identificator for this @@ -3234,44 +3231,44 @@ err: CBotInstr* CBotExprVar::CompileMethode(CBotToken* &p, CBotCStack* pStack) { - CBotToken* pp = p; - CBotCStack* pStk = pStack->TokenStack(); - - pStk->SetStartError(pp->GivStart()); - - // 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(); // 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 - - CBotToken* pp = p; - - 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; + CBotCStack* pStk = pStack->TokenStack(); + + pStk->SetStartError(pp->GivStart()); + + // 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(); // 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 + + CBotToken* pp = p; + + 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); } @@ -3279,85 +3276,85 @@ CBotInstr* CBotExprVar::CompileMethode(CBotToken* &p, CBotCStack* pStack) bool CBotExprVar::Execute(CBotStack* &pj) { - CBotVar* pVar = NULL; - CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; + CBotVar* pVar = NULL; + CBotStack* pile = pj->AddStack(this); +// if ( pile == EOX ) return true; -// if ( pile->IfStep() ) return false; +// if ( pile->IfStep() ) return false; - 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; // récupère la variable selon champs et index +// DEBUG("CBotExprVar::Execute", 1 , pj); - 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); // 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(); + } - pVar = pile1->GivVar(); // récupère si interrompu + pVar = pile1->GivVar(); // récupère si interrompu - if ( pVar == NULL ) - { -// pile1->SetError(TX_NULLPT, &m_token); - return pj->Return(pile1); - } + if ( pVar == NULL ) + { +// pile1->SetError(TX_NULLPT, &m_token); + 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); // opération faite } 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); // récupère la variable selon champs et index + return; + } } // retrouve une variable à l'exécution 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); // cherche la variable avec mise à jour si nécessaire + 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; // Champs d'une instance, tableau, méthode ? - 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 ); // ne rend pas la pile mais récupère le résultat si une méthode a été appelée } @@ -3365,11 +3362,11 @@ bool CBotExprVar::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToke 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); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -3378,58 +3375,58 @@ void CBotExprVar::RestoreStateVar(CBotStack* &pj, bool bMain) 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; // 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; } ////////////////////////////////////////////////////////////////////////////////////////// @@ -3440,255 +3437,255 @@ CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars) CBotInstrMethode::CBotInstrMethode() { - m_Parameters = NULL; - m_MethodeIdent = 0; -// m_nThisIdent = 0; - name = "CBotInstrMethode"; + m_Parameters = NULL; + m_MethodeIdent = 0; +// m_nThisIdent = 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; + 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 + 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; + if ( !bMain ) return; - CBotVar* ppVars[1000]; - CBotStack* pile1 = pile->RestoreStack(this); // une place pour la copie de This - if ( pile1 == NULL ) 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; + 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); + CBotVar* pThis = pile1->FindVar("this"); +// pThis->SetUniqNum(m_nThisIdent); + pThis->SetUniqNum(-2); - 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 - 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; + 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; + p = p->GivNext(); + if ( p == NULL) break; + } + ppVars[i] = NULL; - CBotClass* pClass = CBotClass::Find(m_ClassName); - CBotVar* pResult = NULL; + CBotClass* pClass = CBotClass::Find(m_ClassName); + CBotVar* pResult = NULL; - CBotVar* pRes = pResult; + CBotVar* pRes = pResult; - pClass->RestoreMethode(m_MethodeIdent, m_NomMethod, - pThis, ppVars, pile2); + 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 + 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 } /////////////////////////////////////////////////////////////////////////// @@ -3698,10 +3695,10 @@ bool CBotInstrMethode::Execute(CBotStack* &pj) CBotNew::CBotNew() { - name = "CBotNew"; - m_Parameters = NULL; - m_nMethodeIdent = 0; -// m_nThisIdent = 0; + name = "CBotNew"; + m_Parameters = NULL; + m_nMethodeIdent = 0; +// m_nThisIdent = 0; } CBotNew::~CBotNew() @@ -3710,214 +3707,214 @@ 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; + + // 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); + } error: - delete inst; - return pStack->Return(NULL, pStk); + delete inst; + return pStack->Return(NULL, pStk); } // exécute une instruction "new" bool CBotNew::Execute(CBotStack* &pj) { - CBotStack* pile = pj->AddStack(this); //pile principale -// if ( pile == EOX ) return true; + CBotStack* pile = pj->AddStack(this); //pile principale +// if ( pile == EOX ) return true; - if ( pile->IfStep() ) return false; + if ( pile->IfStep() ) return false; - CBotStack* pile1 = pj->AddStack2(); //pile secondaire + CBotStack* pile1 = pj->AddStack2(); //pile secondaire - 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 + // crée la variable "this" de type pointeur à l'objet - if ( pile->GivState()==0) - { - // crée une instance de la classe demandée - // et initialise le pointeur à cet objet + if ( pile->GivState()==0) + { + // crée une instance de la classe demandée + // et initialise le pointeur à cet objet - pThis = CBotVar::Create("this", pClass); -// pThis->SetUniqNum( m_nThisIdent ) ; - pThis->SetUniqNum( -2 ) ; + pThis = CBotVar::Create("this", pClass); +// pThis->SetUniqNum( m_nThisIdent ) ; + pThis->SetUniqNum( -2 ) ; - pile1->SetVar(pThis); // la place sur la pile1 - pile->IncState(); - } + pile1->SetVar(pThis); // la place sur la pile1 + pile->IncState(); + } - // retrouve le pointeur this si on a été interrompu - if ( pThis == NULL) - { - pThis = pile1->GivVar(); // retrouve le pointeur - } + // retrouve le pointeur this si on a été interrompu + if ( pThis == NULL) + { + pThis = pile1->GivVar(); // retrouve le pointeur + } - // y a-t-il une assignation ou des paramètres (constructeur) - if ( pile->GivState()==1) - { - // évalue le constructeur de l'instance + // y a-t-il une assignation ou des paramètres (constructeur) + if ( pile->GivState()==1) + { + // évalue le constructeur de l'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; + // évalue les paramètres + // et place les valeurs sur la pile + // pour pouvoir être interrompu n'importe quand - 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; + 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; - // crée une variable pour le résultat - CBotVar* pResult = NULL; // constructeurs toujours void + // crée une variable pour le résultat + CBotVar* pResult = NULL; // constructeurs toujours void - if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GivName(), - pThis, ppVars, - pResult, pile2, GivToken())) return false; // interrompu + if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GivName(), + pThis, ppVars, + pResult, pile2, GivToken())) return false; // interrompu - pThis->ConstructorSet(); // signale que le constructeur a été appelé -// pile->Return(pile2); // libère un bout de pile + pThis->ConstructorSet(); // signale que le constructeur a été appelé +// pile->Return(pile2); // libère un bout de pile -// pile->IncState(); - } +// pile->IncState(); + } - return pj->Return( pile1 ); // transmet en dessous + return pj->Return( pile1 ); // transmet en dessous } 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); //pile principale + if ( pile == NULL ) return; - CBotStack* pile1 = pj->AddStack2(); //pile secondaire + CBotStack* pile1 = pj->AddStack2(); //pile secondaire - 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 + // crée la variable "this" de type pointeur à l'objet - 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(); // retrouve le pointeur +// pThis->SetUniqNum( m_nThisIdent ); + pThis->SetUniqNum( -2 ); - // y a-t-il une assignation ou des paramètres (constructeur) - if ( pile->GivState()==1) - { - // évalue le constructeur de l'instance + // y a-t-il une assignation ou des paramètres (constructeur) + if ( pile->GivState()==1) + { + // évalue le constructeur de l'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; + // évalue les paramètres + // et place les valeurs sur la pile + // pour pouvoir être interrompu n'importe quand - 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(); // de la place sur la pile pour les résultats + 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); // interrompu ici ! + 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) ; // interrompu ici ! + } } ///////////////////////////////////////////////////////////// @@ -3925,77 +3922,77 @@ void CBotNew::RestoreState(CBotStack* &pj, bool bMain) bool TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op ) { - int t1 = type1.GivType(); - int t2 = type2.GivType(); - - int max = (t1 > t2) ? t1 : t2; - - if ( max == 99 ) return false; // un résultat est 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; - - 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 true; - } - - type1.SetType(max); - type2.SetType(max); - return true; + int t1 = type1.GivType(); + int t2 = type2.GivType(); + + int max = (t1 > t2) ? t1 : t2; + + if ( max == 99 ) return false; // un résultat est 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; + + 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 true; + } + + type1.SetType(max); + type2.SetType(max); + return true; } // regarde si deux variables sont compatible pour un passage de paramètre 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; // un résultat est 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; } @@ -4007,65 +4004,65 @@ bool TypesCompatibles( const CBotTypResult& type1, const CBotTypResult& type2 ) 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 +#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; + 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; + CBotProgram* p = pile->GivBotCall(true); + if ( !p->m_bDebugDD ) return; - FILE* pf = fopen("CbotDebug.txt", "a"); + FILE* pf = fopen("CbotDebug.txt", "a"); - fputs( text, pf ); + fputs( text, pf ); - CBotString v = " " + num(val) + "\n"; - fputs( v, pf ); + CBotString v = " " + num(val) + "\n"; + fputs( v, pf ); - fclose( pf); + fclose( pf); } #endif 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/CBotDll.h b/src/CBot/CBotDll.h index f0d7fef..514146f 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -13,66 +13,68 @@ // * // * 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 #include +#include "resource.h" +#include +#include -// #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, + CBotTypShort = 2, + CBotTypChar = 3, + CBotTypInt = 4, + CBotTypLong = 5, + CBotTypFloat = 6, + CBotTypDouble = 7, + 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 = non encore implémenté // pour SetUserPtr lors de la suppression d'un objet #define OBJECTDELETED ((void*)-1) @@ -84,90 +86,75 @@ enum CBotType 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; + 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 + // divers constructeurs selon les besoins + CBotTypResult(int type); + // 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 }; /* // 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 +165,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 @@ -256,106 +243,74 @@ public: 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(const char* lpsz); - //DllExport - int ReverseFind(const char c); - //DllExport - int ReverseFind(const char* lpsz); - //DllExport - bool LoadString(unsigned int 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, const char* 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 const char*() const; // as a C string - - int Compare(const char* 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 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 +319,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 +350,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) { - 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 +534,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 + + 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); + static + CBotVar* Create( CBotVar* pVar ); -/* //DllExport - static - CBotVar* Create( const char* name, int type, const char* ClassName = NULL); - // crée une variable selon son type,*/ - //DllExport - static - CBotVar* Create( const char* name, CBotTypResult type); - // idem à partir du type complet + void SetUserPtr(void* pUser); + // associe un pointeur utilisateur à une instance - //DllExport - static - CBotVar* Create( const char* name, CBotClass* pClass); - // idem pour une instance d'une classe connue + virtual void SetIdent(long UniqId); + // associe un identificateur unique à une instance + // ( c'est à l'utilisateur de s'assurer que l'id est unique) - static - CBotVar* Create( const CBotToken* name, int type ); - static - CBotVar* Create( const CBotToken* name, CBotTypResult type ); + void* GivUserPtr(); + // rend le pointeur associé à la variable - static - CBotVar* Create( const char* name, int type, CBotClass* pClass); + CBotString GivName(); // le nom de la variable, s'il est connu + //////////////////////////////////////////////////////////////////////////////////// + void SetName(const char* name); // change le nom de la variable - static - CBotVar* Create( CBotVar* pVar ); + int GivType(int mode = 0); // rend le type de base (int) de la variable + //////////////////////////////////////////////////////////////////////////////////////// + CBotTypResult GivTypResult(int mode = 0); // rend le type complet de la variable - //DllExport - void SetUserPtr(void* pUser); - // associe un pointeur utilisateur à une instance - //DllExport - virtual void SetIdent(long UniqId); - // associe un identificateur unique à une instance - // ( c'est à l'utilisateur de s'assurer que l'id est unique) + CBotToken* GivToken(); + void SetType(CBotTypResult& type); - //DllExport - void* GivUserPtr(); - // rend le pointeur associé à la variable + void SetInit(int bInit); // met la variable dans l'état IS_UNDEF, IS_DEF, IS_NAN - //DllExport - CBotString GivName(); // le nom de la variable, s'il est connu - //////////////////////////////////////////////////////////////////////////////////// - void SetName(const char* name); // change le nom de la variable + int GivInit(); // donne l'état de la variable - //DllExport - int GivType(int mode = 0); // rend le type de base (int) de la variable - //////////////////////////////////////////////////////////////////////////////////////// + void SetStatic(bool bStatic); + bool IsStatic(); - //DllExport - CBotTypResult GivTypResult(int mode = 0); // rend le type complet de la variable + void SetPrivate(int mPrivate); + bool IsPrivate(int mode = PR_PROTECT); + int GivPrivate(); + virtual + void ConstructorSet(); - CBotToken* GivToken(); - void SetType(CBotTypResult& type); + void SetVal(CBotVar* var); // remprend une valeur - //DllExport - void SetInit(int bInit); // met la variable dans l'état IS_UNDEF, IS_DEF, IS_NAN + 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 - //DllExport - int GivInit(); // donne l'état de la variable + virtual + CBotVar* GivItem(int row, bool bGrow = false); - //DllExport - void SetStatic(bool bStatic); - //DllExport - bool IsStatic(); + virtual + CBotVar* GivItemList(); // donne la liste des éléments - //DllExport - void SetPrivate(int mPrivate); - //DllExport - bool IsPrivate(int mode = PR_PROTECT); - //DllExport - int GivPrivate(); + CBotVar* GivStaticVar(); // rend le pointeur à la variable si elle est statique - virtual - void ConstructorSet(); + bool IsElemOfClass(const char* name); + // dit si l'élément appartient à la classe "name" + // rend true si l'objet est d'une classe fille - void SetVal(CBotVar* var); // remprend une valeur + CBotVar* GivNext(); // prochaine variable dans la liste (paramètres) + //////////////////////////////////////////////////////////////////////////////////////////// - //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 + void AddNext(CBotVar* pVar); // ajoute dans une liste - //DllExport - virtual - CBotVar* GivItem(int row, bool bGrow = false); + virtual + void Copy(CBotVar* pSrc, bool bName = true); // fait une copie de la variable - //DllExport - virtual - CBotVar* GivItemList(); // donne la liste des éléments + virtual void SetValInt(int val, const char* name = NULL); + // initialise avec une valeur entière (#) + ///////////////////////////////////////////////////////////////////////////////// - //DllExport - CBotVar* GivStaticVar(); // rend le pointeur à la variable si elle est statique + virtual void SetValFloat(float val); // initialise avec une valeur réelle (#) + //////////////////////////////////////////////////////////////////////////////// - //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 SetValString(const char* p);// initialise avec une valeur chaîne (#) + //////////////////////////////////////////////////////////////////////////////// - void AddNext(CBotVar* pVar); // ajoute dans une liste + virtual int GivValInt(); // demande la valeur entière (#) + //////////////////////////////////////////////////////////////////////// - virtual - void Copy(CBotVar* pSrc, bool bName = true); // fait une copie de la variable + virtual float GivValFloat(); // demande la valeur réelle (#) + /////////////////////////////////////////////////////////////////////// - //DllExport - virtual void SetValInt(int val, const char* name = NULL); - // initialise avec une valeur entière (#) - ///////////////////////////////////////////////////////////////////////////////// + virtual + CBotString GivValString(); // demande la valeur chaîne (#) + /////////////////////////////////////////////////////////////////////// - //DllExport - virtual void SetValFloat(float val); // initialise avec une valeur réelle (#) - //////////////////////////////////////////////////////////////////////////////// + virtual void SetClass(CBotClass* pClass); + virtual + CBotClass* GivClass(); - //DllExport - virtual void SetValString(const char* p);// initialise avec une valeur chaîne (#) - //////////////////////////////////////////////////////////////////////////////// + virtual void SetPointer(CBotVar* p); + virtual + CBotVarClass* GivPointer(); +// virtual void SetIndirection(CBotVar* pVar); - //DllExport - virtual int GivValInt(); // demande la valeur entière (#) - //////////////////////////////////////////////////////////////////////// + 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 - //DllExport - virtual float GivValFloat(); // demande la valeur réelle (#) - /////////////////////////////////////////////////////////////////////// + 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 - CBotString GivValString(); // demande la valeur chaîne (#) - /////////////////////////////////////////////////////////////////////// + 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 SetClass(CBotClass* pClass); - virtual - CBotClass* GivClass(); + virtual void Neg(); + virtual void Not(); + virtual void Inc(); + virtual void Dec(); - virtual void SetPointer(CBotVar* p); - virtual - CBotVarClass* GivPointer(); -// virtual void SetIndirection(CBotVar* pVar); - 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 bool Save0State(FILE* pf); + virtual bool Save1State(FILE* pf); + static bool RestoreState(FILE* pf, 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 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(); + 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 +763,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,64 +974,64 @@ 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é ! @@ -1176,25 +1039,27 @@ public: // routine implémentant l'instruction GOTO( CPoint pos ) 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 +#endif //_CBOTDLL_H_ + diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 77ed7d7..291a1e5 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -13,7 +13,12 @@ // * // * 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) + +/** + * \file CBotStack.cpp + * \brief Management of the stack + */ + #include "CBot.h" #include diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index 5f35337..33e1d04 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -13,53 +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 + +//strings management #include "CBot.h" #include #include #include -/// TODO need to be implemented to be able to load library -// HINSTANCE CBotString::m_hInstance = (HINSTANCE)LoadLibrary("libCbot.dll"); // how to retrieve it otherwise ?? +//Map is filled with id-string pars that are needed for CBot language parsing +const std::map 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, "%="}, + {TX_UNDEF, "undefined"}, + {TX_NAN, "not a number"}, + {ID_SUPER, "super"} +}; 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 = strlen( p ); + m_lg = strlen(p); - m_ptr = NULL; - if (m_lg>0) - { - m_ptr = (char*)malloc(m_lg+1); - strcpy(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); - strcpy(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); + } } @@ -67,539 +159,533 @@ CBotString::CBotString(const CBotString& srcString) int CBotString::GivLength() { - if ( m_ptr == NULL ) return 0; - return strlen( 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]; + + size_t i; + for (i = 0; i < m_lg && i < nCount && i < 1999; ++i) + { + chain[i] = m_ptr[i]; + } + chain[i] = 0 ; - return CBotString( chaine ); + 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(const char * lpsz) { - int i, j; - int l = strlen(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(const char * lpsz) { - int i, j; - int l = strlen(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); - strcpy(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(unsigned int id) { - char buffer[MAXSTRING]; - /// \TODO implement loading strings from resources. Figure out how to do it - // m_lg = ::LoadString( m_hInstance, id, buffer, MAXSTRING ); - - if (m_ptr != NULL) free(m_ptr); + const char * str = NULL; + str = MapIdToString((EID)id); + if (m_ptr != NULL) free(m_ptr); - m_ptr = NULL; - if (m_lg > 0) - { - m_ptr = (char*)malloc(m_lg+1); - strcpy(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); - strcpy(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, 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); - strcpy(p, m_ptr); - char* pp = p + m_lg; - strcpy(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 = strlen(pString); - if ( pString != NULL ) - { - m_lg = strlen(pString); + if (m_lg != 0) + { + m_ptr = (char*)malloc(m_lg+1); + strcpy(m_ptr, pString); + } + } - if (m_lg != 0) - { - m_ptr = (char*)malloc(m_lg+1); - strcpy(m_ptr, pString); - } - } - - return *this; + 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) strcpy(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); - strcpy(p, m_ptr); - char* pp = p + m_lg; - strcpy(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) { - return Compare(str) == 0; + return Compare(str) == 0; } bool CBotString::operator==(const char* p) { - return Compare(p) == 0; + return Compare(p) == 0; } bool CBotString::operator!=(const CBotString& str) { - return Compare(str) != 0; + return Compare(str) != 0; } bool CBotString::operator!=(const char* p) { - return Compare(p) != 0; + return Compare(p) != 0; } bool CBotString::operator>(const CBotString& str) { - return Compare(str) > 0; + return Compare(str) > 0; } bool CBotString::operator>(const char* p) { - return Compare(p) > 0; + return Compare(p) > 0; } bool CBotString::operator>=(const CBotString& str) { - return Compare(str) >= 0; + return Compare(str) >= 0; } bool CBotString::operator>=(const char* p) { - return Compare(p) >= 0; + return Compare(p) >= 0; } bool CBotString::operator<(const CBotString& str) { - return Compare(str) < 0; + return Compare(str) < 0; } bool CBotString::operator<(const char* p) { - return Compare(p) < 0; + return Compare(p) < 0; } bool CBotString::operator<=(const CBotString& str) { - return Compare(str) <= 0; + return Compare(str) <= 0; } bool CBotString::operator<=(const char* p) { - return Compare(p) <= 0; + return Compare(p) <= 0; } 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 emptyString[] = {0}; CBotString::operator const char * () const { - if (this == NULL || m_ptr == NULL) return emptyString; - return m_ptr; + if (this == NULL || m_ptr == NULL) return emptyString; + return m_ptr; } int CBotString::Compare(const char * lpsz) const { - char* p = m_ptr; - if (lpsz == NULL) lpsz = emptyString; - if (m_ptr == NULL) p = emptyString; - 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[] (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); - - - // Ret rid of old stuff (note: no destructors called) - delete[] (unsigned char *)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 1b6392c..03a5337 100644 --- a/src/CBot/CBotToken.cpp +++ b/src/CBot/CBotToken.cpp @@ -464,6 +464,7 @@ bool CBotToken::GivKeyDefNum(const char* w, CBotToken* &token) // reprend la liste des mots clefs dans les ressources +/// \todo Fixme Figure out how this should work. void CBotToken::LoadKeyWords() { CBotString s; 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/resource.h b/src/CBot/resource.h index 7e57d32..f82fb9c 100644 --- a/src/CBot/resource.h +++ b/src/CBot/resource.h @@ -15,98 +15,105 @@ // * 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 +173,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_ + -- cgit v1.2.3-1-g7c22 From 26f91499473ce0f7738fee0931a337ef19d713de Mon Sep 17 00:00:00 2001 From: Zaba999 Date: Fri, 20 Jul 2012 23:13:02 +0200 Subject: Further translations and doxygen comments. --- src/CBot/CBot.cpp | 1827 +++++++++++++++++------------------- src/CBot/CBot.h | 2020 +++++++++++++++++++++------------------- src/CBot/CBotDll.h | 102 +- src/CBot/CBotFunction.cpp | 4 - src/CBot/CBotStack.cpp | 1707 +++++++++++++++++----------------- src/CBot/CBotString.cpp | 6 +- src/CBot/CBotVar.cpp | 2270 ++++++++++++++++++++++----------------------- src/CBot/resource.h | 2 - 8 files changed, 3957 insertions(+), 3981 deletions(-) (limited to 'src') diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index e73eea0..fb25049 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -87,8 +87,8 @@ bool CBotInstr::ChkLvl(const CBotString& label, int type) while (--i>=0) { if ( type == ID_CONTINUE && m_labelLvl[i] == "#SWITCH") continue; - if ( label.IsEmpty() ) return true; - if ( m_labelLvl[i] == label ) return true; + if (label.IsEmpty()) return true; + if (m_labelLvl[i] == label) return true; } return false; } @@ -128,21 +128,21 @@ CBotToken* CBotInstr::GivToken() void CBotInstr::AddNext(CBotInstr* n) { CBotInstr* p = this; - while ( p->m_next != NULL ) p = p->m_next; + 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; + 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; + while (p->m_next3b != NULL) p = p->m_next3b; p->m_next3b = n; } @@ -175,17 +175,17 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) { CBotToken* pp = p; - if ( p == NULL ) 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 ) ) + 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 )) + if (!IsOfTypeList(pp, ID_WHILE, ID_FOR, ID_DO, ID_REPEAT, 0)) { pStack->SetError(TX_LABEL, pp->GivStart()); return NULL; @@ -255,7 +255,7 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) pStack->SetStartError(p->GivStart()); - // ne doit pas être un mot réservé par DefineNum + // should not be a reserved word DefineNum if (p->GivType() == TokenTypDef) { pStack->SetError(TX_RESERVED, p); @@ -264,16 +264,16 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) // this might be an instance of class definnition CBotToken* ppp = p; - if (IsOfType( ppp, TokenTypVar )) + if (IsOfType(ppp, TokenTypVar)) { - if ( CBotClass::Find(p) != NULL ) + if (CBotClass::Find(p) != NULL) { - // oui, compile la déclaration de l'instance + // yes, compiles the declaration of the instance return CBotClassInst::Compile(p, pStack); } } - // ce peut être une instruction arithmétique + // this can be an arythmetic instruction CBotInstr* inst = CBotExpression::Compile(p, pStack); if (IsOfType(p, ID_SEP)) { @@ -287,46 +287,46 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) bool CBotInstr::Execute(CBotStack* &pj) { CBotString ClassManquante = name; - ASM_TRAP(); // ne doit jamais passer par cette routine - // mais utiliser les routines des classes filles + ASM_TRAP(); // should never go through this routine + // but use the routines of the subclasses return false; } bool CBotInstr::Execute(CBotStack* &pj, CBotVar* pVar) { - if ( !Execute(pj) ) return false; - pVar->SetVal( pj->GivVar() ); + if (!Execute(pj)) return false; + pVar->SetVal(pj->GivVar()); return true; } 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 + ASM_TRAP(); // should never go through this routine + // but use the routines of the subclasses } bool CBotInstr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) { - ASM_TRAP(); // papa sait pas faire, voir les filles + ASM_TRAP(); // dad do not know, see the girls return false; } bool CBotInstr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) { - ASM_TRAP(); // papa sait pas faire, voir les filles + ASM_TRAP(); // dad do not know, see the girls return false; } 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) { @@ -337,10 +337,11 @@ bool CBotInstr::CompCase(CBotStack* &pj, int val) ////////////////////////////////////////////////////////////////////////////////////// -// 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) @@ -349,14 +350,14 @@ CBotInstr* CBotBlock::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal) if (IsOfType(p, ID_OPBLK)) { - CBotInstr* inst = CBotListInstr::Compile( p, pStack, bLocal ); + CBotInstr* inst = CBotListInstr::Compile(p, pStack, bLocal); if (IsOfType(p, ID_CLBLK)) { return inst; } - pStack->SetError(TX_CLOSEBLK, p->GivStart()); // manque la parenthèse + pStack->SetError(TX_CLOSEBLK, p->GivStart()); // missing parenthesis delete inst; return NULL; } @@ -367,28 +368,28 @@ CBotInstr* CBotBlock::Compile(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 (*) + // to handle the case with local definition instruction (*) CBotCStack* pStk = pStack->TokenStack(p, bLocal); - return pStack->Return( CBotInstr::Compile(p, pStk), // une instruction unique + 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() { @@ -403,16 +404,16 @@ CBotListInstr::~CBotListInstr() 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(); while (true) { - if ( p == NULL ) break; + 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)) { @@ -421,7 +422,7 @@ CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal 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()) { @@ -429,62 +430,60 @@ CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal return pStack->Return(NULL, pStk); } - if ( inst->m_Instr == NULL ) inst->m_Instr = i; - else inst->m_Instr->AddNext(i); // ajoute à la suite + 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) { - 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 + while (state-->0) p = p->GivNext(); // returns to the interrupted operation - if ( p != NULL ) while (true) + if (p != NULL) while (true) { -// DEBUG( "CBotListInstr", pile->GivState(), pile ); - - 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 (p == NULL) break; + if (!pile->IncState()) ;//return false; // ready for next } - return pj->Return( pile ); // transmet en dessous + return pj->Return(pile); } void CBotListInstr::RestoreState(CBotStack* &pj, bool bMain) { - if ( !bMain ) return; + if (!bMain) return; CBotStack* pile = pj->RestoreStack(this); - if ( pile == NULL ) return; + 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 + 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() { @@ -499,7 +498,7 @@ CBotLeftExprVar::~CBotLeftExprVar() CBotInstr* CBotLeftExprVar::Compile(CBotToken* &p, CBotCStack* pStack) { - // vérifie que le token est un nom de variable + // verifies that the token is a variable name if (p->GivType() != TokenTypVar) { pStack->SetError( TX_NOVAR, p->GivStart()); @@ -513,20 +512,20 @@ CBotInstr* CBotLeftExprVar::Compile(CBotToken* &p, CBotCStack* pStack) return inst; } -// crée une variable et lui assigne le résultat de la pile +// creates a variable and assigns the result to the stack bool CBotLeftExprVar::Execute(CBotStack* &pj) { CBotVar* var1; CBotVar* var2; 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 + var1->SetUniqNum(m_nIdent); // with the unique identifier + pj->AddVar(var1); // place it on the stack + + 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) @@ -534,9 +533,9 @@ void CBotLeftExprVar::RestoreState(CBotStack* &pj, bool bMain) CBotVar* var1; var1 = pj->FindVar(m_token.GivString()); - if ( var1 == NULL ) ASM_TRAP(); + if (var1 == NULL) ASM_TRAP(); - var1->SetUniqNum(m_nIdent); // avec cet identificateur unique + var1->SetUniqNum(m_nIdent); // with the unique identifier } ////////////////////////////////////////////////////////////////////////////////////// @@ -544,7 +543,7 @@ 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[]; @@ -566,52 +565,51 @@ CBotInstr* CBotInstArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu { CBotCStack* pStk = pStack->TokenStack(p); - CBotInstArray* inst = new CBotInstArray(); // crée l'objet + CBotInstArray* inst = new CBotInstArray(); 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 )) ) + // 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)) // redéfinition de la variable ? + 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 ? + while (IsOfType(p, ID_OPBRK)) { - if ( p->GivType() != ID_CLBRK ) - i = CBotExpression::Compile( p, pStk ); // expression pour la valeur + if (p->GivType() != ID_CLBRK) + i = CBotExpression::Compile(p, pStk); // expression for the value else - i = new CBotEmpty(); // spécial si pas de formule + i = new CBotEmpty(); // if no special formula - inst->AddNext3b(i); // construit une liste + inst->AddNext3b(i); // construct a list type = CBotTypResult(CBotTypArrayPointer, type); - if (!pStk->IsOk() || !IsOfType( p, ID_CLBRK ) ) + 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 + 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 + pStack->AddVar(var); // place it on the stack - if ( IsOfType(p, ID_ASS) ) // avec une assignation + if (IsOfType(p, ID_ASS)) // with an assignment { - inst->m_listass = CBotListArray::Compile( p, pStk, type.GivTypElem() ); + 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: @@ -620,86 +618,85 @@ error: } -// exécute la définition d'un tableau +// executes the definition of an array bool CBotInstArray::Execute(CBotStack* &pj) { CBotStack* pile1 = pj->AddStack(this); -// if ( pile1 == EOX ) return true; CBotStack* pile = pile1; - if ( pile1->GivState() == 0 ) + if (pile1->GivState() == 0) { - // cherche les dimensions max du tableau - CBotInstr* p = GivNext3b(); // les différentes formules + // seek the maximum dimension of the table + CBotInstr* p = GivNext3b(); // the different formulas int nb = 0; while (p != NULL) { - pile = pile->AddStack(); // petite place pour travailler + pile = pile->AddStack(); // little room to work nb++; - if ( pile->GivState() == 0 ) + if (pile->GivState() == 0) { - if ( !p->Execute(pile) ) return false; // calcul de la taille // interrompu? + if (!p->Execute(pile)) return false; // size calculation //interrupted? pile->IncState(); } p = p->GivNext3b(); } p = GivNext3b(); - pile = pile1; // revient sur la pile + pile = pile1; // returns to the stack 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 + 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 ); + return pj->Return (pile); } n++; p = p->GivNext3b(); } while (n<100) max[n++] = 0; - m_typevar.SetArray( max ); // mémorise les limitations + 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); // inscrit le tableau de base sur la pile + 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(); } - if ( pile1->GivState() == 1 ) + if (pile1->GivState() == 1) { - if ( m_listass != NULL ) // il y a des assignation pour ce tableau + 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; + 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; + !m_next2b->Execute(pile1 )) return false; - return pj->Return( pile1 ); // transmet en dessous + return pj->Return(pile1); } void CBotInstArray::RestoreState(CBotStack* &pj, bool bMain) @@ -707,47 +704,46 @@ void CBotInstArray::RestoreState(CBotStack* &pj, bool bMain) CBotStack* pile1 = pj; CBotVar* var = pj->FindVar(m_var->GivToken()->GivString()); - if ( var != NULL ) var->SetUniqNum(((CBotLeftExprVar*)m_var)->m_nIdent); + if (var != NULL) var->SetUniqNum(((CBotLeftExprVar*)m_var)->m_nIdent); - if ( bMain ) + if (bMain) { - pile1 = pj->RestoreStack(this); + pile1 = pj->RestoreStack(this); CBotStack* pile = pile1; - if ( pile == NULL ) return; + if (pile == NULL) return; - if ( pile1->GivState() == 0 ) + if (pile1->GivState() == 0) { - // cherche les dimensions max du tableau - CBotInstr* p = GivNext3b(); // les différentes formules + // 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 ) + pile = pile->RestoreStack(); + if (pile == NULL) return; + if (pile->GivState() == 0) { - p->RestoreState(pile, bMain); // calcul de la taille // interrompu! + p->RestoreState(pile, bMain); return; } p = p->GivNext3b(); } } - if ( pile1->GivState() == 1 && m_listass != NULL ) + 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 +// 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 + pVar->SetValInt(-1); pj->SetVar(pVar); return true; } @@ -757,8 +753,8 @@ 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() @@ -779,36 +775,34 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu CBotToken* pp = p; - if ( IsOfType( p, ID_NULL ) ) + 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 + inst->SetToken(pp); + return pStack->Return(inst, pStk); // ok with empty element } - CBotListArray* inst = new CBotListArray(); // crée l'objet + CBotListArray* inst = new CBotListArray(); - if ( IsOfType( p, ID_OPENPAR ) ) + if (IsOfType( p, ID_OPENPAR )) { - // prend chaque élément l'un après l'autre - if ( type.Eq( CBotTypArrayPointer ) ) + // 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 ) ) ) + if (NULL == ( inst->m_expr = CBotListArray::Compile( p, pStk, type ) )) { goto error; } - while ( IsOfType( p, ID_COMMA ) ) // d'autres éléments ? + while (IsOfType( p, ID_COMMA )) // other elements? { pStk->SetStartError(p->GivStart()); - CBotInstr* i = CBotListArray::Compile( p, pStk, type ); - if ( NULL == i ) + CBotInstr* i = CBotListArray::Compile(p, pStk, type); + if (NULL == i) { goto error; } @@ -819,31 +813,31 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu else { pStk->SetStartError(p->GivStart()); - if ( NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) ) + if (NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) { goto error; } - CBotVar* pv = pStk->GivVar(); // le résultat de l'expression + CBotVar* pv = pStk->GivVar(); // result of the expression - if ( pv == NULL || !TypesCompatibles( type, pv->GivTypResult() )) // type compatible ? + if (pv == NULL || !TypesCompatibles( type, pv->GivTypResult())) // compatible type? { pStk->SetError(TX_BADTYPE, p->GivStart()); goto error; } - while ( IsOfType( p, ID_COMMA ) ) // d'autres éléments ? + while (IsOfType( p, ID_COMMA )) // other elements? { pStk->SetStartError(p->GivStart()); - CBotInstr* i = CBotTwoOpExpr::Compile( p, pStk ) ; - if ( NULL == i ) + CBotInstr* i = CBotTwoOpExpr::Compile(p, pStk) ; + if (NULL == i) { goto error; } - CBotVar* pv = pStk->GivVar(); // le résultat de l'expression + CBotVar* pv = pStk->GivVar(); // result of the expression - if ( pv == NULL || !TypesCompatibles( type, pv->GivTypResult() )) // type compatible ? + if (pv == NULL || !TypesCompatibles( type, pv->GivTypResult())) // compatible type? { pStk->SetError(TX_BADTYPE, p->GivStart()); goto error; @@ -867,58 +861,57 @@ error: } -// exécute la définition d'un tableau +// executes the definition of an array bool CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar) { CBotStack* pile1 = pj->AddStack(); -// if ( pile1 == EOX ) return true; CBotVar* pVar2; CBotInstr* p = m_expr; int n = 0; - for ( ; p != NULL ; n++, p = p->GivNext3() ) + for (; p != NULL ; n++, p = p->GivNext3()) { - if ( pile1->GivState() > n ) continue; + if (pile1->GivState() > n) continue; 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(); } - return pj->Return( pile1 ); // transmet en dessous + return pj->Return(pile1); } void CBotListArray::RestoreState(CBotStack* &pj, bool bMain) { - if ( bMain ) + if (bMain) { CBotStack* pile = pj->RestoreStack(this); - if ( pile == NULL ) return; + if (pile == NULL) return; CBotInstr* p = m_expr; 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_next = NULL; // for multiple definitions m_var = m_expr = NULL; name = "CBotInt"; @@ -928,32 +921,31 @@ CBotInt::~CBotInt() { delete m_var; delete m_expr; -// delete m_next; // fait par le destructeur de la classe de base ~CBotInstr() } CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool first) { - if ( IsOfType(p, ID_OPBRK) ) + if (IsOfType(p, ID_OPBRK)) { - if ( !IsOfType(p, ID_CLBRK) ) + 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; + CBotInstr* inst = CompileArray(p, pStack, CBotTypResult(CBotTypArrayPointer, type), false); + if (inst != NULL || !pStack->IsOk()) return inst; } - // compile une déclaration de tableau + // compiles an array declaration if (first) return NULL ; - CBotInstr* inst = CBotInstArray::Compile( p, pStack, type ); - if ( inst == NULL ) 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 (IsOfType(p, ID_COMMA)) // several definitions { - if ( NULL != ( inst->m_next2b = CBotInstArray::CompileArray(p, pStack, type, false) )) // compile la suivante + if (NULL != ( inst->m_next2b = CBotInstArray::CompileArray(p, pStack, type, false))) // compiles next one { return inst; } @@ -961,7 +953,7 @@ CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypRes return NULL; } - if (IsOfType(p, ID_SEP)) // instruction terminée + if (IsOfType(p, ID_SEP)) // end of instruction { return inst; } @@ -973,40 +965,40 @@ CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypRes CBotInstr* CBotInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip) { - CBotToken* pp = cont ? NULL : p; // pas de répétition du token "int" + 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; + if (inst != NULL || !pStack->IsOk()) return inst; CBotCStack* pStk = pStack->TokenStack(pp); - inst = new CBotInt(); // crée l'objet + inst = new CBotInt(); inst->m_expr = NULL; CBotToken* vartoken = p; - inst->SetToken( vartoken ); + inst->SetToken(vartoken); - // détermine l'expression valable pour l'élément gauche - if ( NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) ) + // 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)) // redéfinition de la variable + if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable { pStk->SetError(TX_REDEFVAR, vartoken); goto error; } - if (IsOfType(p, ID_OPBRK)) // avec des indices ? + if (IsOfType(p, ID_OPBRK)) { - delete inst; // n'est pas de type CBotInt - p = vartoken; // revient sur le nom de la variable + delete inst; // type is not CBotInt + p = vartoken; // returns the variable name - // compile une déclaration de tableau + // compiles an array declaration - CBotInstr* inst2 = CBotInstArray::Compile( p, pStk, CBotTypInt ); + CBotInstr* inst2 = CBotInstArray::Compile(p, pStk, CBotTypInt); if (!pStk->IsOk() ) { @@ -1014,24 +1006,24 @@ CBotInstr* CBotInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool n goto error; } - if (IsOfType(p, ID_COMMA)) // plusieurs définitions enchaînées + if (IsOfType(p, ID_COMMA)) // several definition chained { - if ( NULL != ( inst2->m_next2b = CBotInt::Compile(p, pStk, true, noskip) )) // compile la suivante + 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; // pas d'assignation, variable déjà créée + goto suite; // no assignment, variable already created } - if (IsOfType(p, ID_ASS)) // avec une assignation ? + if (IsOfType(p, ID_ASS)) // with an assignment? { - if ( NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) ) + if (NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) { goto error; } - if ( pStk->GivType() >= CBotTypBoolean ) // type compatible ? + if (pStk->GivType() >= CBotTypBoolean) // compatible type ? { pStk->SetError(TX_BADTYPE, p->GivStart()); goto error; @@ -1039,23 +1031,22 @@ CBotInstr* CBotInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool n } { - 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( + 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()); - // lui attribut un numéro unique - pStack->AddVar(var); // la place sur la pile + pStack->AddVar(var); // place it on the stack } - if (IsOfType(p, ID_COMMA)) // plusieurs définitions enchaînées + if (IsOfType(p, ID_COMMA)) // chained several definitions { - if ( NULL != ( inst->m_next2b = CBotInt::Compile(p, pStk, true, noskip) )) // compile la suivante + 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 + if (noskip || IsOfType(p, ID_SEP)) // instruction is completed { return pStack->Return(inst, pStk); } @@ -1068,54 +1059,53 @@ error: 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) { - 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 (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->IfStep() ) return false; + if (pile->IfStep()) return false; if ( m_next2b && - !m_next2b->Execute(pile)) return false; // autre(s) définition(s) + !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) { CBotStack* pile = pj; - if ( bMain ) + if (bMain) { pile = pj->RestoreStack(this); - if ( pile == NULL ) return; + if (pile == NULL) return; if ( pile->GivState()==0) { - if (m_expr) m_expr->RestoreState(pile, bMain); // valeur initiale // interrompu! + if (m_expr) m_expr->RestoreState(pile, bMain); // initial value // interrupted? return; } } 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() @@ -1138,7 +1128,7 @@ CBotInstr* CBotBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bo if (!cont && !IsOfType(p, ID_BOOLEAN, ID_BOOL)) return NULL; CBotBoolean* inst = (CBotBoolean*)CompileArray(p, pStack, CBotTypBoolean); - if ( inst != NULL || !pStack->IsOk() ) return inst; + if (inst != NULL || !pStack->IsOk()) return inst; CBotCStack* pStk = pStack->TokenStack(pp); @@ -1147,64 +1137,63 @@ CBotInstr* CBotBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bo inst->m_expr = NULL; CBotToken* vartoken = p; - inst->SetToken( vartoken ); + inst->SetToken(vartoken); CBotVar* var = NULL; - if ( NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) ) + 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 + if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable { pStk->SetError(TX_REDEFVAR, vartoken); goto error; } - if (IsOfType(p, ID_OPBRK)) // avec des indices ? + if (IsOfType(p, ID_OPBRK)) { - delete inst; // n'est pas de type CBotInt - p = vartoken; // revient sur le nom de la variable + 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 + goto suite; // no assignment, variable already created } - if (IsOfType(p, ID_ASS)) // avec une assignation ? + if (IsOfType(p, ID_ASS)) { - if ( NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) ) + if (NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) { goto error; } - if ( !pStk->GivTypResult().Eq(CBotTypBoolean) ) // type compatible ? + 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 = 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()); - // lui attribut un numéro unique - pStack->AddVar(var); // la place sur la pile + pStack->AddVar(var); suite: - if (IsOfType(p, ID_COMMA)) // plusieurs définitions enchaînées + if (IsOfType(p, ID_COMMA)) { - if ( NULL != ( inst->m_next2b = CBotBoolean::Compile(p, pStk, true, noskip) )) // compile la suivante + if (NULL != ( inst->m_next2b = CBotBoolean::Compile(p, pStk, true, noskip))) { return pStack->Return(inst, pStk); } } - if (noskip || IsOfType(p, ID_SEP)) // instruction terminée + if (noskip || IsOfType(p, ID_SEP)) { return pStack->Return(inst, pStk); } @@ -1217,55 +1206,54 @@ error: return pStack->Return(NULL, pStk); } -// exécute une définition de variable booléenne +// executes a boolean variable definition 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 (m_expr && !m_expr->Execute(pile)) return false; + m_var->Execute(pile); 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) + !m_next2b->Execute(pile)) return false; - return pj->Return( pile ); // transmet en dessous + return pj->Return(pile); } void CBotBoolean::RestoreState(CBotStack* &pj, bool bMain) { CBotStack* pile = pj; - if ( bMain ) + if (bMain) { pile = pj->RestoreStack(this); - if ( pile == NULL ) return; + if (pile == NULL) return; if ( pile->GivState()==0) { - if (m_expr) m_expr->RestoreState(pile, bMain); // valeur initiale interrompu? + 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() @@ -1288,7 +1276,7 @@ CBotInstr* CBotFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool if (!cont && !IsOfType(p, ID_FLOAT)) return NULL; CBotFloat* inst = (CBotFloat*)CompileArray(p, pStack, CBotTypFloat); - if ( inst != NULL || !pStack->IsOk() ) return inst; + if (inst != NULL || !pStack->IsOk()) return inst; CBotCStack* pStk = pStack->TokenStack(pp); @@ -1300,62 +1288,58 @@ CBotInstr* CBotFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool CBotVar* var = NULL; inst->SetToken(vartoken); - if ( NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) ) + 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 + 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)) // avec des indices ? + if (IsOfType(p, ID_OPBRK)) { - 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 ); + delete inst; + p = vartoken; + 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 + goto suite; // no assignment, variable already created } - if (IsOfType(p, ID_ASS)) // avec une assignation ? + if (IsOfType(p, ID_ASS)) { - if ( NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) ) + if (NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) { goto error; } - if ( pStk->GivType() >= CBotTypBoolean ) // type compatible ? + if (pStk->GivType() >= CBotTypBoolean) { 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 = CBotVar::Create(vartoken, CBotTypFloat); + var->SetInit(inst->m_expr != NULL); var->SetUniqNum( ((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum()); - // lui attribut un numéro unique - pStack->AddVar(var); // la place sur la pile + pStack->AddVar(var); suite: - if (IsOfType(p, ID_COMMA)) // plusieurs définitions enchaînées + if (IsOfType(p, ID_COMMA)) { - if ( NULL != ( inst->m_next2b = CBotFloat::Compile(p, pStk, true, noskip) )) // compile la suivante + if (NULL != ( inst->m_next2b = CBotFloat::Compile(p, pStk, true, noskip))) { return pStack->Return(inst, pStk); } } - if (noskip || IsOfType(p, ID_SEP)) // instruction terminée + if (noskip || IsOfType(p, ID_SEP)) { return pStack->Return(inst, pStk); } @@ -1368,55 +1352,54 @@ error: 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) { - 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 (m_expr && !m_expr->Execute(pile)) return false; + m_var->Execute(pile); 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) + !m_next2b->Execute(pile)) return false; - return pj->Return( pile ); // transmet en dessous + return pj->Return(pile); } void CBotFloat::RestoreState(CBotStack* &pj, bool bMain) { CBotStack* pile = pj; - if ( bMain ) + if (bMain) { pile = pj->RestoreStack(this); - if ( pile == NULL ) return; + if (pile == NULL) return; if ( pile->GivState()==0) { - if (m_expr) m_expr->RestoreState(pile, bMain); // valeur initiale interrompu? + 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() @@ -1439,7 +1422,7 @@ CBotInstr* CBotIString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bo if (!cont && !IsOfType(p, ID_STRING)) return NULL; CBotIString* inst = (CBotIString*)CompileArray(p, pStack, CBotTypString); - if ( inst != NULL || !pStack->IsOk() ) return inst; + if (inst != NULL || !pStack->IsOk()) return inst; CBotCStack* pStk = pStack->TokenStack(pp); @@ -1448,47 +1431,46 @@ CBotInstr* CBotIString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bo inst->m_expr = NULL; CBotToken* vartoken = p; - inst->SetToken( vartoken ); + inst->SetToken(vartoken); - if ( NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) ) + 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 + if (pStk->CheckVarLocal(vartoken)) { pStk->SetStartError(vartoken->GivStart()); pStk->SetError(TX_REDEFVAR, vartoken->GivEnd()); goto error; } - if (IsOfType(p, ID_ASS)) // avec une assignation ? + if (IsOfType(p, ID_ASS)) { - if ( NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) ) + if (NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) { goto error; } -/* if ( !pStk->GivTypResult().Eq(CBotTypString) ) // type compatible ? +/* 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 + CBotVar* var = CBotVar::Create(vartoken, CBotTypString); + var->SetInit(inst->m_expr != NULL); var->SetUniqNum( ((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum()); - // lui attribut un numéro unique - pStack->AddVar(var); // la place sur la pile + pStack->AddVar(var); - if (IsOfType(p, ID_COMMA)) // plusieurs définitions enchaînées + if (IsOfType(p, ID_COMMA)) { - if ( NULL != ( inst->m_next2b = CBotIString::Compile(p, pStk, true, noskip) )) // compile la suivante + if (NULL != ( inst->m_next2b = CBotIString::Compile(p, pStk, true, noskip))) { return pStack->Return(inst, pStk); } } - - if (noskip || IsOfType(p, ID_SEP)) // instruction terminée + + if (noskip || IsOfType(p, ID_SEP)) { return pStack->Return(inst, pStk); } @@ -1501,49 +1483,48 @@ error: 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) { - 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 (m_expr && !m_expr->Execute(pile)) return false; + m_var->Execute(pile); 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) + !m_next2b->Execute(pile)) return false; - return pj->Return( pile ); // transmet en dessous + return pj->Return(pile); } void CBotIString::RestoreState(CBotStack* &pj, bool bMain) { CBotStack* pile = pj; - - if ( bMain ) + + if (bMain) { pile = pj->RestoreStack(this); - if ( pile == NULL ) return; + if (pile == NULL) return; if ( pile->GivState()==0) { - if (m_expr) m_expr->RestoreState(pile, bMain); // valeur initiale interrompu? + 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); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1551,8 +1532,8 @@ 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() { @@ -1583,7 +1564,7 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) ID_ASSAND, ID_ASSXOR, ID_ASSOR, ID_ASSSL , ID_ASSSR, ID_ASSASR, 0 )) { - if ( inst->m_leftop == NULL ) + if (inst->m_leftop == NULL) { pStack->SetError(TX_BADLEFT, p->GivEnd()); delete inst; @@ -1599,10 +1580,10 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) CBotTypResult type1 = pStack->GivTypResult(); - // récupère la variable pour la marquer assignée + // get the variable assigned to mark CBotVar* var = NULL; inst->m_leftop->ExecuteVar(var, pStack); - if ( var == NULL ) + if (var == NULL) { delete inst; return NULL; @@ -1617,18 +1598,18 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) CBotTypResult type2 = var->GivTypResult(); - // quels sont les types acceptables ? + // what types are acceptable? switch (OpType) { case ID_ASS: - // if (type2 == CBotTypClass) type2 = -1; // pas de classe - if ( (type1.Eq(CBotTypPointer) && type2.Eq(CBotTypPointer) ) || + // 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); // pas la même classe -//- if ( !type1.Eq(CBotTypClass) ) var->SetPointer(pStack->GivVar()->GivPointer());*/ + if (!c1->IsChildOf(c2)) type2.SetType(-1); +//- if (!type1.Eq(CBotTypClass)) var->SetPointer(pStack->GivVar()->GivPointer());*/ var->SetInit(2); } else @@ -1637,46 +1618,43 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) break; case ID_ASSADD: if (type2.Eq(CBotTypBoolean) || - type2.Eq(CBotTypPointer) ) type2 = -1; // nombres et chaines + 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; // nombres uniquement + if (type2.GivType() >= CBotTypBoolean) type2 = -1; // numbers only break; } - if (!TypeCompatible( type1, type2, OpType )) + if (!TypeCompatible(type1, type2, OpType)) { pStack->SetError(TX_BADTYPE, &inst->m_token); delete inst; return NULL; } - return inst; // types compatibles ? + return inst; // compatible type? } 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 + p = pp; // returns to the top + pStack->SetError(0,0); // forget the error -// 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 ); + 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; } -// exécute une expression avec assignation +// executes an expression with assignment bool CBotExpression::Execute(CBotStack* &pj) { CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; CBotToken* pToken = m_leftop->GivToken(); CBotVar* pVar = NULL; @@ -1686,33 +1664,30 @@ bool CBotExpression::Execute(CBotStack* &pj) 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 + // 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 -// DEBUG( "CBotExpression::Execute", -1, pj); if ( pile1->GivState()==0) { - pile1->SetCopyVar(pVar); // garde une copie sur la pile (si interrompu) + pile1->SetCopyVar(pVar); // keeps the copy on the stack (if interrupted) pile1->IncState(); } - CBotStack* pile2 = pile->AddStack(); // attention pile et surtout pas pile1 + CBotStack* pile2 = pile->AddStack(); if ( pile2->GivState()==0) { -// DEBUG( "CBotExpression::Execute", -2, pj); - if (m_rightop && !m_rightop->Execute(pile2)) return false; // valeur initiale // interrompu? + if (m_rightop && !m_rightop->Execute(pile2)) return false; // initial value // interrupted? pile2->IncState(); } - if ( pile1->GivState() == 1 ) + if (pile1->GivState() == 1) { -// DEBUG( "CBotExpression::Execute", -3, pj); - if ( m_token.GivType() != ID_ASS ) + if (m_token.GivType() != ID_ASS) { - pVar = pile1->GivVar(); // récupére si interrompu + pVar = pile1->GivVar(); // recovers if interrupted IsInit = pVar->GivInit(); - if ( IsInit == IS_NAN ) + if (IsInit == IS_NAN) { pile2->SetError(TX_OPNAN, m_leftop->GivToken()); return pj->Return(pile2); @@ -1720,57 +1695,57 @@ bool CBotExpression::Execute(CBotStack* &pj) result = CBotVar::Create("", pVar->GivTypResult(2)); } - switch ( m_token.GivType() ) + 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 + result->Add(pile1->GivVar(), pile2->GivVar()); + pile2->SetVar(result); break; case ID_ASSSUB: - result->Sub(pile1->GivVar(), pile2->GivVar()); // soustrait - pile2->SetVar(result); // re-place le résultat + result->Sub(pile1->GivVar(), pile2->GivVar()); + pile2->SetVar(result); break; case ID_ASSMUL: - result->Mul(pile1->GivVar(), pile2->GivVar()); // multiplie - pile2->SetVar(result); // re-place le résultat + result->Mul(pile1->GivVar(), pile2->GivVar()); + pile2->SetVar(result); break; case ID_ASSDIV: if (IsInit && - result->Div(pile1->GivVar(), pile2->GivVar())) // divise + result->Div(pile1->GivVar(), pile2->GivVar())) pile2->SetError(TX_DIVZERO, &m_token); - pile2->SetVar(result); // re-place le résultat + pile2->SetVar(result); break; case ID_ASSMODULO: if (IsInit && - result->Modulo(pile1->GivVar(), pile2->GivVar())) // reste de la division + result->Modulo(pile1->GivVar(), pile2->GivVar())) pile2->SetError(TX_DIVZERO, &m_token); - pile2->SetVar(result); // re-place le résultat + pile2->SetVar(result); break; case ID_ASSAND: - result->And(pile1->GivVar(), pile2->GivVar()); // multiplie - pile2->SetVar(result); // re-place le résultat + result->And(pile1->GivVar(), pile2->GivVar()); + pile2->SetVar(result); break; case ID_ASSXOR: result->XOr(pile1->GivVar(), pile2->GivVar()); - pile2->SetVar(result); // re-place le résultat + pile2->SetVar(result); break; case ID_ASSOR: result->Or(pile1->GivVar(), pile2->GivVar()); - pile2->SetVar(result); // re-place le résultat + pile2->SetVar(result); break; case ID_ASSSL: result->SL(pile1->GivVar(), pile2->GivVar()); - pile2->SetVar(result); // re-place le résultat + pile2->SetVar(result); break; case ID_ASSSR: result->SR(pile1->GivVar(), pile2->GivVar()); - pile2->SetVar(result); // re-place le résultat + pile2->SetVar(result); break; case ID_ASSASR: result->ASR(pile1->GivVar(), pile2->GivVar()); - pile2->SetVar(result); // re-place le résultat + pile2->SetVar(result); break; default: ASM_TRAP(); @@ -1781,41 +1756,39 @@ bool CBotExpression::Execute(CBotStack* &pj) pile1->IncState(); } -// DEBUG( "CBotExpression::Execute", -4, pj); - if ( !m_leftop->Execute( pile2, pile1 ) ) - return false; // crée et fait l'assigation du résultat + if (!m_leftop->Execute( pile2, pile1 )) + return false; - return pj->Return( pile2 ); // transmet en dessous + return pj->Return(pile2); } void CBotExpression::RestoreState(CBotStack* &pj, bool bMain) { - if ( bMain ) + if (bMain) { CBotToken* pToken = m_leftop->GivToken(); CBotVar* pVar = NULL; CBotStack* pile = pj->RestoreStack(this); - if ( pile == NULL ) return; + if (pile == NULL) return; CBotStack* pile1 = pile; - if ( pile1->GivState()==0) { - m_leftop->RestoreStateVar(pile, true); // variable avant évaluation de la valeur droite + m_leftop->RestoreStateVar(pile, true); return; } - m_leftop->RestoreStateVar(pile, false); // variable avant évaluation de la valeur droite + m_leftop->RestoreStateVar(pile, false); - CBotStack* pile2 = pile->RestoreStack(); // attention pile et surtout pas pile1 - if ( pile2 == NULL ) return; + CBotStack* pile2 = pile->RestoreStack(); + if (pile2 == NULL) return; if ( pile2->GivState()==0) { - if (m_rightop) m_rightop->RestoreState(pile2, bMain); // valeur initiale // interrompu? + if (m_rightop) m_rightop->RestoreState(pile2, bMain); return; } } @@ -1825,55 +1798,58 @@ void CBotExpression::RestoreState(CBotStack* &pj, bool bMain) ////////////////////////////////////////////////////////////////////////////////////// -// 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 )) + if (IsOfType(p, ID_OPENPAR)) { - CBotInstr* inst = CBotBoolExpr::Compile( p, pStack ); - if ( NULL != inst ) + CBotInstr* inst = CBotBoolExpr::Compile(p, pStack); + if (NULL != inst) { - if ( IsOfType(p, ID_CLOSEPAR )) + if (IsOfType(p, ID_CLOSEPAR)) { return inst; } - pStack->SetError(TX_CLOSEPAR, p->GivStart()); // manque la parenthèse + 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; } ////////////////////////////////////////////////////////////////////////////////////// -// 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()); - CBotInstr* inst = CBotTwoOpExpr::Compile( p, pStack ); + CBotInstr* inst = CBotTwoOpExpr::Compile(p, pStack); - if ( NULL != inst ) + if (NULL != inst) { - if ( pStack->GivTypResult().Eq(CBotTypBoolean) ) + if (pStack->GivTypResult().Eq(CBotTypBoolean)) { return inst; } - pStack->SetError(TX_NOTBOOL, p->GivStart()); // n'est pas un booléan + pStack->SetError(TX_NOTBOOL, p->GivStart()); // is not a boolean } delete inst; @@ -1884,18 +1860,19 @@ CBotInstr* CBotBoolExpr::Compile(CBotToken* &p, CBotCStack* pStack) ////////////////////////////////////////////////////////////////////////////////////// -// 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) { @@ -1903,12 +1880,12 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack) pStk->SetStartError(p->GivStart()); - // est-ce une expression entre parenthèse ? + // is it an expression in parentheses? if (IsOfType(p, ID_OPENPAR)) { - CBotInstr* inst = CBotExpression::Compile( p, pStk ); + CBotInstr* inst = CBotExpression::Compile(p, pStk); - if ( NULL != inst ) + if (NULL != inst) { if (IsOfType(p, ID_CLOSEPAR)) { @@ -1920,41 +1897,41 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack) return pStack->Return(NULL, pStk); } - // est-ce une opération unaire ? + // is this a unary operation? CBotInstr* inst = CBotExprUnaire::Compile(p, pStk); if (inst != NULL || !pStk->IsOk()) return pStack->Return(inst, pStk); - // est-ce un nom de variable ? + // is it a variable name? if (p->GivType() == TokenTypVar) { - // c'est peut-être un appel de méthode sans le "this." devant + // this may be a method call without the "this." before inst = CBotExprVar::CompileMethode(p, pStk); - if ( inst != NULL ) return pStack->Return(inst, pStk); + if (inst != NULL) return pStack->Return(inst, pStk); - // est-ce un appel de procédure ? + // is it a procedure call? inst = CBotInstrCall::Compile(p, pStk); - if ( inst != NULL || !pStk->IsOk() ) + if (inst != NULL || !pStk->IsOk()) return pStack->Return(inst, pStk); CBotToken* pvar = p; - // non, c'est une variable "ordinaire" + // no, it an "ordinaty" variable inst = CBotExprVar::Compile(p, pStk); CBotToken* pp = p; - // post incrémenté ou décrémenté ? + // post incremented or decremented? if (IsOfType(p, ID_INC, ID_DEC)) { - if ( pStk->GivType() >= CBotTypBoolean ) + if (pStk->GivType() >= CBotTypBoolean) { pStk->SetError(TX_BADTYPE, pp); delete inst; return pStack->Return(NULL, pStk); } - // recompile la variable pour read-only + // recompile the variable for read-only delete inst; p = pvar; inst = CBotExprVar::Compile(p, pStk, PR_READ); @@ -1962,13 +1939,13 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack) CBotPostIncExpr* i = new CBotPostIncExpr(); i->SetToken(pp); - i->m_Instr = inst; // instruction associée + i->m_Instr = inst; // associated statement return pStack->Return(i, pStk); } return pStack->Return(inst, pStk); } - // est-ce une variable préincrémentée ou prédécrémentée ? + // pre increpemted or pre decremented? CBotToken* pp = p; if (IsOfType(p, ID_INC, ID_DEC)) { @@ -1979,7 +1956,7 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack) { if (NULL != (i->m_Instr = CBotExprVar::Compile(p, pStk, PR_READ))) { - if ( pStk->GivType() >= CBotTypBoolean ) + if (pStk->GivType() >= CBotTypBoolean) { pStk->SetError(TX_BADTYPE, pp); delete inst; @@ -1992,51 +1969,51 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack) } } - // est-ce un nombre ou un DefineNum ? + // is it a number or DefineNum? if (p->GivType() == TokenTypNum || p->GivType() == TokenTypDef ) { - CBotInstr* inst = CBotExprNum::Compile( p, pStk ); + CBotInstr* inst = CBotExprNum::Compile(p, pStk); return pStack->Return(inst, pStk); } - // est-ce une chaine ? + // is this a chaine? if (p->GivType() == TokenTypString) { CBotInstr* inst = CBotExprAlpha::Compile(p, pStk); return pStack->Return(inst, pStk); } - // est un élément "true" ou "false" + // is a "true" or "false" if (p->GivType() == ID_TRUE || p->GivType() == ID_FALSE ) { - CBotInstr* inst = CBotExprBool::Compile( p, pStk ); + CBotInstr* inst = CBotExprBool::Compile(p, pStk); return pStack->Return(inst, pStk); } - // est un objet à créer avec new + // is an object to be created with new if (p->GivType() == ID_NEW) { - CBotInstr* inst = CBotNew::Compile( p, pStk ); + CBotInstr* inst = CBotNew::Compile(p, pStk); return pStack->Return(inst, pStk); } - // est un pointeur nul - if (IsOfType( p, ID_NULL )) + // is a null pointer + if (IsOfType(p, ID_NULL)) { CBotInstr* inst = new CBotExprNull (); - inst->SetToken( pp ); + 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 )) + // is a number nan + if (IsOfType(p, ID_NAN)) { CBotInstr* inst = new CBotExprNan (); - inst->SetToken( pp ); + inst->SetToken(pp); CBotVar* var = CBotVar::Create("", CBotTypInt); var->SetInit(IS_NAN); pStk->SetVar(var); @@ -2050,10 +2027,10 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack) ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// -// 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() { @@ -2084,88 +2061,89 @@ bool CBotPostIncExpr::Execute(CBotStack* &pj) 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); CBotStack* pile3 = pile2->AddStack(this); - if ( pile3->IfStep() ) return false; + if (pile3->IfStep()) return false; - if ( var1->GivInit() == IS_NAN ) + if (var1->GivInit() == IS_NAN) { - pile1->SetError( TX_OPNAN, &m_token ); + pile1->SetError(TX_OPNAN, &m_token); } - if ( var1->GivInit() != IS_DEF ) + if (var1->GivInit() != IS_DEF) { - pile1->SetError( TX_NOTINIT, &m_token ); + pile1->SetError(TX_NOTINIT, &m_token); } 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) { - if ( !bMain ) return; + if (!bMain) return; CBotStack* pile1 = pj->RestoreStack(this); - if ( pile1 == NULL ) return; + if (pile1 == NULL) return; ((CBotExprVar*)m_Instr)->RestoreStateVar(pile1, bMain); - if ( pile1 != NULL ) pile1->RestoreStack(this); + if (pile1 != NULL) pile1->RestoreStack(this); } bool CBotPreIncExpr::Execute(CBotStack* &pj) { CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; - if ( pile->IfStep() ) return false; + if (pile->IfStep()) return false; CBotVar* var1; - if ( pile->GivState() == 0 ) + 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 + // 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 ) + if (var1->GivInit() == IS_NAN) { - pile->SetError( TX_OPNAN, &m_token ); - return pj->Return(pile); // opération faite + pile->SetError(TX_OPNAN, &m_token); + return pj->Return(pile); // operation performed } - if ( var1->GivInit() != IS_DEF ) + if (var1->GivInit() != IS_DEF) { - pile->SetError( TX_NOTINIT, &m_token ); - return pj->Return(pile); // opération faite + 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 + else var1->Dec(); // ((CBotVarInt*)var1)->m_val 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) { - if ( !bMain ) return; + if (!bMain) return; CBotStack* pile = pj->RestoreStack(this); - if ( pile == NULL ) return; + if (pile == NULL) return; - if ( pile->GivState() == 0 ) + if (pile->GivState() == 0) { return; } @@ -2175,7 +2153,7 @@ void CBotPreIncExpr::RestoreState(CBotStack* &pj, bool bMain) ////////////////////////////////////////////////////////////////////////////////////// -// compile une expression unaire +// compile an unary expression // + // - // not @@ -2197,24 +2175,24 @@ 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; + if (!IsOfTypeList( p, ID_ADD, ID_SUB, ID_LOG_NOT, ID_TXT_NOT, ID_NOT, 0 )) return NULL; CBotCStack* pStk = pStack->TokenStack(pp); CBotExprUnaire* inst = new CBotExprUnaire(); inst->SetToken(pp); - if ( NULL != (inst->m_Expr = CBotParExpr::Compile( p, pStk )) ) + if (NULL != (inst->m_Expr = CBotParExpr::Compile( p, pStk ))) { - if ( op == ID_ADD && pStk->GivType() < CBotTypBoolean ) // seulement avec des nombre + if (op == ID_ADD && pStk->GivType() < CBotTypBoolean) // only with the number return pStack->Return(inst, pStk); - if ( op == ID_SUB && pStk->GivType() < CBotTypBoolean ) // seulement avec des nombre + if (op == ID_SUB && pStk->GivType() < CBotTypBoolean) // only with the numer return pStack->Return(inst, pStk); - if ( op == ID_NOT && pStk->GivType() < CBotTypFloat ) // seulement avec des entiers + 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) )// seulement avec des booléens + 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) )// seulement avec des booléens + if (op == ID_TXT_NOT && pStk->GivTypResult().Eq(CBotTypBoolean))// only with boolean return pStack->Return(inst, pStk); pStk->SetError(TX_BADTYPE, &inst->m_token); @@ -2223,30 +2201,29 @@ CBotInstr* CBotExprUnaire::Compile(CBotToken* &p, CBotCStack* pStack) return pStack->Return(NULL, pStk); } -// exécute l'expresson unaire +// executes unary expression bool CBotExprUnaire::Execute(CBotStack* &pj) { CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; - if ( pile->GivState() == 0 ) + if (pile->GivState() == 0) { - if (!m_Expr->Execute( pile )) return false; // interrompu ? + if (!m_Expr->Execute(pile)) return false; // interrupted ? pile->IncState(); } CBotStack* pile2 = pile->AddStack(); - if ( pile2->IfStep() ) return false; + 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 + break; case ID_SUB: - var->Neg(); // change le signe + var->Neg(); // change the sign break; case ID_NOT: case ID_LOG_NOT: @@ -2254,19 +2231,19 @@ bool CBotExprUnaire::Execute(CBotStack* &pj) var->Not(); break; } - return pj->Return(pile); // transmet en dessous + return pj->Return(pile); // forwards below } void CBotExprUnaire::RestoreState(CBotStack* &pj, bool bMain) { - if ( !bMain ) return; + if (!bMain) return; CBotStack* pile = pj->RestoreStack(this); if ( pile == NULL) return; - if ( pile->GivState() == 0 ) + if (pile->GivState() == 0) { - m_Expr->RestoreState( pile, bMain ); // interrompu ici ! + m_Expr->RestoreState(pile, bMain); // interrupted here! return; } } @@ -2274,7 +2251,7 @@ void CBotExprUnaire::RestoreState(CBotStack* &pj, bool bMain) ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// -// gestion des index pour les tableaux +// index management for arrays // array [ expression ] @@ -2289,95 +2266,89 @@ CBotIndexExpr::~CBotIndexExpr() 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) { - if ( pVar->GivType(1) != CBotTypArrayPointer ) + if (pVar->GivType(1) != CBotTypArrayPointer) ASM_TRAP(); - pVar = ((CBotVarArray*)pVar)->GivItem(0, false); // à la compilation rend l'élément [0] - if ( pVar == NULL ) + 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); + 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) { CBotStack* pj = pile; -// DEBUG( "CBotIndexExpr::ExecuteVar", -1 , pj); - if ( pVar->GivType(1) != CBotTypArrayPointer ) + if (pVar->GivType(1) != CBotTypArrayPointer) ASM_TRAP(); pile = pile->AddStack(); -// if ( pile == EOX ) return true; - if ( pile->GivState() == 0 ) + if (pile->GivState() == 0) { - if ( !m_expr->Execute(pile) ) return false; + if (!m_expr->Execute(pile)) return false; pile->IncState(); } - // traite les tableaux + // 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 ) + 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 ) + 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; -// 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) { pile = pile->RestoreStack(); - if ( pile == NULL ) return; + if (pile == NULL) return; - if ( bMain && pile->GivState() == 0 ) + if (bMain && pile->GivState() == 0) { m_expr->RestoreState(pile, true); return; } - if ( m_next3 ) + 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 @@ -2397,16 +2368,15 @@ void CBotFieldExpr::SetUniqNum(int 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) { - if ( pVar->GivType(1) != CBotTypPointer ) + if (pVar->GivType(1) != CBotTypPointer) ASM_TRAP(); -// pVar = pVar->GivItem(m_token.GivString()); pVar = pVar->GivItemRef(m_nIdent); - if ( pVar == NULL ) + if (pVar == NULL) { pile->SetError(TX_NOITEM, &m_token); return false; @@ -2418,74 +2388,69 @@ bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) return true; } -// idem à l'exécution - 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; + 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 ) + if (pVar->GivType(1) != CBotTypPointer) ASM_TRAP(); CBotVarClass* pItem = pVar->GivPointer(); - if ( pItem == NULL ) + if (pItem == NULL) { pile->SetError(TX_NULLPT, prevToken); - return pj->Return( pile ); + return pj->Return(pile); } - if ( pItem->GivUserPtr() == OBJECTDELETED ) + if (pItem->GivUserPtr() == OBJECTDELETED) { pile->SetError(TX_DELETEDPT, prevToken); - return pj->Return( pile ); + 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 ) + if (pVar == NULL) { pile->SetError(TX_NOITEM, &m_token); - return pj->Return( pile ); + return pj->Return(pile); } - if ( pVar->IsStatic() ) + if (pVar->IsStatic()) { -// DEBUG( "IsStatic", 0, pj) ; - // pour une variable statique, la prend dans la classe elle-même + // for a static variable, takes it in the class itself CBotClass* pClass = pItem->GivClass(); pVar = pClass->GivItem(m_token.GivString()); -// DEBUG( "done "+pVar->GivName(), 0, pj) ; } - // demande la mise à jour de l'élément, s'il y a lieu + // 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; - 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) { - pj = pj->RestoreStack(this); // modifie pj en sortie - if ( pj == NULL ) return; + pj = pj->RestoreStack(this); + if (pj == NULL) return; - if ( m_next3 != NULL ) + 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"; @@ -2515,13 +2480,13 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack) // is it a variable name? if (p->GivType() == TokenTypVar) { - CBotLeftExpr* inst = new CBotLeftExpr(); // creates the object + CBotLeftExpr* inst = new CBotLeftExpr(); // creates the object inst->SetToken(p); CBotVar* var; - if ( NULL != (var = pStk->FindVar(p)) ) // seek if known variable + if (NULL != (var = pStk->FindVar(p))) // seek if known variable { inst->m_nIdent = var->GivUniqNum(); if (inst->m_nIdent > 0 && inst->m_nIdent < 9000) @@ -2529,81 +2494,81 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack) if ( var->IsPrivate(PR_READ) && !pStk->GivBotCall()->m_bCompileClass) { - pStk->SetError( TX_PRIVATE, p ); + pStk->SetError(TX_PRIVATE, p); goto err; } - // il s'agit d'un élement de la classe courante - // ajoute l'équivalent d'un this. devant + // this is an element of the current class + // adds the equivalent of this. before CBotToken pthis("this"); inst->SetToken(&pthis); - inst->m_nIdent = -2; // ident pour this + inst->m_nIdent = -2; // indent for this - CBotFieldExpr* i = new CBotFieldExpr(); // nouvel élément - i->SetToken( p ); // garde le nom du token - inst->AddNext3(i); // ajoute à la suite + 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(); // token suivant + p = p->GivNext(); // next token while (true) { - if ( var->GivType() == CBotTypArrayPointer ) // s'il sagit d'un tableau + if (var->GivType() == CBotTypArrayPointer) { - if ( IsOfType( p, ID_OPBRK ) ) // regarde s'il y a un index + if (IsOfType( p, ID_OPBRK )) { CBotIndexExpr* i = new CBotIndexExpr(); - i->m_expr = CBotExpression::Compile(p, pStk); // compile la formule - inst->AddNext3(i); // ajoute à la chaine + i->m_expr = CBotExpression::Compile(p, pStk); + inst->AddNext3(i); // add to the chain - var = ((CBotVarArray*)var)->GivItem(0,true); // donne le composant [0] + var = ((CBotVarArray*)var)->GivItem(0,true); // gets the component [0] - if ( i->m_expr == NULL ) + if (i->m_expr == NULL) { - pStk->SetError( TX_BADINDEX, p->GivStart() ); + pStk->SetError(TX_BADINDEX, p->GivStart()); goto err; } - if ( !pStk->IsOk() || !IsOfType( p, ID_CLBRK ) ) + if (!pStk->IsOk() || !IsOfType( p, ID_CLBRK )) { - pStk->SetError( TX_CLBRK, p->GivStart() ); + pStk->SetError(TX_CLBRK, p->GivStart()); goto err; } continue; } } - if ( var->GivType(1) == CBotTypPointer ) // pour les classes + if (var->GivType(1) == CBotTypPointer) // for classes { - if ( IsOfType(p, ID_DOT) ) + 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 + CBotFieldExpr* i = new CBotFieldExpr(); // new element + i->SetToken(pp); // keeps the name of the token + inst->AddNext3(i); // adds after - if ( p->GivType() == TokenTypVar ) // doit être un nom + if (p->GivType() == TokenTypVar) // must be a name { - var = var->GivItem(p->GivString()); // récupère l'item correpondant - if ( var != NULL ) + 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 ); + pStk->SetError(TX_PRIVATE, pp); goto err; } i->SetUniqNum(var->GivUniqNum()); - p = p->GivNext(); // saute le nom + p = p->GivNext(); // skips the name continue; } - pStk->SetError( TX_NOITEM, p ); + pStk->SetError(TX_NOITEM, p); } - pStk->SetError( TX_DOT, p->GivStart() ); + pStk->SetError(TX_DOT, p->GivStart()); goto err; } } @@ -2611,7 +2576,7 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack) } - if ( pStk->IsOk() ) return (CBotLeftExpr*) pStack->Return(inst, pStk); + if (pStk->IsOk()) return (CBotLeftExpr*) pStack->Return(inst, pStk); } pStk->SetError(TX_UNDEFVAR, p); err: @@ -2622,31 +2587,26 @@ err: return (CBotLeftExpr*) pStack->Return(NULL, pStk); } -// exécute, trouve une variable et lui assigne le résultat de la pile - +// 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; 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 ( var1 ) + if (var1) { - var2 = pj->GivVar(); // resultat sur la pile d'entrée - if ( var2 ) + var2 = pj->GivVar(); // result on the input stack + if (var2) { CBotTypResult t1 = var1->GivTypResult(); CBotTypResult t2 = var2->GivTypResult(); - if ( t2.Eq(CBotTypPointer) ) + if (t2.Eq(CBotTypPointer)) { CBotClass* c1 = t1.GivClass(); CBotClass* c2 = t2.GivClass(); @@ -2654,24 +2614,24 @@ bool CBotLeftExpr::Execute(CBotStack* &pj, CBotStack* array) { CBotToken* pt = &m_token; pile->SetError(TX_BADTYPE, pt); - return pj->Return(pile); // opération faite + return pj->Return(pile); // operation performed } } - var1->SetVal(var2); // fait l'assignation + var1->SetVal(var2); // do assignment } - pile->SetCopyVar( var1 ); // remplace sur la pile par une copie de la variable elle-même - // (pour avoir le nom) + 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) { pVar = pile->FindVar(m_token); - if ( pVar == NULL ) return false; + if (pVar == NULL) return false; if ( m_next3 != NULL && !m_next3->ExecuteVar(pVar, pile) ) return false; @@ -2679,14 +2639,14 @@ bool CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) return true; } -// retrouve une variable à l'exécution +// fetch the variable at runtume 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 ) + if (pVar == NULL) { #ifdef _DEBUG ASM_TRAP(); @@ -2695,7 +2655,7 @@ bool CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevT 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; @@ -2705,19 +2665,19 @@ bool CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevT 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 ) + if (m_next3 != NULL) m_next3->RestoreStateVar(pile, bMain); } ////////////////////////////////////////////////////////////////////////////////////////// -// transforme une chaîne en nombre entier -// peut être de la forme 0xabc123 +// converts a string into integer +// may be of the form 0xabc123 -long GivNumInt( const char* p ) +long GivNumInt(const char* p) { long num = 0; while (*p >= '0' && *p <= '9') @@ -2725,21 +2685,21 @@ long GivNumInt( const char* p ) num = num * 10 + *p - '0'; p++; } - if ( *p == 'x' || *p == 'X' ) + if (*p == 'x' || *p == 'X') { while (*++p != 0) { - if ( *p >= '0' && *p <= '9' ) + if (*p >= '0' && *p <= '9') { num = num * 16 + *p - '0'; continue; } - if ( *p >= 'A' && *p <= 'F' ) + if (*p >= 'A' && *p <= 'F') { num = num * 16 + *p - 'A' + 10; continue; } - if ( *p >= 'a' && *p <= 'f' ) + if (*p >= 'a' && *p <= 'f') { num = num * 16 + *p - 'a' + 10; continue; @@ -2750,9 +2710,8 @@ long GivNumInt( const char* p ) return num; } -// transforme une chaîne en un nombre réel - -extern float GivNumFloat( const char* p ) +// converts a string into a float number +extern float GivNumFloat(const char* p) { double num = 0; double div = 10; @@ -2769,7 +2728,7 @@ extern float GivNumFloat( const char* p ) p++; } - if ( *p == '.' ) + if (*p == '.') { p++; while (*p >= '0' && *p <= '9') @@ -2781,33 +2740,33 @@ extern float GivNumFloat( const char* p ) } int exp = 0; - if ( *p == 'e' || *p == 'E' ) + if (*p == 'e' || *p == 'E') { char neg = 0; p++; - if ( *p == '-' || *p == '+' ) neg = *p++; + if (*p == '-' || *p == '+') neg = *p++; while (*p >= '0' && *p <= '9') { exp = exp * 10 + (*p - '0'); p++; } - if ( neg == '-' ) exp = -exp; + if (neg == '-') exp = -exp; } - while ( exp > 0 ) + while (exp > 0) { num *= 10.0; exp--; } - while ( exp < 0 ) + while (exp < 0) { num /= 10.0; exp++; } - if ( bNeg ) num = -num; + if (bNeg) num = -num; return (float)num; } @@ -2815,8 +2774,7 @@ extern float GivNumFloat( const char* p ) ////////////////////////////////////////////////////////////////////////////////////// -// compile un token représentant un nombre - +// compiles a token representing a number CBotExprNum::CBotExprNum() { name = "CBotExprNum"; @@ -2836,13 +2794,13 @@ CBotInstr* CBotExprNum::Compile(CBotToken* &p, CBotCStack* pStack) CBotString s = p->GivString(); inst->m_numtype = CBotTypInt; - if ( p->GivType() == TokenTypDef ) + 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 ) ) ) + 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); @@ -2864,19 +2822,18 @@ CBotInstr* CBotExprNum::Compile(CBotToken* &p, CBotCStack* pStack) return pStack->Return(NULL, pStk); } -// exécute, retourne le nombre correspondant +// execute, returns the corresponding number bool CBotExprNum::Execute(CBotStack* &pj) { CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; - if ( pile->IfStep() ) return false; + if (pile->IfStep()) return false; CBotVar* var = CBotVar::Create((CBotToken*)NULL, m_numtype); CBotString nombre ; - if ( m_token.GivType() == TokenTypDef ) + if (m_token.GivType() == TokenTypDef) { nombre = m_token.GivString(); } @@ -2885,27 +2842,27 @@ bool CBotExprNum::Execute(CBotStack* &pj) { case CBotTypShort: case CBotTypInt: - var->SetValInt( m_valint, nombre ); // valeur du nombre + var->SetValInt(m_valint, nombre); break; case CBotTypFloat: - var->SetValFloat( m_valfloat ); // valeur du nombre + var->SetValFloat(m_valfloat); break; } - pile->SetVar( var ); // mis sur la pile + 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) { - 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() { @@ -2931,37 +2888,36 @@ CBotInstr* CBotExprAlpha::Compile(CBotToken* &p, CBotCStack* pStack) return pStack->Return(inst, pStk); } -// exécute, retourne la chaîne correspondante +// execute, returns the corresponding string bool CBotExprAlpha::Execute(CBotStack* &pj) { CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; - if ( pile->IfStep() ) return false; + if (pile->IfStep()) return false; CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypString); CBotString chaine = m_token.GivString(); - chaine = chaine.Mid(1, chaine.GivLength()-2); // enlève les guillemets + 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); } 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() { @@ -2981,7 +2937,7 @@ CBotInstr* CBotExprBool::Compile(CBotToken* &p, CBotCStack* pStack) p->GivType() == ID_FALSE ) { inst = new CBotExprBool(); - inst->SetToken(p); // mémorise l'opération false ou true + inst->SetToken(p); // stores the operation false or true p = p->GivNext(); CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypBoolean); @@ -2991,32 +2947,31 @@ CBotInstr* CBotExprBool::Compile(CBotToken* &p, CBotCStack* pStack) return pStack->Return(inst, pStk); } -// exécute, retourne true ou false +// executes, returns true or false bool CBotExprBool::Execute(CBotStack* &pj) { CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; - if ( pile->IfStep() ) return false; + if (pile->IfStep()) return false; CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypBoolean); 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) { - if ( bMain ) pj->RestoreStack(this); + if (bMain) pj->RestoreStack(this); } ////////////////////////////////////////////////////////////////////////////////////////// -// gestion de l'opérande "null" +// management of the operand "null" CBotExprNull::CBotExprNull() { @@ -3027,29 +2982,28 @@ CBotExprNull::~CBotExprNull() { } -// exécute, retourne un pointeur vide +// executes, returns an empty pointer bool CBotExprNull::Execute(CBotStack* &pj) { CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; - if ( pile->IfStep() ) return false; + 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) { - if ( bMain ) pj->RestoreStack(this); + if (bMain) pj->RestoreStack(this); } ////////////////////////////////////////////////////////////////////////////////////////// -// gestion de l'opérande "nan" +// management of the operand "nan" CBotExprNan::CBotExprNan() { @@ -3060,30 +3014,29 @@ CBotExprNan::~CBotExprNan() { } -// exécute, retourne un pointeur vide +// executes, returns null pointer bool CBotExprNan::Execute(CBotStack* &pj) { CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; - if ( pile->IfStep() ) return false; + 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) { - 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() { @@ -3105,23 +3058,23 @@ CBotInstr* CBotExprVar::Compile(CBotToken* &p, CBotCStack* pStack, int privat) // is it a variable? if (p->GivType() == TokenTypVar) { - CBotInstr* inst = new CBotExprVar(); // create the object + CBotInstr* inst = new CBotExprVar(); // create the object inst->SetToken(p); CBotVar* var; - if ( NULL != (var = pStk->FindVar(p)) ) // seek if known variable + if (NULL != (var = pStk->FindVar(p))) // seek if known variable { int ident = var->GivUniqNum(); - ((CBotExprVar*)inst)->m_nIdent = ident; // identifies variable by its number + ((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 ); + pStk->SetError(TX_PRIVATE, p); goto err; } @@ -3131,85 +3084,84 @@ CBotInstr* CBotExprVar::Compile(CBotToken* &p, CBotCStack* pStack, int privat) ///tests CBotToken token("this"); inst->SetToken(&token); - ((CBotExprVar*)inst)->m_nIdent = -2; // identificator for this + ((CBotExprVar*)inst)->m_nIdent = -2; // identificator for this - CBotFieldExpr* i = new CBotFieldExpr(); // new element - i->SetToken( p ); // keeps the name of the token + CBotFieldExpr* i = new CBotFieldExpr(); // new element + i->SetToken(p); // keeps the name of the token i->SetUniqNum(ident); - inst->AddNext3(i); // added after + inst->AddNext3(i); // added after } - p = p->GivNext(); // next token + p = p->GivNext(); // next token while (true) { - if ( var->GivType() == CBotTypArrayPointer ) // s'il sagit d'un tableau + if (var->GivType() == CBotTypArrayPointer) { - if ( IsOfType( p, ID_OPBRK ) ) // regarde s'il y a un index + if (IsOfType( p, ID_OPBRK )) // check if there is an aindex { CBotIndexExpr* i = new CBotIndexExpr(); - i->m_expr = CBotExpression::Compile(p, pStk); // compile la formule - inst->AddNext3(i); // ajoute à la chaine + i->m_expr = CBotExpression::Compile(p, pStk); // compile the formula + inst->AddNext3(i); // add to the chain - var = ((CBotVarArray*)var)->GivItem(0,true); // donne le composant [0] + var = ((CBotVarArray*)var)->GivItem(0,true); // gets the component [0] - if ( i->m_expr == NULL ) + if (i->m_expr == NULL) { - pStk->SetError( TX_BADINDEX, p->GivStart() ); + pStk->SetError(TX_BADINDEX, p->GivStart()); goto err; } - if ( !pStk->IsOk() || !IsOfType( p, ID_CLBRK ) ) + if (!pStk->IsOk() || !IsOfType( p, ID_CLBRK )) { - pStk->SetError( TX_CLBRK, p->GivStart() ); + pStk->SetError(TX_CLBRK, p->GivStart()); goto err; } continue; } - //// pStk->SetError( TX_OPBRK, p->GivStart() ); } - if ( var->GivType(1) == CBotTypPointer ) // pour les classes + if (var->GivType(1) == CBotTypPointer) // for classes { - if ( IsOfType(p, ID_DOT) ) + if (IsOfType(p, ID_DOT)) { CBotToken* pp = p; - if ( p->GivType() == TokenTypVar ) // doit être un nom + if (p->GivType() == TokenTypVar) // must be a name { - if ( p->GivNext()->GivType() == ID_OPENPAR )// un appel de méthode ? + if (p->GivNext()->GivType() == ID_OPENPAR) // a method call? { CBotInstr* i = CBotInstrMethode::Compile(p, pStk, var); - if ( !pStk->IsOk() ) goto err; - inst->AddNext3(i); // ajoute à la suite + if (!pStk->IsOk()) goto err; + inst->AddNext3(i); // added after 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 ) + 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 ); + pStk->SetError(TX_PRIVATE, pp); goto err; } } } - if ( var != NULL ) + if (var != NULL) { - p = p->GivNext(); // saute le nom + p = p->GivNext(); // skips the name continue; } - pStk->SetError( TX_NOITEM, p ); + pStk->SetError(TX_NOITEM, p); goto err; } - pStk->SetError( TX_DOT, p->GivStart() ); + pStk->SetError(TX_DOT, p->GivStart()); goto err; } } @@ -3217,8 +3169,8 @@ CBotInstr* CBotExprVar::Compile(CBotToken* &p, CBotCStack* pStack, int privat) 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->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: @@ -3236,34 +3188,35 @@ CBotInstr* CBotExprVar::CompileMethode(CBotToken* &p, CBotCStack* pStack) pStk->SetStartError(pp->GivStart()); - // est-ce un nom de variable ? + // is it a variable ? if (pp->GivType() == TokenTypVar) { CBotToken pthis("this"); CBotVar* var = pStk->FindVar(pthis); - if ( var == 0 ) return pStack->Return(NULL, pStk); + if (var == 0) return pStack->Return(NULL, pStk); + + CBotInstr* inst = new CBotExprVar(); + + // this is an element of the current class + // adds the equivalent of this. before - 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 + ((CBotExprVar*)inst)->m_nIdent = -2; // ident for this CBotToken* pp = p; - if ( pp->GivType() == TokenTypVar ) // doit être un nom + if (pp->GivType() == TokenTypVar) { - if ( pp->GivNext()->GivType() == ID_OPENPAR ) // un appel de méthode ? + if (pp->GivNext()->GivType() == ID_OPENPAR) // a method call? { CBotInstr* i = CBotInstrMethode::Compile(pp, pStk, var); - if ( pStk->IsOk() ) + if (pStk->IsOk()) { - inst->AddNext3(i); // ajoute à la suite - p = pp; // instructions passées + inst->AddNext3(i); // add after + p = pp; // previous instruction return pStack->Return(inst, pStk); } - pStk->SetError(0,0); // l'erreur n'est pas traitée ici + pStk->SetError(0,0); // the error is not adressed here } } delete inst; @@ -3272,77 +3225,71 @@ CBotInstr* CBotExprVar::CompileMethode(CBotToken* &p, CBotCStack* pStack) } -// exécute, rend la valeur d'une variable +// execute, making the value of a variable bool CBotExprVar::Execute(CBotStack* &pj) { CBotVar* pVar = NULL; CBotStack* pile = pj->AddStack(this); -// if ( pile == EOX ) return true; - -// if ( pile->IfStep() ) return false; CBotStack* pile1 = pile; - if ( pile1->GivState() == 0 ) + 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 (!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 + if (pVar) pile1->SetCopyVar(pVar); // place a copy on the stack else { -//-- pile1->SetVar(NULL); // la pile contient déjà le resultat (méthode) return pj->Return(pile1); } pile1->IncState(); } - pVar = pile1->GivVar(); // récupère si interrompu + pVar = pile1->GivVar(); - if ( pVar == NULL ) + if (pVar == NULL) { -// pile1->SetError(TX_NULLPT, &m_token); return pj->Return(pile1); } - if ( pVar->GivInit() == IS_UNDEF ) + if (pVar->GivInit() == IS_UNDEF) { CBotToken* pt = &m_token; - while ( pt->GivNext() != NULL ) pt = pt->GivNext(); + while (pt->GivNext() != NULL) pt = pt->GivNext(); pile1->SetError(TX_NOTINIT, pt); return pj->Return(pile1); } - return pj->Return(pile1); // opération faite + return pj->Return(pile1); // operation completed } void CBotExprVar::RestoreState(CBotStack* &pj, bool bMain) { - if ( !bMain ) return; + if (!bMain) return; CBotStack* pile = pj->RestoreStack(this); - if ( pile == NULL ) return; + if (pile == NULL) return; CBotStack* pile1 = pile; - if ( pile1->GivState() == 0 ) + if (pile1->GivState() == 0) { - RestoreStateVar(pile, bMain); // récupère la variable selon champs et index + 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) { CBotStack* pile = pj; - pj = pj->AddStack( this ); + 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 ) + pVar = pj->FindVar(m_nIdent, true); // tries with the variable update if necessary + if (pVar == NULL) { #ifdef _DEBUG ASM_TRAP(); @@ -3352,61 +3299,60 @@ bool CBotExprVar::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToke } if ( m_next3 != NULL && !m_next3->ExecuteVar(pVar, pj, &m_token, bStep, false) ) - return false; // Champs d'une instance, tableau, méthode ? + 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) { - pj = pj->RestoreStack( this ); - if ( pj == NULL ) return; + pj = pj->RestoreStack(this); + if (pj == NULL) return; - if ( m_next3 != NULL ) + 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 + CBotInstr* ret = NULL; // to return to the list -// pStack->SetStartError(p->GivStart()); CBotCStack* pile = pStack; int i = 0; - if ( IsOfType(p, ID_OPENPAR) ) + 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 + pile = pile->TokenStack(); // keeps the result on the stack - if ( first ) pStack->SetStartError(start); + if (first) pStack->SetStartError(start); first = false; CBotInstr* param = CBotExpression::Compile(p, pile); end = p->GivStart(); - if ( !pile->IsOk() ) + if (!pile->IsOk()) { return pStack->Return(NULL, pile); } - if ( ret == NULL ) ret = param; - else ret->AddNext(param); // construit la liste + if (ret == NULL) ret = param; + else ret->AddNext(param); // construct the list - if ( param != NULL ) + if (param != NULL) { - if ( pile->GivTypResult().Eq(99) ) + if (pile->GivTypResult().Eq(99)) { delete pStack->TokenStack(); pStack->SetError(TX_VOID, p->GivStart()); @@ -3416,7 +3362,7 @@ CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars) ppVars[i]->GivToken()->SetPos(start, end); i++; - if (IsOfType(p, ID_COMMA)) continue; // saute la virgule + if (IsOfType(p, ID_COMMA)) continue; // skips the comma if (IsOfType(p, ID_CLOSEPAR)) break; } @@ -3433,13 +3379,12 @@ CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars) ////////////////////////////////////////////////////////////////////////////////////// -// compile un appel d'une méthode +// compile a method call CBotInstrMethode::CBotInstrMethode() { m_Parameters = NULL; m_MethodeIdent = 0; -// m_nThisIdent = 0; name = "CBotInstrMethode"; } @@ -3451,30 +3396,28 @@ CBotInstrMethode::~CBotInstrMethode() CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* var) { CBotInstrMethode* inst = new CBotInstrMethode(); - inst->SetToken(p); // token correspondant - -// inst->m_nThisIdent = CBotVar::NextUniqNum(); + inst->SetToken(p); // corresponding token - if ( NULL != var ) + if (NULL != var) { CBotToken* pp = p; p = p->GivNext(); - if ( p->GivType() == ID_OPENPAR ) + if (p->GivType() == ID_OPENPAR) { inst->m_NomMethod = pp->GivString(); - // compile la liste des paramètres + // compiles the list of parameters CBotVar* ppVars[1000]; inst->m_Parameters = CompileParams(p, pStack, ppVars); - if ( pStack->IsOk() ) + if (pStack->IsOk()) { - CBotClass* pClass = var->GivClass(); // pointeur à la classe - inst->m_ClassName = pClass->GivName(); // le nom de la classe + 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(); // libères les paramètres encore sur la pile + delete pStack->TokenStack(); // release parameters on the stack inst->m_typRes = r; if (inst->m_typRes.GivType() > 20) @@ -3483,13 +3426,12 @@ CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* delete inst; return NULL; } - // met un résultat sur la pile pour avoir quelque chose + // 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)) { -// CBotClass* pClass = CBotClass::Find(inst->m_RetClassName); pResult->SetClass(inst->m_typRes.GivClass()); } pStack->SetVar(pResult); @@ -3500,39 +3442,36 @@ CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* return NULL; } } - pStack->SetError( 1234, p ); + pStack->SetError(1234, p); delete inst; return NULL; } -// exécute l'appel de méthode +// 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); // une place pour la copie de This -// if ( pile1 == EOX ) return true; + CBotStack* pile1 = pj->AddStack(this, true); // a place for the copy of This -// DEBUG( "CBotInstrMethode::ExecuteVar", 0, pj ); - - if ( pVar->GivPointer() == NULL ) + if (pVar->GivPointer() == NULL) { - pj->SetError( TX_NULLPT, prevToken ); + pj->SetError(TX_NULLPT, prevToken); } - if ( pile1->IfStep() ) return false; + if (pile1->IfStep()) return false; - CBotStack* pile2 = pile1->AddStack(); // et pour les paramètres à venir + CBotStack* pile2 = pile1->AddStack(); // for the next parameters 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 !! + // 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(m_nThisIdent); pThis->SetUniqNum(-2); pile1->AddVar(pThis); pile1->IncState(); @@ -3540,18 +3479,19 @@ bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre 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 ) + // 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 (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 + if (!p->Execute(pile2)) return false; // interrupted here? + if (!pile2->SetState(1)) return false; // special mark to recognize parameters } - ppVars[i++] = pile2->GivVar(); // construit la liste des pointeurs - pile2 = pile2->AddStack(); // de la place sur la pile pour les résultats + 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; } @@ -3563,51 +3503,50 @@ bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre 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 + pResult, pile2, GivToken())) return false; if (pRes != pResult) delete pRes; - pVar = NULL; // ne retourne pas une valeur par cela - return pj->Return(pile2); // libère toute la pile + 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; + if (!bMain) return; CBotVar* ppVars[1000]; - CBotStack* pile1 = pile->RestoreStack(this); // une place pour la copie de This - if ( pile1 == NULL ) return; + CBotStack* pile1 = pile->RestoreStack(this); // place for the copy of This + if (pile1 == NULL) return; - CBotStack* pile2 = pile1->RestoreStack(); // et pour les paramètres à venir - if ( pile2 == NULL ) return; + CBotStack* pile2 = pile1->RestoreStack(); // and for the parameters coming + 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 ) + // 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 (pile2->GivState() == 0) { - p->RestoreState(pile2, true); // interrompu ici ! + p->RestoreState(pile2, true); // interrupted here! return; } - ppVars[i++] = pile2->GivVar(); // construit la liste des pointeurs + ppVars[i++] = pile2->GivVar(); // construct the list of pointers pile2 = pile2->RestoreStack(); - if ( pile2 == NULL ) return; + if (pile2 == NULL) return; p = p->GivNext(); if ( p == NULL) break; @@ -3627,19 +3566,18 @@ void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, bool bMain) 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; + CBotStack* pile1 = pj->AddStack(this, true); // place for the copy of This - if ( pile1->IfStep() ) return false; + if (pile1->IfStep()) return false; - CBotStack* pile2 = pile1->AddStack(); // et pour les paramètres à venir + CBotStack* pile2 = pile1->AddStack(); // and for the parameters coming 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 !! + // 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(); @@ -3647,18 +3585,18 @@ bool CBotInstrMethode::Execute(CBotStack* &pj) 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 ) + // 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 (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 + if (!p->Execute(pile2)) return false; // interrupted here? + if (!pile2->SetState(1)) return false; // special mark to recognize parameters } - ppVars[i++] = pile2->GivVar(); // construit la liste des pointeurs - pile2 = pile2->AddStack(); // de la place sur la pile pour les résultats + 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; } @@ -3670,35 +3608,33 @@ bool CBotInstrMethode::Execute(CBotStack* &pj) 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 + pResult, pile2, GivToken())) return false; // interupted - // met la nouvelle valeur de this à la place de l'ancienne variable + // 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); // libère toute la pile + 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; } CBotNew::~CBotNew() @@ -3708,9 +3644,9 @@ CBotNew::~CBotNew() CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack) { CBotToken* pp = p; - if ( !IsOfType(p, ID_NEW) ) return NULL; + if (!IsOfType(p, ID_NEW)) return NULL; - // vérifie que le token est un nom de classe + // verifies that the token is a class name if (p->GivType() != TokenTypVar) return NULL; CBotClass* pClass = CBotClass::Find(p); @@ -3719,11 +3655,6 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack) 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); @@ -3731,28 +3662,26 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack) inst->m_vartoken = p; p = p->GivNext(); - // crée l'objet sur le "tas" - // avec un pointeur sur cet objet + // creates the object on the "job" + // with a pointer to the object CBotVar* pVar = CBotVar::Create("", pClass); -// inst->m_nThisIdent = CBotVar::NextUniqNum(); - // fait l'appel du créateur + // do the call of the creator CBotCStack* pStk = pStack->TokenStack(); { - // regarde s'il y a des paramètres + // check if there are parameters CBotVar* ppVars[1000]; inst->m_Parameters = CompileParams(p, pStk, ppVars); - if ( !pStk->IsOk() ) goto error; + if (!pStk->IsOk()) goto error; - // le constructeur existe-il ? -// CBotString noname; + // constructor exist? CBotTypResult r = pClass->CompileMethode(pClass->GivName(), pVar, ppVars, pStk, inst->m_nMethodeIdent); - delete pStk->TokenStack(); // libère le supplément de pile + delete pStk->TokenStack(); // release extra stack 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 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) { @@ -3760,14 +3689,14 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack) goto error; } - // si le constructeur n'existe pas, mais qu'il y a des paramètres + // 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; } - // rend le pointeur à l'objet sur la pile + // makes pointer to the object on the stack pStk->SetVar(pVar); return pStack->Return(inst, pStk); } @@ -3776,47 +3705,46 @@ error: return pStack->Return(NULL, pStk); } -// exécute une instruction "new" +// executes instruction "new" 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; 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 + // 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 ) ; + pThis->SetUniqNum(-2) ; - pile1->SetVar(pThis); // la place sur la pile1 + pile1->SetVar(pThis); // place on stack1 pile->IncState(); } - // retrouve le pointeur this si on a été interrompu + // fetch the this pointer if it was interrupted if ( pThis == NULL) { - pThis = pile1->GivVar(); // retrouve le pointeur + pThis = pile1->GivVar(); // find the pointer } - // y a-t-il une assignation ou des paramètres (constructeur) + // is there an assignment or parameters (constructor) if ( pile->GivState()==1) - { - // évalue le constructeur de l'instance + { + // evaluates the constructor of the instance CBotVar* ppVars[1000]; CBotStack* pile2 = pile; @@ -3824,16 +3752,16 @@ bool CBotNew::Execute(CBotStack* &pj) 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 + // evaluate the parameters + // and places the values on the stack + // to be interrupted at any time - 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 ) + pile2 = pile2->AddStack(); // space on the stack for the result + if (pile2->GivState() == 0) { - if (!p->Execute(pile2)) return false; // interrompu ici ? + if (!p->Execute(pile2)) return false; // interrupted here? pile2->SetState(1); } ppVars[i++] = pile2->GivVar(); @@ -3842,49 +3770,45 @@ bool CBotNew::Execute(CBotStack* &pj) } ppVars[i] = NULL; - // crée une variable pour le résultat - CBotVar* pResult = NULL; // constructeurs toujours void + // create a variable for the result + CBotVar* pResult = NULL; // constructos still void if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GivName(), pThis, ppVars, - pResult, pile2, GivToken())) return false; // interrompu - - pThis->ConstructorSet(); // signale que le constructeur a été appelé -// pile->Return(pile2); // libère un bout de pile + 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) { - 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); - // crée la variable "this" de type pointeur à l'objet + // create the variable "this" pointer type to the object 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) + // is ther an assignment or parameters (constructor) if ( pile->GivState()==1) - { - // évalue le constructeur de l'instance + { + // evaluates the constructor of the instance CBotVar* ppVars[1000]; CBotStack* pile2 = pile; @@ -3892,18 +3816,18 @@ void CBotNew::RestoreState(CBotStack* &pj, bool bMain) 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 + // evaluate the parameters + // and places the values on the stack + // to be interrupted at any time - 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; + pile2 = pile2->RestoreStack(); // space on the stack for the result + if (pile2 == NULL) return; - if ( pile2->GivState() == 0 ) + if (pile2->GivState() == 0) { - p->RestoreState(pile2, bMain); // interrompu ici ! + p->RestoreState(pile2, bMain); // interrupt here! return; } ppVars[i++] = pile2->GivVar(); @@ -3913,28 +3837,28 @@ void CBotNew::RestoreState(CBotStack* &pj, bool bMain) ppVars[i] = NULL; pClass->RestoreMethode(m_nMethodeIdent, m_vartoken.GivString(), pThis, - ppVars, pile2) ; // interrompu ici ! + 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 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 + // 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 (max >= CBotTypBoolean) { if ( (op == ID_EQ || op == ID_NE) && (t1 == CBotTypPointer && t2 == CBotTypNullPointer)) return true; @@ -3954,8 +3878,9 @@ bool TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op ) 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 + // accept the case in reverse + // the transaction will be denied at runtime if the pointer is not + // compatible } return true; @@ -3966,28 +3891,28 @@ bool TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op ) 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(); - 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; - if ( max == 99 ) return false; // un résultat est void ? + if (max == 99) return false; // result is void? - if ( max >= CBotTypBoolean ) + if (max >= CBotTypBoolean) { - if ( t2 != t1 ) return false; + if (t2 != t1) return false; - if ( max == CBotTypArrayPointer ) + if (max == CBotTypArrayPointer) return TypesCompatibles(type1.GivTypElem(), type2.GivTypElem()); - if ( max == CBotTypClass || max == CBotTypPointer ) + if (max == CBotTypClass || max == CBotTypPointer) return type1.GivClass() == type2.GivClass() ; return true ; @@ -3997,10 +3922,11 @@ bool TypesCompatibles( const CBotTypResult& type1, const CBotTypResult& type2 ) ///////////////////////////////////////////////////////////////////////////////////// -// 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) { @@ -4035,34 +3961,3 @@ size_t fRead(void *buffer, size_t length, FILE* 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 6f18be8..d618131 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -13,50 +13,50 @@ // * // * 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"); +#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) {...} @@ -65,139 +65,232 @@ class CBotRepeat; // repeat (nb) {...} //////////////////////////////////////////////////////////////////////// // actually, externally, the only thing he can do -// this is to create an instance of a stack +// 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 @@ -214,7 +307,7 @@ inline int CBotStack::GivState() inline int CBotStack::GivError() { - return m_error; + return m_error; } //////////////////////////////////////////////////////////////////////// @@ -225,70 +318,70 @@ 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); }; @@ -300,105 +393,104 @@ extern bool SaveVar(FILE* pf, CBotVar* pVar); class CBotInstr { private: - static - CBotStringArray - m_labelLvl; + static + CBotStringArray + m_labelLvl; protected: - CBotToken m_token; // keeps the token - CBotString name; // debug - CBotInstr* m_next; // linked command - CBotInstr* m_next2b; // second list definition chain - CBotInstr* m_next3; // third list for indices and fields - CBotInstr* m_next3b; // necessary for reporting tables + CBotToken m_token; // keeps the token + CBotString name; // debug + CBotInstr* m_next; // linked command + CBotInstr* m_next2b; // second list definition chain + CBotInstr* m_next3; // third list for indices and fields + CBotInstr* m_next3b; // necessary for reporting tables /* - for example, the following program - int x[]; x[1] = 4; - int y[x[1]][10], z; + 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->... + 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); - 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 @@ -430,144 +522,144 @@ public: 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); }; @@ -576,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); }; @@ -606,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 @@ -624,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); }; @@ -646,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 @@ -669,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); }; @@ -687,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 @@ -704,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 @@ -721,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 @@ -743,8 +835,8 @@ private: public: - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + static + CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); }; @@ -754,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); }; @@ -774,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 @@ -793,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 @@ -814,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); }; @@ -864,8 +956,8 @@ class CBotBoolExpr : public CBotInstr private: public: - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + static + CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); }; @@ -878,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 @@ -901,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); }; @@ -921,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); }; @@ -932,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 @@ -968,25 +1060,25 @@ 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 for the variable name @@ -994,53 +1086,53 @@ public: 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); }; @@ -1048,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); }; @@ -1067,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); }; @@ -1082,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 @@ -1094,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 @@ -1124,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); }; @@ -1146,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); }; @@ -1215,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); }; @@ -1256,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); }; @@ -1312,59 +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* 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(); }; @@ -1372,68 +1464,68 @@ 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); }; @@ -1455,7 +1547,7 @@ 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 @@ -1465,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 @@ -1517,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 @@ -1549,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(); }; @@ -1577,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(); - 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/CBotDll.h b/src/CBot/CBotDll.h index 514146f..f2e2297 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -49,20 +49,17 @@ class CBotCStack; // stack // 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, - CBotTypByte = 1, - CBotTypShort = 2, - CBotTypChar = 3, + CBotTypByte = 1, //n + CBotTypShort = 2, //n + CBotTypChar = 3, //n CBotTypInt = 4, - CBotTypLong = 5, + CBotTypLong = 5, //n CBotTypFloat = 6, - CBotTypDouble = 7, + CBotTypDouble = 7, //n CBotTypBoolean = 8, CBotTypString = 9, @@ -74,71 +71,79 @@ enum CBotType 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 - CBotTypResult(int type); - // 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(); + /** + * \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 + // rend le type CBotTyp* du résultat void SetType(int n); - // modifie le type + // modifie le type CBotClass* GivClass() const; - // rend le pointeur à la classe (pour les CBotTypClass, CBotTypPointer) + // rend le pointeur à la classe (pour les CBotTypClass, CBotTypPointer) int GivLimite() const; - // rend la taille limite du tableau (CBotTypArray) + // rend la taille limite du tableau (CBotTypArray) void SetLimite(int n); - // fixe une limite au tableau + // fixe une limite au tableau void SetArray(int* max ); - // idem avec une liste de dimension (tableaux de tableaux) + // idem avec une liste de dimension (tableaux de tableaux) CBotTypResult& GivTypElem() const; - // rend le type des éléments du tableau (CBotTypArray) + // rend le type des éléments du tableau (CBotTypArray) bool Compare(const CBotTypResult& typ) const; - // compare si les types sont compatibles + // compare si les types sont compatibles bool Eq(int type) const; - // compare le type + // compare le type CBotTypResult& - operator=(const CBotTypResult& src); - // copie un type complet dans un autre + 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; }; /* @@ -236,11 +241,12 @@ 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: @@ -303,7 +309,7 @@ private: int m_lg; /** \brief Keeps the string corresponding to keyword ID */ - static const std::map s_keywordString; + static const std::map s_keywordString; /** * \brief MapIdToString maps given ID to its string equivalent diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp index 784e647..363b939 100644 --- a/src/CBot/CBotFunction.cpp +++ b/src/CBot/CBotFunction.cpp @@ -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,7 +1390,6 @@ 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 @@ -1627,12 +1625,10 @@ 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 ) ) diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 291a1e5..419798f 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -14,10 +14,7 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/.////////////////////////////////////////////////////////////////////// -/** - * \file CBotStack.cpp - * \brief Management of the stack - */ +//Management of the stack #include "CBot.h" @@ -25,7 +22,7 @@ #include -#define ITIMER 100 +#define ITIMER 100 //////////////////////////////////////////////////////////////////////////// // gestion de la pile d'exécution @@ -40,202 +37,202 @@ 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) { - // constructor must exist or the destructor is never called! + // 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) { - 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) { - 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) { - 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() { - return m_bBlock; + return m_bBlock; } 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) { - 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() { - if (!m_bOver) return false; - m_error = TX_STACKOVER; - return true; + if (!m_bOver) return false; + m_error = TX_STACKOVER; + return true; } #else @@ -246,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) { - 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) { - 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) { - 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) { - 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() { - 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; } @@ -365,20 +362,20 @@ 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; } @@ -386,181 +383,173 @@ CBotStack* CBotStack::RestoreStackEOX(CBotCall* instr) // routine pour l'exécution pas à pas 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) { - 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) { - 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) { - 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) { - 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; -} - -// retrouve une variable sur la pile selon son numéro d'identification -// ce qui va plus vite que de comparer les noms. + 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; +} 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) { - CBotToken* pt = &Token; - return FindVar(pt, bUpdate, bModif); + CBotToken* pt = &Token; + return FindVar(pt, bUpdate, bModif); } 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; } @@ -568,120 +557,120 @@ 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) { - 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() { - 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(); } @@ -689,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) { - 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) { - 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) { - 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) { - 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 - - return m_next->SaveState(pf); // enregistre la suite + 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 + + return m_next->SaveState(pf); // enregistre la suite } bool CBotStack::RestoreState(FILE* pf, CBotStack* &pStack) { - unsigned short 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 +{ + 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 - } +{ + 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) { - 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) { - 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) { - 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) { - 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) { - 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) { - unsigned short w, wi, prv, st; - float ww; - CBotString name, s; - - delete pVar; - - 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; - - 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 - } - - if ( w == CBotTypClass ) w = CBotTypIntrinsic; // forcément intrinsèque - - if (!ReadWord(pf, wi)) return false; // init ? - - if (!ReadString(pf, name)) return false; // nom de la variable - - 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; - - // 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) ; - - 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; - - 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; + unsigned short w, wi, prv, st; + float ww; + CBotString name, s; + + delete pVar; + + 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; + + 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 + } + + if ( w == CBotTypClass ) w = CBotTypIntrinsic; // forcément intrinsèque + + if (!ReadWord(pf, wi)) return false; // init ? + + if (!ReadString(pf, name)) return false; // nom de la variable + + 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; + + // 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) ; + + 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; + + 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; } @@ -1123,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) @@ -1135,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) { - 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 @@ -1262,40 +1251,40 @@ 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() @@ -1306,100 +1295,100 @@ 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) { - 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 } @@ -1407,76 +1396,76 @@ void CBotCStack::AddVar(CBotVar* pVar) 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; + 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 33e1d04..9d5d257 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -23,7 +23,7 @@ #include //Map is filled with id-string pars that are needed for CBot language parsing -const std::map CBotString::s_keywordString = +const std::map CBotString::s_keywordString = { {ID_IF, "if"}, {ID_ELSE, "else"}, @@ -113,9 +113,9 @@ const std::map CBotString::s_keywordString = {ID_MODULO, "%"}, {ID_POWER, "**"}, {ID_ASSMODULO, "%="}, + {ID_SUPER, "super"}, {TX_UNDEF, "undefined"}, - {TX_NAN, "not a number"}, - {ID_SUPER, "super"} + {TX_NAN, "not a number"} }; CBotString::CBotString() diff --git a/src/CBot/CBotVar.cpp b/src/CBot/CBotVar.cpp index 79ba021..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 = (const char*) m_token->GivString(); - CBotString s = (const char*) GivValString(); - const char* v = (const char*) 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) { - // 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) { -/* 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(int bInit) { - 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(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(); - } - } + 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(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) { - ASM_TRAP(); - return NULL; + ASM_TRAP(); + return NULL; } // dit si une variable appartient à une classe donnée 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 + 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; + m_bStatic = bStatic; } void CBotVar::SetPrivate(int mPrivate) { - m_mPrivate = mPrivate; + m_mPrivate = mPrivate; } bool CBotVar::IsStatic() { - return m_bStatic; + return m_bStatic; } 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,174 +663,174 @@ 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) { - ASM_TRAP(); - return false; + ASM_TRAP(); + return false; } bool CBotVar::Hi(CBotVar* left, CBotVar* right) { - ASM_TRAP(); - return false; + ASM_TRAP(); + return false; } bool CBotVar::Ls(CBotVar* left, CBotVar* right) { - ASM_TRAP(); - return false; + ASM_TRAP(); + return false; } bool CBotVar::Hs(CBotVar* left, CBotVar* right) { - ASM_TRAP(); - return false; + ASM_TRAP(); + return false; } bool CBotVar::Eq(CBotVar* left, CBotVar* right) { - ASM_TRAP(); - return false; + ASM_TRAP(); + return false; } 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) { - 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 } */ @@ -839,19 +839,19 @@ void CBotVar::SetIndirection(CBotVar* pVar) // copie une variable dans une autre 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,189 +859,189 @@ 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) { - return left->GivValInt() < right->GivValInt(); + return left->GivValInt() < right->GivValInt(); } bool CBotVarInt::Hi(CBotVar* left, CBotVar* right) { - return left->GivValInt() > right->GivValInt(); + return left->GivValInt() > right->GivValInt(); } bool CBotVarInt::Ls(CBotVar* left, CBotVar* right) { - return left->GivValInt() <= right->GivValInt(); + return left->GivValInt() <= right->GivValInt(); } bool CBotVarInt::Hs(CBotVar* left, CBotVar* right) { - return left->GivValInt() >= right->GivValInt(); + return left->GivValInt() >= right->GivValInt(); } bool CBotVarInt::Eq(CBotVar* left, CBotVar* right) { - return left->GivValInt() == right->GivValInt(); + return left->GivValInt() == right->GivValInt(); } bool CBotVarInt::Ne(CBotVar* left, CBotVar* right) { - return left->GivValInt() != right->GivValInt(); + return left->GivValInt() != right->GivValInt(); } @@ -1050,19 +1050,19 @@ bool CBotVarInt::Ne(CBotVar* left, CBotVar* right) // copie une variable dans une autre 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,139 +1070,139 @@ 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) { - return left->GivValFloat() < right->GivValFloat(); + return left->GivValFloat() < right->GivValFloat(); } bool CBotVarFloat::Hi(CBotVar* left, CBotVar* right) { - return left->GivValFloat() > right->GivValFloat(); + return left->GivValFloat() > right->GivValFloat(); } bool CBotVarFloat::Ls(CBotVar* left, CBotVar* right) { - return left->GivValFloat() <= right->GivValFloat(); + return left->GivValFloat() <= right->GivValFloat(); } bool CBotVarFloat::Hs(CBotVar* left, CBotVar* right) { - return left->GivValFloat() >= right->GivValFloat(); + return left->GivValFloat() >= right->GivValFloat(); } bool CBotVarFloat::Eq(CBotVar* left, CBotVar* right) { - return left->GivValFloat() == right->GivValFloat(); + return left->GivValFloat() == right->GivValFloat(); } bool CBotVarFloat::Ne(CBotVar* left, CBotVar* right) { - return left->GivValFloat() != right->GivValFloat(); + return left->GivValFloat() != right->GivValFloat(); } @@ -1211,19 +1211,19 @@ bool CBotVarFloat::Ne(CBotVar* left, CBotVar* right) // copie une variable dans une autre 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,77 +1231,77 @@ 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) { - return left->GivValInt() == right->GivValInt(); + return left->GivValInt() == right->GivValInt(); } bool CBotVarBoolean::Ne(CBotVar* left, CBotVar* right) { - return left->GivValInt() != right->GivValInt(); + return left->GivValInt() != right->GivValInt(); } ////////////////////////////////////////////////////////////////////////////////////// @@ -1309,82 +1309,82 @@ bool CBotVarBoolean::Ne(CBotVar* left, CBotVar* right) // copie une variable dans une autre 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) { - return (left->GivValString() == right->GivValString()); + return (left->GivValString() == right->GivValString()); } bool CBotVarString::Ne(CBotVar* left, CBotVar* right) { - return (left->GivValString() != right->GivValString()); + return (left->GivValString() != right->GivValString()); } bool CBotVarString::Lo(CBotVar* left, CBotVar* right) { - return (left->GivValString() == right->GivValString()); + return (left->GivValString() == right->GivValString()); } bool CBotVarString::Hi(CBotVar* left, CBotVar* right) { - return (left->GivValString() == right->GivValString()); + return (left->GivValString() == right->GivValString()); } bool CBotVarString::Ls(CBotVar* left, CBotVar* right) { - return (left->GivValString() == right->GivValString()); + return (left->GivValString() == right->GivValString()); } bool CBotVarString::Hs(CBotVar* left, CBotVar* right) { - return (left->GivValString() == right->GivValString()); + return (left->GivValString() == right->GivValString()); } @@ -1393,177 +1393,177 @@ bool CBotVarString::Hs(CBotVar* left, CBotVar* right) // copie une variable dans une autre 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) { -/* 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 @@ -1571,145 +1571,145 @@ CBotVar* CBotVarClass::GivItemRef(int nIdent) 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) { - 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) { - 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) { - 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) { - 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) { - 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) { -/* 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) { - 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) { - 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) { - 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) { - 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 { - 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 { - 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/resource.h b/src/CBot/resource.h index f82fb9c..6bf48e1 100644 --- a/src/CBot/resource.h +++ b/src/CBot/resource.h @@ -13,8 +13,6 @@ // * // * 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 #ifndef _RESOURCE_H_ #define _RESOURCE_H_ -- cgit v1.2.3-1-g7c22