cppDeclaration.cxx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. // Filename: cppDeclaration.cxx
  2. // Created by: drose (19Oct99)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #include "cppDeclaration.h"
  19. #include "cppPreprocessor.h"
  20. ////////////////////////////////////////////////////////////////////
  21. // Function: CPPDeclaration::Constructor
  22. // Access: Public
  23. // Description:
  24. ////////////////////////////////////////////////////////////////////
  25. CPPDeclaration::
  26. CPPDeclaration(const CPPFile &file) :
  27. _file(file)
  28. {
  29. _vis = V_unknown;
  30. _template_scope = NULL;
  31. _leading_comment = (CPPCommentBlock *)NULL;
  32. }
  33. ////////////////////////////////////////////////////////////////////
  34. // Function: CPPDeclaration::Copy Constructor
  35. // Access: Public
  36. // Description:
  37. ////////////////////////////////////////////////////////////////////
  38. CPPDeclaration::
  39. CPPDeclaration(const CPPDeclaration &copy) :
  40. _vis(copy._vis),
  41. _template_scope(copy._template_scope),
  42. _file(copy._file),
  43. _leading_comment(copy._leading_comment)
  44. {
  45. }
  46. ////////////////////////////////////////////////////////////////////
  47. // Function: CPPDeclaration::Destructor
  48. // Access: Public
  49. // Description:
  50. ////////////////////////////////////////////////////////////////////
  51. CPPDeclaration::
  52. ~CPPDeclaration() {
  53. }
  54. ////////////////////////////////////////////////////////////////////
  55. // Function: CPPDeclaration::Equivalence Operator
  56. // Access: Public
  57. // Description:
  58. ////////////////////////////////////////////////////////////////////
  59. bool CPPDeclaration::
  60. operator == (const CPPDeclaration &other) const {
  61. if (get_subtype() != other.get_subtype()) {
  62. return false;
  63. }
  64. return is_equal(&other);
  65. }
  66. ////////////////////////////////////////////////////////////////////
  67. // Function: CPPDeclaration::Nonequivalence Operator
  68. // Access: Public
  69. // Description:
  70. ////////////////////////////////////////////////////////////////////
  71. bool CPPDeclaration::
  72. operator != (const CPPDeclaration &other) const {
  73. return !(*this == other);
  74. }
  75. ////////////////////////////////////////////////////////////////////
  76. // Function: CPPDeclaration::Ordering Operator
  77. // Access: Public
  78. // Description:
  79. ////////////////////////////////////////////////////////////////////
  80. bool CPPDeclaration::
  81. operator < (const CPPDeclaration &other) const {
  82. if (get_subtype() != other.get_subtype()) {
  83. return get_subtype() < other.get_subtype();
  84. }
  85. return is_less(&other);
  86. }
  87. ////////////////////////////////////////////////////////////////////
  88. // Function: CPPDeclaration::is_template
  89. // Access: Public
  90. // Description: Returns true if this is a template declaration of
  91. // some kind: a template function or a template class,
  92. // typically.
  93. ////////////////////////////////////////////////////////////////////
  94. bool CPPDeclaration::
  95. is_template() const {
  96. return _template_scope != NULL;
  97. }
  98. ////////////////////////////////////////////////////////////////////
  99. // Function: CPPDeclaration::get_template_scope
  100. // Access: Public
  101. // Description: If is_template(), above, returns true, this returns
  102. // the CPPTemplateScope in which this particular
  103. // template declaration is defined. This scope includes
  104. // the information about the template parameters.
  105. ////////////////////////////////////////////////////////////////////
  106. CPPTemplateScope *CPPDeclaration::
  107. get_template_scope() const {
  108. return _template_scope;
  109. }
  110. ////////////////////////////////////////////////////////////////////
  111. // Function: CPPDeclaration::is_fully_specified
  112. // Access: Public, Virtual
  113. // Description: Returns true if this declaration is an actual,
  114. // factual declaration, or false if some part of the
  115. // declaration depends on a template parameter which has
  116. // not yet been instantiated.
  117. ////////////////////////////////////////////////////////////////////
  118. bool CPPDeclaration::
  119. is_fully_specified() const {
  120. return !is_template();
  121. }
  122. ////////////////////////////////////////////////////////////////////
  123. // Function: CPPDeclaration::instantiate
  124. // Access: Public, Virtual
  125. // Description:
  126. ////////////////////////////////////////////////////////////////////
  127. CPPDeclaration *CPPDeclaration::
  128. instantiate(const CPPTemplateParameterList *,
  129. CPPScope *, CPPScope *,
  130. CPPPreprocessor *error_sink) const {
  131. if (error_sink != NULL) {
  132. error_sink->warning("Ignoring template parameters");
  133. }
  134. return (CPPDeclaration *)this;
  135. }
  136. ////////////////////////////////////////////////////////////////////
  137. // Function: CPPDeclaration::substitute_decl
  138. // Access: Public, Virtual
  139. // Description:
  140. ////////////////////////////////////////////////////////////////////
  141. CPPDeclaration *CPPDeclaration::
  142. substitute_decl(SubstDecl &subst, CPPScope *, CPPScope *) {
  143. SubstDecl::const_iterator si = subst.find(this);
  144. if (si != subst.end()) {
  145. return (*si).second;
  146. }
  147. return this;
  148. }
  149. ////////////////////////////////////////////////////////////////////
  150. // Function: CPPDeclaration::as_instance
  151. // Access: Public, Virtual
  152. // Description:
  153. ////////////////////////////////////////////////////////////////////
  154. CPPInstance *CPPDeclaration::
  155. as_instance() {
  156. return (CPPInstance *)NULL;
  157. }
  158. ////////////////////////////////////////////////////////////////////
  159. // Function: CPPDeclaration::as_class_template_parameter
  160. // Access: Public, Virtual
  161. // Description:
  162. ////////////////////////////////////////////////////////////////////
  163. CPPClassTemplateParameter *CPPDeclaration::
  164. as_class_template_parameter() {
  165. return (CPPClassTemplateParameter *)NULL;
  166. }
  167. ////////////////////////////////////////////////////////////////////
  168. // Function: CPPDeclaration::as_typedef
  169. // Access: Public, Virtual
  170. // Description:
  171. ////////////////////////////////////////////////////////////////////
  172. CPPTypedef *CPPDeclaration::
  173. as_typedef() {
  174. return (CPPTypedef *)NULL;
  175. }
  176. ////////////////////////////////////////////////////////////////////
  177. // Function: CPPDeclaration::as_type_declaration
  178. // Access: Public, Virtual
  179. // Description:
  180. ////////////////////////////////////////////////////////////////////
  181. CPPTypeDeclaration *CPPDeclaration::
  182. as_type_declaration() {
  183. return (CPPTypeDeclaration *)NULL;
  184. }
  185. ////////////////////////////////////////////////////////////////////
  186. // Function: CPPDeclaration::as_expression
  187. // Access: Public, Virtual
  188. // Description:
  189. ////////////////////////////////////////////////////////////////////
  190. CPPExpression *CPPDeclaration::
  191. as_expression() {
  192. return (CPPExpression *)NULL;
  193. }
  194. ////////////////////////////////////////////////////////////////////
  195. // Function: CPPDeclaration::as_type
  196. // Access: Public, Virtual
  197. // Description:
  198. ////////////////////////////////////////////////////////////////////
  199. CPPType *CPPDeclaration::
  200. as_type() {
  201. return (CPPType *)NULL;
  202. }
  203. ////////////////////////////////////////////////////////////////////
  204. // Function: CPPDeclaration::as_namespace
  205. // Access: Public, Virtual
  206. // Description:
  207. ////////////////////////////////////////////////////////////////////
  208. CPPNamespace *CPPDeclaration::
  209. as_namespace() {
  210. return (CPPNamespace *)NULL;
  211. }
  212. ////////////////////////////////////////////////////////////////////
  213. // Function: CPPDeclaration::as_using
  214. // Access: Public, Virtual
  215. // Description:
  216. ////////////////////////////////////////////////////////////////////
  217. CPPUsing *CPPDeclaration::
  218. as_using() {
  219. return (CPPUsing *)NULL;
  220. }
  221. ////////////////////////////////////////////////////////////////////
  222. // Function: CPPDeclaration::as_simple_type
  223. // Access: Public, Virtual
  224. // Description:
  225. ////////////////////////////////////////////////////////////////////
  226. CPPSimpleType *CPPDeclaration::
  227. as_simple_type() {
  228. return (CPPSimpleType *)NULL;
  229. }
  230. ////////////////////////////////////////////////////////////////////
  231. // Function: CPPDeclaration::as_pointer_type
  232. // Access: Public, Virtual
  233. // Description:
  234. ////////////////////////////////////////////////////////////////////
  235. CPPPointerType *CPPDeclaration::
  236. as_pointer_type() {
  237. return (CPPPointerType *)NULL;
  238. }
  239. ////////////////////////////////////////////////////////////////////
  240. // Function: CPPDeclaration::as_reference_type
  241. // Access: Public, Virtual
  242. // Description:
  243. ////////////////////////////////////////////////////////////////////
  244. CPPReferenceType *CPPDeclaration::
  245. as_reference_type() {
  246. return (CPPReferenceType *)NULL;
  247. }
  248. ////////////////////////////////////////////////////////////////////
  249. // Function: CPPDeclaration::as_array_type
  250. // Access: Public, Virtual
  251. // Description:
  252. ////////////////////////////////////////////////////////////////////
  253. CPPArrayType *CPPDeclaration::
  254. as_array_type() {
  255. return (CPPArrayType *)NULL;
  256. }
  257. ////////////////////////////////////////////////////////////////////
  258. // Function: CPPDeclaration::as_const_type
  259. // Access: Public, Virtual
  260. // Description:
  261. ////////////////////////////////////////////////////////////////////
  262. CPPConstType *CPPDeclaration::
  263. as_const_type() {
  264. return (CPPConstType *)NULL;
  265. }
  266. ////////////////////////////////////////////////////////////////////
  267. // Function: CPPDeclaration::as_function_type
  268. // Access: Public, Virtual
  269. // Description:
  270. ////////////////////////////////////////////////////////////////////
  271. CPPFunctionType *CPPDeclaration::
  272. as_function_type() {
  273. return (CPPFunctionType *)NULL;
  274. }
  275. ////////////////////////////////////////////////////////////////////
  276. // Function: CPPDeclaration::as_function_group
  277. // Access: Public, Virtual
  278. // Description:
  279. ////////////////////////////////////////////////////////////////////
  280. CPPFunctionGroup *CPPDeclaration::
  281. as_function_group() {
  282. return (CPPFunctionGroup *)NULL;
  283. }
  284. ////////////////////////////////////////////////////////////////////
  285. // Function: CPPDeclaration::as_extension_type
  286. // Access: Public, Virtual
  287. // Description:
  288. ////////////////////////////////////////////////////////////////////
  289. CPPExtensionType *CPPDeclaration::
  290. as_extension_type() {
  291. return (CPPExtensionType *)NULL;
  292. }
  293. ////////////////////////////////////////////////////////////////////
  294. // Function: CPPDeclaration::as_struct_type
  295. // Access: Public, Virtual
  296. // Description:
  297. ////////////////////////////////////////////////////////////////////
  298. CPPStructType *CPPDeclaration::
  299. as_struct_type() {
  300. return (CPPStructType *)NULL;
  301. }
  302. ////////////////////////////////////////////////////////////////////
  303. // Function: CPPDeclaration::as_enum_type
  304. // Access: Public, Virtual
  305. // Description:
  306. ////////////////////////////////////////////////////////////////////
  307. CPPEnumType *CPPDeclaration::
  308. as_enum_type() {
  309. return (CPPEnumType *)NULL;
  310. }
  311. ////////////////////////////////////////////////////////////////////
  312. // Function: CPPDeclaration::as_tbd_type
  313. // Access: Public, Virtual
  314. // Description:
  315. ////////////////////////////////////////////////////////////////////
  316. CPPTBDType *CPPDeclaration::
  317. as_tbd_type() {
  318. return (CPPTBDType *)NULL;
  319. }
  320. ////////////////////////////////////////////////////////////////////
  321. // Function: CPPDeclaration::as_type_proxy
  322. // Access: Public, Virtual
  323. // Description:
  324. ////////////////////////////////////////////////////////////////////
  325. CPPTypeProxy *CPPDeclaration::
  326. as_type_proxy() {
  327. return (CPPTypeProxy *)NULL;
  328. }
  329. ////////////////////////////////////////////////////////////////////
  330. // Function: CPPDeclaration::is_equal
  331. // Access: Protected, Virtual
  332. // Description: Called by CPPDeclaration to determine whether this
  333. // type is equivalent to another type of the same type.
  334. ////////////////////////////////////////////////////////////////////
  335. bool CPPDeclaration::
  336. is_equal(const CPPDeclaration *other) const {
  337. return this == other;
  338. }
  339. ////////////////////////////////////////////////////////////////////
  340. // Function: CPPDeclaration::is_less
  341. // Access: Protected, Virtual
  342. // Description: Called by CPPDeclaration to determine whether this
  343. // type should be ordered before another type of the
  344. // same type, in an arbitrary but fixed ordering.
  345. ////////////////////////////////////////////////////////////////////
  346. bool CPPDeclaration::
  347. is_less(const CPPDeclaration *other) const {
  348. return this < other;
  349. }