cppDeclaration.h 7.0 KB

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