OSDN Git Service

* config/arm/arm.c (arm_promote_prototypes): Use TARGET_AAPCS_BASED.
[pf3gnuchains/gcc-fork.git] / gcc / cpppch.c
index 602711a..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,23 +17,22 @@ 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"
 #include "hashtab.h"
 #include "mkdeps.h"
 
-static int write_macdef PARAMS ((cpp_reader *, cpp_hashnode *, void *));
-static int save_idents PARAMS ((cpp_reader *, cpp_hashnode *, void *));
-static hashval_t hashmem PARAMS ((const void *, size_t));
-static hashval_t cpp_string_hash PARAMS ((const void *));
-static int cpp_string_eq PARAMS ((const void *, const void *));
-static int count_defs PARAMS ((cpp_reader *, cpp_hashnode *, void *));
-static int comp_hashnodes PARAMS ((const void *, const void *));
-static int collect_ht_nodes PARAMS ((cpp_reader *, cpp_hashnode *, void *));
-static int write_defs PARAMS ((cpp_reader *, cpp_hashnode *, void *));
-static int save_macros PARAMS ((cpp_reader *, cpp_hashnode *, void *));
+static int write_macdef (cpp_reader *, cpp_hashnode *, void *);
+static int save_idents (cpp_reader *, cpp_hashnode *, void *);
+static hashval_t hashmem (const void *, size_t);
+static hashval_t cpp_string_hash (const void *);
+static int cpp_string_eq (const void *, const void *);
+static int count_defs (cpp_reader *, cpp_hashnode *, void *);
+static int comp_hashnodes (const void *, const void *);
+static int collect_ht_nodes (cpp_reader *, cpp_hashnode *, void *);
+static int write_defs (cpp_reader *, cpp_hashnode *, void *);
+static int save_macros (cpp_reader *, cpp_hashnode *, void *);
 
 /* This structure represents a macro definition on disk.  */
 struct macrodef_struct 
@@ -47,10 +46,7 @@ struct macrodef_struct
    Suitable for being called by cpp_forall_identifiers.  */
 
 static int
-write_macdef (pfile, hn, file_p)
-     cpp_reader *pfile;
-     cpp_hashnode *hn;
-     void *file_p;
+write_macdef (cpp_reader *pfile, cpp_hashnode *hn, void *file_p)
 {
   FILE *f = (FILE *) file_p;
   switch (hn->type)
@@ -84,7 +80,8 @@ write_macdef (pfile, hn, 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;
          }
       }
@@ -112,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.  */
@@ -123,10 +120,7 @@ struct cpp_savedstate
    put the definition in 'definedstrs'.  */
 
 static int
-save_idents (pfile, hn, ss_p)
-     cpp_reader *pfile ATTRIBUTE_UNUSED;
-     cpp_hashnode *hn;
-     void *ss_p;
+save_idents (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
 {
   struct cpp_savedstate *const ss = (struct cpp_savedstate *)ss_p;
   
@@ -158,9 +152,7 @@ save_idents (pfile, hn, ss_p)
 /* Hash some memory in a generic way.  */
 
 static hashval_t
-hashmem (p_p, sz)
-     const void *p_p;
-     size_t sz;
+hashmem (const void *p_p, size_t sz)
 {
   const unsigned char *p = (const unsigned char *)p_p;
   size_t i;
@@ -175,8 +167,7 @@ hashmem (p_p, sz)
 /* Hash a cpp string for the hashtable machinery.  */
 
 static hashval_t
-cpp_string_hash (a_p)
-     const void *a_p;
+cpp_string_hash (const void *a_p)
 {
   const struct cpp_string *a = (const struct cpp_string *) a_p;
   return hashmem (a->text, a->len);
@@ -185,9 +176,7 @@ cpp_string_hash (a_p)
 /* Compare two cpp strings for the hashtable machinery.  */
 
 static int
-cpp_string_eq (a_p, b_p)
-     const void *a_p;
-     const void *b_p;
+cpp_string_eq (const void *a_p, const void *b_p)
 {
   const struct cpp_string *a = (const struct cpp_string *) a_p;
   const struct cpp_string *b = (const struct cpp_string *) b_p;
@@ -201,9 +190,7 @@ cpp_string_eq (a_p, b_p)
    would be called when reading the precompiled header back in.  */
 
 int
-cpp_save_state (r, f)
-     cpp_reader *r;
-     FILE *f;
+cpp_save_state (cpp_reader *r, FILE *f)
 {
   /* Save the list of non-void identifiers for the dependency checking.  */
   r->savedstate = xmalloc (sizeof (struct cpp_savedstate));
@@ -220,10 +207,7 @@ cpp_save_state (r, f)
 /* Calculate the 'hashsize' field of the saved state.  */
 
 static int
-count_defs (pfile, hn, ss_p)
-     cpp_reader *pfile ATTRIBUTE_UNUSED;
-     cpp_hashnode *hn;
-     void *ss_p;
+count_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
 {
   struct cpp_savedstate *const ss = (struct cpp_savedstate *)ss_p;
   
@@ -260,12 +244,9 @@ count_defs (pfile, hn, ss_p)
     }
 }
 
-/* Collect the identifiers into the state's string table. */
+/* Collect the identifiers into the state's string table.  */
 static int
-write_defs (pfile, hn, ss_p)
-     cpp_reader *pfile ATTRIBUTE_UNUSED;
-     cpp_hashnode *hn;
-     void *ss_p;
+write_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
 {
   struct cpp_savedstate *const ss = (struct cpp_savedstate *)ss_p;
   
@@ -305,9 +286,7 @@ write_defs (pfile, hn, ss_p)
 /* Comparison function for qsort.  The arguments point to pointers of
    type ht_hashnode *.  */
 static int
-comp_hashnodes (px, py)
-     const void *px;
-     const void *py;
+comp_hashnodes (const void *px, const void *py)
 {
   cpp_hashnode *x = *(cpp_hashnode **) px;
   cpp_hashnode *y = *(cpp_hashnode **) py;
@@ -318,9 +297,7 @@ comp_hashnodes (px, py)
    called after the PCH is ready to be saved.  */
 
 int
-cpp_write_pch_deps (r, f)
-     cpp_reader *r;
-     FILE *f;
+cpp_write_pch_deps (cpp_reader *r, FILE *f)
 {
   struct macrodef_struct z;
   struct cpp_savedstate *const ss = r->savedstate;
@@ -337,7 +314,7 @@ cpp_write_pch_deps (r, 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)
@@ -352,7 +329,7 @@ cpp_write_pch_deps (r, 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);
@@ -367,9 +344,7 @@ cpp_write_pch_deps (r, f)
    cpp_read_state.  */
 
 int
-cpp_write_pch_state (r, f)
-     cpp_reader *r;
-     FILE *f;
+cpp_write_pch_state (cpp_reader *r, FILE *f)
 {
   struct macrodef_struct z;
 
@@ -378,7 +353,7 @@ cpp_write_pch_state (r, 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;
     }
 
@@ -387,7 +362,13 @@ cpp_write_pch_state (r, 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;
     }
 
@@ -410,10 +391,8 @@ struct ht_node_list
 /* Callback for collecting identifiers from hash table */
 
 static int
-collect_ht_nodes (pfile, hn, nl_p)
-     cpp_reader *pfile ATTRIBUTE_UNUSED;
-     cpp_hashnode *hn;
-     void *nl_p;
+collect_ht_nodes (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn,
+                 void *nl_p)
 {
   struct ht_node_list *const nl = (struct ht_node_list *)nl_p;
 
@@ -446,10 +425,7 @@ collect_ht_nodes (pfile, hn, nl_p)
 */
 
 int
-cpp_valid_state (r, name, fd)
-     cpp_reader *r;
-     const char *name;
-     int fd;
+cpp_valid_state (cpp_reader *r, const char *name, int fd)
 {
   struct macrodef_struct m;
   size_t namebufsz = 256;
@@ -489,7 +465,7 @@ cpp_valid_state (r, name, 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;
@@ -501,7 +477,7 @@ cpp_valid_state (r, name, 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,
@@ -526,7 +502,7 @@ cpp_valid_state (r, name, 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;
@@ -540,7 +516,13 @@ cpp_valid_state (r, name, 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);
@@ -550,7 +532,7 @@ cpp_valid_state (r, name, 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:
@@ -583,10 +565,7 @@ struct save_macro_data
    a PCH restore.  */
 
 static int 
-save_macros (r, h, data_p)
-     cpp_reader *r ATTRIBUTE_UNUSED;
-     cpp_hashnode *h;
-     void *data_p;
+save_macros (cpp_reader *r ATTRIBUTE_UNUSED, cpp_hashnode *h, void *data_p)
 {
   struct save_macro_data *data = (struct save_macro_data *)data_p;
   if (h->type != NT_VOID
@@ -614,9 +593,7 @@ save_macros (r, h, data_p)
    macros in 'data'.  */
 
 void
-cpp_prepare_state (r, data)
-     cpp_reader *r;
-     struct save_macro_data **data;
+cpp_prepare_state (cpp_reader *r, struct save_macro_data **data)
 {
   struct save_macro_data *d = xmalloc (sizeof (struct save_macro_data));
   
@@ -632,11 +609,8 @@ cpp_prepare_state (r, data)
    DEPNAME is passed to deps_restore.  */
 
 int
-cpp_read_state (r, name, f, data)
-     cpp_reader *r;
-     const char *name;
-     FILE *f;
-     struct save_macro_data *data;
+cpp_read_state (cpp_reader *r, const char *name, FILE *f,
+               struct save_macro_data *data)
 {
   struct macrodef_struct m;
   size_t defnlen = 256;
@@ -644,7 +618,6 @@ cpp_read_state (r, name, f, data)
   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.  */
@@ -719,8 +692,8 @@ cpp_read_state (r, name, f, data)
       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))
@@ -733,7 +706,6 @@ cpp_read_state (r, name, f, data)
     }
 
   r->state = old_state;
-  r->line = saved_line;
   free (defn);
   defn = NULL;
 
@@ -741,9 +713,12 @@ cpp_read_state (r, name, f, data)
       != 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;
 }