diff --git a/c-tests/types.c b/c-tests/types.c new file mode 100644 index 0000000..93f7463 --- /dev/null +++ b/c-tests/types.c @@ -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; +} diff --git a/type.c b/type.c index 7a61a06..3a1f926 100644 --- a/type.c +++ b/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)