gdb/dictionary.h - gdb

Data types defined

Macros defined

Source code

  1. /* Routines for name->symbol lookups in GDB.

  2.    Copyright (C) 2003-2015 Free Software Foundation, Inc.

  3.    Contributed by David Carlton <carlton@bactrian.org> and by Kealia,
  4.    Inc.

  5.    This file is part of GDB.

  6.    This program is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 3 of the License, or
  9.    (at your option) any later version.

  10.    This program is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.

  14.    You should have received a copy of the GNU General Public License
  15.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  16. #ifndef DICTIONARY_H
  17. #define DICTIONARY_H

  18. #include "symfile.h"

  19. /* An opaque type for dictionaries; only dictionary.c should know
  20.    about its innards.  */

  21. struct dictionary;

  22. /* Other types needed for declarations.  */

  23. struct symbol;
  24. struct obstack;
  25. struct pending;


  26. /* The creation functions for various implementations of
  27.    dictionaries.  */

  28. /* Create a dictionary implemented via a fixed-size hashtable.  All
  29.    memory it uses is allocated on OBSTACK; the environment is
  30.    initialized from SYMBOL_LIST.  */

  31. extern struct dictionary *dict_create_hashed (struct obstack *obstack,
  32.                                               const struct pending
  33.                                               *symbol_list);

  34. /* Create a dictionary implemented via a hashtable that grows as
  35.    necessary.  The dictionary is initially empty; to add symbols to
  36.    it, call dict_add_symbol().  Call dict_free() when you're done with
  37.    it.  */

  38. extern struct dictionary *dict_create_hashed_expandable (void);

  39. /* Create a dictionary implemented via a fixed-size array.  All memory
  40.    it uses is allocated on OBSTACK; the environment is initialized
  41.    from the SYMBOL_LIST.  The symbols are ordered in the same order
  42.    that they're found in SYMBOL_LIST.  */

  43. extern struct dictionary *dict_create_linear (struct obstack *obstack,
  44.                                               const struct pending
  45.                                               *symbol_list);

  46. /* Create a dictionary implemented via an array that grows as
  47.    necessary.  The dictionary is initially empty; to add symbols to
  48.    it, call dict_add_symbol().  Call dict_free() when you're done with
  49.    it.  */

  50. extern struct dictionary *dict_create_linear_expandable (void);


  51. /* The functions providing the interface to dictionaries.  Note that
  52.    the most common parts of the interface, namely symbol lookup, are
  53.    only provided via iterator functions.  */

  54. /* Free the memory used by a dictionary that's not on an obstack.  (If
  55.    any.)  */

  56. extern void dict_free (struct dictionary *dict);

  57. /* Add a symbol to an expandable dictionary.  */

  58. extern void dict_add_symbol (struct dictionary *dict, struct symbol *sym);

  59. /* Utility to add a list of symbols to a dictionary.  */

  60. extern void dict_add_pending (struct dictionary *dict,
  61.                               const struct pending *symbol_list);

  62. /* Is the dictionary empty?  */

  63. extern int dict_empty (struct dictionary *dict);

  64. /* A type containing data that is used when iterating over all symbols
  65.    in a dictionary.  Don't ever look at its innards; this type would
  66.    be opaque if we didn't need to be able to allocate it on the
  67.    stack.  */

  68. struct dict_iterator
  69. {
  70.   /* The dictionary that this iterator is associated to.  */
  71.   const struct dictionary *dict;
  72.   /* The next two members are data that is used in a way that depends
  73.      on DICT's implementation type.  */
  74.   int index;
  75.   struct symbol *current;
  76. };

  77. /* Initialize ITERATOR to point at the first symbol in DICT, and
  78.    return that first symbol, or NULL if DICT is empty.  */

  79. extern struct symbol *dict_iterator_first (const struct dictionary *dict,
  80.                                            struct dict_iterator *iterator);

  81. /* Advance ITERATOR, and return the next symbol, or NULL if there are
  82.    no more symbols.  Don't call this if you've previously received
  83.    NULL from dict_iterator_first or dict_iterator_next on this
  84.    iteration.  */

  85. extern struct symbol *dict_iterator_next (struct dict_iterator *iterator);

  86. /* Initialize ITERATOR to point at the first symbol in DICT whose
  87.    SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), and return
  88.    that first symbol, or NULL if there are no such symbols.  */

  89. extern struct symbol *dict_iter_name_first (const struct dictionary *dict,
  90.                                             const char *name,
  91.                                             struct dict_iterator *iterator);

  92. /* Advance ITERATOR to point at the next symbol in DICT whose
  93.    SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), or NULL if
  94.    there are no more such symbols.  Don't call this if you've
  95.    previously received NULL from dict_iterator_first or
  96.    dict_iterator_next on this iteration.  And don't call it unless
  97.    ITERATOR was created by a previous call to dict_iter_name_first
  98.    with the same NAME.  */

  99. extern struct symbol *dict_iter_name_next (const char *name,
  100.                                            struct dict_iterator *iterator);

  101. /* Initialize ITERATOR to point at the first symbol in DICT whose
  102.    SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (which must use
  103.    the same conventions as strcmp_iw and be compatible with any
  104.    dictionary hashing function), and return that first symbol, or NULL
  105.    if there are no such symbols.  */

  106. extern struct symbol *dict_iter_match_first (const struct dictionary *dict,
  107.                                              const char *name,
  108.                                              symbol_compare_ftype *compare,
  109.                                              struct dict_iterator *iterator);

  110. /* Advance ITERATOR to point at the next symbol in DICT whose
  111.    SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (see
  112.    dict_iter_match_first), or NULL if there are no more such symbols.
  113.    Don't call this if you've previously received NULL from
  114.    dict_iterator_match_first or dict_iterator_match_next on this
  115.    iteration.  And don't call it unless ITERATOR was created by a
  116.    previous call to dict_iter_match_first with the same NAME and COMPARE.  */

  117. extern struct symbol *dict_iter_match_next (const char *name,
  118.                                             symbol_compare_ftype *compare,
  119.                                             struct dict_iterator *iterator);

  120. /* Return some notion of the size of the dictionary: the number of
  121.    symbols if we have that, the number of hash buckets otherwise.  */

  122. extern int dict_size (const struct dictionary *dict);

  123. /* Macro to loop through all symbols in a dictionary DICT, in no
  124.    particular order.  ITER is a struct dict_iterator (NOTE: __not__ a
  125.    struct dict_iterator *), and SYM points to the current symbol.

  126.    It's implemented as a single loop, so you can terminate the loop
  127.    early by a break if you desire.  */

  128. #define ALL_DICT_SYMBOLS(dict, iter, sym)                        \
  129.         for ((sym) = dict_iterator_first ((dict), &(iter));        \
  130.              (sym);                                                \
  131.              (sym) = dict_iterator_next (&(iter)))

  132. #endif /* DICTIONARY_H */