This is an automated email from the git hooks/post-receive script. odyx pushed a commit to branch debian/master in repository colobot.
commit f6cc7d2c9c91baf08bd53b9616590f18737fc814 Author: Grunaka <d...@romainbreton.fr> Date: Wed Nov 11 20:15:42 2015 +0100 Moving CBotExprUnaire class in its own header and source files. --- src/CBot/CBot.cpp | 100 +--------------------------- src/CBot/CBot.h | 14 ---- src/CBot/CBotInstr/CBotExprUnaire.cpp | 118 ++++++++++++++++++++++++++++++++++ src/CBot/CBotInstr/CBotExprUnaire.h | 73 +++++++++++++++++++++ src/CBot/CMakeLists.txt | 1 + 5 files changed, 193 insertions(+), 113 deletions(-) diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index 042e4c7..de9f730 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -55,6 +55,7 @@ #include "CBotInstr/CBotExprVar.h" #include "CBotInstr/CBotInstrCall.h" #include "CBotInstr/CBotListInstr.h" +#include "CBotInstr/CBotExprUnaire.h" // Local include @@ -1840,105 +1841,6 @@ CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack) return pStack->Return(nullptr, pStk); } - -////////////////////////////////////////////////////////////////////////////////////// -// compile an unary expression -// + -// - -// not -// ! -// ~ - -CBotExprUnaire::CBotExprUnaire() -{ - m_Expr = nullptr; - name = "CBotExprUnaire"; -} - -CBotExprUnaire::~CBotExprUnaire() -{ - delete m_Expr; -} - -CBotInstr* CBotExprUnaire::Compile(CBotToken* &p, CBotCStack* pStack) -{ - int op = p->GetType(); - CBotToken* pp = p; - if (!IsOfTypeList( p, ID_ADD, ID_SUB, ID_LOG_NOT, ID_TXT_NOT, ID_NOT, 0 )) return nullptr; - - CBotCStack* pStk = pStack->TokenStack(pp); - - CBotExprUnaire* inst = new CBotExprUnaire(); - inst->SetToken(pp); - - if (nullptr != (inst->m_Expr = CBotParExpr::Compile( p, pStk ))) - { - if (op == ID_ADD && pStk->GetType() < CBotTypBoolean) // only with the number - return pStack->Return(inst, pStk); - if (op == ID_SUB && pStk->GetType() < CBotTypBoolean) // only with the numer - return pStack->Return(inst, pStk); - if (op == ID_NOT && pStk->GetType() < CBotTypFloat) // only with an integer - return pStack->Return(inst, pStk); - if (op == ID_LOG_NOT && pStk->GetTypResult().Eq(CBotTypBoolean))// only with boolean - return pStack->Return(inst, pStk); - if (op == ID_TXT_NOT && pStk->GetTypResult().Eq(CBotTypBoolean))// only with boolean - return pStack->Return(inst, pStk); - - pStk->SetError(TX_BADTYPE, &inst->m_token); - } - delete inst; - return pStack->Return(nullptr, pStk); -} - -// executes unary expression - -bool CBotExprUnaire::Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); - - if (pile->GetState() == 0) - { - if (!m_Expr->Execute(pile)) return false; // interrupted ? - pile->IncState(); - } - - CBotStack* pile2 = pile->AddStack(); - if (pile2->IfStep()) return false; - - CBotVar* var = pile->GetVar(); // get the result on the stack - - switch (GetTokenType()) - { - case ID_ADD: - break; - case ID_SUB: - var->Neg(); // change the sign - break; - case ID_NOT: - case ID_LOG_NOT: - case ID_TXT_NOT: - var->Not(); - break; - } - return pj->Return(pile); // forwards below -} - -void CBotExprUnaire::RestoreState(CBotStack* &pj, bool bMain) -{ - if (!bMain) return; - - CBotStack* pile = pj->RestoreStack(this); - if ( pile == nullptr) return; - - if (pile->GetState() == 0) - { - m_Expr->RestoreState(pile, bMain); // interrupted here! - return; - } -} - -////////////////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////////////// // index management for arrays // array [ expression ] diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 32cdb69..6ae6885 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -769,20 +769,6 @@ public: CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); }; -// unary expression -class CBotExprUnaire : public CBotInstr -{ -private: - CBotInstr* m_Expr; // expression to be evaluated -public: - CBotExprUnaire(); - ~CBotExprUnaire(); - static - CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - bool Execute(CBotStack* &pStack) override; - void RestoreState(CBotStack* &pj, bool bMain) override; -}; - // all operations with two operands class CBotTwoOpExpr : public CBotInstr diff --git a/src/CBot/CBotInstr/CBotExprUnaire.cpp b/src/CBot/CBotInstr/CBotExprUnaire.cpp new file mode 100644 index 0000000..1d63f1d --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprUnaire.cpp @@ -0,0 +1,118 @@ +/* + * 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 "CBotExprUnaire.h" + +// Local include + +// Global include + + +//////////////////////////////////////////////////////////////////////////////// +CBotExprUnaire::CBotExprUnaire() +{ + m_Expr = nullptr; + name = "CBotExprUnaire"; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotExprUnaire::~CBotExprUnaire() +{ + delete m_Expr; +} + +//////////////////////////////////////////////////////////////////////////////// +CBotInstr* CBotExprUnaire::Compile(CBotToken* &p, CBotCStack* pStack) +{ + int op = p->GetType(); + CBotToken* pp = p; + if (!IsOfTypeList( p, ID_ADD, ID_SUB, ID_LOG_NOT, ID_TXT_NOT, ID_NOT, 0 )) return nullptr; + + CBotCStack* pStk = pStack->TokenStack(pp); + + CBotExprUnaire* inst = new CBotExprUnaire(); + inst->SetToken(pp); + + if (nullptr != (inst->m_Expr = CBotParExpr::Compile( p, pStk ))) + { + if (op == ID_ADD && pStk->GetType() < CBotTypBoolean) // only with the number + return pStack->Return(inst, pStk); + if (op == ID_SUB && pStk->GetType() < CBotTypBoolean) // only with the numer + return pStack->Return(inst, pStk); + if (op == ID_NOT && pStk->GetType() < CBotTypFloat) // only with an integer + return pStack->Return(inst, pStk); + if (op == ID_LOG_NOT && pStk->GetTypResult().Eq(CBotTypBoolean))// only with boolean + return pStack->Return(inst, pStk); + if (op == ID_TXT_NOT && pStk->GetTypResult().Eq(CBotTypBoolean))// only with boolean + return pStack->Return(inst, pStk); + + pStk->SetError(TX_BADTYPE, &inst->m_token); + } + delete inst; + return pStack->Return(nullptr, pStk); +} + +// executes unary expression +//////////////////////////////////////////////////////////////////////////////// +bool CBotExprUnaire::Execute(CBotStack* &pj) +{ + CBotStack* pile = pj->AddStack(this); + + if (pile->GetState() == 0) + { + if (!m_Expr->Execute(pile)) return false; // interrupted ? + pile->IncState(); + } + + CBotStack* pile2 = pile->AddStack(); + if (pile2->IfStep()) return false; + + CBotVar* var = pile->GetVar(); // get the result on the stack + + switch (GetTokenType()) + { + case ID_ADD: + break; + case ID_SUB: + var->Neg(); // change the sign + break; + case ID_NOT: + case ID_LOG_NOT: + case ID_TXT_NOT: + var->Not(); + break; + } + return pj->Return(pile); // forwards below +} + +//////////////////////////////////////////////////////////////////////////////// +void CBotExprUnaire::RestoreState(CBotStack* &pj, bool bMain) +{ + if (!bMain) return; + + CBotStack* pile = pj->RestoreStack(this); + if ( pile == nullptr) return; + + if (pile->GetState() == 0) + { + m_Expr->RestoreState(pile, bMain); // interrupted here! + return; + } +} diff --git a/src/CBot/CBotInstr/CBotExprUnaire.h b/src/CBot/CBotInstr/CBotExprUnaire.h new file mode 100644 index 0000000..25d2125 --- /dev/null +++ b/src/CBot/CBotInstr/CBotExprUnaire.h @@ -0,0 +1,73 @@ +/* + * 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 CBotExprUnaire class Unary expression. Compile an unary expression + * eg : (+, * -, not, !, ~) + */ +class CBotExprUnaire : public CBotInstr +{ +public: + + /*! + * \brief CBotExprUnaire + */ + CBotExprUnaire(); + + /*! + * \brief ~CBotExprUnaire + */ + ~CBotExprUnaire(); + + /*! + * \brief Compile + * \param p + * \param pStack + * \return + */ + static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); + + /*! + * \brief Execute + * \param pStack + * \return + */ + bool Execute(CBotStack* &pStack) override; + + /*! + * \brief RestoreState + * \param pj + * \param bMain + */ + void RestoreState(CBotStack* &pj, bool bMain) override; + +private: + //! Expression to be evaluated. + CBotInstr* m_Expr; +}; diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index ac6a0c0..4cff8ef 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -33,6 +33,7 @@ set(SOURCES CBotInstr/CBotInstrCall.cpp CBotInstr/CBotListInstr.cpp CBotInstr/CBotBlock.cpp + CBotInstr/CBotExprUnaire.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