cppDeclaration.cxx 13 KB

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