cppTemplateScope.cxx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // Filename: cppTemplateScope.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 "cppTemplateScope.h"
  19. #include "cppExtensionType.h"
  20. #include "cppClassTemplateParameter.h"
  21. #include "cppIdentifier.h"
  22. #include "cppTypedef.h"
  23. ////////////////////////////////////////////////////////////////////
  24. // Function: CPPTemplateScope::Constructor
  25. // Access: Public
  26. // Description:
  27. ////////////////////////////////////////////////////////////////////
  28. CPPTemplateScope::
  29. CPPTemplateScope(CPPScope *parent_scope) :
  30. CPPScope(parent_scope, CPPNameComponent("template"), V_public)
  31. {
  32. }
  33. ////////////////////////////////////////////////////////////////////
  34. // Function: CPPTemplateScope::add_declaration
  35. // Access: Public, Virtual
  36. // Description:
  37. ////////////////////////////////////////////////////////////////////
  38. void CPPTemplateScope::
  39. add_declaration(CPPDeclaration *decl, CPPScope *global_scope,
  40. CPPPreprocessor *preprocessor,
  41. const cppyyltype &pos) {
  42. decl->_template_scope = this;
  43. assert(_parent_scope != NULL);
  44. _parent_scope->add_declaration(decl, global_scope, preprocessor, pos);
  45. }
  46. ////////////////////////////////////////////////////////////////////
  47. // Function: CPPTemplateScope::add_enum_value
  48. // Access: Public, Virtual
  49. // Description:
  50. ////////////////////////////////////////////////////////////////////
  51. void CPPTemplateScope::
  52. add_enum_value(CPPInstance *inst) {
  53. inst->_template_scope = this;
  54. assert(_parent_scope != NULL);
  55. _parent_scope->add_enum_value(inst);
  56. }
  57. ////////////////////////////////////////////////////////////////////
  58. // Function: CPPTemplateScope::define_extension_type
  59. // Access: Public, Virtual
  60. // Description:
  61. ////////////////////////////////////////////////////////////////////
  62. void CPPTemplateScope::
  63. define_extension_type(CPPExtensionType *type) {
  64. type->_template_scope = this;
  65. assert(_parent_scope != NULL);
  66. _parent_scope->define_extension_type(type);
  67. }
  68. ////////////////////////////////////////////////////////////////////
  69. // Function: CPPTemplateScope::define_namespace
  70. // Access: Public, Virtual
  71. // Description:
  72. ////////////////////////////////////////////////////////////////////
  73. void CPPTemplateScope::
  74. define_namespace(CPPNamespace *scope) {
  75. assert(_parent_scope != NULL);
  76. _parent_scope->define_namespace(scope);
  77. }
  78. ////////////////////////////////////////////////////////////////////
  79. // Function: CPPTemplateScope::add_using
  80. // Access: Public, Virtual
  81. // Description:
  82. ////////////////////////////////////////////////////////////////////
  83. void CPPTemplateScope::
  84. add_using(CPPUsing *using_decl, CPPScope *global_scope,
  85. CPPPreprocessor *error_sink) {
  86. assert(_parent_scope != NULL);
  87. _parent_scope->add_using(using_decl, global_scope, error_sink);
  88. }
  89. ////////////////////////////////////////////////////////////////////
  90. // Function: CPPTemplateScope::add_template_parameter
  91. // Access: Public
  92. // Description:
  93. ////////////////////////////////////////////////////////////////////
  94. void CPPTemplateScope::
  95. add_template_parameter(CPPDeclaration *param) {
  96. _parameters._parameters.push_back(param);
  97. CPPClassTemplateParameter *cl = param->as_class_template_parameter();
  98. if (cl != NULL) {
  99. // Create an implicit typedef for this class parameter.
  100. string name = cl->_ident->get_local_name();
  101. _typedefs[name] = new CPPTypedef(new CPPInstance(cl, cl->_ident), false);
  102. }
  103. CPPInstance *inst = param->as_instance();
  104. if (inst != NULL) {
  105. // Register the variable for this value parameter.
  106. string name = inst->get_local_name();
  107. if (!name.empty()) {
  108. _variables[name] = inst;
  109. }
  110. }
  111. }
  112. ////////////////////////////////////////////////////////////////////
  113. // Function: CPPTemplateScope::is_fully_specified
  114. // Access: Public, Virtual
  115. // Description: Returns true if this declaration is an actual,
  116. // factual declaration, or false if some part of the
  117. // declaration depends on a template parameter which has
  118. // not yet been instantiated.
  119. ////////////////////////////////////////////////////////////////////
  120. bool CPPTemplateScope::
  121. is_fully_specified() const {
  122. return false;
  123. }
  124. ////////////////////////////////////////////////////////////////////
  125. // Function: CPPTemplateScope::get_simple_name
  126. // Access: Public, Virtual
  127. // Description:
  128. ////////////////////////////////////////////////////////////////////
  129. string CPPTemplateScope::
  130. get_simple_name() const {
  131. assert(_parent_scope != NULL);
  132. return _parent_scope->get_simple_name();
  133. }
  134. ////////////////////////////////////////////////////////////////////
  135. // Function: CPPTemplateScope::get_local_name
  136. // Access: Public, Virtual
  137. // Description:
  138. ////////////////////////////////////////////////////////////////////
  139. string CPPTemplateScope::
  140. get_local_name(CPPScope *scope) const {
  141. assert(_parent_scope != NULL);
  142. return _parent_scope->get_local_name(scope);
  143. }
  144. ////////////////////////////////////////////////////////////////////
  145. // Function: CPPTemplateScope::get_fully_scoped_name
  146. // Access: Public, Virtual
  147. // Description:
  148. ////////////////////////////////////////////////////////////////////
  149. string CPPTemplateScope::
  150. get_fully_scoped_name() const {
  151. assert(_parent_scope != NULL);
  152. return _parent_scope->get_fully_scoped_name();
  153. }
  154. ////////////////////////////////////////////////////////////////////
  155. // Function: CPPTemplateScope::output
  156. // Access: Public, Virtual
  157. // Description:
  158. ////////////////////////////////////////////////////////////////////
  159. void CPPTemplateScope::
  160. output(ostream &out, CPPScope *scope) const {
  161. CPPScope::output(out, scope);
  162. out << "< ";
  163. _parameters.output(out, scope);
  164. out << " >";
  165. }
  166. ////////////////////////////////////////////////////////////////////
  167. // Function: CPPTemplateScope::as_template_scope
  168. // Access: Public, Virtual
  169. // Description:
  170. ////////////////////////////////////////////////////////////////////
  171. CPPTemplateScope *CPPTemplateScope::
  172. as_template_scope() {
  173. return this;
  174. }