Dependency on WINAPI completely removed.

dev-ui
Zaba999 2012-07-10 22:58:52 +02:00
parent dbd62c96aa
commit 1910219518
9 changed files with 3582 additions and 3909 deletions

View File

@ -12,9 +12,10 @@ find_package(SDL_image REQUIRED)
# Build with debugging symbols # Build with debugging symbols
set(CMAKE_BUILD_TYPE debug) set(CMAKE_BUILD_TYPE debug)
# Global compile flags # Global compile flags
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall") set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall -std=gnu++0x")
set(CMAKE_CXX_FLAGS_DEBUG "-w -g -O0 -Wall") set(CMAKE_CXX_FLAGS_DEBUG "-w -g -O0 -Wall -std=gnu++0x")
# Subdirectory with sources # Subdirectory with sources
add_subdirectory(src bin) add_subdirectory(src bin)

View File

@ -13,29 +13,25 @@
// * // *
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/./////////////////////////////////////////////////////////////////////// // * along with this program. If not, see http://www.gnu.org/licenses/.///////////////////////////////////////////////////////////////////////
// Compilation of various instructions
// Compile all routines are static
// And return an object according to what was found as instruction
// Compiler principle: // compilation of various instructions
// compile all routines are static
// and return an object according to what was found as instruction
// compiler principle:
// compile the routines return an object of the class corresponding to the operation found // compile the routines return an object of the class corresponding to the operation found
// This is always a subclass of CBotInstr. // this is always a subclass of CBotInstr.
// (CBotInstr objects are never used directly) // (CBotInstr objects are never used directly)
// Compiles if the routine returns NULL is that the statement is false // compiles if the routine returns NULL is that the statement is false
// Or misunderstood. // or misunderstood.
// The error is then on the stack CBotCStack :: Isok () is false // the error is then on the stack CBotCStack :: Isok () is false
#include "CBot.h" #include "CBot.h"
// les divers constructeurs / destructeurs
// pour libérer tout selon l'arbre établi
CBotInstr::CBotInstr() CBotInstr::CBotInstr()
{ {
name = "CBotInstr"; name = "CBotInstr";
@ -53,15 +49,15 @@ CBotInstr::~CBotInstr()
delete m_next3b; delete m_next3b;
} }
// compteur de boucles imbriquées, // counter of nested loops,
// pour détermniner les break et continue valides // to determine the break and continue valid
// et liste des labels utilisables // list of labels used
int CBotInstr::m_LoopLvl = 0; int CBotInstr::m_LoopLvl = 0;
CBotStringArray CBotStringArray CBotInstr::m_labelLvl = CBotStringArray();
CBotInstr::m_labelLvl = CBotStringArray();
// ajoute un niveau avec un label // adds a level with a label
void CBotInstr::IncLvl(CBotString& label) void CBotInstr::IncLvl(CBotString& label)
{ {
m_labelLvl.SetSize(m_LoopLvl+1); m_labelLvl.SetSize(m_LoopLvl+1);
@ -69,7 +65,7 @@ void CBotInstr::IncLvl(CBotString& label)
m_LoopLvl++; m_LoopLvl++;
} }
// ajoute un niveau (instruction switch) // adds a level (switch statement)
void CBotInstr::IncLvl() void CBotInstr::IncLvl()
{ {
m_labelLvl.SetSize(m_LoopLvl+1); m_labelLvl.SetSize(m_LoopLvl+1);
@ -77,14 +73,14 @@ void CBotInstr::IncLvl()
m_LoopLvl++; m_LoopLvl++;
} }
// libère un niveau // free a level
void CBotInstr::DecLvl() void CBotInstr::DecLvl()
{ {
m_LoopLvl--; m_LoopLvl--;
m_labelLvl[m_LoopLvl].Empty(); m_labelLvl[m_LoopLvl].Empty();
} }
// controle la validité d'un break ou continu // control validity of break and continue
bool CBotInstr::ChkLvl(const CBotString& label, int type) bool CBotInstr::ChkLvl(const CBotString& label, int type)
{ {
int i = m_LoopLvl; int i = m_LoopLvl;
@ -104,30 +100,30 @@ bool CBotInstr::IsOfClass(CBotString n)
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// gestion de base de la classe CBotInstr // database management class CBotInstr
// définie le token correspondant à l'instruction // set the token corresponding to the instruction
void CBotInstr::SetToken(CBotToken* p) void CBotInstr::SetToken(CBotToken* p)
{ {
m_token = *p; m_token = *p;
} }
// rend le type du token associé à l'instruction // return the type of the token assicated with the instruction
int CBotInstr::GivTokenType() int CBotInstr::GivTokenType()
{ {
return m_token.GivType(); return m_token.GivType();
} }
// rend le token associé // return associated token
CBotToken* CBotInstr::GivToken() CBotToken* CBotInstr::GivToken()
{ {
return &m_token; return &m_token;
} }
// ajoute une instruction à la suite des autres // adds the statement following the other
void CBotInstr::AddNext(CBotInstr* n) void CBotInstr::AddNext(CBotInstr* n)
{ {
@ -150,7 +146,7 @@ void CBotInstr::AddNext3b(CBotInstr* n)
p->m_next3b = n; p->m_next3b = n;
} }
// donne l'instruction suivante // returns next statement
CBotInstr* CBotInstr::GivNext() CBotInstr* CBotInstr::GivNext()
{ {
@ -168,11 +164,12 @@ CBotInstr* CBotInstr::GivNext3b()
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// compile une instruction, qui peut être // compile an instruction which can be
// while, do, try, throw, if, for, switch, break, continu, return // while, do, try, throw, if, for, switch, break, continue, return
// int, float, boolean, string, // int, float, boolean, string,
// déclaration d'une instance d'une classe // declaration of an instance of a class
// expression quelconque // arbitrary expression
CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack)
{ {
@ -180,14 +177,14 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack)
if ( p == NULL ) return NULL; if ( p == NULL ) return NULL;
int type = p->GivType(); // quel est le prochaine token ? int type = p->GivType(); // what is the next token
// y a-t-il un label ? // is it a lable?
if ( IsOfType( pp, TokenTypVar ) && if ( IsOfType( pp, TokenTypVar ) &&
IsOfType( pp, ID_DOTS ) ) IsOfType( pp, ID_DOTS ) )
{ {
type = pp->GivType(); type = pp->GivType();
// seules ces instructions acceptent un label // these instructions accept only lable
if (!IsOfTypeList( pp, ID_WHILE, ID_FOR, ID_DO, ID_REPEAT, 0 )) if (!IsOfTypeList( pp, ID_WHILE, ID_FOR, ID_DO, ID_REPEAT, 0 ))
{ {
pStack->SetError(TX_LABEL, pp->GivStart()); pStack->SetError(TX_LABEL, pp->GivStart());
@ -195,7 +192,7 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack)
} }
} }
// appel la routine de compilation correspondant au token trouvé // call routine corresponding to the compilation token found
switch (type) switch (type)
{ {
case ID_WHILE: case ID_WHILE:
@ -259,15 +256,15 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack)
pStack->SetStartError(p->GivStart()); pStack->SetStartError(p->GivStart());
// ne doit pas être un mot réservé par DefineNum // ne doit pas être un mot réservé par DefineNum
if ( p->GivType() == TokenTypDef ) if (p->GivType() == TokenTypDef)
{ {
pStack->SetError(TX_RESERVED, p); pStack->SetError(TX_RESERVED, p);
return NULL; return NULL;
} }
// ce peut être une définition d'instance de class // this might be an instance of class definnition
CBotToken* ppp = p; CBotToken* ppp = p;
if ( IsOfType( ppp, TokenTypVar ) /* && IsOfType( ppp, TokenTypVar )*/ ) if (IsOfType( ppp, TokenTypVar ))
{ {
if ( CBotClass::Find(p) != NULL ) if ( CBotClass::Find(p) != NULL )
{ {
@ -3131,7 +3128,7 @@ CBotInstr* CBotExprVar::Compile(CBotToken* &p, CBotCStack* pStack, int privat)
// This is an element of the current class // This is an element of the current class
// ads the equivalent of this. before // ads the equivalent of this. before
/// \TODO need to be fixed revised and fixed after adding unit /// \TODO need to be fixed revised and fixed after adding unit
//tests ///tests
CBotToken token("this"); CBotToken token("this");
inst->SetToken(&token); inst->SetToken(&token);
((CBotExprVar*)inst)->m_nIdent = -2; // identificator for this ((CBotExprVar*)inst)->m_nIdent = -2; // identificator for this

View File

@ -1,279 +0,0 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// French (France) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)
#ifdef _WIN32
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE DISCARDABLE
BEGIN
ID_IF "if"
ID_ELSE "else"
ID_WHILE "while"
ID_DO "do"
ID_FOR "for"
ID_BREAK "break"
ID_CONTINUE "continue"
ID_SWITCH "switch"
ID_CASE "case"
ID_DEFAULT "default"
ID_TRY "try"
ID_THROW "throw"
ID_CATCH "catch"
ID_FINALLY "finally"
ID_TXT_AND "and"
ID_TXT_OR "or"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_DEBUGDD "STARTDEBUGDD"
ID_INT "int"
ID_FLOAT "float"
ID_BOOLEAN "boolean"
ID_STRING "string"
ID_VOID "void"
ID_BOOL "bool"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_TXT_NOT "not"
ID_RETURN "return"
ID_CLASS "class"
ID_EXTENDS "extends"
ID_SYNCHO "synchronized"
ID_NEW "new"
ID_PUBLIC "public"
ID_EXTERN "extern"
ID_FINAL "final"
ID_STATIC "static"
ID_PROTECTED "protected"
ID_PRIVATE "private"
ID_REPEAT "repeat"
END
STRINGTABLE DISCARDABLE
BEGIN
TX_OPENPAR "Il manque une parenthèse ouvrante."
TX_CLOSEPAR "Il manque une parenthèse fermante."
TX_NOTBOOL "L'expression doit être un boolean."
TX_UNDEFVAR "Variable non déclarée."
TX_BADLEFT "Assignation impossible."
TX_ENDOF "Terminateur point-virgule non trouvé."
TX_OUTCASE "Instruction ""case"" hors d'un bloc ""switch""."
TX_NOTERM "Instructions après la fin."
END
STRINGTABLE DISCARDABLE
BEGIN
TX_CLOSEBLK "Il manque la fin du bloc."
TX_ELSEWITHOUTIF "Instruction ""else"" sans ""if"" correspondant."
TX_OPENBLK "Début d'un bloc attendu."
TX_BADTYPE "Mauvais type de résultat pour l'assignation."
TX_REDEFVAR "Redéfinition d'une variable."
TX_BAD2TYPE "Les deux opérandes ne sont pas de types compatibles."
TX_UNDEFCALL "Routine inconnue."
TX_MISDOTS "Séparateur "" : "" attendu."
TX_WHILE "Manque le mot ""while""."
TX_BREAK "Instruction ""break"" en dehors d'une boucle."
TX_LABEL "Un label ne peut se placer que devant un ""for"", un ""while"" ou un ""do""."
TX_NOLABEL "Cette étiquette n'existe pas"
TX_NOCASE "Manque une instruction ""case""."
TX_BADNUM "Un nombre est attendu."
TX_VOID "Paramètre void."
TX_NOTYP "Déclaration de type attendu."
END
STRINGTABLE DISCARDABLE
BEGIN
TX_DIVZERO "Division par zéro."
TX_NOTINIT "Variable non initialisée."
TX_BADTHROW "Valeur négative refusée pour ""throw""."
TX_NORETVAL "La fonction n'a pas retourné de résultat"
TX_NORUN "Pas de fonction en exécution"
TX_NOCALL "Appel d'une fonction inexistante"
TX_NOCLASS "Cette classe n'existe pas"
TX_NULLPT "Pointeur nul."
TX_OPNAN "Opération sur un ""nan"""
TX_OUTARRAY "Accès hors du tableau"
TX_STACKOVER "Dépassement de la pile"
TX_DELETEDPT "Pointeur à un objet détruit"
TX_FILEOPEN "Ouverture du fichier impossible"
TX_NOTOPEN "Fichier pas ouvert"
TX_ERRREAD "Erreur de lecture"
TX_ERRWRITE "Erreur d'écriture"
END
STRINGTABLE DISCARDABLE
BEGIN
TX_NOVAR "Nom d'une variable attendu."
TX_NOFONC "Nom de la fonction attendu."
TX_OVERPARAM "Trop de paramètres."
TX_REDEF "Cette fonction existe déjà."
TX_LOWPARAM "Pas assez de paramètres."
TX_BADPARAM "Aucune fonction de ce nom n'accepte ce(s) type(s) de paramètre(s)."
TX_NUMPARAM "Aucune fonction de ce nom n'accepte ce nombre de paramètres."
TX_NOITEM "Cet élément n'existe pas dans cette classe."
TX_DOT "L'objet n'est pas une instance d'une classe."
TX_NOCONST "Il n'y a pas de constructeur approprié."
TX_REDEFCLASS "Cette classe existe déjà."
TX_CLBRK """ ] "" attendu."
TX_RESERVED "Ce mot est réservé."
TX_BADNEW "Mauvais argument pour ""new""."
TX_OPBRK """ [ "" attendu."
TX_BADSTRING "Une chaîne de caractère est attendue."
END
STRINGTABLE DISCARDABLE
BEGIN
TX_BADINDEX "Mauvais type d'index"
TX_PRIVATE "Membre privé de la classe"
TX_NOPUBLIC """public"" manque"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_OPENPAR "("
ID_CLOSEPAR ")"
ID_OPBLK "{"
ID_CLBLK "}"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_SEP ";"
ID_COMMA ","
ID_DOTS ":"
ID_DOT "."
ID_OPBRK "["
ID_CLBRK "]"
ID_DBLDOTS "::"
ID_LOGIC "?"
ID_ADD "+"
ID_SUB "-"
ID_MUL "*"
ID_DIV "/"
ID_ASS "="
ID_ASSADD "+="
ID_ASSSUB "-="
ID_ASSMUL "*="
END
STRINGTABLE DISCARDABLE
BEGIN
ID_TRUE "true"
ID_FALSE "false"
ID_NULL "null"
ID_NAN "nan"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_ASSDIV "/="
ID_ASSOR "|="
ID_ASSAND "&="
ID_ASSXOR "^="
ID_ASSSL "<<="
ID_ASSSR ">>>="
ID_ASSASR ">>="
ID_SL "<<"
ID_SR ">>>"
ID_ASR ">>"
ID_INC "++"
ID_DEC "--"
ID_LO "<"
ID_HI ">"
ID_LS "<="
ID_HS ">="
END
STRINGTABLE DISCARDABLE
BEGIN
ID_EQ "=="
ID_NE "!="
ID_AND "&"
ID_XOR "^"
ID_OR "|"
ID_LOG_AND "&&"
ID_LOG_OR "||"
ID_LOG_NOT "!"
ID_NOT "~"
ID_MODULO "%"
ID_POWER "**"
ID_ASSMODULO "%="
END
STRINGTABLE DISCARDABLE
BEGIN
TX_UNDEF "undefined"
TX_NAN "not a number"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_SUPER "super"
END
#endif // French (France) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@ -13,66 +13,68 @@
// * // *
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.//////////////////////////////////////////////////////////////////////// // * along with this program. If not, see http://www.gnu.org/licenses/.////////////////////////////////////////////////////////////////////////
// Librairie pour l'interprétation du language CBOT #ifndef _CBOTDLL_H_
// pour le jeu COLOBOT #define _CBOTDLL_H_
// /**
* \file CBotDll.h
* \brief Library for interpretation of CBOT language
*/
//#include "stdafx.h"
// #include <windows.h>
#include <stdio.h> #include <stdio.h>
#include "resource.h"
#include <map>
#include <cstring>
// #define DllExport __declspec( dllexport )
#define CBOTVERSION 104 #define CBOTVERSION 104
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// quelques classes définies par ailleurs // forward declaration of needed classes
class CBotToken; // programme transformé en "jetons" class CBotToken; // program turned into "tokens
class CBotStack; // pile pour l'exécution class CBotStack; // for the execution stack
class CBotClass; // classe d'object class CBotClass; // class of object
class CBotInstr; // instruction à exécuter class CBotInstr; // instruction to be executed
class CBotFunction; // les fonctions user class CBotFunction; // user functions
class CBotVar; // les variables class CBotVar; // variables
class CBotVarClass; // une instance de classe class CBotVarClass; // instance of class
class CBotVarPointer; // pointeur à une instance de classe class CBotVarPointer; // pointer to an instance of class
class CBotCall; // les fonctions class CBotCall; // fonctions
class CBotCallMethode; // les méthodes class CBotCallMethode; // methods
class CBotDefParam; // liste de paramètres class CBotDefParam; // parameter list
class CBotCStack; class CBotCStack; // stack
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Gestion des variables // Variables management
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// ces types sont calqués sur les types Java // ces types sont calqués sur les types Java
// ne pas changer l'ordre de ces types // ne pas changer l'ordre de ces types
/** \brief CBotType Defines known types. This types are modeled on Java types. Do not change the order of elements */
enum CBotType enum CBotType
{ {
CBotTypVoid = 0, // fonction retournant void CBotTypVoid = 0,
CBotTypByte = 1, //n // nombre entier ( 8 bits) CBotTypByte = 1,
CBotTypShort = 2, //n // nombre entier (16 bits) CBotTypShort = 2,
CBotTypChar = 3, //n // caractère "unicode" (16 bits) CBotTypChar = 3,
CBotTypInt = 4, // nombre entier (32 bits) CBotTypInt = 4,
CBotTypLong = 5, //n // nombre entier (64 bits) CBotTypLong = 5,
CBotTypFloat = 6, // nombre décimal (32 bits) CBotTypFloat = 6,
CBotTypDouble = 7, //n // nombre décimal (64 bits) CBotTypDouble = 7,
CBotTypBoolean = 8, // true ou false exclusivement CBotTypBoolean = 8,
CBotTypString = 9, // chaine de caractère CBotTypString = 9,
CBotTypArrayPointer = 10, // un tableau de variables CBotTypArrayPointer = 10, // array of variables
CBotTypArrayBody = 11, // idem mais crée l'instance CBotTypArrayBody = 11, // same but creates an instance
CBotTypPointer = 12, // pointeur à une instance CBotTypPointer = 12, // pointer to an instance
CBotTypNullPointer = 13, // pointeur null est spécial CBotTypNullPointer = 13, // null pointer is special
CBotTypClass = 15,
CBotTypClass = 15, // instance d'une classe CBotTypIntrinsic = 16 // instance of a class intrinsic
CBotTypIntrinsic = 16 // instance d'une classe intrinsèque
}; };
//n = non encore implémenté //n = non encore implémenté
// pour SetUserPtr lors de la suppression d'un objet // pour SetUserPtr lors de la suppression d'un objet
#define OBJECTDELETED ((void*)-1) #define OBJECTDELETED ((void*)-1)
@ -93,62 +95,47 @@ private:
public: public:
// divers constructeurs selon les besoins // divers constructeurs selon les besoins
//DllExport
CBotTypResult(int type); CBotTypResult(int type);
// pour les types simples (CBotTypInt à CBotTypString) // pour les types simples (CBotTypInt à CBotTypString)
//DllExport
CBotTypResult(int type, const char* name); CBotTypResult(int type, const char* name);
// pour les types pointeur et classe intrinsic // pour les types pointeur et classe intrinsic
//DllExport
CBotTypResult(int type, CBotClass* pClass); CBotTypResult(int type, CBotClass* pClass);
// idem à partir de l'instance d'une classe // idem à partir de l'instance d'une classe
//DllExport
CBotTypResult(int type, CBotTypResult elem); CBotTypResult(int type, CBotTypResult elem);
// pour les tableaux de variables // pour les tableaux de variables
//DllExport
CBotTypResult(const CBotTypResult& typ); CBotTypResult(const CBotTypResult& typ);
// pour les assignations // pour les assignations
//DllExport
CBotTypResult(); CBotTypResult();
// pour par défaut // pour par défaut
//DllExport
~CBotTypResult(); ~CBotTypResult();
//DllExport
int GivType(int mode = 0) const; int GivType(int mode = 0) const;
// rend le type CBotTyp* du résultat // rend le type CBotTyp* du résultat
void SetType(int n); void SetType(int n);
// modifie le type // modifie le type
//DllExport
CBotClass* GivClass() const; CBotClass* GivClass() const;
// rend le pointeur à la classe (pour les CBotTypClass, CBotTypPointer) // rend le pointeur à la classe (pour les CBotTypClass, CBotTypPointer)
//DllExport
int GivLimite() const; int GivLimite() const;
// rend la taille limite du tableau (CBotTypArray) // rend la taille limite du tableau (CBotTypArray)
//DllExport
void SetLimite(int n); void SetLimite(int n);
// fixe une limite au tableau // fixe une limite au tableau
void SetArray(int* max ); void SetArray(int* max );
// idem avec une liste de dimension (tableaux de tableaux) // idem avec une liste de dimension (tableaux de tableaux)
//DllExport
CBotTypResult& GivTypElem() const; CBotTypResult& GivTypElem() const;
// rend le type des éléments du tableau (CBotTypArray) // rend le type des éléments du tableau (CBotTypArray)
//DllExport
bool Compare(const CBotTypResult& typ) const; bool Compare(const CBotTypResult& typ) const;
// compare si les types sont compatibles // compare si les types sont compatibles
//DllExport
bool Eq(int type) const; bool Eq(int type) const;
// compare le type // compare le type
//DllExport
CBotTypResult& CBotTypResult&
operator=(const CBotTypResult& src); operator=(const CBotTypResult& src);
// copie un type complet dans un autre // copie un type complet dans un autre
@ -256,106 +243,74 @@ public:
class CBotString class CBotString
{ {
private:
char* m_ptr; // pointeur à la chaine
int m_lg; // longueur de la chaine
// static
// HINSTANCE m_hInstance;
public: public:
//DllExport
CBotString(); CBotString();
//DllExport
CBotString(const char* p); CBotString(const char* p);
//DllExport
CBotString(const CBotString& p); CBotString(const CBotString& p);
//DllExport
~CBotString(); ~CBotString();
//DllExport
void Empty(); void Empty();
//DllExport
bool IsEmpty() const; bool IsEmpty() const;
//DllExport
int GivLength(); int GivLength();
//DllExport
int Find(const char c); int Find(const char c);
//DllExport
int Find(const char* lpsz); int Find(const char* lpsz);
//DllExport
int ReverseFind(const char c); int ReverseFind(const char c);
//DllExport
int ReverseFind(const char* lpsz); int ReverseFind(const char* lpsz);
//DllExport
bool LoadString(unsigned int id); bool LoadString(unsigned int id);
//DllExport
CBotString Mid(int nFirst, int nCount) const; CBotString Mid(int nFirst, int nCount) const;
//DllExport
CBotString Mid(int nFirst) const; CBotString Mid(int nFirst) const;
//DllExport CBotString Mid(int start, int lg=-1);
CBotString Left(int nCount) const; CBotString Left(int nCount) const;
//DllExport
CBotString Right(int nCount) const; CBotString Right(int nCount) const;
int Compare(const char* lpsz) const;
void MakeUpper();
void MakeLower();
//DllExport
const CBotString&
operator=(const CBotString& stringSrc);
//DllExport
const CBotString&
operator=(const char ch);
//DllExport
const CBotString&
operator=(const char* pString);
//DllExport
const CBotString&
operator+(const CBotString& str);
//DllExport
friend CBotString
operator+(const CBotString& string, const char* lpsz);
//DllExport /**
const CBotString& * \brief Overloaded oprators to work on CBotString classes
operator+=(const char ch); */
//DllExport const CBotString& operator=(const CBotString& stringSrc);
const CBotString& const CBotString& operator=(const char ch);
operator+=(const CBotString& str); const CBotString& operator=(const char* pString);
//DllExport const CBotString& operator+(const CBotString& str);
friend CBotString operator+(const CBotString& string, const char* lpsz);
const CBotString& operator+=(const char ch);
const CBotString& operator+=(const CBotString& str);
bool operator==(const CBotString& str); bool operator==(const CBotString& str);
//DllExport
bool operator==(const char* p); bool operator==(const char* p);
//DllExport
bool operator!=(const CBotString& str); bool operator!=(const CBotString& str);
//DllExport
bool operator!=(const char* p); bool operator!=(const char* p);
//DllExport
bool operator>(const CBotString& str); bool operator>(const CBotString& str);
//DllExport
bool operator>(const char* p); bool operator>(const char* p);
//DllExport
bool operator>=(const CBotString& str); bool operator>=(const CBotString& str);
//DllExport
bool operator>=(const char* p); bool operator>=(const char* p);
//DllExport
bool operator<(const CBotString& str); bool operator<(const CBotString& str);
//DllExport
bool operator<(const char* p); bool operator<(const char* p);
//DllExport
bool operator<=(const CBotString& str); bool operator<=(const CBotString& str);
//DllExport
bool operator<=(const char* p); bool operator<=(const char* p);
//DllExport
operator const char*() const; // as a C string operator const char*() const; // as a C string
int Compare(const char* lpsz) const;
//DllExport private:
CBotString Mid(int start, int lg=-1);
//DllExport /** \brief Pointer to string */
void MakeUpper(); char* m_ptr;
//DllExport
void MakeLower(); /** \brief Length of the string */
int m_lg;
/** \brief Keeps the string corresponding to keyword ID */
static const std::map<EID, const char const *> s_keywordString;
/**
* \brief MapIdToString maps given ID to its string equivalent
* \param id Provided identifier
* \return string if found, else NullString
*/
static const char * MapIdToString(EID id);
}; };
@ -369,20 +324,13 @@ private:
CBotString* m_pData; // ^aux données CBotString* m_pData; // ^aux données
public: public:
//DllExport
CBotStringArray(); CBotStringArray();
//DllExport
~CBotStringArray(); ~CBotStringArray();
//DllExport
void SetSize(int nb); void SetSize(int nb);
//DllExport
int GivSize(); int GivSize();
//DllExport
void Add(const CBotString& str); void Add(const CBotString& str);
//DllExport
CBotString& operator[](int nIndex); CBotString& operator[](int nIndex);
//DllExport
CBotString& ElementAt(int nIndex); CBotString& ElementAt(int nIndex);
}; };
@ -423,30 +371,23 @@ public:
bool m_bCompileClass; bool m_bCompileClass;
public: public:
//DllExport
static static
void Init(); void Init();
// initialise le module (défini les mots clefs pour les erreurs) // initialise le module (défini les mots clefs pour les erreurs)
// doit être fait une fois (et une seule) au tout début // doit être fait une fois (et une seule) au tout début
//DllExport
static static
void Free(); void Free();
// libère les zones mémoires statiques // libère les zones mémoires statiques
//DllExport
static static
int GivVersion(); int GivVersion();
// donne la version de la librairie CBOT // donne la version de la librairie CBOT
//DllExport
CBotProgram(); CBotProgram();
//DllExport
CBotProgram(CBotVar* pInstance); CBotProgram(CBotVar* pInstance);
//DllExport
~CBotProgram(); ~CBotProgram();
//DllExport
bool Compile( const char* program, CBotStringArray& ListFonctions, void* pUser = NULL); bool Compile( const char* program, CBotStringArray& ListFonctions, void* pUser = NULL);
// compile le programme donné en texte // compile le programme donné en texte
// retourne false s'il y a une erreur à la compilation // retourne false s'il y a une erreur à la compilation
@ -454,51 +395,41 @@ public:
// ListFonctions retourne le nom des fonctions déclarées extern // ListFonctions retourne le nom des fonctions déclarées extern
// pUser permet de passer un pointeur pour les routines définies par AddFunction // pUser permet de passer un pointeur pour les routines définies par AddFunction
//DllExport
void SetIdent(long n); void SetIdent(long n);
// associe un identificateur avec l'instance CBotProgram // associe un identificateur avec l'instance CBotProgram
//DllExport
long GivIdent(); long GivIdent();
// redonne l'identificateur // redonne l'identificateur
//DllExport
int GivError(); int GivError();
//DllExport
bool GetError(int& code, int& start, int& end); bool GetError(int& code, int& start, int& end);
//DllExport
bool GetError(int& code, int& start, int& end, CBotProgram* &pProg); bool GetError(int& code, int& start, int& end, CBotProgram* &pProg);
// si true // si true
// donne l'erreur trouvée à la compilation // donne l'erreur trouvée à la compilation
// ou à l'exécution // ou à l'exécution
// start et end délimite le bloc où se trouve l'erreur // start et end délimite le bloc où se trouve l'erreur
// pProg permet de savoir dans quel "module" s'est produite l'erreur d'exécution // pProg permet de savoir dans quel "module" s'est produite l'erreur d'exécution
//DllExport
static static
CBotString GivErrorText(int code); CBotString GivErrorText(int code);
//DllExport
bool Start(const char* name); bool Start(const char* name);
// définie quelle fonction doit être exécutée // définie quelle fonction doit être exécutée
// retourne false si la fontion name n'est pas trouvée // retourne false si la fontion name n'est pas trouvée
// le programme ne fait rien, il faut appeller Run() pour cela // le programme ne fait rien, il faut appeller Run() pour cela
//DllExport
bool Run(void* pUser = NULL, int timer = -1); bool Run(void* pUser = NULL, int timer = -1);
// exécute le programme // exécute le programme
// retourne false si le programme a été suspendu // retourne false si le programme a été suspendu
// retourne true si le programme s'est terminé avec ou sans erreur // retourne true si le programme s'est terminé avec ou sans erreur
// timer = 0 permet de faire une avance pas à pas // timer = 0 permet de faire une avance pas à pas
//DllExport
bool GetRunPos(const char* &FunctionName, int &start, int &end); bool GetRunPos(const char* &FunctionName, int &start, int &end);
// donne la position dans le programme en exécution // donne la position dans le programme en exécution
// retourne false si on n'est pas en exécution (programme terminé) // retourne false si on n'est pas en exécution (programme terminé)
// FunctionName est un pointeur rendu sur le nom de la fonction // FunctionName est un pointeur rendu sur le nom de la fonction
// start et end la position dans le texte du token en traitement // start et end la position dans le texte du token en traitement
//DllExport
CBotVar* GivStackVars(const char* &FunctionName, int level); CBotVar* GivStackVars(const char* &FunctionName, int level);
// permet d'obtenir le pointeur aux variables sur la pile d'exécution // permet d'obtenir le pointeur aux variables sur la pile d'exécution
// level est un paramètre d'entrée, 0 pour le dernier niveau, -1, -2, etc pour les autres niveau // level est un paramètre d'entrée, 0 pour le dernier niveau, -1, -2, etc pour les autres niveau
@ -507,18 +438,15 @@ public:
// FunctionName donne le nom de la fonction où se trouvent ces variables // FunctionName donne le nom de la fonction où se trouvent ces variables
// FunctionName == NULL signifiant qu'on est plus dans le programme (selon level) // FunctionName == NULL signifiant qu'on est plus dans le programme (selon level)
//DllExport
void Stop(); void Stop();
// arrête l'exécution du programme // arrête l'exécution du programme
// quitte donc le mode "suspendu" // quitte donc le mode "suspendu"
//DllExport
static static
void SetTimer(int n); void SetTimer(int n);
// défini le nombre de pas (parties d'instructions) à faire // défini le nombre de pas (parties d'instructions) à faire
// dans Run() avant de rendre la main "false" // dans Run() avant de rendre la main "false"
//DllExport
static static
bool AddFunction(const char* name, bool AddFunction(const char* name,
bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser), bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
@ -526,21 +454,17 @@ public:
// cet appel permet d'ajouter de manière externe (**) // cet appel permet d'ajouter de manière externe (**)
// une nouvelle fonction utilisable par le programme CBot // une nouvelle fonction utilisable par le programme CBot
//DllExport
static static
bool DefineNum(const char* name, long val); bool DefineNum(const char* name, long val);
//DllExport
bool SaveState(FILE* pf); bool SaveState(FILE* pf);
// sauvegarde l'état d'exécution dans le fichier // sauvegarde l'état d'exécution dans le fichier
// le fichier doit avoir été ouvert avec l'appel fopen de cette dll // le fichier doit avoir été ouvert avec l'appel fopen de cette dll
// sinon le système plante // sinon le système plante
//DllExport
bool RestoreState(FILE* pf); bool RestoreState(FILE* pf);
// rétablie l'état de l'exécution depuis le fichier // rétablie l'état de l'exécution depuis le fichier
// le programme compilé doit évidemment être identique // le programme compilé doit évidemment être identique
//DllExport
bool GetPosition(const char* name, int& start, int& stop, bool GetPosition(const char* name, int& start, int& stop,
CBotGet modestart = GetPosExtern, CBotGet modestart = GetPosExtern,
CBotGet modestop = GetPosBloc); CBotGet modestop = GetPosBloc);
@ -555,13 +479,9 @@ public:
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// routines pour la gestion d'un fichier (FILE*) // routines pour la gestion d'un fichier (FILE*)
//DllExport
FILE* fOpen(const char* name, const char* mode); FILE* fOpen(const char* name, const char* mode);
//DllExport
int fClose(FILE* filehandle); int fClose(FILE* filehandle);
//DllExport
size_t fWrite(const void *buffer, size_t elemsize, size_t length, FILE* filehandle); size_t fWrite(const void *buffer, size_t elemsize, size_t length, FILE* filehandle);
//DllExport
size_t fRead(void *buffer, size_t elemsize, size_t length, FILE* filehandle); size_t fRead(void *buffer, size_t elemsize, size_t length, FILE* filehandle);
@ -614,7 +534,6 @@ bool rMoyenne(CBotVar* pVar, CBotVar* pResult, int& Exception)
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// Classe pour la gestion des variables // Classe pour la gestion des variables
// les méthodes marquées DllExport
// peuvent être utile à l'exterieur du module // peuvent être utile à l'exterieur du module
// ( il n'est pour l'instant pas prévu de pouvoir créer ces objets en externe ) // ( il n'est pour l'instant pas prévu de pouvoir créer ces objets en externe )
@ -662,18 +581,10 @@ public:
CBotVar(); CBotVar();
virtual ~CBotVar( ); // destructeur virtual ~CBotVar( ); // destructeur
/* //DllExport
static
CBotVar* Create( const char* name, int type, const char* ClassName = NULL);
// crée une variable selon son type,*/
//DllExport
static static
CBotVar* Create( const char* name, CBotTypResult type); CBotVar* Create( const char* name, CBotTypResult type);
// idem à partir du type complet // idem à partir du type complet
//DllExport
static static
CBotVar* Create( const char* name, CBotClass* pClass); CBotVar* Create( const char* name, CBotClass* pClass);
// idem pour une instance d'une classe connue // idem pour une instance d'une classe connue
@ -690,51 +601,38 @@ virtual ~CBotVar( ); // destructeur
CBotVar* Create( CBotVar* pVar ); CBotVar* Create( CBotVar* pVar );
//DllExport
void SetUserPtr(void* pUser); void SetUserPtr(void* pUser);
// associe un pointeur utilisateur à une instance // associe un pointeur utilisateur à une instance
//DllExport
virtual void SetIdent(long UniqId); virtual void SetIdent(long UniqId);
// associe un identificateur unique à une instance // associe un identificateur unique à une instance
// ( c'est à l'utilisateur de s'assurer que l'id est unique) // ( c'est à l'utilisateur de s'assurer que l'id est unique)
//DllExport
void* GivUserPtr(); void* GivUserPtr();
// rend le pointeur associé à la variable // rend le pointeur associé à la variable
//DllExport
CBotString GivName(); // le nom de la variable, s'il est connu CBotString GivName(); // le nom de la variable, s'il est connu
//////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////
void SetName(const char* name); // change le nom de la variable void SetName(const char* name); // change le nom de la variable
//DllExport
int GivType(int mode = 0); // rend le type de base (int) de la variable int GivType(int mode = 0); // rend le type de base (int) de la variable
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
//DllExport
CBotTypResult GivTypResult(int mode = 0); // rend le type complet de la variable CBotTypResult GivTypResult(int mode = 0); // rend le type complet de la variable
CBotToken* GivToken(); CBotToken* GivToken();
void SetType(CBotTypResult& type); void SetType(CBotTypResult& type);
//DllExport
void SetInit(int bInit); // met la variable dans l'état IS_UNDEF, IS_DEF, IS_NAN void SetInit(int bInit); // met la variable dans l'état IS_UNDEF, IS_DEF, IS_NAN
//DllExport
int GivInit(); // donne l'état de la variable int GivInit(); // donne l'état de la variable
//DllExport
void SetStatic(bool bStatic); void SetStatic(bool bStatic);
//DllExport
bool IsStatic(); bool IsStatic();
//DllExport
void SetPrivate(int mPrivate); void SetPrivate(int mPrivate);
//DllExport
bool IsPrivate(int mode = PR_PROTECT); bool IsPrivate(int mode = PR_PROTECT);
//DllExport
int GivPrivate(); int GivPrivate();
virtual virtual
@ -742,29 +640,23 @@ virtual ~CBotVar( ); // destructeur
void SetVal(CBotVar* var); // remprend une valeur void SetVal(CBotVar* var); // remprend une valeur
//DllExport
virtual virtual
CBotVar* GivItem(const char* name); // rend un élément d'une classe selon son nom (*) CBotVar* GivItem(const char* name); // rend un élément d'une classe selon son nom (*)
virtual virtual
CBotVar* GivItemRef(int nIdent); // idem à partir du n° ref CBotVar* GivItemRef(int nIdent); // idem à partir du n° ref
//DllExport
virtual virtual
CBotVar* GivItem(int row, bool bGrow = false); CBotVar* GivItem(int row, bool bGrow = false);
//DllExport
virtual virtual
CBotVar* GivItemList(); // donne la liste des éléments CBotVar* GivItemList(); // donne la liste des éléments
//DllExport
CBotVar* GivStaticVar(); // rend le pointeur à la variable si elle est statique CBotVar* GivStaticVar(); // rend le pointeur à la variable si elle est statique
//DllExport
bool IsElemOfClass(const char* name); bool IsElemOfClass(const char* name);
// dit si l'élément appartient à la classe "name" // dit si l'élément appartient à la classe "name"
// rend true si l'objet est d'une classe fille // rend true si l'objet est d'une classe fille
//DllExport
CBotVar* GivNext(); // prochaine variable dans la liste (paramètres) CBotVar* GivNext(); // prochaine variable dans la liste (paramètres)
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
@ -773,24 +665,19 @@ virtual ~CBotVar( ); // destructeur
virtual virtual
void Copy(CBotVar* pSrc, bool bName = true); // fait une copie de la variable void Copy(CBotVar* pSrc, bool bName = true); // fait une copie de la variable
//DllExport
virtual void SetValInt(int val, const char* name = NULL); virtual void SetValInt(int val, const char* name = NULL);
// initialise avec une valeur entière (#) // initialise avec une valeur entière (#)
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
//DllExport
virtual void SetValFloat(float val); // initialise avec une valeur réelle (#) virtual void SetValFloat(float val); // initialise avec une valeur réelle (#)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//DllExport
virtual void SetValString(const char* p);// initialise avec une valeur chaîne (#) virtual void SetValString(const char* p);// initialise avec une valeur chaîne (#)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//DllExport
virtual int GivValInt(); // demande la valeur entière (#) virtual int GivValInt(); // demande la valeur entière (#)
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
//DllExport
virtual float GivValFloat(); // demande la valeur réelle (#) virtual float GivValFloat(); // demande la valeur réelle (#)
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
@ -838,13 +725,11 @@ virtual ~CBotVar( ); // destructeur
virtual bool Save1State(FILE* pf); virtual bool Save1State(FILE* pf);
static bool RestoreState(FILE* pf, CBotVar* &pVar); static bool RestoreState(FILE* pf, CBotVar* &pVar);
//DllExport
void debug(); void debug();
// virtual // virtual
// CBotVar* GivMyThis(); // CBotVar* GivMyThis();
//DllExport
virtual virtual
void Maj(void* pUser = NULL, bool bContinue = true); void Maj(void* pUser = NULL, bool bContinue = true);
@ -901,34 +786,27 @@ private:
public: public:
bool m_IsDef; // marque si est définie ou pas encore bool m_IsDef; // marque si est définie ou pas encore
//DllExport
CBotClass( const char* name, CBotClass( const char* name,
CBotClass* pParent, bool bIntrinsic = false ); // constructeur CBotClass* pParent, bool bIntrinsic = false ); // constructeur
// Dès qu'une classe est créée, elle est connue // Dès qu'une classe est créée, elle est connue
// partout dans CBot // partout dans CBot
// le mode intrinsic donne une classe qui n'est pas gérée par des pointeurs // le mode intrinsic donne une classe qui n'est pas gérée par des pointeurs
//DllExport
~CBotClass( ); // destructeur ~CBotClass( ); // destructeur
//DllExport
bool AddFunction(const char* name, bool AddFunction(const char* name,
bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception), bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception),
CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar)); CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar));
// cet appel permet d'ajouter de manière externe (**) // cet appel permet d'ajouter de manière externe (**)
// une nouvelle méthode utilisable par les objets de cette classe // une nouvelle méthode utilisable par les objets de cette classe
//DllExport
bool AddUpdateFunc( void rMaj ( CBotVar* pThis, void* pUser ) ); bool AddUpdateFunc( void rMaj ( CBotVar* pThis, void* pUser ) );
// défini la routine qui sera appellée pour mettre à jour les élements de la classe // défini la routine qui sera appellée pour mettre à jour les élements de la classe
//DllExport
bool AddItem(CBotString name, CBotTypResult type, int mPrivate = PR_PUBLIC); bool AddItem(CBotString name, CBotTypResult type, int mPrivate = PR_PUBLIC);
// ajoute un élément à la classe // ajoute un élément à la classe
// //DllExport
// bool AddItem(CBotString name, CBotClass* pClass); // bool AddItem(CBotString name, CBotClass* pClass);
// idem pour des éléments appartenant à pClass // idem pour des éléments appartenant à pClass
//DllExport
bool AddItem(CBotVar* pVar); bool AddItem(CBotVar* pVar);
// idem en passant le pointeur à une instance d'une variable // idem en passant le pointeur à une instance d'une variable
// l'objet est pris tel quel, il ne faut donc pas le détruire // l'objet est pris tel quel, il ne faut donc pas le détruire
@ -938,20 +816,16 @@ public:
// idem en donnant un élément de type CBotVar // idem en donnant un élément de type CBotVar
void AddNext(CBotClass* pClass); void AddNext(CBotClass* pClass);
//DllExport
CBotString GivName(); // rend le nom de la classe CBotString GivName(); // rend le nom de la classe
//DllExport
CBotClass* GivParent(); // donne la classe père (ou NULL) CBotClass* GivParent(); // donne la classe père (ou NULL)
// dit si une classe est dérivée (Extends) d'une autre // dit si une classe est dérivée (Extends) d'une autre
// rend true aussi si les classes sont identiques // rend true aussi si les classes sont identiques
//DllExport
bool IsChildOf(CBotClass* pClass); bool IsChildOf(CBotClass* pClass);
static static
CBotClass* Find(CBotToken* &pToken); // trouve une classe d'après son nom CBotClass* Find(CBotToken* &pToken); // trouve une classe d'après son nom
//DllExport
static static
CBotClass* Find(const char* name); CBotClass* Find(const char* name);
@ -978,11 +852,9 @@ public:
static static
void Free(); void Free();
//DllExport
static static
bool SaveStaticState(FILE* pf); bool SaveStaticState(FILE* pf);
//DllExport
static static
bool RestoreStaticState(FILE* pf); bool RestoreStaticState(FILE* pf);
@ -1054,30 +926,21 @@ public:
// constructeur // constructeur
~CBotToken(); // destructeur ~CBotToken(); // destructeur
//DllExport
int GivType(); // rend le type du token int GivType(); // rend le type du token
//DllExport
CBotString& GivString(); // rend la chaine correspondant à ce token CBotString& GivString(); // rend la chaine correspondant à ce token
//DllExport
CBotString& GivSep(); // rend le séparateur suivant le token CBotString& GivSep(); // rend le séparateur suivant le token
//DllExport
int GivStart(); // position du début dans le texte int GivStart(); // position du début dans le texte
//DllExport
int GivEnd(); // position de fin dans le texte int GivEnd(); // position de fin dans le texte
//DllExport
CBotToken* GivNext(); // rend le suivant dans la liste CBotToken* GivNext(); // rend le suivant dans la liste
//DllExport
CBotToken* GivPrev(); // rend le Précédent dans la liste CBotToken* GivPrev(); // rend le Précédent dans la liste
//DllExport
static static
CBotToken* CompileTokens(const char* p, int& error); CBotToken* CompileTokens(const char* p, int& error);
// transforme tout le programme // transforme tout le programme
//DllExport
static static
void Delete(CBotToken* pToken); // libère la liste void Delete(CBotToken* pToken); // libère la liste
@ -1198,3 +1061,5 @@ bool rDoGoto( CBotVar* pVar, CBotVar* pResult, int& exception )
} }
#endif #endif
#endif //_CBOTDLL_H_

View File

@ -13,7 +13,12 @@
// * // *
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.////////////////////////////////////////////////////////////////////// // * along with this program. If not, see http://www.gnu.org/licenses/.//////////////////////////////////////////////////////////////////////
// gestion de la pile (stack)
/**
* \file CBotStack.cpp
* \brief Management of the stack
*/
#include "CBot.h" #include "CBot.h"
#include <cstdlib> #include <cstdlib>

View File

@ -13,34 +13,126 @@
// * // *
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.///////////////////////////////////////////////////// // * along with this program. If not, see http://www.gnu.org/licenses/./////////////////////////////////////////////////////
// gestion de chaine
// basé sur le CString de MFC //strings management
// mais moins complet
#include "CBot.h" #include "CBot.h"
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <algorithm> #include <algorithm>
/// TODO need to be implemented to be able to load library
// HINSTANCE CBotString::m_hInstance = (HINSTANCE)LoadLibrary("libCbot.dll"); // how to retrieve it otherwise ??
//Map is filled with id-string pars that are needed for CBot language parsing
const std::map<EID, const char const *> CBotString::s_keywordString =
{
{ID_IF, "if"},
{ID_ELSE, "else"},
{ID_WHILE, "while"},
{ID_DO, "do"},
{ID_FOR, "for"},
{ID_BREAK, "break"},
{ID_CONTINUE, "continue"},
{ID_SWITCH, "switch"},
{ID_CASE, "case"},
{ID_DEFAULT, "default"},
{ID_TRY, "try"},
{ID_THROW, "throw"},
{ID_CATCH, "catch"},
{ID_FINALLY, "finally"},
{ID_TXT_AND, "and"},
{ID_TXT_OR, "or"},
{ID_TXT_NOT, "not"},
{ID_RETURN, "return"},
{ID_CLASS, "class"},
{ID_EXTENDS, "extends"},
{ID_SYNCHO, "synchronized"},
{ID_NEW, "new"},
{ID_PUBLIC, "public"},
{ID_EXTERN, "extern"},
{ID_FINAL, "final"},
{ID_STATIC, "static"},
{ID_PROTECTED, "protected"},
{ID_PRIVATE, "private"},
{ID_REPEAT, "repeat"},
{ID_DEBUGDD, "STARTDEBUGDD"},
{ID_INT, "int"},
{ID_FLOAT, "float"},
{ID_BOOLEAN, "boolean"},
{ID_STRING, "string"},
{ID_VOID, "void"},
{ID_BOOL, "bool"},
{ID_TRUE, "true"},
{ID_FALSE, "false"},
{ID_NULL, "null"},
{ID_NAN, "nan"},
{ID_OPENPAR, "("},
{ID_CLOSEPAR, ")"},
{ID_OPBLK, "{"},
{ID_CLBLK, "}"},
{ID_SEP, "},"},
{ID_COMMA, ","},
{ID_DOTS, ":"},
{ID_DOT, "."},
{ID_OPBRK, "["},
{ID_CLBRK, "]"},
{ID_DBLDOTS, "::"},
{ID_LOGIC, "?"},
{ID_ADD, "+"},
{ID_SUB, "-"},
{ID_MUL, "*"},
{ID_DIV, "/"},
{ID_ASS, "="},
{ID_ASSADD, "+="},
{ID_ASSSUB, "-="},
{ID_ASSMUL, "*="},
{ID_ASSDIV, "/="},
{ID_ASSOR, "|="},
{ID_ASSAND, "&="},
{ID_ASSXOR, "^="},
{ID_ASSSL, "<<="},
{ID_ASSSR, ">>>="},
{ID_ASSASR, ">>="},
{ID_SL, "<<"},
{ID_SR, ">>"},
{ID_ASR, ">>"},
{ID_INC, "++"},
{ID_DEC, "--"},
{ID_LO, "<"},
{ID_HI, ">"},
{ID_LS, "<<"},
{ID_HS, ">="},
{ID_EQ, "=="},
{ID_NE, "!="},
{ID_AND, "&"},
{ID_XOR, "^"},
{ID_OR, "|"},
{ID_LOG_AND, "&&"},
{ID_LOG_OR, "||"},
{ID_LOG_NOT, "!"},
{ID_NOT, "~"},
{ID_MODULO, "%"},
{ID_POWER, "**"},
{ID_ASSMODULO, "%="},
{TX_UNDEF, "undefined"},
{TX_NAN, "not a number"},
{ID_SUPER, "super"}
};
CBotString::CBotString() CBotString::CBotString()
{ {
m_ptr = NULL; // chaine vide m_ptr = NULL;
m_lg = 0; m_lg = 0;
} }
CBotString::~CBotString() CBotString::~CBotString()
{ {
if (m_ptr != NULL) free(m_ptr); free(m_ptr); //we can call free on null pointer as it's save
} }
CBotString::CBotString(const char* p) CBotString::CBotString(const char* p)
{ {
m_lg = strlen( p ); m_lg = strlen(p);
m_ptr = NULL; m_ptr = NULL;
if (m_lg>0) if (m_lg>0)
@ -67,7 +159,7 @@ CBotString::CBotString(const CBotString& srcString)
int CBotString::GivLength() int CBotString::GivLength()
{ {
if ( m_ptr == NULL ) return 0; if (m_ptr == NULL) return 0;
return strlen( m_ptr ); return strlen( m_ptr );
} }
@ -75,70 +167,67 @@ int CBotString::GivLength()
CBotString CBotString::Left(int nCount) const CBotString CBotString::Left(int nCount) const
{ {
char chaine[2000]; char chain[2000];
int i; size_t i;
for (i = 0; i < m_lg && i < nCount && i < 1999; i++) for (i = 0; i < m_lg && i < nCount && i < 1999; ++i)
{ {
chaine[i] = m_ptr[i]; chain[i] = m_ptr[i];
} }
chaine[i] = 0 ; chain[i] = 0 ;
return CBotString( chaine ); return CBotString(chain);
} }
CBotString CBotString::Right(int nCount) const CBotString CBotString::Right(int nCount) const
{ {
char chaine[2000]; char chain[2000];
int i = m_lg - nCount; int i = m_lg - nCount;
if ( i < 0 ) i = 0; if ( i < 0 ) i = 0;
int j; size_t j;
for ( j = 0 ; i < m_lg && i < 1999; i++) for (size_t j = 0 ; i < m_lg && i < 1999; ++i)
{ {
chaine[j++] = m_ptr[i]; chain[j++] = m_ptr[i];
} }
chaine[j] = 0 ; chain[j] = 0 ;
return CBotString( chaine ); return CBotString(chain);
} }
CBotString CBotString::Mid(int nFirst, int nCount) const CBotString CBotString::Mid(int nFirst, int nCount) const
{ {
char chaine[2000]; char chain[2000];
int i; size_t i;
for (i = nFirst; i < m_lg && i < 1999 && i <= nFirst + nCount; ++i)
for ( i = nFirst; i < m_lg && i < 1999 && i <= nFirst + nCount; i++)
{ {
chaine[i] = m_ptr[i]; chain[i] = m_ptr[i];
} }
chaine[i] = 0 ; chain[i] = 0 ;
return CBotString( chaine ); return CBotString(chain);
} }
CBotString CBotString::Mid(int nFirst) const CBotString CBotString::Mid(int nFirst) const
{ {
char chaine[2000]; char chain[2000];
int i; size_t i;
for (i = nFirst; i < m_lg && i < 1999 ; ++i)
for ( i = nFirst; i < m_lg && i < 1999 ; i++)
{ {
chaine[i] = m_ptr[i]; chain[i] = m_ptr[i];
} }
chaine[i] = 0 ; chain[i] = 0 ;
return CBotString( chaine ); return CBotString(chain);
} }
int CBotString::Find(const char c) int CBotString::Find(const char c)
{ {
int i; for (size_t i = 0; i < m_lg; ++i)
for (i = 0; i < m_lg; i++)
{ {
if (m_ptr[i] == c) return i; if (m_ptr[i] == c) return i;
} }
@ -147,12 +236,11 @@ int CBotString::Find(const char c)
int CBotString::Find(const char * lpsz) int CBotString::Find(const char * lpsz)
{ {
int i, j;
int l = strlen(lpsz); int l = strlen(lpsz);
for (i = 0; i <= m_lg-l; i++) for (size_t i = 0; i <= m_lg-l; ++i)
{ {
for (j = 0; j < l; j++) for (size_t j = 0; j < l; ++j)
{ {
if (m_ptr[i+j] != lpsz[j]) goto bad; if (m_ptr[i+j] != lpsz[j]) goto bad;
} }
@ -165,7 +253,7 @@ bad:;
int CBotString::ReverseFind(const char c) int CBotString::ReverseFind(const char c)
{ {
int i; int i;
for (i = m_lg-1; i >= 0; i--) for (i = m_lg-1; i >= 0; --i)
{ {
if (m_ptr[i] == c) return i; if (m_ptr[i] == c) return i;
} }
@ -177,9 +265,9 @@ int CBotString::ReverseFind(const char * lpsz)
int i, j; int i, j;
int l = strlen(lpsz); int l = strlen(lpsz);
for (i = m_lg-l; i >= 0; i--) for (i = m_lg-l; i >= 0; --i)
{ {
for (j = 0; j < l; j++) for (j = 0; j < l; ++j)
{ {
if (m_ptr[i+j] != lpsz[j]) goto bad; if (m_ptr[i+j] != lpsz[j]) goto bad;
} }
@ -207,9 +295,7 @@ CBotString CBotString::Mid(int start, int lg)
void CBotString::MakeUpper() void CBotString::MakeUpper()
{ {
int i; for (size_t i = 0; i < m_lg && i < 1999 ; ++i)
for ( i = 0; i < m_lg && i < 1999 ; i++)
{ {
char c = m_ptr[i]; char c = m_ptr[i];
if ( c >= 'a' && c <= 'z' ) m_ptr[i] = c - 'a' + 'A'; if ( c >= 'a' && c <= 'z' ) m_ptr[i] = c - 'a' + 'A';
@ -218,32 +304,25 @@ void CBotString::MakeUpper()
void CBotString::MakeLower() void CBotString::MakeLower()
{ {
int i; for (size_t i = 0; i < m_lg && i < 1999 ; ++i)
for ( i = 0; i < m_lg && i < 1999 ; i++)
{ {
char c = m_ptr[i]; char c = m_ptr[i];
if ( c >= 'A' && c <= 'Z' ) m_ptr[i] = c - 'A' + 'a'; if ( c >= 'A' && c <= 'Z' ) m_ptr[i] = c - 'A' + 'a';
} }
} }
#define MAXSTRING 256
bool CBotString::LoadString(unsigned int id) bool CBotString::LoadString(unsigned int id)
{ {
char buffer[MAXSTRING]; const char * str = NULL;
/// \TODO implement loading strings from resources. Figure out how to do it str = MapIdToString((EID)id);
// m_lg = ::LoadString( m_hInstance, id, buffer, MAXSTRING );
if (m_ptr != NULL) free(m_ptr); if (m_ptr != NULL) free(m_ptr);
m_lg = strlen(str);
m_ptr = NULL; m_ptr = NULL;
if (m_lg > 0) if (m_lg > 0)
{ {
m_ptr = (char*)malloc(m_lg+1); m_ptr = (char*)malloc(m_lg+1);
strcpy(m_ptr, buffer); strcpy(m_ptr, str);
return true; return true;
} }
return false; return false;
@ -252,10 +331,10 @@ bool CBotString::LoadString(unsigned int id)
const CBotString& CBotString::operator=(const CBotString& stringSrc) const CBotString& CBotString::operator=(const CBotString& stringSrc)
{ {
if (m_ptr != NULL) free(m_ptr); free(m_ptr);
m_ptr = NULL;
m_lg = stringSrc.m_lg; m_lg = stringSrc.m_lg;
m_ptr = NULL;
if (m_lg > 0) if (m_lg > 0)
{ {
@ -268,7 +347,7 @@ const CBotString& CBotString::operator=(const CBotString& stringSrc)
CBotString operator+(const CBotString& string, const char * lpsz) CBotString operator+(const CBotString& string, const char * lpsz)
{ {
CBotString s ( string ); CBotString s(string);
s += lpsz; s += lpsz;
return s; return s;
} }
@ -281,7 +360,7 @@ const CBotString& CBotString::operator+(const CBotString& stringSrc)
char* pp = p + m_lg; char* pp = p + m_lg;
strcpy(pp, stringSrc.m_ptr); strcpy(pp, stringSrc.m_ptr);
if (m_ptr != NULL) free(m_ptr); free(m_ptr);
m_ptr = p; m_ptr = p;
m_lg += stringSrc.m_lg; m_lg += stringSrc.m_lg;
@ -290,7 +369,7 @@ const CBotString& CBotString::operator+(const CBotString& stringSrc)
const CBotString& CBotString::operator=(const char ch) const CBotString& CBotString::operator=(const char ch)
{ {
if (m_ptr != NULL) free(m_ptr); free(m_ptr);
m_lg = 1; m_lg = 1;
@ -303,10 +382,10 @@ const CBotString& CBotString::operator=(const char ch)
const CBotString& CBotString::operator=(const char* pString) const CBotString& CBotString::operator=(const char* pString)
{ {
if (m_ptr != NULL) free(m_ptr); free(m_ptr);
m_ptr = NULL; m_ptr = NULL;
if ( pString != NULL ) if (pString != NULL)
{ {
m_lg = strlen(pString); m_lg = strlen(pString);
@ -329,7 +408,7 @@ const CBotString& CBotString::operator+=(const char ch)
p[m_lg++] = ch; p[m_lg++] = ch;
p[m_lg] = 0; p[m_lg] = 0;
if (m_ptr != NULL) free(m_ptr); free(m_ptr);
m_ptr = p; m_ptr = p;
@ -346,7 +425,7 @@ const CBotString& CBotString::operator+=(const CBotString& str)
m_lg = m_lg + str.m_lg; m_lg = m_lg + str.m_lg;
if (m_ptr != NULL) free(m_ptr); free(m_ptr);
m_ptr = p; m_ptr = p;
@ -420,7 +499,7 @@ bool CBotString::IsEmpty() const
void CBotString::Empty() void CBotString::Empty()
{ {
if (m_ptr != NULL) free(m_ptr); free(m_ptr);
m_ptr = NULL; m_ptr = NULL;
m_lg = 0; m_lg = 0;
} }
@ -442,10 +521,20 @@ int CBotString::Compare(const char * lpsz) const
return strcmp(p, lpsz); // wcscmp return strcmp(p, lpsz); // wcscmp
} }
const char * CBotString::MapIdToString(EID id)
{
if (s_keywordString.find(id) != s_keywordString.end())
{
return s_keywordString.at(id);
}
else
{
return emptyString;
}
}
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// tableaux de chaines // arrays of strings
CBotStringArray::CBotStringArray() CBotStringArray::CBotStringArray()
{ {
@ -455,7 +544,7 @@ CBotStringArray::CBotStringArray()
CBotStringArray::~CBotStringArray() CBotStringArray::~CBotStringArray()
{ {
SetSize(0); // détruit les données ! SetSize(0); // destroys data !
} }
@ -471,9 +560,8 @@ void CBotStringArray::Add(const CBotString& str)
m_pData[m_nSize-1] = str; m_pData[m_nSize-1] = str;
} }
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
// routines utilitaires // utility routines
static inline void ConstructElement(CBotString* pNewData) static inline void ConstructElement(CBotString* pNewData)
{ {
@ -520,7 +608,7 @@ static void CopyElements(CBotString* pDest, CBotString* pSrc, int nCount)
// sélect la taille du tableau // set the array size
void CBotStringArray::SetSize(int nNewSize) void CBotStringArray::SetSize(int nNewSize)
{ {
@ -582,7 +670,7 @@ void CBotStringArray::SetSize(int nNewSize)
ConstructElements(&pNewData[m_nSize], nNewSize-m_nSize); ConstructElements(&pNewData[m_nSize], nNewSize-m_nSize);
// Ret rid of old stuff (note: no destructors called) // Get rid of old stuff (note: no destructors called)
delete[] (unsigned char *)m_pData; delete[] (unsigned char *)m_pData;
m_pData = pNewData; m_pData = pNewData;
m_nSize = nNewSize; m_nSize = nNewSize;
@ -601,5 +689,3 @@ CBotString& CBotStringArray::ElementAt(int nIndex)
return m_pData[nIndex]; return m_pData[nIndex];
} }

View File

@ -464,6 +464,7 @@ bool CBotToken::GivKeyDefNum(const char* w, CBotToken* &token)
// reprend la liste des mots clefs dans les ressources // reprend la liste des mots clefs dans les ressources
/// \todo Fixme Figure out how this should work.
void CBotToken::LoadKeyWords() void CBotToken::LoadKeyWords()
{ {
CBotString s; CBotString s;

View File

@ -10,7 +10,6 @@ CBotToken.cpp
CBotTwoOpExpr.cpp CBotTwoOpExpr.cpp
CBotVar.cpp CBotVar.cpp
CBotWhile.cpp CBotWhile.cpp
CBot.rc
) )
add_library(CBot SHARED ${SOURCES}) add_library(CBot SHARED ${SOURCES})

View File

@ -15,98 +15,105 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.//{{NO_DEPENDENCIES}} // * along with this program. If not, see http://www.gnu.org/licenses/.//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file. // Microsoft Developer Studio generated include file.
// Used by CBot.rc // Used by CBot.rc
// #ifndef _RESOURCE_H_
#define ID_KEYWORDS 2000 #define _RESOURCE_H_
#define ID_IF 2000
#define ID_ELSE 2001 enum EID
#define ID_WHILE 2002 {
#define ID_DO 2003 ID_IF = 2000,
#define ID_FOR 2004 ID_ELSE,
#define ID_BREAK 2005 ID_WHILE,
#define ID_CONTINUE 2006 ID_DO,
#define ID_SWITCH 2007 ID_FOR,
#define ID_CASE 2008 ID_BREAK,
#define ID_DEFAULT 2009 ID_CONTINUE,
#define ID_TRY 2010 ID_SWITCH,
#define ID_THROW 2011 ID_CASE,
#define ID_CATCH 2012 ID_DEFAULT,
#define ID_FINALLY 2013 ID_TRY,
#define ID_TXT_AND 2014 ID_THROW,
#define ID_TXT_OR 2015 ID_CATCH,
#define ID_TXT_NOT 2016 ID_FINALLY,
#define ID_RETURN 2017 ID_TXT_AND,
#define ID_CLASS 2018 ID_TXT_OR,
#define ID_EXTENDS 2019 ID_TXT_NOT,
#define ID_SYNCHO 2020 ID_RETURN,
#define ID_NEW 2021 ID_CLASS,
#define ID_PUBLIC 2022 ID_EXTENDS,
#define ID_EXTERN 2023 ID_SYNCHO,
#define ID_FINAL 2024 ID_NEW,
#define ID_STATIC 2025 ID_PUBLIC,
#define ID_PROTECTED 2026 ID_EXTERN,
#define ID_PRIVATE 2027 ID_FINAL,
#define ID_REPEAT 2028 ID_STATIC,
#define ID_DEBUGDD 2099 ID_PROTECTED,
#define ID_INT 2100 ID_PRIVATE,
#define ID_FLOAT 2101 ID_REPEAT,
#define ID_BOOLEAN 2102 ID_DEBUGDD,
#define ID_STRING 2103 ID_INT,
#define ID_VOID 2104 ID_FLOAT,
#define ID_BOOL 2105 ID_BOOLEAN,
#define ID_TRUE 2200 ID_STRING,
#define ID_FALSE 2201 ID_VOID,
#define ID_NULL 2202 ID_BOOL,
#define ID_NAN 2203
#define ID_OPENPAR 2300 ID_TRUE = 2200,
#define ID_CLOSEPAR 2301 ID_FALSE,
#define ID_OPBLK 2302 ID_NULL,
#define ID_CLBLK 2303 ID_NAN,
#define ID_SEP 2304
#define ID_COMMA 2305 ID_OPENPAR = 2300,
#define ID_DOTS 2306 ID_CLOSEPAR,
#define ID_DOT 2307 ID_OPBLK,
#define ID_OPBRK 2308 ID_CLBLK,
#define ID_CLBRK 2309 ID_SEP,
#define ID_DBLDOTS 2310 ID_COMMA,
#define ID_LOGIC 2311 ID_DOTS,
#define ID_ADD 2312 ID_DOT,
#define ID_SUB 2313 ID_OPBRK,
#define ID_MUL 2314 ID_CLBRK,
#define ID_DIV 2315 ID_DBLDOTS,
#define ID_ASS 2316 ID_LOGIC,
#define ID_ASSADD 2317 ID_ADD,
#define ID_ASSSUB 2318 ID_SUB,
#define ID_ASSMUL 2319 ID_MUL,
#define ID_ASSDIV 2320 ID_DIV,
#define ID_ASSOR 2321 ID_ASS,
#define ID_ASSAND 2322 ID_ASSADD,
#define ID_ASSXOR 2323 ID_ASSSUB,
#define ID_ASSSL 2324 ID_ASSMUL,
#define ID_ASSSR 2325 ID_ASSDIV,
#define ID_ASSASR 2326 ID_ASSOR,
#define ID_SL 2327 ID_ASSAND,
#define ID_SR 2328 ID_ASSXOR,
#define ID_ASR 2329 ID_ASSSL,
#define ID_INC 2330 ID_ASSSR,
#define ID_DEC 2331 ID_ASSASR,
#define ID_LO 2332 ID_SL,
#define ID_HI 2333 ID_SR,
#define ID_LS 2334 ID_ASR,
#define ID_HS 2335 ID_INC,
#define ID_EQ 2336 ID_DEC,
#define ID_NE 2337 ID_LO,
#define ID_AND 2338 ID_HI,
#define ID_XOR 2339 ID_LS,
#define ID_OR 2340 ID_HS,
#define ID_LOG_AND 2341 ID_EQ,
#define ID_LOG_OR 2342 ID_NE,
#define ID_LOG_NOT 2343 ID_AND,
#define ID_NOT 2344 ID_XOR,
#define ID_MODULO 2345 ID_OR,
#define ID_POWER 2346 ID_LOG_AND,
#define ID_ASSMODULO 2347 ID_LOG_OR,
#define TX_UNDEF 4000 ID_LOG_NOT,
#define TX_NAN 4001 ID_NOT,
ID_MODULO,
ID_POWER,
ID_ASSMODULO,
TX_UNDEF = 4000,
TX_NAN,
ID_SUPER = 6000
};
#define TX_OPENPAR 5000 #define TX_OPENPAR 5000
#define TX_CLOSEPAR 5001 #define TX_CLOSEPAR 5001
#define TX_NOTBOOL 5002 #define TX_NOTBOOL 5002
@ -166,15 +173,6 @@
#define TX_NOTOPEN 6013 #define TX_NOTOPEN 6013
#define TX_ERRREAD 6014 #define TX_ERRREAD 6014
#define TX_ERRWRITE 6015 #define TX_ERRWRITE 6015
#define ID_SUPER 62020
// Next default values for new objects #endif //_RESOURCE_H_
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif