[colobot] 89/377: Moving CBotIndexExpr class in its own header and source files.
Didier Raboud
odyx at moszumanska.debian.org
Wed Mar 30 13:34:01 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 d0cfdfb998d15818d9e5ef31869cd836434e7dfe
Author: Grunaka <dev at romainbreton.fr>
Date: Wed Nov 11 21:55:02 2015 +0100
Moving CBotIndexExpr class in its own header and source files.
---
src/CBot/CBot.cpp | 98 +----------------------------
src/CBot/CBot.h | 17 ------
src/CBot/CBotInstr/CBotExprVar.cpp | 1 +
src/CBot/CBotInstr/CBotIndexExpr.cpp | 115 +++++++++++++++++++++++++++++++++++
src/CBot/CBotInstr/CBotIndexExpr.h | 81 ++++++++++++++++++++++++
src/CBot/CMakeLists.txt | 1 +
6 files changed, 199 insertions(+), 114 deletions(-)
diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp
index c2b392b..d0a1239 100644
--- a/src/CBot/CBot.cpp
+++ b/src/CBot/CBot.cpp
@@ -59,6 +59,7 @@
#include "CBotInstr/CBotBoolExpr.h"
#include "CBotInstr/CBotTwoOpExpr.h"
#include "CBotInstr/CBotExpression.h"
+#include "CBotInstr/CBotIndexExpr.h"
// Local include
@@ -1378,103 +1379,6 @@ CBotInstr* CBotCondition::Compile(CBotToken* &p, CBotCStack* pStack)
}
//////////////////////////////////////////////////////////////////////////////////////
-// index management for arrays
-// array [ expression ]
-
-
-CBotIndexExpr::CBotIndexExpr()
-{
- m_expr = nullptr;
- name = "CBotIndexExpr";
-}
-
-CBotIndexExpr::~CBotIndexExpr()
-{
- delete m_expr;
-}
-
-// finds a field from the instance at compile time
-
-bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
-{
- if (pVar->GetType(1) != CBotTypArrayPointer)
- assert(0);
-
- pVar = (static_cast<CBotVarArray*>(pVar))->GetItem(0, false); // at compile time makes the element [0]
- if (pVar == nullptr)
- {
- pile->SetError(TX_OUTARRAY, m_token.GetEnd());
- return false;
- }
- if (m_next3 != nullptr) return m_next3->ExecuteVar(pVar, pile);
- return true;
-}
-
-// attention, changes the pointer to the stack intentionally
-// place the index calculated on the additional stack
-
-
-bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend)
-{
- CBotStack* pj = pile;
-
- if (pVar->GetType(1) != CBotTypArrayPointer)
- assert(0);
-
- pile = pile->AddStack();
-
- if (pile->GetState() == 0)
- {
- if (!m_expr->Execute(pile)) return false;
- pile->IncState();
- }
- // handles array
-
- CBotVar* p = pile->GetVar(); // result on the stack
-
- if (p == nullptr || p->GetType() > CBotTypDouble)
- {
- pile->SetError(TX_BADINDEX, prevToken);
- return pj->Return(pile);
- }
-
- int n = p->GetValInt(); // position in the table
-
- pVar = (static_cast<CBotVarArray*>(pVar))->GetItem(n, bExtend);
- if (pVar == nullptr)
- {
- pile->SetError(TX_OUTARRAY, prevToken);
- return pj->Return(pile);
- }
-
- pVar->Maj(pile->GetPUser(), true);
-
- if ( m_next3 != nullptr &&
- !m_next3->ExecuteVar(pVar, pile, prevToken, bStep, bExtend) ) return false;
-
- // does not release the stack
- // to avoid recalculation of the index twice where appropriate
- return true;
-}
-
-void CBotIndexExpr::RestoreStateVar(CBotStack* &pile, bool bMain)
-{
- pile = pile->RestoreStack();
- if (pile == nullptr) return;
-
- if (bMain && pile->GetState() == 0)
- {
- m_expr->RestoreState(pile, true);
- return;
- }
-
- if (m_next3)
- m_next3->RestoreStateVar(pile, bMain);
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////////////////////
// field management in an instance (dot operator)
// toto.x
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index 1709ba1..995e5c6 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -689,24 +689,7 @@ public:
void RestoreStateVar(CBotStack* &pj, bool bMain) override;
};
-// management of indices of the tables
-class CBotIndexExpr : public CBotInstr
-{
-private:
- CBotInstr* m_expr; // expression for calculating the index
- friend class CBotLeftExpr;
- friend class CBotExprVar;
-
-public:
- CBotIndexExpr();
- ~CBotIndexExpr();
-// static
-// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) override;
- bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) override;
- void RestoreStateVar(CBotStack* &pj, bool bMain) override;
-};
#define MAX(a,b) ((a>b) ? a : b)
diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp
index 0101fcb..93ffeec 100644
--- a/src/CBot/CBotInstr/CBotExprVar.cpp
+++ b/src/CBot/CBotInstr/CBotExprVar.cpp
@@ -21,6 +21,7 @@
#include "CBotExprVar.h"
#include "CBotInstrMethode.h"
#include "CBotExpression.h"
+#include "CBotIndexExpr.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotIndexExpr.cpp b/src/CBot/CBotInstr/CBotIndexExpr.cpp
new file mode 100644
index 0000000..2d3d6d2
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotIndexExpr.cpp
@@ -0,0 +1,115 @@
+/*
+ * 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 "CBotIndexExpr.h"
+
+// Local include
+
+// Global include
+#include <cassert>
+
+////////////////////////////////////////////////////////////////////////////////
+CBotIndexExpr::CBotIndexExpr()
+{
+ m_expr = nullptr;
+ name = "CBotIndexExpr";
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotIndexExpr::~CBotIndexExpr()
+{
+ delete m_expr;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
+{
+ if (pVar->GetType(1) != CBotTypArrayPointer)
+ assert(0);
+
+ pVar = (static_cast<CBotVarArray*>(pVar))->GetItem(0, false); // at compile time makes the element [0]
+ if (pVar == nullptr)
+ {
+ pile->SetError(TX_OUTARRAY, m_token.GetEnd());
+ return false;
+ }
+ if (m_next3 != nullptr) return m_next3->ExecuteVar(pVar, pile);
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotIndexExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend)
+{
+ CBotStack* pj = pile;
+
+ if (pVar->GetType(1) != CBotTypArrayPointer)
+ assert(0);
+
+ pile = pile->AddStack();
+
+ if (pile->GetState() == 0)
+ {
+ if (!m_expr->Execute(pile)) return false;
+ pile->IncState();
+ }
+ // handles array
+
+ CBotVar* p = pile->GetVar(); // result on the stack
+
+ if (p == nullptr || p->GetType() > CBotTypDouble)
+ {
+ pile->SetError(TX_BADINDEX, prevToken);
+ return pj->Return(pile);
+ }
+
+ int n = p->GetValInt(); // position in the table
+
+ pVar = (static_cast<CBotVarArray*>(pVar))->GetItem(n, bExtend);
+ if (pVar == nullptr)
+ {
+ pile->SetError(TX_OUTARRAY, prevToken);
+ return pj->Return(pile);
+ }
+
+ pVar->Maj(pile->GetPUser(), true);
+
+ if ( m_next3 != nullptr &&
+ !m_next3->ExecuteVar(pVar, pile, prevToken, bStep, bExtend) ) return false;
+
+ // does not release the stack
+ // to avoid recalculation of the index twice where appropriate
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotIndexExpr::RestoreStateVar(CBotStack* &pile, bool bMain)
+{
+ pile = pile->RestoreStack();
+ if (pile == nullptr) return;
+
+ if (bMain && pile->GetState() == 0)
+ {
+ m_expr->RestoreState(pile, true);
+ return;
+ }
+
+ if (m_next3)
+ m_next3->RestoreStateVar(pile, bMain);
+}
diff --git a/src/CBot/CBotInstr/CBotIndexExpr.h b/src/CBot/CBotInstr/CBotIndexExpr.h
new file mode 100644
index 0000000..730a4de
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotIndexExpr.h
@@ -0,0 +1,81 @@
+/*
+ * 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 CBotIndexExpr class Index management for arrays
+ * eg :
+ * - array [ expression ]
+ */
+class CBotIndexExpr : public CBotInstr
+{
+public:
+
+ /*!
+ * \brief CBotIndexExpr
+ */
+ CBotIndexExpr();
+
+ /*!
+ * \brief ~CBotIndexExpr
+ */
+ ~CBotIndexExpr();
+
+ /*!
+ * \brief ExecuteVar Finds a field from the instance at compile time.
+ * \param pVar
+ * \param pile
+ * \return
+ */
+ bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) override;
+
+ /*!
+ * \brief ExecuteVar Warning, changes the pointer to the stack intentionally
+ * place the index calculated on the additional stack.
+ * \param pVar
+ * \param pile
+ * \param prevToken
+ * \param bStep
+ * \param bExtend
+ * \return
+ */
+ bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend) override;
+
+ /*!
+ * \brief RestoreStateVar
+ * \param pj
+ * \param bMain
+ */
+ void RestoreStateVar(CBotStack* &pj, bool bMain) override;
+
+
+private:
+ //! Expression for calculating the index.
+ CBotInstr* m_expr;
+ friend class CBotLeftExpr;
+ friend class CBotExprVar;
+};
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index ce4f6d7..bb4d325 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -38,6 +38,7 @@ set(SOURCES
CBotInstr/CBotLogicExpr.cpp
CBotInstr/CBotTwoOpExpr.cpp
CBotInstr/CBotExpression.cpp
+ CBotInstr/CBotIndexExpr.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