181 #define DICT_VECTOR(d) (d)->vector
185 #define DICT_HASHED_NBUCKETS(d) (d)->data.hashed.nbuckets
186 #define DICT_HASHED_BUCKETS(d) (d)->data.hashed.buckets
187 #define DICT_HASHED_BUCKET(d,i) DICT_HASHED_BUCKETS (d) [i]
189 #define DICT_HASHED_EXPANDABLE_NSYMS(d) (d)->data.hashed_expandable.nsyms
193 #define DICT_LINEAR_NSYMS(d) (d)->data.linear.nsyms
194 #define DICT_LINEAR_SYMS(d) (d)->data.linear.syms
195 #define DICT_LINEAR_SYM(d,i) DICT_LINEAR_SYMS (d) [i]
197 #define DICT_LINEAR_EXPANDABLE_CAPACITY(d) \
198 (d)->data.linear_expandable.capacity
202 #define DICT_EXPANDABLE_INITIAL_CAPACITY 10
207 #define DICT_HASHTABLE_SIZE(n) ((n)/5 + 1)
214 #define DICT_ITERATOR_DICT(iter) (iter)->dict
217 #define DICT_ITERATOR_INDEX(iter) (iter)->index
220 #define DICT_ITERATOR_CURRENT(iter) (iter)->current
248 static unsigned int dict_hash (
const char *
string);
360 int nsyms = 0, nbuckets, i;
362 const struct pending *list_counter;
364 retval = obstack_alloc (obstack,
sizeof (
struct dictionary));
368 for (list_counter = symbol_list;
369 list_counter != NULL;
370 list_counter = list_counter->
next)
372 nsyms += list_counter->
nsyms;
376 buckets = obstack_alloc (obstack, nbuckets *
sizeof (
struct symbol *));
377 memset (buckets, 0, nbuckets *
sizeof (
struct symbol *));
381 for (list_counter = symbol_list;
382 list_counter != NULL;
383 list_counter = list_counter->
next)
385 for (i = list_counter->
nsyms - 1; i >= 0; --i)
408 sizeof (
struct symbol *));
426 const struct pending *list_counter;
428 retval = obstack_alloc (obstack,
sizeof (
struct dictionary));
432 for (list_counter = symbol_list;
433 list_counter != NULL;
434 list_counter = list_counter->
next)
436 nsyms += list_counter->
nsyms;
439 syms = obstack_alloc (obstack, nsyms *
sizeof (
struct symbol *));
444 for (list_counter = symbol_list, j = nsyms - 1;
445 list_counter != NULL;
446 list_counter = list_counter->
next)
448 for (i = list_counter->
nsyms - 1;
452 syms[j] = list_counter->
symbol[i];
476 *
sizeof (
struct symbol *));
509 for (list = symbol_list; list != NULL; list = list->
next)
511 for (i = 0; i < list->
nsyms; ++i)
523 return (
DICT_VECTOR (dict))->iterator_first (dict, iterator);
533 ->iterator_next (iterator);
555 return (
DICT_VECTOR (dict))->iter_match_first (dict, name,
564 ->iter_match_next (name, compare, iterator);
602 _(
"dict_add_symbol: non-expandable dictionary"));
709 unsigned int hash_index;
715 buckets[hash_index] = sym;
757 int new_nbuckets = 2*old_nbuckets + 1;
759 sizeof (
struct symbol *));
765 for (i = 0; i < old_nbuckets; ++i)
767 struct symbol *sym, *next_sym;
769 sym = old_buckets[i];
826 if (strcmp (
string,
"TKB") == 0)
834 if (string0 ==
string)
842 if (
string[1] ==
'_' &&
string != string0)
846 if ((c < 'a' || c >
'z') && c !=
'O')
901 struct symbol *sym, *retval = NULL;
947 *
sizeof (
struct symbol *));
static struct symbol * iterator_first_linear(const struct dictionary *dict, struct dict_iterator *iterator)
#define DICT_HASHED_EXPANDABLE_NSYMS(d)
static const struct dict_vector dict_linear_expandable_vector
struct dictionary * dict_create_hashed(struct obstack *obstack, const struct pending *symbol_list)
static struct @39 symbol_list[]
#define DICT_LINEAR_SYM(d, i)
void dict_free(struct dictionary *dict)
struct dictionary_hashed_expandable hashed_expandable
struct dictionary * dict_create_linear_expandable(void)
int strcmp_iw(const char *string1, const char *string2)
struct symbol * hash_next
const struct dict_vector * vector
static void expand_hashtable(struct dictionary *dict)
static struct symbol * iterator_hashed_advance(struct dict_iterator *iter)
void internal_error(const char *file, int line, const char *fmt,...)
struct symbol * dict_iter_match_first(const struct dictionary *dict, const char *name, symbol_compare_ftype *compare, struct dict_iterator *iterator)
int(* size)(const struct dictionary *dict)
#define DICT_HASHED_BUCKET(d, i)
#define DICT_LINEAR_SYMS(d)
void(* add_symbol)(struct dictionary *dict, struct symbol *sym)
struct symbol * symbol[PENDINGSIZE]
#define DICT_ITERATOR_CURRENT(iter)
static void add_symbol_linear_expandable(struct dictionary *dict, struct symbol *sym)
#define DICT_ITERATOR_DICT(iter)
#define DICT_HASHED_NBUCKETS(d)
static const struct dict_vector dict_linear_vector
static void free_hashed_expandable(struct dictionary *dict)
struct dictionary_hashed hashed
#define DICT_LINEAR_NSYMS(d)
void dict_add_pending(struct dictionary *dict, const struct pending *symbol_list)
#define DICT_EXPANDABLE_INITIAL_CAPACITY
static struct symbol * iterator_next_hashed(struct dict_iterator *iterator)
static const struct dict_vector dict_hashed_expandable_vector
#define SYMBOL_HASH_NEXT(hash, c)
#define DICT_LINEAR_EXPANDABLE_CAPACITY(d)
struct dictionary * dict_create_linear(struct obstack *obstack, const struct pending *symbol_list)
static int size_linear(const struct dictionary *dict)
static int startswith(const char *string, const char *pattern)
static struct symbol * iter_match_first_linear(const struct dictionary *dict, const char *name, symbol_compare_ftype *compare, struct dict_iterator *iterator)
static struct symbol * iterator_first_hashed(const struct dictionary *dict, struct dict_iterator *iterator)
static void add_symbol(struct symbol *, struct symtab *, struct block *)
int dict_empty(struct dictionary *dict)
union dictionary::@50 data
struct symbol * dict_iterator_next(struct dict_iterator *iterator)
unsigned long hash(const void *addr, int length)
static void add_symbol_hashed_expandable(struct dictionary *dict, struct symbol *sym)
static void free_linear_expandable(struct dictionary *dict)
PTR xrealloc(PTR ptr, size_t size)
const char const char int
int( symbol_compare_ftype)(const char *string1, const char *string2)
struct symbol * dict_iter_match_next(const char *name, symbol_compare_ftype *compare, struct dict_iterator *iterator)
struct dictionary_linear linear
void(* free)(struct dictionary *dict)
static struct symbol * iter_match_next_hashed(const char *name, symbol_compare_ftype *compare, struct dict_iterator *iterator)
void dict_add_symbol(struct dictionary *dict, struct symbol *sym)
struct dictionary * dict_create_hashed_expandable(void)
static int size_hashed_expandable(const struct dictionary *dict)
static void insert_symbol_hashed(struct dictionary *dict, struct symbol *sym)
static const struct dict_vector dict_hashed_vector
#define SYMBOL_SEARCH_NAME(symbol)
struct symbol * dict_iter_name_first(const struct dictionary *dict, const char *name, struct dict_iterator *iterator)
static unsigned int dict_hash(const char *string)
int dict_size(const struct dictionary *dict)
#define DICT_HASHTABLE_SIZE(n)
struct symbol * dict_iter_name_next(const char *name, struct dict_iterator *iterator)
const struct dictionary * dict
PTR xcalloc(size_t number, size_t size)
static struct symbol * iter_match_next_linear(const char *name, symbol_compare_ftype *compare, struct dict_iterator *iterator)
static void add_symbol_nonexpandable(struct dictionary *dict, struct symbol *sym)
static int size_hashed(const struct dictionary *dict)
static struct symbol * iter_match_first_hashed(const struct dictionary *dict, const char *name, symbol_compare_ftype *compare, struct dict_iterator *iterator)
struct dictionary_linear_expandable linear_expandable
static void free_obstack(struct dictionary *dict)
struct symbol * dict_iterator_first(const struct dictionary *dict, struct dict_iterator *iterator)
unsigned int msymbol_hash_iw(const char *string)
static struct symbol * iterator_next_linear(struct dict_iterator *iterator)
#define DICT_HASHED_BUCKETS(d)
#define DICT_ITERATOR_INDEX(iter)