old-cross-binutils/gdb/dictionary.h
David Carlton de4f826b0f 2003-06-11 David Carlton <carlton@bactrian.org>
* dictionary.h: New.
	* dictionary.c: New.
	* block.h: Add opaque declaration for struct dictionary.
	(struct block): Add 'dict' member; delete 'hashtable', 'nsyms',
	'sym' members.
	(BLOCK_DICT): New macro.
	Delete macros BLOCK_HASHTABLE, BLOCK_NSYMS, BLOCK_SYM,
	BLOCK_BUCKETS, BLOCK_BUCKET, BLOCK_HASHTABLE_SIZE,
	BLOCK_SHOULD_SORT.
	(ALL_BLOCK_SYMBOLS): Update definition.
	* Makefile.in (SFILES): Add dictionary.c.
	(dictionary_h): New.
	(COMMON_OBS): Add dictionary.o.
	(dictionary.o): New.
	(ada-lang.o): Depend on dictionary_h.
	(buildsym.o, coffread.o, jv-lang.o, mdebugread.o, objfiles.o)
	(stack.o, symmisc.o, symtab.o, tracepoint.o, valops.o)
	(mi-cmd-stack.o): Ditto.
	(gdbtk-cmds.o): Update dependencies.
	(gdbtk-stack.o): Ditto.
	* ada-lang.c: Include dictionary.h.
	(symtab_for_sym): Update uses of ALL_BLOCK_SYMBOLS.
	(fill_in_ada_prototype, debug_print_block): Ditto.
	(ada_add_block_symbols): Update uses of ALL_BLOCK_SYMBOLS; replace
	explicit iteration by use of ALL_BLOCK_SYMBOLS.  Delete variable
	'is_sorted'.
	* mdebugread.c: Include dictionary.h.
	(struct parse_stack): Delete 'maxsyms' member.
	(parse_symbol): Update calls to new_block.  Delete calls to
	shrink_block.  Use dictionary methods.
	(psymtab_to_symtab_1): Delete calls to sort_symtab_syms.
	Update calls to new_symtab.  Don't maintain maxsyms data.
	(mylookup_symbol): Update use of ALL_BLOCK_SYMBOLS.
	(add_symbol): Just call dict_add_symbol.
	(new_symtab): Delete 'maxsyms' argument.
	(new_symtab): Update calls to new_block.
	(new_block): Delete 'maxsyms' argument; add 'function' argument.
	(shrink_block): Delete function.
	(fixup_sigtramp): Update call to new_block.  Add symbol via
	dict_add_symbol.
	* jv-lang.c: Include dictionary.h.
	(get_java_class_symtab): Set the BLOCK_DICT of the blocks
	appropriately.  Set class_symtab->free_func.  Make sure the
	blockvector is big enough to hold two blocks.
	(add_class_symtab_symbol): Use dictionary methods.
	(free_class_block): New function.
	(type_from_class): Replace explicit iteration by
	ALL_BLOCK_SYMBOLS.
	* symtab.h (struct symtab): Replace 'free_ptr' method by
	'free_func'.
	* dwarf2read.c (psymtab_to_symtab_1): Delete call to
	sort_symtab_syms.
	* dwarfread.c (psymtab_to_symtab_1): Delete call to
	sort_symtab_syms.
	* coffread.c (coff_symfile_read): Delete call to sort_symtab_syms.
	Include dictionary.h.
	(patch_opaque_types): Update use of ALL_BLOCK_SYMBOLS.
	* dbxread.c (dbx_psymtab_to_symtab_1): Delete call to
	sort_symtab_syms.
	* objfiles.c: Include dictionary.h.
	(objfile_relocate): Update use of ALL_BLOCK_SYMBOLS.
	* buildsym.c: Include dictionary.h.
	(finish_block): Use dictionary methods.
	(end_symtab): Set free_func to NULL, not free_ptr.
	* tracepoint.c: Include dictionary.h.
	(add_local_symbols): Update use of ALL_BLOCK_SYMBOLS.
	(scope_info): Ditto.
	* stack.c: Include dictionary.h.
	(print_block_frame_locals): Update use of ALL_BLOCK_SYMBOLS.
	(print_block_frame_labels, print_frame_arg_vars)
	(print_frame_args): Ditto.
	* symmisc.c (free_symtab_block): Use dictionary methods.
	(dump_symtab): Ditto.
	(free_symtab): Replace use of 'free_ptr' by 'free_func'.
	Include	dictionary.h.
	* symfile.h: Delete declarations of sort_block_syms,
	sort_symtab_syms.
	* symfile.c (sort_block_syms): Delete.
	(sort_symtab_syms): Delete.
	* symtab.c: Include dictionary.h.
	(lookup_block_symbol): Use dictionary iterators.
	(find_pc_sect_symtab): Update use of ALL_BLOCK_SYMBOLS.
	(search_symbols, make_symbol_completion_list): Ditto.
	(make_symbol_overload_list): Ditto.
	* valops.c (value_of_local): Use dict_empty.
	Include dictionary.h.

2003-06-11  David Carlton  <carlton@bactrian.org>

	* generic/gdbtk-stack.c: Include dictionary.h.
	(gdb_block_vars): Update use of ALL_BLOCK_SYMBOLS.
	(gdb_get_blocks, gdb_get_vars_command): Ditto.
	* generic/gdbtk-cmds.c: Include dictionary.h.
	(gdb_listfuncs): Update use of ALL_BLOCK_SYMBOLS.

2003-06-11  David Carlton  <carlton@bactrian.org>

	* mi-cmd-stack.c: Include dictionary.h.
	(list_args_or_locals): Update use of ALL_BLOCK_SYMBOLS.
2003-06-11 23:29:49 +00:00

156 lines
5.5 KiB
C

/* Routines for name->symbol lookups in GDB.
Copyright 2003 Free Software Foundation, Inc.
Contributed by David Carlton <carlton@bactrian.org> and by Kealia,
Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef DICTIONARY_H
#define DICTIONARY_H
/* An opaque type for dictionaries; only dictionary.c should know
about its innards. */
struct dictionary;
/* Other types needed for declarations. */
struct symbol;
struct obstack;
struct pending;
/* The creation functions for various implementations of
dictionaries. */
/* Create a dictionary implemented via a fixed-size hashtable. All
memory it uses is allocated on OBSTACK; the environment is
initialized from SYMBOL_LIST. */
extern struct dictionary *dict_create_hashed (struct obstack *obstack,
const struct pending
*symbol_list);
/* Create a dictionary implemented via a hashtable that grows as
necessary. The dictionary is initially empty; to add symbols to
it, call dict_add_symbol(). Call dict_free() when you're done with
it. */
extern struct dictionary *dict_create_hashed_expandable (void);
/* Create a dictionary implemented via a fixed-size array. All memory
it uses is allocated on OBSTACK; the environment is initialized
from the SYMBOL_LIST. The symbols are ordered in the same order
that they're found in SYMBOL_LIST. */
extern struct dictionary *dict_create_linear (struct obstack *obstack,
const struct pending
*symbol_list);
/* Create a dictionary implemented via an array that grows as
necessary. The dictionary is initially empty; to add symbols to
it, call dict_add_symbol(). Call dict_free() when you're done with
it. */
extern struct dictionary *dict_create_linear_expandable (void);
/* The functions providing the interface to dictionaries. Note that
the most common parts of the interface, namely symbol lookup, are
only provided via iterator functions. */
/* Free the memory used by a dictionary that's not on an obstack. (If
any.) */
extern void dict_free (struct dictionary *dict);
/* Add a symbol to an expandable dictionary. */
extern void dict_add_symbol (struct dictionary *dict, struct symbol *sym);
/* Is the dictionary empty? */
extern int dict_empty (struct dictionary *dict);
/* A type containing data that is used when iterating over all symbols
in a dictionary. Don't ever look at its innards; this type would
be opaque if we didn't need to be able to allocate it on the
stack. */
struct dict_iterator
{
/* The dictionary that this iterator is associated to. */
const struct dictionary *dict;
/* The next two members are data that is used in a way that depends
on DICT's implementation type. */
int index;
struct symbol *current;
};
/* Initialize ITERATOR to point at the first symbol in DICT, and
return that first symbol, or NULL if DICT is empty. */
extern struct symbol *dict_iterator_first (const struct dictionary *dict,
struct dict_iterator *iterator);
/* Advance ITERATOR, and return the next symbol, or NULL if there are
no more symbols. Don't call this if you've previously received
NULL from dict_iterator_first or dict_iterator_next on this
iteration. */
extern struct symbol *dict_iterator_next (struct dict_iterator *iterator);
/* Initialize ITERATOR to point at the first symbol in DICT whose
SYMBOL_BEST_NAME is NAME (as tested using strcmp_iw), and return
that first symbol, or NULL if there are no such symbols. */
extern struct symbol *dict_iter_name_first (const struct dictionary *dict,
const char *name,
struct dict_iterator *iterator);
/* Advance ITERATOR to point at the next symbol in DICT whose
SYMBOL_BEST_NAME is NAME (as tested using strcmp_iw), or NULL if
there are no more such symbols. Don't call this if you've
previously received NULL from dict_iterator_first or
dict_iterator_next on this iteration. And don't call it unless
ITERATOR was created by a previous call to dict_iter_name_first
with the same NAME. */
extern struct symbol *dict_iter_name_next (const char *name,
struct dict_iterator *iterator);
/* Return some notion of the size of the dictionary: the number of
symbols if we have that, the number of hash buckets otherwise. */
extern int dict_size (const struct dictionary *dict);
/* Macro to loop through all symbols in a dictionary DICT, in no
particular order. ITER is a struct dict_iterator (NOTE: __not__ a
struct dict_iterator *), and SYM points to the current symbol.
It's implemented as a single loop, so you can terminate the loop
early by a break if you desire. */
#define ALL_DICT_SYMBOLS(dict, iter, sym) \
for ((sym) = dict_iterator_first ((dict), &(iter)); \
(sym); \
(sym) = dict_iterator_next (&(iter)))
#endif /* DICTIONARY_H */