[colobot] 95/377: Moving CBotFloat class in its own header and source files.
Didier Raboud
odyx at moszumanska.debian.org
Wed Mar 30 13:34:02 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 ff72d1a77f2cfeffce46fbe1d5e73bd4aa32c72b
Author: Grunaka <dev at romainbreton.fr>
Date: Wed Nov 11 22:54:10 2015 +0100
Moving CBotFloat class in its own header and source files.
---
src/CBot/CBot.cpp | 147 +-------------------------
src/CBot/CBot.h | 19 ----
src/CBot/CBotInstr/CBotFloat.cpp | 170 ++++++++++++++++++++++++++++++
src/CBot/CBotInstr/CBotFloat.h | 76 +++++++++++++
src/CBot/CBotInstr/CBotListExpression.cpp | 1 +
src/CBot/CMakeLists.txt | 1 +
6 files changed, 249 insertions(+), 165 deletions(-)
diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp
index 072aa28..5cb8cac 100644
--- a/src/CBot/CBot.cpp
+++ b/src/CBot/CBot.cpp
@@ -63,6 +63,7 @@
#include "CBotInstr/CBotFieldExpr.h"
#include "CBotInstr/CBotClassInst.h"
#include "CBotInstr/CBotIString.h"
+#include "CBotInstr/CBotFloat.h"
// Local include
@@ -1075,152 +1076,6 @@ void CBotBoolean::RestoreState(CBotStack* &pj, bool bMain)
//////////////////////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////////////////////
-// definition of a real/float variable
-// int a, b = 12.4;
-
-CBotFloat::CBotFloat()
-{
- m_var =
- m_expr = nullptr;
- name = "CBotFloat";
-}
-
-CBotFloat::~CBotFloat()
-{
- delete m_var;
- delete m_expr;
-}
-
-CBotInstr* CBotFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip)
-{
- CBotToken* pp = cont ? nullptr : p;
-
- if (!cont && !IsOfType(p, ID_FLOAT)) return nullptr;
-
- CBotFloat* inst = static_cast<CBotFloat*>(CompileArray(p, pStack, CBotTypFloat));
- if (inst != nullptr || !pStack->IsOk()) return inst;
-
- CBotCStack* pStk = pStack->TokenStack(pp);
-
- inst = new CBotFloat();
-
- inst->m_expr = nullptr;
-
- CBotToken* vartoken = p;
- CBotVar* var = nullptr;
- inst->SetToken(vartoken);
-
- if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )))
- {
- (static_cast<CBotLeftExprVar*>(inst->m_var))->m_typevar = CBotTypFloat;
- if (pStk->CheckVarLocal(vartoken)) // redefinition of a variable
- {
- pStk->SetStartError(vartoken->GetStart());
- pStk->SetError(TX_REDEFVAR, vartoken->GetEnd());
- goto error;
- }
-
- if (IsOfType(p, ID_OPBRK))
- {
- delete inst;
- p = vartoken;
- inst = static_cast<CBotFloat*>(CBotInstArray::Compile(p, pStk, CBotTypFloat));
-
- 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->GetType() >= CBotTypBoolean)
- {
- pStk->SetError(TX_BADTYPE, p->GetStart());
- goto error;
- }
- }
-
- var = CBotVar::Create(vartoken, CBotTypFloat);
- 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 = CBotFloat::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 the definition of a real variable
-
-bool CBotFloat::Execute(CBotStack* &pj)
-{
- CBotStack* pile = pj->AddStack(this);
-
- 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 CBotFloat::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);
- return;
- }
- }
-
- m_var->RestoreState(pile, bMain);
-
- if (m_next2b)
- m_next2b->RestoreState(pile, bMain);
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////
-
// 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 9c1a8e2..8ae8e36 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -582,25 +582,6 @@ public:
void RestoreState(CBotStack* &pj, bool bMain) override;
};
-
-// definition of a real number
-
-class CBotFloat : public CBotInstr
-{
-private:
- CBotInstr* m_var; // variable to initialise
- CBotInstr* m_expr; // a value to put, if there is
-
-public:
- CBotFloat();
- ~CBotFloat();
- 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/CBotFloat.cpp b/src/CBot/CBotInstr/CBotFloat.cpp
new file mode 100644
index 0000000..96c730b
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotFloat.cpp
@@ -0,0 +1,170 @@
+/*
+ * 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 "CBotFloat.h"
+#include "CBotLeftExprVar.h"
+#include "CBotTwoOpExpr.h"
+
+// Local include
+
+// Global include
+
+
+////////////////////////////////////////////////////////////////////////////////
+CBotFloat::CBotFloat()
+{
+ m_var =
+ m_expr = nullptr;
+ name = "CBotFloat";
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotFloat::~CBotFloat()
+{
+ delete m_var;
+ delete m_expr;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotInstr* CBotFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip)
+{
+ CBotToken* pp = cont ? nullptr : p;
+
+ if (!cont && !IsOfType(p, ID_FLOAT)) return nullptr;
+
+ CBotFloat* inst = static_cast<CBotFloat*>(CompileArray(p, pStack, CBotTypFloat));
+ if (inst != nullptr || !pStack->IsOk()) return inst;
+
+ CBotCStack* pStk = pStack->TokenStack(pp);
+
+ inst = new CBotFloat();
+
+ inst->m_expr = nullptr;
+
+ CBotToken* vartoken = p;
+ CBotVar* var = nullptr;
+ inst->SetToken(vartoken);
+
+ if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )))
+ {
+ (static_cast<CBotLeftExprVar*>(inst->m_var))->m_typevar = CBotTypFloat;
+ if (pStk->CheckVarLocal(vartoken)) // redefinition of a variable
+ {
+ pStk->SetStartError(vartoken->GetStart());
+ pStk->SetError(TX_REDEFVAR, vartoken->GetEnd());
+ goto error;
+ }
+
+ if (IsOfType(p, ID_OPBRK))
+ {
+ delete inst;
+ p = vartoken;
+ inst = static_cast<CBotFloat*>(CBotInstArray::Compile(p, pStk, CBotTypFloat));
+
+ 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->GetType() >= CBotTypBoolean)
+ {
+ pStk->SetError(TX_BADTYPE, p->GetStart());
+ goto error;
+ }
+ }
+
+ var = CBotVar::Create(vartoken, CBotTypFloat);
+ 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 = CBotFloat::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 CBotFloat::Execute(CBotStack* &pj)
+{
+ CBotStack* pile = pj->AddStack(this);
+
+ 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 CBotFloat::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);
+ return;
+ }
+ }
+
+ m_var->RestoreState(pile, bMain);
+
+ if (m_next2b)
+ m_next2b->RestoreState(pile, bMain);
+}
diff --git a/src/CBot/CBotInstr/CBotFloat.h b/src/CBot/CBotInstr/CBotFloat.h
new file mode 100644
index 0000000..6223071
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotFloat.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 CBotFloat class Definition of a real/float variable int a, b = 12.4;
+ */
+class CBotFloat : public CBotInstr
+{
+public:
+
+ /*!
+ * \brief CBotFloat
+ */
+ CBotFloat();
+
+ /*!
+ * \brief ~CBotFloat
+ */
+ ~CBotFloat();
+
+ /*!
+ * \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 the definition of a real variable.
+ * \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 285c616..0d2ec83 100644
--- a/src/CBot/CBotInstr/CBotListExpression.cpp
+++ b/src/CBot/CBotInstr/CBotListExpression.cpp
@@ -21,6 +21,7 @@
#include "CBotListExpression.h"
#include "CBotExpression.h"
#include "CBotIString.h"
+#include "CBotFloat.h"
// Local include
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index a0b76fc..6004533 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -44,6 +44,7 @@ set(SOURCES
CBotInstr/CBotCondition.cpp
CBotInstr/CBotClassInst.cpp
CBotInstr/CBotIString.cpp
+ CBotInstr/CBotFloat.cpp
)
# Includes
--
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