[colobot] 59/377: Move CBotDo class in its own header and source files.

Didier Raboud odyx at moszumanska.debian.org
Wed Mar 30 13:33:58 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 1694776ab62658b589df0f89ef4b8192b9b64802
Author: Grunaka <dev at romainbreton.fr>
Date:   Sun Nov 8 18:29:02 2015 +0100

    Move CBotDo class in its own header and source files.
---
 src/CBot/CBot.cpp             |   6 +-
 src/CBot/CBot.h               |  16 -----
 src/CBot/CBotInstr/CBotDo.cpp | 154 ++++++++++++++++++++++++++++++++++++++++++
 src/CBot/CBotInstr/CBotDo.h   |  73 ++++++++++++++++++++
 src/CBot/CBotWhile.cpp        | 134 ------------------------------------
 src/CBot/CMakeLists.txt       |   9 +++
 6 files changed, 241 insertions(+), 151 deletions(-)

diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp
index f4727d3..375c1f3 100644
--- a/src/CBot/CBot.cpp
+++ b/src/CBot/CBot.cpp
@@ -34,9 +34,13 @@
 // the error is then on the stack CBotCStack :: Isok () is false
 
 
-
+// Modules inlcude
 #include "CBot.h"
+#include "CBotInstr/CBotDo.h"
+
+// Local include
 
+// Global include
 #include <cassert>
 
 
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index 6f37b8b..60e1d88 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -483,22 +483,6 @@ public:
     void        RestoreState(CBotStack* &pj, bool bMain) override;
 };
 
-class CBotDo : public CBotInstr
-{
-private:
-    CBotInstr*    m_Block;            // instruction
-    CBotInstr*    m_Condition;        // conditions
-    CBotString    m_label;            // a label if there is
-
-public:
-                CBotDo();
-                ~CBotDo();
-    static
-    CBotInstr*    Compile(CBotToken* &p, CBotCStack* pStack);
-    bool        Execute(CBotStack* &pj) override;
-    void        RestoreState(CBotStack* &pj, bool bMain) override;
-};
-
 class CBotFor : public CBotInstr
 {
 private:
diff --git a/src/CBot/CBotInstr/CBotDo.cpp b/src/CBot/CBotInstr/CBotDo.cpp
new file mode 100644
index 0000000..a24e5db
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotDo.cpp
@@ -0,0 +1,154 @@
+/*
+ * 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 "CBotDo.h"
+
+// Local include
+
+// Global include
+
+
+////////////////////////////////////////////////////////////////////////////////
+CBotDo::CBotDo()
+{
+    m_Condition =
+    m_Block     = nullptr;     // nullptr so that delete is not possible further
+    name = "CBotDo";        // debug
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotDo::~CBotDo()
+{
+    delete  m_Condition;    // frees the condition
+    delete  m_Block;        // frees the instruction block
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotInstr* CBotDo::Compile(CBotToken* &p, CBotCStack* pStack)
+{
+    CBotDo* inst = new CBotDo();                // creates the object
+
+    CBotToken*  pp = p;                         // preserves at the ^ token (starting position)
+
+    if ( IsOfType( p, TokenTypVar ) &&
+         IsOfType( p, ID_DOTS ) )
+    {
+        inst->m_label = pp->GetString();        // register the name of label
+    }
+
+    inst->SetToken(p);
+    if (!IsOfType(p, ID_DO)) return nullptr;       // should never happen
+
+    CBotCStack* pStk = pStack->TokenStack(pp);  // un petit bout de pile svp
+
+
+    // looking for a statement block after the do
+    IncLvl(inst->m_label);
+    inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true );
+    DecLvl();
+
+    if ( pStk->IsOk() )
+    {
+        if (IsOfType(p, ID_WHILE))
+        {
+            if ( nullptr != (inst->m_Condition = CBotCondition::Compile( p, pStk )) )
+            {
+                // the condition exists
+                if (IsOfType(p, ID_SEP))
+                {
+                    return pStack->Return(inst, pStk);  // return an object to the application
+                }
+                pStk->SetError(TX_ENDOF, p->GetStart());
+            }
+        }
+        pStk->SetError(TX_WHILE, p->GetStart());
+    }
+
+    delete inst;                                // error, frees up
+    return pStack->Return(nullptr, pStk);          // no object, the error is on the stack
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotDo :: Execute(CBotStack* &pj)
+{
+    CBotStack* pile = pj->AddStack(this);       // adds an item to the stack
+                                                // or find in case of recovery
+//  if ( pile == EOX ) return true;
+
+    if ( pile->IfStep() ) return false;
+
+    while( true ) switch( pile->GetState() )            // executes the loop
+    {                                                   // there are two possible states (depending on recovery)
+    case 0:
+        // evaluates the associated statement block
+        if ( m_Block != nullptr &&
+            !m_Block->Execute(pile) )
+        {
+            if (pile->IfContinue(1, m_label)) continue; // if continued, will return to test
+            return pj->BreakReturn(pile, m_label);      // sends the results and releases the stack
+        }
+
+        // terminates if there is an error
+        if ( !pile->IsOk() )
+        {
+            return pj->Return(pile);                    // sends the results and releases the stack
+        }
+
+        if (!pile->SetState(1)) return false;           // ready for further
+
+    case 1:
+        // evaluates the condition
+        if ( !m_Condition->Execute(pile) ) return false; // interrupted here ?
+
+        // the result of the condition is on the stack
+
+        // terminates if an error or if the condition is false
+        if ( !pile->IsOk() || pile->GetVal() != true )
+        {
+            return pj->Return(pile);                    // sends the results and releases the stack
+        }
+
+        // returns to instruction block to start
+        if (!pile->SetState(0, 0)) return false;
+        continue;
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotDo :: RestoreState(CBotStack* &pj, bool bMain)
+{
+    if ( !bMain ) return;
+
+    CBotStack* pile = pj->RestoreStack(this);           // adds an item to the stack
+    if ( pile == nullptr ) return;
+
+    switch( pile->GetState() )
+    {                                                   // there are two possible states (depending on recovery)
+    case 0:
+        // restores the assosiated statement's block
+        if ( m_Block != nullptr ) m_Block->RestoreState(pile, bMain);
+        return;
+
+    case 1:
+        // restores the condition
+        m_Condition->RestoreState(pile, bMain);
+        return;
+    }
+}
diff --git a/src/CBot/CBotInstr/CBotDo.h b/src/CBot/CBotInstr/CBotDo.h
new file mode 100644
index 0000000..670a070
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotDo.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
+
+
+class CBotDo : public CBotInstr
+{
+public:
+
+    /*!
+     * \brief CBotDo Default constructor.
+     */
+    CBotDo();
+
+    /*!
+     * \brief ~CBotDo Destructor.
+     */
+    ~CBotDo();
+
+    /*!
+     * \brief Compile Compile the instruction "do".
+     * \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:
+    //! Instruction
+    CBotInstr* m_Block;
+    //! Conditions
+    CBotInstr* m_Condition;
+    //! A label if there is
+    CBotString m_label;
+};
diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp
index 09cdc2c..9a65348 100644
--- a/src/CBot/CBotWhile.cpp
+++ b/src/CBot/CBotWhile.cpp
@@ -157,140 +157,6 @@ void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain)
     }
 }
 
-
-///////////////////////////////////////////////////////////////////////////
-
-///////////////////////////////////////////////////////////////////////////
-// compile the instruction "do"
-
-CBotDo::CBotDo()
-{
-    m_Condition =
-    m_Block     = nullptr;     // nullptr so that delete is not possible further
-    name = "CBotDo";        // debug
-}
-
-CBotDo::~CBotDo()
-{
-    delete  m_Condition;    // frees the condition
-    delete  m_Block;        // frees the instruction block
-}
-
-CBotInstr* CBotDo::Compile(CBotToken* &p, CBotCStack* pStack)
-{
-    CBotDo* inst = new CBotDo();                // creates the object
-
-    CBotToken*  pp = p;                         // preserves at the ^ token (starting position)
-
-    if ( IsOfType( p, TokenTypVar ) &&
-         IsOfType( p, ID_DOTS ) )
-    {
-        inst->m_label = pp->GetString();        // register the name of label
-    }
-
-    inst->SetToken(p);
-    if (!IsOfType(p, ID_DO)) return nullptr;       // should never happen
-
-    CBotCStack* pStk = pStack->TokenStack(pp);  // un petit bout de pile svp
-
-
-    // looking for a statement block after the do
-    IncLvl(inst->m_label);
-    inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true );
-    DecLvl();
-
-    if ( pStk->IsOk() )
-    {
-        if (IsOfType(p, ID_WHILE))
-        {
-            if ( nullptr != (inst->m_Condition = CBotCondition::Compile( p, pStk )) )
-            {
-                // the condition exists
-                if (IsOfType(p, ID_SEP))
-                {
-                    return pStack->Return(inst, pStk);  // return an object to the application
-                }
-                pStk->SetError(TX_ENDOF, p->GetStart());
-            }
-        }
-        pStk->SetError(TX_WHILE, p->GetStart());
-    }
-
-    delete inst;                                // error, frees up
-    return pStack->Return(nullptr, pStk);          // no object, the error is on the stack
-}
-
-// executes instruction "do"
-
-bool CBotDo :: Execute(CBotStack* &pj)
-{
-    CBotStack* pile = pj->AddStack(this);       // adds an item to the stack
-                                                // or find in case of recovery
-//  if ( pile == EOX ) return true;
-
-    if ( pile->IfStep() ) return false;
-
-    while( true ) switch( pile->GetState() )            // executes the loop
-    {                                                   // there are two possible states (depending on recovery)
-    case 0:
-        // evaluates the associated statement block
-        if ( m_Block != nullptr &&
-            !m_Block->Execute(pile) )
-        {
-            if (pile->IfContinue(1, m_label)) continue; // if continued, will return to test
-            return pj->BreakReturn(pile, m_label);      // sends the results and releases the stack
-        }
-
-        // terminates if there is an error
-        if ( !pile->IsOk() )
-        {
-            return pj->Return(pile);                    // sends the results and releases the stack
-        }
-
-        if (!pile->SetState(1)) return false;           // ready for further
-
-    case 1:
-        // evaluates the condition
-        if ( !m_Condition->Execute(pile) ) return false; // interrupted here ?
-
-        // the result of the condition is on the stack
-
-        // terminates if an error or if the condition is false
-        if ( !pile->IsOk() || pile->GetVal() != true )
-        {
-            return pj->Return(pile);                    // sends the results and releases the stack
-        }
-
-        // returns to instruction block to start
-        if (!pile->SetState(0, 0)) return false;
-        continue;
-    }
-}
-
-void CBotDo :: RestoreState(CBotStack* &pj, bool bMain)
-{
-    if ( !bMain ) return;
-
-    CBotStack* pile = pj->RestoreStack(this);           // adds an item to the stack
-    if ( pile == nullptr ) return;
-
-    switch( pile->GetState() )
-    {                                                   // there are two possible states (depending on recovery)
-    case 0:
-        // restores the assosiated statement's block
-        if ( m_Block != nullptr ) m_Block->RestoreState(pile, bMain);
-        return;
-
-    case 1:
-        // restores the condition
-        m_Condition->RestoreState(pile, bMain);
-        return;
-    }
-}
-
-
-///////////////////////////////////////////////////////////////////////////
-
 ///////////////////////////////////////////////////////////////////////////
 // compiles instruction "for"
 
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index dc7707f..27c283a 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -10,8 +10,17 @@ set(SOURCES
     CBotTwoOpExpr.cpp
     CBotVar.cpp
     CBotWhile.cpp
+    CBotInstr/CBotDo.cpp
 )
 
+# Includes
+set(LOCAL_INCLUDES
+    ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+include_directories(${LOCAL_INCLUDES})
+
+
 if(CBOT_STATIC)
     add_library(CBot STATIC ${SOURCES})
 else()

-- 
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