cppTBDType.cxx 7.0 KB

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