cppTemplateScope.cxx 6.4 KB

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