[colobot] 94/377: Moving CBotIString 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 13b82b7e8e60afc6d69e35efe4c90a8a665535e9
Author: Grunaka <dev at romainbreton.fr>
Date:   Wed Nov 11 22:45:27 2015 +0100

    Moving CBotIString class in its own header and source files.
---
 src/CBot/CBot.cpp                         | 133 +------------------------
 src/CBot/CBot.h                           |  17 ----
 src/CBot/CBotInstr/CBotIString.cpp        | 156 ++++++++++++++++++++++++++++++
 src/CBot/CBotInstr/CBotIString.h          |  76 +++++++++++++++
 src/CBot/CBotInstr/CBotListExpression.cpp |   1 +
 src/CBot/CMakeLists.txt                   |   1 +
 6 files changed, 235 insertions(+), 149 deletions(-)

diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp
index 9e4716e..072aa28 100644
--- a/src/CBot/CBot.cpp
+++ b/src/CBot/CBot.cpp
@@ -62,6 +62,7 @@
 #include "CBotInstr/CBotIndexExpr.h"
 #include "CBotInstr/CBotFieldExpr.h"
 #include "CBotInstr/CBotClassInst.h"
+#include "CBotInstr/CBotIString.h"
 
 
 // Local include
@@ -1220,138 +1221,6 @@ void CBotFloat::RestoreState(CBotStack* &pj, bool bMain)
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-
-//////////////////////////////////////////////////////////////////////////////////////
-// define a string variable
-// int a, b = "salut";
-
-CBotIString::CBotIString()
-{
-    m_var    =
-    m_expr    = nullptr;
-    name = "CBotIString";
-}
-
-CBotIString::~CBotIString()
-{
-    delete m_var;
-    delete m_expr;
-}
-
-CBotInstr* CBotIString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip)
-{
-    CBotToken*    pp = cont ? nullptr : p;
-
-    if (!cont && !IsOfType(p, ID_STRING)) return nullptr;
-
-    CBotIString*    inst = static_cast<CBotIString*>(CompileArray(p, pStack, CBotTypString));
-    if (inst != nullptr || !pStack->IsOk()) return inst;
-
-    CBotCStack* pStk = pStack->TokenStack(pp);
-
-    inst = new CBotIString();
-
-    inst->m_expr = nullptr;
-
-    CBotToken*    vartoken = p;
-    inst->SetToken(vartoken);
-
-    if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )))
-    {
-        (static_cast<CBotLeftExprVar*>(inst->m_var))->m_typevar = CBotTypString;
-        if (pStk->CheckVarLocal(vartoken))
-        {
-            pStk->SetStartError(vartoken->GetStart());
-            pStk->SetError(TX_REDEFVAR, vartoken->GetEnd());
-            goto error;
-        }
-
-        if (IsOfType(p,  ID_ASS))
-        {
-            if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
-            {
-                goto error;
-            }
-/*            if (!pStk->GetTypResult().Eq(CBotTypString))            // type compatible ?
-            {
-                pStk->SetError(TX_BADTYPE, p->GetStart());
-                goto error;
-            }*/
-        }
-
-        CBotVar*    var = CBotVar::Create(vartoken, CBotTypString);
-        var->SetInit(inst->m_expr != nullptr ? CBotVar::InitType::DEF : CBotVar::InitType::UNDEF);
-        var->SetUniqNum(
-            (static_cast<CBotLeftExprVar*>(inst->m_var))->m_nIdent = CBotVar::NextUniqNum());
-        pStack->AddVar(var);
-
-        if (IsOfType(p,  ID_COMMA))
-        {
-            if (nullptr != ( inst->m_next2b = CBotIString::Compile(p, pStk, true, noskip)))
-            {
-                return pStack->Return(inst, pStk);
-            }
-        }
-
-        if (noskip || IsOfType(p,  ID_SEP))
-        {
-            return pStack->Return(inst, pStk);
-        }
-
-        pStk->SetError(TX_ENDOF, p->GetStart());
-    }
-
-error:
-    delete inst;
-    return pStack->Return(nullptr, pStk);
-}
-
-// executes the definition of the string variable
-
-bool CBotIString::Execute(CBotStack* &pj)
-{
-    CBotStack*    pile = pj->AddStack(this);
-
-    if ( pile->GetState()==0)
-    {
-        if (m_expr && !m_expr->Execute(pile)) return false;
-        m_var->Execute(pile);
-
-        if (!pile->SetState(1)) return false;
-    }
-
-    if (pile->IfStep()) return false;
-
-    if ( m_next2b &&
-         !m_next2b->Execute(pile)) return false;
-
-    return pj->Return(pile);
-}
-
-void CBotIString::RestoreState(CBotStack* &pj, bool bMain)
-{
-    CBotStack*    pile = pj;
-
-    if (bMain)
-    {
-        pile = pj->RestoreStack(this);
-        if (pile == nullptr) return;
-
-        if ( pile->GetState()==0)
-        {
-            if (m_expr) m_expr->RestoreState(pile, bMain);
-            return;
-        }
-    }
-
-    m_var->RestoreState(pile, bMain);
-
-    if (m_next2b)
-         m_next2b->RestoreState(pile, bMain);
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////
-
 // compile a list of parameters
 
 CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars)
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index a045dc3..9c1a8e2 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -600,23 +600,6 @@ public:
     void        RestoreState(CBotStack* &pj, bool bMain) override;
 };
 
-// definition of an element string
-
-class CBotIString : public CBotInstr
-{
-private:
-    CBotInstr*    m_var;                // variable to initialise
-    CBotInstr*    m_expr;                // a value to put, if there is
-
-public:
-                CBotIString();
-                ~CBotIString();
-    static
-    CBotInstr*    Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false);
-    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/CBotIString.cpp b/src/CBot/CBotInstr/CBotIString.cpp
new file mode 100644
index 0000000..b0e8a6a
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotIString.cpp
@@ -0,0 +1,156 @@
+/*
+ * 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 "CBotIString.h"
+#include "CBotLeftExprVar.h"
+#include "CBotTwoOpExpr.h"
+
+// Local include
+
+// Global include
+
+
+////////////////////////////////////////////////////////////////////////////////
+CBotIString::CBotIString()
+{
+    m_var    =
+    m_expr    = nullptr;
+    name = "CBotIString";
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotIString::~CBotIString()
+{
+    delete m_var;
+    delete m_expr;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CBotInstr* CBotIString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, bool noskip)
+{
+    CBotToken*    pp = cont ? nullptr : p;
+
+    if (!cont && !IsOfType(p, ID_STRING)) return nullptr;
+
+    CBotIString*    inst = static_cast<CBotIString*>(CompileArray(p, pStack, CBotTypString));
+    if (inst != nullptr || !pStack->IsOk()) return inst;
+
+    CBotCStack* pStk = pStack->TokenStack(pp);
+
+    inst = new CBotIString();
+
+    inst->m_expr = nullptr;
+
+    CBotToken*    vartoken = p;
+    inst->SetToken(vartoken);
+
+    if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )))
+    {
+        (static_cast<CBotLeftExprVar*>(inst->m_var))->m_typevar = CBotTypString;
+        if (pStk->CheckVarLocal(vartoken))
+        {
+            pStk->SetStartError(vartoken->GetStart());
+            pStk->SetError(TX_REDEFVAR, vartoken->GetEnd());
+            goto error;
+        }
+
+        if (IsOfType(p,  ID_ASS))
+        {
+            if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
+            {
+                goto error;
+            }
+/*            if (!pStk->GetTypResult().Eq(CBotTypString))            // type compatible ?
+            {
+                pStk->SetError(TX_BADTYPE, p->GetStart());
+                goto error;
+            }*/
+        }
+
+        CBotVar*    var = CBotVar::Create(vartoken, CBotTypString);
+        var->SetInit(inst->m_expr != nullptr ? CBotVar::InitType::DEF : CBotVar::InitType::UNDEF);
+        var->SetUniqNum(
+            (static_cast<CBotLeftExprVar*>(inst->m_var))->m_nIdent = CBotVar::NextUniqNum());
+        pStack->AddVar(var);
+
+        if (IsOfType(p,  ID_COMMA))
+        {
+            if (nullptr != ( inst->m_next2b = CBotIString::Compile(p, pStk, true, noskip)))
+            {
+                return pStack->Return(inst, pStk);
+            }
+        }
+
+        if (noskip || IsOfType(p,  ID_SEP))
+        {
+            return pStack->Return(inst, pStk);
+        }
+
+        pStk->SetError(TX_ENDOF, p->GetStart());
+    }
+
+error:
+    delete inst;
+    return pStack->Return(nullptr, pStk);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CBotIString::Execute(CBotStack* &pj)
+{
+    CBotStack*    pile = pj->AddStack(this);
+
+    if ( pile->GetState()==0)
+    {
+        if (m_expr && !m_expr->Execute(pile)) return false;
+        m_var->Execute(pile);
+
+        if (!pile->SetState(1)) return false;
+    }
+
+    if (pile->IfStep()) return false;
+
+    if ( m_next2b &&
+         !m_next2b->Execute(pile)) return false;
+
+    return pj->Return(pile);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CBotIString::RestoreState(CBotStack* &pj, bool bMain)
+{
+    CBotStack*    pile = pj;
+
+    if (bMain)
+    {
+        pile = pj->RestoreStack(this);
+        if (pile == nullptr) return;
+
+        if ( pile->GetState()==0)
+        {
+            if (m_expr) m_expr->RestoreState(pile, bMain);
+            return;
+        }
+    }
+
+    m_var->RestoreState(pile, bMain);
+
+    if (m_next2b)
+         m_next2b->RestoreState(pile, bMain);
+}
diff --git a/src/CBot/CBotInstr/CBotIString.h b/src/CBot/CBotInstr/CBotIString.h
new file mode 100644
index 0000000..1d91ea2
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotIString.h
@@ -0,0 +1,76 @@
+/*
+ * 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 CBotIString class Define a string variable eg : int a, b = "salut";
+ */
+class CBotIString : public CBotInstr
+{
+public:
+
+    /*!
+     * \brief CBotIString
+     */
+    CBotIString();
+
+    /*!
+     * \brief ~CBotIString
+     */
+    ~CBotIString();
+
+    /*!
+     * \brief Compile
+     * \param p
+     * \param pStack
+     * \param cont
+     * \param noskip
+     * \return
+     */
+    static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, bool cont = false, bool noskip=false);
+
+    /*!
+     * \brief Execute Executes the definition of the string variable.
+     * \param pj
+     * \return
+     */
+    bool Execute(CBotStack* &pj) override;
+
+    /*!
+     * \brief RestoreState
+     * \param pj
+     * \param bMain
+     */
+    void RestoreState(CBotStack* &pj, bool bMain) override;
+
+private:
+    //! Variable to initialise.
+    CBotInstr* m_var;
+    //! A value to put, if there is.
+    CBotInstr* m_expr;
+};
diff --git a/src/CBot/CBotInstr/CBotListExpression.cpp b/src/CBot/CBotInstr/CBotListExpression.cpp
index c631e76..285c616 100644
--- a/src/CBot/CBotInstr/CBotListExpression.cpp
+++ b/src/CBot/CBotInstr/CBotListExpression.cpp
@@ -20,6 +20,7 @@
 // Modules inlcude
 #include "CBotListExpression.h"
 #include "CBotExpression.h"
+#include "CBotIString.h"
 
 // Local include
 
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index 7142723..a0b76fc 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -43,6 +43,7 @@ set(SOURCES
     CBotInstr/CBotLeftExpr.cpp
     CBotInstr/CBotCondition.cpp
     CBotInstr/CBotClassInst.cpp
+    CBotInstr/CBotIString.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