]>
Commit | Line | Data |
---|---|---|
22cee43f | 1 | /* Code dealing with "using" directives for GDB. |
1d506c26 | 2 | Copyright (C) 2003-2024 Free Software Foundation, Inc. |
22cee43f PMR |
3 | |
4 | This file is part of GDB. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 3 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
18 | ||
19 | #include "defs.h" | |
20 | #include "namespace.h" | |
68ce1575 | 21 | #include "frame.h" |
83b6e1f1 | 22 | #include "symtab.h" |
22cee43f PMR |
23 | |
24 | /* Add a using directive to USING_DIRECTIVES. If the using directive | |
25 | in question has already been added, don't add it twice. | |
26 | ||
27 | Create a new struct using_direct which imports the namespace SRC | |
28 | into the scope DEST. ALIAS is the name of the imported namespace | |
29 | in the current scope. If ALIAS is NULL then the namespace is known | |
30 | by its original name. DECLARATION is the name if the imported | |
85102364 | 31 | variable if this is a declaration import (Eg. using A::x), otherwise |
22cee43f PMR |
32 | it is NULL. EXCLUDES is a list of names not to import from an |
33 | imported module or NULL. If COPY_NAMES is non-zero, then the | |
34 | arguments are copied into newly allocated memory so they can be | |
791b7405 AB |
35 | temporaries. For EXCLUDES the contents of the vector are copied, |
36 | but the pointed to characters are not copied. */ | |
22cee43f PMR |
37 | |
38 | void | |
39 | add_using_directive (struct using_direct **using_directives, | |
40 | const char *dest, | |
41 | const char *src, | |
42 | const char *alias, | |
43 | const char *declaration, | |
eb1e02fd | 44 | const std::vector<const char *> &excludes, |
68ce1575 | 45 | unsigned int decl_line, |
22cee43f PMR |
46 | int copy_names, |
47 | struct obstack *obstack) | |
48 | { | |
49 | struct using_direct *current; | |
50 | struct using_direct *newobj; | |
224c3ddb | 51 | int alloc_len; |
22cee43f PMR |
52 | |
53 | /* Has it already been added? */ | |
54 | ||
55 | for (current = *using_directives; current != NULL; current = current->next) | |
56 | { | |
57 | int ix; | |
22cee43f PMR |
58 | |
59 | if (strcmp (current->import_src, src) != 0) | |
60 | continue; | |
61 | if (strcmp (current->import_dest, dest) != 0) | |
62 | continue; | |
63 | if ((alias == NULL && current->alias != NULL) | |
64 | || (alias != NULL && current->alias == NULL) | |
65 | || (alias != NULL && current->alias != NULL | |
66 | && strcmp (alias, current->alias) != 0)) | |
67 | continue; | |
68 | if ((declaration == NULL && current->declaration != NULL) | |
69 | || (declaration != NULL && current->declaration == NULL) | |
70 | || (declaration != NULL && current->declaration != NULL | |
71 | && strcmp (declaration, current->declaration) != 0)) | |
72 | continue; | |
73 | ||
74 | /* Compare the contents of EXCLUDES. */ | |
eb1e02fd | 75 | for (ix = 0; ix < excludes.size (); ++ix) |
22cee43f | 76 | if (current->excludes[ix] == NULL |
eb1e02fd | 77 | || strcmp (excludes[ix], current->excludes[ix]) != 0) |
22cee43f | 78 | break; |
eb1e02fd | 79 | if (ix < excludes.size () || current->excludes[ix] != NULL) |
22cee43f PMR |
80 | continue; |
81 | ||
68ce1575 BL |
82 | if (decl_line != current->decl_line) |
83 | continue; | |
84 | ||
22cee43f PMR |
85 | /* Parameters exactly match CURRENT. */ |
86 | return; | |
87 | } | |
88 | ||
224c3ddb | 89 | alloc_len = (sizeof(*newobj) |
eb1e02fd | 90 | + (excludes.size () * sizeof(*newobj->excludes))); |
224c3ddb | 91 | newobj = (struct using_direct *) obstack_alloc (obstack, alloc_len); |
22cee43f PMR |
92 | memset (newobj, 0, sizeof (*newobj)); |
93 | ||
94 | if (copy_names) | |
95 | { | |
021887d8 TT |
96 | newobj->import_src = obstack_strdup (obstack, src); |
97 | newobj->import_dest = obstack_strdup (obstack, dest); | |
22cee43f PMR |
98 | } |
99 | else | |
100 | { | |
101 | newobj->import_src = src; | |
102 | newobj->import_dest = dest; | |
103 | } | |
104 | ||
105 | if (alias != NULL && copy_names) | |
021887d8 | 106 | newobj->alias = obstack_strdup (obstack, alias); |
22cee43f PMR |
107 | else |
108 | newobj->alias = alias; | |
109 | ||
110 | if (declaration != NULL && copy_names) | |
021887d8 | 111 | newobj->declaration = obstack_strdup (obstack, declaration); |
22cee43f PMR |
112 | else |
113 | newobj->declaration = declaration; | |
114 | ||
10657c04 TT |
115 | if (!excludes.empty ()) |
116 | memcpy (newobj->excludes, excludes.data (), | |
117 | excludes.size () * sizeof (*newobj->excludes)); | |
eb1e02fd | 118 | newobj->excludes[excludes.size ()] = NULL; |
22cee43f | 119 | |
68ce1575 BL |
120 | newobj->decl_line = decl_line; |
121 | ||
22cee43f PMR |
122 | newobj->next = *using_directives; |
123 | *using_directives = newobj; | |
124 | } | |
68ce1575 BL |
125 | |
126 | /* See namespace.h. */ | |
127 | ||
128 | bool | |
129 | using_direct::valid_line (unsigned int boundary) const | |
130 | { | |
131 | try | |
132 | { | |
133 | CORE_ADDR curr_pc = get_frame_pc (get_selected_frame (nullptr)); | |
134 | symtab_and_line curr_sal = find_pc_line (curr_pc, 0); | |
135 | return (decl_line <= curr_sal.line) | |
136 | || (decl_line >= boundary); | |
137 | } | |
138 | catch (const gdb_exception &ex) | |
139 | { | |
140 | return true; | |
141 | } | |
142 | } |