[colobot] 81/377: Moving CBotListInstr class in its own header and source files.

Didier Raboud odyx at moszumanska.debian.org
Wed Mar 30 13:34:00 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 840da007a9e0075e77dc53187b45bee7bd5ee50c
Author: Grunaka <dev at romainbreton.fr>
Date:   Wed Nov 11 19:25:12 2015 +0100

    Moving CBotListInstr class in its own header and source files.
---
 src/CBot/CBot.cpp                    |  96 +---------------------------
 src/CBot/CBot.h                      |  18 ------
 src/CBot/CBotInstr/CBotListInstr.cpp | 117 +++++++++++++++++++++++++++++++++++
 src/CBot/CBotInstr/CBotListInstr.h   |  74 ++++++++++++++++++++++
 src/CBot/CMakeLists.txt              |   1 +
 5 files changed, 193 insertions(+), 113 deletions(-)

diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp
index 8eb59b8..98e04d9 100644
--- a/src/CBot/CBot.cpp
+++ b/src/CBot/CBot.cpp
@@ -54,6 +54,7 @@
 #include "CBotInstr/CBotPostIncExpr.h"
 #include "CBotInstr/CBotExprVar.h"
 #include "CBotInstr/CBotInstrCall.h"
+#include "CBotInstr/CBotListInstr.h"
 
 // Local include
 
@@ -408,101 +409,6 @@ CBotInstr* CBotBlock::CompileBlkOrInst(CBotToken* &p, CBotCStack* pStack, bool b
 // where the variable x is known only in the block following the if
 
 
-//////////////////////////////////////////////////////////////////////////////////////////
-
-
-//////////////////////////////////////////////////////////////////////////////////////
-// compiles a list of instructions separated by semicolons
-
-CBotListInstr::CBotListInstr()
-{
-    m_Instr        = nullptr;
-    name = "CBotListInstr";
-}
-
-CBotListInstr::~CBotListInstr()
-{
-    delete    m_Instr;
-}
-
-CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal)
-{
-    CBotCStack* pStk = pStack->TokenStack(p, bLocal);        // variables are local
-
-    CBotListInstr* inst = new CBotListInstr();
-
-    while (true)
-    {
-        if (p == nullptr) break;
-
-        if (IsOfType(p, ID_SEP)) continue;              // empty statement ignored
-        if (p->GetType() == ID_CLBLK) break;
-
-        if (IsOfType(p, 0))
-        {
-            pStack->SetError(TX_CLOSEBLK, p->GetStart());
-            delete inst;
-            return pStack->Return(nullptr, pStk);
-        }
-
-        CBotInstr* i = CBotBlock::CompileBlkOrInst(p, pStk);    // compiles next
-
-        if (!pStk->IsOk())
-        {
-            delete inst;
-            return pStack->Return(nullptr, pStk);
-        }
-
-        if (inst->m_Instr == nullptr) inst->m_Instr = i;
-        else inst->m_Instr->AddNext(i);                            // added a result
-    }
-    return pStack->Return(inst, pStk);
-}
-
-// executes a set of instructions
-
-bool CBotListInstr::Execute(CBotStack* &pj)
-{
-
-    CBotStack*    pile = pj->AddStack(this, true);                //needed for SetState()
-    if (pile->StackOver() ) return pj->Return( pile);
-
-
-    CBotInstr*    p = m_Instr;                                    // the first expression
-
-    int        state = pile->GetState();
-    while (state-->0) p = p->GetNext();                            // returns to the interrupted operation
-
-    if (p != nullptr) while (true)
-    {
-        if (!p->Execute(pile)) return false;
-        p = p->GetNext();
-        if (p == nullptr) break;
-        (void)pile->IncState();                                  // ready for next
-    }
-
-    return pj->Return(pile);
-}
-
-void CBotListInstr::RestoreState(CBotStack* &pj, bool bMain)
-{
-    if (!bMain) return;
-
-    CBotStack*    pile = pj->RestoreStack(this);
-    if (pile == nullptr) return;
-
-    CBotInstr*    p = m_Instr;                                    // the first expression
-
-    int        state = pile->GetState();
-    while ( p != nullptr && state-- > 0)
-    {
-        p->RestoreState(pile, false);
-        p = p->GetNext();                            // returns to the interrupted operation
-    }
-
-    if (p != nullptr) p->RestoreState(pile, true);
-}
-
 //////////////////////////////////////////////////////////////////////////////////////
 // defining an array of any type
 // int a[12];
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index 809617e..326a79e 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -815,24 +815,6 @@ private:
     CBotBlock(const CBotBlock &) = delete;
 };
 
-
-// the content of a block of instructions ... ; ... ; ... ; ... ;
-class CBotListInstr : public CBotInstr
-{
-private:
-    CBotInstr*    m_Instr;            // instructions to do
-
-public:
-                CBotListInstr();
-                ~CBotListInstr();
-    static
-    CBotInstr*    Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true);
-    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/CBotListInstr.cpp b/src/CBot/CBotInstr/CBotListInstr.cpp
new file mode 100644
index 0000000..3d1d9c5
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotListInstr.cpp
@@ -0,0 +1,117 @@
+/*
+ * 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 "CBotListInstr.h"
+
+// Local include
+
+// Global include
+
+////////////////////////////////////////////////////////////////////////////////
+CBotListInstr::CBotListInstr()
+{
+    m_Instr        = nullptr;
+    name = "CBotListInstr";
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotListInstr::~CBotListInstr()
+{
+    delete    m_Instr;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal)
+{
+    CBotCStack* pStk = pStack->TokenStack(p, bLocal);        // variables are local
+
+    CBotListInstr* inst = new CBotListInstr();
+
+    while (true)
+    {
+        if (p == nullptr) break;
+
+        if (IsOfType(p, ID_SEP)) continue;              // empty statement ignored
+        if (p->GetType() == ID_CLBLK) break;
+
+        if (IsOfType(p, 0))
+        {
+            pStack->SetError(TX_CLOSEBLK, p->GetStart());
+            delete inst;
+            return pStack->Return(nullptr, pStk);
+        }
+
+        CBotInstr* i = CBotBlock::CompileBlkOrInst(p, pStk);    // compiles next
+
+        if (!pStk->IsOk())
+        {
+            delete inst;
+            return pStack->Return(nullptr, pStk);
+        }
+
+        if (inst->m_Instr == nullptr) inst->m_Instr = i;
+        else inst->m_Instr->AddNext(i);                            // added a result
+    }
+    return pStack->Return(inst, pStk);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotListInstr::Execute(CBotStack* &pj)
+{
+
+    CBotStack*    pile = pj->AddStack(this, true);                //needed for SetState()
+    if (pile->StackOver() ) return pj->Return( pile);
+
+
+    CBotInstr*    p = m_Instr;                                    // the first expression
+
+    int        state = pile->GetState();
+    while (state-->0) p = p->GetNext();                            // returns to the interrupted operation
+
+    if (p != nullptr) while (true)
+    {
+        if (!p->Execute(pile)) return false;
+        p = p->GetNext();
+        if (p == nullptr) break;
+        (void)pile->IncState();                                  // ready for next
+    }
+
+    return pj->Return(pile);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotListInstr::RestoreState(CBotStack* &pj, bool bMain)
+{
+    if (!bMain) return;
+
+    CBotStack*    pile = pj->RestoreStack(this);
+    if (pile == nullptr) return;
+
+    CBotInstr*    p = m_Instr;                                    // the first expression
+
+    int        state = pile->GetState();
+    while ( p != nullptr && state-- > 0)
+    {
+        p->RestoreState(pile, false);
+        p = p->GetNext();                            // returns to the interrupted operation
+    }
+
+    if (p != nullptr) p->RestoreState(pile, true);
+}
diff --git a/src/CBot/CBotInstr/CBotListInstr.h b/src/CBot/CBotInstr/CBotListInstr.h
new file mode 100644
index 0000000..763c3a8
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotListInstr.h
@@ -0,0 +1,74 @@
+/*
+ * 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 CBotListInstr class Compiles a list of instructions separated by
+ * semicolons eg : ... ; ... ; ... ; ... ;
+ */
+class CBotListInstr : public CBotInstr
+{
+public:
+
+    /*!
+     * \brief CBotListInstr
+     */
+    CBotListInstr();
+
+    /*!
+     * \brief ~CBotListInstr
+     */
+    ~CBotListInstr();
+
+    /*!
+     * \brief Compile
+     * \param p
+     * \param pStack
+     * \param bLocal
+     * \return
+     */
+    static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal = true);
+
+    /*!
+     * \brief Execute Executes a set of instructions.
+     * \param pj
+     * \return
+     */
+    bool Execute(CBotStack* &pj) override;
+
+    /*!
+     * \brief RestoreState
+     * \param pj
+     * \param bMain
+     */
+    void RestoreState(CBotStack* &pj, bool bMain) override;
+
+private:
+    //! Instructions to do.
+    CBotInstr*    m_Instr;
+};
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index 0ba1439..30e717b 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -31,6 +31,7 @@ set(SOURCES
     CBotInstr/CBotExprVar.cpp
     CBotInstr/CBotInstrMethode.cpp
     CBotInstr/CBotInstrCall.cpp
+    CBotInstr/CBotListInstr.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