[colobot] 90/377: Moving CBotFieldExpr 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 4b10358df767aa28a49a4b17b84da4ac98694604
Author: Grunaka <dev at romainbreton.fr>
Date: Wed Nov 11 22:02:17 2015 +0100
Moving CBotFieldExpr class in its own header and source files.
---
src/CBot/CBot.cpp | 103 +----------------------------
src/CBot/CBot.h | 21 ------
src/CBot/CBotInstr/CBotExprVar.cpp | 1 +
src/CBot/CBotInstr/CBotFieldExpr.cpp | 124 +++++++++++++++++++++++++++++++++++
src/CBot/CBotInstr/CBotFieldExpr.h | 83 +++++++++++++++++++++++
src/CBot/CMakeLists.txt | 1 +
6 files changed, 210 insertions(+), 123 deletions(-)
diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp
index d0a1239..7511afa 100644
--- a/src/CBot/CBot.cpp
+++ b/src/CBot/CBot.cpp
@@ -60,6 +60,7 @@
#include "CBotInstr/CBotTwoOpExpr.h"
#include "CBotInstr/CBotExpression.h"
#include "CBotInstr/CBotIndexExpr.h"
+#include "CBotInstr/CBotFieldExpr.h"
// Local include
@@ -1379,108 +1380,6 @@ CBotInstr* CBotCondition::Compile(CBotToken* &p, CBotCStack* pStack)
}
//////////////////////////////////////////////////////////////////////////////////////
-// field management in an instance (dot operator)
-// toto.x
-
-
-CBotFieldExpr::CBotFieldExpr()
-{
- name = "CBotFieldExpr";
- m_nIdent = 0;
-}
-
-CBotFieldExpr::~CBotFieldExpr()
-{
-}
-
-void CBotFieldExpr::SetUniqNum(int num)
-{
- m_nIdent = num;
-}
-
-
-// find a field from the instance at compile
-
-bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
-{
- if (pVar->GetType(1) != CBotTypPointer)
- assert(0);
-
- pVar = pVar->GetItemRef(m_nIdent);
- if (pVar == nullptr)
- {
- pile->SetError(TX_NOITEM, &m_token);
- return false;
- }
-
- if ( m_next3 != nullptr &&
- !m_next3->ExecuteVar(pVar, pile) ) return false;
-
- return true;
-}
-
-bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend)
-{
- CBotStack* pj = pile;
- pile = pile->AddStack(this); // changes in output stack
- if (pile == EOX) return true;
-
-
- if (pVar->GetType(1) != CBotTypPointer)
- assert(0);
-
- CBotVarClass* pItem = pVar->GetPointer();
- if (pItem == nullptr)
- {
- pile->SetError(TX_NULLPT, prevToken);
- return pj->Return(pile);
- }
- if (pItem->GetUserPtr() == OBJECTDELETED)
- {
- pile->SetError(TX_DELETEDPT, prevToken);
- return pj->Return(pile);
- }
-
- if (bStep && pile->IfStep()) return false;
-
- pVar = pVar->GetItemRef(m_nIdent);
- if (pVar == nullptr)
- {
- pile->SetError(TX_NOITEM, &m_token);
- return pj->Return(pile);
- }
-
- if (pVar->IsStatic())
- {
- // for a static variable, takes it in the class itself
- CBotClass* pClass = pItem->GetClass();
- pVar = pClass->GetItem(m_token.GetString());
- }
-
- // request the update of the element, if applicable
- pVar->Maj(pile->GetPUser(), true);
-
- if ( m_next3 != nullptr &&
- !m_next3->ExecuteVar(pVar, pile, &m_token, bStep, bExtend) ) return false;
-
- // does not release the stack
- // to maintain the state SetState () corresponding to step
-
- return true;
-}
-
-void CBotFieldExpr::RestoreStateVar(CBotStack* &pj, bool bMain)
-{
- pj = pj->RestoreStack(this);
- if (pj == nullptr) return;
-
- if (m_next3 != nullptr)
- m_next3->RestoreStateVar(pj, bMain);
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////////////////////
// compile a left operand for an assignment
CBotLeftExpr::CBotLeftExpr()
{
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index 995e5c6..a0beb27 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -670,27 +670,6 @@ public:
};
-// management of the fields of an instance
-
-class CBotFieldExpr : public CBotInstr
-{
-private:
- friend class CBotExpression;
- int m_nIdent;
-
-public:
- CBotFieldExpr();
- ~CBotFieldExpr();
- void SetUniqNum(int num);
-// 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 93ffeec..3c03da9 100644
--- a/src/CBot/CBotInstr/CBotExprVar.cpp
+++ b/src/CBot/CBotInstr/CBotExprVar.cpp
@@ -22,6 +22,7 @@
#include "CBotInstrMethode.h"
#include "CBotExpression.h"
#include "CBotIndexExpr.h"
+#include "CBotFieldExpr.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotFieldExpr.cpp b/src/CBot/CBotInstr/CBotFieldExpr.cpp
new file mode 100644
index 0000000..6453bc3
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotFieldExpr.cpp
@@ -0,0 +1,124 @@
+/*
+ * 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 "CBotFieldExpr.h"
+
+// Local include
+
+// Global include
+#include <cassert>
+
+////////////////////////////////////////////////////////////////////////////////
+CBotFieldExpr::CBotFieldExpr()
+{
+ name = "CBotFieldExpr";
+ m_nIdent = 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotFieldExpr::~CBotFieldExpr()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotFieldExpr::SetUniqNum(int num)
+{
+ m_nIdent = num;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotCStack* &pile)
+{
+ if (pVar->GetType(1) != CBotTypPointer)
+ assert(0);
+
+ pVar = pVar->GetItemRef(m_nIdent);
+ if (pVar == nullptr)
+ {
+ pile->SetError(TX_NOITEM, &m_token);
+ return false;
+ }
+
+ if ( m_next3 != nullptr &&
+ !m_next3->ExecuteVar(pVar, pile) ) return false;
+
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotFieldExpr::ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep, bool bExtend)
+{
+ CBotStack* pj = pile;
+ pile = pile->AddStack(this); // changes in output stack
+ if (pile == EOX) return true;
+
+
+ if (pVar->GetType(1) != CBotTypPointer)
+ assert(0);
+
+ CBotVarClass* pItem = pVar->GetPointer();
+ if (pItem == nullptr)
+ {
+ pile->SetError(TX_NULLPT, prevToken);
+ return pj->Return(pile);
+ }
+ if (pItem->GetUserPtr() == OBJECTDELETED)
+ {
+ pile->SetError(TX_DELETEDPT, prevToken);
+ return pj->Return(pile);
+ }
+
+ if (bStep && pile->IfStep()) return false;
+
+ pVar = pVar->GetItemRef(m_nIdent);
+ if (pVar == nullptr)
+ {
+ pile->SetError(TX_NOITEM, &m_token);
+ return pj->Return(pile);
+ }
+
+ if (pVar->IsStatic())
+ {
+ // for a static variable, takes it in the class itself
+ CBotClass* pClass = pItem->GetClass();
+ pVar = pClass->GetItem(m_token.GetString());
+ }
+
+ // request the update of the element, if applicable
+ pVar->Maj(pile->GetPUser(), true);
+
+ if ( m_next3 != nullptr &&
+ !m_next3->ExecuteVar(pVar, pile, &m_token, bStep, bExtend) ) return false;
+
+ // does not release the stack
+ // to maintain the state SetState () corresponding to step
+
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotFieldExpr::RestoreStateVar(CBotStack* &pj, bool bMain)
+{
+ pj = pj->RestoreStack(this);
+ if (pj == nullptr) return;
+
+ if (m_next3 != nullptr)
+ m_next3->RestoreStateVar(pj, bMain);
+}
diff --git a/src/CBot/CBotInstr/CBotFieldExpr.h b/src/CBot/CBotInstr/CBotFieldExpr.h
new file mode 100644
index 0000000..13f9fc3
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotFieldExpr.h
@@ -0,0 +1,83 @@
+/*
+ * 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 CBotFieldExpr class Management of the fields of an instance
+ * (dot operator) eg : toto.x
+ */
+class CBotFieldExpr : public CBotInstr
+{
+public:
+
+ /*!
+ * \brief CBotFieldExpr
+ */
+ CBotFieldExpr();
+
+ /*!
+ * \brief ~CBotFieldExpr
+ */
+ ~CBotFieldExpr();
+
+ /*!
+ * \brief SetUniqNum
+ * \param num
+ */
+ void SetUniqNum(int num);
+
+ /*!
+ * \brief ExecuteVar Find a field from the instance at compile.
+ * \param pVar
+ * \param pile
+ * \return
+ */
+ bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) override;
+
+ /*!
+ * \brief ExecuteVar
+ * \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:
+ friend class CBotExpression;
+ int m_nIdent;
+};
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index bb4d325..29380c3 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -39,6 +39,7 @@ set(SOURCES
CBotInstr/CBotTwoOpExpr.cpp
CBotInstr/CBotExpression.cpp
CBotInstr/CBotIndexExpr.cpp
+ CBotInstr/CBotFieldExpr.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