From 5b3da837156619fe62bfe10d9a4378c5db0cafe3 Mon Sep 17 00:00:00 2001 From: melex750 Date: Sun, 20 Mar 2016 13:27:02 -0400 Subject: [PATCH] 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 b224a1c0..77e0119f 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(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(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))) {