cppConstType.cxx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // Filename: cppConstType.cxx
  2. // Created by: drose (28Oct99)
  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 "cppConstType.h"
  19. ////////////////////////////////////////////////////////////////////
  20. // Function: CPPConstType::Constructor
  21. // Access: Public
  22. // Description:
  23. ////////////////////////////////////////////////////////////////////
  24. CPPConstType::
  25. CPPConstType(CPPType *wrapped_around) :
  26. CPPType(CPPFile()),
  27. _wrapped_around(wrapped_around)
  28. {
  29. }
  30. ////////////////////////////////////////////////////////////////////
  31. // Function: CPPConstType::is_fully_specified
  32. // Access: Public, Virtual
  33. // Description: Returns true if this declaration is an actual,
  34. // factual declaration, or false if some part of the
  35. // declaration depends on a template parameter which has
  36. // not yet been instantiated.
  37. ////////////////////////////////////////////////////////////////////
  38. bool CPPConstType::
  39. is_fully_specified() const {
  40. return CPPType::is_fully_specified() &&
  41. _wrapped_around->is_fully_specified();
  42. }
  43. ////////////////////////////////////////////////////////////////////
  44. // Function: CPPConstType::substitute_decl
  45. // Access: Public, Virtual
  46. // Description:
  47. ////////////////////////////////////////////////////////////////////
  48. CPPDeclaration *CPPConstType::
  49. substitute_decl(CPPDeclaration::SubstDecl &subst,
  50. CPPScope *current_scope, CPPScope *global_scope) {
  51. SubstDecl::const_iterator si = subst.find(this);
  52. if (si != subst.end()) {
  53. return (*si).second;
  54. }
  55. CPPConstType *rep = new CPPConstType(*this);
  56. rep->_wrapped_around =
  57. _wrapped_around->substitute_decl(subst, current_scope, global_scope)
  58. ->as_type();
  59. if (rep->_wrapped_around == _wrapped_around) {
  60. delete rep;
  61. rep = this;
  62. }
  63. rep = CPPType::new_type(rep)->as_const_type();
  64. subst.insert(SubstDecl::value_type(this, rep));
  65. return rep;
  66. }
  67. ////////////////////////////////////////////////////////////////////
  68. // Function: CPPConstType::resolve_type
  69. // Access: Public, Virtual
  70. // Description: If this CPPType object is a forward reference or
  71. // other nonspecified reference to a type that might now
  72. // be known a real type, returns the real type.
  73. // Otherwise returns the type itself.
  74. ////////////////////////////////////////////////////////////////////
  75. CPPType *CPPConstType::
  76. resolve_type(CPPScope *current_scope, CPPScope *global_scope) {
  77. CPPType *ptype = _wrapped_around->resolve_type(current_scope, global_scope);
  78. if (ptype != _wrapped_around) {
  79. CPPConstType *rep = new CPPConstType(*this);
  80. rep->_wrapped_around = ptype;
  81. return CPPType::new_type(rep);
  82. }
  83. return this;
  84. }
  85. ////////////////////////////////////////////////////////////////////
  86. // Function: CPPConstType::is_tbd
  87. // Access: Public, Virtual
  88. // Description: Returns true if the type, or any nested type within
  89. // the type, is a CPPTBDType and thus isn't fully
  90. // determined right now. In this case, calling
  91. // resolve_type() may or may not resolve the type.
  92. ////////////////////////////////////////////////////////////////////
  93. bool CPPConstType::
  94. is_tbd() const {
  95. return _wrapped_around->is_tbd();
  96. }
  97. ////////////////////////////////////////////////////////////////////
  98. // Function: CPPConstType::is_equivalent
  99. // Access: Public, Virtual
  100. // Description: This is a little more forgiving than is_equal(): it
  101. // returns true if the types appear to be referring to
  102. // the same thing, even if they may have different
  103. // pointers or somewhat different definitions. It's
  104. // useful for parameter matching, etc.
  105. ////////////////////////////////////////////////////////////////////
  106. bool CPPConstType::
  107. is_equivalent(const CPPType &other) const {
  108. const CPPConstType *ot = ((CPPType *)&other)->as_const_type();
  109. if (ot == (CPPConstType *)NULL) {
  110. return CPPType::is_equivalent(other);
  111. }
  112. return _wrapped_around->is_equivalent(*ot->_wrapped_around);
  113. }
  114. ////////////////////////////////////////////////////////////////////
  115. // Function: CPPConstType::output
  116. // Access: Public, Virtual
  117. // Description:
  118. ////////////////////////////////////////////////////////////////////
  119. void CPPConstType::
  120. output(ostream &out, int indent_level, CPPScope *scope, bool complete) const {
  121. _wrapped_around->output(out, indent_level, scope, complete);
  122. out << " const";
  123. }
  124. ////////////////////////////////////////////////////////////////////
  125. // Function: CPPConstType::output_instance
  126. // Access: Public, Virtual
  127. // Description: Formats a C++-looking line that defines an instance
  128. // of the given type, with the indicated name. In most
  129. // cases this will be "type name", but some types have
  130. // special exceptions.
  131. ////////////////////////////////////////////////////////////////////
  132. void CPPConstType::
  133. output_instance(ostream &out, int indent_level, CPPScope *scope,
  134. bool complete, const string &prename,
  135. const string &name) const {
  136. _wrapped_around->output_instance(out, indent_level, scope, complete,
  137. "const " + prename, name);
  138. }
  139. ////////////////////////////////////////////////////////////////////
  140. // Function: CPPConstType::get_subtype
  141. // Access: Public, Virtual
  142. // Description:
  143. ////////////////////////////////////////////////////////////////////
  144. CPPDeclaration::SubType CPPConstType::
  145. get_subtype() const {
  146. return ST_const;
  147. }
  148. ////////////////////////////////////////////////////////////////////
  149. // Function: CPPConstType::as_const_type
  150. // Access: Public, Virtual
  151. // Description:
  152. ////////////////////////////////////////////////////////////////////
  153. CPPConstType *CPPConstType::
  154. as_const_type() {
  155. return this;
  156. }
  157. ////////////////////////////////////////////////////////////////////
  158. // Function: CPPConstType::is_equal
  159. // Access: Protected, Virtual
  160. // Description: Called by CPPDeclaration() to determine whether this type is
  161. // equivalent to another type of the same type.
  162. ////////////////////////////////////////////////////////////////////
  163. bool CPPConstType::
  164. is_equal(const CPPDeclaration *other) const {
  165. const CPPConstType *ot = ((CPPDeclaration *)other)->as_const_type();
  166. assert(ot != NULL);
  167. return _wrapped_around == ot->_wrapped_around;
  168. }
  169. ////////////////////////////////////////////////////////////////////
  170. // Function: CPPConstType::is_less
  171. // Access: Protected, Virtual
  172. // Description: Called by CPPDeclaration() to determine whether this type
  173. // should be ordered before another type of the same
  174. // type, in an arbitrary but fixed ordering.
  175. ////////////////////////////////////////////////////////////////////
  176. bool CPPConstType::
  177. is_less(const CPPDeclaration *other) const {
  178. const CPPConstType *ot = ((CPPDeclaration *)other)->as_const_type();
  179. assert(ot != NULL);
  180. return _wrapped_around < ot->_wrapped_around;
  181. }