Fixed arrays of dynamic arrays causing a compilation error.

This commit is contained in:
Chronos Ouroboros 2019-03-13 07:27:28 -03:00 committed by Christoph Oelckers
parent 04bf975796
commit 8dea4f9523

View file

@ -7343,6 +7343,10 @@ FxExpression *FxArrayElement::Resolve(FCompileContext &ctx)
auto parentfield = static_cast<FxMemberBase *>(Array)->membervar;
SizeAddr = parentfield->Offset + sizeof(void*);
}
else if (Array->ExprType == EFX_ArrayElement)
{
SizeAddr = ~0u;
}
else
{
ScriptPosition.Message(MSG_ERROR, "Invalid resizable array");
@ -7415,6 +7419,7 @@ ExpEmit FxArrayElement::Emit(VMFunctionBuilder *build)
ExpEmit arrayvar = Array->Emit(build);
ExpEmit start;
ExpEmit bound;
bool nestedarray = false;
if (SizeAddr != ~0u)
{
@ -7441,15 +7446,28 @@ ExpEmit FxArrayElement::Emit(VMFunctionBuilder *build)
arraymemberbase->AddressRequested = origaddrreq;
Array->ValueType = origvaluetype;
}
else if (Array->ExprType == EFX_ArrayElement && Array->isStaticArray())
{
bool ismeta = Array->ExprType == EFX_ClassMember && static_cast<FxClassMember*>(Array)->membervar->Flags & VARF_Meta;
arrayvar.Free(build);
start = ExpEmit(build, REGT_POINTER);
build->Emit(OP_LP, start.RegNum, arrayvar.RegNum, build->GetConstantInt(0));
bound = ExpEmit(build, REGT_INT);
build->Emit(OP_LW, bound.RegNum, arrayvar.RegNum, build->GetConstantInt(sizeof(void*)));
nestedarray = true;
}
else start = arrayvar;
if (index->isConstant())
{
unsigned indexval = static_cast<FxConstant *>(index)->GetValue().GetInt();
assert(SizeAddr != ~0u || (indexval < arraytype->ElementCount && "Array index out of bounds"));
assert(SizeAddr != ~0u || nestedarray || (indexval < arraytype->ElementCount && "Array index out of bounds"));
// For resizable arrays we even need to check the bounds if if the index is constant because they are not known at compile time.
if (SizeAddr != ~0u)
if (SizeAddr != ~0u || nestedarray)
{
ExpEmit indexreg(build, REGT_INT);
build->EmitLoadInt(indexreg.RegNum, indexval);