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]

cpplib cleanup, reduce external interface further


Some general cleanup.  Stand-alone CPP used to have to call a
function, cpp_get_line, for each token to know whether it should
appear on a new line of output, and which column to start at.  This
always felt klunky, and was a small drag on performance of standalone
CPP - an extra function call per output token.

Updating the output line number is much better implemented as a
callback, if only because it requires one call per non-empty output
line rather than per token, but the previous code structure did not
allow a simple implementation of this.  It is trivial now, so I've
implemented it below.  Then, with its main customer defecting and the
others able to obtain the same information in other ways, I've removed
cpp_get_line.  Along with other bits of this patch, it brings the
cpp_lexer_pos structure close to death too, but not just yet.

Sigh.  Why do trivial cpplib patches always touch so many files?

Bootstrapping x86 Linux.

Neil.

	* c-lex.c (c_lex): Track line numbers using the token's line
	number.
	* cpperror.c (print_location): Take line and column, for
	default positioning use the previously lexed token.
	(_cpp_begin_message): Take line and column.
	(cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning,
	cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line): Update.
	* cpphash.h (_cpp_begin_message): Update prototype.
	* cppinit.c (push_include): Don't set output line.
	* cpplex.c (_cpp_lex_token): Callback for start of new output lines.
	* cpplib.c (do_diagnostic, _cpp_pop_buffer): Update.
	* cpplib.h (cpp_lookahead, cpp_token_with_pos, cpp_get_line): Remove.
	(struct cpp_token): Remove output_line.
	(struct cpp_callbacks): New member line_change.
	* cppmacro.c (builtin_macro, paste_all_tokens, replace_args,
	cpp_get_token): Preserve BOL flag.
	(cpp_get_line): Remove.
	(_cpp_backup_tokens): Remove useless abort().
	* cppmain.c (cb_line_change): New.
	(scan_translation_unit): Don't worry about starting new lines here.
	* scan-decls.c (scan_decls): Update.

Index: c-lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lex.c,v
retrieving revision 1.150
diff -u -p -r1.150 c-lex.c
--- c-lex.c	2001/08/22 14:34:45	1.150
+++ c-lex.c	2001/09/13 22:33:44
@@ -753,6 +753,7 @@ c_lex (value)
 {
   cpp_token tok;
   enum cpp_ttype type;
+  static unsigned int max_line;
 
   retry:
   timevar_push (TV_CPP);
@@ -761,8 +762,12 @@ c_lex (value)
 
   /* The C++ front end does horrible things with the current line
      number.  To ensure an accurate line number, we must reset it
-     every time we return a token.  */
-  lineno = SOURCE_LINE (map, cpp_get_line (parse_in)->line);
+     every time we return a token.  The original source line increases
+     monotonically, but tokens from macro expansions carry the earlier
+     line where the macro was defined.  */
+  if (tok.line > max_line)
+    max_line = tok.line;
+  lineno = SOURCE_LINE (map, max_line);
 
   *value = NULL_TREE;
   type = tok.type;
Index: cpperror.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpperror.c,v
retrieving revision 1.54
diff -u -p -r1.54 cpperror.c
--- cpperror.c	2001/08/22 20:37:17	1.54
+++ cpperror.c	2001/09/13 22:33:49
@@ -29,8 +29,7 @@ Foundation, 59 Temple Place - Suite 330,
 #include "cpphash.h"
 #include "intl.h"
 
-static void print_location		PARAMS ((cpp_reader *,
-						 const cpp_lexer_pos *));
+static void print_location PARAMS ((cpp_reader *, unsigned int, unsigned int));
 
 /* Don't remove the blank before do, as otherwise the exgettext
    script will mistake this as a function definition */
@@ -38,9 +37,9 @@ static void print_location		PARAMS ((cpp
  do { vfprintf (stderr, _(msgid), ap); putc ('\n', stderr); } while (0)
 
 static void
-print_location (pfile, pos)
+print_location (pfile, line, col)
      cpp_reader *pfile;
-     const cpp_lexer_pos *pos;
+     unsigned int line, col;
 {
   cpp_buffer *buffer = pfile->buffer;
 
@@ -48,17 +47,18 @@ print_location (pfile, pos)
     fprintf (stderr, "%s: ", progname);
   else
     {
-      unsigned int line, col;
       const struct line_map *map;
 
-      if (pos == 0)
-	pos = cpp_get_line (pfile);
-      map = lookup_line (&pfile->line_maps, pos->line);
+      if (line == 0)
+	{
+	  line = pfile->cur_token[-1].line;
+	  col = pfile->cur_token[-1].col;
+	}
 
+      map = lookup_line (&pfile->line_maps, line);
       print_containing_files (&pfile->line_maps, map);
 
-      line = SOURCE_LINE (map, pos->line);
-      col = pos->col;
+      line = SOURCE_LINE (map, line);
       if (col == 0)
 	col = 1;
 
@@ -74,14 +74,15 @@ print_location (pfile, pos)
 }
 
 /* Set up for an error message: print the file and line, bump the error
-   counter, etc.
-   If it returns 0, this error has been suppressed.  */
+   counter, etc.  LINE is the logical line number; zero means to print
+   at the location of the previously lexed token, which tends to be the
+   correct place by default.  Returns 0 if the error has been suppressed.  */
 
 int
-_cpp_begin_message (pfile, code, pos)
+_cpp_begin_message (pfile, code, line, column)
      cpp_reader *pfile;
      enum error_type code;
-     const cpp_lexer_pos *pos;
+     unsigned int line, column;
 {
   int is_warning = 0;
 
@@ -125,7 +126,7 @@ _cpp_begin_message (pfile, code, pos)
       break;
     }
 
-  print_location (pfile, pos);
+  print_location (pfile, line, column);
   if (is_warning)
     fputs (_("warning: "), stderr);
 
@@ -144,7 +145,7 @@ cpp_ice VPARAMS ((cpp_reader *pfile, con
   VA_FIXEDARG (ap, cpp_reader *, pfile);
   VA_FIXEDARG (ap, const char *, msgid);
 
-  if (_cpp_begin_message (pfile, ICE, 0))
+  if (_cpp_begin_message (pfile, ICE, 0, 0))
     v_message (msgid, ap);
 
   VA_CLOSE (ap);
@@ -163,7 +164,7 @@ cpp_fatal VPARAMS ((cpp_reader *pfile, c
   VA_FIXEDARG (ap, cpp_reader *, pfile);
   VA_FIXEDARG (ap, const char *, msgid);
 
-  if (_cpp_begin_message (pfile, FATAL, 0))
+  if (_cpp_begin_message (pfile, FATAL, 0, 0))
     v_message (msgid, ap);
 
   VA_CLOSE (ap);
@@ -176,7 +177,7 @@ cpp_error VPARAMS ((cpp_reader * pfile, 
   VA_FIXEDARG (ap, cpp_reader *, pfile);
   VA_FIXEDARG (ap, const char *, msgid);
 
-  if (_cpp_begin_message (pfile, ERROR, 0))
+  if (_cpp_begin_message (pfile, ERROR, 0, 0))
     v_message (msgid, ap);
 
   VA_CLOSE (ap);
@@ -186,17 +187,13 @@ void
 cpp_error_with_line VPARAMS ((cpp_reader *pfile, int line, int column,
 			     const char *msgid, ...))
 {
-  cpp_lexer_pos pos;
-  
   VA_OPEN (ap, msgid);
   VA_FIXEDARG (ap, cpp_reader *, pfile);
   VA_FIXEDARG (ap, int, line);
   VA_FIXEDARG (ap, int, column);
   VA_FIXEDARG (ap, const char *, msgid);
 
-  pos.line = line;
-  pos.col = column;
-  if (_cpp_begin_message (pfile, ERROR, &pos))
+  if (_cpp_begin_message (pfile, ERROR, line, column))
     v_message (msgid, ap);
 
   VA_CLOSE (ap);
@@ -218,7 +215,7 @@ cpp_warning VPARAMS ((cpp_reader * pfile
   VA_FIXEDARG (ap, cpp_reader *, pfile);
   VA_FIXEDARG (ap, const char *, msgid);
 
-  if (_cpp_begin_message (pfile, WARNING, 0))
+  if (_cpp_begin_message (pfile, WARNING, 0, 0))
     v_message (msgid, ap);
 
   VA_CLOSE (ap);
@@ -228,17 +225,13 @@ void
 cpp_warning_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
 			       const char *msgid, ...))
 {
-  cpp_lexer_pos pos;
-
   VA_OPEN (ap, msgid);
   VA_FIXEDARG (ap, cpp_reader *, pfile);
   VA_FIXEDARG (ap, int, line);
   VA_FIXEDARG (ap, int, column);
   VA_FIXEDARG (ap, const char *, msgid);
 
-  pos.line = line;
-  pos.col = column;
-  if (_cpp_begin_message (pfile, WARNING, &pos))
+  if (_cpp_begin_message (pfile, WARNING, line, column))
     v_message (msgid, ap);
 
   VA_CLOSE (ap);
@@ -251,7 +244,7 @@ cpp_pedwarn VPARAMS ((cpp_reader * pfile
   VA_FIXEDARG (ap, cpp_reader *, pfile);
   VA_FIXEDARG (ap, const char *, msgid);
 
-  if (_cpp_begin_message (pfile, PEDWARN, 0))
+  if (_cpp_begin_message (pfile, PEDWARN, 0, 0))
     v_message (msgid, ap);
 
   VA_CLOSE (ap);
@@ -261,17 +254,13 @@ void
 cpp_pedwarn_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
 			       const char *msgid, ...))
 {
-  cpp_lexer_pos pos;
-  
   VA_OPEN (ap, msgid);
   VA_FIXEDARG (ap, cpp_reader *, pfile);
   VA_FIXEDARG (ap, int, line);
   VA_FIXEDARG (ap, int, column);
   VA_FIXEDARG (ap, const char *, msgid);
 
-  pos.line = line;
-  pos.col = column;
-  if (_cpp_begin_message (pfile, PEDWARN, &pos))
+  if (_cpp_begin_message (pfile, PEDWARN, line, column))
     v_message (msgid, ap);
 
   VA_CLOSE (ap);
Index: cpphash.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpphash.h,v
retrieving revision 1.124
diff -u -p -r1.124 cpphash.h
--- cpphash.h	2001/09/13 20:05:14	1.124
+++ cpphash.h	2001/09/13 22:33:51
@@ -368,7 +368,7 @@ extern unsigned char _cpp_trigraph_map[U
 /* In cpperror.c  */
 enum error_type { WARNING = 0, WARNING_SYSHDR, PEDWARN, ERROR, FATAL, ICE };
 extern int _cpp_begin_message PARAMS ((cpp_reader *, enum error_type,
-				       const cpp_lexer_pos *));
+				       unsigned int, unsigned int));
 
 /* In cppmacro.c */
 extern void _cpp_free_definition	PARAMS ((cpp_hashnode *));
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.180
diff -u -p -r1.180 cppinit.c
--- cppinit.c	2001/09/13 20:05:14	1.180
+++ cppinit.c	2001/09/13 22:33:57
@@ -886,7 +886,7 @@ push_include (pfile, p)
   header.val.str.text = (const unsigned char *) p->arg;
   header.val.str.len = strlen (p->arg);
   /* Make the command line directive take up a line.  */
-  pfile->lexer_pos.line = pfile->lexer_pos.output_line = ++pfile->line;
+  pfile->lexer_pos.line = ++pfile->line;
 
   return _cpp_execute_include (pfile, &header, IT_CMDLINE);
 }
Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplex.c,v
retrieving revision 1.160
diff -u -p -r1.160 cpplex.c
--- cpplex.c	2001/09/13 20:05:15	1.160
+++ cpplex.c	2001/09/13 22:34:02
@@ -953,15 +953,15 @@ _cpp_lex_token (pfile, dest)
       else
 	result = lex_token (pfile, result);
 
-      if (result->flags & BOL)
+      if (result->flags & BOL && !pfile->state.parsing_args)
 	{
-	  pfile->lexer_pos.output_line = result->line;
 	  /* Is this a directive.  If _cpp_handle_directive returns
 	     false, it is an assembler #.  */
 	  if (result->type == CPP_HASH
-	      && !pfile->state.parsing_args
 	      && _cpp_handle_directive (pfile, result->flags & PREV_WHITE))
 	    continue;
+	  if (pfile->cb.line_change && !pfile->state.skipping)
+	    (*pfile->cb.line_change) (pfile, result);
 	}
 
       /* We don't skip tokens in directives.  */
Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.c,v
retrieving revision 1.273
diff -u -p -r1.273 cpplib.c
--- cpplib.c	2001/09/13 20:05:15	1.273
+++ cpplib.c	2001/09/13 22:34:06
@@ -799,7 +799,7 @@ do_diagnostic (pfile, code, print_dir)
      enum error_type code;
      int print_dir;
 {
-  if (_cpp_begin_message (pfile, code, 0))
+  if (_cpp_begin_message (pfile, code, 0, 0))
     {
       if (print_dir)
 	fprintf (stderr, "#%s ", pfile->directive->name);
@@ -1773,11 +1773,7 @@ _cpp_pop_buffer (pfile)
     cpp_error_with_line (pfile, ifs->pos.line, ifs->pos.col,
 			 "unterminated #%s", dtable[ifs->type].name);
 
-  /* The output line can fall out of sync if we missed the final
-     newline from the previous buffer, for example because of an
-     unterminated comment.  Similarly, skipping needs to be cleared in
-     case of a missing #endif.  */
-  pfile->lexer_pos.output_line = pfile->line;
+  /* In case of a missing #endif.  */
   pfile->state.skipping = 0;
 
   /* Update the reader's buffer before _cpp_do_file_change.  */
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.188
diff -u -p -r1.188 cpplib.h
--- cpplib.h	2001/09/13 20:05:16	1.188
+++ cpplib.h	2001/09/13 22:34:09
@@ -42,7 +42,6 @@ typedef struct cpp_string cpp_string;
 typedef struct cpp_hashnode cpp_hashnode;
 typedef struct cpp_macro cpp_macro;
 typedef struct cpp_lexer_pos cpp_lexer_pos;
-typedef struct cpp_lookahead cpp_lookahead;
 typedef struct cpp_callbacks cpp_callbacks;
 
 struct answer;
@@ -191,26 +190,9 @@ struct cpp_token
 struct cpp_lexer_pos
 {
   unsigned int line;
-  unsigned int output_line;
   unsigned short col;
 };
 
-typedef struct cpp_token_with_pos cpp_token_with_pos;
-struct cpp_token_with_pos
-{
-  cpp_token token;
-  cpp_lexer_pos pos;
-};
-
-/* Token lookahead.  */
-struct cpp_lookahead
-{
-  struct cpp_lookahead *next;
-  cpp_token_with_pos *tokens;
-  cpp_lexer_pos pos;
-  unsigned int cur, count, cap;
-};
-
 /* A standalone character.  We may want to make it unsigned for the
    same reason we use unsigned char - to avoid signedness issues.  */
 typedef int cppchar_t;
@@ -390,13 +372,15 @@ struct cpp_options
 /* Call backs.  */
 struct cpp_callbacks
 {
-    void (*file_change) PARAMS ((cpp_reader *, const struct line_map *));
-    void (*include) PARAMS ((cpp_reader *, unsigned int,
-			     const unsigned char *, const cpp_token *));
-    void (*define) PARAMS ((cpp_reader *, unsigned int, cpp_hashnode *));
-    void (*undef) PARAMS ((cpp_reader *, unsigned int, cpp_hashnode *));
-    void (*ident) PARAMS ((cpp_reader *, unsigned int, const cpp_string *));
-    void (*def_pragma) PARAMS ((cpp_reader *, unsigned int));
+  /* Called when a new line of preprocessed output is started.  */
+  void (*line_change) PARAMS ((cpp_reader *, const cpp_token *));
+  void (*file_change) PARAMS ((cpp_reader *, const struct line_map *));
+  void (*include) PARAMS ((cpp_reader *, unsigned int,
+			   const unsigned char *, const cpp_token *));
+  void (*define) PARAMS ((cpp_reader *, unsigned int, cpp_hashnode *));
+  void (*undef) PARAMS ((cpp_reader *, unsigned int, cpp_hashnode *));
+  void (*ident) PARAMS ((cpp_reader *, unsigned int, const cpp_string *));
+  void (*def_pragma) PARAMS ((cpp_reader *, unsigned int));
 };
 
 #define CPP_FATAL_LIMIT 1000
@@ -522,7 +506,6 @@ extern int cpp_avoid_paste PARAMS ((cpp_
 extern enum cpp_ttype cpp_can_paste PARAMS ((cpp_reader *, const cpp_token *,
 					     const cpp_token *, int *));
 extern void cpp_get_token PARAMS ((cpp_reader *, cpp_token *));
-extern const cpp_lexer_pos *cpp_get_line PARAMS ((cpp_reader *));
 extern const unsigned char *cpp_macro_definition PARAMS ((cpp_reader *,
 						  const cpp_hashnode *));
 extern void _cpp_backup_tokens PARAMS ((cpp_reader *, unsigned int));
Index: cppmacro.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v
retrieving revision 1.66
diff -u -p -r1.66 cppmacro.c
--- cppmacro.c	2001/09/13 20:05:16	1.66
+++ cppmacro.c	2001/09/13 22:34:12
@@ -135,7 +135,7 @@ builtin_macro (pfile, token)
      cpp_reader *pfile;
      cpp_token *token;
 {
-  unsigned char flags = ((token->flags & PREV_WHITE) | AVOID_LPASTE);
+  unsigned char flags = ((token->flags & (PREV_WHITE | BOL)) | AVOID_LPASTE);
   cpp_hashnode *node = token->val.node;
 
   switch (node->value.builtin)
@@ -211,21 +211,6 @@ builtin_macro (pfile, token)
   token->flags = flags;
 }
 
-/* Used by cpperror.c to obtain the correct line and column to report
-   in a diagnostic.  */
-const cpp_lexer_pos *
-cpp_get_line (pfile)
-     cpp_reader *pfile;
-{
-  if (pfile->context->prev == NULL)
-    {
-      pfile->lexer_pos.line = pfile->cur_token[-1].line;
-      pfile->lexer_pos.col = pfile->cur_token[-1].col;
-    }
-
-  return &pfile->lexer_pos;
-}
-
 static void
 lock_pools (pfile)
      cpp_reader *pfile;
@@ -454,8 +439,8 @@ paste_all_tokens (pfile, lhs)
 
   /* The pasted token has the PREV_WHITE flag of the LHS, is no longer
      PASTE_LEFT, and is subject to macro expansion.  */
-  lhs->flags &= ~(PREV_WHITE | PASTE_LEFT | NO_EXPAND);
-  lhs->flags |= orig_flags & (PREV_WHITE | AVOID_LPASTE);
+  lhs->flags &= ~(PREV_WHITE | BOL | PASTE_LEFT | NO_EXPAND);
+  lhs->flags |= orig_flags & (PREV_WHITE | BOL | AVOID_LPASTE);
 }
 
 /* Reads the unexpanded tokens of a macro argument into ARG.  VAR_ARGS
@@ -818,8 +803,8 @@ replace_args (pfile, macro, args, list)
 	    memcpy (dest, from, count * sizeof (cpp_token));
 
 	    /* The first token gets PREV_WHITE of the CPP_MACRO_ARG.  */
-	    dest->flags &= ~PREV_WHITE;
-	    dest->flags |= src->flags & PREV_WHITE;
+	    dest->flags &= ~(PREV_WHITE | BOL);
+	    dest->flags |= src->flags & (PREV_WHITE | BOL);
 	    dest->flags |= AVOID_LPASTE;
 
 	    /* The last token gets the PASTE_LEFT of the CPP_MACRO_ARG.  */
@@ -984,7 +969,7 @@ cpp_get_token (pfile, token)
 	  else if (enter_macro_context (pfile, node))
 	    {
 	      /* Pass AVOID_LPASTE and our PREV_WHITE to next token.  */
-	      pfile->buffer->saved_flags = ((token->flags & PREV_WHITE)
+	      pfile->buffer->saved_flags = ((token->flags & (PREV_WHITE | BOL))
 					    | AVOID_LPASTE);
 	      continue;
 	    }
@@ -1042,8 +1027,6 @@ _cpp_backup_tokens (pfile, count)
 	  pfile->cur_token--;
 	  if (pfile->cur_token == pfile->cur_run->base)
 	    {
-	      if (pfile->cur_run == NULL)
-		abort ();
 	      pfile->cur_run = pfile->cur_run->prev;
 	      pfile->cur_token = pfile->cur_run->limit;
 	    }
Index: cppmain.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmain.c,v
retrieving revision 1.77
diff -u -p -r1.77 cppmain.c
--- cppmain.c	2001/08/21 06:20:18	1.77
+++ cppmain.c	2001/09/13 22:34:13
@@ -52,6 +52,7 @@ static void maybe_print_line PARAMS ((co
 
 /* Callback routines for the parser.   Most of these are active only
    in specific modes.  */
+static void cb_line_change PARAMS ((cpp_reader *, const cpp_token *));
 static void cb_define	PARAMS ((cpp_reader *, unsigned int, cpp_hashnode *));
 static void cb_undef	PARAMS ((cpp_reader *, unsigned int, cpp_hashnode *));
 static void cb_include	PARAMS ((cpp_reader *, unsigned int,
@@ -192,6 +193,7 @@ setup_callbacks ()
 {
   cpp_callbacks *cb = cpp_get_callbacks (pfile);
 
+  cb->line_change = cb_line_change;
   if (! options->no_output)
     {
       cb->ident      = cb_ident;
@@ -217,7 +219,7 @@ static void
 scan_translation_unit (pfile)
      cpp_reader *pfile;
 {
-  unsigned int index, line;
+  unsigned int index;
   cpp_token tokens[2], *token;
 
   for (index = 0;; index = 1 - index)
@@ -228,27 +230,8 @@ scan_translation_unit (pfile)
       if (token->type == CPP_EOF)
 	break;
 
-      line = cpp_get_line (pfile)->output_line;
-      if (print.line != line)
-	{
-	  unsigned int col = cpp_get_line (pfile)->col;
-
-	  /* Supply enough whitespace to put this token in its original
-	     column.  Don't bother trying to reconstruct tabs; we can't
-	     get it right in general, and nothing ought to care.  (Yes,
-	     some things do care; the fault lies with them.)  */
-	  maybe_print_line (print.map, line);
-	  if (col > 1)
-	    {
-	      if (token->flags & PREV_WHITE)
-		col--;
-	      while (--col)
-		putc (' ', print.outf);
-	    }
-	}
-      else if ((token->flags & (PREV_WHITE | AVOID_LPASTE))
-	       == AVOID_LPASTE
-	       && cpp_avoid_paste (pfile, &tokens[1 - index], token))
+      if ((token->flags & (PREV_WHITE | AVOID_LPASTE | BOL)) == AVOID_LPASTE
+	  && cpp_avoid_paste (pfile, &tokens[1 - index], token))
 	token->flags |= PREV_WHITE;
       /* Special case '# <directive name>': insert a space between
 	 the # and the token.  This will prevent it from being
@@ -259,7 +242,6 @@ scan_translation_unit (pfile)
 	token->flags |= PREV_WHITE;
 
       cpp_output_token (token, print.outf);
-      print.printed = 1;
       if (token->type == CPP_STRING || token->type == CPP_WSTRING
 	  || token->type == CPP_COMMENT)
 	check_multiline_token (&token->val.str);
@@ -334,8 +316,34 @@ print_line (map, line, special_flags)
       putc ('\n', print.outf);
     }
 }
+
+/* Called when a line of output is started.  TOKEN is the first token
+   of the line, and maybe be CPP_EOF.  */
 
-/* Callbacks.  */
+static void
+cb_line_change (pfile, token)
+     cpp_reader *pfile ATTRIBUTE_UNUSED;
+     const cpp_token *token;
+{
+  if (token->type == CPP_EOF)
+    return;
+
+  maybe_print_line (print.map, token->line);
+  print.printed = 1;
+
+  /* Supply enough spaces to put this token in its original column,
+     one space per column greater than 2, since scan_translation_unit
+     will provide a space if PREV_WHITE.  Don't bother trying to
+     reconstruct tabs; we can't get it right in general, and nothing
+     ought to care.  Some things do care; the fault lies with them.  */
+  if (token->col > 2)
+    {
+      unsigned int spaces = token->col - 2;
+
+      while (spaces--)
+	putc (' ', print.outf);
+    }
+}
 
 static void
 cb_ident (pfile, line, str)
Index: scan-decls.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/scan-decls.c,v
retrieving revision 1.26
diff -u -p -r1.26 scan-decls.c
--- scan-decls.c	2001/08/04 12:01:55	1.26
+++ scan-decls.c	2001/09/13 22:34:13
@@ -170,8 +170,7 @@ scan_decls (pfile, argc, argv)
 			   || token.type == CPP_ELLIPSIS)
 		    have_arg_list = 1;
 		}
-	      recognized_function (&prev_id, 
-				   cpp_get_line (pfile)->line,
+	      recognized_function (&prev_id, token->line,
 				   (saw_inline ? 'I'
 				    : in_extern_C_brace || current_extern_C
 				    ? 'F' : 'f'), have_arg_list);


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