cppTypeProxy.cxx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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 cppTypeProxy.cxx
  10. * @author drose
  11. * @date 1999-12-07
  12. */
  13. #include "cppTypeProxy.h"
  14. #include "cppFile.h"
  15. using std::string;
  16. /**
  17. *
  18. */
  19. CPPTypeProxy::
  20. CPPTypeProxy() :
  21. CPPType(CPPFile())
  22. {
  23. _actual_type = nullptr;
  24. }
  25. /**
  26. * If this CPPType object is a forward reference or other nonspecified
  27. * reference to a type that might now be known a real type, returns the real
  28. * type. Otherwise returns the type itself.
  29. */
  30. CPPType *CPPTypeProxy::
  31. resolve_type(CPPScope *, CPPScope *) {
  32. if (_actual_type == nullptr) {
  33. return this;
  34. }
  35. return _actual_type;
  36. }
  37. /**
  38. * Returns true if the type, or any nested type within the type, is a
  39. * CPPTBDType and thus isn't fully determined right now. In this case,
  40. * calling resolve_type() may or may not resolve the type.
  41. */
  42. bool CPPTypeProxy::
  43. is_tbd() const {
  44. if (_actual_type == nullptr) {
  45. return false;
  46. }
  47. return _actual_type->is_tbd();
  48. }
  49. /**
  50. * Returns true if the type has even been typedef'ed and therefore has a
  51. * simple name available to stand for it. Extension types are all implicitly
  52. * typedef'ed on declaration.
  53. */
  54. bool CPPTypeProxy::
  55. has_typedef_name() const {
  56. if (_actual_type == nullptr) {
  57. return false;
  58. }
  59. return _actual_type->has_typedef_name();
  60. }
  61. /**
  62. * Returns a string that can be used to name the type, if has_typedef_name()
  63. * returned true. This will be the first typedef name applied to the type.
  64. */
  65. string CPPTypeProxy::
  66. get_typedef_name(CPPScope *) const {
  67. if (_actual_type == nullptr) {
  68. return string();
  69. }
  70. return _actual_type->get_typedef_name();
  71. }
  72. /**
  73. * Returns a fundametal one-word name for the type. This name will not
  74. * include any scoping operators or template parameters, so it may not be a
  75. * compilable reference to the type.
  76. */
  77. string CPPTypeProxy::
  78. get_simple_name() const {
  79. if (_actual_type == nullptr) {
  80. return "unknown";
  81. }
  82. return _actual_type->get_simple_name();
  83. }
  84. /**
  85. * Returns the compilable, correct name for this type within the indicated
  86. * scope. If the scope is NULL, within the scope the type is declared in.
  87. */
  88. string CPPTypeProxy::
  89. get_local_name(CPPScope *scope) const {
  90. if (_actual_type == nullptr) {
  91. return "unknown";
  92. }
  93. return _actual_type->get_local_name(scope);
  94. }
  95. /**
  96. * Returns the compilable, correct name for the type, with completely explicit
  97. * scoping.
  98. */
  99. string CPPTypeProxy::
  100. get_fully_scoped_name() const {
  101. if (_actual_type == nullptr) {
  102. return "unknown";
  103. }
  104. return _actual_type->get_fully_scoped_name();
  105. }
  106. /**
  107. * Returns the best name to use for the type from a programmer's point of
  108. * view. This will typically be a typedef name if one is available, or the
  109. * full C++ name if it is not. The typedef may or may not be visible within
  110. * the current scope, so this type name may not be compilable.
  111. */
  112. string CPPTypeProxy::
  113. get_preferred_name() const {
  114. if (_actual_type == nullptr) {
  115. return "unknown";
  116. }
  117. return _actual_type->get_preferred_name();
  118. }
  119. /**
  120. * Returns true if the type has not yet been fully specified, false if it has.
  121. */
  122. bool CPPTypeProxy::
  123. is_incomplete() const {
  124. if (_actual_type == nullptr) {
  125. return true;
  126. }
  127. return _actual_type->is_incomplete();
  128. }
  129. /**
  130. * Formats a C++-looking line that defines an instance of the given type, with
  131. * the indicated name. In most cases this will be "type name", but some types
  132. * have special exceptions.
  133. */
  134. void CPPTypeProxy::
  135. output_instance(std::ostream &out, int indent_level, CPPScope *scope,
  136. bool complete, const string &prename,
  137. const string &name) const {
  138. if (_actual_type == nullptr) {
  139. out << "unknown " << prename << name;
  140. return;
  141. }
  142. _actual_type->output_instance(out, indent_level, scope, complete,
  143. prename, name);
  144. }
  145. /**
  146. *
  147. */
  148. void CPPTypeProxy::
  149. output(std::ostream &out, int indent_level, CPPScope *scope, bool complete) const {
  150. if (_actual_type == nullptr) {
  151. out << "unknown";
  152. return;
  153. }
  154. _actual_type->output(out, indent_level, scope, complete);
  155. }
  156. /**
  157. *
  158. */
  159. CPPDeclaration::SubType CPPTypeProxy::
  160. get_subtype() const {
  161. return ST_type_proxy;
  162. }
  163. /**
  164. *
  165. */
  166. CPPType *CPPTypeProxy::
  167. as_type() {
  168. if (_actual_type == nullptr) {
  169. return this;
  170. }
  171. return _actual_type;
  172. }
  173. /**
  174. *
  175. */
  176. CPPSimpleType *CPPTypeProxy::
  177. as_simple_type() {
  178. if (_actual_type == nullptr) {
  179. return nullptr;
  180. }
  181. return _actual_type->as_simple_type();
  182. }
  183. /**
  184. *
  185. */
  186. CPPPointerType *CPPTypeProxy::
  187. as_pointer_type() {
  188. if (_actual_type == nullptr) {
  189. return nullptr;
  190. }
  191. return _actual_type->as_pointer_type();
  192. }
  193. /**
  194. *
  195. */
  196. CPPReferenceType *CPPTypeProxy::
  197. as_reference_type() {
  198. if (_actual_type == nullptr) {
  199. return nullptr;
  200. }
  201. return _actual_type->as_reference_type();
  202. }
  203. /**
  204. *
  205. */
  206. CPPArrayType *CPPTypeProxy::
  207. as_array_type() {
  208. if (_actual_type == nullptr) {
  209. return nullptr;
  210. }
  211. return _actual_type->as_array_type();
  212. }
  213. /**
  214. *
  215. */
  216. CPPConstType *CPPTypeProxy::
  217. as_const_type() {
  218. if (_actual_type == nullptr) {
  219. return nullptr;
  220. }
  221. return _actual_type->as_const_type();
  222. }
  223. /**
  224. *
  225. */
  226. CPPFunctionType *CPPTypeProxy::
  227. as_function_type() {
  228. if (_actual_type == nullptr) {
  229. return nullptr;
  230. }
  231. return _actual_type->as_function_type();
  232. }
  233. /**
  234. *
  235. */
  236. CPPExtensionType *CPPTypeProxy::
  237. as_extension_type() {
  238. if (_actual_type == nullptr) {
  239. return nullptr;
  240. }
  241. return _actual_type->as_extension_type();
  242. }
  243. /**
  244. *
  245. */
  246. CPPStructType *CPPTypeProxy::
  247. as_struct_type() {
  248. if (_actual_type == nullptr) {
  249. return nullptr;
  250. }
  251. return _actual_type->as_struct_type();
  252. }
  253. /**
  254. *
  255. */
  256. CPPEnumType *CPPTypeProxy::
  257. as_enum_type() {
  258. if (_actual_type == nullptr) {
  259. return nullptr;
  260. }
  261. return _actual_type->as_enum_type();
  262. }
  263. /**
  264. *
  265. */
  266. CPPTBDType *CPPTypeProxy::
  267. as_tbd_type() {
  268. if (_actual_type == nullptr) {
  269. return nullptr;
  270. }
  271. return _actual_type->as_tbd_type();
  272. }
  273. /**
  274. *
  275. */
  276. CPPTypedefType *CPPTypeProxy::
  277. as_typedef_type() {
  278. if (_actual_type == nullptr) {
  279. return nullptr;
  280. }
  281. return _actual_type->as_typedef_type();
  282. }
  283. /**
  284. *
  285. */
  286. CPPTypeProxy *CPPTypeProxy::
  287. as_type_proxy() {
  288. return this;
  289. }