cppTypedef.cxx 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Filename: cppTypedef.cxx
  2. // Created by: drose (19Oct99)
  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 "cppTypedef.h"
  19. ////////////////////////////////////////////////////////////////////
  20. // Function: CPPTypedef::Constructor
  21. // Access: Public
  22. // Description: Constructs a new CPPTypedef object based on the
  23. // indicated CPPInstance object. The CPPInstance is
  24. // deallocated.
  25. //
  26. // If global is true, the typedef is defined at the
  27. // global scope, and hence it's worth telling the type
  28. // itself about. Otherwise, it's just a locally-scoped
  29. // typedef.
  30. ////////////////////////////////////////////////////////////////////
  31. CPPTypedef::
  32. CPPTypedef(CPPInstance *inst, bool global) : CPPInstance(*inst)
  33. {
  34. // Actually, we'll avoid deleting this for now. It causes problems
  35. // for some reason to be determined later.
  36. // delete inst;
  37. assert(_type != NULL);
  38. if (global) {
  39. _type->_typedefs.push_back(this);
  40. CPPType::record_preferred_name_for(_type, inst->get_local_name());
  41. }
  42. }
  43. ////////////////////////////////////////////////////////////////////
  44. // Function: CPPTypedef::substitute_decl
  45. // Access: Public, Virtual
  46. // Description:
  47. ////////////////////////////////////////////////////////////////////
  48. CPPDeclaration *CPPTypedef::
  49. substitute_decl(CPPDeclaration::SubstDecl &subst,
  50. CPPScope *current_scope, CPPScope *global_scope) {
  51. CPPDeclaration *decl =
  52. CPPInstance::substitute_decl(subst, current_scope, global_scope);
  53. assert(decl != NULL);
  54. if (decl->as_typedef()) {
  55. return decl;
  56. }
  57. assert(decl->as_instance() != NULL);
  58. return new CPPTypedef(new CPPInstance(*decl->as_instance()), false);
  59. }
  60. ////////////////////////////////////////////////////////////////////
  61. // Function: CPPTypedef::output
  62. // Access: Public, Virtual
  63. // Description:
  64. ////////////////////////////////////////////////////////////////////
  65. void CPPTypedef::
  66. output(ostream &out, int indent_level, CPPScope *scope, bool) const {
  67. out << "typedef ";
  68. CPPInstance::output(out, indent_level, scope, false);
  69. }
  70. ////////////////////////////////////////////////////////////////////
  71. // Function: CPPTypedef::get_subtype
  72. // Access: Public, Virtual
  73. // Description:
  74. ////////////////////////////////////////////////////////////////////
  75. CPPDeclaration::SubType CPPTypedef::
  76. get_subtype() const {
  77. return ST_typedef;
  78. }
  79. ////////////////////////////////////////////////////////////////////
  80. // Function: CPPTypedef::as_typedef
  81. // Access: Public, Virtual
  82. // Description:
  83. ////////////////////////////////////////////////////////////////////
  84. CPPTypedef *CPPTypedef::
  85. as_typedef() {
  86. return this;
  87. }