diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index aca2d2b0..e701db86 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -550,6 +550,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) while (pStack->IsOk()) { + CBotTypResult type2 = CBotTypResult(type); // reset type after comma std::string pp = p->GetString(); if ( IsOfType(p, ID_NOT) ) { @@ -575,7 +576,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) else i = new CBotEmpty(); // special if not a formula - type = CBotTypResult(CBotTypArrayPointer, type); + type2 = CBotTypResult(CBotTypArrayPointer, type2); if (limites == nullptr) limites = i; else limites->AddNext3(i); @@ -671,7 +672,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) } // definition of an element - if (type.Eq(0)) + if (type2.Eq(0)) { pStack->SetError(CBotErrNoTerminator, p); return false; @@ -683,26 +684,33 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) pStack->SetStartError(p->GetStart()); if ( IsOfType(p, ID_SEP) ) { - pStack->SetError(CBotErrNoExpression, p->GetPrev()); + pStack->SetError(CBotErrNoExpression, p->GetStart()); return false; } - if ( type.Eq(CBotTypArrayPointer) ) + if ( type2.Eq(CBotTypArrayPointer) ) { - i = CBotListArray::Compile(p, pStack, type.GetTypElem()); + if ( nullptr == (i = CBotListArray::Compile(p, pStack, type2.GetTypElem())) ) + { + if (pStack->IsOk()) + { + i = CBotTwoOpExpr::Compile(p, pStack); + if (i == nullptr || !pStack->GetTypResult().Compare(type2)) + { + pStack->SetError(CBotErrBadType1, p->GetStart()); + return false; + } + } + } } else { // it has an assignmet to calculate i = CBotTwoOpExpr::Compile(p, pStack); - CBotTypResult retType = pStack->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC); - - if ( (type.Eq(CBotTypString) && !retType.Eq(CBotTypString)) || - (!(type.Eq(CBotTypPointer) && retType.Eq(CBotTypNullPointer)) && - !TypeCompatible( type, retType, ID_ASS)) ) - + if ( !(type.Eq(CBotTypPointer) && pStack->GetTypResult().Eq(CBotTypNullPointer)) && + !TypesCompatibles( type, pStack->GetTypResult()) ) { - pStack->SetError(CBotErrBadType1, p->GetPrev()); + pStack->SetError(CBotErrBadType1, p->GetStart()); return false; } } @@ -712,7 +720,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) if ( !bSecond ) { - CBotVar* pv = CBotVar::Create(pp, type); + CBotVar* pv = CBotVar::Create(pp, type2); pv -> SetStatic( bStatic ); pv -> SetPrivate( mProtect ); diff --git a/src/CBot/CBotInstr/CBotDefBoolean.cpp b/src/CBot/CBotInstr/CBotDefBoolean.cpp index d64a1860..e89bdc83 100644 --- a/src/CBot/CBotInstr/CBotDefBoolean.cpp +++ b/src/CBot/CBotInstr/CBotDefBoolean.cpp @@ -90,7 +90,7 @@ CBotInstr* CBotDefBoolean::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, pStk->SetStartError(p->GetStart()); if ( IsOfType(p, ID_SEP) ) { - pStk->SetError(CBotErrNoExpression, p->GetPrev()); + pStk->SetError(CBotErrNoExpression, p->GetStart()); goto error; } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) diff --git a/src/CBot/CBotInstr/CBotDefClass.cpp b/src/CBot/CBotInstr/CBotDefClass.cpp index ab4ea991..f7ea77a6 100644 --- a/src/CBot/CBotInstr/CBotDefClass.cpp +++ b/src/CBot/CBotInstr/CBotDefClass.cpp @@ -155,17 +155,18 @@ 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(CBotErrNoExpression, p->GetPrev()); - goto error; - } if (inst->m_hasParams) { pStk->SetError(CBotErrNoTerminator, p->GetStart()); goto error; } + if ( IsOfType(p, ID_SEP) ) + { + pStk->SetError(CBotErrNoExpression, p->GetStart()); + goto error; + } + if ( nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) ) { goto error; @@ -201,7 +202,7 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p var->SetInit(CBotVar::InitType::IS_POINTER); // marks the pointer as init } suite: - if (pStk->IsOk() && 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 { @@ -209,7 +210,7 @@ suite: } } - if (!pStk->IsOk() || 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 5348a529..17466581 100644 --- a/src/CBot/CBotInstr/CBotDefFloat.cpp +++ b/src/CBot/CBotInstr/CBotDefFloat.cpp @@ -89,7 +89,7 @@ CBotInstr* CBotDefFloat::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, b pStk->SetStartError(p->GetStart()); if ( IsOfType(p, ID_SEP) ) { - pStk->SetError(CBotErrNoExpression, p->GetPrev()); + pStk->SetError(CBotErrNoExpression, p->GetStart()); goto error; } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) diff --git a/src/CBot/CBotInstr/CBotDefInt.cpp b/src/CBot/CBotInstr/CBotDefInt.cpp index babd3fda..4e946e9b 100644 --- a/src/CBot/CBotInstr/CBotDefInt.cpp +++ b/src/CBot/CBotInstr/CBotDefInt.cpp @@ -93,7 +93,7 @@ CBotInstr* CBotDefInt::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, boo pStk->SetStartError(p->GetStart()); if ( IsOfType(p, ID_SEP) ) { - pStk->SetError(CBotErrNoExpression, p->GetPrev()); + pStk->SetError(CBotErrNoExpression, p->GetStart()); goto error; } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) diff --git a/src/CBot/CBotInstr/CBotDefString.cpp b/src/CBot/CBotInstr/CBotDefString.cpp index cb4502d9..9bf2eebe 100644 --- a/src/CBot/CBotInstr/CBotDefString.cpp +++ b/src/CBot/CBotInstr/CBotDefString.cpp @@ -93,7 +93,7 @@ CBotInstr* CBotDefString::Compile(CBotToken* &p, CBotCStack* pStack, bool cont, pStk->SetStartError(p->GetStart()); if ( IsOfType(p, ID_SEP) ) { - pStk->SetError(CBotErrNoExpression, p->GetPrev()); + pStk->SetError(CBotErrNoExpression, p->GetStart()); goto error; } if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp index bc6ac28d..559bb9d9 100644 --- a/src/CBot/CBotInstr/CBotListArray.cpp +++ b/src/CBot/CBotInstr/CBotListArray.cpp @@ -61,15 +61,13 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu CBotListArray* inst = new CBotListArray(); - pStk->SetStartError(p->GetStart()); - if (IsOfType( p, ID_OPBLK )) { // each element takes the one after the other if (type.Eq( CBotTypArrayPointer )) { pStk->SetStartError(p->GetStart()); - if ( nullptr == (inst->m_expr = CBotListArray::Compile(p, pStk, type.GetTypElem())) ) + if (nullptr == ( inst->m_expr = CBotListArray::Compile( p, pStk, type.GetTypElem() ) )) { if (pStk->IsOk()) { @@ -81,11 +79,13 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu } } } + while (IsOfType( p, ID_COMMA )) // other elements? { pStk->SetStartError(p->GetStart()); + CBotInstr* i = nullptr; - if ( nullptr == (i = CBotListArray::Compile(p, pStk, type.GetTypElem())) ) + if (nullptr == ( i = CBotListArray::Compile(p, pStk, type.GetTypElem() ) )) { if (pStk->IsOk()) { @@ -97,7 +97,9 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu } } } + inst->m_expr->AddNext3(i); + if ( p->GetType() == ID_COMMA ) continue; if ( p->GetType() == ID_CLBLK ) break; @@ -108,7 +110,6 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu else { pStk->SetStartError(p->GetStart()); - if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk ))) { goto error; @@ -116,7 +117,7 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu CBotVar* pv = pStk->GetVar(); // result of the expression if (pv == nullptr || (!TypesCompatibles( type, pv->GetTypResult()) && - !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer))) ) // compatible type? + !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer)) )) { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; @@ -135,7 +136,7 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu CBotVar* pv = pStk->GetVar(); // result of the expression if (pv == nullptr || (!TypesCompatibles( type, pv->GetTypResult()) && - !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer))) ) // compatible type? + !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer)) )) { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; diff --git a/src/CBot/CBotInstr/CBotListArray.h b/src/CBot/CBotInstr/CBotListArray.h index 329e5877..c5f800b0 100644 --- a/src/CBot/CBotInstr/CBotListArray.h +++ b/src/CBot/CBotInstr/CBotListArray.h @@ -38,7 +38,6 @@ public: * \param p * \param pStack * \param type - * \param classItem * \return */ static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);