[colobot] 101/377: Moving CBotInstArray class in its own header and source files.
Didier Raboud
odyx at moszumanska.debian.org
Wed Mar 30 13:34:03 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 b01e2180d89c0a1b5cd3bc3ce7a24b6ac45f54a9
Author: Grunaka <dev at romainbreton.fr>
Date: Sat Nov 14 12:18:34 2015 +0100
Moving CBotInstArray class in its own header and source files.
---
src/CBot/CBot.cpp | 198 +------------------------------
src/CBot/CBot.h | 20 ----
src/CBot/CBotInstr/CBotBoolean.cpp | 1 +
src/CBot/CBotInstr/CBotClassInst.cpp | 1 +
src/CBot/CBotInstr/CBotFloat.cpp | 1 +
src/CBot/CBotInstr/CBotInstArray.cpp | 224 +++++++++++++++++++++++++++++++++++
src/CBot/CBotInstr/CBotInstArray.h | 82 +++++++++++++
src/CBot/CMakeLists.txt | 1 +
8 files changed, 311 insertions(+), 217 deletions(-)
diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp
index bb40150..84d7398 100644
--- a/src/CBot/CBot.cpp
+++ b/src/CBot/CBot.cpp
@@ -69,6 +69,7 @@
#include "CBotInstr/CBotReturn.h"
#include "CBotInstr/CBotIf.h"
#include "CBotInstr/CBotListArray.h"
+#include "CBotInstr/CBotInstArray.h"
// Local include
@@ -373,203 +374,6 @@ bool CBotInstr::CompCase(CBotStack* &pj, int val)
}
//////////////////////////////////////////////////////////////////////////////////////
-// defining an array of any type
-// int a[12];
-// point x[];
-
-CBotInstArray::CBotInstArray()
-{
- m_var = nullptr;
- m_listass = nullptr;
- name = "CBotInstArray";
-}
-
-CBotInstArray::~CBotInstArray()
-{
- delete m_var;
- delete m_listass;
-}
-
-
-CBotInstr* CBotInstArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type)
-{
- CBotCStack* pStk = pStack->TokenStack(p);
-
- CBotInstArray* inst = new CBotInstArray();
-
- CBotToken* vartoken = p;
- inst->SetToken(vartoken);
-
- // determinse the expression is valid for the item on the left side
- if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )))
- {
- if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable?
- {
- pStk->SetError(TX_REDEFVAR, vartoken);
- goto error;
- }
-
- CBotInstr* i;
- while (IsOfType(p, ID_OPBRK))
- {
- if (p->GetType() != ID_CLBRK)
- i = CBotExpression::Compile(p, pStk); // expression for the value
- else
- i = new CBotEmpty(); // if no special formula
-
- inst->AddNext3b(i); // construct a list
- type = CBotTypResult(CBotTypArrayPointer, type);
-
- if (!pStk->IsOk() || !IsOfType(p, ID_CLBRK ))
- {
- pStk->SetError(TX_CLBRK, p->GetStart());
- goto error;
- }
- }
-
- CBotVar* var = CBotVar::Create(vartoken, type); // create an instance
- inst->m_typevar = type;
-
- var->SetUniqNum(
- (static_cast<CBotLeftExprVar*>(inst->m_var))->m_nIdent = CBotVar::NextUniqNum());
- pStack->AddVar(var); // place it on the stack
-
- if (IsOfType(p, ID_ASS)) // with an assignment
- {
- inst->m_listass = CBotListArray::Compile(p, pStk, type.GetTypElem());
- }
-
- if (pStk->IsOk()) return pStack->Return(inst, pStk);
- }
-
-error:
- delete inst;
- return pStack->Return(nullptr, pStk);
-}
-
-
-// executes the definition of an array
-
-bool CBotInstArray::Execute(CBotStack* &pj)
-{
- CBotStack* pile1 = pj->AddStack(this);
-
- CBotStack* pile = pile1;
-
- if (pile1->GetState() == 0)
- {
- // seek the maximum dimension of the table
- CBotInstr* p = GetNext3b(); // the different formulas
- int nb = 0;
-
- while (p != nullptr)
- {
- pile = pile->AddStack(); // little room to work
- nb++;
- if (pile->GetState() == 0)
- {
- if (!p->Execute(pile)) return false; // size calculation //interrupted?
- pile->IncState();
- }
- p = p->GetNext3b();
- }
-
- p = GetNext3b();
- pile = pile1; // returns to the stack
- int n = 0;
- int max[100];
-
- while (p != nullptr)
- {
- pile = pile->AddStack();
- CBotVar* v = pile->GetVar(); // result
- max[n] = v->GetValInt(); // value
- if (max[n]>MAXARRAYSIZE)
- {
- pile->SetError(TX_OUTARRAY, &m_token);
- return pj->Return (pile);
- }
- n++;
- p = p->GetNext3b();
- }
- while (n<100) max[n++] = 0;
-
- m_typevar.SetArray(max); // store the limitations
-
- // create simply a nullptr pointer
- CBotVar* var = CBotVar::Create(m_var->GetToken(), m_typevar);
- var->SetPointer(nullptr);
- var->SetUniqNum((static_cast<CBotLeftExprVar*>(m_var))->m_nIdent);
- pj->AddVar(var);
-
-#if STACKMEM
- pile1->AddStack()->Delete();
-#else
- delete pile1->AddStack(); // need more indices
-#endif
- pile1->IncState();
- }
-
- if (pile1->GetState() == 1)
- {
- if (m_listass != nullptr) // there is the assignment for this table
- {
- CBotVar* pVar = pj->FindVar((static_cast<CBotLeftExprVar*>(m_var))->m_nIdent);
-
- if (!m_listass->Execute(pile1, pVar)) return false;
- }
- pile1->IncState();
- }
-
- if (pile1->IfStep()) return false;
-
- if ( m_next2b &&
- !m_next2b->Execute(pile1 )) return false;
-
- return pj->Return(pile1);
-}
-
-void CBotInstArray::RestoreState(CBotStack* &pj, bool bMain)
-{
- CBotStack* pile1 = pj;
-
- CBotVar* var = pj->FindVar(m_var->GetToken()->GetString());
- if (var != nullptr) var->SetUniqNum((static_cast<CBotLeftExprVar*>(m_var))->m_nIdent);
-
- if (bMain)
- {
- pile1 = pj->RestoreStack(this);
- CBotStack* pile = pile1;
- if (pile == nullptr) return;
-
- if (pile1->GetState() == 0)
- {
- // seek the maximum dimension of the table
- CBotInstr* p = GetNext3b();
-
- while (p != nullptr)
- {
- pile = pile->RestoreStack();
- if (pile == nullptr) return;
- if (pile->GetState() == 0)
- {
- p->RestoreState(pile, bMain);
- return;
- }
- p = p->GetNext3b();
- }
- }
- if (pile1->GetState() == 1 && m_listass != nullptr)
- {
- m_listass->RestoreState(pile1, bMain);
- }
-
- }
-
- if (m_next2b ) m_next2b->RestoreState( pile1, bMain);
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
// definition of an integer variable
// int a, b = 12;
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index e663e8e..4ccd6a9 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -485,26 +485,6 @@ public:
void RestoreState(CBotStack* &pj, bool bMain) override;
};
-// definition of an array
-
-class CBotInstArray : public CBotInstr
-{
-private:
- CBotInstr* m_var; // the variables to initialize
- CBotInstr* m_listass; // list of assignments for array
- CBotTypResult
- m_typevar; // type of elements
-// CBotString m_ClassName;
-
-public:
- CBotInstArray();
- ~CBotInstArray();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);
- 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
index 9e74fff..e2d2ad2 100644
--- a/src/CBot/CBotInstr/CBotBoolean.cpp
+++ b/src/CBot/CBotInstr/CBotBoolean.cpp
@@ -21,6 +21,7 @@
#include "CBotBoolean.h"
#include "CBotLeftExprVar.h"
#include "CBotTwoOpExpr.h"
+#include "CBotInstArray.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotClassInst.cpp b/src/CBot/CBotInstr/CBotClassInst.cpp
index cf835df..dfbd47b 100644
--- a/src/CBot/CBotInstr/CBotClassInst.cpp
+++ b/src/CBot/CBotInstr/CBotClassInst.cpp
@@ -21,6 +21,7 @@
#include "CBotClassInst.h"
#include "CBotLeftExprVar.h"
#include "CBotTwoOpExpr.h"
+#include "CBotInstArray.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotFloat.cpp b/src/CBot/CBotInstr/CBotFloat.cpp
index 96c730b..acc29ff 100644
--- a/src/CBot/CBotInstr/CBotFloat.cpp
+++ b/src/CBot/CBotInstr/CBotFloat.cpp
@@ -21,6 +21,7 @@
#include "CBotFloat.h"
#include "CBotLeftExprVar.h"
#include "CBotTwoOpExpr.h"
+#include "CBotInstArray.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotInstArray.cpp b/src/CBot/CBotInstr/CBotInstArray.cpp
new file mode 100644
index 0000000..b97e2b5
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotInstArray.cpp
@@ -0,0 +1,224 @@
+/*
+ * 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 "CBotInstArray.h"
+
+#include "CBotLeftExprVar.h"
+#include "CBotExpression.h"
+#include "CBotListArray.h"
+#include "CBotEmpty.h"
+
+// Local include
+
+// Global include
+
+
+////////////////////////////////////////////////////////////////////////////////
+CBotInstArray::CBotInstArray()
+{
+ m_var = nullptr;
+ m_listass = nullptr;
+ name = "CBotInstArray";
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotInstArray::~CBotInstArray()
+{
+ delete m_var;
+ delete m_listass;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotInstr* CBotInstArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type)
+{
+ CBotCStack* pStk = pStack->TokenStack(p);
+
+ CBotInstArray* inst = new CBotInstArray();
+
+ CBotToken* vartoken = p;
+ inst->SetToken(vartoken);
+
+ // determinse the expression is valid for the item on the left side
+ if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )))
+ {
+ if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable?
+ {
+ pStk->SetError(TX_REDEFVAR, vartoken);
+ goto error;
+ }
+
+ CBotInstr* i;
+ while (IsOfType(p, ID_OPBRK))
+ {
+ if (p->GetType() != ID_CLBRK)
+ i = CBotExpression::Compile(p, pStk); // expression for the value
+ else
+ i = new CBotEmpty(); // if no special formula
+
+ inst->AddNext3b(i); // construct a list
+ type = CBotTypResult(CBotTypArrayPointer, type);
+
+ if (!pStk->IsOk() || !IsOfType(p, ID_CLBRK ))
+ {
+ pStk->SetError(TX_CLBRK, p->GetStart());
+ goto error;
+ }
+ }
+
+ CBotVar* var = CBotVar::Create(vartoken, type); // create an instance
+ inst->m_typevar = type;
+
+ var->SetUniqNum(
+ (static_cast<CBotLeftExprVar*>(inst->m_var))->m_nIdent = CBotVar::NextUniqNum());
+ pStack->AddVar(var); // place it on the stack
+
+ if (IsOfType(p, ID_ASS)) // with an assignment
+ {
+ inst->m_listass = CBotListArray::Compile(p, pStk, type.GetTypElem());
+ }
+
+ if (pStk->IsOk()) return pStack->Return(inst, pStk);
+ }
+
+error:
+ delete inst;
+ return pStack->Return(nullptr, pStk);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotInstArray::Execute(CBotStack* &pj)
+{
+ CBotStack* pile1 = pj->AddStack(this);
+
+ CBotStack* pile = pile1;
+
+ if (pile1->GetState() == 0)
+ {
+ // seek the maximum dimension of the table
+ CBotInstr* p = GetNext3b(); // the different formulas
+ int nb = 0;
+
+ while (p != nullptr)
+ {
+ pile = pile->AddStack(); // little room to work
+ nb++;
+ if (pile->GetState() == 0)
+ {
+ if (!p->Execute(pile)) return false; // size calculation //interrupted?
+ pile->IncState();
+ }
+ p = p->GetNext3b();
+ }
+
+ p = GetNext3b();
+ pile = pile1; // returns to the stack
+ int n = 0;
+ int max[100];
+
+ while (p != nullptr)
+ {
+ pile = pile->AddStack();
+ CBotVar* v = pile->GetVar(); // result
+ max[n] = v->GetValInt(); // value
+ if (max[n]>MAXARRAYSIZE)
+ {
+ pile->SetError(TX_OUTARRAY, &m_token);
+ return pj->Return (pile);
+ }
+ n++;
+ p = p->GetNext3b();
+ }
+ while (n<100) max[n++] = 0;
+
+ m_typevar.SetArray(max); // store the limitations
+
+ // create simply a nullptr pointer
+ CBotVar* var = CBotVar::Create(m_var->GetToken(), m_typevar);
+ var->SetPointer(nullptr);
+ var->SetUniqNum((static_cast<CBotLeftExprVar*>(m_var))->m_nIdent);
+ pj->AddVar(var);
+
+#if STACKMEM
+ pile1->AddStack()->Delete();
+#else
+ delete pile1->AddStack(); // need more indices
+#endif
+ pile1->IncState();
+ }
+
+ if (pile1->GetState() == 1)
+ {
+ if (m_listass != nullptr) // there is the assignment for this table
+ {
+ CBotVar* pVar = pj->FindVar((static_cast<CBotLeftExprVar*>(m_var))->m_nIdent);
+
+ if (!m_listass->Execute(pile1, pVar)) return false;
+ }
+ pile1->IncState();
+ }
+
+ if (pile1->IfStep()) return false;
+
+ if ( m_next2b &&
+ !m_next2b->Execute(pile1 )) return false;
+
+ return pj->Return(pile1);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotInstArray::RestoreState(CBotStack* &pj, bool bMain)
+{
+ CBotStack* pile1 = pj;
+
+ CBotVar* var = pj->FindVar(m_var->GetToken()->GetString());
+ if (var != nullptr) var->SetUniqNum((static_cast<CBotLeftExprVar*>(m_var))->m_nIdent);
+
+ if (bMain)
+ {
+ pile1 = pj->RestoreStack(this);
+ CBotStack* pile = pile1;
+ if (pile == nullptr) return;
+
+ if (pile1->GetState() == 0)
+ {
+ // seek the maximum dimension of the table
+ CBotInstr* p = GetNext3b();
+
+ while (p != nullptr)
+ {
+ pile = pile->RestoreStack();
+ if (pile == nullptr) return;
+ if (pile->GetState() == 0)
+ {
+ p->RestoreState(pile, bMain);
+ return;
+ }
+ p = p->GetNext3b();
+ }
+ }
+ if (pile1->GetState() == 1 && m_listass != nullptr)
+ {
+ m_listass->RestoreState(pile1, bMain);
+ }
+
+ }
+
+ if (m_next2b ) m_next2b->RestoreState( pile1, bMain);
+}
diff --git a/src/CBot/CBotInstr/CBotInstArray.h b/src/CBot/CBotInstr/CBotInstArray.h
new file mode 100644
index 0000000..ca2cbe0
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotInstArray.h
@@ -0,0 +1,82 @@
+/*
+ * 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 CBotInstArray class Definition of an array.
+ * Defining an array of any type
+ * int a[12];
+ * point x[];
+ */
+class CBotInstArray : public CBotInstr
+{
+public:
+
+ /*!
+ * \brief CBotInstArray
+ */
+ CBotInstArray();
+
+ /*!
+ * \brief ~CBotInstArray
+ */
+ ~CBotInstArray();
+
+ /*!
+ * \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
+ * \return
+ */
+ bool Execute(CBotStack* &pj) override;
+
+ /*!
+ * \brief RestoreState
+ * \param pj
+ * \param bMain
+ */
+ void RestoreState(CBotStack* &pj, bool bMain) override;
+
+private:
+
+ //! The variables to initialize.
+ CBotInstr* m_var;
+ //! List of assignments for array.
+ CBotInstr* m_listass;
+ //! Type of elements.
+ CBotTypResult m_typevar;
+
+};
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index 64a97f6..baf7b8a 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -49,6 +49,7 @@ set(SOURCES
CBotInstr/CBotReturn.cpp
CBotInstr/CBotIf.cpp
CBotInstr/CBotListArray.cpp
+ CBotInstr/CBotInstArray.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