Fix class.arrays using size of one before comma
parent
6be1f56288
commit
8b7410f803
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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 )))
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 )))
|
||||
|
|
|
@ -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 )))
|
||||
|
|
|
@ -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 )))
|
||||
|
|
|
@ -61,8 +61,6 @@ 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
|
||||
|
@ -81,9 +79,11 @@ 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() ) ))
|
||||
{
|
||||
|
@ -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;
|
||||
|
|
|
@ -38,7 +38,6 @@ public:
|
|||
* \param p
|
||||
* \param pStack
|
||||
* \param type
|
||||
* \param classItem
|
||||
* \return
|
||||
*/
|
||||
static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type);
|
||||
|
|
Loading…
Reference in New Issue