namespace.h revision 1.1.1.5 1 1.1 christos /* Code dealing with "using" directives for GDB.
2 1.1.1.5 christos Copyright (C) 2003-2023 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 christos import statement represents a namespace.
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 christos /* Used during import search to temporarily mark this node as
100 1.1 christos searched. */
101 1.1 christos int searched;
102 1.1 christos
103 1.1 christos /* USING_DIRECT has variable allocation size according to the number of
104 1.1 christos EXCLUDES entries, the last entry is NULL. */
105 1.1 christos const char *excludes[1];
106 1.1 christos };
107 1.1 christos
108 1.1 christos extern void add_using_directive (struct using_direct **using_directives,
109 1.1 christos const char *dest,
110 1.1 christos const char *src,
111 1.1 christos const char *alias,
112 1.1 christos const char *declaration,
113 1.1.1.3 christos const std::vector<const char *> &excludes,
114 1.1 christos int copy_names,
115 1.1.1.5 christos struct obstack *obstack);
116 1.1 christos
117 1.1 christos #endif /* NAMESPACE_H */
118