OSDN Git Service

Enable tree browser for all front ends.
[pf3gnuchains/gcc-fork.git] / gcc / cpppch.c
index e87abea..815235c 100644 (file)
@@ -1,5 +1,5 @@
 /* Part of CPP library.  (Precompiled header reading/writing.)
-   Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 
 This program is free software; you can redistribute it and/or modify it
 under the terms of the GNU General Public License as published by the
@@ -17,7 +17,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "config.h"
 #include "system.h"
-#include "coretypes.h"
 #include "cpplib.h"
 #include "cpphash.h"
 #include "intl.h"
@@ -81,7 +80,8 @@ write_macdef (cpp_reader *pfile, cpp_hashnode *hn, void *file_p)
        if (fwrite (&s, sizeof (s), 1, f) != 1
            || fwrite (defn, 1, s.definition_length, f) != s.definition_length)
          {
-           cpp_errno (pfile, DL_ERROR, "while writing precompiled header");
+           cpp_errno (pfile, CPP_DL_ERROR,
+                      "while writing precompiled header");
            return 0;
          }
       }
@@ -109,7 +109,7 @@ struct cpp_savedstate
   size_t hashsize;
   /* Number of definitions */
   size_t n_defs;
-  /* Array of definitions.  In cpp_write_pch_deps it is used for sorting. */
+  /* Array of definitions.  In cpp_write_pch_deps it is used for sorting.  */
   cpp_hashnode **defs;
   /* Space for the next definition.  Definitions are null-terminated
      strings.  */
@@ -244,7 +244,7 @@ count_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
     }
 }
 
-/* Collect the identifiers into the state's string table. */
+/* Collect the identifiers into the state's string table.  */
 static int
 write_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
 {
@@ -314,7 +314,7 @@ cpp_write_pch_deps (cpp_reader *r, FILE *f)
   ss->n_defs = 0;
   cpp_forall_identifiers (r, write_defs, ss);
 
-  /* Sort the list, copy it into a buffer, and write it out. */
+  /* Sort the list, copy it into a buffer, and write it out.  */
   qsort (ss->defs, ss->n_defs, sizeof (cpp_hashnode *), &comp_hashnodes);
   definedstrs = ss->definedstrs = xmalloc (ss->hashsize);
   for (i = 0; i < ss->n_defs; ++i)
@@ -329,7 +329,7 @@ cpp_write_pch_deps (cpp_reader *r, FILE *f)
   if (fwrite (&z, sizeof (z), 1, f) != 1
       || fwrite (ss->definedstrs, ss->hashsize, 1, f) != 1)
     {
-      cpp_errno (r, DL_ERROR, "while writing precompiled header");
+      cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header");
       return -1;
     }
   free (ss->definedstrs);
@@ -353,7 +353,7 @@ cpp_write_pch_state (cpp_reader *r, FILE *f)
   memset (&z, 0, sizeof (z));
   if (fwrite (&z, sizeof (z), 1, f) != 1)
     {
-      cpp_errno (r, DL_ERROR, "while writing precompiled header");
+      cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header");
       return -1;
     }
 
@@ -362,7 +362,13 @@ cpp_write_pch_state (cpp_reader *r, FILE *f)
 
   if (deps_save (r->deps, f) != 0)
     {
-      cpp_errno (r, DL_ERROR, "while writing precompiled header");
+      cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header");
+      return -1;
+    }
+
+  if (! _cpp_save_file_entries (r, f))
+    {
+      cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header");
       return -1;
     }
 
@@ -459,7 +465,7 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
          || h->flags & NODE_POISONED)
        {
          if (CPP_OPTION (r, warn_invalid_pch))
-           cpp_error (r, DL_WARNING_SYSHDR,
+           cpp_error (r, CPP_DL_WARNING_SYSHDR,
                       "%s: not used because `%.*s' not defined",
                       name, m.name_length, namebuf);
          goto fail;
@@ -471,7 +477,7 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
          || memcmp (namebuf, newdefn, m.definition_length) != 0)
        {
          if (CPP_OPTION (r, warn_invalid_pch))
-           cpp_error (r, DL_WARNING_SYSHDR,
+           cpp_error (r, CPP_DL_WARNING_SYSHDR,
               "%s: not used because `%.*s' defined as `%s' not `%.*s'",
                       name, m.name_length, namebuf, newdefn + m.name_length,
                       m.definition_length - m.name_length,
@@ -496,7 +502,7 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
   qsort (nl.defs, nl.n_defs, sizeof (cpp_hashnode *), &comp_hashnodes);
  
   /* Loop through nl.defs and undeftab, both of which are sorted lists.
-     There should be no matches. */
+     There should be no matches.  */
   first = undeftab;
   last = undeftab + m.definition_length;
   i = 0;
@@ -510,7 +516,13 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
       else if (cmp > 0)
        ++i;
       else
-       goto fail;
+       {
+         if (CPP_OPTION (r, warn_invalid_pch))
+           cpp_error (r, CPP_DL_WARNING_SYSHDR, 
+                      "%s: not used because `%s' is defined",
+                      name, first);
+         goto fail;
+       }
     }
    
   free(nl.defs);
@@ -520,7 +532,7 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
   return 0;
 
  error:
-  cpp_errno (r, DL_ERROR, "while reading precompiled header");
+  cpp_errno (r, CPP_DL_ERROR, "while reading precompiled header");
   return -1;
 
  fail:
@@ -606,7 +618,6 @@ cpp_read_state (cpp_reader *r, const char *name, FILE *f,
   struct lexer_state old_state;
   struct save_macro_item *d;
   size_t i, mac_count;
-  int saved_line = r->line;
 
   /* Restore spec_nodes, which will be full of references to the old 
      hashtable entries and so will now be invalid.  */
@@ -681,8 +692,8 @@ cpp_read_state (cpp_reader *r, const char *name, FILE *f,
       else if (m.name_length != m.definition_length)
        {
          if (cpp_push_buffer (r, defn + m.name_length, 
-                              m.definition_length - m.name_length, 
-                              true, 1) != NULL)
+                              m.definition_length - m.name_length, true)
+             != NULL)
            {
              _cpp_clean_line (r);
              if (!_cpp_create_definition (r, h))
@@ -695,7 +706,6 @@ cpp_read_state (cpp_reader *r, const char *name, FILE *f,
     }
 
   r->state = old_state;
-  r->line = saved_line;
   free (defn);
   defn = NULL;
 
@@ -703,9 +713,12 @@ cpp_read_state (cpp_reader *r, const char *name, FILE *f,
       != 0)
     goto error;
 
+  if (! _cpp_read_file_entries (r, f))
+    goto error;
+
   return 0;
   
  error:
-  cpp_errno (r, DL_ERROR, "while reading precompiled header");
+  cpp_errno (r, CPP_DL_ERROR, "while reading precompiled header");
   return -1;
 }