Makefile.in (c-ppoutput.o): Update.
authorNeil Booth <neil@daikokuya.co.uk>
Thu, 6 Mar 2003 23:12:30 +0000 (23:12 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Thu, 6 Mar 2003 23:12:30 +0000 (23:12 +0000)
* Makefile.in (c-ppoutput.o): Update.
* c-common.h (init_pp_output): New.
(preprocess_file): Update.
* c-lex.c (init_c_lex): Move mbchar initialization to cpplib.
Register builtins.
* c-opts.c (c_common_init): Call init_pp_output if preprocessing.
Make call to cpp_read_main_file common to whether preprocessing
or not.  Don't register builtins.
* c-ppoutput.c: Include c-pragma.h.
(setup_callbacks): Rename init_pp_output.
(preprocess_file): No longer setup callbacks or call
cpp_read_main_file.
* cpphash.h (_cpp_init_mbchar): New.
* cppinit.c (init_library): Call _cpp_init_mbchar.
* cpplex.c (_cpp_init_mbchar): New.

From-SVN: r63913

gcc/ChangeLog
gcc/Makefile.in
gcc/c-common.h
gcc/c-lex.c
gcc/c-opts.c
gcc/c-ppoutput.c
gcc/cpphash.h
gcc/cppinit.c
gcc/cpplex.c

index 3850c9814b196830d19546c4a24c5ff5e0f3e2b5..33e127d1fd060f075d43b0490ab4a24086ea7fe9 100644 (file)
@@ -1,3 +1,21 @@
+2003-03-06  Neil Booth  <neil@daikokuya.co.uk>
+
+       * Makefile.in (c-ppoutput.o): Update.
+       * c-common.h (init_pp_output): New.
+       (preprocess_file): Update.
+       * c-lex.c (init_c_lex): Move mbchar initialization to cpplib.
+       Register builtins.
+       * c-opts.c (c_common_init): Call init_pp_output if preprocessing.
+       Make call to cpp_read_main_file common to whether preprocessing
+       or not.  Don't register builtins.
+       * c-ppoutput.c: Include c-pragma.h.
+       (setup_callbacks): Rename init_pp_output.
+       (preprocess_file): No longer setup callbacks or call
+       cpp_read_main_file.
+       * cpphash.h (_cpp_init_mbchar): New.
+       * cppinit.c (init_library): Call _cpp_init_mbchar.
+       * cpplex.c (_cpp_init_mbchar): New.
+
 2003-03-06  Roger Sayle  <roger@eyesopen.com>
 
        * emit-rtl.c (gen_lowpart): When requesting the low-part of a
index f4c3ba54e71d2c372b44f588a2f5afeb61dad774..86d4b65c8f81e32bb5370e5d0cc9be25d445bd3a 100644 (file)
@@ -1236,7 +1236,7 @@ c-lex.o : c-lex.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
     c-pragma.h input.h intl.h flags.h toplev.h output.h \
     mbchar.h $(CPPLIB_H) $(EXPR_H) $(TM_P_H)
 c-ppoutput.o : c-ppoutput.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
-    c-common.h $(TREE_H) $(CPPLIB_H) cpphash.h $(TM_P_H)
+    c-common.h $(TREE_H) $(CPPLIB_H) cpphash.h $(TM_P_H) c-pragma.h
 c-objc-common.o : c-objc-common.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
     $(C_TREE_H) $(RTL_H) insn-config.h integrate.h $(EXPR_H) $(C_TREE_H) \
     flags.h toplev.h tree-inline.h diagnostic.h integrate.h $(VARRAY_H) \
index fb0b6c7364d27a0c4fbca711bdbaa6f26c99caeb..5214ef765a8cf492fd7507c565e35e7f354701a2 100644 (file)
@@ -1292,8 +1292,9 @@ extern void c_common_read_pch                     PARAMS ((cpp_reader *pfile,
                                                         int fd,
                                                         const char *orig));
 extern void c_common_write_pch                 PARAMS ((void));
-extern void preprocess_file                    PARAMS ((cpp_reader *,
-                                                        const char *,
-                                                        FILE *));
+
+/* In c-ppoutput.c  */
+extern void init_pp_output                     PARAMS ((FILE *));
+extern void preprocess_file                    PARAMS ((cpp_reader *));
 
 #endif /* ! GCC_C_COMMON_H */
index 452056a3c936ed6ef741590a2330a67c51024331..9e97ad76b61675517fc4892139dbd829f392fe6a 100644 (file)
@@ -111,14 +111,9 @@ init_c_lex ()
       toplevel->time = body_time;
     }
   
-#ifdef MULTIBYTE_CHARS
-  /* Change to the native locale for multibyte conversions.  */
-  setlocale (LC_CTYPE, "");
-  GET_ENVIRONMENT (literal_codeset, "LANG");
-#endif
-
   cb = cpp_get_callbacks (parse_in);
 
+  cb->register_builtins = cb_register_builtins;
   cb->line_change = cb_line_change;
   cb->ident = cb_ident;
   cb->file_change = cb_file_change;
index 97ba6cc5b92993101a394d95068242099ac89002..ebf22d7d972e4cfe0f9c3c31f1da85fb248e982c 100644 (file)
@@ -1512,10 +1512,6 @@ c_common_init (filename)
   cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
   cpp_opts->unsigned_wchar = TREE_UNSIGNED (wchar_type_node);
 
-  /* Register preprocessor built-ins before calls to
-     cpp_main_file.  */
-  cpp_get_callbacks (parse_in)->register_builtins = cb_register_builtins;
-
   if (flag_preprocess_only)
     {
       /* Open the output now.  We must do so even if flag_no_output is
@@ -1527,23 +1523,31 @@ c_common_init (filename)
        out_stream = fopen (out_fname, "w");
 
       if (out_stream == NULL)
-       fatal_io_error ("opening output file %s", out_fname);
-      else
-       /* Preprocess the input file to out_stream.  */
-       preprocess_file (parse_in, in_fname, out_stream);
+       {
+         fatal_io_error ("opening output file %s", out_fname);
+         return NULL;
+       }
 
-      /* Exit quickly in toplev.c.  */
-      return NULL;
+      init_pp_output (out_stream);
     }
+  else
+    {
+      init_c_lex ();
 
-  init_c_lex ();
-
-  /* Start it at 0.  */
-  lineno = 0;
+      /* Yuk.  WTF is this?  I do know ObjC relies on it somewhere.  */
+      lineno = 0;
+    }
 
   /* NOTE: we use in_fname here, not the one supplied.  */
   filename = cpp_read_main_file (parse_in, in_fname, ident_hash);
 
+  if (flag_preprocess_only)
+    {
+      if (filename)
+       preprocess_file (parse_in);
+      return NULL;
+    }
+
   /* Has to wait until now so that cpplib has its hash table.  */
   init_pragma ();
 
index 16e2dc174bc40ac4158138746dc2d3702a1b9b63..14ae31bb0b6a0f14731500b2e85f4639af2a1b11 100644 (file)
@@ -24,7 +24,8 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "cpplib.h"
 #include "cpphash.h"
 #include "tree.h"
-#include "c-common.h"
+#include "c-common.h"          /* For flags.  */
+#include "c-pragma.h"          /* For parse_in.  */
 
 /* Encapsulates state used to convert a stream of tokens into a text
    file.  */
@@ -38,8 +39,6 @@ static struct
   unsigned char printed;       /* Nonzero if something output at line.  */
 } print;
 
-static void setup_callbacks PARAMS ((cpp_reader *));
-
 /* General output routines.  */
 static void scan_translation_unit PARAMS ((cpp_reader *));
 static void scan_translation_unit_trad PARAMS ((cpp_reader *));
@@ -64,44 +63,28 @@ static void cb_def_pragma PARAMS ((cpp_reader *, unsigned int));
 
 /* Preprocess and output.  */
 void
-preprocess_file (pfile, in_fname, out_stream)
+preprocess_file (pfile)
      cpp_reader *pfile;
-     const char *in_fname;
-     FILE *out_stream;
 {
-  /* Initialize the print structure.  Setting print.line to -1 here is
-     a trick to guarantee that the first token of the file will cause
-     a linemarker to be output by maybe_print_line.  */
-  print.line = (unsigned int) -1;
-  print.printed = 0;
-  print.prev = 0;
-  print.map = 0;
-  print.outf = out_stream;
+  cpp_finish_options (pfile);
 
-  setup_callbacks (pfile);
-
-  if (cpp_read_main_file (pfile, in_fname, NULL))
+  /* A successful cpp_read_main_file guarantees that we can call
+     cpp_scan_nooutput or cpp_get_token next.  */
+  if (flag_no_output)
     {
-      cpp_finish_options (pfile);
-
-      /* A successful cpp_read_main_file guarantees that we can call
-        cpp_scan_nooutput or cpp_get_token next.  */
-      if (flag_no_output)
-       {
-         /* Scan -included buffers, then the main file.  */
-         while (pfile->buffer->prev)
-           cpp_scan_nooutput (pfile);
-         cpp_scan_nooutput (pfile);
-       }
-      else if (cpp_get_options (pfile)->traditional)
-       scan_translation_unit_trad (pfile);
-      else
-       scan_translation_unit (pfile);
-
-      /* -dM command line option.  Should this be elsewhere?  */
-      if (flag_dump_macros == 'M')
-       cpp_forall_identifiers (pfile, dump_macro, NULL);
+      /* Scan -included buffers, then the main file.  */
+      while (pfile->buffer->prev)
+       cpp_scan_nooutput (pfile);
+      cpp_scan_nooutput (pfile);
     }
+  else if (cpp_get_options (pfile)->traditional)
+    scan_translation_unit_trad (pfile);
+  else
+    scan_translation_unit (pfile);
+
+  /* -dM command line option.  Should this be elsewhere?  */
+  if (flag_dump_macros == 'M')
+    cpp_forall_identifiers (pfile, dump_macro, NULL);
 
   /* Flush any pending output.  */
   if (print.printed)
@@ -109,19 +92,20 @@ preprocess_file (pfile, in_fname, out_stream)
 }
 
 /* Set up the callbacks as appropriate.  */
-static void
-setup_callbacks (pfile)
-     cpp_reader *pfile;
+void
+init_pp_output (out_stream)
+     FILE *out_stream;
 {
-  cpp_options *options = &pfile->opts;
-  cpp_callbacks *cb = cpp_get_callbacks (pfile);
+  cpp_callbacks *cb = cpp_get_callbacks (parse_in);
+
+  cb->register_builtins = cb_register_builtins;
 
   if (!flag_no_output)
     {
       cb->line_change = cb_line_change;
       /* Don't emit #pragma or #ident directives if we are processing
         assembly language; the assembler may choke on them.  */
-      if (options->lang != CLK_ASM)
+      if (cpp_get_options (parse_in)->lang != CLK_ASM)
        {
          cb->ident      = cb_ident;
          cb->def_pragma = cb_def_pragma;
@@ -138,6 +122,15 @@ setup_callbacks (pfile)
       cb->define = cb_define;
       cb->undef  = cb_undef;
     }
+
+  /* Initialize the print structure.  Setting print.line to -1 here is
+     a trick to guarantee that the first token of the file will cause
+     a linemarker to be output by maybe_print_line.  */
+  print.line = (unsigned int) -1;
+  print.printed = 0;
+  print.prev = 0;
+  print.map = 0;
+  print.outf = out_stream;
 }
 
 /* Writes out the preprocessed file, handling spacing and paste
index 3eac96c7d74e806129c0505927d07b6049f98802..6fc6369f793c5af7ba5524caea3ddc06d774d2cc 100644 (file)
@@ -517,6 +517,7 @@ extern cpp_token *_cpp_lex_direct   PARAMS ((cpp_reader *));
 extern int _cpp_equiv_tokens           PARAMS ((const cpp_token *,
                                                 const cpp_token *));
 extern void _cpp_init_tokenrun         PARAMS ((tokenrun *, unsigned int));
+extern void _cpp_init_mbchar           PARAMS ((void));
 
 /* In cppinit.c.  */
 extern void _cpp_maybe_push_include_file PARAMS ((cpp_reader *));
index 2068ba1d675a50edddcf6cfaebea20bc00d89107..76b99b0079d90605231a4354dded9582b53a040d 100644 (file)
@@ -191,6 +191,8 @@ init_library ()
         we were compiled with a compiler that supports C99 designated
         initializers.  */
       init_trigraph_map ();
+
+      _cpp_init_mbchar ();
     }
 }
 
index 169730d53aec29bb1d23454c8f2b5b63405d3f77..7a8af905a4ce4c35ca5a957bfb510a68e8232f77 100644 (file)
@@ -89,6 +89,16 @@ static tokenrun *next_tokenrun PARAMS ((tokenrun *));
 static unsigned int hex_digit_value PARAMS ((unsigned int));
 static _cpp_buff *new_buff PARAMS ((size_t));
 
+/* Change to the native locale for multibyte conversions.  */
+void
+_cpp_init_mbchar ()
+{
+#ifdef MULTIBYTE_CHARS
+  setlocale (LC_CTYPE, "");
+  GET_ENVIRONMENT (literal_codeset, "LANG");
+#endif
+}
+
 /* Utility routine:
 
    Compares, the token TOKEN to the NUL-terminated string STRING.