Fixed a bug in multiple dimension array access (issue #80)
Added a test for this git-svn-id: http://picoc.googlecode.com/svn/trunk@419 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
54ad31d6d3
commit
fa3e9a1187
|
@ -603,7 +603,7 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack *
|
||||||
/* make the array element result */
|
/* make the array element result */
|
||||||
switch (BottomValue->Typ->Base)
|
switch (BottomValue->Typ->Base)
|
||||||
{
|
{
|
||||||
case TypeArray: Result = VariableAllocValueFromExistingData(Parser, BottomValue->Typ->FromType, (union AnyValue *)(&BottomValue->Val->ArrayMem[0] + TypeSize(BottomValue->Typ->FromType, 0, TRUE) * ArrayIndex), BottomValue->IsLValue, BottomValue->LValueFrom); break;
|
case TypeArray: Result = VariableAllocValueFromExistingData(Parser, BottomValue->Typ->FromType, (union AnyValue *)(&BottomValue->Val->ArrayMem[0] + TypeSize(BottomValue->Typ, ArrayIndex, TRUE)), 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;
|
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);
|
default: ProgramFail(Parser, "this %t is not an array", BottomValue->Typ);
|
||||||
}
|
}
|
||||||
|
|
25
tests/38_multiple_array_index.c
Normal file
25
tests/38_multiple_array_index.c
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
int a[4][4];
|
||||||
|
int b = 0;
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
|
||||||
|
for (x = 0; x < 4; x++)
|
||||||
|
{
|
||||||
|
for (y = 0; y < 4; y++)
|
||||||
|
{
|
||||||
|
b++;
|
||||||
|
a[x][y] = b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (x = 0; x < 4; x++)
|
||||||
|
{
|
||||||
|
printf("x=%d: ", x);
|
||||||
|
for (y = 0; y < 4; y++)
|
||||||
|
{
|
||||||
|
printf("%d ", a[x][y]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
4
tests/38_multiple_array_index.expect
Normal file
4
tests/38_multiple_array_index.expect
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
x=0: 1 2 3 4
|
||||||
|
x=1: 5 6 7 8
|
||||||
|
x=2: 9 10 11 12
|
||||||
|
x=3: 13 14 15 16
|
|
@ -30,7 +30,8 @@ TESTS= 00_assignment.test \
|
||||||
34_array_assignment.test \
|
34_array_assignment.test \
|
||||||
35_sizeof.test \
|
35_sizeof.test \
|
||||||
36_array_initialisers.test \
|
36_array_initialisers.test \
|
||||||
37_sprintf.test
|
37_sprintf.test \
|
||||||
|
38_multiple_array_index.test
|
||||||
|
|
||||||
%.test: %.expect %.c
|
%.test: %.expect %.c
|
||||||
@echo Test: $*...
|
@echo Test: $*...
|
||||||
|
|
Loading…
Reference in a new issue