diff options
author | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-03-12 23:46:05 +0000 |
---|---|---|
committer | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-03-12 23:46:05 +0000 |
commit | 5ecec5dabe4dbe0744ff950108e23d2675e77eac (patch) | |
tree | a98d122ee7a482f328ecd041626122a0cd1beaa8 /gcc/cppinit.c | |
parent | a25d35f6be24a9f7ee6b012ee5fef7b81a7ec9df (diff) | |
download | ppe42-gcc-5ecec5dabe4dbe0744ff950108e23d2675e77eac.tar.gz ppe42-gcc-5ecec5dabe4dbe0744ff950108e23d2675e77eac.zip |
Convert cpplib to use libiberty/hashtab.c.
* cpplib.h (struct cpp_reader): Make hashtab and
all_include_files of type 'struct htab *'. Delete HASHSIZE
and ALL_INCLUDE_HASHSIZE macros.
* cpphash.h: Update prototypes.
(struct hashnode): Remove next, prev, and bucket_hdr members.
Make length a size_t. Add hash member.
(struct ihash): Remove next member. Add hash member. Make
name a flexible array member.
* cppfiles.c: Include hashtab.h.
(include_hash): Delete.
(IHASHSIZE): New macro.
(hash_IHASH, eq_IHASH, _cpp_init_include_hash): New functions.
(cpp_included): Do the hash lookup here.
(_cpp_find_include_file): Rewrite.
(cpp_read_file): Put the "fake" hash entry into the hash
table. Honor the control_macro, if it turns out we've seen
the file before. Don't push the buffer here.
(_cpp_read_include_file): Push the buffer here.
(OMODES): New macro. Use it whenever we call open(2).
* cpphash.c: Include hashtab.h.
(hash_HASHNODE, eq_HASHNODE, del_HASHNODE, dump_hash_helper,
_cpp_init_macro_hash, _cpp_dump_macro_hash, _cpp_make_hashnode,
_cpp_lookup_slot): New functions.
(HASHSIZE): new macro.
(hashf, _cpp_install, _cpp_delete_macro): Delete.
(_cpp_lookup): Use hashtab.h routines.
* cppinit.c: Include hashtab.h.
(cpp_reader_init): Call _cpp_init_macro_hash and
_cpp_init_include_hash. Don't allocate hashtab directly.
(cpp_cleanup): Just call htab_delete on pfile->hashtab and
pfile->all_include_files.
(initialize_builtins): Use _cpp_make_hashnode and
htab_find_slot to add hash entries.
(cpp_finish): Just call _cpp_dump_macro_hash.
* cpplib.c: Include hashtab.h.
(do_define): Use _cpp_lookup_slot and _cpp_make_hashnode to
create hash entries.
(do_pragma_poison, do_assert): Likewise.
(do_include): Don't push the buffer here. Don't increment
system_include_depth unless _cpp_read_include_file succeeds.
(do_undef, do_unassert): Use _cpp_lookup_slot and htab_clear_slot
or htab_remove_elt.
(do_pragma_implementation): Use alloca to create copy.
* Makefile.in: Update dependencies.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@32497 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cppinit.c')
-rw-r--r-- | gcc/cppinit.c | 48 |
1 files changed, 11 insertions, 37 deletions
diff --git a/gcc/cppinit.c b/gcc/cppinit.c index c1bb1eb6e48..f6fd246c59c 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -28,6 +28,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "prefix.h" #include "intl.h" #include "version.h" +#include "hashtab.h" #include "mkdeps.h" /* Predefined symbols, built-in macros, and the default include path. */ @@ -554,7 +555,8 @@ cpp_reader_init (pfile) pfile->token_buffer = (U_CHAR *) xmalloc (pfile->token_buffer_size); CPP_SET_WRITTEN (pfile, 0); - pfile->hashtab = (HASHNODE **) xcalloc (HASHSIZE, sizeof (HASHNODE *)); + _cpp_init_macro_hash (pfile); + _cpp_init_include_hash (pfile); } /* Free resources used by PFILE. @@ -563,7 +565,6 @@ void cpp_cleanup (pfile) cpp_reader *pfile; { - int i; while (CPP_BUFFER (pfile) != NULL) cpp_pop_buffer (pfile); @@ -584,25 +585,8 @@ cpp_cleanup (pfile) if (pfile->deps) deps_free (pfile->deps); - for (i = ALL_INCLUDE_HASHSIZE; --i >= 0; ) - { - IHASH *imp, *next; - for (imp = pfile->all_include_files[i]; imp; imp = next) - { - next = imp->next; - free ((PTR) imp->name); - free ((PTR) imp->nshort); - free (imp); - } - pfile->all_include_files[i] = 0; - } - - for (i = HASHSIZE; --i >= 0;) - { - while (pfile->hashtab[i]) - _cpp_delete_macro (pfile->hashtab[i]); - } - free (pfile->hashtab); + htab_delete (pfile->hashtab); + htab_delete (pfile->all_include_files); } @@ -654,7 +638,6 @@ static const struct builtin builtin_array[] = /* Subroutine of cpp_start_read; reads the builtins table above and enters the macros into the hash table. */ - static void initialize_builtins (pfile) cpp_reader *pfile; @@ -662,6 +645,7 @@ initialize_builtins (pfile) int len; const struct builtin *b; const char *val; + HASHNODE *hp; for(b = builtin_array; b->name; b++) { if ((b->flags & STDC) && CPP_TRADITIONAL (pfile)) @@ -670,7 +654,10 @@ initialize_builtins (pfile) val = (b->flags & ULP) ? user_label_prefix : b->value; len = strlen (b->name); - _cpp_install (pfile, b->name, len, b->type, val); + hp = _cpp_make_hashnode (b->name, len, b->type, -1); + hp->value.cpval = val; + *(htab_find_slot (pfile->hashtab, (void *)hp, 1)) = hp; + if ((b->flags & DUMP) && CPP_OPTIONS (pfile)->debug_output) dump_special_to_buffer (pfile, b->name); } @@ -1015,20 +1002,7 @@ cpp_finish (pfile) } if (opts->dump_macros == dump_only) - { - int i; - HASHNODE *h; - for (i = HASHSIZE; --i >= 0;) - { - for (h = pfile->hashtab[i]; h; h = h->next) - if (h->type == T_MACRO) - { - _cpp_dump_definition (pfile, h->name, h->length, - h->value.defn); - CPP_PUTC (pfile, '\n'); - } - } - } + _cpp_dump_macro_hash (pfile); } static void |