Commit 97293897 by Neil Booth Committed by Neil Booth

cpperror.c (print_location): Take line and column, for default positioning use…

cpperror.c (print_location): Take line and column, for default positioning use the previously lexed token.

	* 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
parent 4fb1661f
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) Fri Sep 14 13:54:50 EDT 2001 John Wehle (john@feith.com)
* tree.c (append_random_chars): Generate the random * tree.c (append_random_chars): Generate the random
......
...@@ -60,6 +60,9 @@ static const char *cpp_filename; ...@@ -60,6 +60,9 @@ static const char *cpp_filename;
/* The current line map. */ /* The current line map. */
static const struct line_map *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. */ /* We may keep statistics about how long which files took to compile. */
static int header_time, body_time; static int header_time, body_time;
static splay_tree file_info_tree; static splay_tree file_info_tree;
...@@ -89,6 +92,7 @@ static tree lex_string PARAMS ((const char *, unsigned int, int)); ...@@ -89,6 +92,7 @@ static tree lex_string PARAMS ((const char *, unsigned int, int));
static tree lex_charconst PARAMS ((const cpp_token *)); static tree lex_charconst PARAMS ((const cpp_token *));
static void update_header_times PARAMS ((const char *)); static void update_header_times PARAMS ((const char *));
static int dump_one_header PARAMS ((splay_tree_node, void *)); 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, static void cb_ident PARAMS ((cpp_reader *, unsigned int,
const cpp_string *)); const cpp_string *));
static void cb_file_change PARAMS ((cpp_reader *, const struct line_map *)); static void cb_file_change PARAMS ((cpp_reader *, const struct line_map *));
...@@ -125,6 +129,7 @@ init_c_lex (filename) ...@@ -125,6 +129,7 @@ init_c_lex (filename)
cb = cpp_get_callbacks (parse_in); cb = cpp_get_callbacks (parse_in);
cb->line_change = cb_line_change;
cb->ident = cb_ident; cb->ident = cb_ident;
cb->file_change = cb_file_change; cb->file_change = cb_file_change;
cb->def_pragma = cb_def_pragma; cb->def_pragma = cb_def_pragma;
...@@ -243,6 +248,17 @@ cb_ident (pfile, line, str) ...@@ -243,6 +248,17 @@ cb_ident (pfile, line, str)
#endif #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 static void
cb_file_change (pfile, new_map) cb_file_change (pfile, new_map)
cpp_reader *pfile ATTRIBUTE_UNUSED; cpp_reader *pfile ATTRIBUTE_UNUSED;
...@@ -762,7 +778,7 @@ c_lex (value) ...@@ -762,7 +778,7 @@ c_lex (value)
/* The C++ front end does horrible things with the current line /* The C++ front end does horrible things with the current line
number. To ensure an accurate line number, we must reset it number. To ensure an accurate line number, we must reset it
every time we return a token. */ every time we return a token. */
lineno = SOURCE_LINE (map, cpp_get_line (parse_in)->line); lineno = src_lineno;
*value = NULL_TREE; *value = NULL_TREE;
type = tok.type; type = tok.type;
......
...@@ -29,8 +29,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -29,8 +29,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "cpphash.h" #include "cpphash.h"
#include "intl.h" #include "intl.h"
static void print_location PARAMS ((cpp_reader *, static void print_location PARAMS ((cpp_reader *, unsigned int, unsigned int));
const cpp_lexer_pos *));
/* Don't remove the blank before do, as otherwise the exgettext /* Don't remove the blank before do, as otherwise the exgettext
script will mistake this as a function definition */ script will mistake this as a function definition */
...@@ -38,9 +37,9 @@ static void print_location PARAMS ((cpp_reader *, ...@@ -38,9 +37,9 @@ static void print_location PARAMS ((cpp_reader *,
do { vfprintf (stderr, _(msgid), ap); putc ('\n', stderr); } while (0) do { vfprintf (stderr, _(msgid), ap); putc ('\n', stderr); } while (0)
static void static void
print_location (pfile, pos) print_location (pfile, line, col)
cpp_reader *pfile; cpp_reader *pfile;
const cpp_lexer_pos *pos; unsigned int line, col;
{ {
cpp_buffer *buffer = pfile->buffer; cpp_buffer *buffer = pfile->buffer;
...@@ -48,17 +47,18 @@ print_location (pfile, pos) ...@@ -48,17 +47,18 @@ print_location (pfile, pos)
fprintf (stderr, "%s: ", progname); fprintf (stderr, "%s: ", progname);
else else
{ {
unsigned int line, col;
const struct line_map *map; const struct line_map *map;
if (pos == 0) if (line == 0)
pos = cpp_get_line (pfile); {
map = lookup_line (&pfile->line_maps, pos->line); 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); print_containing_files (&pfile->line_maps, map);
line = SOURCE_LINE (map, pos->line); line = SOURCE_LINE (map, line);
col = pos->col;
if (col == 0) if (col == 0)
col = 1; col = 1;
...@@ -74,14 +74,15 @@ print_location (pfile, pos) ...@@ -74,14 +74,15 @@ print_location (pfile, pos)
} }
/* Set up for an error message: print the file and line, bump the error /* Set up for an error message: print the file and line, bump the error
counter, etc. counter, etc. LINE is the logical line number; zero means to print
If it returns 0, this error has been suppressed. */ 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 int
_cpp_begin_message (pfile, code, pos) _cpp_begin_message (pfile, code, line, column)
cpp_reader *pfile; cpp_reader *pfile;
enum error_type code; enum error_type code;
const cpp_lexer_pos *pos; unsigned int line, column;
{ {
int is_warning = 0; int is_warning = 0;
...@@ -125,7 +126,7 @@ _cpp_begin_message (pfile, code, pos) ...@@ -125,7 +126,7 @@ _cpp_begin_message (pfile, code, pos)
break; break;
} }
print_location (pfile, pos); print_location (pfile, line, column);
if (is_warning) if (is_warning)
fputs (_("warning: "), stderr); fputs (_("warning: "), stderr);
...@@ -144,7 +145,7 @@ cpp_ice VPARAMS ((cpp_reader *pfile, const char *msgid, ...)) ...@@ -144,7 +145,7 @@ cpp_ice VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
VA_FIXEDARG (ap, cpp_reader *, pfile); VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, const char *, msgid); 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); v_message (msgid, ap);
VA_CLOSE (ap); VA_CLOSE (ap);
...@@ -163,7 +164,7 @@ cpp_fatal VPARAMS ((cpp_reader *pfile, const char *msgid, ...)) ...@@ -163,7 +164,7 @@ cpp_fatal VPARAMS ((cpp_reader *pfile, const char *msgid, ...))
VA_FIXEDARG (ap, cpp_reader *, pfile); VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, const char *, msgid); 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); v_message (msgid, ap);
VA_CLOSE (ap); VA_CLOSE (ap);
...@@ -176,7 +177,7 @@ cpp_error VPARAMS ((cpp_reader * pfile, const char *msgid, ...)) ...@@ -176,7 +177,7 @@ cpp_error VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
VA_FIXEDARG (ap, cpp_reader *, pfile); VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, const char *, msgid); 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); v_message (msgid, ap);
VA_CLOSE (ap); VA_CLOSE (ap);
...@@ -186,17 +187,13 @@ void ...@@ -186,17 +187,13 @@ void
cpp_error_with_line VPARAMS ((cpp_reader *pfile, int line, int column, cpp_error_with_line VPARAMS ((cpp_reader *pfile, int line, int column,
const char *msgid, ...)) const char *msgid, ...))
{ {
cpp_lexer_pos pos;
VA_OPEN (ap, msgid); VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, cpp_reader *, pfile); VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, int, line); VA_FIXEDARG (ap, int, line);
VA_FIXEDARG (ap, int, column); VA_FIXEDARG (ap, int, column);
VA_FIXEDARG (ap, const char *, msgid); VA_FIXEDARG (ap, const char *, msgid);
pos.line = line; if (_cpp_begin_message (pfile, ERROR, line, column))
pos.col = column;
if (_cpp_begin_message (pfile, ERROR, &pos))
v_message (msgid, ap); v_message (msgid, ap);
VA_CLOSE (ap); VA_CLOSE (ap);
...@@ -218,7 +215,7 @@ cpp_warning VPARAMS ((cpp_reader * pfile, const char *msgid, ...)) ...@@ -218,7 +215,7 @@ cpp_warning VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
VA_FIXEDARG (ap, cpp_reader *, pfile); VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, const char *, msgid); 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); v_message (msgid, ap);
VA_CLOSE (ap); VA_CLOSE (ap);
...@@ -228,17 +225,13 @@ void ...@@ -228,17 +225,13 @@ void
cpp_warning_with_line VPARAMS ((cpp_reader * pfile, int line, int column, cpp_warning_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
const char *msgid, ...)) const char *msgid, ...))
{ {
cpp_lexer_pos pos;
VA_OPEN (ap, msgid); VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, cpp_reader *, pfile); VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, int, line); VA_FIXEDARG (ap, int, line);
VA_FIXEDARG (ap, int, column); VA_FIXEDARG (ap, int, column);
VA_FIXEDARG (ap, const char *, msgid); VA_FIXEDARG (ap, const char *, msgid);
pos.line = line; if (_cpp_begin_message (pfile, WARNING, line, column))
pos.col = column;
if (_cpp_begin_message (pfile, WARNING, &pos))
v_message (msgid, ap); v_message (msgid, ap);
VA_CLOSE (ap); VA_CLOSE (ap);
...@@ -251,7 +244,7 @@ cpp_pedwarn VPARAMS ((cpp_reader * pfile, const char *msgid, ...)) ...@@ -251,7 +244,7 @@ cpp_pedwarn VPARAMS ((cpp_reader * pfile, const char *msgid, ...))
VA_FIXEDARG (ap, cpp_reader *, pfile); VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, const char *, msgid); 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); v_message (msgid, ap);
VA_CLOSE (ap); VA_CLOSE (ap);
...@@ -261,17 +254,13 @@ void ...@@ -261,17 +254,13 @@ void
cpp_pedwarn_with_line VPARAMS ((cpp_reader * pfile, int line, int column, cpp_pedwarn_with_line VPARAMS ((cpp_reader * pfile, int line, int column,
const char *msgid, ...)) const char *msgid, ...))
{ {
cpp_lexer_pos pos;
VA_OPEN (ap, msgid); VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, cpp_reader *, pfile); VA_FIXEDARG (ap, cpp_reader *, pfile);
VA_FIXEDARG (ap, int, line); VA_FIXEDARG (ap, int, line);
VA_FIXEDARG (ap, int, column); VA_FIXEDARG (ap, int, column);
VA_FIXEDARG (ap, const char *, msgid); VA_FIXEDARG (ap, const char *, msgid);
pos.line = line; if (_cpp_begin_message (pfile, PEDWARN, line, column))
pos.col = column;
if (_cpp_begin_message (pfile, PEDWARN, &pos))
v_message (msgid, ap); v_message (msgid, ap);
VA_CLOSE (ap); VA_CLOSE (ap);
......
...@@ -368,7 +368,7 @@ extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1]; ...@@ -368,7 +368,7 @@ extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
/* In cpperror.c */ /* In cpperror.c */
enum error_type { WARNING = 0, WARNING_SYSHDR, PEDWARN, ERROR, FATAL, ICE }; enum error_type { WARNING = 0, WARNING_SYSHDR, PEDWARN, ERROR, FATAL, ICE };
extern int _cpp_begin_message PARAMS ((cpp_reader *, enum error_type, extern int _cpp_begin_message PARAMS ((cpp_reader *, enum error_type,
const cpp_lexer_pos *)); unsigned int, unsigned int));
/* In cppmacro.c */ /* In cppmacro.c */
extern void _cpp_free_definition PARAMS ((cpp_hashnode *)); extern void _cpp_free_definition PARAMS ((cpp_hashnode *));
......
...@@ -886,7 +886,7 @@ push_include (pfile, p) ...@@ -886,7 +886,7 @@ push_include (pfile, p)
header.val.str.text = (const unsigned char *) p->arg; header.val.str.text = (const unsigned char *) p->arg;
header.val.str.len = strlen (p->arg); header.val.str.len = strlen (p->arg);
/* Make the command line directive take up a line. */ /* 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); return _cpp_execute_include (pfile, &header, IT_CMDLINE);
} }
......
...@@ -955,13 +955,14 @@ _cpp_lex_token (pfile, dest) ...@@ -955,13 +955,14 @@ _cpp_lex_token (pfile, dest)
if (result->flags & BOL) if (result->flags & BOL)
{ {
pfile->lexer_pos.output_line = result->line;
/* Is this a directive. If _cpp_handle_directive returns /* Is this a directive. If _cpp_handle_directive returns
false, it is an assembler #. */ false, it is an assembler #. */
if (result->type == CPP_HASH if (result->type == CPP_HASH
&& !pfile->state.parsing_args && !pfile->state.parsing_args
&& _cpp_handle_directive (pfile, result->flags & PREV_WHITE)) && _cpp_handle_directive (pfile, result->flags & PREV_WHITE))
continue; 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. */ /* We don't skip tokens in directives. */
......
...@@ -799,7 +799,7 @@ do_diagnostic (pfile, code, print_dir) ...@@ -799,7 +799,7 @@ do_diagnostic (pfile, code, print_dir)
enum error_type code; enum error_type code;
int print_dir; int print_dir;
{ {
if (_cpp_begin_message (pfile, code, 0)) if (_cpp_begin_message (pfile, code, 0, 0))
{ {
if (print_dir) if (print_dir)
fprintf (stderr, "#%s ", pfile->directive->name); fprintf (stderr, "#%s ", pfile->directive->name);
...@@ -987,7 +987,14 @@ do_pragma (pfile) ...@@ -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) if (handler)
(*handler) (pfile); (*handler) (pfile);
else if (pfile->cb.def_pragma) else if (pfile->cb.def_pragma)
...@@ -995,6 +1002,7 @@ do_pragma (pfile) ...@@ -995,6 +1002,7 @@ do_pragma (pfile)
_cpp_backup_tokens (pfile, count); _cpp_backup_tokens (pfile, count);
(*pfile->cb.def_pragma) (pfile, pfile->directive_line); (*pfile->cb.def_pragma) (pfile, pfile->directive_line);
} }
pfile->state.prevent_expansion--;
} }
static void static void
...@@ -1773,11 +1781,7 @@ _cpp_pop_buffer (pfile) ...@@ -1773,11 +1781,7 @@ _cpp_pop_buffer (pfile)
cpp_error_with_line (pfile, ifs->pos.line, ifs->pos.col, cpp_error_with_line (pfile, ifs->pos.line, ifs->pos.col,
"unterminated #%s", dtable[ifs->type].name); "unterminated #%s", dtable[ifs->type].name);
/* The output line can fall out of sync if we missed the final /* In case of a missing #endif. */
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;
pfile->state.skipping = 0; pfile->state.skipping = 0;
/* Update the reader's buffer before _cpp_do_file_change. */ /* Update the reader's buffer before _cpp_do_file_change. */
......
...@@ -42,7 +42,6 @@ typedef struct cpp_string cpp_string; ...@@ -42,7 +42,6 @@ typedef struct cpp_string cpp_string;
typedef struct cpp_hashnode cpp_hashnode; typedef struct cpp_hashnode cpp_hashnode;
typedef struct cpp_macro cpp_macro; typedef struct cpp_macro cpp_macro;
typedef struct cpp_lexer_pos cpp_lexer_pos; typedef struct cpp_lexer_pos cpp_lexer_pos;
typedef struct cpp_lookahead cpp_lookahead;
typedef struct cpp_callbacks cpp_callbacks; typedef struct cpp_callbacks cpp_callbacks;
struct answer; struct answer;
...@@ -191,26 +190,9 @@ struct cpp_token ...@@ -191,26 +190,9 @@ struct cpp_token
struct cpp_lexer_pos struct cpp_lexer_pos
{ {
unsigned int line; unsigned int line;
unsigned int output_line;
unsigned short col; 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 /* A standalone character. We may want to make it unsigned for the
same reason we use unsigned char - to avoid signedness issues. */ same reason we use unsigned char - to avoid signedness issues. */
typedef int cppchar_t; typedef int cppchar_t;
...@@ -390,13 +372,15 @@ struct cpp_options ...@@ -390,13 +372,15 @@ struct cpp_options
/* Call backs. */ /* Call backs. */
struct cpp_callbacks struct cpp_callbacks
{ {
void (*file_change) PARAMS ((cpp_reader *, const struct line_map *)); /* Called when a new line of preprocessed output is started. */
void (*include) PARAMS ((cpp_reader *, unsigned int, void (*line_change) PARAMS ((cpp_reader *, const cpp_token *, int));
const unsigned char *, const cpp_token *)); void (*file_change) PARAMS ((cpp_reader *, const struct line_map *));
void (*define) PARAMS ((cpp_reader *, unsigned int, cpp_hashnode *)); void (*include) PARAMS ((cpp_reader *, unsigned int,
void (*undef) PARAMS ((cpp_reader *, unsigned int, cpp_hashnode *)); const unsigned char *, const cpp_token *));
void (*ident) PARAMS ((cpp_reader *, unsigned int, const cpp_string *)); void (*define) PARAMS ((cpp_reader *, unsigned int, cpp_hashnode *));
void (*def_pragma) PARAMS ((cpp_reader *, unsigned int)); 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 #define CPP_FATAL_LIMIT 1000
...@@ -522,7 +506,6 @@ extern int cpp_avoid_paste PARAMS ((cpp_reader *, const cpp_token *, ...@@ -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 *, extern enum cpp_ttype cpp_can_paste PARAMS ((cpp_reader *, const cpp_token *,
const cpp_token *, int *)); const cpp_token *, int *));
extern void cpp_get_token PARAMS ((cpp_reader *, cpp_token *)); 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 *, extern const unsigned char *cpp_macro_definition PARAMS ((cpp_reader *,
const cpp_hashnode *)); const cpp_hashnode *));
extern void _cpp_backup_tokens PARAMS ((cpp_reader *, unsigned int)); extern void _cpp_backup_tokens PARAMS ((cpp_reader *, unsigned int));
......
...@@ -135,7 +135,7 @@ builtin_macro (pfile, token) ...@@ -135,7 +135,7 @@ builtin_macro (pfile, token)
cpp_reader *pfile; cpp_reader *pfile;
cpp_token *token; 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; cpp_hashnode *node = token->val.node;
switch (node->value.builtin) switch (node->value.builtin)
...@@ -211,21 +211,6 @@ builtin_macro (pfile, token) ...@@ -211,21 +211,6 @@ builtin_macro (pfile, token)
token->flags = flags; 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 static void
lock_pools (pfile) lock_pools (pfile)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -454,8 +439,8 @@ paste_all_tokens (pfile, lhs) ...@@ -454,8 +439,8 @@ paste_all_tokens (pfile, lhs)
/* The pasted token has the PREV_WHITE flag of the LHS, is no longer /* The pasted token has the PREV_WHITE flag of the LHS, is no longer
PASTE_LEFT, and is subject to macro expansion. */ PASTE_LEFT, and is subject to macro expansion. */
lhs->flags &= ~(PREV_WHITE | PASTE_LEFT | NO_EXPAND); lhs->flags &= ~(PREV_WHITE | BOL | PASTE_LEFT | NO_EXPAND);
lhs->flags |= orig_flags & (PREV_WHITE | AVOID_LPASTE); lhs->flags |= orig_flags & (PREV_WHITE | BOL | AVOID_LPASTE);
} }
/* Reads the unexpanded tokens of a macro argument into ARG. VAR_ARGS /* Reads the unexpanded tokens of a macro argument into ARG. VAR_ARGS
...@@ -818,8 +803,8 @@ replace_args (pfile, macro, args, list) ...@@ -818,8 +803,8 @@ replace_args (pfile, macro, args, list)
memcpy (dest, from, count * sizeof (cpp_token)); memcpy (dest, from, count * sizeof (cpp_token));
/* The first token gets PREV_WHITE of the CPP_MACRO_ARG. */ /* The first token gets PREV_WHITE of the CPP_MACRO_ARG. */
dest->flags &= ~PREV_WHITE; dest->flags &= ~(PREV_WHITE | BOL);
dest->flags |= src->flags & PREV_WHITE; dest->flags |= src->flags & (PREV_WHITE | BOL);
dest->flags |= AVOID_LPASTE; dest->flags |= AVOID_LPASTE;
/* The last token gets the PASTE_LEFT of the CPP_MACRO_ARG. */ /* The last token gets the PASTE_LEFT of the CPP_MACRO_ARG. */
...@@ -984,7 +969,7 @@ cpp_get_token (pfile, token) ...@@ -984,7 +969,7 @@ cpp_get_token (pfile, token)
else if (enter_macro_context (pfile, node)) else if (enter_macro_context (pfile, node))
{ {
/* Pass AVOID_LPASTE and our PREV_WHITE to next token. */ /* 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); | AVOID_LPASTE);
continue; continue;
} }
...@@ -1042,8 +1027,6 @@ _cpp_backup_tokens (pfile, count) ...@@ -1042,8 +1027,6 @@ _cpp_backup_tokens (pfile, count)
pfile->cur_token--; pfile->cur_token--;
if (pfile->cur_token == pfile->cur_run->base) if (pfile->cur_token == pfile->cur_run->base)
{ {
if (pfile->cur_run == NULL)
abort ();
pfile->cur_run = pfile->cur_run->prev; pfile->cur_run = pfile->cur_run->prev;
pfile->cur_token = pfile->cur_run->limit; pfile->cur_token = pfile->cur_run->limit;
} }
......
...@@ -52,6 +52,7 @@ static void maybe_print_line PARAMS ((const struct line_map *, unsigned int)); ...@@ -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 /* Callback routines for the parser. Most of these are active only
in specific modes. */ 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_define PARAMS ((cpp_reader *, unsigned int, cpp_hashnode *));
static void cb_undef 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, static void cb_include PARAMS ((cpp_reader *, unsigned int,
...@@ -192,6 +193,7 @@ setup_callbacks () ...@@ -192,6 +193,7 @@ setup_callbacks ()
{ {
cpp_callbacks *cb = cpp_get_callbacks (pfile); cpp_callbacks *cb = cpp_get_callbacks (pfile);
cb->line_change = cb_line_change;
if (! options->no_output) if (! options->no_output)
{ {
cb->ident = cb_ident; cb->ident = cb_ident;
...@@ -217,7 +219,7 @@ static void ...@@ -217,7 +219,7 @@ static void
scan_translation_unit (pfile) scan_translation_unit (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
unsigned int index, line; unsigned int index;
cpp_token tokens[2], *token; cpp_token tokens[2], *token;
for (index = 0;; index = 1 - index) for (index = 0;; index = 1 - index)
...@@ -228,27 +230,8 @@ scan_translation_unit (pfile) ...@@ -228,27 +230,8 @@ scan_translation_unit (pfile)
if (token->type == CPP_EOF) if (token->type == CPP_EOF)
break; break;
line = cpp_get_line (pfile)->output_line; if ((token->flags & (PREV_WHITE | AVOID_LPASTE | BOL)) == AVOID_LPASTE
if (print.line != line) && cpp_avoid_paste (pfile, &tokens[1 - index], token))
{
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))
token->flags |= PREV_WHITE; token->flags |= PREV_WHITE;
/* Special case '# <directive name>': insert a space between /* Special case '# <directive name>': insert a space between
the # and the token. This will prevent it from being the # and the token. This will prevent it from being
...@@ -259,7 +242,6 @@ scan_translation_unit (pfile) ...@@ -259,7 +242,6 @@ scan_translation_unit (pfile)
token->flags |= PREV_WHITE; token->flags |= PREV_WHITE;
cpp_output_token (token, print.outf); cpp_output_token (token, print.outf);
print.printed = 1;
if (token->type == CPP_STRING || token->type == CPP_WSTRING if (token->type == CPP_STRING || token->type == CPP_WSTRING
|| token->type == CPP_COMMENT) || token->type == CPP_COMMENT)
check_multiline_token (&token->val.str); check_multiline_token (&token->val.str);
...@@ -335,7 +317,34 @@ print_line (map, line, special_flags) ...@@ -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 static void
cb_ident (pfile, line, str) cb_ident (pfile, line, str)
......
...@@ -170,8 +170,7 @@ scan_decls (pfile, argc, argv) ...@@ -170,8 +170,7 @@ scan_decls (pfile, argc, argv)
|| token.type == CPP_ELLIPSIS) || token.type == CPP_ELLIPSIS)
have_arg_list = 1; have_arg_list = 1;
} }
recognized_function (&prev_id, recognized_function (&prev_id, token->line,
cpp_get_line (pfile)->line,
(saw_inline ? 'I' (saw_inline ? 'I'
: in_extern_C_brace || current_extern_C : in_extern_C_brace || current_extern_C
? 'F' : 'f'), have_arg_list); ? 'F' : 'f'), have_arg_list);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment