Added handling of 'const' type qualifier keyword
There is currently no enforcement of a variable being constant, and the actual type is the same as if 'const' wasn't present.
This commit is contained in:
parent
9fd31b6d37
commit
62969cb0ee
|
@ -9,7 +9,10 @@ unsigned long f;
|
|||
unsigned long int g;
|
||||
|
||||
volatile int i;
|
||||
int volatile j;
|
||||
int volatile static j;
|
||||
|
||||
const int x;
|
||||
long const y;
|
||||
|
||||
int main(void) {
|
||||
return 0;
|
||||
|
|
|
@ -177,7 +177,8 @@ enum LexToken {
|
|||
TokenBackSlash,
|
||||
TokenVolatileType,
|
||||
TokenHashPragma,
|
||||
TokenUnderscorePragma
|
||||
TokenUnderscorePragma,
|
||||
TokenConstType
|
||||
};
|
||||
|
||||
/* used in dynamic memory allocation */
|
||||
|
|
5
lex.c
5
lex.c
|
@ -96,7 +96,8 @@ static struct ReservedWord ReservedWords[] = {
|
|||
{"while", TokenWhile},
|
||||
{"volatile", TokenVolatileType},
|
||||
{"#pragma", TokenHashPragma},
|
||||
{"_Pragma", TokenUnderscorePragma}
|
||||
{"_Pragma", TokenUnderscorePragma},
|
||||
{"const", TokenConstType}
|
||||
};
|
||||
|
||||
|
||||
|
@ -851,7 +852,7 @@ enum LexToken LexGetRawToken(struct ParseState *Parser, struct Value **Value,
|
|||
#ifdef DEBUG_LEXER
|
||||
printf("Got token=%02x inc=%d pos=%d\n", Token, IncPos, Parser->CharacterPos);
|
||||
#endif
|
||||
assert(Token >= TokenNone && Token <= TokenUnderscorePragma);
|
||||
assert(Token >= TokenNone && Token <= TokenConstType);
|
||||
return Token;
|
||||
}
|
||||
|
||||
|
|
1
parse.c
1
parse.c
|
@ -748,6 +748,7 @@ enum ParseResult ParseStatement(struct ParseState *Parser,
|
|||
case TokenRegisterType:
|
||||
case TokenExternType:
|
||||
case TokenVolatileType:
|
||||
case TokenConstType:
|
||||
*Parser = PreState;
|
||||
CheckTrailingSemicolon = ParseDeclaration(Parser, Token);
|
||||
break;
|
||||
|
|
3
stats.c
3
stats.c
|
@ -114,7 +114,8 @@ struct LexTokenStat LexTokenStats[NO_TOKENS] = {
|
|||
{"TokenBackSlash", {0, 0, 0, 0, 0, 0, 0}},
|
||||
{"TokenVolatileType", {0, 0, 0, 0, 0, 0, 0}},
|
||||
{"TokenHashPragma", {0, 0, 0, 0, 0, 0, 0}},
|
||||
{"TokenUnderscorePragma", {0, 0, 0, 0, 0, 0, 0}}
|
||||
{"TokenUnderscorePragma", {0, 0, 0, 0, 0, 0, 0}},
|
||||
{"TokenConstType", {0, 0, 0, 0, 0, 0, 0}}
|
||||
};
|
||||
|
||||
|
||||
|
|
2
stats.h
2
stats.h
|
@ -8,7 +8,7 @@
|
|||
#include "interpreter.h"
|
||||
|
||||
#define NO_RUN_MODES 7
|
||||
#define NO_TOKENS 100
|
||||
#define NO_TOKENS 101
|
||||
|
||||
extern const char *RunModeNames[NO_RUN_MODES];
|
||||
|
||||
|
|
4
type.c
4
type.c
|
@ -411,7 +411,7 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ,
|
|||
/* handle any leading type qualifiers/storage classes */
|
||||
while (Token == TokenStaticType || Token == TokenAutoType ||
|
||||
Token == TokenRegisterType || Token == TokenExternType ||
|
||||
Token == TokenVolatileType) {
|
||||
Token == TokenVolatileType || Token == TokenConstType) {
|
||||
if (Token == TokenStaticType)
|
||||
StaticQualifier = true;
|
||||
else if (Token == TokenVolatileType)
|
||||
|
@ -424,7 +424,7 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ,
|
|||
enum LexToken FollowToken = LexGetToken(Parser, &LexerValue, false);
|
||||
while (FollowToken == TokenStaticType || FollowToken == TokenAutoType ||
|
||||
FollowToken == TokenRegisterType || FollowToken == TokenExternType ||
|
||||
FollowToken == TokenVolatileType) {
|
||||
FollowToken == TokenVolatileType || FollowToken == TokenConstType) {
|
||||
if (FollowToken == TokenStaticType)
|
||||
StaticQualifier = true;
|
||||
else if (FollowToken == TokenVolatileType)
|
||||
|
|
Loading…
Reference in a new issue