1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-23 04:30:10 +00:00

Fixed the bug that C keywords were not simply recognized as identifiers in preprocessing.

This commit is contained in:
acqn 2022-08-07 16:14:45 +08:00
parent 7a139a800e
commit 4bb4f033ea
3 changed files with 21 additions and 10 deletions

View File

@ -215,6 +215,12 @@ static void PPhie11 (PPExpr* Expr)
}
}
/* Check for excessive expressions */
if (!TokIsPunc (&CurTok)) {
PPError ("Missing binary operator");
PPErrorSkipLine ();
}
}
@ -854,7 +860,7 @@ void ParsePPExprInLine (PPExpr* Expr)
/* Initialize the parser status */
PPEvaluationFailed = 0;
PPEvaluationEnabled = 1;
NextLineDisabled = 1;
PPParserRunning = 1;
/* Parse */
PPExprInit (Expr);
@ -867,5 +873,5 @@ void ParsePPExprInLine (PPExpr* Expr)
}
/* Restore parser status */
NextLineDisabled = 0;
PPParserRunning = 0;
}

View File

@ -69,7 +69,7 @@
Token CurTok; /* The current token */
Token NextTok; /* The next token */
int NextLineDisabled; /* Disabled to read next line */
int PPParserRunning; /* Is tokenizer used by the preprocessor */
@ -189,8 +189,10 @@ static int SkipWhite (void)
{
while (1) {
while (CurC == '\0') {
/* If reading next line fails or is forbidden, bail out */
if (NextLineDisabled || PreprocessNextLine () == 0) {
/* If reading next line fails or is disabled with directives, bail
** out.
*/
if (PPParserRunning || PreprocessNextLine () == 0) {
return 0;
}
}
@ -759,11 +761,14 @@ void NextToken (void)
/* Check for keywords and identifiers */
if (IsSym (token)) {
/* Check for a keyword */
if ((NextTok.Tok = FindKey (token)) != TOK_IDENT) {
/* Reserved word found */
return;
if (!PPParserRunning) {
/* Check for a keyword */
if ((NextTok.Tok = FindKey (token)) != TOK_IDENT) {
/* Reserved word found */
return;
}
}
/* No reserved word, check for special symbols */
if (token[0] == '_' && token[1] == '_') {
/* Special symbols */

View File

@ -220,7 +220,7 @@ struct Token {
extern Token CurTok; /* The current token */
extern Token NextTok; /* The next token */
extern int NextLineDisabled; /* Disabled to read next line */
extern int PPParserRunning; /* Is tokenizer used by the preprocessor */