cppNamespace.cxx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Filename: cppNamespace.cxx
  2. // Created by: drose (16Nov99)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #include "cppNamespace.h"
  15. #include "cppIdentifier.h"
  16. #include "cppScope.h"
  17. #include "indent.h"
  18. ////////////////////////////////////////////////////////////////////
  19. // Function: CPPNamespace::Constructor
  20. // Access: Public
  21. // Description:
  22. ////////////////////////////////////////////////////////////////////
  23. CPPNamespace::
  24. CPPNamespace(CPPIdentifier *ident, CPPScope *scope, const CPPFile &file) :
  25. CPPDeclaration(file),
  26. _ident(ident),
  27. _scope(scope),
  28. _is_inline(false)
  29. {
  30. }
  31. ////////////////////////////////////////////////////////////////////
  32. // Function: CPPNamespace::get_simple_name
  33. // Access: Public
  34. // Description:
  35. ////////////////////////////////////////////////////////////////////
  36. string CPPNamespace::
  37. get_simple_name() const {
  38. if (_ident == NULL) {
  39. return "";
  40. }
  41. return _ident->get_simple_name();
  42. }
  43. ////////////////////////////////////////////////////////////////////
  44. // Function: CPPNamespace::get_local_name
  45. // Access: Public
  46. // Description:
  47. ////////////////////////////////////////////////////////////////////
  48. string CPPNamespace::
  49. get_local_name(CPPScope *scope) const {
  50. if (_ident == NULL) {
  51. return "";
  52. }
  53. return _ident->get_local_name(scope);
  54. }
  55. ////////////////////////////////////////////////////////////////////
  56. // Function: CPPNamespace::get_fully_scoped_name
  57. // Access: Public
  58. // Description:
  59. ////////////////////////////////////////////////////////////////////
  60. string CPPNamespace::
  61. get_fully_scoped_name() const {
  62. if (_ident == NULL) {
  63. return "";
  64. }
  65. return _ident->get_fully_scoped_name();
  66. }
  67. ////////////////////////////////////////////////////////////////////
  68. // Function: CPPNamespace::get_scope
  69. // Access: Public
  70. // Description:
  71. ////////////////////////////////////////////////////////////////////
  72. CPPScope *CPPNamespace::
  73. get_scope() const {
  74. return _scope;
  75. }
  76. ////////////////////////////////////////////////////////////////////
  77. // Function: CPPNamespace::output
  78. // Access: Public, Virtual
  79. // Description:
  80. ////////////////////////////////////////////////////////////////////
  81. void CPPNamespace::
  82. output(ostream &out, int indent_level, CPPScope *scope, bool complete) const {
  83. if (_is_inline) {
  84. out << "inline ";
  85. }
  86. if (!complete && _ident != NULL) {
  87. // If we have a name, use it.
  88. out << "namespace " << _ident->get_local_name(scope);
  89. } else {
  90. if (_ident != NULL) {
  91. out << "namespace " << _ident->get_local_name(scope) << " {\n";
  92. } else {
  93. out << "namespace {\n";
  94. }
  95. _scope->write(out, indent_level + 2, _scope);
  96. indent(out, indent_level) << "}";
  97. }
  98. }
  99. ////////////////////////////////////////////////////////////////////
  100. // Function: CPPNamespace::get_subtype
  101. // Access: Public, Virtual
  102. // Description:
  103. ////////////////////////////////////////////////////////////////////
  104. CPPDeclaration::SubType CPPNamespace::
  105. get_subtype() const {
  106. return ST_namespace;
  107. }
  108. ////////////////////////////////////////////////////////////////////
  109. // Function: CPPNamespace::as_namespace
  110. // Access: Public, Virtual
  111. // Description:
  112. ////////////////////////////////////////////////////////////////////
  113. CPPNamespace *CPPNamespace::
  114. as_namespace() {
  115. return this;
  116. }