This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

cpplib: traditional output


This simple patch kills a warning from my previous patch, and
deos preprocessed output directly rather than through the
ISO lexer.

I've not fixed line numbers yet.

Neil.

	* cpphash.h (_cpp_read_logical_line_trad,
	_cpp_expansions_different_trad): Update prototypes.
	* cpplex.c (continue_after_nul): New.
	* cppmain.c: Include cpphash.h.
	(scan_translation_unit_trad): New.
	(cpp_preprocess_file): Call it.
	* cpptrad.c (_cpp_read_logical_line_trad): Take new parameter
	overlay.
	(_cpp_expansions_different_trad): Update prototype.

Index: cpphash.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpphash.h,v
retrieving revision 1.160
diff -u -p -r1.160 cpphash.h
--- cpphash.h	10 Jun 2002 06:03:10 -0000	1.160
+++ cpphash.h	10 Jun 2002 06:54:40 -0000
@@ -510,13 +510,14 @@ extern void _cpp_do_file_change PARAMS (
 extern void _cpp_pop_buffer PARAMS ((cpp_reader *));
 
 /* In cpptrad.c.  */
-extern bool _cpp_read_logical_line_trad PARAMS ((cpp_reader *));
+extern bool _cpp_read_logical_line_trad PARAMS ((cpp_reader *, int));
 extern void _cpp_overlay_buffer PARAMS ((cpp_reader *pfile, const uchar *,
 					 size_t));
 extern cpp_hashnode *_cpp_lex_identifier_trad PARAMS ((cpp_reader *));
 extern void _cpp_set_trad_context PARAMS ((cpp_reader *));
 extern bool _cpp_create_trad_definition PARAMS ((cpp_reader *, cpp_macro *));
-extern bool _cpp_expansions_different_trad PARAMS ((cpp_macro *, cpp_macro *));
+extern bool _cpp_expansions_different_trad PARAMS ((const cpp_macro *,
+						    const cpp_macro *));
 
 /* Utility routines and macros.  */
 #define DSC(str) (const uchar *)str, sizeof str - 1
Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplex.c,v
retrieving revision 1.209
diff -u -p -r1.209 cpplex.c
--- cpplex.c	7 Jun 2002 06:26:32 -0000	1.209
+++ cpplex.c	10 Jun 2002 06:54:41 -0000
@@ -891,7 +891,7 @@ continue_after_nul (pfile)
 
   buffer->saved_flags = BOL;
   if (CPP_OPTION (pfile, traditional))
-    more = _cpp_read_logical_line_trad (pfile);
+    more = _cpp_read_logical_line_trad (pfile, true);
   else
     {
       /* Stop parsing arguments with a CPP_EOF.  When we finally come
Index: cppmain.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmain.c,v
retrieving revision 1.96
diff -u -p -r1.96 cppmain.c
--- cppmain.c	22 May 2002 22:02:15 -0000	1.96
+++ cppmain.c	10 Jun 2002 06:54:41 -0000
@@ -24,6 +24,7 @@ Foundation, 59 Temple Place - Suite 330,
 #include "config.h"
 #include "system.h"
 #include "cpplib.h"
+#include "cpphash.h"
 #include "intl.h"
 
 /* Encapsulates state used to convert the stream of tokens coming from
@@ -42,6 +43,7 @@ static void setup_callbacks PARAMS ((cpp
 
 /* General output routines.  */
 static void scan_translation_unit PARAMS ((cpp_reader *));
+static void scan_translation_unit_trad PARAMS ((cpp_reader *));
 static void check_multiline_token PARAMS ((const cpp_string *));
 static int dump_macro PARAMS ((cpp_reader *, cpp_hashnode *, void *));
 
@@ -104,6 +106,8 @@ cpp_preprocess_file (pfile)
 	 cpp_scan_nooutput or cpp_get_token next.  */
       if (options->no_output)
 	cpp_scan_nooutput (pfile);
+      else if (options->traditional)
+	scan_translation_unit_trad (pfile);
       else
 	scan_translation_unit (pfile);
 
@@ -215,6 +219,22 @@ check_multiline_token (str)
   for (i = 0; i < str->len; i++)
     if (str->text[i] == '\n')
       print.line++;
+}
+
+static void
+scan_translation_unit_trad (pfile)
+     cpp_reader *pfile;
+{
+  bool more;
+  size_t len;
+
+  do
+    {
+      more = _cpp_read_logical_line_trad (pfile, false);
+      len = pfile->trad_out_cur - pfile->trad_out_base;
+      fwrite (pfile->trad_out_base, 1, len, print.outf);
+    }
+  while (more);
 }
 
 /* If the token read on logical line LINE needs to be output on a
Index: cpptrad.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpptrad.c,v
retrieving revision 1.7
diff -u -p -r1.7 cpptrad.c
--- cpptrad.c	10 Jun 2002 06:03:13 -0000	1.7
+++ cpptrad.c	10 Jun 2002 06:54:41 -0000
@@ -298,15 +298,18 @@ restore_buff (pfile)
 /* Reads a logical line into the output buffer.  Returns TRUE if there
    is more text left in the buffer.  */
 bool
-_cpp_read_logical_line_trad (pfile)
+_cpp_read_logical_line_trad (pfile, overlay)
      cpp_reader *pfile;
+     int overlay;
 {
   cpp_buffer *buffer;
-  unsigned int first_line;
+  unsigned int first_line = 0;
 
-  restore_buff (pfile);
-
-  first_line = pfile->line = pfile->trad_line;
+  if (overlay)
+    {
+      restore_buff (pfile);
+      first_line = pfile->line = pfile->trad_line;
+    }
 
   buffer = pfile->buffer;
   if (buffer->cur == buffer->rlimit)
@@ -330,10 +333,14 @@ _cpp_read_logical_line_trad (pfile)
   scan_out_logical_line (pfile, NULL);
   buffer->cur = CUR (pfile->context);
 
-  pfile->trad_line = pfile->line;
-  pfile->line = first_line;
-  _cpp_overlay_buffer (pfile, pfile->trad_out_base,
-		       pfile->trad_out_cur - pfile->trad_out_base);
+  if (overlay)
+    {
+      pfile->trad_line = pfile->line;
+      pfile->line = first_line;
+      _cpp_overlay_buffer (pfile, pfile->trad_out_base,
+			   pfile->trad_out_cur - pfile->trad_out_base);
+    }
+
   return true;
 }
 
@@ -855,7 +862,7 @@ canonicalize_text (dest, src, len, pquot
    than in the form of their whitespace.  */
 bool
 _cpp_expansions_different_trad (macro1, macro2)
-     cpp_macro *macro1, *macro2;
+     const cpp_macro *macro1, *macro2;
 {
   uchar *p1 = xmalloc (macro1->count + macro2->count);
   uchar *p2 = p1 + macro1->count;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]