be more forgiving with || and && in #if expressions

This commit is contained in:
David Rose 2003-01-21 19:29:31 +00:00
parent 570deb3822
commit 3496d7fedc
1 changed files with 17 additions and 0 deletions

View File

@ -463,6 +463,23 @@ evaluate() const {
assert(_u._op._op1 != NULL);
r1 = _u._op._op1->evaluate();
if (r1._type == RT_error) {
// Here's one more special case: if the first operand is
// invalid, it really means we don't know how to evaluate it.
// However, if the operator is ||, then it might not matter as
// long as we can evaluate the second one *and* that comes out
// to be true.
if (_u._op._operator == OROR && r2._type == RT_integer &&
r2.as_integer() != 0) {
return r2;
}
// Ditto for the operator being && and the second one coming out
// false.
if (_u._op._operator == ANDAND && r2._type == RT_integer &&
r2.as_integer() == 0) {
return r2;
}
return r1;
}