OSDN Git Service

* tree-inline.c (find_builtin_longjmp_call): Save and restore
[pf3gnuchains/gcc-fork.git] / gcc / fix-header.c
index 281e4c4..2bf4692 100644 (file)
@@ -1,6 +1,6 @@
 /* fix-header.c - Make C header file suitable for C++.
    Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2003 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
@@ -71,11 +71,14 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
    Written by Per Bothner <bothner@cygnus.com>, July 1993.  */
 
-#include "hconfig.h"
+#include "bconfig.h"
 #include "system.h"
+#include "coretypes.h"
+#include "tm.h"
 #include "obstack.h"
 #include "scan.h"
 #include "cpplib.h"
+#include "c-incpath.h"
 
 static void v_fatal PARAMS ((const char *, va_list)) ATTRIBUTE_PRINTF (1,0) ATTRIBUTE_NORETURN;
 static void fatal PARAMS ((const char *, ...)) ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
@@ -104,7 +107,7 @@ int missing_extern_C_count = 0;
    directory.  (It might be more efficient to do directory pruning
    earlier in fixproto, but this is simpler and easier to customize.) */
 
-static char *files_to_ignore[] = {
+static const char *const files_to_ignore[] = {
   "X11/",
   FIXPROTO_IGNORE_LIST
   0
@@ -199,7 +202,7 @@ static int inf_skip_spaces PARAMS ((int));
 static int inf_read_upto PARAMS ((sstring *, int));
 static int inf_scan_ident PARAMS ((sstring *, int));
 static int check_protection PARAMS ((int *, int *));
-static void cb_change_file PARAMS ((cpp_reader *, const cpp_file_change *));
+static void cb_file_change PARAMS ((cpp_reader *, const struct line_map *));
 
 static void
 add_symbols (flags, names)
@@ -215,9 +218,9 @@ add_symbols (flags, names)
 }
 
 struct std_include_entry {
-  const char *name;
-  symbol_flags flags;
-  namelist names;
+  const char *const name;
+  const symbol_flags flags;
+  const namelist names;
 };
 
 const char NONE[] = "";  /* The empty namelist.  */
@@ -225,9 +228,9 @@ const char NONE[] = "";  /* The empty namelist.  */
 /* Special name to indicate a continuation line in std_include_table.  */
 const char CONTINUED[] = "";
 
-struct std_include_entry *include_entry;
+const struct std_include_entry *include_entry;
 
-struct std_include_entry std_include_table [] = {
+const struct std_include_entry std_include_table [] = {
   { "ctype.h", ANSI_SYMBOL,
       "isalnum\0isalpha\0iscntrl\0isdigit\0isgraph\0islower\0\
 isprint\0ispunct\0isspace\0isupper\0isxdigit\0tolower\0toupper\0" },
@@ -372,8 +375,6 @@ int seen_errno = 0;
 /* The following are only used when handling stdlib.h */
 int seen_EXIT_FAILURE = 0, seen_EXIT_SUCCESS = 0;
 \f
-#define obstack_chunk_alloc xmalloc
-#define obstack_chunk_free free
 struct obstack scan_file_obstack;
 
 /* NOTE:  If you edit this, also edit gen-protos.c !! */
@@ -411,10 +412,10 @@ int lbrac_line, rbrac_line;
 int required_unseen_count = 0;
 int required_other = 0;
 
-static void 
+static void
 write_lbrac ()
 {
-  
+
 #if ADD_MISSING_EXTERN_C
   if (missing_extern_C_count + required_unseen_count > 0)
     fprintf (outf, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n");
@@ -532,8 +533,8 @@ recognized_function (fname, line, kind, have_arg_list)
     missing_extern_C_count++;
 #endif
 
-  fn = lookup_std_proto ((const char *)fname->val.node->name,
-                        fname->val.node->length);
+  fn = lookup_std_proto ((const char *) NODE_NAME (fname->val.node),
+                        NODE_LEN (fname->val.node));
 
   /* Remove the function from the list of required function.  */
   if (fn)
@@ -546,7 +547,7 @@ recognized_function (fname, line, kind, have_arg_list)
   /* If we have a full prototype, we're done.  */
   if (have_arg_list)
     return;
-      
+
   if (kind == 'I')  /* don't edit inline function */
     return;
 
@@ -598,12 +599,12 @@ check_macro_names (pfile, names)
 }
 
 static void
-cb_change_file (pfile, fc)
+cb_file_change (pfile, map)
      cpp_reader *pfile ATTRIBUTE_UNUSED;
-     const cpp_file_change *fc;
+     const struct line_map *map;
 {
   /* Just keep track of current file name.  */
-  cur_file = fc->to.filename;
+  cur_file = map->to_file;
 }
 
 static void
@@ -612,29 +613,56 @@ read_scan_file (in_fname, argc, argv)
      int argc;
      char **argv;
 {
-  cpp_reader* scan_in;
+  cpp_reader *scan_in;
+  cpp_callbacks *cb;
+  cpp_options *options;
   struct fn_decl *fn;
-  int i;
-  register struct symbol_list *cur_symbols;
+  int i, strings_processed;
+  struct symbol_list *cur_symbols;
 
-  obstack_init (&scan_file_obstack); 
+  obstack_init (&scan_file_obstack);
 
   scan_in = cpp_create_reader (CLK_GNUC89);
-  scan_in->cb.change_file = cb_change_file;
+  cb = cpp_get_callbacks (scan_in);
+  cb->file_change = cb_file_change;
 
   /* We are going to be scanning a header file out of its proper context,
      so ignore warnings and errors.  */
-  CPP_OPTION (scan_in, inhibit_warnings) = 1;
-  CPP_OPTION (scan_in, inhibit_errors) = 1;
-  i = cpp_handle_options (scan_in, argc, argv);
-  if (i < argc && ! CPP_FATAL_ERRORS (scan_in))
-    cpp_fatal (scan_in, "Invalid option `%s'", argv[i]);
-  if (CPP_FATAL_ERRORS (scan_in))
+  options = cpp_get_options (scan_in);
+  options->inhibit_warnings = 1;
+  options->inhibit_errors = 1;
+
+  for (i = 0; i < argc; i += strings_processed)
+    {
+      if (argv[i][0] == 'I')
+       {
+         if (argv[i][1] != '\0')
+           strings_processed = 1, add_path (argv[i] + 1, BRACKET, false);
+         else if (i + 1 == argc)
+           strings_processed = 0;
+         else
+           strings_processed = 2, add_path (argv[i + 1], BRACKET, false);
+       }
+      else
+       strings_processed = cpp_handle_option (scan_in, argc - i, argv + i);
+
+      if (strings_processed == 0)
+       break;
+    }
+
+  if (i < argc)
+    cpp_error (scan_in, DL_ERROR, "invalid option `%s'", argv[i]);
+  if (cpp_errors (scan_in))
     exit (FATAL_EXIT_CODE);
 
-  if (! cpp_start_read (scan_in, in_fname))
+  register_include_chains (scan_in, NULL /* sysroot */, NULL /* iprefix */,
+                          true /* stdinc */, false /* cxx_stdinc */,
+                          false /* verbose */);
+  if (! cpp_read_main_file (scan_in, in_fname, NULL))
     exit (FATAL_EXIT_CODE);
 
+  cpp_finish_options (scan_in);
+
   /* We are scanning a system header, so mark it as such.  */
   cpp_make_system_header (scan_in, 1, 0);
 
@@ -651,18 +679,17 @@ read_scan_file (in_fname, argc, argv)
       int seen_filbuf = 0;
 
       /* Scan the macro expansion of "getchar();".  */
-      cpp_push_buffer (scan_in, getchar_call, sizeof(getchar_call) - 1);
+      cpp_push_buffer (scan_in, getchar_call, sizeof(getchar_call) - 1,
+                      /* from_stage3 */ true, 1);
       for (;;)
        {
-         cpp_token t;
+         const cpp_token *t = cpp_get_token (scan_in);
 
-         cpp_get_token (scan_in, &t);
-         if (t.type == CPP_EOF)
+         if (t->type == CPP_EOF)
            break;
-         else if (cpp_ideq (&t, "_filbuf"))
+         else if (cpp_ideq (t, "_filbuf"))
            seen_filbuf++;
        }
-      cpp_pop_buffer (scan_in);
 
       if (seen_filbuf)
        {
@@ -694,7 +721,7 @@ read_scan_file (in_fname, argc, argv)
   if (required_unseen_count + partial_count + required_other
 #if ADD_MISSING_EXTERN_C
       + missing_extern_C_count
-#endif      
+#endif
       == 0)
     {
       if (verbose)
@@ -725,7 +752,7 @@ write_rbrac ()
 {
   struct fn_decl *fn;
   const char *cptr;
-  register struct symbol_list *cur_symbols;
+  struct symbol_list *cur_symbols;
 
   if (required_unseen_count)
     {
@@ -924,17 +951,17 @@ inf_read_upto (str, delim)
 
 static int
 inf_scan_ident (s, c)
-     register sstring *s;
+     sstring *s;
      int c;
 {
   s->ptr = s->base;
-  if (ISALPHA (c) || c == '_')
+  if (ISIDST (c))
     {
       for (;;)
        {
          SSTRING_PUT (s, c);
          c = INF_GET ();
-         if (c == EOF || !(ISALNUM (c) || c == '_'))
+         if (c == EOF || !(ISIDNUM (c)))
            break;
        }
     }
@@ -1069,16 +1096,16 @@ main (argc, argv)
   int endif_line;
   long to_read;
   long int inf_size;
-  register struct symbol_list *cur_symbols;
+  struct symbol_list *cur_symbols;
 
   if (argv[0] && argv[0][0])
     {
-      register char *p;
+      char *p;
 
       progname = 0;
       for (p = argv[0]; *p; p++)
-        if (*p == '/')
-          progname = p;
+       if (*p == '/')
+         progname = p;
       progname = progname ? progname+1 : argv[0];
     }
 
@@ -1095,7 +1122,7 @@ main (argc, argv)
 #ifdef FIXPROTO_IGNORE_LIST
   for (i = 0; files_to_ignore[i] != NULL; i++)
     {
-      char *ignore_name = files_to_ignore[i];
+      const char *const ignore_name = files_to_ignore[i];
       int ignore_len = strlen (ignore_name);
       if (strncmp (inc_filename, ignore_name, ignore_len) == 0)
        {
@@ -1107,7 +1134,7 @@ main (argc, argv)
              exit (SUCCESS_EXIT_CODE);
            }
        }
-         
+
     }
 #endif
 
@@ -1127,7 +1154,7 @@ main (argc, argv)
 
   if (include_entry->name != NULL)
     {
-      struct std_include_entry *entry;
+      const struct std_include_entry *entry;
       cur_symbol_table_size = 0;
       for (entry = include_entry; ;)
        {
@@ -1141,7 +1168,7 @@ main (argc, argv)
   else
     symbol_table[0].names = NULL;
 
-  /* Count and mark the prototypes required for this include file.  */ 
+  /* Count and mark the prototypes required for this include file.  */
   for (cur_symbols = &symbol_table[0]; cur_symbols->names; cur_symbols++)
     {
       int name_len;
@@ -1177,9 +1204,6 @@ main (argc, argv)
     }
   inf_size = sbuf.st_size;
   inf_buffer = (char *) xmalloc (inf_size + 2);
-  inf_buffer[inf_size] = '\n';
-  inf_buffer[inf_size + 1] = '\0';
-  inf_limit = inf_buffer + inf_size;
   inf_ptr = inf_buffer;
 
   to_read = inf_size;
@@ -1202,6 +1226,11 @@ main (argc, argv)
 
   close (inf_fd);
 
+  /* Inf_size may have changed if read was short (as on VMS) */
+  inf_buffer[inf_size] = '\n';
+  inf_buffer[inf_size + 1] = '\0';
+  inf_limit = inf_buffer + inf_size;
+
   /* If file doesn't end with '\n', add one.  */
   if (inf_limit > inf_buffer && inf_limit[-1] != '\n')
     inf_limit++;
@@ -1245,7 +1274,7 @@ main (argc, argv)
          c = INF_GET ();
          if (c == EOF)
            break;
-         if (ISALPHA (c) || c == '_')
+         if (ISIDST (c))
            {
              c = inf_scan_ident (&buf, c);
              (void) INF_UNGET (c);
@@ -1304,24 +1333,16 @@ v_fatal (str, ap)
   fprintf (stderr, "%s: %s: ", progname, inc_filename);
   vfprintf (stderr, str, ap);
   fprintf (stderr, "\n");
-  
+
   exit (FATAL_EXIT_CODE);
 }
 
 static void
 fatal VPARAMS ((const char *str, ...))
 {
-#ifndef ANSI_PROTOTYPES
-  const char *str;
-#endif
-  va_list ap;
-  
-  VA_START(ap, str);
-
-#ifndef ANSI_PROTOTYPES
-  str = va_arg (ap, const char *);
-#endif
+  VA_OPEN (ap, str);
+  VA_FIXEDARG (ap, const char *, str);
 
-  v_fatal(str, ap);
-  va_end(ap);
+  v_fatal (str, ap);
+  VA_CLOSE (ap);
 }