mirror of
https://github.com/cc65/cc65.git
synced 2025-01-11 11:30:13 +00:00
Fixed error recovery with preprocessing directives failures.
This commit is contained in:
parent
f8d08b1e1a
commit
251e984ba8
@ -90,12 +90,14 @@ static void PPExprInit (PPExpr* Expr)
|
|||||||
|
|
||||||
|
|
||||||
static void PPErrorSkipLine (void)
|
static void PPErrorSkipLine (void)
|
||||||
/* Skip the remain tokens till the end of the line and set the expression
|
/* Set the expression parser error flag, skip the remain tokens till the end
|
||||||
** parser error flag.
|
** of the line, clear the current and the next tokens.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
SkipTokens (0, 0);
|
|
||||||
PPEvaluationFailed = 1;
|
PPEvaluationFailed = 1;
|
||||||
|
SkipTokens (0, 0);
|
||||||
|
CurTok.Tok = TOK_CEOF;
|
||||||
|
NextTok.Tok = TOK_CEOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -148,6 +150,10 @@ static void PPhiePrimary (PPExpr* Expr)
|
|||||||
Expr->IVal = 0;
|
Expr->IVal = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TOK_CEOF:
|
||||||
|
/* Error recovery */
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Illegal expression in PP mode */
|
/* Illegal expression in PP mode */
|
||||||
PPError ("Preprocessor expression expected");
|
PPError ("Preprocessor expression expected");
|
||||||
@ -252,6 +258,10 @@ void PPhie10 (PPExpr* Expr)
|
|||||||
Expr->IVal = !Expr->IVal;
|
Expr->IVal = !Expr->IVal;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TOK_CEOF:
|
||||||
|
/* Error recovery */
|
||||||
|
break;
|
||||||
|
|
||||||
case TOK_STAR:
|
case TOK_STAR:
|
||||||
case TOK_AND:
|
case TOK_AND:
|
||||||
case TOK_SIZEOF:
|
case TOK_SIZEOF:
|
||||||
@ -286,7 +296,7 @@ static void PPhie_internal (const token_t* Ops, /* List of generators */
|
|||||||
/* Get the right hand side */
|
/* Get the right hand side */
|
||||||
hienext (&Rhs);
|
hienext (&Rhs);
|
||||||
|
|
||||||
if (PPEvaluationEnabled) {
|
if (PPEvaluationEnabled && !PPEvaluationFailed) {
|
||||||
|
|
||||||
/* If either side is unsigned, the result is unsigned */
|
/* If either side is unsigned, the result is unsigned */
|
||||||
Expr->Flags |= Rhs.Flags & PPEXPR_UNSIGNED;
|
Expr->Flags |= Rhs.Flags & PPEXPR_UNSIGNED;
|
||||||
@ -407,7 +417,7 @@ static void PPhie_compare (const token_t* Ops, /* List of generators */
|
|||||||
/* Get the right hand side */
|
/* Get the right hand side */
|
||||||
hienext (&Rhs);
|
hienext (&Rhs);
|
||||||
|
|
||||||
if (PPEvaluationEnabled) {
|
if (PPEvaluationEnabled && !PPEvaluationFailed) {
|
||||||
|
|
||||||
/* If either side is unsigned, the comparison is unsigned */
|
/* If either side is unsigned, the comparison is unsigned */
|
||||||
Expr->Flags |= Rhs.Flags & PPEXPR_UNSIGNED;
|
Expr->Flags |= Rhs.Flags & PPEXPR_UNSIGNED;
|
||||||
@ -501,7 +511,7 @@ static void PPhie7 (PPExpr* Expr)
|
|||||||
PPhie8 (&Rhs);
|
PPhie8 (&Rhs);
|
||||||
|
|
||||||
/* Evaluate */
|
/* Evaluate */
|
||||||
if (PPEvaluationEnabled) {
|
if (PPEvaluationEnabled && !PPEvaluationFailed) {
|
||||||
/* To shift by a negative value is equivalent to shift to the
|
/* To shift by a negative value is equivalent to shift to the
|
||||||
** opposite direction.
|
** opposite direction.
|
||||||
*/
|
*/
|
||||||
@ -761,46 +771,57 @@ static void PPhie1 (PPExpr* Expr)
|
|||||||
|
|
||||||
case TOK_ASSIGN:
|
case TOK_ASSIGN:
|
||||||
PPError ("Token \"=\" is not valid in preprocessor expressions");
|
PPError ("Token \"=\" is not valid in preprocessor expressions");
|
||||||
|
PPErrorSkipLine ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_PLUS_ASSIGN:
|
case TOK_PLUS_ASSIGN:
|
||||||
PPError ("Token \"+=\" is not valid in preprocessor expressions");
|
PPError ("Token \"+=\" is not valid in preprocessor expressions");
|
||||||
|
PPErrorSkipLine ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_MINUS_ASSIGN:
|
case TOK_MINUS_ASSIGN:
|
||||||
PPError ("Token \"-=\" is not valid in preprocessor expressions");
|
PPError ("Token \"-=\" is not valid in preprocessor expressions");
|
||||||
|
PPErrorSkipLine ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_MUL_ASSIGN:
|
case TOK_MUL_ASSIGN:
|
||||||
PPError ("Token \"*=\" is not valid in preprocessor expressions");
|
PPError ("Token \"*=\" is not valid in preprocessor expressions");
|
||||||
|
PPErrorSkipLine ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_DIV_ASSIGN:
|
case TOK_DIV_ASSIGN:
|
||||||
PPError ("Token \"/=\" is not valid in preprocessor expressions");
|
PPError ("Token \"/=\" is not valid in preprocessor expressions");
|
||||||
|
PPErrorSkipLine ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_MOD_ASSIGN:
|
case TOK_MOD_ASSIGN:
|
||||||
PPError ("Token \"%%=\" is not valid in preprocessor expressions");
|
PPError ("Token \"%%=\" is not valid in preprocessor expressions");
|
||||||
|
PPErrorSkipLine ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_SHL_ASSIGN:
|
case TOK_SHL_ASSIGN:
|
||||||
PPError ("Token \"<<=\" is not valid in preprocessor expressions");
|
PPError ("Token \"<<=\" is not valid in preprocessor expressions");
|
||||||
|
PPErrorSkipLine ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_SHR_ASSIGN:
|
case TOK_SHR_ASSIGN:
|
||||||
PPError ("Token \">>=\" is not valid in preprocessor expressions");
|
PPError ("Token \">>=\" is not valid in preprocessor expressions");
|
||||||
|
PPErrorSkipLine ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_AND_ASSIGN:
|
case TOK_AND_ASSIGN:
|
||||||
PPError ("Token \"&=\" is not valid in preprocessor expressions");
|
PPError ("Token \"&=\" is not valid in preprocessor expressions");
|
||||||
|
PPErrorSkipLine ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_OR_ASSIGN:
|
case TOK_OR_ASSIGN:
|
||||||
PPError ("Token \"|=\" is not valid in preprocessor expressions");
|
PPError ("Token \"|=\" is not valid in preprocessor expressions");
|
||||||
|
PPErrorSkipLine ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_XOR_ASSIGN:
|
case TOK_XOR_ASSIGN:
|
||||||
PPError ("Token \"^=\" is not valid in preprocessor expressions");
|
PPError ("Token \"^=\" is not valid in preprocessor expressions");
|
||||||
|
PPErrorSkipLine ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -827,12 +848,13 @@ static void PPhie0 (PPExpr* Expr)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ParsePPExpr (PPExpr* Expr)
|
void ParsePPExprInLine (PPExpr* Expr)
|
||||||
/* Parse a line for PP expression */
|
/* Parse a line for PP expression */
|
||||||
{
|
{
|
||||||
/* Initialize the parser status */
|
/* Initialize the parser status */
|
||||||
PPEvaluationFailed = 0;
|
PPEvaluationFailed = 0;
|
||||||
PPEvaluationEnabled = 1;
|
PPEvaluationEnabled = 1;
|
||||||
|
NextLineDisabled = 1;
|
||||||
|
|
||||||
/* Parse */
|
/* Parse */
|
||||||
PPExprInit (Expr);
|
PPExprInit (Expr);
|
||||||
@ -841,5 +863,9 @@ void ParsePPExpr (PPExpr* Expr)
|
|||||||
/* If the evaluation fails, the result is always zero */
|
/* If the evaluation fails, the result is always zero */
|
||||||
if (PPEvaluationFailed) {
|
if (PPEvaluationFailed) {
|
||||||
Expr->IVal = 0;
|
Expr->IVal = 0;
|
||||||
|
PPEvaluationFailed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Restore parser status */
|
||||||
|
NextLineDisabled = 0;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ struct PPExpr
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ParsePPExpr (PPExpr* Expr);
|
void ParsePPExprInLine (PPExpr* Expr);
|
||||||
/* Parse a line for PP expression */
|
/* Parse a line for PP expression */
|
||||||
|
|
||||||
|
|
||||||
|
@ -1279,7 +1279,7 @@ static int DoIf (int Skip)
|
|||||||
NextToken ();
|
NextToken ();
|
||||||
|
|
||||||
/* Call the expression parser */
|
/* Call the expression parser */
|
||||||
ParsePPExpr (&Expr);
|
ParsePPExprInLine (&Expr);
|
||||||
|
|
||||||
/* Restore input source */
|
/* Restore input source */
|
||||||
MLine = InitLine (MLine);
|
MLine = InitLine (MLine);
|
||||||
|
@ -69,6 +69,7 @@
|
|||||||
|
|
||||||
Token CurTok; /* The current token */
|
Token CurTok; /* The current token */
|
||||||
Token NextTok; /* The next token */
|
Token NextTok; /* The next token */
|
||||||
|
int NextLineDisabled; /* Disabled to read next line */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -188,7 +189,8 @@ static int SkipWhite (void)
|
|||||||
{
|
{
|
||||||
while (1) {
|
while (1) {
|
||||||
while (CurC == '\0') {
|
while (CurC == '\0') {
|
||||||
if (PreprocessNextLine () == 0) {
|
/* If reading next line fails or is forbidden, bail out */
|
||||||
|
if (NextLineDisabled || PreprocessNextLine () == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,6 +210,7 @@ struct Token {
|
|||||||
|
|
||||||
extern Token CurTok; /* The current token */
|
extern Token CurTok; /* The current token */
|
||||||
extern Token NextTok; /* The next token */
|
extern Token NextTok; /* The next token */
|
||||||
|
extern int NextLineDisabled; /* Disabled to read next line */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user