Fix inline declaration of an array of string

dev-time-step
melex750 2016-03-20 13:27:02 -04:00
parent 707ef97626
commit 5b3da83715
1 changed files with 20 additions and 5 deletions

View File

@ -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)))
{