summaryrefslogtreecommitdiffstats
path: root/src/CBot
diff options
context:
space:
mode:
authorZaba999 <zaba.marcin@gmail.com>2012-07-10 22:58:52 +0200
committerZaba999 <zaba.marcin@gmail.com>2012-07-10 22:58:52 +0200
commit1910219518afb26edf7329e0945b9ddba8061a08 (patch)
tree57e72fa1803ab58358cab01055d883aa2fc32e60 /src/CBot
parentdbd62c96aa351dc1c21e3392348edda2eb012e09 (diff)
downloadcolobot-1910219518afb26edf7329e0945b9ddba8061a08.tar.gz
colobot-1910219518afb26edf7329e0945b9ddba8061a08.tar.bz2
colobot-1910219518afb26edf7329e0945b9ddba8061a08.zip
Dependency on WINAPI completely removed.
Diffstat (limited to 'src/CBot')
-rw-r--r--src/CBot/CBot.cpp5201
-rw-r--r--src/CBot/CBot.rc279
-rw-r--r--src/CBot/CBotDll.h1677
-rw-r--r--src/CBot/CBotStack.cpp7
-rw-r--r--src/CBot/CBotString.cpp710
-rw-r--r--src/CBot/CBotToken.cpp1
-rw-r--r--src/CBot/CMakeLists.txt1
-rw-r--r--src/CBot/resource.h204
8 files changed, 3876 insertions, 4204 deletions
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();
+int CBotInstr::m_LoopLvl = 0;
+CBotStringArray CBotInstr::m_labelLvl = CBotStringArray();
-// ajoute un niveau avec un label
+// adds a level with a label
void CBotInstr::IncLvl(CBotString& label)
{
- m_labelLvl.SetSize(m_LoopLvl+1);
- m_labelLvl[m_LoopLvl] = label;
- m_LoopLvl++;
+ m_labelLvl.SetSize(m_LoopLvl+1);
+ m_labelLvl[m_LoopLvl] = label;
+ m_LoopLvl++;
}
-// ajoute un niveau (instruction switch)
+// adds a level (switch statement)
void CBotInstr::IncLvl()
{
- m_labelLvl.SetSize(m_LoopLvl+1);
- m_labelLvl[m_LoopLvl] = "#SWITCH";
- m_LoopLvl++;
+ m_labelLvl.SetSize(m_LoopLvl+1);
+ m_labelLvl[m_LoopLvl] = "#SWITCH";
+ m_LoopLvl++;
}
-// libère un niveau
+// free a level
void CBotInstr::DecLvl()
{
- m_LoopLvl--;
- m_labelLvl[m_LoopLvl].Empty();
+ m_LoopLvl--;
+ m_labelLvl[m_LoopLvl].Empty();
}
-// controle la validité d'un break ou continu
+// 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);
- 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;
+ 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;
+ }
+
+ // 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;
-
- CBotCStack* pStk = pStack->TokenStack(pp);
+ 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;
- CBotExprUnaire* inst = new CBotExprUnaire();
- inst->SetToken(pp);
+ CBotCStack* pStk = pStack->TokenStack(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);
+ CBotExprUnaire* inst = new CBotExprUnaire();
+ inst->SetToken(pp);
- 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 <windows.h>
#include <stdio.h>
+#include "resource.h"
+#include <map>
+#include <cstring>
-// #define DllExport __declspec( dllexport )
-#define CBOTVERSION 104
+#define CBOTVERSION 104
////////////////////////////////////////////////////////////////////////
-// quelques classes définies par ailleurs
-
-class CBotToken; // programme transformé en "jetons"
-class CBotStack; // pile pour l'exécution
-class CBotClass; // classe d'object
-class CBotInstr; // instruction à exécuter
-class CBotFunction; // les fonctions user
-class CBotVar; // les variables
-class CBotVarClass; // une instance de classe
-class CBotVarPointer; // pointeur à une instance de classe
-class CBotCall; // les fonctions
-class CBotCallMethode; // les méthodes
-class CBotDefParam; // liste de paramètres
-class CBotCStack;
+// forward declaration of needed classes
+
+class CBotToken; // program turned into "tokens
+class CBotStack; // for the execution stack
+class CBotClass; // class of object
+class CBotInstr; // instruction to be executed
+class CBotFunction; // user functions
+class CBotVar; // variables
+class CBotVarClass; // instance of class
+class CBotVarPointer; // pointer to an instance of class
+class CBotCall; // fonctions
+class CBotCallMethode; // methods
+class CBotDefParam; // parameter list
+class CBotCStack; // stack
////////////////////////////////////////////////////////////////////////
-// Gestion des variables
+// Variables management
////////////////////////////////////////////////////////////////////////
// ces types sont calqués sur les types Java
// ne pas changer l'ordre de ces types
+/** \brief CBotType Defines known types. This types are modeled on Java types. Do not change the order of elements */
enum CBotType
{
- CBotTypVoid = 0, // fonction retournant void
- CBotTypByte = 1, //n // nombre entier ( 8 bits)
- CBotTypShort = 2, //n // nombre entier (16 bits)
- CBotTypChar = 3, //n // caractère "unicode" (16 bits)
- CBotTypInt = 4, // nombre entier (32 bits)
- CBotTypLong = 5, //n // nombre entier (64 bits)
- CBotTypFloat = 6, // nombre décimal (32 bits)
- CBotTypDouble = 7, //n // nombre décimal (64 bits)
- CBotTypBoolean = 8, // true ou false exclusivement
- CBotTypString = 9, // chaine de caractère
-
- CBotTypArrayPointer = 10, // un tableau de variables
- CBotTypArrayBody = 11, // idem mais crée l'instance
-
- CBotTypPointer = 12, // pointeur à une instance
- CBotTypNullPointer = 13, // pointeur null est spécial
-
- CBotTypClass = 15, // instance d'une classe
- CBotTypIntrinsic = 16 // instance d'une classe intrinsèque
+ CBotTypVoid = 0,
+ CBotTypByte = 1,
+ 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<EID, const char const *> 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 <cstdlib>
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 <cstdlib>
#include <cstring>
#include <algorithm>
-/// 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<EID, const char const *> 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_
+