2012-03-19 11:44:39 +00:00
|
|
|
|
// * This file is part of the COLOBOT source code
|
2012-03-09 16:08:05 +00:00
|
|
|
|
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
|
|
|
|
// *
|
|
|
|
|
// * This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// * it under the terms of the GNU General Public License as published by
|
|
|
|
|
// * the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// * (at your option) any later version.
|
|
|
|
|
// *
|
|
|
|
|
// * This program is distributed in the hope that it will be useful,
|
|
|
|
|
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// * GNU General Public License for more details.
|
|
|
|
|
// *
|
|
|
|
|
// * You should have received a copy of the GNU General Public License
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// * along with this program. If not, see http://www.gnu.org/licenses/.///////////////////////////////////////////////////////////////////////
|
2012-07-02 19:41:24 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// compilation of various instructions
|
|
|
|
|
// compile all routines are static
|
|
|
|
|
// and return an object according to what was found as instruction
|
|
|
|
|
|
|
|
|
|
// compiler principle:
|
2012-07-02 19:41:24 +00:00
|
|
|
|
// compile the routines return an object of the class corresponding to the operation found
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// this is always a subclass of CBotInstr.
|
2012-07-02 19:41:24 +00:00
|
|
|
|
// (CBotInstr objects are never used directly)
|
|
|
|
|
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// 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
|
2012-07-02 19:41:24 +00:00
|
|
|
|
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "CBot.h"
|
|
|
|
|
|
|
|
|
|
CBotInstr::CBotInstr()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
name = "CBotInstr";
|
|
|
|
|
m_next = NULL;
|
|
|
|
|
m_next2b = NULL;
|
|
|
|
|
m_next3 = NULL;
|
|
|
|
|
m_next3b = NULL;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotInstr::~CBotInstr()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete m_next;
|
|
|
|
|
delete m_next2b;
|
|
|
|
|
delete m_next3;
|
|
|
|
|
delete m_next3b;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// counter of nested loops,
|
|
|
|
|
// to determine the break and continue valid
|
|
|
|
|
// list of labels used
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
int CBotInstr::m_LoopLvl = 0;
|
|
|
|
|
CBotStringArray CBotInstr::m_labelLvl = CBotStringArray();
|
|
|
|
|
|
|
|
|
|
// adds a level with a label
|
2012-03-08 18:32:05 +00:00
|
|
|
|
void CBotInstr::IncLvl(CBotString& label)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_labelLvl.SetSize(m_LoopLvl+1);
|
|
|
|
|
m_labelLvl[m_LoopLvl] = label;
|
|
|
|
|
m_LoopLvl++;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// adds a level (switch statement)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
void CBotInstr::IncLvl()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_labelLvl.SetSize(m_LoopLvl+1);
|
|
|
|
|
m_labelLvl[m_LoopLvl] = "#SWITCH";
|
|
|
|
|
m_LoopLvl++;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// free a level
|
2012-03-08 18:32:05 +00:00
|
|
|
|
void CBotInstr::DecLvl()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_LoopLvl--;
|
|
|
|
|
m_labelLvl[m_LoopLvl].Empty();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// control validity of break and continue
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotInstr::ChkLvl(const CBotString& label, int type)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotInstr::IsOfClass(CBotString n)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return name == n;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// database management class CBotInstr
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// set the token corresponding to the instruction
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
void CBotInstr::SetToken(CBotToken* p)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_token = *p;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// return the type of the token assicated with the instruction
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
int CBotInstr::GivTokenType()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return m_token.GivType();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// return associated token
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotToken* CBotInstr::GivToken()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return &m_token;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// adds the statement following the other
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
void CBotInstr::AddNext(CBotInstr* n)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotInstr* p = this;
|
|
|
|
|
while ( p->m_next != NULL ) p = p->m_next;
|
|
|
|
|
p->m_next = n;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CBotInstr::AddNext3(CBotInstr* n)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotInstr* p = this;
|
|
|
|
|
while ( p->m_next3 != NULL ) p = p->m_next3;
|
|
|
|
|
p->m_next3 = n;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CBotInstr::AddNext3b(CBotInstr* n)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotInstr* p = this;
|
|
|
|
|
while ( p->m_next3b != NULL ) p = p->m_next3b;
|
|
|
|
|
p->m_next3b = n;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// returns next statement
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotInstr* CBotInstr::GivNext()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return m_next;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotInstr* CBotInstr::GivNext3()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return m_next3;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotInstr* CBotInstr::GivNext3b()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return m_next3b;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// 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
|
|
|
|
|
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotToken* pp = p;
|
|
|
|
|
|
|
|
|
|
if ( p == NULL ) return NULL;
|
|
|
|
|
|
|
|
|
|
int type = p->GivType(); // what is the next token
|
|
|
|
|
|
|
|
|
|
// is it a lable?
|
|
|
|
|
if ( IsOfType( pp, TokenTypVar ) &&
|
|
|
|
|
IsOfType( pp, ID_DOTS ) )
|
|
|
|
|
{
|
|
|
|
|
type = pp->GivType();
|
|
|
|
|
// these instructions accept only lable
|
|
|
|
|
if (!IsOfTypeList( pp, ID_WHILE, ID_FOR, ID_DO, ID_REPEAT, 0 ))
|
|
|
|
|
{
|
|
|
|
|
pStack->SetError(TX_LABEL, pp->GivStart());
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// call routine corresponding to the compilation token found
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case ID_WHILE:
|
|
|
|
|
return CBotWhile::Compile(p, pStack);
|
|
|
|
|
|
|
|
|
|
case ID_FOR:
|
|
|
|
|
return CBotFor::Compile(p, pStack);
|
|
|
|
|
|
|
|
|
|
case ID_DO:
|
|
|
|
|
return CBotDo::Compile(p, pStack);
|
|
|
|
|
|
|
|
|
|
case ID_REPEAT:
|
|
|
|
|
return CBotRepeat::Compile(p, pStack);
|
|
|
|
|
|
|
|
|
|
case ID_BREAK:
|
|
|
|
|
case ID_CONTINUE:
|
|
|
|
|
return CBotBreak::Compile(p, pStack);
|
|
|
|
|
|
|
|
|
|
case ID_SWITCH:
|
|
|
|
|
return CBotSwitch::Compile(p, pStack);
|
|
|
|
|
|
|
|
|
|
case ID_TRY:
|
|
|
|
|
return CBotTry::Compile(p, pStack);
|
|
|
|
|
|
|
|
|
|
case ID_THROW:
|
|
|
|
|
return CBotThrow::Compile(p, pStack);
|
|
|
|
|
|
|
|
|
|
case ID_DEBUGDD:
|
|
|
|
|
return CBotStartDebugDD::Compile(p, pStack);
|
|
|
|
|
|
|
|
|
|
case ID_INT:
|
|
|
|
|
return CBotInt::Compile(p, pStack);
|
|
|
|
|
|
|
|
|
|
case ID_FLOAT:
|
|
|
|
|
return CBotFloat::Compile(p, pStack);
|
|
|
|
|
|
|
|
|
|
case ID_STRING:
|
|
|
|
|
return CBotIString::Compile(p, pStack);
|
|
|
|
|
|
|
|
|
|
case ID_BOOLEAN:
|
|
|
|
|
case ID_BOOL:
|
|
|
|
|
return CBotBoolean::Compile(p, pStack);
|
|
|
|
|
|
|
|
|
|
case ID_IF:
|
|
|
|
|
return CBotIf::Compile(p, pStack);
|
|
|
|
|
|
|
|
|
|
case ID_RETURN:
|
|
|
|
|
return CBotReturn::Compile(p, pStack);
|
|
|
|
|
|
|
|
|
|
case ID_ELSE:
|
|
|
|
|
pStack->SetStartError(p->GivStart());
|
|
|
|
|
pStack->SetError(TX_ELSEWITHOUTIF, p->GivEnd());
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
case ID_CASE:
|
|
|
|
|
pStack->SetStartError(p->GivStart());
|
|
|
|
|
pStack->SetError(TX_OUTCASE, p->GivEnd());
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pStack->SetStartError(p->GivStart());
|
|
|
|
|
|
|
|
|
|
// ne doit pas <20>tre un mot r<>serv<72> 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 <20>tre une instruction arithm<68>tique
|
|
|
|
|
CBotInstr* inst = CBotExpression::Compile(p, pStack);
|
|
|
|
|
if (IsOfType(p, ID_SEP))
|
|
|
|
|
{
|
|
|
|
|
return inst;
|
|
|
|
|
}
|
|
|
|
|
pStack->SetError(TX_ENDOF, p->GivStart());
|
|
|
|
|
delete inst;
|
|
|
|
|
return NULL;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotInstr::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotString ClassManquante = name;
|
|
|
|
|
ASM_TRAP(); // ne doit jamais passer par cette routine
|
|
|
|
|
// mais utiliser les routines des classes filles
|
|
|
|
|
return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotInstr::Execute(CBotStack* &pj, CBotVar* pVar)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( !Execute(pj) ) return false;
|
|
|
|
|
pVar->SetVal( pj->GivVar() );
|
|
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotInstr::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotString ClassManquante = name;
|
|
|
|
|
ASM_TRAP(); // ne doit jamais passer par cette routine
|
|
|
|
|
// mais utiliser les routines des classes filles
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotInstr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
ASM_TRAP(); // papa sait pas faire, voir les filles
|
|
|
|
|
return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotInstr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
ASM_TRAP(); // papa sait pas faire, voir les filles
|
|
|
|
|
return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotInstr::RestoreStateVar(CBotStack* &pile, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
ASM_TRAP(); // papa sait pas faire, voir les filles
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// cette routine n'est d<>finie que pour la classe fille CBotCase
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// cela permet de faire l'appel CompCase sur toutes les instructions
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// pour savoir s'il s'agit d'un case pour la valeur d<>sir<69>e.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotInstr::CompCase(CBotStack* &pj, int val)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// compile un bloc d'instruction " { i ; i ; } "
|
|
|
|
|
|
|
|
|
|
// cette classe n'a pas de constructeur, car il n'y a jamais d'instance de cette classe
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// l'objet retourn<72> par Compile est g<>n<EFBFBD>ralement de type CBotListInstr
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
CBotInstr* CBotBlock::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pStack->SetStartError(p->GivStart());
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (IsOfType(p, ID_OPBLK))
|
|
|
|
|
{
|
|
|
|
|
CBotInstr* inst = CBotListInstr::Compile( p, pStack, bLocal );
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (IsOfType(p, ID_CLBLK))
|
|
|
|
|
{
|
|
|
|
|
return inst;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pStack->SetError(TX_CLOSEBLK, p->GivStart()); // manque la parenth<74>se
|
|
|
|
|
delete inst;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pStack->SetError(TX_OPENBLK, p->GivStart());
|
|
|
|
|
return NULL;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
CBotInstr* CBotBlock::CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool bLocal)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// est-ce un nouveau bloc ?
|
|
|
|
|
if ( p->GivType() == ID_OPBLK ) return CBotBlock::Compile(p, pStack);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// sinon, cherche une instruction unique <20> la place
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// pour g<>rer les cas avec d<>finition local <20> l'instructin (*)
|
|
|
|
|
CBotCStack* pStk = pStack->TokenStack(p, bLocal);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return pStack->Return( CBotInstr::Compile(p, pStk), // une instruction unique
|
|
|
|
|
pStk);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// (*) c'est le cas dans l'instruction suivante
|
|
|
|
|
// if ( 1 == 1 ) int x = 0;
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// o<> la variable x n'est connue que dans le bloc qui suit le if.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// compile une liste d'instruction, s<>par<61>s par des points-virgules
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotListInstr::CBotListInstr()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_Instr = NULL;
|
|
|
|
|
name = "CBotListInstr";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotListInstr::~CBotListInstr()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete m_Instr;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotCStack* pStk = pStack->TokenStack(p, bLocal); // les variables sont locales
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotListInstr* inst = new CBotListInstr();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if ( p == NULL ) break;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (IsOfType(p, ID_SEP)) continue; // instruction vide ignor<6F>e
|
|
|
|
|
if ( p->GivType() == ID_CLBLK ) break; // d<>ja plus d'instruction
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (IsOfType(p, 0))
|
|
|
|
|
{
|
|
|
|
|
pStack->SetError(TX_CLOSEBLK, p->GivStart());
|
|
|
|
|
delete inst;
|
|
|
|
|
return pStack->Return(NULL, pStk);
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotInstr* i = CBotBlock::CompileBlkOrInst( p, pStk ); // compile la suivante
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (!pStk->IsOk())
|
|
|
|
|
{
|
|
|
|
|
delete inst;
|
|
|
|
|
return pStack->Return(NULL, pStk);
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( inst->m_Instr == NULL ) inst->m_Instr = i;
|
|
|
|
|
else inst->m_Instr->AddNext(i); // ajoute <20> la suite
|
|
|
|
|
}
|
|
|
|
|
return pStack->Return(inst, pStk);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute une liste d'instructions
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotListInstr::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->AddStack(this, true);//indispensable pour SetState()
|
|
|
|
|
if ( pile->StackOver() ) return pj->Return( pile );
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotInstr* p = m_Instr; // la premi<6D>re expression
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
int state = pile->GivState();
|
|
|
|
|
while (state-->0) p = p->GivNext(); // revient sur l'op<6F>ration interrompue
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( p != NULL ) while (true)
|
|
|
|
|
{
|
|
|
|
|
// DEBUG( "CBotListInstr", pile->GivState(), pile );
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( !p->Execute(pile) ) return false;
|
|
|
|
|
p = p->GivNext();
|
|
|
|
|
if ( p == NULL ) break;
|
|
|
|
|
if (!pile->IncState()) ;//return false; // pr<70>t pour la suivante
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return pj->Return( pile ); // transmet en dessous
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotListInstr::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( !bMain ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->RestoreStack(this);
|
|
|
|
|
if ( pile == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotInstr* p = m_Instr; // la premi<6D>re expression
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
int state = pile->GivState();
|
|
|
|
|
while ( p != NULL && state-- > 0)
|
|
|
|
|
{
|
|
|
|
|
p->RestoreState(pile, false);
|
|
|
|
|
p = p->GivNext(); // revient sur l'op<6F>ration interrompue
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( p != NULL ) p->RestoreState(pile, true);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// compilation d'un <20>l<EFBFBD>ment se trouvant <20> gauche d'une assignation
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotLeftExprVar::CBotLeftExprVar()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
name = "CBotLeftExprVar";
|
|
|
|
|
m_typevar = -1;
|
|
|
|
|
m_nIdent = 0;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotLeftExprVar::~CBotLeftExprVar()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotInstr* CBotLeftExprVar::Compile(CBotToken* &p, CBotCStack* pStack)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// v<>rifie que le token est un nom de variable
|
|
|
|
|
if (p->GivType() != TokenTypVar)
|
|
|
|
|
{
|
|
|
|
|
pStack->SetError( TX_NOVAR, p->GivStart());
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotLeftExprVar* inst = new CBotLeftExprVar();
|
|
|
|
|
inst->SetToken(p);
|
|
|
|
|
p = p->GivNext();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return inst;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// cr<63>e une variable et lui assigne le r<>sultat de la pile
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotLeftExprVar::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* var1;
|
|
|
|
|
CBotVar* var2;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return true; // op<6F>ration faite
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotLeftExprVar::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* var1;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
var1 = pj->FindVar(m_token.GivString());
|
|
|
|
|
if ( var1 == NULL ) ASM_TRAP();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
var1->SetUniqNum(m_nIdent); // avec cet identificateur unique
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// d<>finition d'un tableau de n'importe quel type
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// int a[12];
|
|
|
|
|
// point x[];
|
|
|
|
|
|
|
|
|
|
CBotInstArray::CBotInstArray()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_var = NULL;
|
|
|
|
|
m_listass = NULL;
|
|
|
|
|
name = "CBotInstArray";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotInstArray::~CBotInstArray()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete m_var;
|
|
|
|
|
delete m_listass;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CBotInstr* CBotInstArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotCStack* pStk = pStack->TokenStack(p);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotInstArray* inst = new CBotInstArray(); // cr<63>e l'objet
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotToken* vartoken = p;
|
|
|
|
|
inst->SetToken(vartoken);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// d<>termine l'expression valable pour l'<27>l<EFBFBD>ment gauche
|
|
|
|
|
if ( NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) )
|
|
|
|
|
{
|
|
|
|
|
if (pStk->CheckVarLocal(vartoken)) // red<65>finition de la variable ?
|
|
|
|
|
{
|
|
|
|
|
pStk->SetError(TX_REDEFVAR, vartoken);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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<73>cial si pas de formule
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
inst->AddNext3b(i); // construit une liste
|
|
|
|
|
type = CBotTypResult(CBotTypArrayPointer, type);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (!pStk->IsOk() || !IsOfType( p, ID_CLBRK ) )
|
|
|
|
|
{
|
|
|
|
|
pStk->SetError(TX_CLBRK, p->GivStart());
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* var = CBotVar::Create(vartoken, type); // cr<63>e avec une instance
|
|
|
|
|
inst->m_typevar = type;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
var->SetUniqNum(
|
|
|
|
|
((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum());
|
|
|
|
|
// lui attribut un num<75>ro unique
|
|
|
|
|
pStack->AddVar(var); // la place sur la pile
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( IsOfType(p, ID_ASS) ) // avec une assignation
|
|
|
|
|
{
|
|
|
|
|
inst->m_listass = CBotListArray::Compile( p, pStk, type.GivTypElem() );
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pStk->IsOk() ) return pStack->Return(inst, pStk);
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
error:
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete inst;
|
|
|
|
|
return pStack->Return(NULL, pStk);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute la d<>finition d'un tableau
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotInstArray::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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<66>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<75>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<63>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();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
#else
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete pile1->AddStack(); // plus besoin des indices
|
2012-03-08 18:32:05 +00:00
|
|
|
|
#endif
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pile1->IncState();
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( !m_listass->Execute(pile1, pVar) ) return false;
|
|
|
|
|
}
|
|
|
|
|
pile1->IncState();
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile1->IfStep() ) return false; // montre ce pas ?
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next2b &&
|
|
|
|
|
!m_next2b->Execute( pile1 ) ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return pj->Return( pile1 ); // transmet en dessous
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotInstArray::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile1 = pj;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* var = pj->FindVar(m_var->GivToken()->GivString());
|
|
|
|
|
if ( var != NULL ) var->SetUniqNum(((CBotLeftExprVar*)m_var)->m_nIdent);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( bMain )
|
|
|
|
|
{
|
|
|
|
|
pile1 = pj->RestoreStack(this);
|
|
|
|
|
CBotStack* pile = pile1;
|
|
|
|
|
if ( pile == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile1->GivState() == 0 )
|
|
|
|
|
{
|
|
|
|
|
// cherche les dimensions max du tableau
|
|
|
|
|
CBotInstr* p = GivNext3b(); // les diff<66>rentes formules
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next2b ) m_next2b->RestoreState( pile1, bMain );
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// cas particulier pour les indices vides
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotEmpty :: Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* pVar = CBotVar::Create("", CBotTypInt);
|
|
|
|
|
pVar->SetValInt(-1); // met la valeur -1 sur la pile
|
|
|
|
|
pj->SetVar(pVar);
|
|
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotEmpty :: RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// d<>finition d'une liste d'initialisation pour un tableau
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// int [ ] a [ ] = ( ( 1, 2, 3 ) , ( 3, 2, 1 ) ) ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CBotListArray::CBotListArray()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_expr = NULL;
|
|
|
|
|
name = "CBotListArray";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotListArray::~CBotListArray()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete m_expr;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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 <20>l<EFBFBD>ment vide
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotListArray* inst = new CBotListArray(); // cr<63>e l'objet
|
|
|
|
|
|
|
|
|
|
if ( IsOfType( p, ID_OPENPAR ) )
|
|
|
|
|
{
|
|
|
|
|
// prend chaque <20>l<EFBFBD>ment l'un apr<70>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 <20>l<EFBFBD>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 <20>l<EFBFBD>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);
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
error:
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete inst;
|
|
|
|
|
return pStack->Return(NULL, pStk);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute la d<>finition d'un tableau
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile1 = pj->AddStack();
|
|
|
|
|
// if ( pile1 == EOX ) return true;
|
|
|
|
|
CBotVar* pVar2;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotInstr* p = m_expr;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
int n = 0;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
for ( ; p != NULL ; n++, p = p->GivNext3() )
|
|
|
|
|
{
|
|
|
|
|
if ( pile1->GivState() > n ) continue;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pVar2 = pVar->GivItem(n, true);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( !p->Execute(pile1, pVar2) ) return false; // <20>value l'expression
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pile1->IncState();
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return pj->Return( pile1 ); // transmet en dessous
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotListArray::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( bMain )
|
|
|
|
|
{
|
|
|
|
|
CBotStack* pile = pj->RestoreStack(this);
|
|
|
|
|
if ( pile == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotInstr* p = m_expr;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
int state = pile->GivState();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
while( state-- > 0 ) p = p->GivNext3() ;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
p->RestoreState(pile, bMain); // calcul de la taille // interrompu!
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// d<>finition d'une variable enti<74>re
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// int a, b = 12;
|
|
|
|
|
|
|
|
|
|
CBotInt::CBotInt()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_next = NULL; // pour les d<>finitions multiples
|
|
|
|
|
m_var =
|
|
|
|
|
m_expr = NULL;
|
|
|
|
|
name = "CBotInt";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotInt::~CBotInt()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete m_var;
|
|
|
|
|
delete m_expr;
|
|
|
|
|
// delete m_next; // fait par le destructeur de la classe de base ~CBotInstr()
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypResult type, bool first)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( IsOfType(p, ID_OPBRK) )
|
|
|
|
|
{
|
|
|
|
|
if ( !IsOfType(p, ID_CLBRK) )
|
|
|
|
|
{
|
|
|
|
|
pStack->SetError(TX_CLBRK, p->GivStart());
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotInstr* inst = CompileArray(p, pStack, CBotTypResult( CBotTypArrayPointer, type ), false);
|
|
|
|
|
if ( inst != NULL || !pStack->IsOk() ) return inst;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// compile une d<>claration de tableau
|
|
|
|
|
if (first) return NULL ;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotInstr* inst = CBotInstArray::Compile( p, pStack, type );
|
|
|
|
|
if ( inst == NULL ) return NULL;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (IsOfType(p, ID_COMMA)) // plusieurs d<>finitions encha<68>n<EFBFBD>es
|
|
|
|
|
{
|
|
|
|
|
if ( NULL != ( inst->m_next2b = CBotInstArray::CompileArray(p, pStack, type, false) )) // compile la suivante
|
|
|
|
|
{
|
|
|
|
|
return inst;
|
|
|
|
|
}
|
|
|
|
|
delete inst;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (IsOfType(p, ID_SEP)) // instruction termin<69>e
|
|
|
|
|
{
|
|
|
|
|
return inst;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete inst;
|
|
|
|
|
pStack->SetError(TX_ENDOF, p->GivStart());
|
|
|
|
|
return NULL;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
CBotInstr* CBotInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotToken* pp = cont ? NULL : p; // pas de r<>p<EFBFBD>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<63>e l'objet
|
|
|
|
|
|
|
|
|
|
inst->m_expr = NULL;
|
|
|
|
|
|
|
|
|
|
CBotToken* vartoken = p;
|
|
|
|
|
inst->SetToken( vartoken );
|
|
|
|
|
|
|
|
|
|
// d<>termine l'expression valable pour l'<27>l<EFBFBD>ment gauche
|
|
|
|
|
if ( NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) )
|
|
|
|
|
{
|
|
|
|
|
((CBotLeftExprVar*)inst->m_var)->m_typevar = CBotTypInt;
|
|
|
|
|
if (pStk->CheckVarLocal(vartoken)) // red<65>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<68>n<EFBFBD>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<EFBFBD> cr<63><72>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<63>e la variable (apr<70>s l'assignation <20>valu<6C>e)
|
|
|
|
|
var->SetInit(inst->m_expr != NULL); // la marque initialis<69>e si avec assignation
|
|
|
|
|
var->SetUniqNum(
|
|
|
|
|
((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum());
|
|
|
|
|
// lui attribut un num<75>ro unique
|
|
|
|
|
pStack->AddVar(var); // la place sur la pile
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsOfType(p, ID_COMMA)) // plusieurs d<>finitions encha<68>n<EFBFBD>es
|
|
|
|
|
{
|
|
|
|
|
if ( NULL != ( inst->m_next2b = CBotInt::Compile(p, pStk, true, noskip) )) // compile la suivante
|
|
|
|
|
{
|
|
|
|
|
return pStack->Return(inst, pStk);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
suite:
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (noskip || IsOfType(p, ID_SEP)) // instruction termin<69>e
|
|
|
|
|
{
|
|
|
|
|
return pStack->Return(inst, pStk);
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pStk->SetError(TX_ENDOF, p->GivStart());
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
error:
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete inst;
|
|
|
|
|
return pStack->Return(NULL, pStk);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute la d<>finition de la variable enti<74>re
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotInt::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->AddStack(this); //indispensable pour SetState()
|
|
|
|
|
// if ( pile == EOX ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->GivState()==0)
|
|
|
|
|
{
|
|
|
|
|
if (m_expr && !m_expr->Execute(pile)) return false; // valeur initiale // interrompu?
|
|
|
|
|
m_var->Execute( pile ); // cr<63>e et fait l'assigation du r<>sultat
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (!pile->SetState(1)) return false;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->IfStep() ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next2b &&
|
|
|
|
|
!m_next2b->Execute(pile)) return false; // autre(s) d<>finition(s)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return pj->Return( pile ); // transmet en dessous
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotInt::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj;
|
|
|
|
|
if ( bMain )
|
|
|
|
|
{
|
|
|
|
|
pile = pj->RestoreStack(this);
|
|
|
|
|
if ( pile == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->GivState()==0)
|
|
|
|
|
{
|
|
|
|
|
if (m_expr) m_expr->RestoreState(pile, bMain); // valeur initiale // interrompu!
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_var->RestoreState(pile, bMain);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next2b ) m_next2b->RestoreState(pile, bMain); // autre(s) d<>finition(s)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// d<>finition d'une variable bool<6F>en
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// int a, b = false;
|
|
|
|
|
|
|
|
|
|
CBotBoolean::CBotBoolean()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_var =
|
|
|
|
|
m_expr = NULL;
|
|
|
|
|
name = "CBotBoolean";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotBoolean::~CBotBoolean()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete m_var;
|
|
|
|
|
delete m_expr;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
CBotInstr* CBotBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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<65>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<EFBFBD> cr<63><72>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<63>e la variable (apr<70>s l'assignation <20>valu<6C>e)
|
|
|
|
|
var->SetInit(inst->m_expr != NULL); // la marque initialis<69>e si avec assignation
|
|
|
|
|
var->SetUniqNum(
|
|
|
|
|
((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum());
|
|
|
|
|
// lui attribut un num<75>ro unique
|
|
|
|
|
pStack->AddVar(var); // la place sur la pile
|
2012-03-08 18:32:05 +00:00
|
|
|
|
suite:
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (IsOfType(p, ID_COMMA)) // plusieurs d<>finitions encha<68>n<EFBFBD>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<69>e
|
|
|
|
|
{
|
|
|
|
|
return pStack->Return(inst, pStk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pStk->SetError(TX_ENDOF, p->GivStart());
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
error:
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete inst;
|
|
|
|
|
return pStack->Return(NULL, pStk);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute une d<>finition de variable bool<6F>enne
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotBoolean::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->AddStack(this);//indispensable pour SetState()
|
|
|
|
|
// if ( pile == EOX ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->GivState()==0)
|
|
|
|
|
{
|
|
|
|
|
if (m_expr && !m_expr->Execute(pile)) return false; // valeur initiale // interrompu?
|
|
|
|
|
m_var->Execute( pile ); // cr<63>e et fait l'assigation du r<>sultat
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (!pile->SetState(1)) return false;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->IfStep() ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next2b &&
|
|
|
|
|
!m_next2b->Execute(pile)) return false; // autre(s) d<>finition(s)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return pj->Return( pile ); // transmet en dessous
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotBoolean::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj;
|
|
|
|
|
if ( bMain )
|
|
|
|
|
{
|
|
|
|
|
pile = pj->RestoreStack(this);
|
|
|
|
|
if ( pile == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->GivState()==0)
|
|
|
|
|
{
|
|
|
|
|
if (m_expr) m_expr->RestoreState(pile, bMain); // valeur initiale interrompu?
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_var->RestoreState( pile, bMain ); //
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next2b )
|
|
|
|
|
m_next2b->RestoreState(pile, bMain); // autre(s) d<>finition(s)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// d<>finition d'une variable r<>elle
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// int a, b = 12.4;
|
|
|
|
|
|
|
|
|
|
CBotFloat::CBotFloat()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_var =
|
|
|
|
|
m_expr = NULL;
|
|
|
|
|
name = "CBotFloat";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotFloat::~CBotFloat()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete m_var;
|
|
|
|
|
delete m_expr;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
CBotInstr* CBotFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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<65>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<EFBFBD> cr<63><72>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<63>e la variable (apr<70>s l'assignation <20>valu<6C>e)
|
|
|
|
|
var->SetInit(inst->m_expr != NULL); // la marque initialis<69>e si avec assignation
|
|
|
|
|
var->SetUniqNum(
|
|
|
|
|
((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum());
|
|
|
|
|
// lui attribut un num<75>ro unique
|
|
|
|
|
pStack->AddVar(var); // la place sur la pile
|
2012-03-08 18:32:05 +00:00
|
|
|
|
suite:
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (IsOfType(p, ID_COMMA)) // plusieurs d<>finitions encha<68>n<EFBFBD>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<69>e
|
|
|
|
|
{
|
|
|
|
|
return pStack->Return(inst, pStk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pStk->SetError(TX_ENDOF, p->GivStart());
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
error:
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete inst;
|
|
|
|
|
return pStack->Return(NULL, pStk);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute la d<>fintion de la variable r<>elle
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotFloat::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->AddStack(this);//indispensable pour SetState()
|
|
|
|
|
// if ( pile == EOX ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->GivState()==0)
|
|
|
|
|
{
|
|
|
|
|
if (m_expr && !m_expr->Execute(pile)) return false; // valeur initiale // interrompu?
|
|
|
|
|
m_var->Execute( pile ); // cr<63>e et fait l'assigation du r<>sultat
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (!pile->SetState(1)) return false;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->IfStep() ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next2b &&
|
|
|
|
|
!m_next2b->Execute(pile)) return false; // autre(s) d<>finition(s)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return pj->Return( pile ); // transmet en dessous
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotFloat::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj;
|
|
|
|
|
if ( bMain )
|
|
|
|
|
{
|
|
|
|
|
pile = pj->RestoreStack(this);
|
|
|
|
|
if ( pile == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->GivState()==0)
|
|
|
|
|
{
|
|
|
|
|
if (m_expr) m_expr->RestoreState(pile, bMain); // valeur initiale interrompu?
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_var->RestoreState( pile, bMain ); //
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next2b )
|
|
|
|
|
m_next2b->RestoreState(pile, bMain); // autre(s) d<>finition(s)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// d<>finition d'une variable cha<68>ne de caract<63>res
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// int a, b = "salut";
|
|
|
|
|
|
|
|
|
|
CBotIString::CBotIString()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_var =
|
|
|
|
|
m_expr = NULL;
|
|
|
|
|
name = "CBotIString";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotIString::~CBotIString()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete m_var;
|
|
|
|
|
delete m_expr;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
CBotInstr* CBotIString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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<65>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<63>e la variable (apr<70>s l'assignation <20>valu<6C>e)
|
|
|
|
|
var->SetInit(inst->m_expr != NULL); // la marque initialis<69>e si avec assignation
|
|
|
|
|
var->SetUniqNum(
|
|
|
|
|
((CBotLeftExprVar*)inst->m_var)->m_nIdent = CBotVar::NextUniqNum());
|
|
|
|
|
// lui attribut un num<75>ro unique
|
|
|
|
|
pStack->AddVar(var); // la place sur la pile
|
|
|
|
|
|
|
|
|
|
if (IsOfType(p, ID_COMMA)) // plusieurs d<>finitions encha<68>n<EFBFBD>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<69>e
|
|
|
|
|
{
|
|
|
|
|
return pStack->Return(inst, pStk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pStk->SetError(TX_ENDOF, p->GivStart());
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
error:
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete inst;
|
|
|
|
|
return pStack->Return(NULL, pStk);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute la d<>finition de la variable string
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotIString::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->AddStack(this);//indispensable pour SetState()
|
|
|
|
|
// if ( pile == EOX ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->GivState()==0)
|
|
|
|
|
{
|
|
|
|
|
if (m_expr && !m_expr->Execute(pile)) return false; // valeur initiale // interrompu?
|
|
|
|
|
m_var->Execute( pile ); // cr<63>e et fait l'assigation du r<>sultat
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (!pile->SetState(1)) return false;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->IfStep() ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next2b &&
|
|
|
|
|
!m_next2b->Execute(pile)) return false; // autre(s) d<>finition(s)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return pj->Return( pile ); // transmet en dessous
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotIString::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj;
|
|
|
|
|
|
|
|
|
|
if ( bMain )
|
|
|
|
|
{
|
|
|
|
|
pile = pj->RestoreStack(this);
|
|
|
|
|
if ( pile == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->GivState()==0)
|
|
|
|
|
{
|
|
|
|
|
if (m_expr) m_expr->RestoreState(pile, bMain); // valeur initiale interrompu?
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_var->RestoreState( pile, bMain ); //
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next2b )
|
|
|
|
|
m_next2b->RestoreState(pile, bMain); // autre(s) d<>finition(s)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// compile une instruction de type " x = 123 " ou " z * 5 + 4 "
|
|
|
|
|
// avec ou sans assignation donc
|
|
|
|
|
|
|
|
|
|
CBotExpression::CBotExpression()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_leftop = NULL;
|
|
|
|
|
m_rightop = NULL;
|
|
|
|
|
name = "CBotExpression";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotExpression::~CBotExpression()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete m_leftop;
|
|
|
|
|
delete m_rightop;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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<75>re la variable pour la marquer assign<67>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;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute une expression avec assignation
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotExpression::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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 <20>tre fait avant pour les indices <20>ventuels (pile peut <20>tre chang<6E>e)
|
|
|
|
|
if ( !m_leftop->ExecuteVar(pVar, pile, NULL, false) ) return false; // variable avant <20>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<75>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<63>e et fait l'assigation du r<>sultat
|
|
|
|
|
|
|
|
|
|
return pj->Return( pile2 ); // transmet en dessous
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotExpression::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( bMain )
|
|
|
|
|
{
|
|
|
|
|
CBotToken* pToken = m_leftop->GivToken();
|
|
|
|
|
CBotVar* pVar = NULL;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->RestoreStack(this);
|
|
|
|
|
if ( pile == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile1 = pile;
|
|
|
|
|
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile1->GivState()==0)
|
|
|
|
|
{
|
|
|
|
|
m_leftop->RestoreStateVar(pile, true); // variable avant <20>valuation de la valeur droite
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_leftop->RestoreStateVar(pile, false); // variable avant <20>valuation de la valeur droite
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile2 = pile->RestoreStack(); // attention pile et surtout pas pile1
|
|
|
|
|
if ( pile2 == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile2->GivState()==0)
|
|
|
|
|
{
|
|
|
|
|
if (m_rightop) m_rightop->RestoreState(pile2, bMain); // valeur initiale // interrompu?
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// compile une instruction de type " ( condition ) "
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// la condition doit <20>tre de type bool<6F>en
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
// cette classe n'a pas de constructeur, car il n'y a jamais d'instance de cette classe
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// l'objet retourn<72> par Compile est g<>n<EFBFBD>ralement de type CBotExpression
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotInstr* CBotCondition::Compile(CBotToken* &p, CBotCStack* pStack)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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<74>se
|
|
|
|
|
}
|
|
|
|
|
delete inst;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pStack->SetError(TX_OPENPAR, p->GivStart()); // manque la parenth<74>se
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return NULL;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// compile une instruction de type " condition "
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// la condition doit <20>tre de type bool<6F>en
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
// cette classe n'a pas de constructeur, car il n'y a jamais d'instance de cette classe
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// l'objet retourn<72> par Compile est g<>n<EFBFBD>ralement de type CBotExpression
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotInstr* CBotBoolExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pStack->SetStartError(p->GivStart());
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotInstr* inst = CBotTwoOpExpr::Compile( p, pStack );
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( NULL != inst )
|
|
|
|
|
{
|
|
|
|
|
if ( pStack->GivTypResult().Eq(CBotTypBoolean) )
|
|
|
|
|
{
|
|
|
|
|
return inst;
|
|
|
|
|
}
|
|
|
|
|
pStack->SetError(TX_NOTBOOL, p->GivStart()); // n'est pas un bool<6F>an
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete inst;
|
|
|
|
|
return NULL;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// compile soit :
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// une instruction entre parenth<74>ses (...)
|
|
|
|
|
// une expression unaire (n<>gatif, not)
|
|
|
|
|
// nom de variable
|
|
|
|
|
// les variables pr<70> et post incr<63>ment<6E>es ou d<>cr<63>ment<6E>es
|
|
|
|
|
// un nombre donn<6E> par DefineNum
|
|
|
|
|
// une constante
|
|
|
|
|
// un appel de proc<6F>dure
|
|
|
|
|
// l'instruction new
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
// cette classe n'a pas de constructeur, car il n'y a jamais d'instance de cette classe
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// l'objet retourn<72> par Compile est de la classe correspondant <20> l'instruction
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotCStack* pStk = pStack->TokenStack();
|
|
|
|
|
|
|
|
|
|
pStk->SetStartError(p->GivStart());
|
|
|
|
|
|
|
|
|
|
// est-ce une expression entre parenth<74>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<6F>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-<2D>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<6F>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<63>ment<6E> ou d<>cr<63>ment<6E> ?
|
|
|
|
|
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<63>e
|
|
|
|
|
return pStack->Return(i, pStk);
|
|
|
|
|
}
|
|
|
|
|
return pStack->Return(inst, pStk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// est-ce une variable pr<70>incr<63>ment<6E>e ou pr<70>d<EFBFBD>cr<63>ment<6E>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 <20>l<EFBFBD>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 <20> cr<63>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);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// gestion du post et pr<70>- incr<63>ment/d<>cr<63>ment
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// il n'y a pas de routine Compile, l'objet est cr<63><72> directement
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// dans CBotParExpr::Compile
|
|
|
|
|
|
|
|
|
|
CBotPostIncExpr::CBotPostIncExpr()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_Instr = NULL;
|
|
|
|
|
name = "CBotPostIncExpr";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotPostIncExpr::~CBotPostIncExpr()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete m_Instr;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotPreIncExpr::CBotPreIncExpr()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_Instr = NULL;
|
|
|
|
|
name = "CBotPreIncExpr";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotPreIncExpr::~CBotPreIncExpr()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete m_Instr;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotPostIncExpr::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile1 = pj->AddStack(this);
|
|
|
|
|
CBotStack* pile2 = pile1;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* var1 = NULL;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( !((CBotExprVar*)m_Instr)->ExecuteVar(var1, pile2, NULL, true) ) return false; // r<>cup<75>re la variable selon champs et index
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pile1->SetState(1);
|
|
|
|
|
pile1->SetCopyVar(var1); // place le r<>sultat (avant incr<63>mentation);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile3 = pile2->AddStack(this);
|
|
|
|
|
if ( pile3->IfStep() ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( var1->GivInit() == IS_NAN )
|
|
|
|
|
{
|
|
|
|
|
pile1->SetError( TX_OPNAN, &m_token );
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( var1->GivInit() != IS_DEF )
|
|
|
|
|
{
|
|
|
|
|
pile1->SetError( TX_NOTINIT, &m_token );
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (GivTokenType() == ID_INC) var1->Inc();
|
|
|
|
|
else var1->Dec();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return pj->Return(pile1); // op<6F>ration faite, r<>sultat sur pile2
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotPostIncExpr::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( !bMain ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile1 = pj->RestoreStack(this);
|
|
|
|
|
if ( pile1 == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
((CBotExprVar*)m_Instr)->RestoreStateVar(pile1, bMain);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile1 != NULL ) pile1->RestoreStack(this);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotPreIncExpr::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->AddStack(this);
|
|
|
|
|
// if ( pile == EOX ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->IfStep() ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* var1;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->GivState() == 0 )
|
|
|
|
|
{
|
|
|
|
|
CBotStack* pile2 = pile;
|
|
|
|
|
if ( !((CBotExprVar*)m_Instr)->ExecuteVar(var1, pile2, NULL, true) ) return false; // r<>cup<75>re la variable selon champs et index
|
|
|
|
|
// pile2 est modifi<66> en retour
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( var1->GivInit() == IS_NAN )
|
|
|
|
|
{
|
|
|
|
|
pile->SetError( TX_OPNAN, &m_token );
|
|
|
|
|
return pj->Return(pile); // op<6F>ration faite
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( var1->GivInit() != IS_DEF )
|
|
|
|
|
{
|
|
|
|
|
pile->SetError( TX_NOTINIT, &m_token );
|
|
|
|
|
return pj->Return(pile); // op<6F>ration faite
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (GivTokenType() == ID_INC) var1->Inc();
|
|
|
|
|
else var1->Dec(); // ((CBotVarInt*)var1)->m_val
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pile->IncState();
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( !m_Instr->Execute(pile) ) return false;
|
|
|
|
|
return pj->Return(pile); // op<6F>ration faite
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotPreIncExpr::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( !bMain ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->RestoreStack(this);
|
|
|
|
|
if ( pile == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->GivState() == 0 )
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_Instr->RestoreState(pile, bMain);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// compile une expression unaire
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// +
|
|
|
|
|
// -
|
|
|
|
|
// not
|
|
|
|
|
// !
|
|
|
|
|
// ~
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotExprUnaire::CBotExprUnaire()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_Expr = NULL;
|
|
|
|
|
name = "CBotExprUnaire";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotExprUnaire::~CBotExprUnaire()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete m_Expr;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotInstr* CBotExprUnaire::Compile(CBotToken* &p, CBotCStack* pStack)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotCStack* pStk = pStack->TokenStack(pp);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotExprUnaire* inst = new CBotExprUnaire();
|
|
|
|
|
inst->SetToken(pp);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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<6F>ens
|
|
|
|
|
return pStack->Return(inst, pStk);
|
|
|
|
|
if ( op == ID_TXT_NOT && pStk->GivTypResult().Eq(CBotTypBoolean) )// seulement avec des bool<6F>ens
|
|
|
|
|
return pStack->Return(inst, pStk);
|
|
|
|
|
|
|
|
|
|
pStk->SetError(TX_BADTYPE, &inst->m_token);
|
|
|
|
|
}
|
|
|
|
|
delete inst;
|
|
|
|
|
return pStack->Return(NULL, pStk);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute l'expresson unaire
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotExprUnaire::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->AddStack(this);
|
|
|
|
|
// if ( pile == EOX ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->GivState() == 0 )
|
|
|
|
|
{
|
|
|
|
|
if (!m_Expr->Execute( pile )) return false; // interrompu ?
|
|
|
|
|
pile->IncState();
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile2 = pile->AddStack();
|
|
|
|
|
if ( pile2->IfStep() ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* var = pile->GivVar(); // r<>cup<75>re le r<>sultat sur la pile
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotExprUnaire::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( !bMain ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->RestoreStack(this);
|
|
|
|
|
if ( pile == NULL) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->GivState() == 0 )
|
|
|
|
|
{
|
|
|
|
|
m_Expr->RestoreState( pile, bMain ); // interrompu ici !
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// gestion des index pour les tableaux
|
|
|
|
|
// array [ expression ]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CBotIndexExpr::CBotIndexExpr()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_expr = NULL;
|
|
|
|
|
name = "CBotIndexExpr";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotIndexExpr::~CBotIndexExpr()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete m_expr;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// trouve un champ <20> partir de l'instance <20> la compilation
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pVar->GivType(1) != CBotTypArrayPointer )
|
|
|
|
|
ASM_TRAP();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pVar = ((CBotVarArray*)pVar)->GivItem(0, false); // <20> la compilation rend l'<27>l<EFBFBD>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;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// idem <20> l'ex<65>cution
|
|
|
|
|
// attention, modifie le pointeur <20> la pile volontairement
|
|
|
|
|
// place les index calcul<75>s sur la pile suppl<70>mentaire
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pj = pile;
|
|
|
|
|
// DEBUG( "CBotIndexExpr::ExecuteVar", -1 , pj);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pVar->GivType(1) != CBotTypArrayPointer )
|
|
|
|
|
ASM_TRAP();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pile = pile->AddStack();
|
|
|
|
|
// if ( pile == EOX ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->GivState() == 0 )
|
|
|
|
|
{
|
|
|
|
|
if ( !m_expr->Execute(pile) ) return false;
|
|
|
|
|
pile->IncState();
|
|
|
|
|
}
|
|
|
|
|
// traite les tableaux
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* p = pile->GivVar(); // r<>sultat sur la pile
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( p == NULL || p->GivType() > CBotTypDouble )
|
|
|
|
|
{
|
|
|
|
|
pile->SetError(TX_BADINDEX, prevToken);
|
|
|
|
|
return pj->Return(pile);
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
int n = p->GivValInt(); // position dans le tableau
|
|
|
|
|
// DEBUG( "CBotIndexExpr::ExecuteVar", n , pj);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pVar = ((CBotVarArray*)pVar)->GivItem(n, bExtend);
|
|
|
|
|
if ( pVar == NULL )
|
|
|
|
|
{
|
|
|
|
|
pile->SetError(TX_OUTARRAY, prevToken);
|
|
|
|
|
return pj->Return(pile);
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// DEBUG( "CBotIndexExpr::ExecuteVar", -2 , pj);
|
|
|
|
|
//if ( bUpdate )
|
|
|
|
|
pVar->Maj(pile->GivPUser(), true);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// DEBUG( "CBotIndexExpr::ExecuteVar", -3 , pj);
|
|
|
|
|
if ( m_next3 != NULL &&
|
|
|
|
|
!m_next3->ExecuteVar(pVar, pile, prevToken, bStep, bExtend) ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// DEBUG( "CBotIndexExpr::ExecuteVar", -4 , pj);
|
|
|
|
|
return true; // ne lib<69>re pas la pile
|
|
|
|
|
// pour <20>viter de recalculer les index deux fois le cas <20>ch<63>ant
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotIndexExpr::RestoreStateVar(CBotStack* &pile, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pile = pile->RestoreStack();
|
|
|
|
|
if ( pile == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( bMain && pile->GivState() == 0 )
|
|
|
|
|
{
|
|
|
|
|
m_expr->RestoreState(pile, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next3 )
|
|
|
|
|
m_next3->RestoreStateVar(pile, bMain);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// gestion des champs dans une instance (op<6F>rateur point)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// toto.x
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CBotFieldExpr::CBotFieldExpr()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
name = "CBotFieldExpr";
|
|
|
|
|
m_nIdent = 0;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotFieldExpr::~CBotFieldExpr()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CBotFieldExpr::SetUniqNum(int num)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_nIdent = num;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// trouve un champ <20> partir de l'instance <20> la compilation
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pVar->GivType(1) != CBotTypPointer )
|
|
|
|
|
ASM_TRAP();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// pVar = pVar->GivItem(m_token.GivString());
|
|
|
|
|
pVar = pVar->GivItemRef(m_nIdent);
|
|
|
|
|
if ( pVar == NULL )
|
|
|
|
|
{
|
|
|
|
|
pile->SetError(TX_NOITEM, &m_token);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next3 != NULL &&
|
|
|
|
|
!m_next3->ExecuteVar(pVar, pile) ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// idem <20> l'ex<65>cution
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pj = pile;
|
|
|
|
|
pile = pile->AddStack(this); // modifie pile en sortie
|
|
|
|
|
if ( pile == EOX ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// DEBUG( "CBotFieldExpre::ExecuteVar "+m_token.GivString(), 0, pj );
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pVar->GivType(1) != CBotTypPointer )
|
|
|
|
|
ASM_TRAP();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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 );
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( bStep && pile->IfStep() ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// pVar = pVar->GivItem(m_token.GivString());
|
|
|
|
|
pVar = pVar->GivItemRef(m_nIdent);
|
|
|
|
|
if ( pVar == NULL )
|
|
|
|
|
{
|
|
|
|
|
pile->SetError(TX_NOITEM, &m_token);
|
|
|
|
|
return pj->Return( pile );
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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) ;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// demande la mise <20> jour de l'<27>l<EFBFBD>ment, s'il y a lieu
|
|
|
|
|
pVar->Maj(pile->GivPUser(), true);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next3 != NULL &&
|
|
|
|
|
!m_next3->ExecuteVar(pVar, pile, &m_token, bStep, bExtend) ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return true; // ne lib<69>re pas la pile
|
|
|
|
|
// pour conserver l'<27>tat SetState() correspondant <20> l'<27>tape
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotFieldExpr::RestoreStateVar(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pj = pj->RestoreStack(this); // modifie pj en sortie
|
|
|
|
|
if ( pj == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next3 != NULL )
|
|
|
|
|
m_next3->RestoreStateVar(pj, bMain);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// compile un op<6F>rande gauche pour une assignation
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotLeftExpr::CBotLeftExpr()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
name = "CBotLeftExpr";
|
|
|
|
|
m_nIdent = 0;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotLeftExpr::~CBotLeftExpr()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
// compiles an expression for a left-operand (left of an assignment)
|
|
|
|
|
// this can be
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// toto
|
|
|
|
|
// toto[ 3 ]
|
|
|
|
|
// toto.x
|
|
|
|
|
// toto.pos.x
|
|
|
|
|
// toto[2].pos.x
|
|
|
|
|
// toto[1].pos[2].x
|
|
|
|
|
// toto[1][2][3]
|
|
|
|
|
|
|
|
|
|
CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
|
|
|
|
{
|
2012-07-04 20:14:28 +00:00
|
|
|
|
CBotCStack* pStk = pStack->TokenStack();
|
|
|
|
|
|
|
|
|
|
pStk->SetStartError(p->GivStart());
|
|
|
|
|
|
|
|
|
|
// is it a variable name?
|
|
|
|
|
if (p->GivType() == TokenTypVar)
|
|
|
|
|
{
|
|
|
|
|
CBotLeftExpr* inst = new CBotLeftExpr(); // creates the object
|
|
|
|
|
|
|
|
|
|
inst->SetToken(p);
|
|
|
|
|
|
|
|
|
|
CBotVar* var;
|
|
|
|
|
|
|
|
|
|
if ( NULL != (var = pStk->FindVar(p)) ) // seek if known variable
|
|
|
|
|
{
|
|
|
|
|
inst->m_nIdent = var->GivUniqNum();
|
|
|
|
|
if (inst->m_nIdent > 0 && inst->m_nIdent < 9000)
|
|
|
|
|
{
|
|
|
|
|
if ( var->IsPrivate(PR_READ) &&
|
|
|
|
|
!pStk->GivBotCall()->m_bCompileClass)
|
|
|
|
|
{
|
|
|
|
|
pStk->SetError( TX_PRIVATE, p );
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
// il s'agit d'un <20>lement de la classe courante
|
|
|
|
|
// ajoute l'<27>quivalent d'un this. devant
|
|
|
|
|
CBotToken pthis("this");
|
|
|
|
|
inst->SetToken(&pthis);
|
|
|
|
|
inst->m_nIdent = -2; // ident pour this
|
|
|
|
|
|
|
|
|
|
CBotFieldExpr* i = new CBotFieldExpr(); // nouvel <20>l<EFBFBD>ment
|
|
|
|
|
i->SetToken( p ); // garde le nom du token
|
|
|
|
|
inst->AddNext3(i); // ajoute <20> la suite
|
|
|
|
|
|
|
|
|
|
var = pStk->FindVar(pthis);
|
|
|
|
|
var = var->GivItem(p->GivString());
|
|
|
|
|
i->SetUniqNum(var->GivUniqNum());
|
|
|
|
|
}
|
|
|
|
|
p = p->GivNext(); // token suivant
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if ( var->GivType() == CBotTypArrayPointer ) // s'il sagit d'un tableau
|
|
|
|
|
{
|
|
|
|
|
if ( IsOfType( p, ID_OPBRK ) ) // regarde s'il y a un index
|
|
|
|
|
{
|
|
|
|
|
CBotIndexExpr* i = new CBotIndexExpr();
|
|
|
|
|
i->m_expr = CBotExpression::Compile(p, pStk); // compile la formule
|
|
|
|
|
inst->AddNext3(i); // ajoute <20> la chaine
|
|
|
|
|
|
|
|
|
|
var = ((CBotVarArray*)var)->GivItem(0,true); // donne le composant [0]
|
|
|
|
|
|
|
|
|
|
if ( i->m_expr == NULL )
|
|
|
|
|
{
|
|
|
|
|
pStk->SetError( TX_BADINDEX, p->GivStart() );
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !pStk->IsOk() || !IsOfType( p, ID_CLBRK ) )
|
|
|
|
|
{
|
|
|
|
|
pStk->SetError( TX_CLBRK, p->GivStart() );
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( var->GivType(1) == CBotTypPointer ) // pour les classes
|
|
|
|
|
{
|
|
|
|
|
if ( IsOfType(p, ID_DOT) )
|
|
|
|
|
{
|
|
|
|
|
CBotToken* pp = p;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotFieldExpr* i = new CBotFieldExpr(); // nouvel <20>l<EFBFBD>ment
|
|
|
|
|
i->SetToken( pp ); // garde le nom du token
|
|
|
|
|
inst->AddNext3(i); // ajoute <20> la suite
|
|
|
|
|
|
|
|
|
|
if ( p->GivType() == TokenTypVar ) // doit <20>tre un nom
|
|
|
|
|
{
|
|
|
|
|
var = var->GivItem(p->GivString()); // r<>cup<75>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);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
err:
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete inst;
|
|
|
|
|
return (CBotLeftExpr*) pStack->Return(NULL, pStk);
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return (CBotLeftExpr*) pStack->Return(NULL, pStk);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute, trouve une variable et lui assigne le r<>sultat de la pile
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotLeftExpr::Execute(CBotStack* &pj, CBotStack* array)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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<74>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<6F>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<6F>ration faite
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// retrouve une variable pendant la compilation
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pVar = pile->FindVar(m_token);
|
|
|
|
|
if ( pVar == NULL ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next3 != NULL &&
|
|
|
|
|
!m_next3->ExecuteVar(pVar, pile) ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// retrouve une variable <20> l'ex<65>cution
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotLeftExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pile = pile->AddStack( this ); // d<>place la pile
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pVar = pile->FindVar(m_nIdent);
|
|
|
|
|
if ( pVar == NULL )
|
|
|
|
|
{
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
ASM_TRAP();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
#endif
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pile->SetError(2, &m_token);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( bStep && m_next3 == NULL && pile->IfStep() ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next3 != NULL &&
|
|
|
|
|
!m_next3->ExecuteVar(pVar, pile, &m_token, bStep, true) ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotLeftExpr::RestoreStateVar(CBotStack* &pile, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pile = pile->RestoreStack( this ); // d<>place la pile
|
|
|
|
|
if ( pile == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next3 != NULL )
|
|
|
|
|
m_next3->RestoreStateVar(pile, bMain);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// transforme une cha<68>ne en nombre entier
|
|
|
|
|
// peut <20>tre de la forme 0xabc123
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
long GivNumInt( const char* p )
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// transforme une cha<68>ne en un nombre r<>el
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
extern float GivNumFloat( const char* p )
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// compile un token repr<70>sentant un nombre
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotExprNum::CBotExprNum()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
name = "CBotExprNum";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotExprNum::~CBotExprNum()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotInstr* CBotExprNum::Compile(CBotToken* &p, CBotCStack* pStack)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute, retourne le nombre correspondant
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotExprNum::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->AddStack(this);
|
|
|
|
|
// if ( pile == EOX ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->IfStep() ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* var = CBotVar::Create((CBotToken*)NULL, m_numtype);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotString nombre ;
|
|
|
|
|
if ( m_token.GivType() == TokenTypDef )
|
|
|
|
|
{
|
|
|
|
|
nombre = m_token.GivString();
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return pj->Return(pile); // c'est ok
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotExprNum::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( bMain ) pj->RestoreStack(this);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// compile un token repr<70>sentant une chaine de caract<63>res
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotExprAlpha::CBotExprAlpha()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
name = "CBotExprAlpha";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotExprAlpha::~CBotExprAlpha()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotInstr* CBotExprAlpha::Compile(CBotToken* &p, CBotCStack* pStack)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotCStack* pStk = pStack->TokenStack();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotExprAlpha* inst = new CBotExprAlpha();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
inst->SetToken(p);
|
|
|
|
|
p = p->GivNext();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypString);
|
|
|
|
|
pStk->SetVar(var);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return pStack->Return(inst, pStk);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute, retourne la cha<68>ne correspondante
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotExprAlpha::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->AddStack(this);
|
|
|
|
|
// if ( pile == EOX ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->IfStep() ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypString);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotString chaine = m_token.GivString();
|
|
|
|
|
chaine = chaine.Mid(1, chaine.GivLength()-2); // enl<6E>ve les guillemets
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
var->SetValString( chaine ); // valeur du nombre
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pile->SetVar( var ); // mis sur la pile
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return pj->Return(pile);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotExprAlpha::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( bMain ) pj->RestoreStack(this);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// compile un token repr<70>sentant true ou false
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotExprBool::CBotExprBool()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
name = "CBotExprBool";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotExprBool::~CBotExprBool()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotInstr* CBotExprBool::Compile(CBotToken* &p, CBotCStack* pStack)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotCStack* pStk = pStack->TokenStack();
|
|
|
|
|
CBotExprBool* inst = NULL;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( p->GivType() == ID_TRUE ||
|
|
|
|
|
p->GivType() == ID_FALSE )
|
|
|
|
|
{
|
|
|
|
|
inst = new CBotExprBool();
|
|
|
|
|
inst->SetToken(p); // m<>morise l'op<6F>ration false ou true
|
|
|
|
|
p = p->GivNext();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypBoolean);
|
|
|
|
|
pStk->SetVar(var);
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return pStack->Return(inst, pStk);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute, retourne true ou false
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotExprBool::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->AddStack(this);
|
|
|
|
|
// if ( pile == EOX ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->IfStep() ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypBoolean);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if (GivTokenType() == ID_TRUE) var->SetValInt(1);
|
|
|
|
|
else var->SetValInt(0);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pile->SetVar( var ); // mis sur la pile
|
|
|
|
|
return pj->Return(pile); // transmet en dessous
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotExprBool::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( bMain ) pj->RestoreStack(this);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// gestion de l'op<6F>rande "null"
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotExprNull::CBotExprNull()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
name = "CBotExprNull";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotExprNull::~CBotExprNull()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute, retourne un pointeur vide
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotExprNull::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->AddStack(this);
|
|
|
|
|
// if ( pile == EOX ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->IfStep() ) return false;
|
|
|
|
|
CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypNullPointer);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
var->SetInit(true); // pointeur null valide
|
|
|
|
|
pile->SetVar( var ); // mis sur la pile
|
|
|
|
|
return pj->Return(pile); // transmet en dessous
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotExprNull::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( bMain ) pj->RestoreStack(this);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// gestion de l'op<6F>rande "nan"
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotExprNan::CBotExprNan()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
name = "CBotExprNan";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotExprNan::~CBotExprNan()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute, retourne un pointeur vide
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotExprNan::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->AddStack(this);
|
|
|
|
|
// if ( pile == EOX ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->IfStep() ) return false;
|
|
|
|
|
CBotVar* var = CBotVar::Create((CBotToken*)NULL, CBotTypInt);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
var->SetInit(IS_NAN); // nombre nan
|
|
|
|
|
pile->SetVar( var ); // mis sur la pile
|
|
|
|
|
return pj->Return(pile); // transmet en dessous
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotExprNan::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( bMain ) pj->RestoreStack(this);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// compile un nom de variable
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// v<>rifie qu'elle est connue sur la pile
|
|
|
|
|
// et qu'elle a <20>t<EFBFBD> initialis<69>e
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotExprVar::CBotExprVar()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
name = "CBotExprVar";
|
|
|
|
|
m_nIdent = 0;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotExprVar::~CBotExprVar()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotInstr* CBotExprVar::Compile(CBotToken* &p, CBotCStack* pStack, int privat)
|
|
|
|
|
{
|
2012-07-04 20:14:28 +00:00
|
|
|
|
CBotToken* pDebut = p;
|
|
|
|
|
CBotCStack* pStk = pStack->TokenStack();
|
|
|
|
|
|
|
|
|
|
pStk->SetStartError(p->GivStart());
|
|
|
|
|
|
|
|
|
|
// is it a variable?
|
|
|
|
|
if (p->GivType() == TokenTypVar)
|
|
|
|
|
{
|
|
|
|
|
CBotInstr* inst = new CBotExprVar(); // create the object
|
|
|
|
|
|
|
|
|
|
inst->SetToken(p);
|
|
|
|
|
|
|
|
|
|
CBotVar* var;
|
|
|
|
|
|
|
|
|
|
if ( NULL != (var = pStk->FindVar(p)) ) // seek if known variable
|
|
|
|
|
{
|
|
|
|
|
int ident = var->GivUniqNum();
|
|
|
|
|
((CBotExprVar*)inst)->m_nIdent = ident; // identifies variable by its number
|
|
|
|
|
|
|
|
|
|
if (ident > 0 && ident < 9000)
|
|
|
|
|
{
|
|
|
|
|
if ( var->IsPrivate(privat) &&
|
|
|
|
|
!pStk->GivBotCall()->m_bCompileClass)
|
|
|
|
|
{
|
|
|
|
|
pStk->SetError( TX_PRIVATE, p );
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is an element of the current class
|
|
|
|
|
// ads the equivalent of this. before
|
|
|
|
|
/// \TODO need to be fixed revised and fixed after adding unit
|
2012-07-10 20:58:52 +00:00
|
|
|
|
///tests
|
2012-07-04 20:14:28 +00:00
|
|
|
|
CBotToken token("this");
|
|
|
|
|
inst->SetToken(&token);
|
|
|
|
|
((CBotExprVar*)inst)->m_nIdent = -2; // identificator for this
|
|
|
|
|
|
|
|
|
|
CBotFieldExpr* i = new CBotFieldExpr(); // new element
|
|
|
|
|
i->SetToken( p ); // keeps the name of the token
|
|
|
|
|
i->SetUniqNum(ident);
|
|
|
|
|
inst->AddNext3(i); // added after
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p = p->GivNext(); // next token
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if ( var->GivType() == CBotTypArrayPointer ) // s'il sagit d'un tableau
|
|
|
|
|
{
|
|
|
|
|
if ( IsOfType( p, ID_OPBRK ) ) // regarde s'il y a un index
|
|
|
|
|
{
|
|
|
|
|
CBotIndexExpr* i = new CBotIndexExpr();
|
|
|
|
|
i->m_expr = CBotExpression::Compile(p, pStk); // compile la formule
|
|
|
|
|
inst->AddNext3(i); // ajoute <20> la chaine
|
|
|
|
|
|
|
|
|
|
var = ((CBotVarArray*)var)->GivItem(0,true); // donne le composant [0]
|
|
|
|
|
|
|
|
|
|
if ( i->m_expr == NULL )
|
|
|
|
|
{
|
|
|
|
|
pStk->SetError( TX_BADINDEX, p->GivStart() );
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
if ( !pStk->IsOk() || !IsOfType( p, ID_CLBRK ) )
|
|
|
|
|
{
|
|
|
|
|
pStk->SetError( TX_CLBRK, p->GivStart() );
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//// pStk->SetError( TX_OPBRK, p->GivStart() );
|
|
|
|
|
}
|
|
|
|
|
if ( var->GivType(1) == CBotTypPointer ) // pour les classes
|
|
|
|
|
{
|
|
|
|
|
if ( IsOfType(p, ID_DOT) )
|
|
|
|
|
{
|
|
|
|
|
CBotToken* pp = p;
|
|
|
|
|
|
|
|
|
|
if ( p->GivType() == TokenTypVar ) // doit <20>tre un nom
|
|
|
|
|
{
|
|
|
|
|
if ( p->GivNext()->GivType() == ID_OPENPAR )// un appel de m<>thode ?
|
|
|
|
|
{
|
|
|
|
|
CBotInstr* i = CBotInstrMethode::Compile(p, pStk, var);
|
|
|
|
|
if ( !pStk->IsOk() ) goto err;
|
|
|
|
|
inst->AddNext3(i); // ajoute <20> la suite
|
|
|
|
|
return pStack->Return(inst, pStk);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CBotFieldExpr* i = new CBotFieldExpr(); // nouvel <20>l<EFBFBD>ment
|
|
|
|
|
i->SetToken( pp ); // garde le nom du token
|
|
|
|
|
inst->AddNext3(i); // ajoute <20> la suite
|
|
|
|
|
var = var->GivItem(p->GivString()); // r<>cup<75>re l'item correpondant
|
|
|
|
|
if ( var != NULL )
|
|
|
|
|
{
|
|
|
|
|
i->SetUniqNum(var->GivUniqNum());
|
|
|
|
|
if ( var->IsPrivate() &&
|
|
|
|
|
!pStk->GivBotCall()->m_bCompileClass)
|
|
|
|
|
{
|
|
|
|
|
pStk->SetError( TX_PRIVATE, pp );
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( var != NULL )
|
|
|
|
|
{
|
|
|
|
|
p = p->GivNext(); // saute le nom
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
pStk->SetError( TX_NOITEM, p );
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
pStk->SetError( TX_DOT, p->GivStart() );
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pStk->SetCopyVar(var); // place une copie de la variable sur la pile (pour le type)
|
|
|
|
|
if ( pStk->IsOk() ) return pStack->Return(inst, pStk);
|
|
|
|
|
}
|
|
|
|
|
pStk->SetError(TX_UNDEFVAR, p);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
err:
|
2012-07-04 20:14:28 +00:00
|
|
|
|
delete inst;
|
|
|
|
|
return pStack->Return(NULL, pStk);
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
return pStack->Return(NULL, pStk);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotInstr* CBotExprVar::CompileMethode(CBotToken* &p, CBotCStack* pStack)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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<63>e l'objet
|
|
|
|
|
|
|
|
|
|
// il s'agit d'un <20>lement de la classe courante
|
|
|
|
|
// ajoute l'<27>quivalent d'un this. devant
|
|
|
|
|
inst->SetToken(&pthis);
|
|
|
|
|
((CBotExprVar*)inst)->m_nIdent = -2; // ident pour this
|
|
|
|
|
|
|
|
|
|
CBotToken* pp = p;
|
|
|
|
|
|
|
|
|
|
if ( pp->GivType() == TokenTypVar ) // doit <20>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 <20> la suite
|
|
|
|
|
p = pp; // instructions pass<73>es
|
|
|
|
|
return pStack->Return(inst, pStk);
|
|
|
|
|
}
|
|
|
|
|
pStk->SetError(0,0); // l'erreur n'est pas trait<69>e ici
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
delete inst;
|
|
|
|
|
}
|
|
|
|
|
return pStack->Return(NULL, pStk);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute, rend la valeur d'une variable
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotExprVar::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* pVar = NULL;
|
|
|
|
|
CBotStack* pile = pj->AddStack(this);
|
|
|
|
|
// if ( pile == EOX ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// if ( pile->IfStep() ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile1 = pile;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile1->GivState() == 0 )
|
|
|
|
|
{
|
|
|
|
|
if ( !ExecuteVar(pVar, pile, NULL, true) ) return false; // r<>cup<75>re la variable selon champs et index
|
|
|
|
|
// DEBUG("CBotExprVar::Execute", 1 , pj);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pVar ) pile1->SetCopyVar(pVar); // la place une copie sur la pile
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//-- pile1->SetVar(NULL); // la pile contient d<>j<EFBFBD> le resultat (m<>thode)
|
|
|
|
|
return pj->Return(pile1);
|
|
|
|
|
}
|
|
|
|
|
pile1->IncState();
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pVar = pile1->GivVar(); // r<>cup<75>re si interrompu
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pVar == NULL )
|
|
|
|
|
{
|
|
|
|
|
// pile1->SetError(TX_NULLPT, &m_token);
|
|
|
|
|
return pj->Return(pile1);
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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<6F>ration faite
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotExprVar::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( !bMain ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->RestoreStack(this);
|
|
|
|
|
if ( pile == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile1 = pile;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile1->GivState() == 0 )
|
|
|
|
|
{
|
|
|
|
|
RestoreStateVar(pile, bMain); // r<>cup<75>re la variable selon champs et index
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// retrouve une variable <20> l'ex<65>cution
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotExprVar::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj;
|
|
|
|
|
pj = pj->AddStack( this );
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( bStep && m_nIdent>0 && pj->IfStep() ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pVar = pj->FindVar(m_nIdent, true); // cherche la variable avec mise <20> jour si n<>cessaire
|
|
|
|
|
if ( pVar == NULL )
|
|
|
|
|
{
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
ASM_TRAP();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
#endif
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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 ?
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return pile->ReturnKeep( pj ); // ne rend pas la pile mais r<>cup<75>re le r<>sultat si une m<>thode a <20>t<EFBFBD> appel<65>e
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// retrouve une variable <20> l'ex<65>cution
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotExprVar::RestoreStateVar(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pj = pj->RestoreStack( this );
|
|
|
|
|
if ( pj == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( m_next3 != NULL )
|
|
|
|
|
m_next3->RestoreStateVar(pj, bMain);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// compile une liste de param<61>tres
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
bool first = true;
|
|
|
|
|
CBotInstr* ret = NULL; // pour la liste <20> 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;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// compile un appel d'une m<>thode
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotInstrMethode::CBotInstrMethode()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
m_Parameters = NULL;
|
|
|
|
|
m_MethodeIdent = 0;
|
|
|
|
|
// m_nThisIdent = 0;
|
|
|
|
|
name = "CBotInstrMethode";
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotInstrMethode::~CBotInstrMethode()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete m_Parameters;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar* var)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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<61>tres
|
|
|
|
|
CBotVar* ppVars[1000];
|
|
|
|
|
inst->m_Parameters = CompileParams(p, pStack, ppVars);
|
|
|
|
|
|
|
|
|
|
if ( pStack->IsOk() )
|
|
|
|
|
{
|
|
|
|
|
CBotClass* pClass = var->GivClass(); // pointeur <20> 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<69>res les param<61>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;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute l'appel de m<>thode
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep, bool bExtend)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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<61>tres <20> venir
|
|
|
|
|
|
|
|
|
|
if ( pile1->GivState() == 0)
|
|
|
|
|
{
|
|
|
|
|
CBotVar* pThis = CBotVar::Create(pVar);
|
|
|
|
|
pThis->Copy(pVar);
|
|
|
|
|
// la valeur de This doit <20>tre prise avant l'<27>valuation des param<61>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;
|
|
|
|
|
// <20>value les param<61>tres
|
|
|
|
|
// et place les valeurs sur la pile
|
|
|
|
|
// pour pouvoir <20>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<73>ciale pour reconna<6E>re les param<61>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<69>re toute la pile
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( !bMain ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* ppVars[1000];
|
|
|
|
|
CBotStack* pile1 = pile->RestoreStack(this); // une place pour la copie de This
|
|
|
|
|
if ( pile1 == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile2 = pile1->RestoreStack(); // et pour les param<61>tres <20> venir
|
|
|
|
|
if ( pile2 == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* pThis = pile1->FindVar("this");
|
|
|
|
|
// pThis->SetUniqNum(m_nThisIdent);
|
|
|
|
|
pThis->SetUniqNum(-2);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
int i = 0;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotInstr* p = m_Parameters;
|
|
|
|
|
// <20>value les param<61>tres
|
|
|
|
|
// et place les valeurs sur la pile
|
|
|
|
|
// pour pouvoir <20>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;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
p = p->GivNext();
|
|
|
|
|
if ( p == NULL) break;
|
|
|
|
|
}
|
|
|
|
|
ppVars[i] = NULL;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotClass* pClass = CBotClass::Find(m_ClassName);
|
|
|
|
|
CBotVar* pResult = NULL;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* pRes = pResult;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pClass->RestoreMethode(m_MethodeIdent, m_NomMethod,
|
|
|
|
|
pThis, ppVars, pile2);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotInstrMethode::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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<61>tres <20> venir
|
|
|
|
|
|
|
|
|
|
if ( pile1->GivState() == 0)
|
|
|
|
|
{
|
|
|
|
|
CBotVar* pThis = pile1->CopyVar(m_token);
|
|
|
|
|
// la valeur de This doit <20>tre prise avant l'<27>valuation des param<61>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;
|
|
|
|
|
// <20>value les param<61>tres
|
|
|
|
|
// et place les valeurs sur la pile
|
|
|
|
|
// pour pouvoir <20>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<73>ciale pour reconna<6E>re les param<61>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 <20> 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<69>re toute la pile
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// compile une instruction "new"
|
|
|
|
|
|
|
|
|
|
CBotNew::CBotNew()
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
name = "CBotNew";
|
|
|
|
|
m_Parameters = NULL;
|
|
|
|
|
m_nMethodeIdent = 0;
|
|
|
|
|
// m_nThisIdent = 0;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotNew::~CBotNew()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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<63>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<63>ateur
|
|
|
|
|
CBotCStack* pStk = pStack->TokenStack();
|
|
|
|
|
{
|
|
|
|
|
// regarde s'il y a des param<61>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<69>re le suppl<70>ment de pile
|
|
|
|
|
int typ = r.GivType();
|
|
|
|
|
|
|
|
|
|
// s'il n'y a pas de constructeur, et pas de param<61>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<61>tres
|
|
|
|
|
if (typ<0 && inst->m_Parameters != NULL)
|
|
|
|
|
{
|
|
|
|
|
pStk->SetError(TX_NOCONST, &inst->m_vartoken);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// rend le pointeur <20> l'objet sur la pile
|
|
|
|
|
pStk->SetVar(pVar);
|
|
|
|
|
return pStack->Return(inst, pStk);
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
error:
|
2012-07-10 20:58:52 +00:00
|
|
|
|
delete inst;
|
|
|
|
|
return pStack->Return(NULL, pStk);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// ex<65>cute une instruction "new"
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool CBotNew::Execute(CBotStack* &pj)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->AddStack(this); //pile principale
|
|
|
|
|
// if ( pile == EOX ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->IfStep() ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile1 = pj->AddStack2(); //pile secondaire
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* pThis = NULL;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotToken* pt = &m_vartoken;
|
|
|
|
|
CBotClass* pClass = CBotClass::Find(pt);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// cr<63>e la variable "this" de type pointeur <20> l'objet
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->GivState()==0)
|
|
|
|
|
{
|
|
|
|
|
// cr<63>e une instance de la classe demand<6E>e
|
|
|
|
|
// et initialise le pointeur <20> cet objet
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pThis = CBotVar::Create("this", pClass);
|
|
|
|
|
// pThis->SetUniqNum( m_nThisIdent ) ;
|
|
|
|
|
pThis->SetUniqNum( -2 ) ;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pile1->SetVar(pThis); // la place sur la pile1
|
|
|
|
|
pile->IncState();
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// retrouve le pointeur this si on a <20>t<EFBFBD> interrompu
|
|
|
|
|
if ( pThis == NULL)
|
|
|
|
|
{
|
|
|
|
|
pThis = pile1->GivVar(); // retrouve le pointeur
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// y a-t-il une assignation ou des param<61>tres (constructeur)
|
|
|
|
|
if ( pile->GivState()==1)
|
|
|
|
|
{
|
|
|
|
|
// <20>value le constructeur de l'instance
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* ppVars[1000];
|
|
|
|
|
CBotStack* pile2 = pile;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
int i = 0;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotInstr* p = m_Parameters;
|
|
|
|
|
// <20>value les param<61>tres
|
|
|
|
|
// et place les valeurs sur la pile
|
|
|
|
|
// pour pouvoir <20>tre interrompu n'importe quand
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// cr<63>e une variable pour le r<>sultat
|
|
|
|
|
CBotVar* pResult = NULL; // constructeurs toujours void
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GivName(),
|
|
|
|
|
pThis, ppVars,
|
|
|
|
|
pResult, pile2, GivToken())) return false; // interrompu
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pThis->ConstructorSet(); // signale que le constructeur a <20>t<EFBFBD> appel<65>
|
|
|
|
|
// pile->Return(pile2); // lib<69>re un bout de pile
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// pile->IncState();
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return pj->Return( pile1 ); // transmet en dessous
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
void CBotNew::RestoreState(CBotStack* &pj, bool bMain)
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( !bMain ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile = pj->RestoreStack(this); //pile principale
|
|
|
|
|
if ( pile == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotStack* pile1 = pj->AddStack2(); //pile secondaire
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotToken* pt = &m_vartoken;
|
|
|
|
|
CBotClass* pClass = CBotClass::Find(pt);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// cr<63>e la variable "this" de type pointeur <20> l'objet
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( pile->GivState()==0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* pThis = pile1->GivVar(); // retrouve le pointeur
|
|
|
|
|
// pThis->SetUniqNum( m_nThisIdent );
|
|
|
|
|
pThis->SetUniqNum( -2 );
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
// y a-t-il une assignation ou des param<61>tres (constructeur)
|
|
|
|
|
if ( pile->GivState()==1)
|
|
|
|
|
{
|
|
|
|
|
// <20>value le constructeur de l'instance
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotVar* ppVars[1000];
|
|
|
|
|
CBotStack* pile2 = pile;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
int i = 0;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotInstr* p = m_Parameters;
|
|
|
|
|
// <20>value les param<61>tres
|
|
|
|
|
// et place les valeurs sur la pile
|
|
|
|
|
// pour pouvoir <20>tre interrompu n'importe quand
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( p != NULL) while ( true )
|
|
|
|
|
{
|
|
|
|
|
pile2 = pile2->RestoreStack(); // de la place sur la pile pour les r<>sultats
|
|
|
|
|
if ( pile2 == NULL ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
pClass->RestoreMethode(m_nMethodeIdent, m_vartoken.GivString(), pThis,
|
|
|
|
|
ppVars, pile2) ; // interrompu ici !
|
|
|
|
|
}
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// regarde si deux r<>sultats sont compatibles pour faire une op<6F>ration
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool TypeCompatible( CBotTypResult& type1, CBotTypResult& type2, int op )
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
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<61>nation de cha<68>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 <20> l'envers,
|
|
|
|
|
// l'op<6F>ration sera refus<75>e <20> l'ex<65>cution si le pointeur n'est pas compatible
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type1.SetType(max);
|
|
|
|
|
type2.SetType(max);
|
|
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// regarde si deux variables sont compatible pour un passage de param<61>tre
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-04 20:14:28 +00:00
|
|
|
|
bool TypesCompatibles( const CBotTypResult& type1, const CBotTypResult& type2 )
|
2012-03-08 18:32:05 +00:00
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
int t1 = type1.GivType();
|
|
|
|
|
int t2 = type2.GivType();
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( t1 == CBotTypIntrinsic ) t1 = CBotTypClass;
|
|
|
|
|
if ( t2 == CBotTypIntrinsic ) t2 = CBotTypClass;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
int max = (t1 > t2) ? t1 : t2;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( max == 99 ) return false; // un r<>sultat est void ?
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( max >= CBotTypBoolean )
|
|
|
|
|
{
|
|
|
|
|
if ( t2 != t1 ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( max == CBotTypArrayPointer )
|
|
|
|
|
return TypesCompatibles(type1.GivTypElem(), type2.GivTypElem());
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
if ( max == CBotTypClass || max == CBotTypPointer )
|
|
|
|
|
return type1.GivClass() == type2.GivClass() ;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return true ;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Gestion des fichiers
|
|
|
|
|
|
2012-03-19 11:44:39 +00:00
|
|
|
|
// n<>cessaire car il n'est pas possible de faire le fopen dans le programme principal
|
2012-03-08 18:32:05 +00:00
|
|
|
|
// et les fwrite ou fread dans une dll en utilisant le FILE* rendu.
|
|
|
|
|
|
|
|
|
|
FILE* fOpen(const char* name, const char* mode)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return fopen(name, mode);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int fClose(FILE* filehandle)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return fclose(filehandle);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t fWrite(const void *buffer, size_t elemsize, size_t length, FILE* filehandle)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return fwrite(buffer, elemsize, length, filehandle);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t fRead(void *buffer, size_t elemsize, size_t length, FILE* filehandle)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return fread(buffer, elemsize, length, filehandle);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t fWrite(const void *buffer, size_t length, FILE* filehandle)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return fwrite(buffer, 1, length, filehandle);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t fRead(void *buffer, size_t length, FILE* filehandle)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
return fread(buffer, 1, length, filehandle);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
#if false
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
CBotString num(int n)
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotString s;
|
|
|
|
|
if ( n<0 ) {n = -n; s += "-";}
|
|
|
|
|
if ( n > 9 )
|
|
|
|
|
{
|
|
|
|
|
s += num(n/10);
|
|
|
|
|
}
|
|
|
|
|
s += '0' + n%10;
|
|
|
|
|
return s;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern void DEBUG( const char* text, int val, CBotStack* pile )
|
|
|
|
|
{
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotProgram* p = pile->GivBotCall(true);
|
|
|
|
|
if ( !p->m_bDebugDD ) return;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
FILE* pf = fopen("CbotDebug.txt", "a");
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
fputs( text, pf );
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
CBotString v = " " + num(val) + "\n";
|
|
|
|
|
fputs( v, pf );
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
2012-07-10 20:58:52 +00:00
|
|
|
|
fclose( pf);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|