recover from errors in bool expressions (ie, don't segfault)

This commit is contained in:
Bill Currie 2003-10-24 22:23:56 +00:00
parent 8e030089a7
commit 58d0f188f1
2 changed files with 41 additions and 20 deletions

View file

@ -1514,10 +1514,14 @@ convert_bool (expr_t *e, int block)
if (e->type == ex_uexpr && e->e.expr.op == '!') {
e = convert_bool (e->e.expr.e1, 0);
if (e->type == ex_error)
return e;
e = unary_expr ('!', e);
}
if (e->type != ex_bool) {
e = test_expr (e, 1);
if (e->type == ex_error)
return e;
if (e->type == ex_integer) {
e = new_unary_expr ('g', 0);
if (e->e.integer_val)
@ -1578,7 +1582,12 @@ bool_expr (int op, expr_t *label, expr_t *e1, expr_t *e2)
return binary_expr (op, e1, e2);
e1 = convert_bool (e1, 0);
if (e1->type == ex_error)
return e1;
e2 = convert_bool (e2, 0);
if (e2->type == ex_error)
return e2;
block = new_block_expr ();
append_expr (block, e1);
@ -2375,6 +2384,8 @@ conditional_expr (expr_t *cond, expr_t *e1, expr_t *e2)
return e2;
cond = convert_bool (cond, 1);
if (cond->type == ex_error)
return cond;
backpatch (cond->e.bool.true_list, tlabel);
backpatch (cond->e.bool.false_list, flabel);

View file

@ -671,10 +671,12 @@ statement
append_expr ($$, continue_label);
$5 = convert_bool ($5, 1);
if ($5->type != ex_error) {
backpatch ($5->e.bool.true_list, l1);
backpatch ($5->e.bool.false_list, l2);
append_expr ($5->e.bool.e, l2);
append_expr ($$, $5);
}
break_label = $2;
continue_label = $3;
@ -698,10 +700,12 @@ statement
append_expr ($$, continue_label);
$7 = convert_bool ($7, 1);
if ($7->type != ex_error) {
backpatch ($7->e.bool.true_list, l1);
backpatch ($7->e.bool.false_list, break_label);
append_expr ($7->e.bool.e, break_label);
append_expr ($$, $7);
}
break_label = $2;
continue_label = $3;
@ -736,10 +740,12 @@ statement
free_local_inits ($5);
$3 = convert_bool ($3, 1);
if ($3->type != ex_error) {
backpatch ($3->e.bool.true_list, tl);
backpatch ($3->e.bool.false_list, fl);
append_expr ($3->e.bool.e, tl);
append_expr ($$, $3);
}
append_expr ($$, $6);
append_expr ($$, fl);
@ -774,10 +780,12 @@ statement
free_local_inits ($5);
$3 = convert_bool ($3, 1);
if ($3->type != ex_error) {
backpatch ($3->e.bool.true_list, tl);
backpatch ($3->e.bool.false_list, fl);
append_expr ($3->e.bool.e, tl);
append_expr ($$, $3);
}
append_expr ($$, $6);
@ -826,10 +834,12 @@ statement
if ($7) {
append_expr ($$, l1);
$7 = convert_bool ($7, 1);
if ($7->type != ex_error) {
backpatch ($7->e.bool.true_list, tl);
backpatch ($7->e.bool.false_list, fl);
append_expr ($7->e.bool.e, fl);
append_expr ($$, $7);
}
} else {
append_expr ($$, fl);
}