Browse Source

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

David Rose 23 years ago
parent
commit
3496d7fedc
1 changed files with 17 additions and 0 deletions
  1. 17 0
      dtool/src/cppparser/cppExpression.cxx

+ 17 - 0
dtool/src/cppparser/cppExpression.cxx

@@ -463,6 +463,23 @@ evaluate() const {
     assert(_u._op._op1 != NULL);
     assert(_u._op._op1 != NULL);
     r1 = _u._op._op1->evaluate();
     r1 = _u._op._op1->evaluate();
     if (r1._type == RT_error) {
     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;
       return r1;
     }
     }