Fixed regression in array initialisers with trailing commas.

git-svn-id: http://picoc.googlecode.com/svn/trunk@579 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2012-09-06 12:07:57 +00:00
parent 83de73dc45
commit 29d15395ba
2 changed files with 19 additions and 12 deletions

28
parse.c
View file

@ -181,8 +181,8 @@ struct Value *ParseFunctionDefinition(struct ParseState *Parser, struct ValueTyp
/* parse an array initialiser and assign to a variable */
int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable, int DoAssignment)
{
int ArrayIndex;
enum LexToken Token = TokenComma;
int ArrayIndex = 0;
enum LexToken Token;
struct Value *CValue;
/* count the number of elements in the array */
@ -201,13 +201,11 @@ int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable,
}
/* parse the array initialiser */
for (ArrayIndex = 0; Token == TokenComma; ArrayIndex++)
Token = LexGetToken(Parser, NULL, FALSE);
while (Token != TokenRightBrace)
{
struct Value *ArrayElement = NULL;
if (Token != TokenComma)
ProgramFail(Parser, "comma expected");
if (Parser->Mode == RunModeRun && DoAssignment)
ArrayElement = VariableAllocValueFromExistingData(Parser, NewVariable->Typ->FromType, (union AnyValue *)(&NewVariable->Val->ArrayMem[0] + TypeSize(NewVariable->Typ->FromType, 0, TRUE) * ArrayIndex), TRUE, NewVariable);
@ -221,13 +219,21 @@ int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable,
VariableStackPop(Parser, ArrayElement);
}
Token = LexGetToken(Parser, NULL, TRUE);
ArrayIndex++;
Token = LexGetToken(Parser, NULL, FALSE);
if (Token == TokenComma)
{
LexGetToken(Parser, NULL, TRUE);
Token = LexGetToken(Parser, NULL, FALSE);
}
else if (Token != TokenRightBrace)
ProgramFail(Parser, "comma expected");
}
if (Token == TokenComma)
Token = LexGetToken(Parser, NULL, TRUE);
if (Token != TokenRightBrace)
if (Token == TokenRightBrace)
LexGetToken(Parser, NULL, TRUE);
else
ProgramFail(Parser, "'}' expected");
return ArrayIndex;

View file

@ -48,7 +48,8 @@ TESTS= 00_assignment.test \
50_logical_second_arg.test \
51_static.test \
52_unnamed_enum.test \
54_goto.test
54_goto.test \
55_array_initialiser.test
%.test: %.expect %.c
@echo Test: $*...