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:
parent
9abf00e2d3
commit
b403e76600
16
c-tests/types.c
Normal file
16
c-tests/types.c
Normal 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
17
type.c
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue