cppTemplateScope.cxx 3.7 KB

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