[colobot] 67/377: Moving CBotThrow class in its own header and source files.
Didier Raboud
odyx at moszumanska.debian.org
Wed Mar 30 13:33:59 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 a80245b012b8a85e5d01a6eb80d732f03fa2dd43
Author: Grunaka <dev at romainbreton.fr>
Date: Sun Nov 8 19:53:30 2015 +0100
Moving CBotThrow class in its own header and source files.
---
src/CBot/CBot.cpp | 1 +
src/CBot/CBot.h | 13 ------
src/CBot/CBotInstr/CBotThrow.cpp | 99 ++++++++++++++++++++++++++++++++++++++++
src/CBot/CBotInstr/CBotThrow.h | 73 +++++++++++++++++++++++++++++
src/CBot/CBotWhile.cpp | 75 ------------------------------
src/CBot/CMakeLists.txt | 1 +
6 files changed, 174 insertions(+), 88 deletions(-)
diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp
index b46a29d..6fda676 100644
--- a/src/CBot/CBot.cpp
+++ b/src/CBot/CBot.cpp
@@ -41,6 +41,7 @@
#include "CBotInstr/CBotSwitch.h"
#include "CBotInstr/CBotBreak.h"
#include "CBotInstr/CBotTry.h"
+#include "CBotInstr/CBotThrow.h"
// Local include
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index baebe04..c331ff4 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -497,19 +497,6 @@ public:
void RestoreState(CBotStack* &pj, bool bMain) override;
};
-class CBotThrow : public CBotInstr
-{
-private:
- CBotInstr* m_Value; // the value to send
-
-public:
- CBotThrow();
- ~CBotThrow();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- bool Execute(CBotStack* &pj) override;
- void RestoreState(CBotStack* &pj, bool bMain) override;
-};
class CBotIf : public CBotInstr
diff --git a/src/CBot/CBotInstr/CBotThrow.cpp b/src/CBot/CBotInstr/CBotThrow.cpp
new file mode 100644
index 0000000..14e61f0
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotThrow.cpp
@@ -0,0 +1,99 @@
+/*
+ * 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 "CBotThrow.h"
+
+// Local include
+
+// Global include
+
+
+////////////////////////////////////////////////////////////////////////////////
+CBotThrow::CBotThrow()
+{
+ m_Value = nullptr; // nullptr so that delete is not possible further
+
+ name = "CBotThrow"; // debug
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotThrow::~CBotThrow()
+{
+ delete m_Value;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotInstr* CBotThrow::Compile(CBotToken* &p, CBotCStack* pStack)
+{
+ pStack->SetStartError(p->GetStart());
+
+ CBotThrow* inst = new CBotThrow(); // creates the object
+ inst->SetToken(p);
+
+ CBotToken* pp = p; // preserves at the ^ token (starting position)
+
+ if (!IsOfType(p, ID_THROW)) return nullptr; // should never happen
+
+ inst->m_Value = CBotExpression::Compile( p, pStack );
+
+ if (pStack->GetType() < CBotTypLong && pStack->IsOk())
+ {
+ return inst; // return an object to the application
+ }
+ pStack->SetError(TX_BADTYPE, pp);
+
+ delete inst; // error, frees up
+ return nullptr; // no object, the error is on the stack
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotThrow::Execute(CBotStack* &pj)
+{
+ CBotStack* pile = pj->AddStack(this);
+// if ( pile == EOX ) return true;
+
+ if ( pile->GetState() == 0 )
+ {
+ if ( !m_Value->Execute(pile) ) return false;
+ pile->IncState();
+ }
+
+ if ( pile->IfStep() ) return false;
+
+ int val = pile->GetVal();
+ if ( val < 0 ) val = TX_BADTHROW;
+ pile->SetError( val, &m_token );
+ return pj->Return( pile );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotThrow::RestoreState(CBotStack* &pj, bool bMain)
+{
+ if ( !bMain ) return;
+
+ CBotStack* pile = pj->RestoreStack(this);
+ if ( pile == nullptr ) return;
+
+ if ( pile->GetState() == 0 )
+ {
+ m_Value->RestoreState(pile, bMain);
+ return;
+ }
+}
diff --git a/src/CBot/CBotInstr/CBotThrow.h b/src/CBot/CBotInstr/CBotThrow.h
new file mode 100644
index 0000000..997550a
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotThrow.h
@@ -0,0 +1,73 @@
+/*
+ * 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 CBotThrow class Compiles instruction "throw".
+ */
+class CBotThrow : public CBotInstr
+{
+public:
+
+ /*!
+ * \brief CBotThrow
+ */
+ CBotThrow();
+
+ /*!
+ * \brief ~CBotThrow
+ */
+ ~CBotThrow();
+
+ /*!
+ * \brief Compile
+ * \param p
+ * \param pStack
+ * \return
+ */
+ static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+
+ /*!
+ * \brief Execute Execution of instruction "throw".
+ * \param pj
+ * \return
+ */
+ bool Execute(CBotStack* &pj) override;
+
+ /*!
+ * \brief RestoreState
+ * \param pj
+ * \param bMain
+ */
+ void RestoreState(CBotStack* &pj, bool bMain) override;
+
+private:
+ //! The value to send.
+ CBotInstr* m_Value;
+
+};
diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp
index 89647e2..2891c60 100644
--- a/src/CBot/CBotWhile.cpp
+++ b/src/CBot/CBotWhile.cpp
@@ -156,78 +156,3 @@ void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain)
return;
}
}
-
-///////////////////////////////////////////////////////////////////////////
-// compiles instruction "throw"
-
-CBotThrow::CBotThrow()
-{
- m_Value = nullptr; // nullptr so that delete is not possible further
-
- name = "CBotThrow"; // debug
-}
-
-CBotThrow::~CBotThrow()
-{
- delete m_Value;
-}
-
-CBotInstr* CBotThrow::Compile(CBotToken* &p, CBotCStack* pStack)
-{
- pStack->SetStartError(p->GetStart());
-
- CBotThrow* inst = new CBotThrow(); // creates the object
- inst->SetToken(p);
-
- CBotToken* pp = p; // preserves at the ^ token (starting position)
-
- if (!IsOfType(p, ID_THROW)) return nullptr; // should never happen
-
- inst->m_Value = CBotExpression::Compile( p, pStack );
-
- if (pStack->GetType() < CBotTypLong && pStack->IsOk())
- {
- return inst; // return an object to the application
- }
- pStack->SetError(TX_BADTYPE, pp);
-
- delete inst; // error, frees up
- return nullptr; // no object, the error is on the stack
-}
-
-// execution of instruction "throw"
-
-bool CBotThrow :: Execute(CBotStack* &pj)
-{
- CBotStack* pile = pj->AddStack(this);
-// if ( pile == EOX ) return true;
-
- if ( pile->GetState() == 0 )
- {
- if ( !m_Value->Execute(pile) ) return false;
- pile->IncState();
- }
-
- if ( pile->IfStep() ) return false;
-
- int val = pile->GetVal();
- if ( val < 0 ) val = TX_BADTHROW;
- pile->SetError( val, &m_token );
- return pj->Return( pile );
-}
-
-void CBotThrow :: RestoreState(CBotStack* &pj, bool bMain)
-{
- if ( !bMain ) return;
-
- CBotStack* pile = pj->RestoreStack(this);
- if ( pile == nullptr ) return;
-
- if ( pile->GetState() == 0 )
- {
- m_Value->RestoreState(pile, bMain);
- return;
- }
-}
-
-
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index cd17d7b..80b1303 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -18,6 +18,7 @@ set(SOURCES
CBotInstr/CBotBreak.cpp
CBotInstr/CBotTry.cpp
CBotInstr/CBotCatch.cpp
+ CBotInstr/CBotThrow.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