1 /* Routines for name->symbol lookups in GDB.
3 Copyright (C) 2003-2018 Free Software Foundation, Inc.
5 Contributed by David Carlton <carlton@bactrian.org> and by Kealia,
8 This file is part of GDB.
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
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
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.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "gdb_obstack.h"
28 #include "dictionary.h"
29 #include "safe-ctype.h"
31 /* This file implements dictionaries, which are tables that associate
32 symbols to names. They are represented by an opaque type 'struct
33 dictionary'. That type has various internal implementations, which
34 you can choose between depending on what properties you need
35 (e.g. fast lookup, order-preserving, expandable).
37 Each dictionary starts with a 'virtual function table' that
38 contains the functions that actually implement the various
39 operations that dictionaries provide. (Note, however, that, for
40 the sake of client code, we also provide some functions that can be
41 implemented generically in terms of the functions in the vtable.)
43 To add a new dictionary implementation <impl>, what you should do
46 * Add a new element DICT_<IMPL> to dict_type.
48 * Create a new structure dictionary_<impl>. If your new
49 implementation is a variant of an existing one, make sure that
50 their structs have the same initial data members. Define accessor
51 macros for your new data members.
53 * Implement all the functions in dict_vector as static functions,
54 whose name is the same as the corresponding member of dict_vector
55 plus _<impl>. You don't have to do this for those members where
56 you can reuse existing generic functions
57 (e.g. add_symbol_nonexpandable, free_obstack) or in the case where
58 your new implementation is a variant of an existing implementation
59 and where the variant doesn't affect the member function in
62 * Define a static const struct dict_vector dict_<impl>_vector.
64 * Define a function dict_create_<impl> to create these
65 gizmos. Add its declaration to dictionary.h.
67 To add a new operation <op> on all existing implementations, what
70 * Add a new member <op> to struct dict_vector.
72 * If there is useful generic behavior <op>, define a static
73 function <op>_something_informative that implements that behavior.
74 (E.g. add_symbol_nonexpandable, free_obstack.)
76 * For every implementation <impl> that should have its own specific
77 behavior for <op>, define a static function <op>_<impl>
80 * Modify all existing dict_vector_<impl>'s to include the appropriate
83 * Define a function dict_<op> that looks up <op> in the dict_vector
84 and calls the appropriate function. Add a declaration for
85 dict_<op> to dictionary.h. */
87 /* An enum representing the various implementations of dictionaries.
88 Used only for debugging. */
92 /* Symbols are stored in a fixed-size hash table. */
94 /* Symbols are stored in an expandable hash table. */
95 DICT_HASHED_EXPANDABLE,
96 /* Symbols are stored in a fixed-size array. */
98 /* Symbols are stored in an expandable array. */
99 DICT_LINEAR_EXPANDABLE
102 /* The virtual function table. */
106 /* The type of the dictionary. This is only here to make debugging
107 a bit easier; it's not actually used. */
109 /* The function to free a dictionary. */
110 void (*free) (struct dictionary *dict);
111 /* Add a symbol to a dictionary, if possible. */
112 void (*add_symbol) (struct dictionary *dict, struct symbol *sym);
113 /* Iterator functions. */
114 struct symbol *(*iterator_first) (const struct dictionary *dict,
115 struct dict_iterator *iterator);
116 struct symbol *(*iterator_next) (struct dict_iterator *iterator);
117 /* Functions to iterate over symbols with a given name. */
118 struct symbol *(*iter_match_first) (const struct dictionary *dict,
119 const lookup_name_info &name,
120 struct dict_iterator *iterator);
121 struct symbol *(*iter_match_next) (const lookup_name_info &name,
122 struct dict_iterator *iterator);
123 /* A size function, for maint print symtabs. */
124 int (*size) (const struct dictionary *dict);
127 /* Now comes the structs used to store the data for different
128 implementations. If two implementations have data in common, put
129 the common data at the top of their structs, ordered in the same
132 struct dictionary_hashed
135 struct symbol **buckets;
138 struct dictionary_hashed_expandable
140 /* How many buckets we currently have. */
142 struct symbol **buckets;
143 /* How many syms we currently have; we need this so we will know
144 when to add more buckets. */
148 struct dictionary_linear
151 struct symbol **syms;
154 struct dictionary_linear_expandable
156 /* How many symbols we currently have. */
158 struct symbol **syms;
159 /* How many symbols we can store before needing to reallocate. */
163 /* And now, the star of our show. */
167 const struct language_defn *language;
168 const struct dict_vector *vector;
171 struct dictionary_hashed hashed;
172 struct dictionary_hashed_expandable hashed_expandable;
173 struct dictionary_linear linear;
174 struct dictionary_linear_expandable linear_expandable;
179 /* Accessor macros. */
181 #define DICT_VECTOR(d) (d)->vector
182 #define DICT_LANGUAGE(d) (d)->language
184 /* These can be used for DICT_HASHED_EXPANDABLE, too. */
186 #define DICT_HASHED_NBUCKETS(d) (d)->data.hashed.nbuckets
187 #define DICT_HASHED_BUCKETS(d) (d)->data.hashed.buckets
188 #define DICT_HASHED_BUCKET(d,i) DICT_HASHED_BUCKETS (d) [i]
190 #define DICT_HASHED_EXPANDABLE_NSYMS(d) (d)->data.hashed_expandable.nsyms
192 /* These can be used for DICT_LINEAR_EXPANDABLEs, too. */
194 #define DICT_LINEAR_NSYMS(d) (d)->data.linear.nsyms
195 #define DICT_LINEAR_SYMS(d) (d)->data.linear.syms
196 #define DICT_LINEAR_SYM(d,i) DICT_LINEAR_SYMS (d) [i]
198 #define DICT_LINEAR_EXPANDABLE_CAPACITY(d) \
199 (d)->data.linear_expandable.capacity
201 /* The initial size of a DICT_*_EXPANDABLE dictionary. */
203 #define DICT_EXPANDABLE_INITIAL_CAPACITY 10
205 /* This calculates the number of buckets we'll use in a hashtable,
206 given the number of symbols that it will contain. */
208 #define DICT_HASHTABLE_SIZE(n) ((n)/5 + 1)
210 /* Accessor macros for dict_iterators; they're here rather than
211 dictionary.h because code elsewhere should treat dict_iterators as
214 /* The dictionary that the iterator is associated to. */
215 #define DICT_ITERATOR_DICT(iter) (iter)->dict
216 /* For linear dictionaries, the index of the last symbol returned; for
217 hashed dictionaries, the bucket of the last symbol returned. */
218 #define DICT_ITERATOR_INDEX(iter) (iter)->index
219 /* For hashed dictionaries, this points to the last symbol returned;
220 otherwise, this is unused. */
221 #define DICT_ITERATOR_CURRENT(iter) (iter)->current
223 /* Declarations of functions for vectors. */
225 /* Functions that might work across a range of dictionary types. */
227 static void add_symbol_nonexpandable (struct dictionary *dict,
230 static void free_obstack (struct dictionary *dict);
232 /* Functions for DICT_HASHED and DICT_HASHED_EXPANDABLE
235 static struct symbol *iterator_first_hashed (const struct dictionary *dict,
236 struct dict_iterator *iterator);
238 static struct symbol *iterator_next_hashed (struct dict_iterator *iterator);
240 static struct symbol *iter_match_first_hashed (const struct dictionary *dict,
241 const lookup_name_info &name,
242 struct dict_iterator *iterator);
244 static struct symbol *iter_match_next_hashed (const lookup_name_info &name,
245 struct dict_iterator *iterator);
247 /* Functions only for DICT_HASHED. */
249 static int size_hashed (const struct dictionary *dict);
251 /* Functions only for DICT_HASHED_EXPANDABLE. */
253 static void free_hashed_expandable (struct dictionary *dict);
255 static void add_symbol_hashed_expandable (struct dictionary *dict,
258 static int size_hashed_expandable (const struct dictionary *dict);
260 /* Functions for DICT_LINEAR and DICT_LINEAR_EXPANDABLE
263 static struct symbol *iterator_first_linear (const struct dictionary *dict,
264 struct dict_iterator *iterator);
266 static struct symbol *iterator_next_linear (struct dict_iterator *iterator);
268 static struct symbol *iter_match_first_linear (const struct dictionary *dict,
269 const lookup_name_info &name,
270 struct dict_iterator *iterator);
272 static struct symbol *iter_match_next_linear (const lookup_name_info &name,
273 struct dict_iterator *iterator);
275 static int size_linear (const struct dictionary *dict);
277 /* Functions only for DICT_LINEAR_EXPANDABLE. */
279 static void free_linear_expandable (struct dictionary *dict);
281 static void add_symbol_linear_expandable (struct dictionary *dict,
284 /* Various vectors that we'll actually use. */
286 static const struct dict_vector dict_hashed_vector =
288 DICT_HASHED, /* type */
289 free_obstack, /* free */
290 add_symbol_nonexpandable, /* add_symbol */
291 iterator_first_hashed, /* iterator_first */
292 iterator_next_hashed, /* iterator_next */
293 iter_match_first_hashed, /* iter_name_first */
294 iter_match_next_hashed, /* iter_name_next */
295 size_hashed, /* size */
298 static const struct dict_vector dict_hashed_expandable_vector =
300 DICT_HASHED_EXPANDABLE, /* type */
301 free_hashed_expandable, /* free */
302 add_symbol_hashed_expandable, /* add_symbol */
303 iterator_first_hashed, /* iterator_first */
304 iterator_next_hashed, /* iterator_next */
305 iter_match_first_hashed, /* iter_name_first */
306 iter_match_next_hashed, /* iter_name_next */
307 size_hashed_expandable, /* size */
310 static const struct dict_vector dict_linear_vector =
312 DICT_LINEAR, /* type */
313 free_obstack, /* free */
314 add_symbol_nonexpandable, /* add_symbol */
315 iterator_first_linear, /* iterator_first */
316 iterator_next_linear, /* iterator_next */
317 iter_match_first_linear, /* iter_name_first */
318 iter_match_next_linear, /* iter_name_next */
319 size_linear, /* size */
322 static const struct dict_vector dict_linear_expandable_vector =
324 DICT_LINEAR_EXPANDABLE, /* type */
325 free_linear_expandable, /* free */
326 add_symbol_linear_expandable, /* add_symbol */
327 iterator_first_linear, /* iterator_first */
328 iterator_next_linear, /* iterator_next */
329 iter_match_first_linear, /* iter_name_first */
330 iter_match_next_linear, /* iter_name_next */
331 size_linear, /* size */
334 /* Declarations of helper functions (i.e. ones that don't go into
337 static struct symbol *iterator_hashed_advance (struct dict_iterator *iter);
339 static void insert_symbol_hashed (struct dictionary *dict,
342 static void expand_hashtable (struct dictionary *dict);
344 /* The creation functions. */
346 /* See dictionary.h. */
349 dict_create_hashed (struct obstack *obstack,
350 enum language language,
351 const struct pending *symbol_list)
353 struct dictionary *retval;
354 int nsyms = 0, nbuckets, i;
355 struct symbol **buckets;
356 const struct pending *list_counter;
358 retval = XOBNEW (obstack, struct dictionary);
359 DICT_VECTOR (retval) = &dict_hashed_vector;
360 DICT_LANGUAGE (retval) = language_def (language);
362 /* Calculate the number of symbols, and allocate space for them. */
363 for (list_counter = symbol_list;
364 list_counter != NULL;
365 list_counter = list_counter->next)
367 nsyms += list_counter->nsyms;
369 nbuckets = DICT_HASHTABLE_SIZE (nsyms);
370 DICT_HASHED_NBUCKETS (retval) = nbuckets;
371 buckets = XOBNEWVEC (obstack, struct symbol *, nbuckets);
372 memset (buckets, 0, nbuckets * sizeof (struct symbol *));
373 DICT_HASHED_BUCKETS (retval) = buckets;
375 /* Now fill the buckets. */
376 for (list_counter = symbol_list;
377 list_counter != NULL;
378 list_counter = list_counter->next)
380 for (i = list_counter->nsyms - 1; i >= 0; --i)
382 insert_symbol_hashed (retval, list_counter->symbol[i]);
389 /* See dictionary.h. */
391 extern struct dictionary *
392 dict_create_hashed_expandable (enum language language)
394 struct dictionary *retval = XNEW (struct dictionary);
396 DICT_VECTOR (retval) = &dict_hashed_expandable_vector;
397 DICT_LANGUAGE (retval) = language_def (language);
398 DICT_HASHED_NBUCKETS (retval) = DICT_EXPANDABLE_INITIAL_CAPACITY;
399 DICT_HASHED_BUCKETS (retval) = XCNEWVEC (struct symbol *,
400 DICT_EXPANDABLE_INITIAL_CAPACITY);
401 DICT_HASHED_EXPANDABLE_NSYMS (retval) = 0;
406 /* See dictionary.h. */
409 dict_create_linear (struct obstack *obstack,
410 enum language language,
411 const struct pending *symbol_list)
413 struct dictionary *retval;
415 struct symbol **syms;
416 const struct pending *list_counter;
418 retval = XOBNEW (obstack, struct dictionary);
419 DICT_VECTOR (retval) = &dict_linear_vector;
420 DICT_LANGUAGE (retval) = language_def (language);
422 /* Calculate the number of symbols, and allocate space for them. */
423 for (list_counter = symbol_list;
424 list_counter != NULL;
425 list_counter = list_counter->next)
427 nsyms += list_counter->nsyms;
429 DICT_LINEAR_NSYMS (retval) = nsyms;
430 syms = XOBNEWVEC (obstack, struct symbol *, nsyms );
431 DICT_LINEAR_SYMS (retval) = syms;
433 /* Now fill in the symbols. Start filling in from the back, so as
434 to preserve the original order of the symbols. */
435 for (list_counter = symbol_list, j = nsyms - 1;
436 list_counter != NULL;
437 list_counter = list_counter->next)
439 for (i = list_counter->nsyms - 1;
443 syms[j] = list_counter->symbol[i];
450 /* See dictionary.h. */
453 dict_create_linear_expandable (enum language language)
455 struct dictionary *retval = XNEW (struct dictionary);
457 DICT_VECTOR (retval) = &dict_linear_expandable_vector;
458 DICT_LANGUAGE (retval) = language_def (language);
459 DICT_LINEAR_NSYMS (retval) = 0;
460 DICT_LINEAR_EXPANDABLE_CAPACITY (retval) = DICT_EXPANDABLE_INITIAL_CAPACITY;
461 DICT_LINEAR_SYMS (retval)
462 = XNEWVEC (struct symbol *, DICT_LINEAR_EXPANDABLE_CAPACITY (retval));
467 /* The functions providing the dictionary interface. */
469 /* Free the memory used by a dictionary that's not on an obstack. (If
473 dict_free (struct dictionary *dict)
475 (DICT_VECTOR (dict))->free (dict);
478 /* Add SYM to DICT. DICT had better be expandable. */
481 dict_add_symbol (struct dictionary *dict, struct symbol *sym)
483 (DICT_VECTOR (dict))->add_symbol (dict, sym);
486 /* Utility to add a list of symbols to a dictionary.
487 DICT must be an expandable dictionary. */
490 dict_add_pending (struct dictionary *dict, const struct pending *symbol_list)
492 const struct pending *list;
495 for (list = symbol_list; list != NULL; list = list->next)
497 for (i = 0; i < list->nsyms; ++i)
498 dict_add_symbol (dict, list->symbol[i]);
502 /* Initialize ITERATOR to point at the first symbol in DICT, and
503 return that first symbol, or NULL if DICT is empty. */
506 dict_iterator_first (const struct dictionary *dict,
507 struct dict_iterator *iterator)
509 return (DICT_VECTOR (dict))->iterator_first (dict, iterator);
512 /* Advance ITERATOR, and return the next symbol, or NULL if there are
516 dict_iterator_next (struct dict_iterator *iterator)
518 return (DICT_VECTOR (DICT_ITERATOR_DICT (iterator)))
519 ->iterator_next (iterator);
523 dict_iter_match_first (const struct dictionary *dict,
524 const lookup_name_info &name,
525 struct dict_iterator *iterator)
527 return (DICT_VECTOR (dict))->iter_match_first (dict, name, iterator);
531 dict_iter_match_next (const lookup_name_info &name,
532 struct dict_iterator *iterator)
534 return (DICT_VECTOR (DICT_ITERATOR_DICT (iterator)))
535 ->iter_match_next (name, iterator);
539 dict_size (const struct dictionary *dict)
541 return (DICT_VECTOR (dict))->size (dict);
544 /* Now come functions (well, one function, currently) that are
545 implemented generically by means of the vtable. Typically, they're
548 /* Test to see if DICT is empty. */
551 dict_empty (struct dictionary *dict)
553 struct dict_iterator iter;
555 return (dict_iterator_first (dict, &iter) == NULL);
559 /* The functions implementing the dictionary interface. */
561 /* Generic functions, where appropriate. */
564 free_obstack (struct dictionary *dict)
570 add_symbol_nonexpandable (struct dictionary *dict, struct symbol *sym)
572 internal_error (__FILE__, __LINE__,
573 _("dict_add_symbol: non-expandable dictionary"));
576 /* Functions for DICT_HASHED and DICT_HASHED_EXPANDABLE. */
578 static struct symbol *
579 iterator_first_hashed (const struct dictionary *dict,
580 struct dict_iterator *iterator)
582 DICT_ITERATOR_DICT (iterator) = dict;
583 DICT_ITERATOR_INDEX (iterator) = -1;
584 return iterator_hashed_advance (iterator);
587 static struct symbol *
588 iterator_next_hashed (struct dict_iterator *iterator)
592 next = DICT_ITERATOR_CURRENT (iterator)->hash_next;
595 return iterator_hashed_advance (iterator);
598 DICT_ITERATOR_CURRENT (iterator) = next;
603 static struct symbol *
604 iterator_hashed_advance (struct dict_iterator *iterator)
606 const struct dictionary *dict = DICT_ITERATOR_DICT (iterator);
607 int nbuckets = DICT_HASHED_NBUCKETS (dict);
610 for (i = DICT_ITERATOR_INDEX (iterator) + 1; i < nbuckets; ++i)
612 struct symbol *sym = DICT_HASHED_BUCKET (dict, i);
616 DICT_ITERATOR_INDEX (iterator) = i;
617 DICT_ITERATOR_CURRENT (iterator) = sym;
625 static struct symbol *
626 iter_match_first_hashed (const struct dictionary *dict,
627 const lookup_name_info &name,
628 struct dict_iterator *iterator)
630 const language_defn *lang = DICT_LANGUAGE (dict);
631 unsigned int hash_index = (name.search_name_hash (lang->la_language)
632 % DICT_HASHED_NBUCKETS (dict));
633 symbol_name_matcher_ftype *matches_name
634 = get_symbol_name_matcher (lang, name);
637 DICT_ITERATOR_DICT (iterator) = dict;
639 /* Loop through the symbols in the given bucket, breaking when SYM
640 first matches. If SYM never matches, it will be set to NULL;
641 either way, we have the right return value. */
643 for (sym = DICT_HASHED_BUCKET (dict, hash_index);
645 sym = sym->hash_next)
647 /* Warning: the order of arguments to compare matters! */
648 if (matches_name (SYMBOL_SEARCH_NAME (sym), name, NULL))
652 DICT_ITERATOR_CURRENT (iterator) = sym;
656 static struct symbol *
657 iter_match_next_hashed (const lookup_name_info &name,
658 struct dict_iterator *iterator)
660 const language_defn *lang = DICT_LANGUAGE (DICT_ITERATOR_DICT (iterator));
661 symbol_name_matcher_ftype *matches_name
662 = get_symbol_name_matcher (lang, name);
665 for (next = DICT_ITERATOR_CURRENT (iterator)->hash_next;
667 next = next->hash_next)
669 if (matches_name (SYMBOL_SEARCH_NAME (next), name, NULL))
673 DICT_ITERATOR_CURRENT (iterator) = next;
678 /* Insert SYM into DICT. */
681 insert_symbol_hashed (struct dictionary *dict,
684 unsigned int hash_index;
686 struct symbol **buckets = DICT_HASHED_BUCKETS (dict);
688 /* We don't want to insert a symbol into a dictionary of a different
689 language. The two may not use the same hashing algorithm. */
690 gdb_assert (SYMBOL_LANGUAGE (sym) == DICT_LANGUAGE (dict)->la_language);
692 hash = search_name_hash (SYMBOL_LANGUAGE (sym), SYMBOL_SEARCH_NAME (sym));
693 hash_index = hash % DICT_HASHED_NBUCKETS (dict);
694 sym->hash_next = buckets[hash_index];
695 buckets[hash_index] = sym;
699 size_hashed (const struct dictionary *dict)
701 return DICT_HASHED_NBUCKETS (dict);
704 /* Functions only for DICT_HASHED_EXPANDABLE. */
707 free_hashed_expandable (struct dictionary *dict)
709 xfree (DICT_HASHED_BUCKETS (dict));
714 add_symbol_hashed_expandable (struct dictionary *dict,
717 int nsyms = ++DICT_HASHED_EXPANDABLE_NSYMS (dict);
719 if (DICT_HASHTABLE_SIZE (nsyms) > DICT_HASHED_NBUCKETS (dict))
720 expand_hashtable (dict);
722 insert_symbol_hashed (dict, sym);
723 DICT_HASHED_EXPANDABLE_NSYMS (dict) = nsyms;
727 size_hashed_expandable (const struct dictionary *dict)
729 return DICT_HASHED_EXPANDABLE_NSYMS (dict);
733 expand_hashtable (struct dictionary *dict)
735 int old_nbuckets = DICT_HASHED_NBUCKETS (dict);
736 struct symbol **old_buckets = DICT_HASHED_BUCKETS (dict);
737 int new_nbuckets = 2 * old_nbuckets + 1;
738 struct symbol **new_buckets = XCNEWVEC (struct symbol *, new_nbuckets);
741 DICT_HASHED_NBUCKETS (dict) = new_nbuckets;
742 DICT_HASHED_BUCKETS (dict) = new_buckets;
744 for (i = 0; i < old_nbuckets; ++i)
746 struct symbol *sym, *next_sym;
748 sym = old_buckets[i];
751 for (next_sym = sym->hash_next;
753 next_sym = sym->hash_next)
755 insert_symbol_hashed (dict, sym);
759 insert_symbol_hashed (dict, sym);
766 /* See dictionary.h. */
769 default_search_name_hash (const char *string0)
771 /* The Ada-encoded version of a name P1.P2...Pn has either the form
772 P1__P2__...Pn<suffix> or _ada_P1__P2__...Pn<suffix> (where the Pi
773 are lower-cased identifiers). The <suffix> (which can be empty)
774 encodes additional information about the denoted entity. This
775 routine hashes such names to msymbol_hash_iw(Pn). It actually
776 does this for a superset of both valid Pi and of <suffix>, but
777 in other cases it simply returns msymbol_hash_iw(STRING0). */
785 if (startswith (string, "_ada_"))
788 return msymbol_hash_iw (string0);
799 if (string0 == string)
800 return msymbol_hash_iw (string0);
805 return msymbol_hash_iw (string0);
807 if (string[1] == '_' && string != string0)
811 if ((c < 'a' || c > 'z') && c != 'O')
819 /* Ignore "TKB" suffixes.
821 These are used by Ada for subprograms implementing a task body.
822 For instance for a task T inside package Pck, the name of the
823 subprogram implementing T's body is `pck__tTKB'. We need to
824 ignore the "TKB" suffix because searches for this task body
825 subprogram are going to be performed using `pck__t' (the encoded
826 version of the natural name `pck.t'). */
827 if (strcmp (string, "TKB") == 0)
832 hash = SYMBOL_HASH_NEXT (hash, *string);
838 /* Functions for DICT_LINEAR and DICT_LINEAR_EXPANDABLE. */
840 static struct symbol *
841 iterator_first_linear (const struct dictionary *dict,
842 struct dict_iterator *iterator)
844 DICT_ITERATOR_DICT (iterator) = dict;
845 DICT_ITERATOR_INDEX (iterator) = 0;
846 return DICT_LINEAR_NSYMS (dict) ? DICT_LINEAR_SYM (dict, 0) : NULL;
849 static struct symbol *
850 iterator_next_linear (struct dict_iterator *iterator)
852 const struct dictionary *dict = DICT_ITERATOR_DICT (iterator);
854 if (++DICT_ITERATOR_INDEX (iterator) >= DICT_LINEAR_NSYMS (dict))
857 return DICT_LINEAR_SYM (dict, DICT_ITERATOR_INDEX (iterator));
860 static struct symbol *
861 iter_match_first_linear (const struct dictionary *dict,
862 const lookup_name_info &name,
863 struct dict_iterator *iterator)
865 DICT_ITERATOR_DICT (iterator) = dict;
866 DICT_ITERATOR_INDEX (iterator) = -1;
868 return iter_match_next_linear (name, iterator);
871 static struct symbol *
872 iter_match_next_linear (const lookup_name_info &name,
873 struct dict_iterator *iterator)
875 const struct dictionary *dict = DICT_ITERATOR_DICT (iterator);
876 const language_defn *lang = DICT_LANGUAGE (dict);
877 symbol_name_matcher_ftype *matches_name
878 = get_symbol_name_matcher (lang, name);
880 int i, nsyms = DICT_LINEAR_NSYMS (dict);
881 struct symbol *sym, *retval = NULL;
883 for (i = DICT_ITERATOR_INDEX (iterator) + 1; i < nsyms; ++i)
885 sym = DICT_LINEAR_SYM (dict, i);
887 if (matches_name (SYMBOL_SEARCH_NAME (sym), name, NULL))
894 DICT_ITERATOR_INDEX (iterator) = i;
900 size_linear (const struct dictionary *dict)
902 return DICT_LINEAR_NSYMS (dict);
905 /* Functions only for DICT_LINEAR_EXPANDABLE. */
908 free_linear_expandable (struct dictionary *dict)
910 xfree (DICT_LINEAR_SYMS (dict));
916 add_symbol_linear_expandable (struct dictionary *dict,
919 int nsyms = ++DICT_LINEAR_NSYMS (dict);
921 /* Do we have enough room? If not, grow it. */
922 if (nsyms > DICT_LINEAR_EXPANDABLE_CAPACITY (dict))
924 DICT_LINEAR_EXPANDABLE_CAPACITY (dict) *= 2;
925 DICT_LINEAR_SYMS (dict)
926 = XRESIZEVEC (struct symbol *, DICT_LINEAR_SYMS (dict),
927 DICT_LINEAR_EXPANDABLE_CAPACITY (dict));
930 DICT_LINEAR_SYM (dict, nsyms - 1) = sym;