Commit 245391da by Richard Kenner

(skip_evaluation): New variable.

(&&, ||, ?:): Increment it in unevaluated subexpressions.
(/, %, integer_overflow): Suppress diagnostics if skip_evaluation != 0.
(yyerror): Clear skip_evaluation.

From-SVN: r9914
parent 17856c49
...@@ -86,6 +86,10 @@ static jmp_buf parse_return_error; ...@@ -86,6 +86,10 @@ static jmp_buf parse_return_error;
/* Nonzero means count most punctuation as part of a name. */ /* Nonzero means count most punctuation as part of a name. */
static int keyword_parsing = 0; static int keyword_parsing = 0;
/* Nonzero means do not evaluate this expression.
This is a count, since unevaluated expressions can nest. */
static int skip_evaluation;
/* some external tables of character types */ /* some external tables of character types */
extern unsigned char is_idstart[], is_idchar[], is_hor_space[]; extern unsigned char is_idstart[], is_idchar[], is_hor_space[];
...@@ -225,7 +229,8 @@ exp : exp '*' exp ...@@ -225,7 +229,8 @@ exp : exp '*' exp
| exp '/' exp | exp '/' exp
{ if ($3.value == 0) { if ($3.value == 0)
{ {
error ("division by zero in #if"); if (!skip_evaluation)
error ("division by zero in #if");
$3.value = 1; $3.value = 1;
} }
$$.unsignedp = $1.unsignedp || $3.unsignedp; $$.unsignedp = $1.unsignedp || $3.unsignedp;
...@@ -240,7 +245,8 @@ exp : exp '*' exp ...@@ -240,7 +245,8 @@ exp : exp '*' exp
| exp '%' exp | exp '%' exp
{ if ($3.value == 0) { if ($3.value == 0)
{ {
error ("division by zero in #if"); if (!skip_evaluation)
error ("division by zero in #if");
$3.value = 1; $3.value = 1;
} }
$$.unsignedp = $1.unsignedp || $3.unsignedp; $$.unsignedp = $1.unsignedp || $3.unsignedp;
...@@ -313,15 +319,26 @@ exp : exp '*' exp ...@@ -313,15 +319,26 @@ exp : exp '*' exp
| exp '|' exp | exp '|' exp
{ $$.value = $1.value | $3.value; { $$.value = $1.value | $3.value;
$$.unsignedp = $1.unsignedp || $3.unsignedp; } $$.unsignedp = $1.unsignedp || $3.unsignedp; }
| exp AND exp | exp AND
{ $$.value = ($1.value && $3.value); { skip_evaluation += !$1.value; }
exp
{ skip_evaluation -= !$1.value;
$$.value = ($1.value && $4.value);
$$.unsignedp = 0; } $$.unsignedp = 0; }
| exp OR exp | exp OR
{ $$.value = ($1.value || $3.value); { skip_evaluation += !!$1.value; }
exp
{ skip_evaluation -= !!$1.value;
$$.value = ($1.value || $4.value);
$$.unsignedp = 0; } $$.unsignedp = 0; }
| exp '?' exp ':' exp | exp '?'
{ $$.value = $1.value ? $3.value : $5.value; { skip_evaluation += !$1.value; }
$$.unsignedp = $3.unsignedp || $5.unsignedp; } exp ':'
{ skip_evaluation += !!$1.value - !$1.value; }
exp
{ skip_evaluation -= !!$1.value;
$$.value = $1.value ? $4.value : $7.value;
$$.unsignedp = $4.unsignedp || $7.unsignedp; }
| INT | INT
{ $$ = yylval.integer; } { $$ = yylval.integer; }
| CHAR | CHAR
...@@ -865,13 +882,14 @@ yyerror (s) ...@@ -865,13 +882,14 @@ yyerror (s)
char *s; char *s;
{ {
error (s); error (s);
skip_evaluation = 0;
longjmp (parse_return_error, 1); longjmp (parse_return_error, 1);
} }
static void static void
integer_overflow () integer_overflow ()
{ {
if (pedantic) if (!skip_evaluation && pedantic)
pedwarn ("integer overflow in preprocessor expression"); pedwarn ("integer overflow in preprocessor expression");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment