From 29a72a4f09d8606f1414e5380c5eeb2ad5fc6737 Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Tue, 28 Mar 2000 21:45:02 +0000 Subject: [PATCH] cppfiles.c (hash_IHASH): Just return i->hash. 2000-03-28 Zack Weinberg * 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. From-SVN: r32792 --- gcc/ChangeLog | 26 ++++++++++++++++++++++-- gcc/cppfiles.c | 51 +++++++++++++++++++++++++---------------------- gcc/cpphash.c | 54 ++++++++++++++++++++++++++++++++------------------ gcc/cpphash.h | 1 + gcc/cppinit.c | 3 ++- gcc/cpplib.c | 7 ++++++- 6 files changed, 95 insertions(+), 47 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index abbdd6c7246..2f07047620b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,25 @@ +2000-03-28 Zack Weinberg + + * 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. + 2000-03-28 Jason Merrill * config/arm/arm.md (return peepholes): Update to reflect the new @@ -36,11 +58,11 @@ Tue Mar 28 08:29:46 2000 Jan Hubicka 2000-03-28 Neil Booth - * (cpplex.c) _cpp_read_and_prescan. Mark end of input buffer with + * cpplex.c (_cpp_read_and_prescan): Mark end of input buffer with '\\' rather than a null character, so nulls are not special. Fix "\\\n" handling in end-of-buffer conditions. Use trigraph map to speed trigraph conversion. - (_cpp_init_input_buffer) Initialize trigraph map. + (_cpp_init_input_buffer): Initialize trigraph map. 2000-03-27 Alan Modra diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c index bc137a93708..f46052e8b29 100644 --- a/gcc/cppfiles.c +++ b/gcc/cppfiles.c @@ -66,18 +66,8 @@ static unsigned int hash_IHASH (x) const void *x; { - IHASH *i = (IHASH *)x; - unsigned int r = 0, len = 0; - const U_CHAR *s = i->nshort; - - if (i->hash != (unsigned long)-1) - return i->hash; - - do - len++, r = r * 67 + (*s++ - 113); - while (*s && *s != '.'); - i->hash = r + len; - return r + len; + const IHASH *i = (const IHASH *)x; + return i->hash; } /* Compare an existing IHASH structure with a potential one. */ @@ -158,8 +148,9 @@ cpp_included (pfile, fname) { IHASH dummy, *ptr; dummy.nshort = fname; - dummy.hash = -1; - ptr = htab_find (pfile->all_include_files, (const void *)&dummy); + dummy.hash = _cpp_calc_hash (fname, strlen (fname)); + ptr = htab_find_with_hash (pfile->all_include_files, + (const void *)&dummy, dummy.hash); return (ptr != NULL); } @@ -219,11 +210,12 @@ find_include_file (pfile, fname, search_start, ihash, before) int f; char *name; - dummy.hash = -1; dummy.nshort = fname; + dummy.hash = _cpp_calc_hash (fname, strlen (fname)); path = (fname[0] == '/') ? ABSOLUTE_PATH : search_start; - slot = (IHASH **) htab_find_slot (pfile->all_include_files, - (const void *)&dummy, 1); + slot = (IHASH **) htab_find_slot_with_hash (pfile->all_include_files, + (const void *)&dummy, + dummy.hash, 1); if (*slot && (ih = redundant_include_p (pfile, *slot, path))) { @@ -280,10 +272,20 @@ find_include_file (pfile, fname, search_start, ihash, before) } else { - ih = (IHASH *) xmalloc (sizeof (IHASH) + strlen (name) - + strlen (fname) + 1); - ih->nshort = ih->name + strlen (fname) + 1; - strcpy ((char *)ih->nshort, fname); + char *s; + + if ((s = strstr (name, fname)) != NULL) + { + ih = (IHASH *) xmalloc (sizeof (IHASH) + strlen (name)); + ih->nshort = ih->name + (s - name); + } + else + { + ih = (IHASH *) xmalloc (sizeof (IHASH) + strlen (name) + + strlen (fname) + 1); + ih->nshort = ih->name + strlen (name) + 1; + strcpy ((char *)ih->nshort, fname); + } } strcpy ((char *)ih->name, name); ih->foundhere = path; @@ -620,10 +622,11 @@ cpp_read_file (pfile, fname) if (fname == NULL) fname = ""; - dummy.hash = -1; dummy.nshort = fname; - slot = (IHASH **) htab_find_slot (pfile->all_include_files, - (const void *) &dummy, 1); + dummy.hash = _cpp_calc_hash (fname, strlen (fname)); + slot = (IHASH **) htab_find_slot_with_hash (pfile->all_include_files, + (const void *) &dummy, + dummy.hash, 1); if (*slot && (ih = redundant_include_p (pfile, *slot, ABSOLUTE_PATH))) { if (ih == (IHASH *)-1) 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; diff --git a/gcc/cpphash.h b/gcc/cpphash.h index 704cab47d87..2cfbad7acf3 100644 --- a/gcc/cpphash.h +++ b/gcc/cpphash.h @@ -255,6 +255,7 @@ enum file_change_code {same_file, rename_file, enter_file, leave_file}; extern HASHNODE *_cpp_make_hashnode PARAMS ((const U_CHAR *, size_t, enum node_type, unsigned long)); +extern unsigned int _cpp_calc_hash PARAMS ((const U_CHAR *, size_t)); extern HASHNODE *_cpp_lookup PARAMS ((cpp_reader *, const U_CHAR *, int)); extern HASHNODE **_cpp_lookup_slot PARAMS ((cpp_reader *, diff --git a/gcc/cppinit.c b/gcc/cppinit.c index 419257308a4..1410d7370f0 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -660,7 +660,8 @@ initialize_builtins (pfile) val = b->value; len = strlen (b->name); - hp = _cpp_make_hashnode (b->name, len, b->type, -1); + hp = _cpp_make_hashnode (b->name, len, b->type, + _cpp_calc_hash (b->name, len)); hp->value.cpval = val; *(htab_find_slot (pfile->hashtab, (void *)hp, 1)) = hp; diff --git a/gcc/cpplib.c b/gcc/cpplib.c index dac186d9904..88433f829c9 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -508,6 +508,8 @@ do_include (pfile) char *token; len = parse_include (pfile, dtable[T_INCLUDE].name); + if (len == 0) + return 0; token = alloca (len + 1); strcpy (token, CPP_PWRITTEN (pfile)); @@ -537,6 +539,8 @@ do_import (pfile) } len = parse_include (pfile, dtable[T_IMPORT].name); + if (len == 0) + return 0; token = alloca (len + 1); strcpy (token, CPP_PWRITTEN (pfile)); @@ -559,7 +563,8 @@ do_include_next (pfile) cpp_pedwarn (pfile, "ANSI C does not allow `#include_next'"); len = parse_include (pfile, dtable[T_INCLUDE_NEXT].name); - + if (len == 0) + return 0; token = alloca (len + 1); strcpy (token, CPP_PWRITTEN (pfile)); -- 2.30.2