Fixed bug with typedef, introduced with extra type qualifier parsing

Caused by overwriting the value of the actual type token being parsed by
any following tokens that were examined or consumed, rather than just
ignoring their values.
This commit is contained in:
Russell Joyce 2020-06-12 15:30:32 +01:00
parent 62969cb0ee
commit 5261facbd7
No known key found for this signature in database
GPG key ID: 3D46BD9018AF7B72
2 changed files with 9 additions and 6 deletions

View file

@ -14,6 +14,9 @@ int volatile static j;
const int x;
long const y;
typedef int MyInt;
MyInt z = 1;
int main(void) {
return 0;
}

12
type.c
View file

@ -421,7 +421,7 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ,
}
/* handle any trailing type qualifiers/storage classes */
enum LexToken FollowToken = LexGetToken(Parser, &LexerValue, false);
enum LexToken FollowToken = LexGetToken(Parser, NULL, false);
while (FollowToken == TokenStaticType || FollowToken == TokenAutoType ||
FollowToken == TokenRegisterType || FollowToken == TokenExternType ||
FollowToken == TokenVolatileType || FollowToken == TokenConstType) {
@ -430,8 +430,8 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ,
else if (FollowToken == TokenVolatileType)
VolatileQualifier = true;
LexGetToken(Parser, &LexerValue, true);
FollowToken = LexGetToken(Parser, &LexerValue, false);
LexGetToken(Parser, NULL, true);
FollowToken = LexGetToken(Parser, NULL, false);
}
if (IsStatic != NULL)
@ -441,7 +441,7 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ,
/* handle signed/unsigned with no trailing type */
if (Token == TokenSignedType || Token == TokenUnsignedType) {
enum LexToken FollowToken = LexGetToken(Parser, &LexerValue, false);
enum LexToken FollowToken = LexGetToken(Parser, NULL, false);
Unsigned = (Token == TokenUnsignedType);
if (FollowToken != TokenIntType && FollowToken != TokenLongType &&
@ -459,9 +459,9 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ,
/* handle long with trailing int by consuming and ignoring the int */
if (Token == TokenLongType) {
enum LexToken FollowToken = LexGetToken(Parser, &LexerValue, false);
enum LexToken FollowToken = LexGetToken(Parser, NULL, false);
if (FollowToken == TokenIntType) {
LexGetToken(Parser, &LexerValue, true);
LexGetToken(Parser, NULL, true);
}
}