cppTBDType.cxx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // Filename: cppTBDType.C
  2. // Created by: drose (05Nov99)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. #include "cppTBDType.h"
  6. #include "cppIdentifier.h"
  7. #include "cppSimpleType.h"
  8. ////////////////////////////////////////////////////////////////////
  9. // Function: CPPTBDType::Constructor
  10. // Access: Public
  11. // Description:
  12. ////////////////////////////////////////////////////////////////////
  13. CPPTBDType::
  14. CPPTBDType(CPPIdentifier *ident) :
  15. CPPType(CPPFile()),
  16. _ident(ident)
  17. {
  18. _subst_decl_recursive_protect = false;
  19. }
  20. ////////////////////////////////////////////////////////////////////
  21. // Function: CPPTBDType::resolve_type
  22. // Access: Public, Virtual
  23. // Description: If this CPPType object is a forward reference or
  24. // other nonspecified reference to a type that might now
  25. // be known a real type, returns the real type.
  26. // Otherwise returns the type itself.
  27. ////////////////////////////////////////////////////////////////////
  28. CPPType *CPPTBDType::
  29. resolve_type(CPPScope *current_scope, CPPScope *global_scope) {
  30. CPPType *type = _ident->find_type(current_scope, global_scope);
  31. if (type != NULL) {
  32. return type;
  33. }
  34. return this;
  35. }
  36. ////////////////////////////////////////////////////////////////////
  37. // Function: CPPTBDType::is_tbd
  38. // Access: Public, Virtual
  39. // Description: Returns true if the type, or any nested type within
  40. // the type, is a CPPTBDType and thus isn't fully
  41. // determined right now. In this case, calling
  42. // resolve_type() may or may not resolve the type.
  43. ////////////////////////////////////////////////////////////////////
  44. bool CPPTBDType::
  45. is_tbd() const {
  46. return true;
  47. }
  48. ////////////////////////////////////////////////////////////////////
  49. // Function: CPPTBDType::get_simple_name
  50. // Access: Public, Virtual
  51. // Description: Returns a fundametal one-word name for the type.
  52. // This name will not include any scoping operators or
  53. // template parameters, so it may not be a compilable
  54. // reference to the type.
  55. ////////////////////////////////////////////////////////////////////
  56. string CPPTBDType::
  57. get_simple_name() const {
  58. return _ident->get_simple_name();
  59. }
  60. ////////////////////////////////////////////////////////////////////
  61. // Function: CPPTBDType::get_local_name
  62. // Access: Public, Virtual
  63. // Description: Returns the compilable, correct name for this type
  64. // within the indicated scope. If the scope is NULL,
  65. // within the scope the type is declared in.
  66. ////////////////////////////////////////////////////////////////////
  67. string CPPTBDType::
  68. get_local_name(CPPScope *scope) const {
  69. return _ident->get_local_name(scope);
  70. }
  71. ////////////////////////////////////////////////////////////////////
  72. // Function: CPPTBDType::get_fully_scoped_name
  73. // Access: Public, Virtual
  74. // Description: Returns the compilable, correct name for the type,
  75. // with completely explicit scoping.
  76. ////////////////////////////////////////////////////////////////////
  77. string CPPTBDType::
  78. get_fully_scoped_name() const {
  79. return _ident->get_fully_scoped_name();
  80. }
  81. ////////////////////////////////////////////////////////////////////
  82. // Function: CPPTBDType::substitute_decl
  83. // Access: Public, Virtual
  84. // Description:
  85. ////////////////////////////////////////////////////////////////////
  86. CPPDeclaration *CPPTBDType::
  87. substitute_decl(CPPDeclaration::SubstDecl &subst,
  88. CPPScope *current_scope, CPPScope *global_scope) {
  89. CPPDeclaration *top =
  90. CPPDeclaration::substitute_decl(subst, current_scope, global_scope);
  91. if (top != this) {
  92. return top;
  93. }
  94. // Protect against recursive entry into this function block. I know
  95. // it's ugly--have you got any better suggestions?
  96. if (_subst_decl_recursive_protect) {
  97. // We're already executing this block.
  98. return this;
  99. }
  100. _subst_decl_recursive_protect = true;
  101. CPPTBDType *rep = new CPPTBDType(*this);
  102. rep->_ident = _ident->substitute_decl(subst, current_scope, global_scope);
  103. if (rep->_ident == _ident) {
  104. delete rep;
  105. rep = this;
  106. }
  107. rep = CPPType::new_type(rep)->as_tbd_type();
  108. assert(rep != NULL);
  109. CPPType *result = rep;
  110. // Can we now define it as a real type?
  111. CPPType *type = rep->_ident->find_type(current_scope, global_scope, subst);
  112. if (type != NULL) {
  113. result = type;
  114. }
  115. subst.insert(SubstDecl::value_type(this, result));
  116. _subst_decl_recursive_protect = false;
  117. return result;
  118. }
  119. ////////////////////////////////////////////////////////////////////
  120. // Function: CPPTBDType::output
  121. // Access: Public, Virtual
  122. // Description:
  123. ////////////////////////////////////////////////////////////////////
  124. void CPPTBDType::
  125. output(ostream &out, int, CPPScope *, bool) const {
  126. out /* << "typename " */ << *_ident;
  127. }
  128. ////////////////////////////////////////////////////////////////////
  129. // Function: CPPTBDType::get_subtype
  130. // Access: Public, Virtual
  131. // Description:
  132. ////////////////////////////////////////////////////////////////////
  133. CPPDeclaration::SubType CPPTBDType::
  134. get_subtype() const {
  135. return ST_tbd;
  136. }
  137. ////////////////////////////////////////////////////////////////////
  138. // Function: CPPTBDType::as_tbd_type
  139. // Access: Public, Virtual
  140. // Description:
  141. ////////////////////////////////////////////////////////////////////
  142. CPPTBDType *CPPTBDType::
  143. as_tbd_type() {
  144. return this;
  145. }
  146. ////////////////////////////////////////////////////////////////////
  147. // Function: CPPTBDType::is_equal
  148. // Access: Protected, Virtual
  149. // Description: Called by CPPDeclaration() to determine whether this type is
  150. // equivalent to another type of the same type.
  151. ////////////////////////////////////////////////////////////////////
  152. bool CPPTBDType::
  153. is_equal(const CPPDeclaration *other) const {
  154. const CPPTBDType *ot = ((CPPDeclaration *)other)->as_tbd_type();
  155. assert(ot != NULL);
  156. return (*_ident) == (*ot->_ident);
  157. }
  158. ////////////////////////////////////////////////////////////////////
  159. // Function: CPPTBDType::is_less
  160. // Access: Protected, Virtual
  161. // Description: Called by CPPDeclaration() to determine whether this type
  162. // should be ordered before another type of the same
  163. // type, in an arbitrary but fixed ordering.
  164. ////////////////////////////////////////////////////////////////////
  165. bool CPPTBDType::
  166. is_less(const CPPDeclaration *other) const {
  167. const CPPTBDType *ot = ((CPPDeclaration *)other)->as_tbd_type();
  168. assert(ot != NULL);
  169. return (*_ident) < (*ot->_ident);
  170. }