cppTemplateScope.cxx 6.0 KB

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