Fixed problem with using array index operator on pointers. Issue #61.
git-svn-id: http://picoc.googlecode.com/svn/trunk@367 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
be2ba2cb5f
commit
e44aca659f
15
expression.c
15
expression.c
|
@ -657,20 +657,19 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack *
|
|||
int ArrayIndex;
|
||||
struct Value *Result;
|
||||
|
||||
if (BottomValue->Typ->Base != TypeArray)
|
||||
ProgramFail(Parser, "this %t is not an array", BottomValue->Typ);
|
||||
|
||||
if (!IS_NUMERIC_COERCIBLE(TopValue))
|
||||
ProgramFail(Parser, "array index must be an integer");
|
||||
|
||||
ArrayIndex = ExpressionCoerceInteger(TopValue);
|
||||
#ifndef NATIVE_POINTERS
|
||||
if (ArrayIndex < 0 || ArrayIndex >= BottomValue->Val->Array.Size)
|
||||
ProgramFail(Parser, "illegal array index %d [0..%d]", ArrayIndex, BottomValue->Val->Array.Size-1);
|
||||
#endif
|
||||
|
||||
/* make the array element result */
|
||||
Result = VariableAllocValueFromExistingData(Parser, BottomValue->Typ->FromType, (union AnyValue *)((char *)BottomValue->Val->Array.Data + TypeSize(BottomValue->Typ->FromType, 0, TRUE) * ArrayIndex), BottomValue->IsLValue, BottomValue->LValueFrom);
|
||||
switch (BottomValue->Typ->Base)
|
||||
{
|
||||
case TypeArray: Result = VariableAllocValueFromExistingData(Parser, BottomValue->Typ->FromType, (union AnyValue *)((char *)BottomValue->Val->Array.Data + TypeSize(BottomValue->Typ->FromType, 0, TRUE) * ArrayIndex), BottomValue->IsLValue, BottomValue->LValueFrom); break;
|
||||
case TypePointer: Result = VariableAllocValueFromExistingData(Parser, BottomValue->Typ->FromType, (union AnyValue *)((char *)BottomValue->Val->NativePointer + TypeSize(BottomValue->Typ->FromType, 0, TRUE) * ArrayIndex), BottomValue->IsLValue, BottomValue->LValueFrom); break;
|
||||
default: ProgramFail(Parser, "this %t is not an array", BottomValue->Typ);
|
||||
}
|
||||
|
||||
ExpressionStackPushValueNode(Parser, StackTop, Result);
|
||||
}
|
||||
#ifndef NO_FP
|
||||
|
|
Loading…
Reference in a new issue