Fixes the order of declaration of array bounds - they were previously reversed.

git-svn-id: http://picoc.googlecode.com/svn/trunk@524 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2011-02-14 22:53:10 +00:00
parent b2c4d6ce83
commit ea6f2c006a

62
type.c
View file

@ -385,6 +385,36 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ)
return TRUE; return TRUE;
} }
/* parse a type - the part at the end after the identifier. eg. array specifications etc. */
struct ValueType *TypeParseBack(struct ParseState *Parser, struct ValueType *FromType)
{
enum LexToken Token;
struct ParseState Before;
ParserCopy(&Before, Parser);
Token = LexGetToken(Parser, NULL, TRUE);
if (Token == TokenLeftSquareBracket)
{
/* add another array bound */
enum RunMode OldMode = Parser->Mode;
int ArraySize;
Parser->Mode = RunModeRun;
ArraySize = ExpressionParseInt(Parser);
Parser->Mode = OldMode;
if (LexGetToken(Parser, NULL, TRUE) != TokenRightSquareBracket)
ProgramFail(Parser, "']' expected");
return TypeGetMatching(Parser, TypeParseBack(Parser, FromType), TypeArray, ArraySize, StrEmpty);
}
else
{
/* the type specification has finished */
ParserCopy(Parser, &Before);
return FromType;
}
}
/* parse a type - the part which is repeated with each identifier in a declaration list */ /* parse a type - the part which is repeated with each identifier in a declaration list */
void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, struct ValueType **Typ, char **Identifier) void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, struct ValueType **Typ, char **Identifier)
{ {
@ -435,36 +465,8 @@ void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, s
if (*Identifier != StrEmpty) if (*Identifier != StrEmpty)
{ {
/* parse stuff after the identifier */ /* parse stuff after the identifier */
Done = FALSE; *Typ = TypeParseBack(Parser, *Typ);
while (!Done) }
{
Before = *Parser;
switch (LexGetToken(Parser, NULL, TRUE))
{
case TokenLeftSquareBracket:
{
enum RunMode OldMode = Parser->Mode;
int ArraySize;
Parser->Mode = RunModeRun;
ArraySize = ExpressionParseInt(Parser);
Parser->Mode = OldMode;
if (LexGetToken(Parser, NULL, TRUE) != TokenRightSquareBracket)
ProgramFail(Parser, "']' expected");
*Typ = TypeGetMatching(Parser, *Typ, TypeArray, ArraySize, StrEmpty);
}
break;
#if 0
case TokenOpenBracket:
break; /* XXX - finish this */
#endif
default: ParserCopy(Parser, &Before); Done = TRUE; break;
}
}
}
} }
/* parse a type - a complete declaration including identifier */ /* parse a type - a complete declaration including identifier */