[colobot] 04/145: Fix inline declaration of an array of string

Didier Raboud odyx at moszumanska.debian.org
Mon Jul 11 12:56:11 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 5b3da837156619fe62bfe10d9a4378c5db0cafe3
Author: melex750 <melex750 at users.noreply.github.com>
Date:   Sun Mar 20 13:27:02 2016 -0400

    Fix inline declaration of an array of string
---
 src/CBot/CBotInstr/CBotDefString.cpp | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/CBot/CBotInstr/CBotDefString.cpp b/src/CBot/CBotInstr/CBotDefString.cpp
index b224a1c..77e0119 100644
--- a/src/CBot/CBotInstr/CBotDefString.cpp
+++ b/src/CBot/CBotInstr/CBotDefString.cpp
@@ -20,6 +20,7 @@
 #include "CBot/CBotInstr/CBotDefString.h"
 
 #include "CBot/CBotInstr/CBotLeftExprVar.h"
+#include "CBot/CBotInstr/CBotDefArray.h"
 #include "CBot/CBotInstr/CBotTwoOpExpr.h"
 
 #include "CBot/CBotStack.h"
@@ -61,6 +62,7 @@ CBotInstr* CBotDefString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont,
     inst->m_expr = nullptr;
 
     CBotToken*    vartoken = p;
+    CBotVar*    var = nullptr;
     inst->SetToken(vartoken);
 
     if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )))
@@ -73,6 +75,19 @@ CBotInstr* CBotDefString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont,
             goto error;
         }
 
+        if (IsOfType(p,  ID_OPBRK))
+        {
+            delete inst;    // type is not CBotDefString
+            p = vartoken;   // returns the variable name
+
+            // compiles an array declaration
+
+            CBotInstr* inst2 = CBotDefArray::Compile(p, pStk, CBotTypString);
+
+            inst = static_cast<CBotDefString*>(inst2);
+            goto suite;     // no assignment, variable already created
+        }
+
         if (IsOfType(p,  ID_ASS))
         {
             pStk->SetStartError(p->GetStart());
@@ -85,20 +100,20 @@ CBotInstr* CBotDefString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont,
             {
                 goto error;
             }
-            if (!pStk->GetTypResult().Eq(CBotTypString))            // type compatible ?
+/*            if (!pStk->GetTypResult().Eq(CBotTypString))            // type compatible ?
             {
                 pStk->SetError(CBotErrBadType1, p->GetStart());
                 goto error;
-            }
+            }*/
         }
 
-        CBotVar*    var = CBotVar::Create(*vartoken, CBotTypString);
+        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))
+suite:
+        if (pStk->IsOk() && IsOfType(p,  ID_COMMA))
         {
             if (nullptr != ( inst->m_next2b = CBotDefString::Compile(p, pStk, true, noskip)))
             {

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