cppSimpleType.cxx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // Filename: cppSimpleType.cxx
  2. // Created by: drose (19Oct99)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #include "cppSimpleType.h"
  19. #include "cppGlobals.h"
  20. ////////////////////////////////////////////////////////////////////
  21. // Function: CPPSimpleType::Constructor
  22. // Access: Public
  23. // Description:
  24. ////////////////////////////////////////////////////////////////////
  25. CPPSimpleType::
  26. CPPSimpleType(CPPSimpleType::Type type, int flags) :
  27. CPPType(CPPFile()),
  28. _type(type), _flags(flags)
  29. {
  30. }
  31. ////////////////////////////////////////////////////////////////////
  32. // Function: CPPSimpleType::is_tbd
  33. // Access: Public, Virtual
  34. // Description: Returns true if the type, or any nested type within
  35. // the type, is a CPPTBDType and thus isn't fully
  36. // determined right now. In this case, calling
  37. // resolve_type() may or may not resolve the type.
  38. ////////////////////////////////////////////////////////////////////
  39. bool CPPSimpleType::
  40. is_tbd() const {
  41. return (_type == T_unknown);
  42. }
  43. ////////////////////////////////////////////////////////////////////
  44. // Function: CPPSimpleType::is_parameter_expr
  45. // Access: Public, Virtual
  46. // Description: Returns true if the type is a special parameter
  47. // expression type.
  48. //
  49. // This sort of type is created to handle instance
  50. // declarations that initially look like function
  51. // prototypes.
  52. ////////////////////////////////////////////////////////////////////
  53. bool CPPSimpleType::
  54. is_parameter_expr() const {
  55. return (_type == T_parameter);
  56. }
  57. ////////////////////////////////////////////////////////////////////
  58. // Function: CPPSimpleType::get_preferred_name
  59. // Access: Public, Virtual
  60. // Description:
  61. ////////////////////////////////////////////////////////////////////
  62. string CPPSimpleType::
  63. get_preferred_name() const {
  64. // Simple types always prefer to use their native types.
  65. return get_local_name();
  66. }
  67. ////////////////////////////////////////////////////////////////////
  68. // Function: CPPSimpleType::output
  69. // Access: Public, Virtual
  70. // Description:
  71. ////////////////////////////////////////////////////////////////////
  72. void CPPSimpleType::
  73. output(ostream &out, int, CPPScope *, bool) const {
  74. if (_flags & F_unsigned) {
  75. out << "unsigned ";
  76. }
  77. if (_flags & F_signed) {
  78. out << "signed ";
  79. }
  80. if ((_type == T_int && (_flags & F_longlong) != 0) &&
  81. !cpp_longlong_keyword.empty()) {
  82. // It's a long long, and we have a specific long long type name.
  83. // This is to output code for compilers that don't recognize "long
  84. // long int".
  85. out << cpp_longlong_keyword;
  86. return;
  87. }
  88. if (_flags & F_longlong) {
  89. out << "long long ";
  90. } else if (_flags & F_long) {
  91. out << "long ";
  92. } else if (_flags & F_short) {
  93. out << "short ";
  94. }
  95. switch (_type) {
  96. case T_bool:
  97. out << "bool";
  98. break;
  99. case T_char:
  100. out << "char";
  101. break;
  102. case T_wchar_t:
  103. out << "wchar_t";
  104. break;
  105. case T_int:
  106. out << "int";
  107. break;
  108. case T_float:
  109. out << "float";
  110. break;
  111. case T_double:
  112. out << "double";
  113. break;
  114. case T_void:
  115. out << "void";
  116. break;
  117. case T_unknown:
  118. out << "unknown";
  119. break;
  120. case T_parameter:
  121. out << "parameter";
  122. break;
  123. default:
  124. out << "***invalid type***";
  125. }
  126. }
  127. ////////////////////////////////////////////////////////////////////
  128. // Function: CPPSimpleType::get_subtype
  129. // Access: Public, Virtual
  130. // Description:
  131. ////////////////////////////////////////////////////////////////////
  132. CPPDeclaration::SubType CPPSimpleType::
  133. get_subtype() const {
  134. return ST_simple;
  135. }
  136. ////////////////////////////////////////////////////////////////////
  137. // Function: CPPSimpleType::as_simple_type
  138. // Access: Public, Virtual
  139. // Description:
  140. ////////////////////////////////////////////////////////////////////
  141. CPPSimpleType *CPPSimpleType::
  142. as_simple_type() {
  143. return this;
  144. }
  145. ////////////////////////////////////////////////////////////////////
  146. // Function: CPPSimpleType::is_equal
  147. // Access: Protected, Virtual
  148. // Description: Called by CPPDeclaration() to determine whether this type is
  149. // equivalent to another type of the same type.
  150. ////////////////////////////////////////////////////////////////////
  151. bool CPPSimpleType::
  152. is_equal(const CPPDeclaration *other) const {
  153. const CPPSimpleType *ot = ((CPPDeclaration *)other)->as_simple_type();
  154. assert(ot != NULL);
  155. return _type == ot->_type && _flags == ot->_flags;
  156. }
  157. ////////////////////////////////////////////////////////////////////
  158. // Function: CPPSimpleType::is_less
  159. // Access: Protected, Virtual
  160. // Description: Called by CPPDeclaration() to determine whether this type
  161. // should be ordered before another type of the same
  162. // type, in an arbitrary but fixed ordering.
  163. ////////////////////////////////////////////////////////////////////
  164. bool CPPSimpleType::
  165. is_less(const CPPDeclaration *other) const {
  166. const CPPSimpleType *ot = ((CPPDeclaration *)other)->as_simple_type();
  167. assert(ot != NULL);
  168. if (_type != ot->_type) {
  169. return _type < ot->_type;
  170. }
  171. return _flags < ot->_flags;
  172. }