Added handling of trailing type qualifiers/storage classes

Handles situations such as `int volatile x` rather than `volatile int x`
by consuming the keywords as part of the type specifier.
This commit is contained in:
Russell Joyce 2020-06-10 18:21:35 +01:00
parent 9abf00e2d3
commit b403e76600
No known key found for this signature in database
GPG key ID: 3D46BD9018AF7B72
2 changed files with 32 additions and 1 deletions

16
c-tests/types.c Normal file
View file

@ -0,0 +1,16 @@
int a;
unsigned b;
unsigned int c;
long d;
long int e;
unsigned long f;
unsigned long int g;
volatile int i;
int volatile j;
int main(void) {
return 0;
}

17
type.c
View file

@ -405,9 +405,10 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ,
Picoc *pc = Parser->pc;
*Typ = NULL;
/* ignore leading type qualifiers */
ParserCopy(&Before, Parser);
Token = LexGetToken(Parser, &LexerValue, true);
/* handle any leading type qualifiers/storage classes */
while (Token == TokenStaticType || Token == TokenAutoType ||
Token == TokenRegisterType || Token == TokenExternType ||
Token == TokenVolatileType) {
@ -419,6 +420,20 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ,
Token = LexGetToken(Parser, &LexerValue, true);
}
/* handle any trailing type qualifiers/storage classes */
enum LexToken FollowToken = LexGetToken(Parser, &LexerValue, false);
while (FollowToken == TokenStaticType || FollowToken == TokenAutoType ||
FollowToken == TokenRegisterType || FollowToken == TokenExternType ||
FollowToken == TokenVolatileType) {
if (FollowToken == TokenStaticType)
StaticQualifier = true;
else if (FollowToken == TokenVolatileType)
VolatileQualifier = true;
LexGetToken(Parser, &LexerValue, true);
FollowToken = LexGetToken(Parser, &LexerValue, false);
}
if (IsStatic != NULL)
*IsStatic = StaticQualifier;
if (IsVolatile != NULL)