From c3e862a842ee1ff07a0be8af1b80fbc9fb2feff5 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 8 Nov 2013 10:25:45 +0000 Subject: [PATCH] Add is_double and is_short --- dtool/src/interrogate/typeManager.cxx | 100 ++++++++++++++++++++++++-- dtool/src/interrogate/typeManager.h | 5 +- 2 files changed, 97 insertions(+), 8 deletions(-) diff --git a/dtool/src/interrogate/typeManager.cxx b/dtool/src/interrogate/typeManager.cxx index 8dc01d9855..03b742e6a3 100644 --- a/dtool/src/interrogate/typeManager.cxx +++ b/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 an unsigned -// "long long" type or larger, or at least a 64-bit -// unsigned integer. +// Description: Returns true if the indicated type is the "short" +// type, whether signed or unsigned. //////////////////////////////////////////////////////////////////// bool TypeManager:: -is_unsigned_longlong(CPPType *type) { +is_short(CPPType *type) { switch (type->get_subtype()) { case CPPDeclaration::ST_const: - return is_unsigned_longlong(type->as_const_type()->_wrapped_around); + 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_longlong | CPPSimpleType::F_unsigned)) == (CPPSimpleType::F_longlong | CPPSimpleType::F_unsigned)); + (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 +// "short" type. +//////////////////////////////////////////////////////////////////// +bool TypeManager:: +is_unsigned_short(CPPType *type) { + switch (type->get_subtype()) { + case CPPDeclaration::ST_const: + 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_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 diff --git a/dtool/src/interrogate/typeManager.h b/dtool/src/interrogate/typeManager.h index 938fca3c97..9123da52ed 100644 --- a/dtool/src/interrogate/typeManager.h +++ b/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);