namespace.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Code dealing with "using" directives for GDB.
  2. Copyright (C) 2003-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef NAMESPACE_H
  15. #define NAMESPACE_H
  16. #include "gdbsupport/gdb_vecs.h"
  17. #include "gdbsupport/gdb_obstack.h"
  18. /* This struct is designed to store data from using directives. It
  19. says that names from namespace IMPORT_SRC should be visible within
  20. namespace IMPORT_DEST. These form a linked list; NEXT is the next
  21. element of the list. If the imported namespace or declaration has
  22. been aliased within the IMPORT_DEST namespace, ALIAS is set to a
  23. string representing the alias. Otherwise, ALIAS is NULL.
  24. DECLARATION is the name of the imported declaration, if this import
  25. statement represents one. Otherwise DECLARATION is NULL and this
  26. import statement represents a namespace.
  27. C++: using namespace A;
  28. Fortran: use A
  29. import_src = "A"
  30. import_dest = local scope of the import statement even such as ""
  31. alias = NULL
  32. declaration = NULL
  33. excludes = NULL
  34. C++: using A::x;
  35. Fortran: use A, only: x
  36. import_src = "A"
  37. import_dest = local scope of the import statement even such as ""
  38. alias = NULL
  39. declaration = "x"
  40. excludes = NULL
  41. The declaration will get imported as import_dest::x.
  42. C++ has no way to import all names except those listed ones.
  43. Fortran: use A, localname => x
  44. import_src = "A"
  45. import_dest = local scope of the import statement even such as ""
  46. alias = "localname"
  47. declaration = "x"
  48. excludes = NULL
  49. +
  50. import_src = "A"
  51. import_dest = local scope of the import statement even such as ""
  52. alias = NULL
  53. declaration = NULL
  54. excludes = ["x"]
  55. All the entries of A get imported except of "x". "x" gets imported as
  56. "localname". "x" is not defined as a local name by this statement.
  57. C++: namespace LOCALNS = A;
  58. Fortran has no way to address non-local namespace/module.
  59. import_src = "A"
  60. import_dest = local scope of the import statement even such as ""
  61. alias = "LOCALNS"
  62. declaration = NULL
  63. excludes = NULL
  64. The namespace will get imported as the import_dest::LOCALNS
  65. namespace.
  66. C++ cannot express it, it would be something like: using localname
  67. = A::x;
  68. Fortran: use A, only localname => x
  69. import_src = "A"
  70. import_dest = local scope of the import statement even such as ""
  71. alias = "localname"
  72. declaration = "x"
  73. excludes = NULL
  74. The declaration will get imported as localname or
  75. `import_dest`localname. */
  76. struct using_direct
  77. {
  78. const char *import_src;
  79. const char *import_dest;
  80. const char *alias;
  81. const char *declaration;
  82. struct using_direct *next;
  83. /* Used during import search to temporarily mark this node as
  84. searched. */
  85. int searched;
  86. /* USING_DIRECT has variable allocation size according to the number of
  87. EXCLUDES entries, the last entry is NULL. */
  88. const char *excludes[1];
  89. };
  90. extern void add_using_directive (struct using_direct **using_directives,
  91. const char *dest,
  92. const char *src,
  93. const char *alias,
  94. const char *declaration,
  95. const std::vector<const char *> &excludes,
  96. int copy_names,
  97. struct obstack *obstack);
  98. #endif /* NAMESPACE_H */