1 1.1 christos /* Code dealing with "using" directives for GDB. 2 1.1.1.6 christos Copyright (C) 2003-2024 Free Software Foundation, Inc. 3 1.1 christos 4 1.1 christos This file is part of GDB. 5 1.1 christos 6 1.1 christos This program is free software; you can redistribute it and/or modify 7 1.1 christos it under the terms of the GNU General Public License as published by 8 1.1 christos the Free Software Foundation; either version 3 of the License, or 9 1.1 christos (at your option) any later version. 10 1.1 christos 11 1.1 christos This program is distributed in the hope that it will be useful, 12 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 13 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 1.1 christos GNU General Public License for more details. 15 1.1 christos 16 1.1 christos You should have received a copy of the GNU General Public License 17 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 1.1 christos 19 1.1.1.7 christos #ifndef GDB_NAMESPACE_H 20 1.1.1.7 christos #define GDB_NAMESPACE_H 21 1.1 christos 22 1.1.1.5 christos #include "gdbsupport/gdb_obstack.h" 23 1.1 christos 24 1.1 christos /* This struct is designed to store data from using directives. It 25 1.1 christos says that names from namespace IMPORT_SRC should be visible within 26 1.1 christos namespace IMPORT_DEST. These form a linked list; NEXT is the next 27 1.1 christos element of the list. If the imported namespace or declaration has 28 1.1 christos been aliased within the IMPORT_DEST namespace, ALIAS is set to a 29 1.1 christos string representing the alias. Otherwise, ALIAS is NULL. 30 1.1 christos DECLARATION is the name of the imported declaration, if this import 31 1.1 christos statement represents one. Otherwise DECLARATION is NULL and this 32 1.1.1.6 christos import statement represents a namespace. DECL_LINE is the line 33 1.1.1.6 christos where the using directive is written in the source code. 34 1.1 christos 35 1.1 christos C++: using namespace A; 36 1.1 christos Fortran: use A 37 1.1 christos import_src = "A" 38 1.1 christos import_dest = local scope of the import statement even such as "" 39 1.1 christos alias = NULL 40 1.1 christos declaration = NULL 41 1.1 christos excludes = NULL 42 1.1 christos 43 1.1 christos C++: using A::x; 44 1.1 christos Fortran: use A, only: x 45 1.1 christos import_src = "A" 46 1.1 christos import_dest = local scope of the import statement even such as "" 47 1.1 christos alias = NULL 48 1.1 christos declaration = "x" 49 1.1 christos excludes = NULL 50 1.1 christos The declaration will get imported as import_dest::x. 51 1.1 christos 52 1.1 christos C++ has no way to import all names except those listed ones. 53 1.1 christos Fortran: use A, localname => x 54 1.1 christos import_src = "A" 55 1.1 christos import_dest = local scope of the import statement even such as "" 56 1.1 christos alias = "localname" 57 1.1 christos declaration = "x" 58 1.1 christos excludes = NULL 59 1.1 christos + 60 1.1 christos import_src = "A" 61 1.1 christos import_dest = local scope of the import statement even such as "" 62 1.1 christos alias = NULL 63 1.1 christos declaration = NULL 64 1.1 christos excludes = ["x"] 65 1.1 christos All the entries of A get imported except of "x". "x" gets imported as 66 1.1 christos "localname". "x" is not defined as a local name by this statement. 67 1.1 christos 68 1.1 christos C++: namespace LOCALNS = A; 69 1.1 christos Fortran has no way to address non-local namespace/module. 70 1.1 christos import_src = "A" 71 1.1 christos import_dest = local scope of the import statement even such as "" 72 1.1 christos alias = "LOCALNS" 73 1.1 christos declaration = NULL 74 1.1 christos excludes = NULL 75 1.1 christos The namespace will get imported as the import_dest::LOCALNS 76 1.1 christos namespace. 77 1.1 christos 78 1.1 christos C++ cannot express it, it would be something like: using localname 79 1.1 christos = A::x; 80 1.1 christos Fortran: use A, only localname => x 81 1.1 christos import_src = "A" 82 1.1 christos import_dest = local scope of the import statement even such as "" 83 1.1 christos alias = "localname" 84 1.1 christos declaration = "x" 85 1.1 christos excludes = NULL 86 1.1 christos The declaration will get imported as localname or 87 1.1 christos `import_dest`localname. */ 88 1.1 christos 89 1.1 christos struct using_direct 90 1.1 christos { 91 1.1 christos const char *import_src; 92 1.1 christos const char *import_dest; 93 1.1 christos 94 1.1 christos const char *alias; 95 1.1 christos const char *declaration; 96 1.1 christos 97 1.1 christos struct using_direct *next; 98 1.1 christos 99 1.1.1.6 christos /* The line where the using directive was declared on the source file. 100 1.1.1.6 christos This is used to check if the using directive is already active at the 101 1.1.1.6 christos point where the inferior is stopped. */ 102 1.1.1.6 christos unsigned int decl_line; 103 1.1.1.6 christos 104 1.1 christos /* Used during import search to temporarily mark this node as 105 1.1 christos searched. */ 106 1.1 christos int searched; 107 1.1 christos 108 1.1 christos /* USING_DIRECT has variable allocation size according to the number of 109 1.1 christos EXCLUDES entries, the last entry is NULL. */ 110 1.1 christos const char *excludes[1]; 111 1.1.1.6 christos 112 1.1.1.6 christos /* Returns true if the using_directive USING_DIR is valid in CURR_LINE. 113 1.1.1.6 christos Because current GCC (at least version 12.2) sets the decl_line as 114 1.1.1.6 christos the last line in the current block, we need to take this into 115 1.1.1.6 christos consideration when checking the validity, by comparing it to 116 1.1.1.6 christos BOUNDARY, the last line of the current block. */ 117 1.1.1.6 christos bool valid_line (unsigned int boundary) const; 118 1.1 christos }; 119 1.1 christos 120 1.1 christos extern void add_using_directive (struct using_direct **using_directives, 121 1.1 christos const char *dest, 122 1.1 christos const char *src, 123 1.1 christos const char *alias, 124 1.1 christos const char *declaration, 125 1.1.1.3 christos const std::vector<const char *> &excludes, 126 1.1.1.6 christos const unsigned int decl_line, 127 1.1.1.5 christos struct obstack *obstack); 128 1.1 christos 129 1.1.1.7 christos #endif /* GDB_NAMESPACE_H */ 130