This is an automated email from the git hooks/post-receive script. odyx pushed a commit to branch debian/master in repository colobot.
commit 17cbae8e688a551ba225f9d646ec8137cacd9ad0 Author: Grunaka <d...@romainbreton.fr> Date: Wed Nov 11 23:03:32 2015 +0100 Moving CBotBoolean class in its own header and source files. --- src/CBot/CBot.cpp | 149 +------------------------- src/CBot/CBot.h | 17 --- src/CBot/CBotInstr/CBotBoolean.cpp | 172 ++++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotBoolean.h | 76 +++++++++++++ src/CBot/CBotInstr/CBotListExpression.cpp | 1 + src/CBot/CMakeLists.txt | 1 + 6 files changed, 251 insertions(+), 165 deletions(-) diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 5cb8cac..d08e01e 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -64,6 +64,7 @@ #include "CBotInstr/CBotClassInst.h" #include "CBotInstr/CBotIString.h" #include "CBotInstr/CBotFloat.h" +#include "CBotInstr/CBotBoolean.h" // Local include @@ -928,154 +929,6 @@ void CBotInt::RestoreState(CBotStack* &pj, bool bMain) ////////////////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////////////// -// defining a boolean variable -// int a, b = false; - -CBotBoolean::CBotBoolean() -{ - m_var = - m_expr = nullptr; - name = "CBotBoolean"; -} - -CBotBoolean::~CBotBoolean() -{ - delete m_var; - delete m_expr; -} - -CBotInstr* CBotBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip) -{ - CBotToken* pp = cont ? nullptr : p; - - if (!cont && !IsOfType(p, ID_BOOLEAN, ID_BOOL)) return nullptr; - - CBotBoolean* inst = static_cast<CBotBoolean*>(CompileArray(p, pStack, CBotTypBoolean)); - if (inst != nullptr || !pStack->IsOk()) return inst; - - CBotCStack* pStk = pStack->TokenStack(pp); - - inst = new CBotBoolean(); - - inst->m_expr = nullptr; - - CBotToken* vartoken = p; - inst->SetToken(vartoken); - CBotVar* var = nullptr; - - if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk ))) - { - (static_cast<CBotLeftExprVar*>(inst->m_var))->m_typevar = CBotTypBoolean; - if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable - { - pStk->SetError(TX_REDEFVAR, vartoken); - goto error; - } - - if (IsOfType(p, ID_OPBRK)) - { - delete inst; // type is not CBotInt - p = vartoken; // resutns to the variable name - - // compiles an array declaration - - inst = static_cast<CBotBoolean*>(CBotInstArray::Compile(p, pStk, CBotTypBoolean)); - - if (!pStk->IsOk() ) - { - pStk->SetError(TX_CLBRK, p->GetStart()); - goto error; - } - goto suite; // no assignment, variable already created - } - - if (IsOfType(p, ID_ASS)) - { - if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) - { - goto error; - } - if (!pStk->GetTypResult().Eq(CBotTypBoolean)) - { - pStk->SetError(TX_BADTYPE, p->GetStart()); - goto error; - } - } - - var = CBotVar::Create(vartoken, CBotTypBoolean);// create the variable (evaluated after the assignment) - var->SetInit(inst->m_expr != nullptr ? CBotVar::InitType::DEF : CBotVar::InitType::UNDEF); - var->SetUniqNum( - (static_cast<CBotLeftExprVar*>(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); - pStack->AddVar(var); -suite: - if (IsOfType(p, ID_COMMA)) - { - if (nullptr != ( inst->m_next2b = CBotBoolean::Compile(p, pStk, true, noskip))) - { - return pStack->Return(inst, pStk); - } - } - - if (noskip || IsOfType(p, ID_SEP)) - { - return pStack->Return(inst, pStk); - } - - pStk->SetError(TX_ENDOF, p->GetStart()); - } - -error: - delete inst; - return pStack->Return(nullptr, pStk); -} - -// executes a boolean variable definition - -bool CBotBoolean::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this);//essential for SetState() - - if ( pile->GetState()==0) - { - if (m_expr && !m_expr->Execute(pile)) return false; - m_var->Execute(pile); - - if (!pile->SetState(1)) return false; - } - - if (pile->IfStep()) return false; - - if ( m_next2b && - !m_next2b->Execute(pile)) return false; - - return pj->Return(pile); -} - -void CBotBoolean::RestoreState(CBotStack* &pj, bool bMain) -{ - CBotStack* pile = pj; - if (bMain) - { - pile = pj->RestoreStack(this); - if (pile == nullptr) return; - - if ( pile->GetState()==0) - { - if (m_expr) m_expr->RestoreState(pile, bMain); // initial value interrupted? - return; - } - } - - m_var->RestoreState(pile, bMain); - - if (m_next2b) - m_next2b->RestoreState(pile, bMain); // other(s) definition(s) -} - -////////////////////////////////////////////////////////////////////////////////////////// - // compile a list of parameters CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars) diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 8ae8e36..cc1cb2d 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -565,23 +565,6 @@ class CBotEmpty : public CBotInstr void RestoreState(CBotStack* &pj, bool bMain) override; }; -// defininition of a boolean - -class CBotBoolean : public CBotInstr -{ -private: - CBotInstr* m_var; // variable to initialise - CBotInstr* m_expr; // a value to put, if there is - -public: - CBotBoolean(); - ~CBotBoolean(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false); - bool Execute(CBotStack* &pj) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - #define MAX(a,b) ((a>b) ? a : b) diff --git a/src/CBot/CBotInstr/CBotBoolean.cpp b/src/CBot/CBotInstr/CBotBoolean.cpp new file mode 100644 index 0000000..9e74fff --- /dev/null +++ b/src/CBot/CBotInstr/CBotBoolean.cpp @@ -0,0 +1,172 @@ +/* + * 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 + */ + +// Modules inlcude +#include "CBotBoolean.h" +#include "CBotLeftExprVar.h" +#include "CBotTwoOpExpr.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotBoolean::CBotBoolean() +{ + m_var = + m_expr = nullptr; + name = "CBotBoolean"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotBoolean::~CBotBoolean() +{ + delete m_var; + delete m_expr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip) +{ + CBotToken* pp = cont ? nullptr : p; + + if (!cont && !IsOfType(p, ID_BOOLEAN, ID_BOOL)) return nullptr; + + CBotBoolean* inst = static_cast<CBotBoolean*>(CompileArray(p, pStack, CBotTypBoolean)); + if (inst != nullptr || !pStack->IsOk()) return inst; + + CBotCStack* pStk = pStack->TokenStack(pp); + + inst = new CBotBoolean(); + + inst->m_expr = nullptr; + + CBotToken* vartoken = p; + inst->SetToken(vartoken); + CBotVar* var = nullptr; + + if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk ))) + { + (static_cast<CBotLeftExprVar*>(inst->m_var))->m_typevar = CBotTypBoolean; + if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable + { + pStk->SetError(TX_REDEFVAR, vartoken); + goto error; + } + + if (IsOfType(p, ID_OPBRK)) + { + delete inst; // type is not CBotInt + p = vartoken; // resutns to the variable name + + // compiles an array declaration + + inst = static_cast<CBotBoolean*>(CBotInstArray::Compile(p, pStk, CBotTypBoolean)); + + if (!pStk->IsOk() ) + { + pStk->SetError(TX_CLBRK, p->GetStart()); + goto error; + } + goto suite; // no assignment, variable already created + } + + if (IsOfType(p, ID_ASS)) + { + if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) + { + goto error; + } + if (!pStk->GetTypResult().Eq(CBotTypBoolean)) + { + pStk->SetError(TX_BADTYPE, p->GetStart()); + goto error; + } + } + + var = CBotVar::Create(vartoken, CBotTypBoolean);// create the variable (evaluated after the assignment) + var->SetInit(inst->m_expr != nullptr ? CBotVar::InitType::DEF : CBotVar::InitType::UNDEF); + var->SetUniqNum( + (static_cast<CBotLeftExprVar*>(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); + pStack->AddVar(var); +suite: + if (IsOfType(p, ID_COMMA)) + { + if (nullptr != ( inst->m_next2b = CBotBoolean::Compile(p, pStk, true, noskip))) + { + return pStack->Return(inst, pStk); + } + } + + if (noskip || IsOfType(p, ID_SEP)) + { + return pStack->Return(inst, pStk); + } + + pStk->SetError(TX_ENDOF, p->GetStart()); + } + +error: + delete inst; + return pStack->Return(nullptr, pStk); +} + +//////////////////////////////////////////////////////////////////////////////// +bool CBotBoolean::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this);//essential for SetState() + + if ( pile->GetState()==0) + { + if (m_expr && !m_expr->Execute(pile)) return false; + m_var->Execute(pile); + + if (!pile->SetState(1)) return false; + } + + if (pile->IfStep()) return false; + + if ( m_next2b && + !m_next2b->Execute(pile)) return false; + + return pj->Return(pile); +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotBoolean::RestoreState(CBotStack* &pj, bool bMain) +{ + CBotStack* pile = pj; + if (bMain) + { + pile = pj->RestoreStack(this); + if (pile == nullptr) return; + + if ( pile->GetState()==0) + { + if (m_expr) m_expr->RestoreState(pile, bMain); // initial value interrupted? + return; + } + } + + m_var->RestoreState(pile, bMain); + + if (m_next2b) + m_next2b->RestoreState(pile, bMain); // other(s) definition(s) +} diff --git a/src/CBot/CBotInstr/CBotBoolean.h b/src/CBot/CBotInstr/CBotBoolean.h new file mode 100644 index 0000000..5767420 --- /dev/null +++ b/src/CBot/CBotInstr/CBotBoolean.h @@ -0,0 +1,76 @@ +/* + * 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 CBotBoolean class Defining a boolean variable int a, b = false; + */ +class CBotBoolean : public CBotInstr +{ +public: + + /*! + * \brief CBotBoolean + */ + CBotBoolean(); + + /*! + * \brief ~CBotBoolean + */ + ~CBotBoolean(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \param cont + * \param noskip + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false); + + /*! + * \brief Execute Executes a boolean variable definition. + * \param pj + * \return + */ + bool Execute(CBotStack* &pj) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! Variable to initialise. + CBotInstr* m_var; + //! A value to put, if there is. + CBotInstr* m_expr; +}; diff --git a/src/CBot/CBotInstr/CBotListExpression.cpp b/src/CBot/CBotInstr/CBotListExpression.cpp index 0d2ec83..a6a58e5 100644 --- a/src/CBot/CBotInstr/CBotListExpression.cpp +++ b/src/CBot/CBotInstr/CBotListExpression.cpp @@ -22,6 +22,7 @@ #include "CBotExpression.h" #include "CBotIString.h" #include "CBotFloat.h" +#include "CBotBoolean.h" // Local include diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index 6004533..a001e1d 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -45,6 +45,7 @@ set(SOURCES CBotInstr/CBotClassInst.cpp CBotInstr/CBotIString.cpp CBotInstr/CBotFloat.cpp + CBotInstr/CBotBoolean.cpp ) # Includes -- 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