cppSimpleType.cxx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // Filename: cppSimpleType.C
  2. // Created by: drose (19Oct99)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. #include "cppSimpleType.h"
  6. #include "cppGlobals.h"
  7. ////////////////////////////////////////////////////////////////////
  8. // Function: CPPSimpleType::Constructor
  9. // Access: Public
  10. // Description:
  11. ////////////////////////////////////////////////////////////////////
  12. CPPSimpleType::
  13. CPPSimpleType(CPPSimpleType::Type type, int flags) :
  14. CPPType(CPPFile()),
  15. _type(type), _flags(flags)
  16. {
  17. }
  18. ////////////////////////////////////////////////////////////////////
  19. // Function: CPPSimpleType::is_tbd
  20. // Access: Public, Virtual
  21. // Description: Returns true if the type, or any nested type within
  22. // the type, is a CPPTBDType and thus isn't fully
  23. // determined right now. In this case, calling
  24. // resolve_type() may or may not resolve the type.
  25. ////////////////////////////////////////////////////////////////////
  26. bool CPPSimpleType::
  27. is_tbd() const {
  28. return (_type == T_unknown);
  29. }
  30. ////////////////////////////////////////////////////////////////////
  31. // Function: CPPSimpleType::get_preferred_name
  32. // Access: Public, Virtual
  33. // Description:
  34. ////////////////////////////////////////////////////////////////////
  35. string CPPSimpleType::
  36. get_preferred_name() const {
  37. // Simple types always prefer to use their native types.
  38. return get_local_name();
  39. }
  40. ////////////////////////////////////////////////////////////////////
  41. // Function: CPPSimpleType::output
  42. // Access: Public, Virtual
  43. // Description:
  44. ////////////////////////////////////////////////////////////////////
  45. void CPPSimpleType::
  46. output(ostream &out, int, CPPScope *, bool) const {
  47. if (_flags & F_unsigned) {
  48. out << "unsigned ";
  49. }
  50. if (_flags & F_signed) {
  51. out << "signed ";
  52. }
  53. if ((_type == T_int && (_flags & F_longlong) != 0) &&
  54. !cpp_longlong_keyword.empty()) {
  55. // It's a long long, and we have a specific long long type name.
  56. // This is to output code for compilers that don't recognize "long
  57. // long int".
  58. out << cpp_longlong_keyword;
  59. return;
  60. }
  61. if (_flags & F_longlong) {
  62. out << "long long ";
  63. } else if (_flags & F_long) {
  64. out << "long ";
  65. } else if (_flags & F_short) {
  66. out << "short ";
  67. }
  68. switch (_type) {
  69. case T_bool:
  70. out << "bool";
  71. break;
  72. case T_char:
  73. out << "char";
  74. break;
  75. case T_int:
  76. out << "int";
  77. break;
  78. case T_float:
  79. out << "float";
  80. break;
  81. case T_double:
  82. out << "double";
  83. break;
  84. case T_void:
  85. out << "void";
  86. break;
  87. case T_unknown:
  88. out << "unknown";
  89. break;
  90. default:
  91. out << "***invalid type***";
  92. }
  93. }
  94. ////////////////////////////////////////////////////////////////////
  95. // Function: CPPSimpleType::get_subtype
  96. // Access: Public, Virtual
  97. // Description:
  98. ////////////////////////////////////////////////////////////////////
  99. CPPDeclaration::SubType CPPSimpleType::
  100. get_subtype() const {
  101. return ST_simple;
  102. }
  103. ////////////////////////////////////////////////////////////////////
  104. // Function: CPPSimpleType::as_simple_type
  105. // Access: Public, Virtual
  106. // Description:
  107. ////////////////////////////////////////////////////////////////////
  108. CPPSimpleType *CPPSimpleType::
  109. as_simple_type() {
  110. return this;
  111. }
  112. ////////////////////////////////////////////////////////////////////
  113. // Function: CPPSimpleType::is_equal
  114. // Access: Protected, Virtual
  115. // Description: Called by CPPDeclaration() to determine whether this type is
  116. // equivalent to another type of the same type.
  117. ////////////////////////////////////////////////////////////////////
  118. bool CPPSimpleType::
  119. is_equal(const CPPDeclaration *other) const {
  120. const CPPSimpleType *ot = ((CPPDeclaration *)other)->as_simple_type();
  121. assert(ot != NULL);
  122. return _type == ot->_type && _flags == ot->_flags;
  123. }
  124. ////////////////////////////////////////////////////////////////////
  125. // Function: CPPSimpleType::is_less
  126. // Access: Protected, Virtual
  127. // Description: Called by CPPDeclaration() to determine whether this type
  128. // should be ordered before another type of the same
  129. // type, in an arbitrary but fixed ordering.
  130. ////////////////////////////////////////////////////////////////////
  131. bool CPPSimpleType::
  132. is_less(const CPPDeclaration *other) const {
  133. const CPPSimpleType *ot = ((CPPDeclaration *)other)->as_simple_type();
  134. assert(ot != NULL);
  135. if (_type != ot->_type) {
  136. return _type < ot->_type;
  137. }
  138. return _flags < ot->_flags;
  139. }