cppfiles.c (hash_IHASH): Just return i->hash.
authorZack Weinberg <zack@gcc.gnu.org>
Tue, 28 Mar 2000 21:45:02 +0000 (21:45 +0000)
committerZack Weinberg <zack@gcc.gnu.org>
Tue, 28 Mar 2000 21:45:02 +0000 (21:45 +0000)
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.

From-SVN: r32792

gcc/ChangeLog
gcc/cppfiles.c
gcc/cpphash.c
gcc/cpphash.h
gcc/cppinit.c
gcc/cpplib.c

index abbdd6c72467a30f414cf06241ad66368c1b1244..2f07047620be06ec1d51f360cde8e9515e36f0ef 100644 (file)
@@ -1,3 +1,25 @@
+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.
+
 2000-03-28  Jason Merrill  <jason@casey.cygnus.com>
 
        * config/arm/arm.md (return peepholes): Update to reflect the new
@@ -36,11 +58,11 @@ Tue Mar 28 08:29:46 2000  Jan Hubicka  <jh@suse.cz>
 
 2000-03-28  Neil Booth  <NeilB@earthling.net>
 
-        * (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  <alan@linuxcare.com.au>
 
index bc137a93708fd360031b6551e0a66b7cdfd0a538..f46052e8b2940a095966cc9426ed8f756255d1d6 100644 (file)
@@ -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)
index 236a94273fa170a84dead953ad28dd50711d6092..f0f131989925c6bfceba64090b1dda11d1a31938 100644 (file)
@@ -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;
index 704cab47d873ceece0c5bc210f0a98588ab8bf6f..2cfbad7acf3d37eabcf8c3a631e7256580193b0e 100644 (file)
@@ -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 *,
index 419257308a4f25d5fda32ea1eb0ddd2b2d63b040..1410d7370f0b32d83239f2f495dccf86862db530 100644 (file)
@@ -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;
 
index dac186d9904e547e7a96f24ad2ac6641308bd89a..88433f829c92c3bae902f9e85cc24377bdcb7162 100644 (file)
@@ -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));