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;
|
unsigned long int g;
|
||||||
|
|
||||||
volatile int i;
|
volatile int i;
|
||||||
int volatile j;
|
int volatile static j;
|
||||||
|
|
||||||
|
const int x;
|
||||||
|
long const y;
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -177,7 +177,8 @@ enum LexToken {
|
||||||
TokenBackSlash,
|
TokenBackSlash,
|
||||||
TokenVolatileType,
|
TokenVolatileType,
|
||||||
TokenHashPragma,
|
TokenHashPragma,
|
||||||
TokenUnderscorePragma
|
TokenUnderscorePragma,
|
||||||
|
TokenConstType
|
||||||
};
|
};
|
||||||
|
|
||||||
/* used in dynamic memory allocation */
|
/* used in dynamic memory allocation */
|
||||||
|
|
5
lex.c
5
lex.c
|
@ -96,7 +96,8 @@ static struct ReservedWord ReservedWords[] = {
|
||||||
{"while", TokenWhile},
|
{"while", TokenWhile},
|
||||||
{"volatile", TokenVolatileType},
|
{"volatile", TokenVolatileType},
|
||||||
{"#pragma", TokenHashPragma},
|
{"#pragma", TokenHashPragma},
|
||||||
{"_Pragma", TokenUnderscorePragma}
|
{"_Pragma", TokenUnderscorePragma},
|
||||||
|
{"const", TokenConstType}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -851,7 +852,7 @@ enum LexToken LexGetRawToken(struct ParseState *Parser, struct Value **Value,
|
||||||
#ifdef DEBUG_LEXER
|
#ifdef DEBUG_LEXER
|
||||||
printf("Got token=%02x inc=%d pos=%d\n", Token, IncPos, Parser->CharacterPos);
|
printf("Got token=%02x inc=%d pos=%d\n", Token, IncPos, Parser->CharacterPos);
|
||||||
#endif
|
#endif
|
||||||
assert(Token >= TokenNone && Token <= TokenUnderscorePragma);
|
assert(Token >= TokenNone && Token <= TokenConstType);
|
||||||
return Token;
|
return Token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
parse.c
1
parse.c
|
@ -748,6 +748,7 @@ enum ParseResult ParseStatement(struct ParseState *Parser,
|
||||||
case TokenRegisterType:
|
case TokenRegisterType:
|
||||||
case TokenExternType:
|
case TokenExternType:
|
||||||
case TokenVolatileType:
|
case TokenVolatileType:
|
||||||
|
case TokenConstType:
|
||||||
*Parser = PreState;
|
*Parser = PreState;
|
||||||
CheckTrailingSemicolon = ParseDeclaration(Parser, Token);
|
CheckTrailingSemicolon = ParseDeclaration(Parser, Token);
|
||||||
break;
|
break;
|
||||||
|
|
3
stats.c
3
stats.c
|
@ -114,7 +114,8 @@ struct LexTokenStat LexTokenStats[NO_TOKENS] = {
|
||||||
{"TokenBackSlash", {0, 0, 0, 0, 0, 0, 0}},
|
{"TokenBackSlash", {0, 0, 0, 0, 0, 0, 0}},
|
||||||
{"TokenVolatileType", {0, 0, 0, 0, 0, 0, 0}},
|
{"TokenVolatileType", {0, 0, 0, 0, 0, 0, 0}},
|
||||||
{"TokenHashPragma", {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"
|
#include "interpreter.h"
|
||||||
|
|
||||||
#define NO_RUN_MODES 7
|
#define NO_RUN_MODES 7
|
||||||
#define NO_TOKENS 100
|
#define NO_TOKENS 101
|
||||||
|
|
||||||
extern const char *RunModeNames[NO_RUN_MODES];
|
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 */
|
/* handle any leading type qualifiers/storage classes */
|
||||||
while (Token == TokenStaticType || Token == TokenAutoType ||
|
while (Token == TokenStaticType || Token == TokenAutoType ||
|
||||||
Token == TokenRegisterType || Token == TokenExternType ||
|
Token == TokenRegisterType || Token == TokenExternType ||
|
||||||
Token == TokenVolatileType) {
|
Token == TokenVolatileType || Token == TokenConstType) {
|
||||||
if (Token == TokenStaticType)
|
if (Token == TokenStaticType)
|
||||||
StaticQualifier = true;
|
StaticQualifier = true;
|
||||||
else if (Token == TokenVolatileType)
|
else if (Token == TokenVolatileType)
|
||||||
|
@ -424,7 +424,7 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ,
|
||||||
enum LexToken FollowToken = LexGetToken(Parser, &LexerValue, false);
|
enum LexToken FollowToken = LexGetToken(Parser, &LexerValue, false);
|
||||||
while (FollowToken == TokenStaticType || FollowToken == TokenAutoType ||
|
while (FollowToken == TokenStaticType || FollowToken == TokenAutoType ||
|
||||||
FollowToken == TokenRegisterType || FollowToken == TokenExternType ||
|
FollowToken == TokenRegisterType || FollowToken == TokenExternType ||
|
||||||
FollowToken == TokenVolatileType) {
|
FollowToken == TokenVolatileType || FollowToken == TokenConstType) {
|
||||||
if (FollowToken == TokenStaticType)
|
if (FollowToken == TokenStaticType)
|
||||||
StaticQualifier = true;
|
StaticQualifier = true;
|
||||||
else if (FollowToken == TokenVolatileType)
|
else if (FollowToken == TokenVolatileType)
|
||||||
|
|
Loading…
Reference in a new issue