cppDeclaration.cxx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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.cxx
  10. * @author drose
  11. * @date 1999-10-19
  12. */
  13. #include "cppDeclaration.h"
  14. #include "cppPreprocessor.h"
  15. /**
  16. *
  17. */
  18. CPPDeclaration::
  19. CPPDeclaration(const CPPFile &file) :
  20. _file(file)
  21. {
  22. _vis = V_unknown;
  23. _template_scope = NULL;
  24. _leading_comment = (CPPCommentBlock *)NULL;
  25. }
  26. /**
  27. *
  28. */
  29. CPPDeclaration::
  30. CPPDeclaration(const CPPDeclaration &copy) :
  31. _vis(copy._vis),
  32. _template_scope(copy._template_scope),
  33. _file(copy._file),
  34. _leading_comment(copy._leading_comment)
  35. {
  36. }
  37. /**
  38. *
  39. */
  40. CPPDeclaration &CPPDeclaration::
  41. operator = (const CPPDeclaration &copy) {
  42. _vis = copy._vis;
  43. _template_scope = copy._template_scope;
  44. _file = copy._file;
  45. _leading_comment = copy._leading_comment;
  46. return *this;
  47. }
  48. /**
  49. *
  50. */
  51. bool CPPDeclaration::
  52. operator == (const CPPDeclaration &other) const {
  53. if (get_subtype() != other.get_subtype()) {
  54. return false;
  55. }
  56. return is_equal(&other);
  57. }
  58. /**
  59. *
  60. */
  61. bool CPPDeclaration::
  62. operator != (const CPPDeclaration &other) const {
  63. return !(*this == other);
  64. }
  65. /**
  66. *
  67. */
  68. bool CPPDeclaration::
  69. operator < (const CPPDeclaration &other) const {
  70. if (get_subtype() != other.get_subtype()) {
  71. return get_subtype() < other.get_subtype();
  72. }
  73. return is_less(&other);
  74. }
  75. /**
  76. * Returns true if this is a template declaration of some kind: a template
  77. * function or a template class, typically.
  78. */
  79. bool CPPDeclaration::
  80. is_template() const {
  81. return _template_scope != NULL;
  82. }
  83. /**
  84. * If is_template(), above, returns true, this returns the CPPTemplateScope in
  85. * which this particular template declaration is defined. This scope includes
  86. * the information about the template parameters.
  87. */
  88. CPPTemplateScope *CPPDeclaration::
  89. get_template_scope() const {
  90. return _template_scope;
  91. }
  92. /**
  93. * Returns true if this declaration is an actual, factual declaration, or
  94. * false if some part of the declaration depends on a template parameter which
  95. * has not yet been instantiated.
  96. */
  97. bool CPPDeclaration::
  98. is_fully_specified() const {
  99. return !is_template();
  100. }
  101. /**
  102. *
  103. */
  104. CPPDeclaration *CPPDeclaration::
  105. instantiate(const CPPTemplateParameterList *,
  106. CPPScope *, CPPScope *,
  107. CPPPreprocessor *error_sink) const {
  108. if (error_sink != NULL) {
  109. error_sink->warning("Ignoring template parameters");
  110. }
  111. return (CPPDeclaration *)this;
  112. }
  113. /**
  114. *
  115. */
  116. CPPDeclaration *CPPDeclaration::
  117. substitute_decl(SubstDecl &subst, CPPScope *, CPPScope *) {
  118. SubstDecl::const_iterator si = subst.find(this);
  119. if (si != subst.end()) {
  120. assert((*si).second != NULL);
  121. return (*si).second;
  122. }
  123. return this;
  124. }
  125. /**
  126. *
  127. */
  128. CPPInstance *CPPDeclaration::
  129. as_instance() {
  130. return (CPPInstance *)NULL;
  131. }
  132. /**
  133. *
  134. */
  135. CPPClassTemplateParameter *CPPDeclaration::
  136. as_class_template_parameter() {
  137. return (CPPClassTemplateParameter *)NULL;
  138. }
  139. /**
  140. *
  141. */
  142. CPPTypedefType *CPPDeclaration::
  143. as_typedef_type() {
  144. return (CPPTypedefType *)NULL;
  145. }
  146. /**
  147. *
  148. */
  149. CPPTypeDeclaration *CPPDeclaration::
  150. as_type_declaration() {
  151. return (CPPTypeDeclaration *)NULL;
  152. }
  153. /**
  154. *
  155. */
  156. CPPExpression *CPPDeclaration::
  157. as_expression() {
  158. return (CPPExpression *)NULL;
  159. }
  160. /**
  161. *
  162. */
  163. CPPType *CPPDeclaration::
  164. as_type() {
  165. return (CPPType *)NULL;
  166. }
  167. /**
  168. *
  169. */
  170. CPPNamespace *CPPDeclaration::
  171. as_namespace() {
  172. return (CPPNamespace *)NULL;
  173. }
  174. /**
  175. *
  176. */
  177. CPPUsing *CPPDeclaration::
  178. as_using() {
  179. return (CPPUsing *)NULL;
  180. }
  181. /**
  182. *
  183. */
  184. CPPSimpleType *CPPDeclaration::
  185. as_simple_type() {
  186. return (CPPSimpleType *)NULL;
  187. }
  188. /**
  189. *
  190. */
  191. CPPPointerType *CPPDeclaration::
  192. as_pointer_type() {
  193. return (CPPPointerType *)NULL;
  194. }
  195. /**
  196. *
  197. */
  198. CPPReferenceType *CPPDeclaration::
  199. as_reference_type() {
  200. return (CPPReferenceType *)NULL;
  201. }
  202. /**
  203. *
  204. */
  205. CPPArrayType *CPPDeclaration::
  206. as_array_type() {
  207. return (CPPArrayType *)NULL;
  208. }
  209. /**
  210. *
  211. */
  212. CPPConstType *CPPDeclaration::
  213. as_const_type() {
  214. return (CPPConstType *)NULL;
  215. }
  216. /**
  217. *
  218. */
  219. CPPFunctionType *CPPDeclaration::
  220. as_function_type() {
  221. return (CPPFunctionType *)NULL;
  222. }
  223. /**
  224. *
  225. */
  226. CPPFunctionGroup *CPPDeclaration::
  227. as_function_group() {
  228. return (CPPFunctionGroup *)NULL;
  229. }
  230. /**
  231. *
  232. */
  233. CPPExtensionType *CPPDeclaration::
  234. as_extension_type() {
  235. return (CPPExtensionType *)NULL;
  236. }
  237. /**
  238. *
  239. */
  240. CPPStructType *CPPDeclaration::
  241. as_struct_type() {
  242. return (CPPStructType *)NULL;
  243. }
  244. /**
  245. *
  246. */
  247. CPPEnumType *CPPDeclaration::
  248. as_enum_type() {
  249. return (CPPEnumType *)NULL;
  250. }
  251. /**
  252. *
  253. */
  254. CPPTBDType *CPPDeclaration::
  255. as_tbd_type() {
  256. return (CPPTBDType *)NULL;
  257. }
  258. /**
  259. *
  260. */
  261. CPPTypeProxy *CPPDeclaration::
  262. as_type_proxy() {
  263. return (CPPTypeProxy *)NULL;
  264. }
  265. /**
  266. *
  267. */
  268. CPPMakeProperty *CPPDeclaration::
  269. as_make_property() {
  270. return (CPPMakeProperty *)NULL;
  271. }
  272. /**
  273. *
  274. */
  275. CPPMakeSeq *CPPDeclaration::
  276. as_make_seq() {
  277. return (CPPMakeSeq *)NULL;
  278. }
  279. /**
  280. * Called by CPPDeclaration to determine whether this type is equivalent to
  281. * another type of the same type.
  282. */
  283. bool CPPDeclaration::
  284. is_equal(const CPPDeclaration *other) const {
  285. return this == other;
  286. }
  287. /**
  288. * Called by CPPDeclaration to determine whether this type should be ordered
  289. * before another type of the same type, in an arbitrary but fixed ordering.
  290. */
  291. bool CPPDeclaration::
  292. is_less(const CPPDeclaration *other) const {
  293. return this < other;
  294. }
  295. ostream &
  296. operator << (ostream &out, const CPPDeclaration::SubstDecl &subst) {
  297. CPPDeclaration::SubstDecl::const_iterator it;
  298. for (it = subst.begin(); it != subst.end(); ++it) {
  299. out << " ";
  300. if (it->first == NULL) {
  301. out << "(null)";
  302. } else {
  303. out << *(it->first);
  304. }
  305. out << " -> ";
  306. if (it->second == NULL) {
  307. out << "(null)";
  308. } else {
  309. out << *(it->second);
  310. }
  311. out << "\n";
  312. }
  313. return out;
  314. }