summaryrefslogtreecommitdiff
path: root/gcc/cppmain.c
diff options
context:
space:
mode:
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2001-09-14 22:04:46 +0000
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2001-09-14 22:04:46 +0000
commit5621a3645f8d24e20cb362058f3dc24c5bccff94 (patch)
tree4c00cb933362af65600541484760cce6502de1a6 /gcc/cppmain.c
parent0812d83c21c766dd94d25afa4a6e30dd54bd97d0 (diff)
downloadgcc-5621a3645f8d24e20cb362058f3dc24c5bccff94.tar.gz
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@45613 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cppmain.c')
-rw-r--r--gcc/cppmain.c57
1 files changed, 33 insertions, 24 deletions
diff --git a/gcc/cppmain.c b/gcc/cppmain.c
index b710dadc576..560d81f4bdd 100644
--- a/gcc/cppmain.c
+++ b/gcc/cppmain.c
@@ -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)