diff options
author | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-03-28 21:45:02 +0000 |
---|---|---|
committer | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-03-28 21:45:02 +0000 |
commit | 45aa4a519626ccfd084760e47f86d654a69bd754 (patch) | |
tree | ed8035556cbbe82211a22a58d3beaeef00e865d0 /gcc/cpphash.c | |
parent | 6aae6e10ad921dbe4d034777dd9f37043e23bea3 (diff) | |
download | gcc-45aa4a519626ccfd084760e47f86d654a69bd754.tar.gz |
2000-03-28 Zack Weinberg <zack@wolery.cumb.org>
* cppfiles.c (hash_IHASH): Just return i->hash.
(cpp_included): Set dummy.hash using _cpp_calc_hash. Use
htab_find_with_hash.
(cpp_read_file): Likewise.
(find_include_file): Likewise. Properly initialize
ih->nshort. Share ih->name and ih->nshort if possible.
* cpphash.c (_cpp_calc_hash): New function.
(hash_HASHNODE): Just return h->hash.
(_cpp_lookup): Set dummy.hash using _cpp_calc_hash. Use
htab_find_with_hash.
* cpphash.h: Prototype _cpp_calc_hash.
* cppinit.c (initialize_builtins): Provide a valid hash
to _cpp_make_hashnode, using _cpp_calc_hash.
* cpphash.c (collect_expansion): # is not a special character
in object-like macros. In -traditional mode, /**/ is not
token paste at the beginning or end of the line.
* cpplib.c (do_include, do_import, do_include_next): If
parse_include fails, return immediately.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@32792 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cpphash.c')
-rw-r--r-- | gcc/cpphash.c | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/gcc/cpphash.c b/gcc/cpphash.c index 236a94273fa..f0f13198992 100644 --- a/gcc/cpphash.c +++ b/gcc/cpphash.c @@ -99,26 +99,30 @@ struct argdata int stringified_length; }; -/* Calculate hash of a HASHNODE structure. */ -static unsigned int -hash_HASHNODE (x) - const void *x; +/* Calculate hash of a string of length LEN. */ +unsigned int +_cpp_calc_hash (str, len) + const U_CHAR *str; + size_t len; { - HASHNODE *h = (HASHNODE *)x; - const U_CHAR *s = h->name; - unsigned int len = h->length; - unsigned int n = len, r = 0; + size_t n = len; + unsigned int r = 0; - if (h->hash != (unsigned long)-1) - return h->hash; - do - r = r * 67 + (*s++ - 113); + r = r * 67 + (*str++ - 113); while (--n); - h->hash = r + len; return r + len; } +/* Calculate hash of a HASHNODE structure. */ +static unsigned int +hash_HASHNODE (x) + const void *x; +{ + const HASHNODE *h = (const HASHNODE *)x; + return h->hash; +} + /* Compare two HASHNODE structures. */ static int eq_HASHNODE (x, y) @@ -192,9 +196,10 @@ _cpp_lookup (pfile, name, len) dummy.name = name; dummy.length = len; - dummy.hash = -1; + dummy.hash = _cpp_calc_hash (name, len); - return (HASHNODE *) htab_find (pfile->hashtab, (void *)&dummy); + return (HASHNODE *) htab_find_with_hash (pfile->hashtab, + (void *)&dummy, dummy.hash); } /* Find the hashtable slot for name "name". Used to insert or delete. */ @@ -218,9 +223,11 @@ _cpp_lookup_slot (pfile, name, len, insert, hash) dummy.name = name; dummy.length = len; - dummy.hash = -1; + dummy.hash = _cpp_calc_hash (name, len); - slot = (HASHNODE **) htab_find_slot (pfile->hashtab, (void *)&dummy, insert); + slot = (HASHNODE **) htab_find_slot_with_hash (pfile->hashtab, + (void *)&dummy, + dummy.hash, insert); if (insert) *hash = dummy.hash; return slot; @@ -336,8 +343,13 @@ collect_expansion (pfile, arglist) break; case CPP_STRINGIZE: + /* # is not special in object-like macros. It is special in + function-like macros with no args. (6.10.3.2 para 1.) */ + if (arglist == NULL) + goto norm; + /* # is not special immediately after PASTE. + (Implied by 6.10.3.3 para 4.) */ if (last_token == PASTE) - /* Not really a stringifier. */ goto norm; last_token = STRIZE; CPP_SET_WRITTEN (pfile, here); /* delete from replacement text */ @@ -374,12 +386,16 @@ collect_expansion (pfile, arglist) case CPP_COMMENT: /* We must be in -traditional mode. Pretend this was a token paste, but only if there was no leading or - trailing space. */ + trailing space and it's in the middle of the line. */ CPP_SET_WRITTEN (pfile, here); + if (last_token == START) + break; if (is_hspace (pfile->token_buffer[here-1])) break; if (is_hspace (PEEKC ())) break; + if (PEEKC () == '\n') + break; if (last_token == ARG) endpat->raw_after = 1; last_token = PASTE; |