cppDeclaration.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 cppDeclaration.h
  10. * @author drose
  11. * @date 1999-10-19
  12. */
  13. #ifndef CPPDECLARATION_H
  14. #define CPPDECLARATION_H
  15. #include "dtoolbase.h"
  16. #include "cppVisibility.h"
  17. #include "cppFile.h"
  18. #include "cppCommentBlock.h"
  19. #include <string>
  20. #include <vector>
  21. #include <map>
  22. #include <set>
  23. class CPPInstance;
  24. class CPPTemplateParameterList;
  25. class CPPTypedefType;
  26. class CPPTypeDeclaration;
  27. class CPPExpression;
  28. class CPPType;
  29. class CPPNamespace;
  30. class CPPUsing;
  31. class CPPSimpleType;
  32. class CPPPointerType;
  33. class CPPReferenceType;
  34. class CPPArrayType;
  35. class CPPConstType;
  36. class CPPFunctionType;
  37. class CPPFunctionGroup;
  38. class CPPExtensionType;
  39. class CPPStructType;
  40. class CPPEnumType;
  41. class CPPTypeProxy;
  42. class CPPMakeProperty;
  43. class CPPMakeSeq;
  44. class CPPClosureType;
  45. class CPPClassTemplateParameter;
  46. class CPPTBDType;
  47. class CPPScope;
  48. class CPPTemplateScope;
  49. class CPPPreprocessor;
  50. /**
  51. *
  52. */
  53. class CPPDeclaration {
  54. public:
  55. enum SubType {
  56. // Subtypes of CPPDeclaration
  57. ST_instance,
  58. ST_type_declaration,
  59. ST_expression,
  60. ST_type,
  61. ST_namespace,
  62. ST_using,
  63. ST_make_property,
  64. ST_make_seq,
  65. // Subtypes of CPPType
  66. ST_simple,
  67. ST_pointer,
  68. ST_reference,
  69. ST_array,
  70. ST_const,
  71. ST_function,
  72. ST_function_group,
  73. ST_extension,
  74. ST_struct,
  75. ST_enum,
  76. ST_class_template_parameter,
  77. ST_tbd,
  78. ST_type_proxy,
  79. ST_typedef,
  80. ST_closure,
  81. };
  82. CPPDeclaration(const CPPFile &file);
  83. CPPDeclaration(const CPPDeclaration &copy);
  84. virtual ~CPPDeclaration() {};
  85. CPPDeclaration &operator = (const CPPDeclaration &copy);
  86. bool operator == (const CPPDeclaration &other) const;
  87. bool operator != (const CPPDeclaration &other) const;
  88. bool operator < (const CPPDeclaration &other) const;
  89. bool is_template() const;
  90. CPPTemplateScope *get_template_scope() const;
  91. virtual bool is_fully_specified() const;
  92. virtual CPPDeclaration *
  93. instantiate(const CPPTemplateParameterList *actual_params,
  94. CPPScope *current_scope, CPPScope *global_scope,
  95. CPPPreprocessor *error_sink = nullptr) const;
  96. typedef std::map<CPPDeclaration *, CPPDeclaration *> SubstDecl;
  97. virtual CPPDeclaration *substitute_decl(SubstDecl &subst,
  98. CPPScope *current_scope,
  99. CPPScope *global_scope);
  100. typedef std::set<CPPDeclaration *> Instantiations;
  101. Instantiations _instantiations;
  102. virtual void output(std::ostream &out, int indent_level, CPPScope *scope,
  103. bool complete) const=0;
  104. virtual SubType get_subtype() const=0;
  105. virtual CPPInstance *as_instance();
  106. virtual CPPClassTemplateParameter *as_class_template_parameter();
  107. virtual CPPTypedefType *as_typedef_type();
  108. virtual CPPTypeDeclaration *as_type_declaration();
  109. virtual CPPExpression *as_expression();
  110. virtual CPPType *as_type();
  111. virtual CPPNamespace *as_namespace();
  112. virtual CPPUsing *as_using();
  113. virtual CPPSimpleType *as_simple_type();
  114. virtual CPPPointerType *as_pointer_type();
  115. virtual CPPReferenceType *as_reference_type();
  116. virtual CPPArrayType *as_array_type();
  117. virtual CPPConstType *as_const_type();
  118. virtual CPPFunctionType *as_function_type();
  119. virtual CPPFunctionGroup *as_function_group();
  120. virtual CPPExtensionType *as_extension_type();
  121. virtual CPPStructType *as_struct_type();
  122. virtual CPPEnumType *as_enum_type();
  123. virtual CPPTBDType *as_tbd_type();
  124. virtual CPPTypeProxy *as_type_proxy();
  125. virtual CPPMakeProperty *as_make_property();
  126. virtual CPPMakeSeq *as_make_seq();
  127. virtual CPPClosureType *as_closure_type();
  128. inline const CPPInstance *as_instance() const {
  129. return ((CPPDeclaration *)this)->as_instance();
  130. }
  131. inline const CPPClassTemplateParameter *as_class_template_parameter() const {
  132. return ((CPPDeclaration *)this)->as_class_template_parameter();
  133. }
  134. inline const CPPTypedefType *as_typedef_type() const {
  135. return ((CPPDeclaration *)this)->as_typedef_type();
  136. }
  137. inline const CPPTypeDeclaration *as_type_declaration() const {
  138. return ((CPPDeclaration *)this)->as_type_declaration();
  139. }
  140. inline const CPPExpression *as_expression() const {
  141. return ((CPPDeclaration *)this)->as_expression();
  142. }
  143. inline const CPPType *as_type() const {
  144. return ((CPPDeclaration *)this)->as_type();
  145. }
  146. inline const CPPNamespace *as_namespace() const {
  147. return ((CPPDeclaration *)this)->as_namespace();
  148. }
  149. inline const CPPUsing *as_using() const {
  150. return ((CPPDeclaration *)this)->as_using();
  151. }
  152. inline const CPPSimpleType *as_simple_type() const {
  153. return ((CPPDeclaration *)this)->as_simple_type();
  154. }
  155. inline const CPPPointerType *as_pointer_type() const {
  156. return ((CPPDeclaration *)this)->as_pointer_type();
  157. }
  158. inline const CPPReferenceType *as_reference_type() const {
  159. return ((CPPDeclaration *)this)->as_reference_type();
  160. }
  161. inline const CPPArrayType *as_array_type() const {
  162. return ((CPPDeclaration *)this)->as_array_type();
  163. }
  164. inline const CPPConstType *as_const_type() const {
  165. return ((CPPDeclaration *)this)->as_const_type();
  166. }
  167. inline const CPPFunctionType *as_function_type() const {
  168. return ((CPPDeclaration *)this)->as_function_type();
  169. }
  170. inline const CPPFunctionGroup *as_function_group() const {
  171. return ((CPPDeclaration *)this)->as_function_group();
  172. }
  173. inline const CPPExtensionType *as_extension_type() const {
  174. return ((CPPDeclaration *)this)->as_extension_type();
  175. }
  176. inline const CPPStructType *as_struct_type() const {
  177. return ((CPPDeclaration *)this)->as_struct_type();
  178. }
  179. inline const CPPEnumType *as_enum_type() const {
  180. return ((CPPDeclaration *)this)->as_enum_type();
  181. }
  182. inline const CPPTBDType *as_tbd_type() const {
  183. return ((CPPDeclaration *)this)->as_tbd_type();
  184. }
  185. inline const CPPTypeProxy *as_type_proxy() const {
  186. return ((CPPDeclaration *)this)->as_type_proxy();
  187. }
  188. inline const CPPMakeProperty *as_make_property() const {
  189. return ((CPPDeclaration *)this)->as_make_property();
  190. }
  191. inline const CPPMakeSeq *as_make_seq() const {
  192. return ((CPPDeclaration *)this)->as_make_seq();
  193. }
  194. inline const CPPClosureType *as_closure_type() const {
  195. return ((CPPDeclaration *)this)->as_closure_type();
  196. }
  197. CPPVisibility _vis;
  198. CPPTemplateScope *_template_scope;
  199. CPPFile _file;
  200. CPPCommentBlock *_leading_comment;
  201. protected:
  202. virtual bool is_equal(const CPPDeclaration *other) const;
  203. virtual bool is_less(const CPPDeclaration *other) const;
  204. };
  205. inline std::ostream &
  206. operator << (std::ostream &out, const CPPDeclaration &decl) {
  207. decl.output(out, 0, nullptr, false);
  208. return out;
  209. }
  210. std::ostream &
  211. operator << (std::ostream &out, const CPPDeclaration::SubstDecl &decl);
  212. #endif