diff --git a/src/CBot/CBotInstr/CBotDefArray.cpp b/src/CBot/CBotInstr/CBotDefArray.cpp index 2cb05aa0..c70c8f9b 100644 --- a/src/CBot/CBotInstr/CBotDefArray.cpp +++ b/src/CBot/CBotInstr/CBotDefArray.cpp @@ -72,19 +72,26 @@ CBotInstr* CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResul CBotInstr* i; while (IsOfType(p, ID_OPBRK)) { + pStk->SetStartError(p->GetStart()); if (p->GetType() != ID_CLBRK) - i = CBotExpression::Compile(p, pStk); // expression for the value + { + i = CBotExpression::Compile(p, pStk); // expression for the value + if (i == nullptr || pStk->GetType() >= CBotTypBoolean) // must be a number + { + pStk->SetError(CBotErrBadIndex, p->GetStart()); + goto error; + } + } else i = new CBotEmpty(); // if no special formula inst->AddNext3b(i); // construct a list type = CBotTypResult(CBotTypArrayPointer, type); - if (!pStk->IsOk() || !IsOfType(p, ID_CLBRK )) - { - pStk->SetError(CBotErrCloseIndex, p->GetStart()); - goto error; - } + if (IsOfType(p, ID_CLBRK)) continue; + + pStk->SetError(CBotErrCloseIndex, p->GetStart()); + goto error; } CBotVar* var = CBotVar::Create(*vartoken, type); // create an instance @@ -96,17 +103,23 @@ CBotInstr* CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResul if (IsOfType(p, ID_ASS)) // with an assignment { - if ((inst->m_listass = CBotTwoOpExpr::Compile(p, pStk)) != nullptr) + pStk->SetStartError(p->GetStart()); + if ( IsOfType(p, ID_SEP) ) { - if (!pStk->GetTypResult().Compare(type)) // compatible type ? - { - pStk->SetError(CBotErrBadType1, p->GetStart()); - goto error; - } + pStk->SetError(CBotErrBadLeft, p->GetPrev()); + goto error; } - else + if ( nullptr == (inst->m_listass = CBotListArray::Compile(p, pStk, type.GetTypElem())) ) { - inst->m_listass = CBotListArray::Compile(p, pStk, type.GetTypElem()); + if (pStk->IsOk()) + { + inst->m_listass = CBotTwoOpExpr::Compile(p, pStk); + if (inst->m_listass == nullptr || !pStk->GetTypResult().Compare(type)) // compatible type ? + { + pStk->SetError(CBotErrBadType1, p->GetStart()); + goto error; + } + } } } diff --git a/src/CBot/CBotInstr/CBotDefBoolean.cpp b/src/CBot/CBotInstr/CBotDefBoolean.cpp index bcac0722..63b9d346 100644 --- a/src/CBot/CBotInstr/CBotDefBoolean.cpp +++ b/src/CBot/CBotInstr/CBotDefBoolean.cpp @@ -82,16 +82,17 @@ CBotInstr* CBotDefBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, inst = static_cast(CBotDefArray::Compile(p, pStk, CBotTypBoolean)); - if (!pStk->IsOk() ) - { - pStk->SetError(CBotErrCloseIndex, p->GetStart()); - goto error; - } goto suite; // no assignment, variable already created } if (IsOfType(p, ID_ASS)) { + pStk->SetStartError(p->GetStart()); + if ( IsOfType(p, ID_SEP) ) + { + pStk->SetError(CBotErrBadLeft, p->GetPrev()); + goto error; + } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) { goto error; @@ -109,7 +110,7 @@ CBotInstr* CBotDefBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); pStack->AddVar(var); suite: - if (IsOfType(p, ID_COMMA)) + if (pStk->IsOk() && IsOfType(p, ID_COMMA)) { if (nullptr != ( inst->m_next2b = CBotDefBoolean::Compile(p, pStk, true, noskip))) { diff --git a/src/CBot/CBotInstr/CBotDefClass.cpp b/src/CBot/CBotInstr/CBotDefClass.cpp index 39ac6afa..72ec71ec 100644 --- a/src/CBot/CBotInstr/CBotDefClass.cpp +++ b/src/CBot/CBotInstr/CBotDefClass.cpp @@ -101,11 +101,6 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p inst = static_cast(CBotDefArray::Compile(p, pStk, type )); - if (!pStk->IsOk() ) - { - pStk->SetError(CBotErrCloseIndex, p->GetStart()); - goto error; - } goto suite; // no assignment, variable already created } @@ -159,6 +154,12 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p if (IsOfType(p, ID_ASS)) // with a assignment? { + pStk->SetStartError(p->GetStart()); + if ( IsOfType(p, ID_SEP) ) + { + pStk->SetError(CBotErrBadLeft, p->GetPrev()); + goto error; + } if (inst->m_hasParams) { pStk->SetError(CBotErrNoTerminator, p->GetStart()); @@ -200,7 +201,7 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p var->SetInit(CBotVar::InitType::IS_POINTER); // marks the pointer as init } suite: - if (IsOfType(p, ID_COMMA)) // several chained definitions + if (pStk->IsOk() && IsOfType(p, ID_COMMA)) // several chained definitions { if ( nullptr != ( inst->m_next = CBotDefClass::Compile(p, pStk, pClass) )) // compiles the following { @@ -208,7 +209,7 @@ suite: } } - if (IsOfType(p, ID_SEP)) // complete instruction + if (!pStk->IsOk() || IsOfType(p, ID_SEP)) // complete instruction { return pStack->Return(inst, pStk); } diff --git a/src/CBot/CBotInstr/CBotDefFloat.cpp b/src/CBot/CBotInstr/CBotDefFloat.cpp index 9a99662f..33398fa2 100644 --- a/src/CBot/CBotInstr/CBotDefFloat.cpp +++ b/src/CBot/CBotInstr/CBotDefFloat.cpp @@ -81,16 +81,17 @@ CBotInstr* CBotDefFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, b p = vartoken; inst = static_cast(CBotDefArray::Compile(p, pStk, CBotTypFloat)); - if (!pStk->IsOk() ) - { - pStk->SetError(CBotErrCloseIndex, p->GetStart()); - goto error; - } goto suite; // no assignment, variable already created } if (IsOfType(p, ID_ASS)) { + pStk->SetStartError(p->GetStart()); + if ( IsOfType(p, ID_SEP) ) + { + pStk->SetError(CBotErrBadLeft, p->GetPrev()); + goto error; + } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) { goto error; @@ -108,7 +109,7 @@ CBotInstr* CBotDefFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, b (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); pStack->AddVar(var); suite: - if (IsOfType(p, ID_COMMA)) + if (pStk->IsOk() && IsOfType(p, ID_COMMA)) { if (nullptr != ( inst->m_next2b = CBotDefFloat::Compile(p, pStk, true, noskip))) { diff --git a/src/CBot/CBotInstr/CBotDefInt.cpp b/src/CBot/CBotInstr/CBotDefInt.cpp index 360eb22b..9f7dcb61 100644 --- a/src/CBot/CBotInstr/CBotDefInt.cpp +++ b/src/CBot/CBotInstr/CBotDefInt.cpp @@ -84,25 +84,18 @@ CBotInstr* CBotDefInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, boo CBotInstr* inst2 = CBotDefArray::Compile(p, pStk, CBotTypInt); - if (!pStk->IsOk() ) - { - pStk->SetError(CBotErrCloseIndex, p->GetStart()); - goto error; - } - - if (IsOfType(p, ID_COMMA)) // several definition chained - { - if (nullptr != ( inst2->m_next2b = CBotDefInt::Compile(p, pStk, true, noskip))) // compile the next one - { - return pStack->Return(inst2, pStk); - } - } inst = static_cast(inst2); goto suite; // no assignment, variable already created } if (IsOfType(p, ID_ASS)) // with an assignment? { + pStk->SetStartError(p->GetStart()); + if ( IsOfType(p, ID_SEP) ) + { + pStk->SetError(CBotErrBadLeft, p->GetPrev()); + goto error; + } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) { goto error; @@ -121,15 +114,15 @@ CBotInstr* CBotDefInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, boo (static_cast(inst->m_var))->m_nIdent = CBotVar::NextUniqNum()); pStack->AddVar(var); // place it on the stack } - - if (IsOfType(p, ID_COMMA)) // chained several definitions +suite: + if (pStk->IsOk() && IsOfType(p, ID_COMMA)) // chained several definitions { if (nullptr != ( inst->m_next2b = CBotDefInt::Compile(p, pStk, true, noskip))) // compile next one { return pStack->Return(inst, pStk); } } -suite: + if (noskip || IsOfType(p, ID_SEP)) // instruction is completed { return pStack->Return(inst, pStk); diff --git a/src/CBot/CBotInstr/CBotDefString.cpp b/src/CBot/CBotInstr/CBotDefString.cpp index c878a84c..b224a1c0 100644 --- a/src/CBot/CBotInstr/CBotDefString.cpp +++ b/src/CBot/CBotInstr/CBotDefString.cpp @@ -75,15 +75,21 @@ CBotInstr* CBotDefString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, if (IsOfType(p, ID_ASS)) { + pStk->SetStartError(p->GetStart()); + if ( IsOfType(p, ID_SEP) ) + { + pStk->SetError(CBotErrBadLeft, p->GetPrev()); + goto error; + } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) { 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);