cppNamespace.cxx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Filename: cppNamespace.cxx
  2. // Created by: drose (16Nov99)
  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 "cppNamespace.h"
  19. #include "cppIdentifier.h"
  20. #include "cppScope.h"
  21. #include "indent.h"
  22. ////////////////////////////////////////////////////////////////////
  23. // Function: CPPNamespace::Constructor
  24. // Access: Public
  25. // Description:
  26. ////////////////////////////////////////////////////////////////////
  27. CPPNamespace::
  28. CPPNamespace(CPPIdentifier *ident, CPPScope *scope, const CPPFile &file) :
  29. CPPDeclaration(file),
  30. _ident(ident), _scope(scope)
  31. {
  32. }
  33. ////////////////////////////////////////////////////////////////////
  34. // Function: CPPNamespace::get_simple_name
  35. // Access: Public
  36. // Description:
  37. ////////////////////////////////////////////////////////////////////
  38. string CPPNamespace::
  39. get_simple_name() const {
  40. if (_ident == NULL) {
  41. return "";
  42. }
  43. return _ident->get_simple_name();
  44. }
  45. ////////////////////////////////////////////////////////////////////
  46. // Function: CPPNamespace::get_local_name
  47. // Access: Public
  48. // Description:
  49. ////////////////////////////////////////////////////////////////////
  50. string CPPNamespace::
  51. get_local_name(CPPScope *scope) const {
  52. if (_ident == NULL) {
  53. return "";
  54. }
  55. return _ident->get_local_name(scope);
  56. }
  57. ////////////////////////////////////////////////////////////////////
  58. // Function: CPPNamespace::get_fully_scoped_name
  59. // Access: Public
  60. // Description:
  61. ////////////////////////////////////////////////////////////////////
  62. string CPPNamespace::
  63. get_fully_scoped_name() const {
  64. if (_ident == NULL) {
  65. return "";
  66. }
  67. return _ident->get_fully_scoped_name();
  68. }
  69. ////////////////////////////////////////////////////////////////////
  70. // Function: CPPNamespace::get_scope
  71. // Access: Public
  72. // Description:
  73. ////////////////////////////////////////////////////////////////////
  74. CPPScope *CPPNamespace::
  75. get_scope() const {
  76. return _scope;
  77. }
  78. ////////////////////////////////////////////////////////////////////
  79. // Function: CPPNamespace::output
  80. // Access: Public, Virtual
  81. // Description:
  82. ////////////////////////////////////////////////////////////////////
  83. void CPPNamespace::
  84. output(ostream &out, int indent_level, CPPScope *scope, bool complete) const {
  85. if (!complete && _ident != NULL) {
  86. // If we have a name, use it.
  87. out << "namespace " << _ident->get_local_name(scope);
  88. } else {
  89. if (_ident != NULL) {
  90. out << "namespace " << _ident->get_local_name(scope) << " {\n";
  91. } else {
  92. out << "namespace {\n";
  93. }
  94. _scope->write(out, indent_level + 2, _scope);
  95. indent(out, indent_level) << "}";
  96. }
  97. }
  98. ////////////////////////////////////////////////////////////////////
  99. // Function: CPPNamespace::get_subtype
  100. // Access: Public, Virtual
  101. // Description:
  102. ////////////////////////////////////////////////////////////////////
  103. CPPDeclaration::SubType CPPNamespace::
  104. get_subtype() const {
  105. return ST_namespace;
  106. }
  107. ////////////////////////////////////////////////////////////////////
  108. // Function: CPPNamespace::as_namespace
  109. // Access: Public, Virtual
  110. // Description:
  111. ////////////////////////////////////////////////////////////////////
  112. CPPNamespace *CPPNamespace::
  113. as_namespace() {
  114. return this;
  115. }