Commit | Line | Data |
---|---|---|
de4f826b DC |
1 | /* Routines for name->symbol lookups in GDB. |
2 | ||
b811d2c2 | 3 | Copyright (C) 2003-2020 Free Software Foundation, Inc. |
de4f826b DC |
4 | |
5 | Contributed by David Carlton <carlton@bactrian.org> and by Kealia, | |
6 | Inc. | |
7 | ||
8 | This file is part of GDB. | |
9 | ||
10 | This program is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
a9762ec7 JB |
12 | the Free Software Foundation; either version 3 of the License, or |
13 | (at your option) any later version. | |
de4f826b | 14 | |
a9762ec7 JB |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
de4f826b DC |
19 | |
20 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
de4f826b DC |
22 | |
23 | #ifndef DICTIONARY_H | |
24 | #define DICTIONARY_H | |
25 | ||
2edb89d3 JK |
26 | #include "symfile.h" |
27 | ||
b026f593 KS |
28 | /* An opaque type for multi-language dictionaries; only dictionary.c should |
29 | know about its innards. */ | |
de4f826b | 30 | |
b026f593 | 31 | struct multidictionary; |
de4f826b DC |
32 | |
33 | /* Other types needed for declarations. */ | |
34 | ||
35 | struct symbol; | |
36 | struct obstack; | |
37 | struct pending; | |
5ffa0793 | 38 | struct language_defn; |
de4f826b DC |
39 | |
40 | /* The creation functions for various implementations of | |
b026f593 | 41 | multi-language dictionaries. */ |
de4f826b | 42 | |
b026f593 | 43 | /* Create a multi-language dictionary of symbols implemented via |
5ffa0793 PA |
44 | a fixed-size hashtable. All memory it uses is allocated on |
45 | OBSTACK; the environment is initialized from SYMBOL_LIST. */ | |
de4f826b | 46 | |
b026f593 KS |
47 | extern struct multidictionary * |
48 | mdict_create_hashed (struct obstack *obstack, | |
49 | const struct pending *symbol_list); | |
de4f826b | 50 | |
b026f593 KS |
51 | /* Create a multi-language dictionary of symbols, implemented |
52 | via a hashtable that grows as necessary. The initial dictionary of | |
53 | LANGUAGE is empty; to add symbols to it, call mdict_add_symbol(). | |
54 | Call mdict_free() when you're done with it. */ | |
de4f826b | 55 | |
b026f593 KS |
56 | extern struct multidictionary * |
57 | mdict_create_hashed_expandable (enum language language); | |
de4f826b | 58 | |
b026f593 | 59 | /* Create a multi-language dictionary of symbols, implemented |
5ffa0793 PA |
60 | via a fixed-size array. All memory it uses is allocated on |
61 | OBSTACK; the environment is initialized from the SYMBOL_LIST. The | |
62 | symbols are ordered in the same order that they're found in | |
63 | SYMBOL_LIST. */ | |
de4f826b | 64 | |
b026f593 KS |
65 | extern struct multidictionary * |
66 | mdict_create_linear (struct obstack *obstack, | |
67 | const struct pending *symbol_list); | |
de4f826b | 68 | |
b026f593 KS |
69 | /* Create a multi-language dictionary of symbols, implemented |
70 | via an array that grows as necessary. The multidictionary initially | |
71 | contains a single empty dictionary of LANGUAGE; to add symbols to it, | |
72 | call mdict_add_symbol(). Call mdict_free() when you're done with it. */ | |
de4f826b | 73 | |
b026f593 KS |
74 | extern struct multidictionary * |
75 | mdict_create_linear_expandable (enum language language); | |
de4f826b | 76 | |
b026f593 KS |
77 | /* The functions providing the interface to multi-language dictionaries. |
78 | Note that the most common parts of the interface, namely symbol lookup, | |
79 | are only provided via iterator functions. */ | |
de4f826b | 80 | |
b026f593 | 81 | /* Free the memory used by a multidictionary that's not on an obstack. (If |
de4f826b DC |
82 | any.) */ |
83 | ||
b026f593 | 84 | extern void mdict_free (struct multidictionary *mdict); |
de4f826b | 85 | |
b026f593 | 86 | /* Add a symbol to an expandable multidictionary. */ |
de4f826b | 87 | |
b026f593 KS |
88 | extern void mdict_add_symbol (struct multidictionary *mdict, |
89 | struct symbol *sym); | |
de4f826b | 90 | |
b026f593 | 91 | /* Utility to add a list of symbols to a multidictionary. */ |
0bfa869d | 92 | |
b026f593 KS |
93 | extern void mdict_add_pending (struct multidictionary *mdict, |
94 | const struct pending *symbol_list); | |
0bfa869d | 95 | |
de4f826b DC |
96 | /* A type containing data that is used when iterating over all symbols |
97 | in a dictionary. Don't ever look at its innards; this type would | |
98 | be opaque if we didn't need to be able to allocate it on the | |
99 | stack. */ | |
100 | ||
101 | struct dict_iterator | |
102 | { | |
103 | /* The dictionary that this iterator is associated to. */ | |
104 | const struct dictionary *dict; | |
105 | /* The next two members are data that is used in a way that depends | |
106 | on DICT's implementation type. */ | |
107 | int index; | |
108 | struct symbol *current; | |
109 | }; | |
110 | ||
c7748ee9 KS |
111 | /* The multi-language dictionary iterator. Like dict_iterator above, |
112 | these contents should be considered private. */ | |
113 | ||
114 | struct mdict_iterator | |
115 | { | |
116 | /* The multidictionary with whcih this iterator is associated. */ | |
117 | const struct multidictionary *mdict; | |
118 | ||
119 | /* The iterator used to iterate through individual dictionaries. */ | |
120 | struct dict_iterator iterator; | |
121 | ||
122 | /* The current index of the dictionary being iterated over. */ | |
123 | unsigned short current_idx; | |
124 | }; | |
125 | ||
b026f593 KS |
126 | /* Initialize ITERATOR to point at the first symbol in MDICT, and |
127 | return that first symbol, or NULL if MDICT is empty. */ | |
de4f826b | 128 | |
b026f593 KS |
129 | extern struct symbol * |
130 | mdict_iterator_first (const struct multidictionary *mdict, | |
131 | struct mdict_iterator *miterator); | |
de4f826b | 132 | |
b026f593 | 133 | /* Advance MITERATOR, and return the next symbol, or NULL if there are |
de4f826b | 134 | no more symbols. Don't call this if you've previously received |
b026f593 | 135 | NULL from mdict_iterator_first or mdict_iterator_next on this |
de4f826b DC |
136 | iteration. */ |
137 | ||
b026f593 | 138 | extern struct symbol *mdict_iterator_next (struct mdict_iterator *miterator); |
de4f826b | 139 | |
b026f593 | 140 | /* Initialize MITERATOR to point at the first symbol in MDICT whose |
987012b8 | 141 | search_name () is NAME, as tested using COMPARE (which must use |
c4d840bd PH |
142 | the same conventions as strcmp_iw and be compatible with any |
143 | dictionary hashing function), and return that first symbol, or NULL | |
144 | if there are no such symbols. */ | |
145 | ||
b026f593 KS |
146 | extern struct symbol * |
147 | mdict_iter_match_first (const struct multidictionary *mdict, | |
148 | const lookup_name_info &name, | |
149 | struct mdict_iterator *miterator); | |
c4d840bd | 150 | |
b026f593 | 151 | /* Advance MITERATOR to point at the next symbol in MDICT whose |
987012b8 | 152 | search_name () is NAME, as tested using COMPARE (see |
c4d840bd PH |
153 | dict_iter_match_first), or NULL if there are no more such symbols. |
154 | Don't call this if you've previously received NULL from | |
b026f593 KS |
155 | mdict_iterator_match_first or mdict_iterator_match_next on this |
156 | iteration. And don't call it unless MITERATOR was created by a | |
157 | previous call to mdict_iter_match_first with the same NAME and COMPARE. */ | |
c4d840bd | 158 | |
b026f593 KS |
159 | extern struct symbol *mdict_iter_match_next (const lookup_name_info &name, |
160 | struct mdict_iterator *miterator); | |
c4d840bd | 161 | |
b026f593 | 162 | /* Return some notion of the size of the multidictionary: the number of |
de4f826b DC |
163 | symbols if we have that, the number of hash buckets otherwise. */ |
164 | ||
b026f593 | 165 | extern int mdict_size (const struct multidictionary *mdict); |
de4f826b DC |
166 | |
167 | /* Macro to loop through all symbols in a dictionary DICT, in no | |
168 | particular order. ITER is a struct dict_iterator (NOTE: __not__ a | |
169 | struct dict_iterator *), and SYM points to the current symbol. | |
170 | ||
171 | It's implemented as a single loop, so you can terminate the loop | |
172 | early by a break if you desire. */ | |
173 | ||
174 | #define ALL_DICT_SYMBOLS(dict, iter, sym) \ | |
b026f593 | 175 | for ((sym) = mdict_iterator_first ((dict), &(iter)); \ |
de4f826b | 176 | (sym); \ |
b026f593 | 177 | (sym) = mdict_iterator_next (&(iter))) |
de4f826b DC |
178 | |
179 | #endif /* DICTIONARY_H */ |