[colobot] 100/377: Moving CBotListArray 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 ede0d03026292a8e30373f37eb250aa5bf459a33
Author: Grunaka <dev at romainbreton.fr>
Date: Sat Nov 14 12:07:17 2015 +0100
Moving CBotListArray class in its own header and source files.
---
src/CBot/CBot.cpp | 154 +-----------------------------
src/CBot/CBot.h | 18 ----
src/CBot/CBotFunction.cpp | 1 +
src/CBot/CBotInstr/CBotListArray.cpp | 175 +++++++++++++++++++++++++++++++++++
src/CBot/CBotInstr/CBotListArray.h | 76 +++++++++++++++
src/CBot/CMakeLists.txt | 1 +
6 files changed, 254 insertions(+), 171 deletions(-)
diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp
index 03c6aab..bb40150 100644
--- a/src/CBot/CBot.cpp
+++ b/src/CBot/CBot.cpp
@@ -68,6 +68,7 @@
#include "CBotInstr/CBotEmpty.h"
#include "CBotInstr/CBotReturn.h"
#include "CBotInstr/CBotIf.h"
+#include "CBotInstr/CBotListArray.h"
// Local include
@@ -569,159 +570,6 @@ void CBotInstArray::RestoreState(CBotStack* &pj, bool bMain)
}
//////////////////////////////////////////////////////////////////////////////////////
-// defining a list table initialization
-// int [ ] a [ ] = (( 1, 2, 3 ) , ( 3, 2, 1 )) ;
-
-
-CBotListArray::CBotListArray()
-{
- m_expr = nullptr;
- name = "CBotListArray";
-}
-
-CBotListArray::~CBotListArray()
-{
- delete m_expr;
-}
-
-
-CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type)
-{
- CBotCStack* pStk = pStack->TokenStack(p);
-
- CBotToken* pp = p;
-
- if (IsOfType( p, ID_NULL ))
- {
- CBotInstr* inst = new CBotExprNull ();
- inst->SetToken(pp);
- return pStack->Return(inst, pStk); // ok with empty element
- }
-
- CBotListArray* inst = new CBotListArray();
-
- if (IsOfType( p, ID_OPENPAR ))
- {
- // each element takes the one after the other
- if (type.Eq( CBotTypArrayPointer ))
- {
- type = type.GetTypElem();
-
- pStk->SetStartError(p->GetStart());
- if (nullptr == ( inst->m_expr = CBotListArray::Compile( p, pStk, type ) ))
- {
- goto error;
- }
-
- while (IsOfType( p, ID_COMMA )) // other elements?
- {
- pStk->SetStartError(p->GetStart());
-
- CBotInstr* i = CBotListArray::Compile(p, pStk, type);
- if (nullptr == i)
- {
- goto error;
- }
-
- inst->m_expr->AddNext3(i);
- }
- }
- else
- {
- pStk->SetStartError(p->GetStart());
- if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
- {
- goto error;
- }
- CBotVar* pv = pStk->GetVar(); // result of the expression
-
- if (pv == nullptr || !TypesCompatibles( type, pv->GetTypResult())) // compatible type?
- {
- pStk->SetError(TX_BADTYPE, p->GetStart());
- goto error;
- }
-
- while (IsOfType( p, ID_COMMA )) // other elements?
- {
- pStk->SetStartError(p->GetStart());
-
- CBotInstr* i = CBotTwoOpExpr::Compile(p, pStk) ;
- if (nullptr == i)
- {
- goto error;
- }
-
- CBotVar* pv = pStk->GetVar(); // result of the expression
-
- if (pv == nullptr || !TypesCompatibles( type, pv->GetTypResult())) // compatible type?
- {
- pStk->SetError(TX_BADTYPE, p->GetStart());
- goto error;
- }
- inst->m_expr->AddNext3(i);
- }
- }
-
- if (!IsOfType(p, ID_CLOSEPAR) )
- {
- pStk->SetError(TX_CLOSEPAR, p->GetStart());
- goto error;
- }
-
- return pStack->Return(inst, pStk);
- }
-
-error:
- delete inst;
- return pStack->Return(nullptr, pStk);
-}
-
-
-// executes the definition of an array
-
-bool CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar)
-{
- CBotStack* pile1 = pj->AddStack();
- CBotVar* pVar2;
-
- CBotInstr* p = m_expr;
-
- int n = 0;
-
- for (; p != nullptr ; n++, p = p->GetNext3())
- {
- if (pile1->GetState() > n) continue;
-
- pVar2 = pVar->GetItem(n, true);
-
- if (!p->Execute(pile1, pVar2)) return false; // evaluate expression
-
- pile1->IncState();
- }
-
- return pj->Return(pile1);
-}
-
-void CBotListArray::RestoreState(CBotStack* &pj, bool bMain)
-{
- if (bMain)
- {
- CBotStack* pile = pj->RestoreStack(this);
- if (pile == nullptr) return;
-
- CBotInstr* p = m_expr;
-
- int state = pile->GetState();
-
- while(state-- > 0) p = p->GetNext3() ;
-
- p->RestoreState(pile, bMain); // size calculation //interrupted!
- }
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////////////////////
// definition of an integer variable
// int a, b = 12;
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index d180474..e663e8e 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -505,24 +505,6 @@ public:
void RestoreState(CBotStack* &pj, bool bMain) override;
};
-
-// definition of a assignment list for a table
-// int [ ] a [ ] = ( ( 1, 2, 3 ) , ( 3, 2, 1 ) ) ;
-
-class CBotListArray : public CBotInstr
-{
-private:
- CBotInstr* m_expr; // an expression for an element
- // others are linked with CBotInstr :: m_next3;
-public:
- CBotListArray();
- ~CBotListArray();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);
- bool Execute(CBotStack* &pj, CBotVar* pVar) override;
- void RestoreState(CBotStack* &pj, bool bMain) override;
-};
-
#define MAX(a,b) ((a>b) ? a : b)
diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp
index 090f28d..88bfabd 100644
--- a/src/CBot/CBotFunction.cpp
+++ b/src/CBot/CBotFunction.cpp
@@ -27,6 +27,7 @@
#include "CBotInstr/CBotTwoOpExpr.h"
#include "CBotInstr/CBotExpression.h"
#include "CBotInstr/CBotEmpty.h"
+#include "CBotInstr/CBotListArray.h"
#include <cassert>
diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp
new file mode 100644
index 0000000..8ab3207
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotListArray.cpp
@@ -0,0 +1,175 @@
+/*
+ * 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 "CBotListArray.h"
+
+#include "CBotExprNull.h"
+#include "CBotTwoOpExpr.h"
+
+// Local include
+
+// Global include
+
+////////////////////////////////////////////////////////////////////////////////
+CBotListArray::CBotListArray()
+{
+ m_expr = nullptr;
+ name = "CBotListArray";
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotListArray::~CBotListArray()
+{
+ delete m_expr;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type)
+{
+ CBotCStack* pStk = pStack->TokenStack(p);
+
+ CBotToken* pp = p;
+
+ if (IsOfType( p, ID_NULL ))
+ {
+ CBotInstr* inst = new CBotExprNull ();
+ inst->SetToken(pp);
+ return pStack->Return(inst, pStk); // ok with empty element
+ }
+
+ CBotListArray* inst = new CBotListArray();
+
+ if (IsOfType( p, ID_OPENPAR ))
+ {
+ // each element takes the one after the other
+ if (type.Eq( CBotTypArrayPointer ))
+ {
+ type = type.GetTypElem();
+
+ pStk->SetStartError(p->GetStart());
+ if (nullptr == ( inst->m_expr = CBotListArray::Compile( p, pStk, type ) ))
+ {
+ goto error;
+ }
+
+ while (IsOfType( p, ID_COMMA )) // other elements?
+ {
+ pStk->SetStartError(p->GetStart());
+
+ CBotInstr* i = CBotListArray::Compile(p, pStk, type);
+ if (nullptr == i)
+ {
+ goto error;
+ }
+
+ inst->m_expr->AddNext3(i);
+ }
+ }
+ else
+ {
+ pStk->SetStartError(p->GetStart());
+ if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
+ {
+ goto error;
+ }
+ CBotVar* pv = pStk->GetVar(); // result of the expression
+
+ if (pv == nullptr || !TypesCompatibles( type, pv->GetTypResult())) // compatible type?
+ {
+ pStk->SetError(TX_BADTYPE, p->GetStart());
+ goto error;
+ }
+
+ while (IsOfType( p, ID_COMMA )) // other elements?
+ {
+ pStk->SetStartError(p->GetStart());
+
+ CBotInstr* i = CBotTwoOpExpr::Compile(p, pStk) ;
+ if (nullptr == i)
+ {
+ goto error;
+ }
+
+ CBotVar* pv = pStk->GetVar(); // result of the expression
+
+ if (pv == nullptr || !TypesCompatibles( type, pv->GetTypResult())) // compatible type?
+ {
+ pStk->SetError(TX_BADTYPE, p->GetStart());
+ goto error;
+ }
+ inst->m_expr->AddNext3(i);
+ }
+ }
+
+ if (!IsOfType(p, ID_CLOSEPAR) )
+ {
+ pStk->SetError(TX_CLOSEPAR, p->GetStart());
+ goto error;
+ }
+
+ return pStack->Return(inst, pStk);
+ }
+
+error:
+ delete inst;
+ return pStack->Return(nullptr, pStk);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar)
+{
+ CBotStack* pile1 = pj->AddStack();
+ CBotVar* pVar2;
+
+ CBotInstr* p = m_expr;
+
+ int n = 0;
+
+ for (; p != nullptr ; n++, p = p->GetNext3())
+ {
+ if (pile1->GetState() > n) continue;
+
+ pVar2 = pVar->GetItem(n, true);
+
+ if (!p->Execute(pile1, pVar2)) return false; // evaluate expression
+
+ pile1->IncState();
+ }
+
+ return pj->Return(pile1);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotListArray::RestoreState(CBotStack* &pj, bool bMain)
+{
+ if (bMain)
+ {
+ CBotStack* pile = pj->RestoreStack(this);
+ if (pile == nullptr) return;
+
+ CBotInstr* p = m_expr;
+
+ int state = pile->GetState();
+
+ while(state-- > 0) p = p->GetNext3() ;
+
+ p->RestoreState(pile, bMain); // size calculation //interrupted!
+ }
+}
diff --git a/src/CBot/CBotInstr/CBotListArray.h b/src/CBot/CBotInstr/CBotListArray.h
new file mode 100644
index 0000000..921273d
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotListArray.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 CBotListArray class Definition of a assignment list for a table
+ * int [ ] a [ ] = ( ( 1, 2, 3 ) , ( 3, 2, 1 ) ) ;
+ */
+class CBotListArray : public CBotInstr
+{
+
+public:
+
+ /*!
+ * \brief CBotListArray
+ */
+ CBotListArray();
+
+ /*!
+ * \brief ~CBotListArray
+ */
+ ~CBotListArray();
+
+ /*!
+ * \brief Compile
+ * \param p
+ * \param pStack
+ * \param type
+ * \return
+ */
+ static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);
+
+ /*!
+ * \brief Execute Executes the definition of an array.
+ * \param pj
+ * \param pVar
+ * \return
+ */
+ bool Execute(CBotStack* &pj, CBotVar* pVar) override;
+
+ /*!
+ * \brief RestoreState
+ * \param pj
+ * \param bMain
+ */
+ void RestoreState(CBotStack* &pj, bool bMain) override;
+
+private:
+ //! An expression for an element others are linked with CBotInstr :: m_next3;
+ CBotInstr* m_expr;
+};
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index 8469f46..64a97f6 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -48,6 +48,7 @@ set(SOURCES
CBotInstr/CBotEmpty.cpp
CBotInstr/CBotReturn.cpp
CBotInstr/CBotIf.cpp
+ CBotInstr/CBotListArray.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