Browse Source

Add is_double and is_short

rdb 12 years ago
parent
commit
c3e862a842
2 changed files with 96 additions and 7 deletions
  1. 92 6
      dtool/src/interrogate/typeManager.cxx
  2. 4 1
      dtool/src/interrogate/typeManager.h

+ 92 - 6
dtool/src/interrogate/typeManager.cxx

@@ -807,24 +807,52 @@ is_unsigned_integer(CPPType *type) {
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: TypeManager::is_unsigned_longlong
+//     Function: TypeManager::is_short
+//       Access: Public, Static
+//  Description: Returns true if the indicated type is the "short"
+//               type, whether signed or unsigned.
+////////////////////////////////////////////////////////////////////
+bool TypeManager::
+is_short(CPPType *type) {
+  switch (type->get_subtype()) {
+  case CPPDeclaration::ST_const:
+    return is_short(type->as_const_type()->_wrapped_around);
+
+  case CPPDeclaration::ST_simple:
+    {
+      CPPSimpleType *simple_type = type->as_simple_type();
+      if (simple_type != (CPPSimpleType *)NULL) {
+        return (simple_type->_type == CPPSimpleType::T_int && 
+                (simple_type->_flags & CPPSimpleType::F_short) != 0);
+      }
+    }
+    break;
+
+  default:
+    break;
+  }
+
+  return false;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: TypeManager::is_unsigned_short
 //       Access: Public, Static
 //  Description: Returns true if the indicated type is an unsigned
-//               "long long" type or larger, or at least a 64-bit
-//               unsigned integer.
+//               "short" type.
 ////////////////////////////////////////////////////////////////////
 bool TypeManager::
-is_unsigned_longlong(CPPType *type) {
+is_unsigned_short(CPPType *type) {
   switch (type->get_subtype()) {
   case CPPDeclaration::ST_const:
-    return is_unsigned_longlong(type->as_const_type()->_wrapped_around);
+    return is_unsigned_short(type->as_const_type()->_wrapped_around);
 
   case CPPDeclaration::ST_simple:
     {
       CPPSimpleType *simple_type = type->as_simple_type();
       if (simple_type != (CPPSimpleType *)NULL) {
         return (simple_type->_type == CPPSimpleType::T_int && 
-                (simple_type->_flags & (CPPSimpleType::F_longlong | CPPSimpleType::F_unsigned)) == (CPPSimpleType::F_longlong | CPPSimpleType::F_unsigned));
+                (simple_type->_flags & (CPPSimpleType::F_short | CPPSimpleType::F_unsigned)) == (CPPSimpleType::F_short | CPPSimpleType::F_unsigned));
       }
     }
     break;
@@ -866,6 +894,64 @@ is_longlong(CPPType *type) {
   return false;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: TypeManager::is_unsigned_longlong
+//       Access: Public, Static
+//  Description: Returns true if the indicated type is an unsigned
+//               "long long" type or larger, or at least a 64-bit
+//               unsigned integer.
+////////////////////////////////////////////////////////////////////
+bool TypeManager::
+is_unsigned_longlong(CPPType *type) {
+  switch (type->get_subtype()) {
+  case CPPDeclaration::ST_const:
+    return is_unsigned_longlong(type->as_const_type()->_wrapped_around);
+
+  case CPPDeclaration::ST_simple:
+    {
+      CPPSimpleType *simple_type = type->as_simple_type();
+      if (simple_type != (CPPSimpleType *)NULL) {
+        return (simple_type->_type == CPPSimpleType::T_int && 
+                (simple_type->_flags & (CPPSimpleType::F_longlong | CPPSimpleType::F_unsigned)) == (CPPSimpleType::F_longlong | CPPSimpleType::F_unsigned));
+      }
+    }
+    break;
+
+  default:
+    break;
+  }
+
+  return false;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: TypeManager::is_double
+//       Access: Public, Static
+//  Description: Returns true if the indicated type is the "double"
+//               type.
+////////////////////////////////////////////////////////////////////
+bool TypeManager::
+is_double(CPPType *type) {
+  switch (type->get_subtype()) {
+  case CPPDeclaration::ST_const:
+    return is_float(type->as_const_type()->_wrapped_around);
+
+  case CPPDeclaration::ST_simple:
+    {
+      CPPSimpleType *simple_type = type->as_simple_type();
+      if (simple_type != (CPPSimpleType *)NULL) {
+        return (simple_type->_type == CPPSimpleType::T_double);
+      }
+    }
+    break;
+
+  default:
+    break;
+  }
+
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: TypeManager::is_float
 //       Access: Public, Static

+ 4 - 1
dtool/src/interrogate/typeManager.h

@@ -80,8 +80,11 @@ public:
   static bool is_bool(CPPType *type);
   static bool is_integer(CPPType *type);
   static bool is_unsigned_integer(CPPType *type);
-  static bool is_unsigned_longlong(CPPType *type);
+  static bool is_short(CPPType *type);
+  static bool is_unsigned_short(CPPType *type);
   static bool is_longlong(CPPType *type);
+  static bool is_unsigned_longlong(CPPType *type);
+  static bool is_double(CPPType *type);
   static bool is_float(CPPType *type);
   static bool is_void(CPPType *type);
   static bool is_reference_count(CPPType *type);