dictionary.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* Routines for name->symbol lookups in GDB.
  2. Copyright (C) 2003-2022 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 multi-language dictionaries; only dictionary.c should
  20. know about its innards. */
  21. struct multidictionary;
  22. /* Other types needed for declarations. */
  23. struct symbol;
  24. struct obstack;
  25. struct pending;
  26. struct language_defn;
  27. /* The creation functions for various implementations of
  28. multi-language dictionaries. */
  29. /* Create a multi-language dictionary of symbols implemented via
  30. a fixed-size hashtable. All memory it uses is allocated on
  31. OBSTACK; the environment is initialized from SYMBOL_LIST. */
  32. extern struct multidictionary *
  33. mdict_create_hashed (struct obstack *obstack,
  34. const struct pending *symbol_list);
  35. /* Create a multi-language dictionary of symbols, implemented
  36. via a hashtable that grows as necessary. The initial dictionary of
  37. LANGUAGE is empty; to add symbols to it, call mdict_add_symbol().
  38. Call mdict_free() when you're done with it. */
  39. extern struct multidictionary *
  40. mdict_create_hashed_expandable (enum language language);
  41. /* Create a multi-language dictionary of symbols, implemented
  42. via a fixed-size array. All memory it uses is allocated on
  43. OBSTACK; the environment is initialized from the SYMBOL_LIST. The
  44. symbols are ordered in the same order that they're found in
  45. SYMBOL_LIST. */
  46. extern struct multidictionary *
  47. mdict_create_linear (struct obstack *obstack,
  48. const struct pending *symbol_list);
  49. /* Create a multi-language dictionary of symbols, implemented
  50. via an array that grows as necessary. The multidictionary initially
  51. contains a single empty dictionary of LANGUAGE; to add symbols to it,
  52. call mdict_add_symbol(). Call mdict_free() when you're done with it. */
  53. extern struct multidictionary *
  54. mdict_create_linear_expandable (enum language language);
  55. /* The functions providing the interface to multi-language dictionaries.
  56. Note that the most common parts of the interface, namely symbol lookup,
  57. are only provided via iterator functions. */
  58. /* Free the memory used by a multidictionary that's not on an obstack. (If
  59. any.) */
  60. extern void mdict_free (struct multidictionary *mdict);
  61. /* Add a symbol to an expandable multidictionary. */
  62. extern void mdict_add_symbol (struct multidictionary *mdict,
  63. struct symbol *sym);
  64. /* Utility to add a list of symbols to a multidictionary. */
  65. extern void mdict_add_pending (struct multidictionary *mdict,
  66. const struct pending *symbol_list);
  67. /* A type containing data that is used when iterating over all symbols
  68. in a dictionary. Don't ever look at its innards; this type would
  69. be opaque if we didn't need to be able to allocate it on the
  70. stack. */
  71. struct dict_iterator
  72. {
  73. /* The dictionary that this iterator is associated to. */
  74. const struct dictionary *dict;
  75. /* The next two members are data that is used in a way that depends
  76. on DICT's implementation type. */
  77. int index;
  78. struct symbol *current;
  79. };
  80. /* The multi-language dictionary iterator. Like dict_iterator above,
  81. these contents should be considered private. */
  82. struct mdict_iterator
  83. {
  84. /* The multidictionary with whcih this iterator is associated. */
  85. const struct multidictionary *mdict;
  86. /* The iterator used to iterate through individual dictionaries. */
  87. struct dict_iterator iterator;
  88. /* The current index of the dictionary being iterated over. */
  89. unsigned short current_idx;
  90. };
  91. /* Initialize ITERATOR to point at the first symbol in MDICT, and
  92. return that first symbol, or NULL if MDICT is empty. */
  93. extern struct symbol *
  94. mdict_iterator_first (const struct multidictionary *mdict,
  95. struct mdict_iterator *miterator);
  96. /* Advance MITERATOR, and return the next symbol, or NULL if there are
  97. no more symbols. Don't call this if you've previously received
  98. NULL from mdict_iterator_first or mdict_iterator_next on this
  99. iteration. */
  100. extern struct symbol *mdict_iterator_next (struct mdict_iterator *miterator);
  101. /* Initialize MITERATOR to point at the first symbol in MDICT whose
  102. 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 *
  107. mdict_iter_match_first (const struct multidictionary *mdict,
  108. const lookup_name_info &name,
  109. struct mdict_iterator *miterator);
  110. /* Advance MITERATOR to point at the next symbol in MDICT whose
  111. 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. mdict_iterator_match_first or mdict_iterator_match_next on this
  115. iteration. And don't call it unless MITERATOR was created by a
  116. previous call to mdict_iter_match_first with the same NAME and COMPARE. */
  117. extern struct symbol *mdict_iter_match_next (const lookup_name_info &name,
  118. struct mdict_iterator *miterator);
  119. /* Return some notion of the size of the multidictionary: the number of
  120. symbols if we have that, the number of hash buckets otherwise. */
  121. extern int mdict_size (const struct multidictionary *mdict);
  122. /* Macro to loop through all symbols in a dictionary DICT, in no
  123. particular order. ITER is a struct dict_iterator (NOTE: __not__ a
  124. struct dict_iterator *), and SYM points to the current symbol.
  125. It's implemented as a single loop, so you can terminate the loop
  126. early by a break if you desire. */
  127. #define ALL_DICT_SYMBOLS(dict, iter, sym) \
  128. for ((sym) = mdict_iterator_first ((dict), &(iter)); \
  129. (sym); \
  130. (sym) = mdict_iterator_next (&(iter)))
  131. #endif /* DICTIONARY_H */