Fix array[] parameters in functions

This commit is contained in:
drmortalwombat 2021-11-04 08:29:54 +01:00
parent a3d8c94620
commit 180da3de4a
2 changed files with 15 additions and 4 deletions

View File

@ -1634,12 +1634,16 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
vl = Dereference(proc, block, vl);
if (!vl.mType->IsNumericType())
mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Not a numeric type");
else if (vl.mType->mType == DT_TYPE_INTEGER && vl.mType->mSize < 2)
vl = CoerceType(proc, block, vl, TheSignedIntTypeDeclaration);
ins->mOperator = IA_NEG;
break;
case TK_BINARY_NOT:
vl = Dereference(proc, block, vl);
if (!(vl.mType->mType == DT_TYPE_POINTER || vl.mType->IsNumericType()))
mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Not a numeric or pointer type");
else if (vl.mType->mType == DT_TYPE_INTEGER && vl.mType->mSize < 2)
vl = CoerceType(proc, block, vl, TheUnsignedIntTypeDeclaration);
ins->mOperator = IA_NOT;
break;
case TK_MUL:

View File

@ -431,16 +431,23 @@ Declaration* Parser::ParsePostfixDeclaration(void)
}
else
{
if (!(adec->mBase->mFlags & DTF_DEFINED))
if (!(adec->mBase->mFlags & DTF_DEFINED) && adec->mBase->mType != DT_TYPE_ARRAY)
mErrors->Error(adec->mLocation, EERR_UNDEFINED_OBJECT, "Type of argument not defined");
adec->mType = DT_ARGUMENT;
adec->mVarIndex = vi;
adec->mOffset = 0;
if (adec->mBase->mType == DT_TYPE_ARRAY)
adec->mSize = 2;
else
adec->mSize = adec->mBase->mSize;
{
Declaration * ndec = new Declaration(adec->mBase->mLocation, DT_TYPE_POINTER);
ndec->mBase = adec->mBase->mBase;
ndec->mSize = 2;
ndec->mFlags |= DTF_DEFINED;
adec->mBase = ndec;
}
adec->mSize = adec->mBase->mSize;
vi += adec->mSize;
if (pdec)
pdec->mNext = adec;