cppDeclaration.cxx 6.0 KB

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