cppTypeProxy.cxx 12 KB

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