[colobot] 98/377: Moving CBotReturn 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 c0e2201c70756a22d590a8678fb3487c8a4b85b9
Author: Grunaka <dev at romainbreton.fr>
Date: Sat Nov 14 11:51:15 2015 +0100
Moving CBotReturn class in its own header and source files.
---
src/CBot/CBot.cpp | 1 +
src/CBot/CBot.h | 18 -------
src/CBot/CBotFunction.cpp | 83 ----------------------------
src/CBot/CBotInstr/CBotReturn.cpp | 110 ++++++++++++++++++++++++++++++++++++++
src/CBot/CBotInstr/CBotReturn.h | 72 +++++++++++++++++++++++++
src/CBot/CMakeLists.txt | 1 +
6 files changed, 184 insertions(+), 101 deletions(-)
diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp
index e9d4171..4d6a14b 100644
--- a/src/CBot/CBot.cpp
+++ b/src/CBot/CBot.cpp
@@ -66,6 +66,7 @@
#include "CBotInstr/CBotFloat.h"
#include "CBotInstr/CBotBoolean.h"
#include "CBotInstr/CBotEmpty.h"
+#include "CBotInstr/CBotReturn.h"
// Local include
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index 5197bd8..9707b60 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -467,24 +467,6 @@ public:
bool IsOfClass(CBotString name);
};
-
-
-class CBotReturn : public CBotInstr
-{
-private:
- CBotInstr* m_Instr; // paramter of return
-
-public:
- CBotReturn();
- ~CBotReturn();
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
- bool Execute(CBotStack* &pj) override;
- void RestoreState(CBotStack* &pj, bool bMain) override;
-};
-
-
-
class CBotIf : public CBotInstr
{
private:
diff --git a/src/CBot/CBotFunction.cpp b/src/CBot/CBotFunction.cpp
index f298f10..090f28d 100644
--- a/src/CBot/CBotFunction.cpp
+++ b/src/CBot/CBotFunction.cpp
@@ -1108,89 +1108,6 @@ CBotString CBotDefParam::GetParamString()
return param;
}
-
-
-//////////////////////////////////////////////////////////////////////////
-// return parameters
-
-CBotReturn::CBotReturn()
-{
- m_Instr = nullptr;
- name = "CBotReturn"; // debug
-}
-
-CBotReturn::~CBotReturn()
-{
- delete m_Instr;
-}
-
-CBotInstr* CBotReturn::Compile(CBotToken* &p, CBotCStack* pStack)
-{
- CBotToken* pp = p;
-
- if (!IsOfType(p, ID_RETURN)) return nullptr; // should never happen
-
- CBotReturn* inst = new CBotReturn(); // creates the object
- inst->SetToken( pp );
-
- CBotTypResult type = pStack->GetRetType();
-
- if ( type.GetType() == 0 ) // returned void ?
- {
- if ( IsOfType( p, ID_SEP ) ) return inst;
- pStack->SetError( TX_BADTYPE, pp );
- return nullptr;
- }
-
- inst->m_Instr = CBotExpression::Compile(p, pStack);
- if ( pStack->IsOk() )
- {
- CBotTypResult retType = pStack->GetTypResult(2);
- if (TypeCompatible(retType, type, ID_ASS))
- {
- if ( IsOfType( p, ID_SEP ) )
- return inst;
-
- pStack->SetError(TX_ENDOF, p->GetStart());
- }
- pStack->SetError(TX_BADTYPE, p->GetStart());
- }
-
- delete inst;
- return nullptr; // no object, the error is on the stack
-}
-
-bool CBotReturn::Execute(CBotStack* &pj)
-{
- CBotStack* pile = pj->AddStack(this);
-// if ( pile == EOX ) return true;
-
- if ( pile->GetState() == 0 )
- {
- if ( m_Instr != nullptr && !m_Instr->Execute(pile) ) return false; // evaluate the result
- // the result is on the stack
- pile->IncState();
- }
-
- if ( pile->IfStep() ) return false;
-
- pile->SetBreak(3, CBotString());
- return pj->Return(pile);
-}
-
-void CBotReturn::RestoreState(CBotStack* &pj, bool bMain)
-{
- if ( !bMain ) return;
- CBotStack* pile = pj->RestoreStack(this);
- if ( pile == nullptr ) return;
-
- if ( pile->GetState() == 0 )
- {
- if ( m_Instr != nullptr ) m_Instr->RestoreState(pile, bMain); // evaluate the result
- return;
- }
-}
-
//////////////////////////////////////////////////////////////////////////////
// statement of user classes
diff --git a/src/CBot/CBotInstr/CBotReturn.cpp b/src/CBot/CBotInstr/CBotReturn.cpp
new file mode 100644
index 0000000..d64326c
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotReturn.cpp
@@ -0,0 +1,110 @@
+/*
+ * 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 "CBotReturn.h"
+#include "CBotExpression.h"
+
+// Local include
+
+// Global include
+
+
+////////////////////////////////////////////////////////////////////////////////
+CBotReturn::CBotReturn()
+{
+ m_Instr = nullptr;
+ name = "CBotReturn"; // debug
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotReturn::~CBotReturn()
+{
+ delete m_Instr;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotInstr* CBotReturn::Compile(CBotToken* &p, CBotCStack* pStack)
+{
+ CBotToken* pp = p;
+
+ if (!IsOfType(p, ID_RETURN)) return nullptr; // should never happen
+
+ CBotReturn* inst = new CBotReturn(); // creates the object
+ inst->SetToken( pp );
+
+ CBotTypResult type = pStack->GetRetType();
+
+ if ( type.GetType() == 0 ) // returned void ?
+ {
+ if ( IsOfType( p, ID_SEP ) ) return inst;
+ pStack->SetError( TX_BADTYPE, pp );
+ return nullptr;
+ }
+
+ inst->m_Instr = CBotExpression::Compile(p, pStack);
+ if ( pStack->IsOk() )
+ {
+ CBotTypResult retType = pStack->GetTypResult(2);
+ if (TypeCompatible(retType, type, ID_ASS))
+ {
+ if ( IsOfType( p, ID_SEP ) )
+ return inst;
+
+ pStack->SetError(TX_ENDOF, p->GetStart());
+ }
+ pStack->SetError(TX_BADTYPE, p->GetStart());
+ }
+
+ delete inst;
+ return nullptr; // no object, the error is on the stack
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotReturn::Execute(CBotStack* &pj)
+{
+ CBotStack* pile = pj->AddStack(this);
+// if ( pile == EOX ) return true;
+
+ if ( pile->GetState() == 0 )
+ {
+ if ( m_Instr != nullptr && !m_Instr->Execute(pile) ) return false; // evaluate the result
+ // the result is on the stack
+ pile->IncState();
+ }
+
+ if ( pile->IfStep() ) return false;
+
+ pile->SetBreak(3, CBotString());
+ return pj->Return(pile);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotReturn::RestoreState(CBotStack* &pj, bool bMain)
+{
+ if ( !bMain ) return;
+ CBotStack* pile = pj->RestoreStack(this);
+ if ( pile == nullptr ) return;
+
+ if ( pile->GetState() == 0 )
+ {
+ if ( m_Instr != nullptr ) m_Instr->RestoreState(pile, bMain); // evaluate the result
+ return;
+ }
+}
diff --git a/src/CBot/CBotInstr/CBotReturn.h b/src/CBot/CBotInstr/CBotReturn.h
new file mode 100644
index 0000000..978c6c1
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotReturn.h
@@ -0,0 +1,72 @@
+/*
+ * 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 CBotReturn class. Return parameters
+ */
+class CBotReturn : public CBotInstr
+{
+public:
+
+ /*!
+ * \brief CBotReturn
+ */
+ CBotReturn();
+
+ /*!
+ * \brief ~CBotReturn
+ */
+ ~CBotReturn();
+
+ /*!
+ * \brief Compile
+ * \param p
+ * \param pStack
+ * \return
+ */
+ static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+
+ /*!
+ * \brief Execute
+ * \param pj
+ * \return
+ */
+ bool Execute(CBotStack* &pj) override;
+
+ /*!
+ * \brief RestoreState
+ * \param pj
+ * \param bMain
+ */
+ void RestoreState(CBotStack* &pj, bool bMain) override;
+
+private:
+ //! Parameter of return
+ CBotInstr *m_Instr;
+
+};
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index bc2a19e..2d25fca 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -47,6 +47,7 @@ set(SOURCES
CBotInstr/CBotFloat.cpp
CBotInstr/CBotBoolean.cpp
CBotInstr/CBotEmpty.cpp
+ CBotInstr/CBotReturn.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