[colobot] 61/377: Moving CBotListExpression 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 dd6f6e29c227a3d5a348bbb7da2189535627c3f8
Author: Grunaka <dev at romainbreton.fr>
Date:   Sun Nov 8 18:54:49 2015 +0100

    Moving CBotListExpression class in its own header and source files.
---
 src/CBot/CBot.h                           |  14 ----
 src/CBot/CBotInstr/CBotFor.cpp            |   1 +
 src/CBot/CBotInstr/CBotListExpression.cpp | 123 ++++++++++++++++++++++++++++++
 src/CBot/CBotInstr/CBotListExpression.h   |  72 +++++++++++++++++
 src/CBot/CBotWhile.cpp                    |  95 -----------------------
 src/CBot/CMakeLists.txt                   |   1 +
 6 files changed, 197 insertions(+), 109 deletions(-)

diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index 37d1867..4d70132 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -835,20 +835,6 @@ public:
     void        RestoreState(CBotStack* &pj, bool bMain) override;
 };
 
-class CBotListExpression : public CBotInstr
-{
-private:
-    CBotInstr*    m_Expr;                // the first expression to be evaluated
-
-public:
-                CBotListExpression();
-                ~CBotListExpression();
-    static
-    CBotInstr*    Compile(CBotToken* &p, CBotCStack* pStack);
-    bool        Execute(CBotStack* &pStack) override;
-    void        RestoreState(CBotStack* &pj, bool bMain) override;
-};
-
 class CBotLogicExpr : public CBotInstr
 {
 private:
diff --git a/src/CBot/CBotInstr/CBotFor.cpp b/src/CBot/CBotInstr/CBotFor.cpp
index f920f0e..7dc07d4 100644
--- a/src/CBot/CBotInstr/CBotFor.cpp
+++ b/src/CBot/CBotInstr/CBotFor.cpp
@@ -19,6 +19,7 @@
 
 // Modules inlcude
 #include "CBotFor.h"
+#include "CBotListExpression.h"
 
 // Local include
 
diff --git a/src/CBot/CBotInstr/CBotListExpression.cpp b/src/CBot/CBotInstr/CBotListExpression.cpp
new file mode 100644
index 0000000..66f7eaf
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotListExpression.cpp
@@ -0,0 +1,123 @@
+/*
+ * 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 "CBotListExpression.h"
+
+// Local include
+
+// Global include
+
+////////////////////////////////////////////////////////////////////////////////
+/// Seeks a declaration of variable or expression
+static CBotInstr* CompileInstrOrDefVar(CBotToken* &p, CBotCStack* pStack)
+{
+    CBotInstr*  i = CBotInt::Compile( p, pStack, false, true );         // Is this a declaration of an integer?
+    if ( i== nullptr ) i = CBotFloat::Compile( p, pStack, false, true );   // or a real number?
+    if ( i== nullptr ) i = CBotBoolean::Compile( p, pStack, false, true ); // or a boolean?
+    if ( i== nullptr ) i = CBotIString::Compile( p, pStack, false, true ); // ar a string?
+    if ( i== nullptr ) i = CBotExpression::Compile( p, pStack );           // compiles an expression
+    return i;
+}
+////////////////////////////////////////////////////////////////////////////////
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+CBotListExpression::CBotListExpression()
+{
+    m_Expr  = nullptr;
+    name = "CBotListExpression";
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotListExpression::~CBotListExpression()
+{
+    delete  m_Expr;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotInstr* CBotListExpression::Compile(CBotToken* &p, CBotCStack* pStack)
+{
+    CBotListExpression* inst = new CBotListExpression();
+
+    inst->m_Expr = CompileInstrOrDefVar( p, pStack );           // compile the first expression in a list
+    if (pStack->IsOk())
+    {
+        while ( IsOfType(p, ID_COMMA) )                         // more instructions?
+        {
+            CBotInstr*  i = CompileInstrOrDefVar( p, pStack );      // Is this a declaration of an integer?
+            inst->m_Expr->AddNext(i);                           // added after
+            if ( !pStack->IsOk() )
+            {
+                delete inst;
+                return nullptr;                                    // no object, the error is on the stack
+            }
+        }
+        return inst;
+    }
+    delete inst;
+    return nullptr;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotListExpression::Execute(CBotStack* &pj)
+{
+    CBotStack*  pile = pj->AddStack();                          // essential
+    CBotInstr*  p = m_Expr;                                     // 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;
+        if (!pile->IncState()) return false;                    // ready for next
+    }
+    return pj->Return(pile);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotListExpression::RestoreState(CBotStack* &pj, bool bMain)
+{
+    CBotStack*  pile = pj;
+    int     state = 0x7000;
+
+    if ( bMain )
+    {
+        pile = pj->RestoreStack();
+        if ( pile == nullptr ) return;
+        state = pile->GetState();
+    }
+
+    CBotInstr*  p = m_Expr;                                     // the first expression
+
+    while (p != nullptr && state-->0)
+    {
+        p->RestoreState(pile, false);
+        p = p->GetNext();                           // returns to the interrupted operation
+    }
+
+    if ( p != nullptr )
+    {
+        p->RestoreState(pile, bMain);
+    }
+}
diff --git a/src/CBot/CBotInstr/CBotListExpression.h b/src/CBot/CBotInstr/CBotListExpression.h
new file mode 100644
index 0000000..c4e6711
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotListExpression.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 CBotListExpression class. Compiles a list of expressions is used
+ * only in "for" statement in incrementing and intitialisation.
+ */
+class CBotListExpression : public CBotInstr
+{
+public:
+
+    /*!
+     * \brief CBotListExpression
+     */
+    CBotListExpression();
+
+    /*!
+     * \brief CBotListExpression
+     */
+    ~CBotListExpression();
+
+    /*!
+     * \brief Compile
+     * \param p
+     * \param pStack
+     * \return
+     */
+    static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+
+    /*!
+     * \brief Execute
+     * \param pStack
+     * \return
+     */
+    bool Execute(CBotStack* &pStack) override;
+
+    /*!
+     * \brief RestoreState
+     * \param pj
+     * \param bMain
+     */
+    void RestoreState(CBotStack* &pj, bool bMain) override;
+
+private:
+    //! The first expression to be evaluated
+    CBotInstr* m_Expr;
+};
diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp
index d58dc54..a691c5a 100644
--- a/src/CBot/CBotWhile.cpp
+++ b/src/CBot/CBotWhile.cpp
@@ -157,101 +157,6 @@ void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain)
     }
 }
 
-//////////////////////////////////////////////////////////////////////////////////////
-// compiles a list of expressions
-// is used only in "for" statement
-// in incrementing and intitialisation
-
-CBotListExpression::CBotListExpression()
-{
-    m_Expr  = nullptr;
-    name = "CBotListExpression";
-}
-
-CBotListExpression::~CBotListExpression()
-{
-    delete  m_Expr;
-}
-
-// seeks a declaration of variable or expression
-
-static CBotInstr* CompileInstrOrDefVar(CBotToken* &p, CBotCStack* pStack)
-{
-    CBotInstr*  i = CBotInt::Compile( p, pStack, false, true );         // Is this a declaration of an integer?
-    if ( i== nullptr ) i = CBotFloat::Compile( p, pStack, false, true );   // or a real number?
-    if ( i== nullptr ) i = CBotBoolean::Compile( p, pStack, false, true ); // or a boolean?
-    if ( i== nullptr ) i = CBotIString::Compile( p, pStack, false, true ); // ar a string?
-    if ( i== nullptr ) i = CBotExpression::Compile( p, pStack );           // compiles an expression
-    return i;
-}
-
-CBotInstr* CBotListExpression::Compile(CBotToken* &p, CBotCStack* pStack)
-{
-    CBotListExpression* inst = new CBotListExpression();
-
-    inst->m_Expr = CompileInstrOrDefVar( p, pStack );           // compile the first expression in a list
-    if (pStack->IsOk())
-    {
-        while ( IsOfType(p, ID_COMMA) )                         // more instructions?
-        {
-            CBotInstr*  i = CompileInstrOrDefVar( p, pStack );      // Is this a declaration of an integer?
-            inst->m_Expr->AddNext(i);                           // added after
-            if ( !pStack->IsOk() )
-            {
-                delete inst;
-                return nullptr;                                    // no object, the error is on the stack
-            }
-        }
-        return inst;
-    }
-    delete inst;
-    return nullptr;
-}
-
-bool CBotListExpression::Execute(CBotStack* &pj)
-{
-    CBotStack*  pile = pj->AddStack();                          // essential
-    CBotInstr*  p = m_Expr;                                     // 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;
-        if (!pile->IncState()) return false;                    // ready for next
-    }
-    return pj->Return(pile);
-}
-
-void CBotListExpression::RestoreState(CBotStack* &pj, bool bMain)
-{
-    CBotStack*  pile = pj;
-    int     state = 0x7000;
-
-    if ( bMain )
-    {
-        pile = pj->RestoreStack();
-        if ( pile == nullptr ) return;
-        state = pile->GetState();
-    }
-
-    CBotInstr*  p = m_Expr;                                     // the first expression
-
-    while (p != nullptr && state-->0)
-    {
-        p->RestoreState(pile, false);
-        p = p->GetNext();                           // returns to the interrupted operation
-    }
-
-    if ( p != nullptr )
-    {
-        p->RestoreState(pile, bMain);
-    }
-}
-
 ///////////////////////////////////////////////////////////////////////////
 // compiles instruction "switch"
 
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index 34782a0..030c4de 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -12,6 +12,7 @@ set(SOURCES
     CBotWhile.cpp
     CBotInstr/CBotDo.cpp
     CBotInstr/CBotFor.cpp
+    CBotInstr/CBotListExpression.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