[colobot] 107/377: Moving CBotProgram class in its own header and source files.

Didier Raboud odyx at moszumanska.debian.org
Wed Mar 30 13:34:03 UTC 2016


This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch debian/master
in repository colobot.

commit 70dc6785f2fecd4b03e60c0f78e092e55842fb93
Author: Grunaka <dev at romainbreton.fr>
Date:   Sun Nov 15 18:05:35 2015 +0100

    Moving CBotProgram class in its own header and source files.
---
 src/CBot/CBot.h          |   1 +
 src/CBot/CBotClass.h     |   2 +
 src/CBot/CBotDll.h       | 128 -----------------------
 src/CBot/CBotProgram.cpp | 172 ++++++++++++++++++-------------
 src/CBot/CBotProgram.h   | 260 +++++++++++++++++++++++++++++++++++++++++++++++
 src/script/script.h      |   2 +
 6 files changed, 366 insertions(+), 199 deletions(-)

diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index c5fc9de..e98a1c6 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -28,6 +28,7 @@
 #include "resource.h"
 #include "CBotDll.h"                    // public definitions
 #include "CBotToken.h"                  // token management
+#include "CBotProgram.h"
 
 #define    STACKMEM    1                /// \def preserve memory for the execution stack
 #define    MAXSTACK    990              /// \def stack size reserved
diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h
index e2bc000..3cc4f9f 100644
--- a/src/CBot/CBotClass.h
+++ b/src/CBot/CBotClass.h
@@ -22,6 +22,8 @@
 // Modules inlcude
 #include "CBotDll.h"
 
+#include "CBotProgram.h"
+
 // Local include
 
 // Global include
diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h
index c1e8b69..6bd1603 100644
--- a/src/CBot/CBotDll.h
+++ b/src/CBot/CBotDll.h
@@ -440,134 +440,6 @@ public:
     CBotString&        ElementAt(int nIndex);
 };
 
-////////////////////////////////////////////////////////////////////
-// main class managing CBot program
-//
-
-class CBotProgram
-{
-private:
-    CBotFunction*    m_Prog;            // the user-defined functions
-    CBotFunction*    m_pRun;            // the basic function for the execution
-    CBotClass*        m_pClass;        // classes defined in this part
-    CBotStack*        m_pStack;        // execution stack
-    CBotVar*        m_pInstance;    // instance of the parent class
-    friend class    CBotFunction;
-
-    int                m_ErrorCode;
-    int                m_ErrorStart;
-    int                m_ErrorEnd;
-
-    long            m_Ident;        // associated identifier
-
-public:
-    bool m_bCompileClass;
-
-public:
-    static void Init();
-    //                initializes the module (defined keywords for errors)
-    //                should be done once (and only one) at the beginning
-    static
-    void            Free();
-    //                frees the static memory areas
-
-    static
-    int                GetVersion();
-    //                gives the version of the library CBOT
-
-
-                    CBotProgram();
-                    CBotProgram(CBotVar* pInstance);
-                    ~CBotProgram();
-
-    bool            Compile( const char* program, CBotStringArray& ListFonctions, void* pUser = nullptr);
-    //                compiles the program given in text
-    //                returns false if an error at compile
-    //                see GetCompileError () to retrieve the error
-    //                ListFonctions returns the names of functions declared as extern
-    //                pUser can pass a pointer to routines defined by AddFunction
-
-    void            SetIdent(long n);
-    //                associates an identifier with the instance CBotProgram
-
-    long            GetIdent();
-    //                gives the identifier
-
-    int                GetError();
-    bool            GetError(int& code, int& start, int& end);
-    bool            GetError(int& code, int& start, int& end, CBotProgram* &pProg);
-    //                if true
-    //                gives the error found in the compilation
-    //                or execution
-    //                delimits the start and end block where the error
-    //                pProg lets you know what "module" has produced runtime error
-    static         CBotString        GetErrorText(int code);
-
-
-    bool            Start(const char* name);
-    //                defines what function should be executed
-    //                returns false if the funtion name is not found
-    //                the program does nothing, we must call Run () for this
-
-    bool            Run(void* pUser = nullptr, int timer = -1);
-    //                executes the program
-    //                returns false if the program was suspended
-    //                returns true if the program ended with or without error
-    //                timer = 0 allows to advance step by step
-
-    bool            GetRunPos(const char* &FunctionName, int &start, int &end);
-    //                gives the position in the executing program
-    //                returns false if it is not running (program completion)
-    //                FunctionName is a pointer made to the name of the function
-    //                start and end position in the text of the token processing
-
-    CBotVar*        GetStackVars(const char* &FunctionName, int level);
-    //                provides the pointer to the variables on the execution stack
-    //                level is an input parameter,  0 for the last level, -1, -2, etc. for the other levels
-    //                the return value (CBotVar *) is a variable list (or nullptr)
-    //                    that can be processed as the list of parameters received by a routine
-    //                FunctionName gives the name of the function where are these variables
-    //                FunctionName == nullptr means that is more in a program (depending on  level)
-
-    void            Stop();
-    //                stops execution of the program
-    //                therefore quits "suspend" mode
-
-    static
-    void            SetTimer(int n);
-    //                defines the number of steps (parts of instructions) to done
-    //                in Run() before rendering hand "false" \TODO avant de rendre la main "false"
-
-    static
-    bool            AddFunction(const char* name,
-                                bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
-                                CBotTypResult rCompile (CBotVar* &pVar, void* pUser));
-    //                call this to add externally (**)
-    //                a new function used by the program CBoT
-
-    static
-    bool            DefineNum(const char* name, long val);
-
-    bool            SaveState(FILE* pf);
-    //                backup the execution status in the file
-    //                the file must have been opened with the fopen call this dll (\TODO this library??)
-    //                if the system crashes
-    bool            RestoreState(FILE* pf);
-    //                restores the state of execution from file
-    //                the compiled program must obviously be the same
-
-    bool            GetPosition(const char* name, int& start, int& stop,
-                                CBotGet modestart = GetPosExtern,
-                                CBotGet modestop  = GetPosBloc);
-    //                gives the position of a routine in the original text
-    //                the user can select the item to find from the beginning to the end
-    //                see the above modes in CBotGet
-
-
-    CBotFunction*    GetFunctions();
-};
-
-
 ///////////////////////////////////////////////////////////////////////////////
 // routines for file management  (* FILE)
     FILE*        fOpen(const char* name, const char* mode);
diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp
index 27485f8..23752d5 100644
--- a/src/CBot/CBotProgram.cpp
+++ b/src/CBot/CBotProgram.cpp
@@ -17,9 +17,7 @@
  * along with this program. If not, see http://gnu.org/licenses
  */
 
-//////////////////////////////////////////////////////////////////////
-// database management of CBoT program
-
+// Modules inlcude
 #include "CBot.h"
 
 #include "CBotCall.h"
@@ -27,8 +25,14 @@
 #include "CBotClass.h"
 #include "CBotUtils.h"
 
+#include "StringFunctions.cpp"
+
+// Local include
+
+// Global include
 #include <stdio.h>
 
+////////////////////////////////////////////////////////////////////////////////
 CBotProgram::CBotProgram()
 {
     m_Prog      = nullptr;
@@ -41,6 +45,7 @@ CBotProgram::CBotProgram()
     m_Ident     = 0;
 }
 
+////////////////////////////////////////////////////////////////////////////////
 CBotProgram::CBotProgram(CBotVar* pInstance)
 {
     m_Prog      = nullptr;
@@ -53,7 +58,7 @@ CBotProgram::CBotProgram(CBotVar* pInstance)
     m_Ident     = 0;
 }
 
-
+////////////////////////////////////////////////////////////////////////////////
 CBotProgram::~CBotProgram()
 {
 //  delete  m_pClass;
@@ -70,7 +75,7 @@ CBotProgram::~CBotProgram()
 #endif
 }
 
-
+////////////////////////////////////////////////////////////////////////////////
 bool CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions, void* pUser )
 {
     int         error = 0;
@@ -165,7 +170,7 @@ bool CBotProgram::Compile( const char* program, CBotStringArray& ListFonctions,
     return (m_Prog != nullptr);
 }
 
-
+////////////////////////////////////////////////////////////////////////////////
 bool CBotProgram::Start(const char* name)
 {
 #if STACKMEM
@@ -199,6 +204,7 @@ bool CBotProgram::Start(const char* name)
     return true;                                    // we are ready for Run ()
 }
 
+////////////////////////////////////////////////////////////////////////////////
 bool CBotProgram::GetPosition(const char* name, int& start, int& stop, CBotGet modestart, CBotGet modestop)
 {
     CBotFunction* p = m_Prog;
@@ -214,6 +220,7 @@ bool CBotProgram::GetPosition(const char* name, int& start, int& stop, CBotGet m
     return true;
 }
 
+////////////////////////////////////////////////////////////////////////////////
 bool CBotProgram::Run(void* pUser, int timer)
 {
     bool    ok;
@@ -268,6 +275,7 @@ error:
     return true;
 }
 
+////////////////////////////////////////////////////////////////////////////////
 void CBotProgram::Stop()
 {
 #if STACKMEM
@@ -279,8 +287,7 @@ void CBotProgram::Stop()
     m_pRun = nullptr;
 }
 
-
-
+////////////////////////////////////////////////////////////////////////////////
 bool CBotProgram::GetRunPos(const char* &FunctionName, int &start, int &end)
 {
     FunctionName = nullptr;
@@ -291,6 +298,7 @@ bool CBotProgram::GetRunPos(const char* &FunctionName, int &start, int &end)
     return true;
 }
 
+////////////////////////////////////////////////////////////////////////////////
 CBotVar* CBotProgram::GetStackVars(const char* &FunctionName, int level)
 {
     FunctionName = nullptr;
@@ -299,26 +307,31 @@ CBotVar* CBotProgram::GetStackVars(const char* &FunctionName, int level)
     return m_pStack->GetStackVars(FunctionName, level);
 }
 
+////////////////////////////////////////////////////////////////////////////////
 void CBotProgram::SetTimer(int n)
 {
     CBotStack::SetTimer( n );
 }
 
+////////////////////////////////////////////////////////////////////////////////
 int CBotProgram::GetError()
 {
     return m_ErrorCode;
 }
 
+////////////////////////////////////////////////////////////////////////////////
 void CBotProgram::SetIdent(long n)
 {
     m_Ident = n;
 }
 
+////////////////////////////////////////////////////////////////////////////////
 long CBotProgram::GetIdent()
 {
     return m_Ident;
 }
 
+////////////////////////////////////////////////////////////////////////////////
 bool CBotProgram::GetError(int& code, int& start, int& end)
 {
     code  = m_ErrorCode;
@@ -327,6 +340,7 @@ bool CBotProgram::GetError(int& code, int& start, int& end)
     return code > 0;
 }
 
+////////////////////////////////////////////////////////////////////////////////
 bool CBotProgram::GetError(int& code, int& start, int& end, CBotProgram* &pProg)
 {
     code    = m_ErrorCode;
@@ -336,6 +350,7 @@ bool CBotProgram::GetError(int& code, int& start, int& end, CBotProgram* &pProg)
     return code > 0;
 }
 
+////////////////////////////////////////////////////////////////////////////////
 CBotString CBotProgram::GetErrorText(int code)
 {
     CBotString TextError;
@@ -350,12 +365,13 @@ CBotString CBotProgram::GetErrorText(int code)
     return TextError;
 }
 
-
+////////////////////////////////////////////////////////////////////////////////
 CBotFunction* CBotProgram::GetFunctions()
 {
     return  m_Prog;
 }
 
+////////////////////////////////////////////////////////////////////////////////
 bool CBotProgram::AddFunction(const char* name,
                               bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
                               CBotTypResult rCompile (CBotVar* &pVar, void* pUser))
@@ -364,7 +380,7 @@ bool CBotProgram::AddFunction(const char* name,
     return CBotCall::AddFunction(name, rExec, rCompile);
 }
 
-
+////////////////////////////////////////////////////////////////////////////////
 bool WriteWord(FILE* pf, unsigned short w)
 {
     size_t  lg;
@@ -374,6 +390,7 @@ bool WriteWord(FILE* pf, unsigned short w)
     return (lg == 1);
 }
 
+////////////////////////////////////////////////////////////////////////////////
 bool ReadWord(FILE* pf, unsigned short& w)
 {
     size_t  lg;
@@ -383,6 +400,7 @@ bool ReadWord(FILE* pf, unsigned short& w)
     return (lg == 1);
 }
 
+////////////////////////////////////////////////////////////////////////////////
 bool WriteFloat(FILE* pf, float w)
 {
     size_t  lg;
@@ -392,6 +410,7 @@ bool WriteFloat(FILE* pf, float w)
     return (lg == 1);
 }
 
+////////////////////////////////////////////////////////////////////////////////
 bool ReadFloat(FILE* pf, float& w)
 {
     size_t  lg;
@@ -401,6 +420,7 @@ bool ReadFloat(FILE* pf, float& w)
     return (lg == 1);
 }
 
+////////////////////////////////////////////////////////////////////////////////
 bool WriteLong(FILE* pf, long w)
 {
     size_t  lg;
@@ -410,6 +430,7 @@ bool WriteLong(FILE* pf, long w)
     return (lg == 1);
 }
 
+////////////////////////////////////////////////////////////////////////////////
 bool ReadLong(FILE* pf, long& w)
 {
     size_t  lg;
@@ -419,6 +440,7 @@ bool ReadLong(FILE* pf, long& w)
     return (lg == 1);
 }
 
+////////////////////////////////////////////////////////////////////////////////
 bool WriteString(FILE* pf, CBotString s)
 {
     size_t  lg1, lg2;
@@ -430,6 +452,7 @@ bool WriteString(FILE* pf, CBotString s)
     return (lg1 == lg2);
 }
 
+////////////////////////////////////////////////////////////////////////////////
 bool ReadString(FILE* pf, CBotString& s)
 {
     unsigned short  w;
@@ -445,6 +468,7 @@ bool ReadString(FILE* pf, CBotString& s)
     return (lg1 == lg2);
 }
 
+////////////////////////////////////////////////////////////////////////////////
 bool WriteType(FILE* pf, CBotTypResult type)
 {
     int typ = type.GetType();
@@ -464,6 +488,7 @@ bool WriteType(FILE* pf, CBotTypResult type)
     return true;
 }
 
+////////////////////////////////////////////////////////////////////////////////
 bool ReadType(FILE* pf, CBotTypResult& type)
 {
     unsigned short  w, ww;
@@ -494,13 +519,40 @@ bool ReadType(FILE* pf, CBotTypResult& type)
     return true;
 }
 
+////////////////////////////////////////////////////////////////////////////////
+bool rSizeOf( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
+{
+    if ( pVar == nullptr ) return TX_LOWPARAM;
 
+    int i = 0;
+    pVar = pVar->GetItemList();
+
+    while ( pVar != nullptr )
+    {
+        i++;
+        pVar = pVar->GetNext();
+    }
+
+    pResult->SetValInt(i);
+    return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotTypResult cSizeOf( CBotVar* &pVar, void* pUser )
+{
+    if ( pVar == nullptr ) return CBotTypResult( TX_LOWPARAM );
+    if ( pVar->GetType() != CBotTypArrayPointer )
+                        return CBotTypResult( TX_BADPARAM );
+    return CBotTypResult( CBotTypInt );
+}
+
+////////////////////////////////////////////////////////////////////////////////
 bool CBotProgram::DefineNum(const char* name, long val)
 {
     return CBotToken::DefineNum(name, val);
 }
 
-
+////////////////////////////////////////////////////////////////////////////////
 bool CBotProgram::SaveState(FILE* pf)
 {
     if (!WriteWord( pf, CBOTVERSION)) return false;
@@ -519,7 +571,7 @@ bool CBotProgram::SaveState(FILE* pf)
     return true;
 }
 
-
+////////////////////////////////////////////////////////////////////////////////
 bool CBotProgram::RestoreState(FILE* pf)
 {
     unsigned short  w;
@@ -553,12 +605,43 @@ bool CBotProgram::RestoreState(FILE* pf)
     return true;
 }
 
+////////////////////////////////////////////////////////////////////////////////
 int CBotProgram::GetVersion()
 {
     return  CBOTVERSION;
 }
 
+////////////////////////////////////////////////////////////////////////////////
+void CBotProgram::Init()
+{
+    CBotToken::DefineNum("CBotErrZeroDiv",       TX_DIVZERO);     // division by zero
+    CBotToken::DefineNum("CBotErrNotInit",       TX_NOTINIT);     // uninitialized variable
+    CBotToken::DefineNum("CBotErrBadThrow",      TX_BADTHROW);    // throw a negative value
+    //CBotToken::DefineNum("CBotErrNoRetVal",      6003);           // function did not return results // TODO: Not used. I'm pretty sure not returning a value crashes the game :P
+    CBotToken::DefineNum("CBotErrNoRun",         TX_NORUN);       // active Run () without a function // TODO: Is this actually a runtime error?
+    CBotToken::DefineNum("CBotErrUndefFunc",     TX_NOCALL);      // Calling a function that no longer exists
+    CBotToken::DefineNum("CBotErrUndefClass",    TX_NOCLASS);     // Class no longer exists
+    CBotToken::DefineNum("CBotErrNullPointer",   TX_NULLPT);      // Attempted to use a null pointer
+    CBotToken::DefineNum("CBotErrNan",           TX_OPNAN);       // Can't do operations on nan
+    CBotToken::DefineNum("CBotErrOutOfBounds",   TX_OUTARRAY);    // Attempted access out of bounds of an array
+    CBotToken::DefineNum("CBotErrStackOverflow", TX_STACKOVER);   // Stack overflow
+    CBotToken::DefineNum("CBotErrDeletedObject", TX_DELETEDPT);   // Attempted to use deleted object
+
+    CBotProgram::AddFunction("sizeof", rSizeOf, cSizeOf );
+
+    InitStringFunctions();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotProgram::Free()
+{
+    CBotToken::Free() ;
+    CBotCall ::Free() ;
+    CBotClass::Free() ;
+}
+
 
+////////////////////////////////////////////////////////////////////////////////
 CBotCallMethode::CBotCallMethode(const char* name,
                    bool rExec (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception, void* user),
                    CBotTypResult rCompile (CBotVar* pThis, CBotVar* &pVar))
@@ -570,6 +653,7 @@ CBotCallMethode::CBotCallMethode(const char* name,
     m_nFuncIdent = CBotVar::NextUniqNum();
 }
 
+////////////////////////////////////////////////////////////////////////////////
 CBotCallMethode::~CBotCallMethode()
 {
     delete m_next;
@@ -578,7 +662,7 @@ CBotCallMethode::~CBotCallMethode()
 
 // is acceptable by a call procedure name
 // and given parameters
-
+////////////////////////////////////////////////////////////////////////////////
 CBotTypResult CBotCallMethode::CompileCall(const char* name, CBotVar* pThis,
                                            CBotVar** ppVar, CBotCStack* pStack,
                                            long& nIdent)
@@ -607,17 +691,19 @@ CBotTypResult CBotCallMethode::CompileCall(const char* name, CBotVar* pThis,
     return CBotTypResult(-1);
 }
 
-
+////////////////////////////////////////////////////////////////////////////////
 CBotString CBotCallMethode::GetName()
 {
     return  m_name;
 }
 
+////////////////////////////////////////////////////////////////////////////////
 CBotCallMethode* CBotCallMethode::Next()
 {
     return  m_next;
 }
 
+////////////////////////////////////////////////////////////////////////////////
 void CBotCallMethode::AddNext(CBotCallMethode* pt)
 {
     CBotCallMethode* p = this;
@@ -626,7 +712,7 @@ void CBotCallMethode::AddNext(CBotCallMethode* pt)
     p->m_next = pt;
 }
 
-
+////////////////////////////////////////////////////////////////////////////////
 int CBotCallMethode::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotVar* &pResult, CBotStack* pStack, CBotToken* pToken)
 {
     CBotCallMethode*    pt = this;
@@ -698,59 +784,3 @@ int CBotCallMethode::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBot
 
     return -1;
 }
-
-bool rSizeOf( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
-{
-    if ( pVar == nullptr ) return TX_LOWPARAM;
-
-    int i = 0;
-    pVar = pVar->GetItemList();
-
-    while ( pVar != nullptr )
-    {
-        i++;
-        pVar = pVar->GetNext();
-    }
-
-    pResult->SetValInt(i);
-    return true;
-}
-
-CBotTypResult cSizeOf( CBotVar* &pVar, void* pUser )
-{
-    if ( pVar == nullptr ) return CBotTypResult( TX_LOWPARAM );
-    if ( pVar->GetType() != CBotTypArrayPointer )
-                        return CBotTypResult( TX_BADPARAM );
-    return CBotTypResult( CBotTypInt );
-}
-
-
-// TODO: Refactor this - including .cpp files is bad
-#include "StringFunctions.cpp"
-
-void CBotProgram::Init()
-{
-    CBotToken::DefineNum("CBotErrZeroDiv",       TX_DIVZERO);     // division by zero
-    CBotToken::DefineNum("CBotErrNotInit",       TX_NOTINIT);     // uninitialized variable
-    CBotToken::DefineNum("CBotErrBadThrow",      TX_BADTHROW);    // throw a negative value
-    //CBotToken::DefineNum("CBotErrNoRetVal",      6003);           // function did not return results // TODO: Not used. I'm pretty sure not returning a value crashes the game :P
-    CBotToken::DefineNum("CBotErrNoRun",         TX_NORUN);       // active Run () without a function // TODO: Is this actually a runtime error?
-    CBotToken::DefineNum("CBotErrUndefFunc",     TX_NOCALL);      // Calling a function that no longer exists
-    CBotToken::DefineNum("CBotErrUndefClass",    TX_NOCLASS);     // Class no longer exists
-    CBotToken::DefineNum("CBotErrNullPointer",   TX_NULLPT);      // Attempted to use a null pointer
-    CBotToken::DefineNum("CBotErrNan",           TX_OPNAN);       // Can't do operations on nan
-    CBotToken::DefineNum("CBotErrOutOfBounds",   TX_OUTARRAY);    // Attempted access out of bounds of an array
-    CBotToken::DefineNum("CBotErrStackOverflow", TX_STACKOVER);   // Stack overflow
-    CBotToken::DefineNum("CBotErrDeletedObject", TX_DELETEDPT);   // Attempted to use deleted object
-
-    CBotProgram::AddFunction("sizeof", rSizeOf, cSizeOf );
-
-    InitStringFunctions();
-}
-
-void CBotProgram::Free()
-{
-    CBotToken::Free() ;
-    CBotCall ::Free() ;
-    CBotClass::Free() ;
-}
diff --git a/src/CBot/CBotProgram.h b/src/CBot/CBotProgram.h
new file mode 100644
index 0000000..02aa537
--- /dev/null
+++ b/src/CBot/CBotProgram.h
@@ -0,0 +1,260 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsitec.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#pragma once
+
+// Modules inlcude
+
+// Local include
+
+// Global include
+
+
+/*!
+ * \brief The CBotProgram class Main class managing CBot program.
+ */
+class CBotProgram
+{
+public:
+
+    /*!
+     * \brief CBotProgram
+     */
+    CBotProgram();
+
+    /*!
+     * \brief CBotProgram
+     * \param pInstance
+     */
+    CBotProgram(CBotVar* pInstance);
+
+    /*!
+     * \brief ~CBotProgram
+     */
+    ~CBotProgram();
+
+    /*!
+     * \brief Init Initializes the module (defined keywords for errors) should
+     * be done once (and only one) at the beginning.
+     */
+    static void Init();
+
+    /*!
+     * \brief Free Frees the static memory areas.
+     */
+    static void Free();
+
+    /*!
+     * \brief GetVersion Gives the version of the library CBOT.
+     * \return
+     */
+    static int GetVersion();
+
+    /*!
+     * \brief Compile compiles the program given in text.
+     * \param program
+     * \param ListFonctions Returns the names of functions declared as extern.
+     * \param pUser Can pass a pointer to routines defined by AddFunction.
+     * \return false if an error at compile.
+     * \see GetCompileError() to retrieve the error.
+     */
+    bool Compile( const char* program, CBotStringArray& ListFonctions, void* pUser = nullptr);
+
+    /*!
+     * \brief SetIdent Associates an identifier with the instance CBotProgram.
+     * \param n
+     */
+    void SetIdent(long n);
+
+    /*!
+     * \brief GetIdent Gives the identifier.
+     * \return
+     */
+    long GetIdent();
+
+    /*!
+     * \brief GetError
+     * \return
+     */
+    int GetError();
+
+    /*!
+     * \brief GetError
+     * \param code
+     * \param start
+     * \param end
+     * \return
+     */
+    bool GetError(int& code, int& start, int& end);
+
+    /*!
+     * \brief GetError
+     * \param code
+     * \param start Delimits the start block where the error occured.
+     * \param end Delimits the end block where the error occured.
+     * \param pProg Lets you know what "module" has produced runtime error.
+     * \return If true gives the error found in the compilation or execution.
+     */
+    bool GetError(int& code, int& start, int& end, CBotProgram* &pProg);
+
+    /*!
+     * \brief GetErrorText
+     * \param code
+     * \return
+     */
+    static CBotString GetErrorText(int code);
+
+    /*!
+     * \brief Start Defines what function should be executed. The program does
+     * nothing, we must call Run () for this.
+     * \param name
+     * \return false if the funtion name is not found
+     */
+    bool Start(const char* name);
+
+    /*!
+     * \brief Run Executes the program.
+     * \param pUser
+     * \param timer timer = 0 allows to advance step by step.
+     * \return false if the program was suspended, true if the program ended
+     * with or without error.
+     */
+    bool Run(void* pUser = nullptr, int timer = -1);
+
+    /*!
+     * \brief GetRunPos Gives the position in the executing program
+     * \param FunctionName is a pointer made to the name of the function
+     * \param start start and end position in the text of the token processing
+     * \param end
+     * \return false if it is not running (program completion)
+     */
+    bool GetRunPos(const char* &FunctionName, int &start, int &end);
+
+    /*!
+     * \brief GetStackVars provides the pointer to the variables on the
+     * execution stack level is an input parameter,  0 for the last level, -1,
+     * -2, etc. for the other levels the return value (CBotVar *) is a variable.
+     * that can be processed as the list of parameters received by a routine
+     * list (or nullptr)
+     * \param FunctionName gives the name of the function where are these
+     * variables. FunctionName == nullptr means that is more in a program
+     * (depending on  level)
+     * \param level
+     * \return
+     */
+    CBotVar* GetStackVars(const char* &FunctionName, int level);
+
+    /*!
+     * \brief Stop stops execution of the program therefore quits "suspend" mode
+     */
+    void Stop();
+
+    /*!
+     * \brief SetTimer defines the number of steps (parts of instructions) to
+     * done in Run() before rendering hand "false"
+     * \TODO avant de rendre la main "false"
+     * \param n
+     */
+    static void SetTimer(int n);
+    //
+    //
+
+    /*!
+     * \brief AddFunction Call this to add externally (**) a new function used
+     * by the program CBoT.
+     * \param name
+     * \param rExec
+     * \param rCompile
+     * \return
+     */
+    static bool AddFunction(const char* name,
+                                bool rExec (CBotVar* pVar, CBotVar* pResult, int& Exception, void* pUser),
+                                CBotTypResult rCompile (CBotVar* &pVar, void* pUser));
+
+    /*!
+     * \brief DefineNum
+     * \param name
+     * \param val
+     * \return
+     */
+    static bool DefineNum(const char* name, long val);
+
+    /*!
+     * \brief SaveState Backup the execution status in the file the file must
+     * have been opened with the fopen call this dll (\TODO this library??)
+     * if the system crashes
+     * \param pf
+     * \return
+     */
+    bool SaveState(FILE* pf);
+
+    /*!
+     * \brief RestoreState Restores the state of execution from file the
+     * compiled program must obviously be the same.
+     * \param pf
+     * \return
+     */
+    bool RestoreState(FILE* pf);
+
+    /*!
+     * \brief GetPosition Gives the position of a routine in the original text
+     * the user can select the item to find from the beginning to the end
+     * see the above modes in CBotGet.
+     * \param name
+     * \param start
+     * \param stop
+     * \param modestart
+     * \param modestop
+     * \return
+     */
+    bool GetPosition(const char* name, int& start, int& stop,
+                                CBotGet modestart = GetPosExtern,
+                                CBotGet modestop  = GetPosBloc);
+
+    /*!
+     * \brief GetFunctions
+     * \return
+     */
+    CBotFunction* GetFunctions();
+
+    /*!
+     * \brief m_bCompileClass
+     */
+    bool m_bCompileClass;
+
+private:
+
+    //! The user-defined functions.
+    CBotFunction* m_Prog;
+    //! The basic function for the execution.
+    CBotFunction* m_pRun;
+    //! Classes defined in this part.
+    CBotClass* m_pClass;
+    //! Execution stack.
+    CBotStack* m_pStack;
+    //! Instance of the parent class.
+    CBotVar* m_pInstance;
+    friend class CBotFunction;
+
+    int m_ErrorCode;
+    int m_ErrorStart;
+    int m_ErrorEnd;
+    //! Associated identifier.
+    long m_Ident;
+};
diff --git a/src/script/script.h b/src/script/script.h
index d57d271..d4a42eb 100644
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -24,7 +24,9 @@
 
 #pragma once
 
+// TODO replace by CBot.h
 #include "CBot/CBotDll.h"
+#include "CBot/CBotProgram.h"
 
 #include <memory>
 #include <string>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git



More information about the Pkg-games-commits mailing list