cpperror.c (print_location): Take line and column, for default positioning use the...
authorNeil Booth <neil@daikokuya.demon.co.uk>
Fri, 14 Sep 2001 22:04:46 +0000 (22:04 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Fri, 14 Sep 2001 22:04:46 +0000 (22:04 +0000)
* 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.
(do_pragma): Kludge for front ends.  Don't expand macros at all.
* 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.
* c-lex.c (c_lex, init_c_lex): Update.
(cb_line_change, src_lineno): New.

From-SVN: r45613

gcc/ChangeLog
gcc/c-lex.c
gcc/cpperror.c
gcc/cpphash.h
gcc/cppinit.c
gcc/cpplex.c
gcc/cpplib.c
gcc/cpplib.h
gcc/cppmacro.c
gcc/cppmain.c
gcc/scan-decls.c

index 281a4eed8d4f438c9de05b508903d91a7c98d573..483400150fcd0ba71d2cae1387aab42c6c411357 100644 (file)
@@ -1,3 +1,28 @@
+2001-09-14  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+       * 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.
+       (do_pragma): Kludge for front ends.  Don't expand macros at all.
+       * 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.
+       * c-lex.c (c_lex, init_c_lex): Update.
+       (cb_line_change, src_lineno): New.
+
 Fri Sep 14 13:54:50 EDT 2001  John Wehle  (john@feith.com)
 
        * tree.c (append_random_chars): Generate the random
index 669bb169e9a97f7070f4071e9385a80499e551d3..3a80a74a550450513eddc440c4e33000ac512e52 100644 (file)
@@ -60,6 +60,9 @@ static const char *cpp_filename;
 /* The current line map.  */
 static const struct line_map *map;
 
+/* The line used to refresh the lineno global variable after each token.  */
+static unsigned int src_lineno;
+
 /* We may keep statistics about how long which files took to compile.  */
 static int header_time, body_time;
 static splay_tree file_info_tree;
@@ -89,6 +92,7 @@ static tree lex_string                PARAMS ((const char *, unsigned int, int));
 static tree lex_charconst      PARAMS ((const cpp_token *));
 static void update_header_times        PARAMS ((const char *));
 static int dump_one_header     PARAMS ((splay_tree_node, void *));
+static void cb_line_change     PARAMS ((cpp_reader *, const cpp_token *, int));
 static void cb_ident           PARAMS ((cpp_reader *, unsigned int,
                                         const cpp_string *));
 static void cb_file_change    PARAMS ((cpp_reader *, const struct line_map *));
@@ -125,6 +129,7 @@ init_c_lex (filename)
 
   cb = cpp_get_callbacks (parse_in);
 
+  cb->line_change = cb_line_change;
   cb->ident = cb_ident;
   cb->file_change = cb_file_change;
   cb->def_pragma = cb_def_pragma;
@@ -243,6 +248,17 @@ cb_ident (pfile, line, str)
 #endif
 }
 
+/* Called at the start of every non-empty line.  TOKEN is the first
+   lexed token on the line.  Used for diagnostic line numbers.  */
+static void
+cb_line_change (pfile, token, parsing_args)
+     cpp_reader *pfile ATTRIBUTE_UNUSED;
+     const cpp_token *token;
+     int parsing_args ATTRIBUTE_UNUSED;
+{
+  src_lineno = SOURCE_LINE (map, token->line);
+}
+
 static void
 cb_file_change (pfile, new_map)
      cpp_reader *pfile ATTRIBUTE_UNUSED;
@@ -762,7 +778,7 @@ 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);
+  lineno = src_lineno;
 
   *value = NULL_TREE;
   type = tok.type;
index 3dbf534affd7d677e91a3c19f88b27dcf2292ef3..6a3b0c149d98b1beff2d16acf1a686051bc020ef 100644 (file)
@@ -29,8 +29,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 #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_reader *,
  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, const char *msgid, ...))
   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, const char *msgid, ...))
   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, const char *msgid, ...))
   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, const char *msgid, ...))
   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, const char *msgid, ...))
   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 acf727f672feaaea2027aadc2dd2f5c2ecaf012d..dd851dcade151f6f9f51d28f7b1f28d62e37419e 100644 (file)
@@ -368,7 +368,7 @@ extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
 /* 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 2cf746104505fc2a8145d9972f42780193dc979c..94e11981b64cd546a10807d7539ca2d466b94861 100644 (file)
@@ -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 6d640e090afa805e84e21a9295f45c796b45886b..32430773fdf3c6564dbcccf50d290091a3fe5542 100644 (file)
@@ -955,13 +955,14 @@ _cpp_lex_token (pfile, dest)
 
       if (result->flags & BOL)
        {
-         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, pfile->state.parsing_args);
        }
 
       /* We don't skip tokens in directives.  */
index 5fe4b1ef8ee1ed09647e9aa1df308fd7d9137c33..06541ad9ecf3b80ed2b2d57f3e8e8e9cd11e0bb3 100644 (file)
@@ -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);
@@ -987,7 +987,14 @@ do_pragma (pfile)
        }
     }
 
-  pfile->state.prevent_expansion--;
+  /* FIXME.  This is an awful kludge to get the front ends to update
+     their notion of line number for diagnostic purposes.  The line
+     number should be passed to the handler and they should do it
+     themselves.  Stand-alone CPP must ignore us, otherwise it will
+     prefix the directive with spaces, hence the 1.  Ugh.  */
+  if (pfile->cb.line_change)
+    (*pfile->cb.line_change)(pfile, &tok, 1);
+
   if (handler)
     (*handler) (pfile);
   else if (pfile->cb.def_pragma)
@@ -995,6 +1002,7 @@ do_pragma (pfile)
       _cpp_backup_tokens (pfile, count);
       (*pfile->cb.def_pragma) (pfile, pfile->directive_line);
     }
+  pfile->state.prevent_expansion--;
 }
 
 static void
@@ -1773,11 +1781,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 ef6a1a56b013816b0abcec1bab5ffebbead3252d..77199956765b81ce21706dda3444988685ee8e05 100644 (file)
@@ -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 *, int));
+  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_reader *, const cpp_token *,
 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 357d1baa940d904c3e8c410165ea581ad5ca17ad..61abc4a37d546f28f61d65670f67615aed1b4b29 100644 (file)
@@ -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 b710dadc576ca0046f3cff2f37f5380fa0208bc2..560d81f4bdda40b61f7bb40f6c1a656a5931d9c7 100644 (file)
@@ -52,6 +52,7 @@ static void maybe_print_line PARAMS ((const struct line_map *, unsigned int));
 
 /* 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 *, int));
 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);
@@ -335,7 +317,34 @@ print_line (map, line, special_flags)
     }
 }
 
-/* Callbacks.  */
+/* Called when a line of output is started.  TOKEN is the first token
+   of the line, and maybe be CPP_EOF.  */
+
+static void
+cb_line_change (pfile, token, parsing_args)
+     cpp_reader *pfile ATTRIBUTE_UNUSED;
+     const cpp_token *token;
+     int parsing_args;
+{
+  if (token->type == CPP_EOF || parsing_args)
+    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 2fe570e3ec409daaf22cda955d6f322c75254834..7fd36cabe9eb76bf537d6384c9c84de233f05038 100644 (file)
@@ -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);