diff options
author | Zack Weinberg <zack@wolery.cumb.org> | 2000-03-12 23:46:05 +0000 |
---|---|---|
committer | Zack Weinberg <zack@gcc.gnu.org> | 2000-03-12 23:46:05 +0000 |
commit | d35364d13e14ba0eea541a77484c716f1cf82195 (patch) | |
tree | a98d122ee7a482f328ecd041626122a0cd1beaa8 /gcc/cpplib.c | |
parent | 6973bf5482d8a5a150c3ee1424bf7e154e61dd51 (diff) | |
download | gcc-d35364d13e14ba0eea541a77484c716f1cf82195.zip gcc-d35364d13e14ba0eea541a77484c716f1cf82195.tar.gz gcc-d35364d13e14ba0eea541a77484c716f1cf82195.tar.bz2 |
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.
From-SVN: r32497
Diffstat (limited to 'gcc/cpplib.c')
-rw-r--r-- | gcc/cpplib.c | 108 |
1 files changed, 63 insertions, 45 deletions
diff --git a/gcc/cpplib.c b/gcc/cpplib.c index aaecad7..91f86b7 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -24,6 +24,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "cpplib.h" #include "cpphash.h" +#include "hashtab.h" #include "intl.h" #include "mkdeps.h" @@ -659,9 +660,10 @@ do_define (pfile, keyword) cpp_reader *pfile; const struct directive *keyword ATTRIBUTE_UNUSED; { - HASHNODE *hp; + HASHNODE **slot; DEFINITION *def; long here; + unsigned long hash; int len, c; int funlike = 0; U_CHAR *sym; @@ -692,9 +694,11 @@ do_define (pfile, keyword) if (def == 0) return 0; - if ((hp = _cpp_lookup (pfile, sym, len)) != NULL) + slot = _cpp_lookup_slot (pfile, sym, len, 1, &hash); + if (*slot) { int ok; + HASHNODE *hp = *slot; /* Redefining a macro is ok if the definitions are the same. */ if (hp->type == T_MACRO) @@ -729,7 +733,11 @@ do_define (pfile, keyword) } } else - _cpp_install (pfile, sym, len, T_MACRO, (char *) def); + { + HASHNODE *hp = _cpp_make_hashnode (sym, len, T_MACRO, hash); + hp->value.defn = def; + *slot = hp; + } if (CPP_OPTIONS (pfile)->debug_output || CPP_OPTIONS (pfile)->dump_macros == dump_definitions) @@ -1260,21 +1268,12 @@ do_include (pfile, keyword) if (importing) ihash->control_macro = (const U_CHAR *) ""; - if (cpp_push_buffer (pfile, NULL, 0) == NULL) - { - close (fd); - return 0; - } - - if (angle_brackets) - pfile->system_include_depth++; /* Decremented in file_cleanup. */ - if (_cpp_read_include_file (pfile, fd, ihash)) { output_line_command (pfile, enter_file); - pfile->only_seen_white = 2; + if (angle_brackets) + pfile->system_include_depth++; /* Decremented in file_cleanup. */ } - return 0; } @@ -1435,7 +1434,7 @@ do_undef (pfile, keyword) const struct directive *keyword; { int len; - HASHNODE *hp; + HASHNODE **slot; U_CHAR *buf, *name, *limit; int c; long here = CPP_WRITTEN (pfile); @@ -1468,8 +1467,10 @@ do_undef (pfile, keyword) } CPP_SET_WRITTEN (pfile, here); - while ((hp = _cpp_lookup (pfile, name, len)) != NULL) + slot = _cpp_lookup_slot (pfile, name, len, 0, 0); + if (slot) { + HASHNODE *hp = *slot; /* If we are generating additional info for debugging (with -g) we need to pass through all effective #undef commands. */ if (CPP_OPTIONS (pfile)->debug_output && keyword) @@ -1480,7 +1481,8 @@ do_undef (pfile, keyword) { if (hp->type != T_MACRO) cpp_warning (pfile, "undefining `%s'", hp->name); - _cpp_delete_macro (hp); + + htab_clear_slot (pfile->hashtab, (void **)slot); } } @@ -1692,6 +1694,7 @@ do_pragma_implementation (pfile) long written = CPP_WRITTEN (pfile); U_CHAR *name; U_CHAR *copy; + size_t len; token = get_directive_token (pfile); if (token == CPP_VSPACE) @@ -1703,14 +1706,15 @@ do_pragma_implementation (pfile) } name = pfile->token_buffer + written + 1; - copy = (U_CHAR *) xstrdup (name); - copy[strlen(copy)] = '\0'; /* trim trailing quote */ - + len = strlen (name); + copy = (U_CHAR *) alloca (len); + memcpy (copy, name, len - 1); + copy[len] = '\0'; /* trim trailing quote */ + if (cpp_included (pfile, copy)) cpp_warning (pfile, "`#pragma implementation' for `%s' appears after file is included", copy); - free (copy); return 0; } @@ -1721,11 +1725,13 @@ do_pragma_poison (pfile) /* Poison these symbols so that all subsequent usage produces an error message. */ U_CHAR *p; - HASHNODE *hp; + HASHNODE **slot; long written; size_t len; enum cpp_token token; int writeit; + unsigned long hash; + /* As a rule, don't include #pragma poison commands in output, unless the user asks for them. */ writeit = (CPP_OPTIONS (pfile)->debug_output @@ -1747,8 +1753,10 @@ do_pragma_poison (pfile) p = pfile->token_buffer + written; len = strlen (p); - if ((hp = _cpp_lookup (pfile, p, len))) + slot = _cpp_lookup_slot (pfile, p, len, 1, &hash); + if (*slot) { + HASHNODE *hp = *slot; if (hp->type != T_POISON) { cpp_warning (pfile, "poisoning existing macro `%s'", p); @@ -1759,7 +1767,11 @@ do_pragma_poison (pfile) } } else - _cpp_install (pfile, p, len, T_POISON, 0); + { + HASHNODE *hp = _cpp_make_hashnode (p, len, T_POISON, hash); + hp->value.cpval = 0; + *slot = hp; + } if (writeit) CPP_PUTC (pfile, ' '); } @@ -3025,7 +3037,9 @@ do_assert (pfile, keyword) U_CHAR *sym; int ret, c; HASHNODE *base, *this; - int baselen, thislen; + HASHNODE **bslot, **tslot; + size_t blen, tlen; + unsigned long bhash, thash; if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing) cpp_pedwarn (pfile, "ANSI C does not allow `#assert'"); @@ -3049,27 +3063,30 @@ do_assert (pfile, keyword) goto error; } - thislen = strlen (sym); - baselen = (U_CHAR *) strchr (sym, '(') - sym; - this = _cpp_lookup (pfile, sym, thislen); - if (this) + tlen = strlen (sym); + blen = (U_CHAR *) strchr (sym, '(') - sym; + tslot = _cpp_lookup_slot (pfile, sym, tlen, 1, &thash); + if (*tslot) { cpp_warning (pfile, "`%s' re-asserted", sym); goto error; } - base = _cpp_lookup (pfile, sym, baselen); - if (! base) - base = _cpp_install (pfile, sym, baselen, T_ASSERT, 0); - else if (base->type != T_ASSERT) - { - /* Token clash - but with what?! */ - cpp_ice (pfile, "base->type != T_ASSERT in do_assert"); - goto error; - } - - this = _cpp_install (pfile, sym, thislen, T_ASSERT, - (char *)base->value.aschain); + bslot = _cpp_lookup_slot (pfile, sym, blen, 1, &bhash); + if (! *bslot) + *bslot = base = _cpp_make_hashnode (sym, blen, T_ASSERT, bhash); + else + { + base = *bslot; + if (base->type != T_ASSERT) + { + /* Token clash - but with what?! */ + cpp_ice (pfile, "base->type != T_ASSERT in do_assert"); + goto error; + } + } + *tslot = this = _cpp_make_hashnode (sym, tlen, T_ASSERT, thash); + this->value.aschain = base->value.aschain; base->value.aschain = this; pfile->limit = sym; /* Pop */ @@ -3118,9 +3135,9 @@ do_unassert (pfile, keyword) for (this = base->value.aschain; this; this = next) { next = this->value.aschain; - _cpp_delete_macro (this); + htab_remove_elt (pfile->hashtab, this); } - _cpp_delete_macro (base); + htab_remove_elt (pfile->hashtab, base); } else { @@ -3135,10 +3152,11 @@ do_unassert (pfile, keyword) next = next->value.aschain; next->value.aschain = this->value.aschain; - _cpp_delete_macro (this); + htab_remove_elt (pfile->hashtab, this); if (base->value.aschain == NULL) - _cpp_delete_macro (base); /* Last answer for this predicate deleted. */ + /* Last answer for this predicate deleted. */ + htab_remove_elt (pfile->hashtab, base); } pfile->limit = sym; /* Pop */ |