diff options
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; |