This is an automated email from the git hooks/post-receive script. odyx pushed a commit to branch debian/master in repository colobot.
commit 4712e0ef6a1d3512e3ac0097e325b3d97a879422 Author: Grunaka <d...@romainbreton.fr> Date: Sun Nov 15 18:31:57 2015 +0100 Moving CBotFunction class in its own header and source files. --- src/CBot/CBot.h | 67 ------- src/CBot/CBotClass.cpp | 1 + src/CBot/{ => CBotInstr}/CBotFunction.cpp | 73 ++++---- src/CBot/CBotInstr/CBotFunction.h | 282 ++++++++++++++++++++++++++++++ src/CBot/CBotProgram.cpp | 2 + src/CBot/CBotStack.cpp | 2 + src/CBot/CMakeLists.txt | 2 +- 7 files changed, 331 insertions(+), 98 deletions(-) diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index e98a1c6..33efc71 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -550,70 +550,3 @@ public: CBotString GetParamString(); }; - - -// a function declaration - -class CBotFunction : CBotInstr -{ -private: - // management of list of (static) public functions - static - CBotFunction* m_listPublic; - CBotFunction* m_nextpublic; - CBotFunction* m_prevpublic; - friend class CBotCStack; -// long m_nThisIdent; - long m_nFuncIdent; - bool m_bSynchro; // synchronized method? - -private: - CBotDefParam* m_Param; // parameter list - CBotInstr* m_Block; // the instruction block - CBotFunction* m_next; - CBotToken m_retToken; // if returns CBotTypClass - CBotTypResult m_retTyp; // complete type of the result - - bool m_bPublic; // public function - bool m_bExtern; // extern function - CBotString m_MasterClass; // name of the class we derive - CBotProgram* m_pProg; - friend class CBotProgram; - friend class CBotClass; - - CBotToken m_extern; // for the position of the word "extern" - CBotToken m_openpar; - CBotToken m_closepar; - CBotToken m_openblk; - CBotToken m_closeblk; -public: - CBotFunction(); - ~CBotFunction(); - static - CBotFunction* Compile(CBotToken* &p, CBotCStack* pStack, CBotFunction* pFunc, bool bLocal = true); - static - CBotFunction* Compile1(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass); - bool Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance = nullptr); - void RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance = nullptr); - - void AddNext(CBotFunction* p); - CBotTypResult CompileCall(const char* name, CBotVar** ppVars, long& nIdent); - CBotFunction* FindLocalOrPublic(long& nIdent, const char* name, CBotVar** ppVars, CBotTypResult& TypeOrError, bool bPublic = true); - - int DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken); - void RestoreCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack); - int DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken, CBotClass* pClass); - void RestoreCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotClass* pClass); - bool CheckParam(CBotDefParam* pParam); - - static - void AddPublic(CBotFunction* pfunc); - - CBotString GetName(); - CBotString GetParams(); - bool IsPublic(); - bool IsExtern(); - CBotFunction* Next(); - - bool GetPosition(int& start, int& stop, CBotGet modestart, CBotGet modestop); -}; diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 9c18f2c..f37d55c 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -23,6 +23,7 @@ #include "CBotInstr/CBotNew.h" #include "CBotInstr/CBotLeftExprVar.h" #include "CBotInstr/CBotTwoOpExpr.h" +#include "CBotInstr/CBotFunction.h" #include "CBotCall.h" diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp similarity index 93% rename from src/CBot/CBotFunction.cpp rename to src/CBot/CBotInstr/CBotFunction.cpp index 61a9887..61428da 100644 --- a/src/CBot/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -17,9 +17,9 @@ * along with this program. If not, see http://gnu.org/licenses */ -/////////////////////////////////////////////////////////////////////// -// compilation of various functions declared by the user -// + +// Modules inlcude +#include "CBotFunction.h" #include "CBot.h" @@ -32,12 +32,13 @@ #include "CBotStack.h" #include "CBotClass.h" +// Local include + +// Global include #include <cassert> -// various constructors / destructors -// \TODO translation:to liberate all according to esteblished tree -// pour libérer tout selon l'arbre établi +//////////////////////////////////////////////////////////////////////////////// CBotFunction::CBotFunction() { m_Param = nullptr; // empty parameter list @@ -53,8 +54,10 @@ CBotFunction::CBotFunction() m_bSynchro = false; } +//////////////////////////////////////////////////////////////////////////////// CBotFunction* CBotFunction::m_listPublic = nullptr; +//////////////////////////////////////////////////////////////////////////////// CBotFunction::~CBotFunction() { delete m_Param; // empty parameter list @@ -80,16 +83,19 @@ CBotFunction::~CBotFunction() } } +//////////////////////////////////////////////////////////////////////////////// bool CBotFunction::IsPublic() { return m_bPublic; } +//////////////////////////////////////////////////////////////////////////////// bool CBotFunction::IsExtern() { return m_bExtern; } +//////////////////////////////////////////////////////////////////////////////// bool CBotFunction::GetPosition(int& start, int& stop, CBotGet modestart, CBotGet modestop) { start = m_extern.GetStart(); @@ -131,7 +137,7 @@ bool CBotFunction::GetPosition(int& start, int& stop, CBotGet modestart, CBotGet return true; } - +//////////////////////////////////////////////////////////////////////////////// CBotTypResult ArrayType(CBotToken* &p, CBotCStack* pile, CBotTypResult type) { while ( IsOfType( p, ID_OPBRK ) ) @@ -146,6 +152,7 @@ CBotTypResult ArrayType(CBotToken* &p, CBotCStack* pile, CBotTypResult type) return type; } +//////////////////////////////////////////////////////////////////////////////// CBotTypResult TypeParam(CBotToken* &p, CBotCStack* pile) { CBotClass* pClass = nullptr; @@ -183,9 +190,7 @@ CBotTypResult TypeParam(CBotToken* &p, CBotCStack* pile) return CBotTypResult( -1 ); } -// compiles a new function -// bLocal allows of the declaration of parameters on the same level -// as the elements belonging to the class for methods +//////////////////////////////////////////////////////////////////////////////// CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunction* finput, bool bLocal) { CBotToken* pp; @@ -298,7 +303,7 @@ bad: return pStack->ReturnFunc(nullptr, pStk); } -// pre-compile a new function +//////////////////////////////////////////////////////////////////////////////// CBotFunction* CBotFunction::Compile1(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass) { CBotFunction* func = new CBotFunction(); @@ -385,6 +390,7 @@ bad: static int xx = 0; #endif +//////////////////////////////////////////////////////////////////////////////// bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance) { CBotStack* pile = pj->AddStack(this, 2); // one end of stack local to this function @@ -434,7 +440,7 @@ bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance) return pj->Return(pile); } - +//////////////////////////////////////////////////////////////////////////////// void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance) { CBotStack* pile = pj->RestoreStack(this); // one end of stack local to this function @@ -463,6 +469,7 @@ void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInst m_Block->RestoreState(pile2, true); } +//////////////////////////////////////////////////////////////////////////////// void CBotFunction::AddNext(CBotFunction* p) { CBotFunction* pp = this; @@ -471,7 +478,7 @@ void CBotFunction::AddNext(CBotFunction* p) pp->m_next = p; } - +//////////////////////////////////////////////////////////////////////////////// CBotTypResult CBotFunction::CompileCall(const char* name, CBotVar** ppVars, long& nIdent) { nIdent = 0; @@ -482,10 +489,7 @@ CBotTypResult CBotFunction::CompileCall(const char* name, CBotVar** ppVars, long return type; } - -// is a function according to its unique identifier -// if the identifier is not found, looking by name and parameters - +//////////////////////////////////////////////////////////////////////////////// CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const char* name, CBotVar** ppVars, CBotTypResult& TypeOrError, bool bPublic) { TypeOrError.SetType(TX_UNDEFCALL); // no routine of the name @@ -638,9 +642,7 @@ CBotFunction* CBotFunction::FindLocalOrPublic(long& nIdent, const char* name, CB return nullptr; } - -// fait un appel à une fonction - +//////////////////////////////////////////////////////////////////////////////// int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken) { CBotTypResult type; @@ -710,6 +712,7 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotS return -1; } +//////////////////////////////////////////////////////////////////////////////// void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar** ppVars, CBotStack* pStack) { CBotTypResult type; @@ -766,11 +769,7 @@ void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar** ppVars, } } - - -// makes call of a method -// note: this is already on the stack, the pointer pThis is just to simplify - +//////////////////////////////////////////////////////////////////////////////// int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotToken* pToken, CBotClass* pClass) { CBotTypResult type; @@ -851,6 +850,7 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar return -1; } +//////////////////////////////////////////////////////////////////////////////// void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar** ppVars, CBotStack* pStack, CBotClass* pClass) { CBotTypResult type; @@ -883,7 +883,7 @@ void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar* pThis, C } } -// see if the "signature" of parameters is identical +//////////////////////////////////////////////////////////////////////////////// bool CBotFunction::CheckParam(CBotDefParam* pParam) { CBotDefParam* pp = m_Param; @@ -898,11 +898,13 @@ bool CBotFunction::CheckParam(CBotDefParam* pParam) return ( pp == nullptr && pParam == nullptr ); } +//////////////////////////////////////////////////////////////////////////////// CBotString CBotFunction::GetName() { return m_token.GetString(); } +//////////////////////////////////////////////////////////////////////////////// CBotString CBotFunction::GetParams() { if ( m_Param == nullptr ) return CBotString("()"); @@ -921,11 +923,13 @@ CBotString CBotFunction::GetParams() return params; } +//////////////////////////////////////////////////////////////////////////////// CBotFunction* CBotFunction::Next() { return m_next; } +//////////////////////////////////////////////////////////////////////////////// void CBotFunction::AddPublic(CBotFunction* func) { if ( m_listPublic != nullptr ) @@ -941,19 +945,20 @@ void CBotFunction::AddPublic(CBotFunction* func) ///////////////////////////////////////////////////////////////////////// // management of parameters - +//////////////////////////////////////////////////////////////////////////////// CBotDefParam::CBotDefParam() { m_next = nullptr; m_nIdent = 0; } +//////////////////////////////////////////////////////////////////////////////// CBotDefParam::~CBotDefParam() { delete m_next; } - +//////////////////////////////////////////////////////////////////////////////// // compiles a list of parameters CBotDefParam* CBotDefParam::Compile(CBotToken* &p, CBotCStack* pStack) { @@ -1014,6 +1019,7 @@ CBotDefParam* CBotDefParam::Compile(CBotToken* &p, CBotCStack* pStack) return nullptr; } +//////////////////////////////////////////////////////////////////////////////// void CBotDefParam::AddNext(CBotDefParam* p) { CBotDefParam* pp = this; @@ -1022,7 +1028,7 @@ void CBotDefParam::AddNext(CBotDefParam* p) pp->m_next = p; } - +//////////////////////////////////////////////////////////////////////////////// bool CBotDefParam::Execute(CBotVar** ppVars, CBotStack* &pj) { int i = 0; @@ -1072,6 +1078,7 @@ bool CBotDefParam::Execute(CBotVar** ppVars, CBotStack* &pj) return true; } +//////////////////////////////////////////////////////////////////////////////// void CBotDefParam::RestoreState(CBotStack* &pj, bool bMain) { // int i = 0; @@ -1086,21 +1093,25 @@ void CBotDefParam::RestoreState(CBotStack* &pj, bool bMain) } } +//////////////////////////////////////////////////////////////////////////////// int CBotDefParam::GetType() { return m_type.GetType(); } +//////////////////////////////////////////////////////////////////////////////// CBotTypResult CBotDefParam::GetTypResult() { return m_type; } +//////////////////////////////////////////////////////////////////////////////// CBotDefParam* CBotDefParam::GetNext() { return m_next; } +//////////////////////////////////////////////////////////////////////////////// CBotString CBotDefParam::GetParamString() { CBotString param; @@ -1118,6 +1129,7 @@ CBotString CBotDefParam::GetParamString() // pre-compile a new class // analysis is complete except the body of routines +//////////////////////////////////////////////////////////////////////////////// CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack) { if ( !IsOfType(p, ID_PUBLIC) ) @@ -1173,6 +1185,7 @@ CBotClass* CBotClass::Compile1(CBotToken* &p, CBotCStack* pStack) return nullptr; } +//////////////////////////////////////////////////////////////////////////////// bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) { bool bStatic = false; @@ -1376,7 +1389,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) return pStack->IsOk(); } - +//////////////////////////////////////////////////////////////////////////////// CBotClass* CBotClass::Compile(CBotToken* &p, CBotCStack* pStack) { if ( !IsOfType(p, ID_PUBLIC) ) return nullptr; diff --git a/src/CBot/CBotInstr/CBotFunction.h b/src/CBot/CBotInstr/CBotFunction.h new file mode 100644 index 0000000..486ffff --- /dev/null +++ b/src/CBot/CBotInstr/CBotFunction.h @@ -0,0 +1,282 @@ +/* + * 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 +#include "CBot.h" + +// Local include + +// Global include + + +/*! + * \brief The CBotFunction class A function declaration. Compilation of various + * functions declared by the user + */ +class CBotFunction : public CBotInstr +{ +public: + + /*! + * \brief CBotFunction + */ + CBotFunction(); + + /*! + * \brief ~CBotFunction + */ + ~CBotFunction(); + + /*! + * \brief Compile Compiles a new function + * \param p + * \param pStack + * \param pFunc + * \param bLocal allows of the declaration of parameters on the same level + * as the elements belonging to the class for methods. + * \return + */ + static CBotFunction* Compile(CBotToken* &p, + CBotCStack* pStack, + CBotFunction* pFunc, + bool bLocal = true); + + /*! + * \brief Compile1 Pre-compile a new function. + * \param p + * \param pStack + * \param pClass + * \return + */ + static CBotFunction* Compile1(CBotToken* &p, + CBotCStack* pStack, + CBotClass* pClass); + + /*! + * \brief Execute + * \param ppVars + * \param pj + * \param pInstance + * \return + */ + bool Execute(CBotVar** ppVars, + CBotStack* &pj, + CBotVar* pInstance = nullptr); + + /*! + * \brief RestoreState + * \param ppVars + * \param pj + * \param pInstance + */ + void RestoreState(CBotVar** ppVars, + CBotStack* &pj, + CBotVar* pInstance = nullptr); + + /*! + * \brief AddNext + * \param p + */ + void AddNext(CBotFunction* p); + + /*! + * \brief CompileCall + * \param name + * \param ppVars + * \param nIdent + * \return + */ + CBotTypResult CompileCall(const char* name, + CBotVar** ppVars, + long& nIdent); + + /*! + * \brief FindLocalOrPublic Is a function according to its unique identifier + * if the identifier is not found, looking by name and parameters. + * \param nIdent + * \param name + * \param ppVars + * \param TypeOrError + * \param bPublic + * \return + */ + CBotFunction* FindLocalOrPublic(long& nIdent, const char* name, + CBotVar** ppVars, + CBotTypResult& TypeOrError, + bool bPublic = true); + + /*! + * \brief DoCall Fait un appel à une fonction. + * \param nIdent + * \param name + * \param ppVars + * \param pStack + * \param pToken + * \return + */ + + int DoCall(long& nIdent, + const char* name, + CBotVar** ppVars, + CBotStack* pStack, + CBotToken* pToken); + + /*! + * \brief RestoreCall + * \param nIdent + * \param name + * \param ppVars + * \param pStack + */ + void RestoreCall(long& nIdent, + const char* name, + CBotVar** ppVars, + CBotStack* pStack); + + /*! + * \brief DoCall Makes call of a method note: this is already on the stack, + * the pointer pThis is just to simplify. + * \param nIdent + * \param name + * \param pThis + * \param ppVars + * \param pStack + * \param pToken + * \param pClass + * \return + */ + int DoCall(long& nIdent, + const char* name, + CBotVar* pThis, + CBotVar** ppVars, + CBotStack* pStack, + CBotToken* pToken, + CBotClass* pClass); + + /*! + * \brief RestoreCall + * \param nIdent + * \param name + * \param pThis + * \param ppVars + * \param pStack + * \param pClass + */ + void RestoreCall(long& nIdent, + const char* name, + CBotVar* pThis, + CBotVar** ppVars, + CBotStack* pStack, + CBotClass* pClass); + + /*! + * \brief CheckParam See if the "signature" of parameters is identical. + * \param pParam + * \return + */ + bool CheckParam(CBotDefParam* pParam); + + /*! + * \brief AddPublic + * \param pfunc + */ + static void AddPublic(CBotFunction* pfunc); + + /*! + * \brief GetName + * \return + */ + CBotString GetName(); + + /*! + * \brief GetParams + * \return + */ + CBotString GetParams(); + + /*! + * \brief IsPublic + * \return + */ + bool IsPublic(); + + /*! + * \brief IsExtern + * \return + */ + bool IsExtern(); + + /*! + * \brief Next + * \return + */ + CBotFunction* Next(); + + /*! + * \brief GetPosition + * \param start + * \param stop + * \param modestart + * \param modestop + * \return + */ + bool GetPosition(int& start, int& stop, + CBotGet modestart, + CBotGet modestop); + +private: + CBotFunction* m_nextpublic; + CBotFunction* m_prevpublic; + long m_nFuncIdent; + //! Synchronized method. + bool m_bSynchro; + + //! Parameter list. + CBotDefParam* m_Param; + //! The instruction block. + CBotInstr* m_Block; + CBotFunction* m_next; + //! If returns CBotTypClass. + CBotToken m_retToken; + //! Complete type of the result. + CBotTypResult m_retTyp; + //! Public function. + bool m_bPublic; + //! Extern function. + bool m_bExtern; + //! Name of the class we derive. + CBotString m_MasterClass; + CBotProgram* m_pProg; + //! For the position of the word "extern". + CBotToken m_extern; + CBotToken m_openpar; + CBotToken m_closepar; + CBotToken m_openblk; + CBotToken m_closeblk; + + //! Management of list of (static) public functions. + static CBotFunction* m_listPublic; + + friend class CBotProgram; + friend class CBotClass; + friend class CBotCStack; + +}; diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 23752d5..8e492ba 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -25,6 +25,8 @@ #include "CBotClass.h" #include "CBotUtils.h" +#include "CBotInstr/CBotFunction.h" + #include "StringFunctions.cpp" // Local include diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 0997f46..0a76713 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -21,6 +21,8 @@ #include "CBotStack.h" #include "CBotCall.h" +#include "CBotInstr/CBotFunction.h" + // Local include // Global include diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 5bb6ad7..7aee901 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -1,7 +1,6 @@ set(SOURCES CBot.cpp CBotClass.cpp - CBotFunction.cpp CBotProgram.cpp CBotStack.cpp CBotString.cpp @@ -53,6 +52,7 @@ set(SOURCES CBotInstr/CBotListArray.cpp CBotInstr/CBotInstArray.cpp CBotInstr/CBotInt.cpp + CBotInstr/CBotFunction.cpp CBotVar/CBotVarArray.cpp ) -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git _______________________________________________ Pkg-games-commits mailing list Pkg-games-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits