Copyright year update in most files of the GDB Project.
[deliverable/binutils-gdb.git] / gdb / dictionary.h
CommitLineData
de4f826b
DC
1/* Routines for name->symbol lookups in GDB.
2
0b302171 3 Copyright (C) 2003, 2007-2012 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
de4f826b
DC
28/* An opaque type for dictionaries; only dictionary.c should know
29 about its innards. */
30
31struct dictionary;
32
33/* Other types needed for declarations. */
34
35struct symbol;
36struct obstack;
37struct pending;
38
39
40/* The creation functions for various implementations of
41 dictionaries. */
42
43/* Create a dictionary implemented via a fixed-size hashtable. All
44 memory it uses is allocated on OBSTACK; the environment is
45 initialized from SYMBOL_LIST. */
46
47extern struct dictionary *dict_create_hashed (struct obstack *obstack,
48 const struct pending
49 *symbol_list);
50
51/* Create a dictionary implemented via a hashtable that grows as
52 necessary. The dictionary is initially empty; to add symbols to
53 it, call dict_add_symbol(). Call dict_free() when you're done with
54 it. */
55
56extern struct dictionary *dict_create_hashed_expandable (void);
57
58/* Create a dictionary implemented via a fixed-size array. All memory
59 it uses is allocated on OBSTACK; the environment is initialized
60 from the SYMBOL_LIST. The symbols are ordered in the same order
61 that they're found in SYMBOL_LIST. */
62
63extern struct dictionary *dict_create_linear (struct obstack *obstack,
64 const struct pending
65 *symbol_list);
66
67/* Create a dictionary implemented via an array that grows as
68 necessary. The dictionary is initially empty; to add symbols to
69 it, call dict_add_symbol(). Call dict_free() when you're done with
70 it. */
71
72extern struct dictionary *dict_create_linear_expandable (void);
73
74
75/* The functions providing the interface to dictionaries. Note that
76 the most common parts of the interface, namely symbol lookup, are
77 only provided via iterator functions. */
78
79/* Free the memory used by a dictionary that's not on an obstack. (If
80 any.) */
81
82extern void dict_free (struct dictionary *dict);
83
84/* Add a symbol to an expandable dictionary. */
85
86extern void dict_add_symbol (struct dictionary *dict, struct symbol *sym);
87
88/* Is the dictionary empty? */
89
90extern int dict_empty (struct dictionary *dict);
91
92/* A type containing data that is used when iterating over all symbols
93 in a dictionary. Don't ever look at its innards; this type would
94 be opaque if we didn't need to be able to allocate it on the
95 stack. */
96
97struct dict_iterator
98{
99 /* The dictionary that this iterator is associated to. */
100 const struct dictionary *dict;
101 /* The next two members are data that is used in a way that depends
102 on DICT's implementation type. */
103 int index;
104 struct symbol *current;
105};
106
107/* Initialize ITERATOR to point at the first symbol in DICT, and
108 return that first symbol, or NULL if DICT is empty. */
109
110extern struct symbol *dict_iterator_first (const struct dictionary *dict,
111 struct dict_iterator *iterator);
112
113/* Advance ITERATOR, and return the next symbol, or NULL if there are
114 no more symbols. Don't call this if you've previously received
115 NULL from dict_iterator_first or dict_iterator_next on this
116 iteration. */
117
118extern struct symbol *dict_iterator_next (struct dict_iterator *iterator);
119
120/* Initialize ITERATOR to point at the first symbol in DICT whose
5ddb52fa 121 SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), and return
de4f826b
DC
122 that first symbol, or NULL if there are no such symbols. */
123
124extern struct symbol *dict_iter_name_first (const struct dictionary *dict,
125 const char *name,
126 struct dict_iterator *iterator);
127
128/* Advance ITERATOR to point at the next symbol in DICT whose
5ddb52fa 129 SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), or NULL if
de4f826b
DC
130 there are no more such symbols. Don't call this if you've
131 previously received NULL from dict_iterator_first or
132 dict_iterator_next on this iteration. And don't call it unless
133 ITERATOR was created by a previous call to dict_iter_name_first
134 with the same NAME. */
135
136extern struct symbol *dict_iter_name_next (const char *name,
137 struct dict_iterator *iterator);
138
c4d840bd
PH
139/* Initialize ITERATOR to point at the first symbol in DICT whose
140 SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (which must use
141 the same conventions as strcmp_iw and be compatible with any
142 dictionary hashing function), and return that first symbol, or NULL
143 if there are no such symbols. */
144
145extern struct symbol *dict_iter_match_first (const struct dictionary *dict,
146 const char *name,
2edb89d3 147 symbol_compare_ftype *compare,
c4d840bd
PH
148 struct dict_iterator *iterator);
149
150/* Advance ITERATOR to point at the next symbol in DICT whose
151 SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (see
152 dict_iter_match_first), or NULL if there are no more such symbols.
153 Don't call this if you've previously received NULL from
154 dict_iterator_match_first or dict_iterator_match_next on this
0963b4bd 155 iteration. And don't call it unless ITERATOR was created by a
c4d840bd
PH
156 previous call to dict_iter_match_first with the same NAME and COMPARE. */
157
158extern struct symbol *dict_iter_match_next (const char *name,
2edb89d3 159 symbol_compare_ftype *compare,
c4d840bd
PH
160 struct dict_iterator *iterator);
161
de4f826b
DC
162/* Return some notion of the size of the dictionary: the number of
163 symbols if we have that, the number of hash buckets otherwise. */
164
165extern int dict_size (const struct dictionary *dict);
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) \
175 for ((sym) = dict_iterator_first ((dict), &(iter)); \
176 (sym); \
177 (sym) = dict_iterator_next (&(iter)))
178
179#endif /* DICTIONARY_H */
This page took 0.565447 seconds and 4 git commands to generate.