15796c8dcSSimon Schubert /* Routines for name->symbol lookups in GDB. 25796c8dcSSimon Schubert 3*ef5ccd6cSJohn Marino Copyright (C) 2003-2013 Free Software Foundation, Inc. 45796c8dcSSimon Schubert 55796c8dcSSimon Schubert Contributed by David Carlton <carlton@bactrian.org> and by Kealia, 65796c8dcSSimon Schubert Inc. 75796c8dcSSimon Schubert 85796c8dcSSimon Schubert This file is part of GDB. 95796c8dcSSimon Schubert 105796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 115796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 125796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 135796c8dcSSimon Schubert (at your option) any later version. 145796c8dcSSimon Schubert 155796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 165796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 175796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 185796c8dcSSimon Schubert GNU General Public License for more details. 195796c8dcSSimon Schubert 205796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 215796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 225796c8dcSSimon Schubert 235796c8dcSSimon Schubert #ifndef DICTIONARY_H 245796c8dcSSimon Schubert #define DICTIONARY_H 255796c8dcSSimon Schubert 26c50c785cSJohn Marino #include "symfile.h" 27c50c785cSJohn Marino 285796c8dcSSimon Schubert /* An opaque type for dictionaries; only dictionary.c should know 295796c8dcSSimon Schubert about its innards. */ 305796c8dcSSimon Schubert 315796c8dcSSimon Schubert struct dictionary; 325796c8dcSSimon Schubert 335796c8dcSSimon Schubert /* Other types needed for declarations. */ 345796c8dcSSimon Schubert 355796c8dcSSimon Schubert struct symbol; 365796c8dcSSimon Schubert struct obstack; 375796c8dcSSimon Schubert struct pending; 385796c8dcSSimon Schubert 395796c8dcSSimon Schubert 405796c8dcSSimon Schubert /* The creation functions for various implementations of 415796c8dcSSimon Schubert dictionaries. */ 425796c8dcSSimon Schubert 435796c8dcSSimon Schubert /* Create a dictionary implemented via a fixed-size hashtable. All 445796c8dcSSimon Schubert memory it uses is allocated on OBSTACK; the environment is 455796c8dcSSimon Schubert initialized from SYMBOL_LIST. */ 465796c8dcSSimon Schubert 475796c8dcSSimon Schubert extern struct dictionary *dict_create_hashed (struct obstack *obstack, 485796c8dcSSimon Schubert const struct pending 495796c8dcSSimon Schubert *symbol_list); 505796c8dcSSimon Schubert 515796c8dcSSimon Schubert /* Create a dictionary implemented via a hashtable that grows as 525796c8dcSSimon Schubert necessary. The dictionary is initially empty; to add symbols to 535796c8dcSSimon Schubert it, call dict_add_symbol(). Call dict_free() when you're done with 545796c8dcSSimon Schubert it. */ 555796c8dcSSimon Schubert 565796c8dcSSimon Schubert extern struct dictionary *dict_create_hashed_expandable (void); 575796c8dcSSimon Schubert 585796c8dcSSimon Schubert /* Create a dictionary implemented via a fixed-size array. All memory 595796c8dcSSimon Schubert it uses is allocated on OBSTACK; the environment is initialized 605796c8dcSSimon Schubert from the SYMBOL_LIST. The symbols are ordered in the same order 615796c8dcSSimon Schubert that they're found in SYMBOL_LIST. */ 625796c8dcSSimon Schubert 635796c8dcSSimon Schubert extern struct dictionary *dict_create_linear (struct obstack *obstack, 645796c8dcSSimon Schubert const struct pending 655796c8dcSSimon Schubert *symbol_list); 665796c8dcSSimon Schubert 675796c8dcSSimon Schubert /* Create a dictionary implemented via an array that grows as 685796c8dcSSimon Schubert necessary. The dictionary is initially empty; to add symbols to 695796c8dcSSimon Schubert it, call dict_add_symbol(). Call dict_free() when you're done with 705796c8dcSSimon Schubert it. */ 715796c8dcSSimon Schubert 725796c8dcSSimon Schubert extern struct dictionary *dict_create_linear_expandable (void); 735796c8dcSSimon Schubert 745796c8dcSSimon Schubert 755796c8dcSSimon Schubert /* The functions providing the interface to dictionaries. Note that 765796c8dcSSimon Schubert the most common parts of the interface, namely symbol lookup, are 775796c8dcSSimon Schubert only provided via iterator functions. */ 785796c8dcSSimon Schubert 795796c8dcSSimon Schubert /* Free the memory used by a dictionary that's not on an obstack. (If 805796c8dcSSimon Schubert any.) */ 815796c8dcSSimon Schubert 825796c8dcSSimon Schubert extern void dict_free (struct dictionary *dict); 835796c8dcSSimon Schubert 845796c8dcSSimon Schubert /* Add a symbol to an expandable dictionary. */ 855796c8dcSSimon Schubert 865796c8dcSSimon Schubert extern void dict_add_symbol (struct dictionary *dict, struct symbol *sym); 875796c8dcSSimon Schubert 88*ef5ccd6cSJohn Marino /* Utility to add a list of symbols to a dictionary. */ 89*ef5ccd6cSJohn Marino 90*ef5ccd6cSJohn Marino extern void dict_add_pending (struct dictionary *dict, 91*ef5ccd6cSJohn Marino const struct pending *symbol_list); 92*ef5ccd6cSJohn Marino 935796c8dcSSimon Schubert /* Is the dictionary empty? */ 945796c8dcSSimon Schubert 955796c8dcSSimon Schubert extern int dict_empty (struct dictionary *dict); 965796c8dcSSimon Schubert 975796c8dcSSimon Schubert /* A type containing data that is used when iterating over all symbols 985796c8dcSSimon Schubert in a dictionary. Don't ever look at its innards; this type would 995796c8dcSSimon Schubert be opaque if we didn't need to be able to allocate it on the 1005796c8dcSSimon Schubert stack. */ 1015796c8dcSSimon Schubert 1025796c8dcSSimon Schubert struct dict_iterator 1035796c8dcSSimon Schubert { 1045796c8dcSSimon Schubert /* The dictionary that this iterator is associated to. */ 1055796c8dcSSimon Schubert const struct dictionary *dict; 1065796c8dcSSimon Schubert /* The next two members are data that is used in a way that depends 1075796c8dcSSimon Schubert on DICT's implementation type. */ 1085796c8dcSSimon Schubert int index; 1095796c8dcSSimon Schubert struct symbol *current; 1105796c8dcSSimon Schubert }; 1115796c8dcSSimon Schubert 1125796c8dcSSimon Schubert /* Initialize ITERATOR to point at the first symbol in DICT, and 1135796c8dcSSimon Schubert return that first symbol, or NULL if DICT is empty. */ 1145796c8dcSSimon Schubert 1155796c8dcSSimon Schubert extern struct symbol *dict_iterator_first (const struct dictionary *dict, 1165796c8dcSSimon Schubert struct dict_iterator *iterator); 1175796c8dcSSimon Schubert 1185796c8dcSSimon Schubert /* Advance ITERATOR, and return the next symbol, or NULL if there are 1195796c8dcSSimon Schubert no more symbols. Don't call this if you've previously received 1205796c8dcSSimon Schubert NULL from dict_iterator_first or dict_iterator_next on this 1215796c8dcSSimon Schubert iteration. */ 1225796c8dcSSimon Schubert 1235796c8dcSSimon Schubert extern struct symbol *dict_iterator_next (struct dict_iterator *iterator); 1245796c8dcSSimon Schubert 1255796c8dcSSimon Schubert /* Initialize ITERATOR to point at the first symbol in DICT whose 126cf7f2e2dSJohn Marino SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), and return 1275796c8dcSSimon Schubert that first symbol, or NULL if there are no such symbols. */ 1285796c8dcSSimon Schubert 1295796c8dcSSimon Schubert extern struct symbol *dict_iter_name_first (const struct dictionary *dict, 1305796c8dcSSimon Schubert const char *name, 1315796c8dcSSimon Schubert struct dict_iterator *iterator); 1325796c8dcSSimon Schubert 1335796c8dcSSimon Schubert /* Advance ITERATOR to point at the next symbol in DICT whose 134cf7f2e2dSJohn Marino SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), or NULL if 1355796c8dcSSimon Schubert there are no more such symbols. Don't call this if you've 1365796c8dcSSimon Schubert previously received NULL from dict_iterator_first or 1375796c8dcSSimon Schubert dict_iterator_next on this iteration. And don't call it unless 1385796c8dcSSimon Schubert ITERATOR was created by a previous call to dict_iter_name_first 1395796c8dcSSimon Schubert with the same NAME. */ 1405796c8dcSSimon Schubert 1415796c8dcSSimon Schubert extern struct symbol *dict_iter_name_next (const char *name, 1425796c8dcSSimon Schubert struct dict_iterator *iterator); 1435796c8dcSSimon Schubert 144c50c785cSJohn Marino /* Initialize ITERATOR to point at the first symbol in DICT whose 145c50c785cSJohn Marino SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (which must use 146c50c785cSJohn Marino the same conventions as strcmp_iw and be compatible with any 147c50c785cSJohn Marino dictionary hashing function), and return that first symbol, or NULL 148c50c785cSJohn Marino if there are no such symbols. */ 149c50c785cSJohn Marino 150c50c785cSJohn Marino extern struct symbol *dict_iter_match_first (const struct dictionary *dict, 151c50c785cSJohn Marino const char *name, 152c50c785cSJohn Marino symbol_compare_ftype *compare, 153c50c785cSJohn Marino struct dict_iterator *iterator); 154c50c785cSJohn Marino 155c50c785cSJohn Marino /* Advance ITERATOR to point at the next symbol in DICT whose 156c50c785cSJohn Marino SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (see 157c50c785cSJohn Marino dict_iter_match_first), or NULL if there are no more such symbols. 158c50c785cSJohn Marino Don't call this if you've previously received NULL from 159c50c785cSJohn Marino dict_iterator_match_first or dict_iterator_match_next on this 160c50c785cSJohn Marino iteration. And don't call it unless ITERATOR was created by a 161c50c785cSJohn Marino previous call to dict_iter_match_first with the same NAME and COMPARE. */ 162c50c785cSJohn Marino 163c50c785cSJohn Marino extern struct symbol *dict_iter_match_next (const char *name, 164c50c785cSJohn Marino symbol_compare_ftype *compare, 165c50c785cSJohn Marino struct dict_iterator *iterator); 166c50c785cSJohn Marino 1675796c8dcSSimon Schubert /* Return some notion of the size of the dictionary: the number of 1685796c8dcSSimon Schubert symbols if we have that, the number of hash buckets otherwise. */ 1695796c8dcSSimon Schubert 1705796c8dcSSimon Schubert extern int dict_size (const struct dictionary *dict); 1715796c8dcSSimon Schubert 1725796c8dcSSimon Schubert /* Macro to loop through all symbols in a dictionary DICT, in no 1735796c8dcSSimon Schubert particular order. ITER is a struct dict_iterator (NOTE: __not__ a 1745796c8dcSSimon Schubert struct dict_iterator *), and SYM points to the current symbol. 1755796c8dcSSimon Schubert 1765796c8dcSSimon Schubert It's implemented as a single loop, so you can terminate the loop 1775796c8dcSSimon Schubert early by a break if you desire. */ 1785796c8dcSSimon Schubert 1795796c8dcSSimon Schubert #define ALL_DICT_SYMBOLS(dict, iter, sym) \ 1805796c8dcSSimon Schubert for ((sym) = dict_iterator_first ((dict), &(iter)); \ 1815796c8dcSSimon Schubert (sym); \ 1825796c8dcSSimon Schubert (sym) = dict_iterator_next (&(iter))) 1835796c8dcSSimon Schubert 1845796c8dcSSimon Schubert #endif /* DICTIONARY_H */ 185