namespace.h revision 1.1.1.6 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 christos #ifndef NAMESPACE_H
20 1.1 christos #define NAMESPACE_H
21 1.1 christos
22 1.1.1.4 christos #include "gdbsupport/gdb_vecs.h"
23 1.1.1.5 christos #include "gdbsupport/gdb_obstack.h"
24 1.1 christos
25 1.1 christos /* This struct is designed to store data from using directives. It
26 1.1 christos says that names from namespace IMPORT_SRC should be visible within
27 1.1 christos namespace IMPORT_DEST. These form a linked list; NEXT is the next
28 1.1 christos element of the list. If the imported namespace or declaration has
29 1.1 christos been aliased within the IMPORT_DEST namespace, ALIAS is set to a
30 1.1 christos string representing the alias. Otherwise, ALIAS is NULL.
31 1.1 christos DECLARATION is the name of the imported declaration, if this import
32 1.1 christos statement represents one. Otherwise DECLARATION is NULL and this
33 1.1.1.6 christos import statement represents a namespace. DECL_LINE is the line
34 1.1.1.6 christos where the using directive is written in the source code.
35 1.1 christos
36 1.1 christos C++: using namespace A;
37 1.1 christos Fortran: use A
38 1.1 christos import_src = "A"
39 1.1 christos import_dest = local scope of the import statement even such as ""
40 1.1 christos alias = NULL
41 1.1 christos declaration = NULL
42 1.1 christos excludes = NULL
43 1.1 christos
44 1.1 christos C++: using A::x;
45 1.1 christos Fortran: use A, only: x
46 1.1 christos import_src = "A"
47 1.1 christos import_dest = local scope of the import statement even such as ""
48 1.1 christos alias = NULL
49 1.1 christos declaration = "x"
50 1.1 christos excludes = NULL
51 1.1 christos The declaration will get imported as import_dest::x.
52 1.1 christos
53 1.1 christos C++ has no way to import all names except those listed ones.
54 1.1 christos Fortran: use A, localname => x
55 1.1 christos import_src = "A"
56 1.1 christos import_dest = local scope of the import statement even such as ""
57 1.1 christos alias = "localname"
58 1.1 christos declaration = "x"
59 1.1 christos excludes = NULL
60 1.1 christos +
61 1.1 christos import_src = "A"
62 1.1 christos import_dest = local scope of the import statement even such as ""
63 1.1 christos alias = NULL
64 1.1 christos declaration = NULL
65 1.1 christos excludes = ["x"]
66 1.1 christos All the entries of A get imported except of "x". "x" gets imported as
67 1.1 christos "localname". "x" is not defined as a local name by this statement.
68 1.1 christos
69 1.1 christos C++: namespace LOCALNS = A;
70 1.1 christos Fortran has no way to address non-local namespace/module.
71 1.1 christos import_src = "A"
72 1.1 christos import_dest = local scope of the import statement even such as ""
73 1.1 christos alias = "LOCALNS"
74 1.1 christos declaration = NULL
75 1.1 christos excludes = NULL
76 1.1 christos The namespace will get imported as the import_dest::LOCALNS
77 1.1 christos namespace.
78 1.1 christos
79 1.1 christos C++ cannot express it, it would be something like: using localname
80 1.1 christos = A::x;
81 1.1 christos Fortran: use A, only localname => x
82 1.1 christos import_src = "A"
83 1.1 christos import_dest = local scope of the import statement even such as ""
84 1.1 christos alias = "localname"
85 1.1 christos declaration = "x"
86 1.1 christos excludes = NULL
87 1.1 christos The declaration will get imported as localname or
88 1.1 christos `import_dest`localname. */
89 1.1 christos
90 1.1 christos struct using_direct
91 1.1 christos {
92 1.1 christos const char *import_src;
93 1.1 christos const char *import_dest;
94 1.1 christos
95 1.1 christos const char *alias;
96 1.1 christos const char *declaration;
97 1.1 christos
98 1.1 christos struct using_direct *next;
99 1.1 christos
100 1.1.1.6 christos /* The line where the using directive was declared on the source file.
101 1.1.1.6 christos This is used to check if the using directive is already active at the
102 1.1.1.6 christos point where the inferior is stopped. */
103 1.1.1.6 christos unsigned int decl_line;
104 1.1.1.6 christos
105 1.1 christos /* Used during import search to temporarily mark this node as
106 1.1 christos searched. */
107 1.1 christos int searched;
108 1.1 christos
109 1.1 christos /* USING_DIRECT has variable allocation size according to the number of
110 1.1 christos EXCLUDES entries, the last entry is NULL. */
111 1.1 christos const char *excludes[1];
112 1.1.1.6 christos
113 1.1.1.6 christos /* Returns true if the using_directive USING_DIR is valid in CURR_LINE.
114 1.1.1.6 christos Because current GCC (at least version 12.2) sets the decl_line as
115 1.1.1.6 christos the last line in the current block, we need to take this into
116 1.1.1.6 christos consideration when checking the validity, by comparing it to
117 1.1.1.6 christos BOUNDARY, the last line of the current block. */
118 1.1.1.6 christos bool valid_line (unsigned int boundary) const;
119 1.1 christos };
120 1.1 christos
121 1.1 christos extern void add_using_directive (struct using_direct **using_directives,
122 1.1 christos const char *dest,
123 1.1 christos const char *src,
124 1.1 christos const char *alias,
125 1.1 christos const char *declaration,
126 1.1.1.3 christos const std::vector<const char *> &excludes,
127 1.1.1.6 christos const unsigned int decl_line,
128 1.1.1.5 christos struct obstack *obstack);
129 1.1 christos
130 1.1 christos #endif /* NAMESPACE_H */
131