[colobot] 60/377: Move CBotFor 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 981f41d8a337097fe45376248098c071bc7b7a3b
Author: Grunaka <dev at romainbreton.fr>
Date:   Sun Nov 8 18:44:36 2015 +0100

    Move CBotFor class in its own header and source files.
---
 src/CBot/CBot.cpp              |   1 +
 src/CBot/CBot.h                |  18 ----
 src/CBot/CBotInstr/CBotFor.cpp | 208 +++++++++++++++++++++++++++++++++++++++++
 src/CBot/CBotInstr/CBotFor.h   |  81 ++++++++++++++++
 src/CBot/CBotWhile.cpp         | 184 ------------------------------------
 src/CBot/CMakeLists.txt        |   1 +
 6 files changed, 291 insertions(+), 202 deletions(-)

diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp
index 375c1f3..dad1ccc 100644
--- a/src/CBot/CBot.cpp
+++ b/src/CBot/CBot.cpp
@@ -37,6 +37,7 @@
 // Modules inlcude
 #include "CBot.h"
 #include "CBotInstr/CBotDo.h"
+#include "CBotInstr/CBotFor.h"
 
 // Local include
 
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index 60e1d88..37d1867 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -483,24 +483,6 @@ public:
     void        RestoreState(CBotStack* &pj, bool bMain) override;
 };
 
-class CBotFor : public CBotInstr
-{
-private:
-    CBotInstr*    m_Init;                // initial intruction
-    CBotInstr*    m_Test;                // test condition
-    CBotInstr*    m_Incr;                // instruction for increment
-    CBotInstr*    m_Block;            // instructions
-    CBotString    m_label;            // a label if there is
-
-public:
-                CBotFor();
-                ~CBotFor();
-    static
-    CBotInstr*    Compile(CBotToken* &p, CBotCStack* pStack);
-    bool        Execute(CBotStack* &pj) override;
-    void        RestoreState(CBotStack* &pj, bool bMain) override;
-};
-
 class CBotBreak : public CBotInstr
 {
 private:
diff --git a/src/CBot/CBotInstr/CBotFor.cpp b/src/CBot/CBotInstr/CBotFor.cpp
new file mode 100644
index 0000000..f920f0e
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotFor.cpp
@@ -0,0 +1,208 @@
+/*
+ * 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 "CBotFor.h"
+
+// Local include
+
+// Global include
+
+////////////////////////////////////////////////////////////////////////////////
+CBotFor::CBotFor()
+{
+    m_Init      =
+    m_Test      =
+    m_Incr      =
+    m_Block     = nullptr;     // nullptr so that delete is not possible further
+    name = "CBotFor";       // debug
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotFor::~CBotFor()
+{
+    delete  m_Init;
+    delete  m_Test;
+    delete  m_Incr;
+    delete  m_Block;        // frees the instruction block
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack)
+{
+    CBotFor*    inst = new CBotFor();           // 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_FOR)) return nullptr;      // should never happen
+
+    if ( !IsOfType(p, ID_OPENPAR))              // missing parenthesis ?
+    {
+        pStack->SetError(TX_OPENPAR, p->GetStart());
+        return nullptr;
+    }
+
+    CBotCStack* pStk = pStack->TokenStack(pp, true);    // un petit bout de pile svp
+
+    // compiles instructions for initialization
+    inst->m_Init = CBotListExpression::Compile( p, pStk );
+    if ( pStk->IsOk() )
+    {
+        if ( !IsOfType(p, ID_SEP))                      // lack the semicolon?
+        {
+            pStack->SetError(TX_OPENPAR, p->GetStart());
+            delete inst;
+            return pStack->Return(nullptr, pStk);          // no object, the error is on the stack
+        }
+        inst->m_Test = CBotBoolExpr::Compile( p, pStk );
+        if ( pStk->IsOk() )
+        {
+            if ( !IsOfType(p, ID_SEP))                      // lack the semicolon?
+            {
+                pStack->SetError(TX_OPENPAR, p->GetStart());
+                delete inst;
+                return pStack->Return(nullptr, pStk);          // no object, the error is on the stack
+            }
+            inst->m_Incr = CBotListExpression::Compile( p, pStk );
+            if ( pStk->IsOk() )
+            {
+                if ( IsOfType(p, ID_CLOSEPAR))              // missing parenthesis ?
+                {
+                    IncLvl(inst->m_label);
+                    inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true );
+                    DecLvl();
+                    if ( pStk->IsOk() )
+                        return pStack->Return(inst, pStk);;
+                }
+                pStack->SetError(TX_CLOSEPAR, p->GetStart());
+            }
+        }
+    }
+
+    delete inst;                                // error, frees up
+    return pStack->Return(nullptr, pStk);          // no object, the error is on the stack
+}
+
+// execution of instruction "for"
+////////////////////////////////////////////////////////////////////////////////
+bool CBotFor :: Execute(CBotStack* &pj)
+{
+    CBotStack* pile = pj->AddStack(this, true);     // adds an item to the stack (variables locales)
+                                                    // 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 four possible states (depending on recovery)
+    case 0:
+        // initialize
+        if ( m_Init != nullptr &&
+             !m_Init->Execute(pile) ) return false;     // interrupted here ?
+        if (!pile->SetState(1)) return false;           // ready for further
+
+    case 1:
+        // evaluates the condition
+        if ( m_Test != nullptr )                           // no strings attached? -> True!
+        {
+            if (!m_Test->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
+            }
+        }
+
+        // la condition est vrai, passe à la suite
+        if (!pile->SetState(2)) return false;           // ready for further
+
+    case 2:
+        // evaluates the associated statement block
+        if ( m_Block != nullptr &&
+            !m_Block->Execute(pile) )
+        {
+            if (pile->IfContinue(3, m_label)) continue; // if continued, going on to incrementation
+            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(3)) return false;           // ready for further
+
+    case 3:
+        // evalutate the incrementation
+        if ( m_Incr != nullptr &&
+            !m_Incr->Execute(pile) ) return false;      // interrupted here ?
+
+        // returns to the test again
+        if (!pile->SetState(1, 0)) return false;            // returns to the test
+        continue;
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotFor :: RestoreState(CBotStack* &pj, bool bMain)
+{
+    if ( !bMain ) return;
+
+    CBotStack* pile = pj->RestoreStack(this);       // adds an item to the stack (variables locales)
+    if ( pile == nullptr ) return;
+
+    switch( pile->GetState() )
+    {                                           // there are four possible states (depending on recovery)
+    case 0:
+        // initialize
+        if ( m_Init != nullptr ) m_Init->RestoreState(pile, true);     // interrupted here !
+        return;
+
+    case 1:
+        if ( m_Init != nullptr ) m_Init->RestoreState(pile, false);    // variables definitions
+
+        // evaluates the condition
+        if ( m_Test != nullptr ) m_Test->RestoreState(pile, true);     // interrupted here !
+        return;
+
+    case 2:
+        if ( m_Init != nullptr ) m_Init->RestoreState(pile, false);    // variable definitions
+
+        // evaluates the associated statement block
+        if ( m_Block != nullptr ) m_Block->RestoreState(pile, true);
+        return;
+
+    case 3:
+        if ( m_Init != nullptr ) m_Init->RestoreState(pile, false);    // variable definitions
+
+        // evaluate the incrementation
+        if ( m_Incr != nullptr ) m_Incr->RestoreState(pile, true);     // interrupted here !
+        return;
+    }
+}
diff --git a/src/CBot/CBotInstr/CBotFor.h b/src/CBot/CBotInstr/CBotFor.h
new file mode 100644
index 0000000..01edc66
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotFor.h
@@ -0,0 +1,81 @@
+/*
+ * 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 CBotFor class
+ */
+class CBotFor : public CBotInstr
+{
+public:
+
+    /*!
+     * \brief CBotFor
+     */
+    CBotFor();
+
+    /*!
+     * \brief CBotFor
+     */
+    ~CBotFor();
+
+    /*!
+     * \brief Compile Compiles instruction "for"
+     * \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:
+
+    //! Initial intruction
+    CBotInstr*    m_Init;
+    //! Test Condition
+    CBotInstr*    m_Test;
+    //! instruction for increment
+    CBotInstr*    m_Incr;
+    //! Instructions
+    CBotInstr*    m_Block;
+    //! A label if there is
+    CBotString    m_label;
+};
diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp
index 9a65348..d58dc54 100644
--- a/src/CBot/CBotWhile.cpp
+++ b/src/CBot/CBotWhile.cpp
@@ -157,188 +157,6 @@ void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain)
     }
 }
 
-///////////////////////////////////////////////////////////////////////////
-// compiles instruction "for"
-
-CBotFor::CBotFor()
-{
-    m_Init      =
-    m_Test      =
-    m_Incr      =
-    m_Block     = nullptr;     // nullptr so that delete is not possible further
-    name = "CBotFor";       // debug
-}
-
-CBotFor::~CBotFor()
-{
-    delete  m_Init;
-    delete  m_Test;
-    delete  m_Incr;
-    delete  m_Block;        // frees the instruction block
-}
-
-CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack)
-{
-    CBotFor*    inst = new CBotFor();           // 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_FOR)) return nullptr;      // should never happen
-
-    if ( !IsOfType(p, ID_OPENPAR))              // missing parenthesis ?
-    {
-        pStack->SetError(TX_OPENPAR, p->GetStart());
-        return nullptr;
-    }
-
-    CBotCStack* pStk = pStack->TokenStack(pp, true);    // un petit bout de pile svp
-
-    // compiles instructions for initialization
-    inst->m_Init = CBotListExpression::Compile( p, pStk );
-    if ( pStk->IsOk() )
-    {
-        if ( !IsOfType(p, ID_SEP))                      // lack the semicolon?
-        {
-            pStack->SetError(TX_OPENPAR, p->GetStart());
-            delete inst;
-            return pStack->Return(nullptr, pStk);          // no object, the error is on the stack
-        }
-        inst->m_Test = CBotBoolExpr::Compile( p, pStk );
-        if ( pStk->IsOk() )
-        {
-            if ( !IsOfType(p, ID_SEP))                      // lack the semicolon?
-            {
-                pStack->SetError(TX_OPENPAR, p->GetStart());
-                delete inst;
-                return pStack->Return(nullptr, pStk);          // no object, the error is on the stack
-            }
-            inst->m_Incr = CBotListExpression::Compile( p, pStk );
-            if ( pStk->IsOk() )
-            {
-                if ( IsOfType(p, ID_CLOSEPAR))              // missing parenthesis ?
-                {
-                    IncLvl(inst->m_label);
-                    inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true );
-                    DecLvl();
-                    if ( pStk->IsOk() )
-                        return pStack->Return(inst, pStk);;
-                }
-                pStack->SetError(TX_CLOSEPAR, p->GetStart());
-            }
-        }
-    }
-
-    delete inst;                                // error, frees up
-    return pStack->Return(nullptr, pStk);          // no object, the error is on the stack
-}
-
-// execution of instruction "for"
-
-bool CBotFor :: Execute(CBotStack* &pj)
-{
-    CBotStack* pile = pj->AddStack(this, true);     // adds an item to the stack (variables locales)
-                                                    // 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 four possible states (depending on recovery)
-    case 0:
-        // initialize
-        if ( m_Init != nullptr &&
-             !m_Init->Execute(pile) ) return false;     // interrupted here ?
-        if (!pile->SetState(1)) return false;           // ready for further
-
-    case 1:
-        // evaluates the condition
-        if ( m_Test != nullptr )                           // no strings attached? -> True!
-        {
-            if (!m_Test->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
-            }
-        }
-
-        // la condition est vrai, passe à la suite
-        if (!pile->SetState(2)) return false;           // ready for further
-
-    case 2:
-        // evaluates the associated statement block
-        if ( m_Block != nullptr &&
-            !m_Block->Execute(pile) )
-        {
-            if (pile->IfContinue(3, m_label)) continue; // if continued, going on to incrementation
-            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(3)) return false;           // ready for further
-
-    case 3:
-        // evalutate the incrementation
-        if ( m_Incr != nullptr &&
-            !m_Incr->Execute(pile) ) return false;      // interrupted here ?
-
-        // returns to the test again
-        if (!pile->SetState(1, 0)) return false;            // returns to the test
-        continue;
-    }
-}
-
-void CBotFor :: RestoreState(CBotStack* &pj, bool bMain)
-{
-    if ( !bMain ) return;
-
-    CBotStack* pile = pj->RestoreStack(this);       // adds an item to the stack (variables locales)
-    if ( pile == nullptr ) return;
-
-    switch( pile->GetState() )
-    {                                           // there are four possible states (depending on recovery)
-    case 0:
-        // initialize
-        if ( m_Init != nullptr ) m_Init->RestoreState(pile, true);     // interrupted here !
-        return;
-
-    case 1:
-        if ( m_Init != nullptr ) m_Init->RestoreState(pile, false);    // variables definitions
-
-        // evaluates the condition
-        if ( m_Test != nullptr ) m_Test->RestoreState(pile, true);     // interrupted here !
-        return;
-
-    case 2:
-        if ( m_Init != nullptr ) m_Init->RestoreState(pile, false);    // variable definitions
-
-        // evaluates the associated statement block
-        if ( m_Block != nullptr ) m_Block->RestoreState(pile, true);
-        return;
-
-    case 3:
-        if ( m_Init != nullptr ) m_Init->RestoreState(pile, false);    // variable definitions
-
-        // evaluate the incrementation
-        if ( m_Incr != nullptr ) m_Incr->RestoreState(pile, true);     // interrupted here !
-        return;
-    }
-}
-
 //////////////////////////////////////////////////////////////////////////////////////
 // compiles a list of expressions
 // is used only in "for" statement
@@ -435,8 +253,6 @@ void CBotListExpression::RestoreState(CBotStack* &pj, bool bMain)
 }
 
 ///////////////////////////////////////////////////////////////////////////
-
-///////////////////////////////////////////////////////////////////////////
 // compiles instruction "switch"
 
 CBotSwitch::CBotSwitch()
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index 27c283a..34782a0 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -11,6 +11,7 @@ set(SOURCES
     CBotVar.cpp
     CBotWhile.cpp
     CBotInstr/CBotDo.cpp
+    CBotInstr/CBotFor.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