Browse Source

Handle bool expressions separately in cppparser

rdb 10 years ago
parent
commit
9a38a6b075
2 changed files with 38 additions and 1 deletions
  1. 35 1
      dtool/src/cppparser/cppExpression.cxx
  2. 3 0
      dtool/src/cppparser/cppExpression.h

+ 35 - 1
dtool/src/cppparser/cppExpression.cxx

@@ -201,6 +201,19 @@ output(ostream &out) const {
   }
   }
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: CPPExpression::Constructor
+//       Access: Public
+//  Description:
+////////////////////////////////////////////////////////////////////
+CPPExpression::
+CPPExpression(bool value) :
+  CPPDeclaration(CPPFile())
+{
+  _type = T_boolean;
+  _u._boolean = value;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: CPPExpression::Constructor
 //     Function: CPPExpression::Constructor
 //       Access: Public
 //       Access: Public
@@ -540,6 +553,9 @@ evaluate() const {
   case T_nullptr:
   case T_nullptr:
     return Result((void *)0);
     return Result((void *)0);
 
 
+  case T_boolean:
+    return Result((int)_u._boolean);
+
   case T_integer:
   case T_integer:
     return Result((int)_u._integer);
     return Result((int)_u._integer);
 
 
@@ -580,8 +596,12 @@ evaluate() const {
     if (r1._type != RT_error) {
     if (r1._type != RT_error) {
       CPPSimpleType *stype = _u._typecast._to->as_simple_type();
       CPPSimpleType *stype = _u._typecast._to->as_simple_type();
       if (stype != NULL) {
       if (stype != NULL) {
-        if (stype->_type == CPPSimpleType::T_int) {
+        if (stype->_type == CPPSimpleType::T_bool) {
+          return Result(r1.as_boolean());
+
+        } else if (stype->_type == CPPSimpleType::T_int) {
           return Result(r1.as_integer());
           return Result(r1.as_integer());
+
         } else if (stype->_type == CPPSimpleType::T_float ||
         } else if (stype->_type == CPPSimpleType::T_float ||
                    stype->_type == CPPSimpleType::T_double) {
                    stype->_type == CPPSimpleType::T_double) {
           return Result(r1.as_real());
           return Result(r1.as_real());
@@ -879,6 +899,9 @@ determine_type() const {
   case T_nullptr:
   case T_nullptr:
     return nullptr_type;
     return nullptr_type;
 
 
+  case T_boolean:
+    return bool_type;
+
   case T_integer:
   case T_integer:
     return int_type;
     return int_type;
 
 
@@ -1060,6 +1083,7 @@ is_fully_specified() const {
 
 
   switch (_type) {
   switch (_type) {
   case T_nullptr:
   case T_nullptr:
+  case T_boolean:
   case T_integer:
   case T_integer:
   case T_real:
   case T_real:
   case T_string:
   case T_string:
@@ -1314,6 +1338,10 @@ output(ostream &out, int indent_level, CPPScope *scope, bool) const {
     out << "nullptr";
     out << "nullptr";
     break;
     break;
 
 
+  case T_boolean:
+    out << (_u._boolean ? "true" : "false");
+    break;
+
   case T_integer:
   case T_integer:
     out << _u._integer;
     out << _u._integer;
     break;
     break;
@@ -1748,6 +1776,9 @@ is_equal(const CPPDeclaration *other) const {
   case T_nullptr:
   case T_nullptr:
     return true;
     return true;
 
 
+  case T_boolean:
+    return _u._boolean == ot->_u._boolean;
+
   case T_integer:
   case T_integer:
     return _u._integer == ot->_u._integer;
     return _u._integer == ot->_u._integer;
 
 
@@ -1828,6 +1859,9 @@ is_less(const CPPDeclaration *other) const {
   case T_nullptr:
   case T_nullptr:
     return false;
     return false;
 
 
+  case T_boolean:
+    return _u._boolean < ot->_u._boolean;
+
   case T_integer:
   case T_integer:
     return _u._integer < ot->_u._integer;
     return _u._integer < ot->_u._integer;
 
 

+ 3 - 0
dtool/src/cppparser/cppExpression.h

@@ -30,6 +30,7 @@ class CPPFunctionGroup;
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 class CPPExpression : public CPPDeclaration {
 class CPPExpression : public CPPDeclaration {
 public:
 public:
+  CPPExpression(bool value);
   CPPExpression(unsigned long long value);
   CPPExpression(unsigned long long value);
   CPPExpression(int value);
   CPPExpression(int value);
   CPPExpression(const string &value);
   CPPExpression(const string &value);
@@ -104,6 +105,7 @@ public:
 
 
   enum Type {
   enum Type {
     T_nullptr,
     T_nullptr,
+    T_boolean,
     T_integer,
     T_integer,
     T_real,
     T_real,
     T_string,
     T_string,
@@ -135,6 +137,7 @@ public:
   Type _type;
   Type _type;
   string _str;
   string _str;
   union {
   union {
+    bool _boolean;
     unsigned long long _integer;
     unsigned long long _integer;
     long double _real;
     long double _real;
     CPPInstance *_variable;
     CPPInstance *_variable;