dictionary.h revision 256281
1174832Sdes/* Routines for name->symbol lookups in GDB.
2141098Sdes
3117610Sdes   Copyright 2003 Free Software Foundation, Inc.
4141098Sdes
5174832Sdes   Contributed by David Carlton <carlton@bactrian.org> and by Kealia,
6117610Sdes   Inc.
7117610Sdes
8117610Sdes   This file is part of GDB.
9117610Sdes
10117610Sdes   This program is free software; you can redistribute it and/or modify
11117610Sdes   it under the terms of the GNU General Public License as published by
12117610Sdes   the Free Software Foundation; either version 2 of the License, or (at
13117610Sdes   your option) any later version.
14117610Sdes
15117610Sdes   This program is distributed in the hope that it will be useful, but
16117610Sdes   WITHOUT ANY WARRANTY; without even the implied warranty of
17174832Sdes   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18147455Sdes   General Public License for more details.
19117610Sdes
20117610Sdes   You should have received a copy of the GNU General Public License
21117610Sdes   along with this program; if not, write to the Free Software
22117610Sdes   Foundation, Inc., 59 Temple Place - Suite 330,
23117610Sdes   Boston, MA 02111-1307, USA.  */
24117610Sdes
25141098Sdes#ifndef DICTIONARY_H
26117610Sdes#define DICTIONARY_H
27141098Sdes
28141098Sdes/* An opaque type for dictionaries; only dictionary.c should know
29141098Sdes   about its innards.  */
30117610Sdes
31141098Sdesstruct dictionary;
32117610Sdes
33117610Sdes/* Other types needed for declarations.  */
34117610Sdes
35117610Sdesstruct symbol;
36117610Sdesstruct obstack;
37117610Sdesstruct pending;
38117610Sdes
39117610Sdes
40117610Sdes/* The creation functions for various implementations of
41141098Sdes   dictionaries.  */
42141098Sdes
43141098Sdes/* Create a dictionary implemented via a fixed-size hashtable.  All
44141098Sdes   memory it uses is allocated on OBSTACK; the environment is
45141098Sdes   initialized from SYMBOL_LIST.  */
46141098Sdes
47174832Sdesextern struct dictionary *dict_create_hashed (struct obstack *obstack,
48141098Sdes					      const struct pending
49141098Sdes					      *symbol_list);
50174832Sdes
51174832Sdes/* Create a dictionary implemented via a hashtable that grows as
52174832Sdes   necessary.  The dictionary is initially empty; to add symbols to
53174832Sdes   it, call dict_add_symbol().  Call dict_free() when you're done with
54174832Sdes   it.  */
55174832Sdes
56141098Sdesextern struct dictionary *dict_create_hashed_expandable (void);
57141098Sdes
58141098Sdes/* Create a dictionary implemented via a fixed-size array.  All memory
59141098Sdes   it uses is allocated on OBSTACK; the environment is initialized
60141098Sdes   from the SYMBOL_LIST.  The symbols are ordered in the same order
61141098Sdes   that they're found in SYMBOL_LIST.  */
62141098Sdes
63141098Sdesextern struct dictionary *dict_create_linear (struct obstack *obstack,
64141098Sdes					      const struct pending
65141098Sdes					      *symbol_list);
66141098Sdes
67174832Sdes/* Create a dictionary implemented via an array that grows as
68141098Sdes   necessary.  The dictionary is initially empty; to add symbols to
69141098Sdes   it, call dict_add_symbol().  Call dict_free() when you're done with
70141098Sdes   it.  */
71174832Sdes
72141098Sdesextern struct dictionary *dict_create_linear_expandable (void);
73141098Sdes
74141098Sdes
75141098Sdes/* The functions providing the interface to dictionaries.  Note that
76141098Sdes   the most common parts of the interface, namely symbol lookup, are
77141098Sdes   only provided via iterator functions.  */
78141098Sdes
79141098Sdes/* Free the memory used by a dictionary that's not on an obstack.  (If
80141098Sdes   any.)  */
81141098Sdes
82117610Sdesextern void dict_free (struct dictionary *dict);
83141098Sdes
84141098Sdes/* Add a symbol to an expandable dictionary.  */
85141098Sdes
86141098Sdesextern void dict_add_symbol (struct dictionary *dict, struct symbol *sym);
87117610Sdes
88117610Sdes/* Is the dictionary empty?  */
89141098Sdes
90117610Sdesextern int dict_empty (struct dictionary *dict);
91141098Sdes
92117610Sdes/* A type containing data that is used when iterating over all symbols
93117610Sdes   in a dictionary.  Don't ever look at its innards; this type would
94141098Sdes   be opaque if we didn't need to be able to allocate it on the
95141098Sdes   stack.  */
96141098Sdes
97141098Sdesstruct dict_iterator
98141098Sdes{
99141098Sdes  /* The dictionary that this iterator is associated to.  */
100117610Sdes  const struct dictionary *dict;
101117610Sdes  /* The next two members are data that is used in a way that depends
102141098Sdes     on DICT's implementation type.  */
103141098Sdes  int index;
104141098Sdes  struct symbol *current;
105141098Sdes};
106141098Sdes
107117610Sdes/* Initialize ITERATOR to point at the first symbol in DICT, and
108141098Sdes   return that first symbol, or NULL if DICT is empty.  */
109141098Sdes
110174832Sdesextern struct symbol *dict_iterator_first (const struct dictionary *dict,
111141098Sdes					   struct dict_iterator *iterator);
112141098Sdes
113141098Sdes/* Advance ITERATOR, and return the next symbol, or NULL if there are
114117610Sdes   no more symbols.  Don't call this if you've previously received
115141098Sdes   NULL from dict_iterator_first or dict_iterator_next on this
116141098Sdes   iteration.  */
117141098Sdes
118117610Sdesextern struct symbol *dict_iterator_next (struct dict_iterator *iterator);
119117610Sdes
120117610Sdes/* Initialize ITERATOR to point at the first symbol in DICT whose
121141098Sdes   SYMBOL_BEST_NAME is NAME (as tested using strcmp_iw), and return
122141098Sdes   that first symbol, or NULL if there are no such symbols.  */
123117610Sdes
124117610Sdesextern struct symbol *dict_iter_name_first (const struct dictionary *dict,
125117610Sdes					    const char *name,
126141098Sdes					    struct dict_iterator *iterator);
127141098Sdes
128141098Sdes/* Advance ITERATOR to point at the next symbol in DICT whose
129141098Sdes   SYMBOL_BEST_NAME is NAME (as tested using strcmp_iw), or NULL if
130141098Sdes   there are no more such symbols.  Don't call this if you've
131141098Sdes   previously received NULL from dict_iterator_first or
132117610Sdes   dict_iterator_next on this iteration.  And don't call it unless
133174832Sdes   ITERATOR was created by a previous call to dict_iter_name_first
134141098Sdes   with the same NAME.  */
135141098Sdes
136141098Sdesextern struct symbol *dict_iter_name_next (const char *name,
137117610Sdes					   struct dict_iterator *iterator);
138174832Sdes
139174832Sdes/* Return some notion of the size of the dictionary: the number of
140141098Sdes   symbols if we have that, the number of hash buckets otherwise.  */
141141098Sdes
142174832Sdesextern int dict_size (const struct dictionary *dict);
143174832Sdes
144141098Sdes/* Macro to loop through all symbols in a dictionary DICT, in no
145141098Sdes   particular order.  ITER is a struct dict_iterator (NOTE: __not__ a
146141098Sdes   struct dict_iterator *), and SYM points to the current symbol.
147141098Sdes
148141098Sdes   It's implemented as a single loop, so you can terminate the loop
149141098Sdes   early by a break if you desire.  */
150141098Sdes
151117610Sdes#define ALL_DICT_SYMBOLS(dict, iter, sym)			\
152141098Sdes	for ((sym) = dict_iterator_first ((dict), &(iter));	\
153117610Sdes	     (sym);						\
154174832Sdes	     (sym) = dict_iterator_next (&(iter)))
155174832Sdes
156141098Sdes#endif /* DICTIONARY_H */
157141098Sdes