Commit 500bee0a by Per Bothner Committed by Per Bothner

line-map.h (struct line_maps): New field highest_line.


	* line-map.h (struct line_maps):  New field highest_line.
	(linemap_position_for_column):  Make non-inline function.
	(LINEMAP_POSITION_FOR_COLUMN):  New macro.
	* line-map.c (linemap_init):  Clear highest_line field.
	(linemap_add):  Set highest_line field.
	(linemap_line_start):  Minor optimization - use highest_line field.
	Reduce maximum column hint to 10000.  Update highest_line field.
	(linemap_position_for_column):  Moved from line-map.h.  Optimize a bit.
	* cpphash.h (struct cpp_reader):  Remove line field - instead use
	line_table->highest_line.
	(saved_line):  Remove unused field.
	(CPP_INCREMENT_FILE):  Don't do linemap_lookup - just use newest map.
	Use  line_table's highest_line field instead of cpp_reader's line.
	* cpplib.c (start_directive):  Likewise use highest_line field.
	(do_line, do_linemarker):  Likewise just use newest map.
	(_cpp_do_file_change):  Don't need to set cpp_reader's line field.
	* cpperror.c (cpp_error):  Likewise use highest_line field.
	* cppfiles.c (open_file_failed:  Likewise.
	(cpp_make_system_header):  Likewise use newest map and highest_line.
	* cppinit.c (cpp_create_reader):  Don't initialize removed field.
	* cpplex.c (_cpp_process_line_notes, _cpp_skip_block_comment,
	skip_line_comment, skip_whitespace, _cpp_get_fresh_line,
	_cpp_lex_direct):  Likewise use highest_line.
	(_cpp_lex_direct):  Use new LINEMAP_POSITION_FOR_COLUMN macro.
	* cppmacro.c (_cpp_builtin_macro_text):  Likewise use highest_line,
	and use newest map.
	* cpppch.c (cpp_read_state):  Don't save+restore cpp_reader's line.
	* cpptrad.c (_cpp_overlay_buffer):  Don't save cpp_reader's line.
	(copy_comment, _cpp_scan_out_logical_line):  Likewise use highest_line.

From-SVN: r81074
parent 9344fdb9
2004-04-22 Per Bothner <per@bothner.com>
* line-map.h (struct line_maps): New field highest_line.
(linemap_position_for_column): Make non-inline function.
(LINEMAP_POSITION_FOR_COLUMN): New macro.
* line-map.c (linemap_init): Clear highest_line field.
(linemap_add): Set highest_line field.
(linemap_line_start): Minor optimization - use highest_line field.
Reduce maximum column hint to 10000. Update highest_line field.
(linemap_position_for_column): Moved from line-map.h. Optimize a bit.
* cpphash.h (struct cpp_reader): Remove line field - instead use
line_table->highest_line.
(saved_line): Remove unused field.
(CPP_INCREMENT_FILE): Don't do linemap_lookup - just use newest map.
Use line_table's highest_line field instead of cpp_reader's line.
* cpplib.c (start_directive): Likewise use highest_line field.
(do_line, do_linemarker): Likewise just use newest map.
(_cpp_do_file_change): Don't need to set cpp_reader's line field.
* cpperror.c (cpp_error): Likewise use highest_line field.
* cppfiles.c (open_file_failed: Likewise.
(cpp_make_system_header): Likewise use newest map and highest_line.
* cppinit.c (cpp_create_reader): Don't initialize removed field.
* cpplex.c (_cpp_process_line_notes, _cpp_skip_block_comment,
skip_line_comment, skip_whitespace, _cpp_get_fresh_line,
_cpp_lex_direct): Likewise use highest_line.
(_cpp_lex_direct): Use new LINEMAP_POSITION_FOR_COLUMN macro.
* cppmacro.c (_cpp_builtin_macro_text): Likewise use highest_line,
and use newest map.
* cpppch.c (cpp_read_state): Don't save+restore cpp_reader's line.
* cpptrad.c (_cpp_overlay_buffer): Don't save cpp_reader's line.
(copy_comment, _cpp_scan_out_logical_line): Likewise use highest_line.
2004-04-23 Alan Modra <amodra@bigpond.net.au> 2004-04-23 Alan Modra <amodra@bigpond.net.au>
PR bootstrap/14992 PR bootstrap/14992
......
...@@ -144,7 +144,7 @@ cpp_error (cpp_reader * pfile, int level, const char *msgid, ...) ...@@ -144,7 +144,7 @@ cpp_error (cpp_reader * pfile, int level, const char *msgid, ...)
if (pfile->state.in_directive) if (pfile->state.in_directive)
src_loc = pfile->directive_line; src_loc = pfile->directive_line;
else else
src_loc = pfile->line; src_loc = pfile->line_table->highest_line;
} }
else else
{ {
......
...@@ -806,7 +806,7 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets, ...@@ -806,7 +806,7 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets,
static void static void
open_file_failed (cpp_reader *pfile, _cpp_file *file) open_file_failed (cpp_reader *pfile, _cpp_file *file)
{ {
int sysp = pfile->line > 1 && pfile->buffer ? pfile->buffer->sysp : 0; int sysp = pfile->line_table->highest_line > 1 && pfile->buffer ? pfile->buffer->sysp : 0;
bool print_dep = CPP_OPTION (pfile, deps.style) > !!sysp; bool print_dep = CPP_OPTION (pfile, deps.style) > !!sysp;
errno = file->err_no; errno = file->err_no;
...@@ -987,14 +987,15 @@ void ...@@ -987,14 +987,15 @@ void
cpp_make_system_header (cpp_reader *pfile, int syshdr, int externc) cpp_make_system_header (cpp_reader *pfile, int syshdr, int externc)
{ {
int flags = 0; int flags = 0;
const struct line_map *map = linemap_lookup (pfile->line_table, pfile->line); const struct line_maps *line_table = pfile->line_table;
const struct line_map *map = &line_table->maps[line_table->used-1];
/* 1 = system header, 2 = system header to be treated as C. */ /* 1 = system header, 2 = system header to be treated as C. */
if (syshdr) if (syshdr)
flags = 1 + (externc != 0); flags = 1 + (externc != 0);
pfile->buffer->sysp = flags; pfile->buffer->sysp = flags;
_cpp_do_file_change (pfile, LC_RENAME, map->to_file, _cpp_do_file_change (pfile, LC_RENAME, map->to_file,
SOURCE_LINE (map, pfile->line), flags); SOURCE_LINE (map, pfile->line_table->highest_line), flags);
} }
/* Allow the client to change the current file. Used by the front end /* Allow the client to change the current file. Used by the front end
......
...@@ -65,10 +65,10 @@ typedef unsigned char uchar; ...@@ -65,10 +65,10 @@ typedef unsigned char uchar;
#define CPP_BUF_COL(BUF) CPP_BUF_COLUMN(BUF, (BUF)->cur) #define CPP_BUF_COL(BUF) CPP_BUF_COLUMN(BUF, (BUF)->cur)
#define CPP_INCREMENT_LINE(PFILE, COLS_HINT) do { \ #define CPP_INCREMENT_LINE(PFILE, COLS_HINT) do { \
const struct line_map *map \ const struct line_maps *line_table = PFILE->line_table; \
= linemap_lookup (PFILE->line_table, PFILE->line); \ const struct line_map *map = &line_table->maps[line_table->used-1]; \
unsigned int line = SOURCE_LINE (map, PFILE->line) + 1; \ unsigned int line = SOURCE_LINE (map, line_table->highest_line); \
PFILE->line = linemap_line_start (PFILE->line_table, line, COLS_HINT); \ linemap_line_start (PFILE->line_table, line + 1, COLS_HINT); \
} while (0) } while (0)
/* Maximum nesting of cpp_buffers. We use a static limit, partly for /* Maximum nesting of cpp_buffers. We use a static limit, partly for
...@@ -344,7 +344,6 @@ struct cpp_reader ...@@ -344,7 +344,6 @@ struct cpp_reader
/* Source line tracking. */ /* Source line tracking. */
struct line_maps *line_table; struct line_maps *line_table;
fileline line;
/* The line of the '#' of the current directive. */ /* The line of the '#' of the current directive. */
fileline directive_line; fileline directive_line;
...@@ -466,10 +465,6 @@ struct cpp_reader ...@@ -466,10 +465,6 @@ struct cpp_reader
/* Used for buffer overlays by cpptrad.c. */ /* Used for buffer overlays by cpptrad.c. */
const uchar *saved_cur, *saved_rlimit, *saved_line_base; const uchar *saved_cur, *saved_rlimit, *saved_line_base;
/* Used to save the original line number during traditional
preprocessing. */
unsigned int saved_line;
/* A saved list of the defined macros, for dependency checking /* A saved list of the defined macros, for dependency checking
of precompiled headers. */ of precompiled headers. */
struct cpp_savedstate *savedstate; struct cpp_savedstate *savedstate;
......
...@@ -172,10 +172,8 @@ cpp_create_reader (enum c_lang lang, hash_table *table, ...@@ -172,10 +172,8 @@ cpp_create_reader (enum c_lang lang, hash_table *table,
other entries are correct zero-initialized. */ other entries are correct zero-initialized. */
pfile->no_search_path.name = (char *) ""; pfile->no_search_path.name = (char *) "";
/* Initialize the line map. Start at logical line 1, so we can use /* Initialize the line map. */
a line number of zero for special states. */
pfile->line_table = line_table; pfile->line_table = line_table;
pfile->line = 1;
/* Initialize lexer state. */ /* Initialize lexer state. */
pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments); pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
......
...@@ -270,12 +270,12 @@ _cpp_process_line_notes (cpp_reader *pfile, int in_comment) ...@@ -270,12 +270,12 @@ _cpp_process_line_notes (cpp_reader *pfile, int in_comment)
if (note->type == '\\' || note->type == ' ') if (note->type == '\\' || note->type == ' ')
{ {
if (note->type == ' ' && !in_comment) if (note->type == ' ' && !in_comment)
cpp_error_with_line (pfile, CPP_DL_WARNING, pfile->line, col, cpp_error_with_line (pfile, CPP_DL_WARNING, pfile->line_table->highest_line, col,
"backslash and newline separated by space"); "backslash and newline separated by space");
if (buffer->next_line > buffer->rlimit) if (buffer->next_line > buffer->rlimit)
{ {
cpp_error_with_line (pfile, CPP_DL_PEDWARN, pfile->line, col, cpp_error_with_line (pfile, CPP_DL_PEDWARN, pfile->line_table->highest_line, col,
"backslash-newline at end of file"); "backslash-newline at end of file");
/* Prevent "no newline at end of file" warning. */ /* Prevent "no newline at end of file" warning. */
buffer->next_line = buffer->rlimit; buffer->next_line = buffer->rlimit;
...@@ -290,14 +290,14 @@ _cpp_process_line_notes (cpp_reader *pfile, int in_comment) ...@@ -290,14 +290,14 @@ _cpp_process_line_notes (cpp_reader *pfile, int in_comment)
&& (!in_comment || warn_in_comment (pfile, note))) && (!in_comment || warn_in_comment (pfile, note)))
{ {
if (CPP_OPTION (pfile, trigraphs)) if (CPP_OPTION (pfile, trigraphs))
cpp_error_with_line (pfile, CPP_DL_WARNING, pfile->line, col, cpp_error_with_line (pfile, CPP_DL_WARNING, pfile->line_table->highest_line, col,
"trigraph ??%c converted to %c", "trigraph ??%c converted to %c",
note->type, note->type,
(int) _cpp_trigraph_map[note->type]); (int) _cpp_trigraph_map[note->type]);
else else
{ {
cpp_error_with_line cpp_error_with_line
(pfile, CPP_DL_WARNING, pfile->line, col, (pfile, CPP_DL_WARNING, pfile->line_table->highest_line, col,
"trigraph ??%c ignored, use -trigraphs to enable", "trigraph ??%c ignored, use -trigraphs to enable",
note->type); note->type);
} }
...@@ -343,7 +343,7 @@ _cpp_skip_block_comment (cpp_reader *pfile) ...@@ -343,7 +343,7 @@ _cpp_skip_block_comment (cpp_reader *pfile)
{ {
buffer->cur = cur; buffer->cur = cur;
cpp_error_with_line (pfile, CPP_DL_WARNING, cpp_error_with_line (pfile, CPP_DL_WARNING,
pfile->line, CPP_BUF_COL (buffer), pfile->line_table->highest_line, CPP_BUF_COL (buffer),
"\"/*\" within comment"); "\"/*\" within comment");
} }
} }
...@@ -375,13 +375,13 @@ static int ...@@ -375,13 +375,13 @@ static int
skip_line_comment (cpp_reader *pfile) skip_line_comment (cpp_reader *pfile)
{ {
cpp_buffer *buffer = pfile->buffer; cpp_buffer *buffer = pfile->buffer;
unsigned int orig_line = pfile->line; unsigned int orig_line = pfile->line_table->highest_line;
while (*buffer->cur != '\n') while (*buffer->cur != '\n')
buffer->cur++; buffer->cur++;
_cpp_process_line_notes (pfile, true); _cpp_process_line_notes (pfile, true);
return orig_line != pfile->line; return orig_line != pfile->line_table->highest_line;
} }
/* Skips whitespace, saving the next non-whitespace character. */ /* Skips whitespace, saving the next non-whitespace character. */
...@@ -400,7 +400,7 @@ skip_whitespace (cpp_reader *pfile, cppchar_t c) ...@@ -400,7 +400,7 @@ skip_whitespace (cpp_reader *pfile, cppchar_t c)
else if (c == '\0') else if (c == '\0')
saw_NUL = true; saw_NUL = true;
else if (pfile->state.in_directive && CPP_PEDANTIC (pfile)) else if (pfile->state.in_directive && CPP_PEDANTIC (pfile))
cpp_error_with_line (pfile, CPP_DL_PEDWARN, pfile->line, cpp_error_with_line (pfile, CPP_DL_PEDWARN, pfile->line_table->highest_line,
CPP_BUF_COL (buffer), CPP_BUF_COL (buffer),
"%s in preprocessing directive", "%s in preprocessing directive",
c == '\f' ? "form feed" : "vertical tab"); c == '\f' ? "form feed" : "vertical tab");
...@@ -777,7 +777,7 @@ _cpp_get_fresh_line (cpp_reader *pfile) ...@@ -777,7 +777,7 @@ _cpp_get_fresh_line (cpp_reader *pfile)
{ {
/* Only warn once. */ /* Only warn once. */
buffer->next_line = buffer->rlimit; buffer->next_line = buffer->rlimit;
cpp_error_with_line (pfile, CPP_DL_PEDWARN, pfile->line, cpp_error_with_line (pfile, CPP_DL_PEDWARN, pfile->line_table->highest_line,
CPP_BUF_COLUMN (buffer, buffer->cur), CPP_BUF_COLUMN (buffer, buffer->cur),
"no newline at end of file"); "no newline at end of file");
} }
...@@ -828,7 +828,7 @@ _cpp_lex_direct (cpp_reader *pfile) ...@@ -828,7 +828,7 @@ _cpp_lex_direct (cpp_reader *pfile)
if (!pfile->state.in_directive) if (!pfile->state.in_directive)
{ {
/* Tell the compiler the line number of the EOF token. */ /* Tell the compiler the line number of the EOF token. */
result->src_loc = pfile->line; result->src_loc = pfile->line_table->highest_line;
result->flags = BOL; result->flags = BOL;
} }
return result; return result;
...@@ -845,19 +845,19 @@ _cpp_lex_direct (cpp_reader *pfile) ...@@ -845,19 +845,19 @@ _cpp_lex_direct (cpp_reader *pfile)
} }
buffer = pfile->buffer; buffer = pfile->buffer;
update_tokens_line: update_tokens_line:
result->src_loc = pfile->line; result->src_loc = pfile->line_table->highest_line;
skipped_white: skipped_white:
if (buffer->cur >= buffer->notes[buffer->cur_note].pos if (buffer->cur >= buffer->notes[buffer->cur_note].pos
&& !pfile->overlaid_buffer) && !pfile->overlaid_buffer)
{ {
_cpp_process_line_notes (pfile, false); _cpp_process_line_notes (pfile, false);
result->src_loc = pfile->line; result->src_loc = pfile->line_table->highest_line;
} }
c = *buffer->cur++; c = *buffer->cur++;
result->src_loc = linemap_position_for_column (pfile->line_table, LINEMAP_POSITION_FOR_COLUMN (result->src_loc, pfile->line_table,
CPP_BUF_COLUMN (buffer, buffer->cur)); CPP_BUF_COLUMN (buffer, buffer->cur));
switch (c) switch (c)
{ {
......
...@@ -228,7 +228,7 @@ start_directive (cpp_reader *pfile) ...@@ -228,7 +228,7 @@ start_directive (cpp_reader *pfile)
pfile->state.save_comments = 0; pfile->state.save_comments = 0;
/* Some handlers need the position of the # for diagnostics. */ /* Some handlers need the position of the # for diagnostics. */
pfile->directive_line = pfile->line; pfile->directive_line = pfile->line_table->highest_line;
} }
/* Called when leaving a directive, _Pragma or command-line directive. */ /* Called when leaving a directive, _Pragma or command-line directive. */
...@@ -777,7 +777,8 @@ strtoul_for_line (const uchar *str, unsigned int len, long unsigned int *nump) ...@@ -777,7 +777,8 @@ strtoul_for_line (const uchar *str, unsigned int len, long unsigned int *nump)
static void static void
do_line (cpp_reader *pfile) do_line (cpp_reader *pfile)
{ {
const struct line_map *map = linemap_lookup (pfile->line_table, pfile->line); const struct line_maps *line_table = pfile->line_table;
const struct line_map *map = &line_table->maps[line_table->used - 1];
const cpp_token *token; const cpp_token *token;
const char *new_file = map->to_file; const char *new_file = map->to_file;
unsigned long new_lineno; unsigned long new_lineno;
...@@ -827,7 +828,8 @@ do_line (cpp_reader *pfile) ...@@ -827,7 +828,8 @@ do_line (cpp_reader *pfile)
static void static void
do_linemarker (cpp_reader *pfile) do_linemarker (cpp_reader *pfile)
{ {
const struct line_map *map = linemap_lookup (pfile->line_table, pfile->line); const struct line_maps *line_table = pfile->line_table;
const struct line_map *map = &line_table->maps[line_table->used - 1];
const cpp_token *token; const cpp_token *token;
const char *new_file = map->to_file; const char *new_file = map->to_file;
unsigned long new_lineno; unsigned long new_lineno;
...@@ -907,10 +909,8 @@ _cpp_do_file_change (cpp_reader *pfile, enum lc_reason reason, ...@@ -907,10 +909,8 @@ _cpp_do_file_change (cpp_reader *pfile, enum lc_reason reason,
{ {
const struct line_map *map = linemap_add (pfile->line_table, reason, sysp, const struct line_map *map = linemap_add (pfile->line_table, reason, sysp,
to_file, file_line); to_file, file_line);
if (map == NULL) if (map != NULL)
pfile->line = 0; linemap_line_start (pfile->line_table, map->to_line, 127);
else
pfile->line = linemap_line_start (pfile->line_table, map->to_line, 127);
if (pfile->cb.file_change) if (pfile->cb.file_change)
pfile->cb.file_change (pfile, map); pfile->cb.file_change (pfile, map);
......
...@@ -133,7 +133,7 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node) ...@@ -133,7 +133,7 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
unsigned int len; unsigned int len;
const char *name; const char *name;
uchar *buf; uchar *buf;
map = linemap_lookup (pfile->line_table, pfile->line); map = linemap_lookup (pfile->line_table, pfile->line_table->highest_line);
if (node->value.builtin == BT_BASE_FILE) if (node->value.builtin == BT_BASE_FILE)
while (! MAIN_FILE_P (map)) while (! MAIN_FILE_P (map))
...@@ -158,12 +158,12 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node) ...@@ -158,12 +158,12 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
break; break;
case BT_SPECLINE: case BT_SPECLINE:
map = linemap_lookup (pfile->line_table, pfile->line); map = &pfile->line_table->maps[pfile->line_table->used-1];
/* If __LINE__ is embedded in a macro, it must expand to the /* If __LINE__ is embedded in a macro, it must expand to the
line of the macro's invocation, not its definition. line of the macro's invocation, not its definition.
Otherwise things like assert() will not work properly. */ Otherwise things like assert() will not work properly. */
if (CPP_OPTION (pfile, traditional)) if (CPP_OPTION (pfile, traditional))
number = pfile->line; number = pfile->line_table->highest_line;
else else
number = pfile->cur_token[-1].src_loc; number = pfile->cur_token[-1].src_loc;
number = SOURCE_LINE (map, number); number = SOURCE_LINE (map, number);
......
...@@ -618,7 +618,6 @@ cpp_read_state (cpp_reader *r, const char *name, FILE *f, ...@@ -618,7 +618,6 @@ cpp_read_state (cpp_reader *r, const char *name, FILE *f,
struct lexer_state old_state; struct lexer_state old_state;
struct save_macro_item *d; struct save_macro_item *d;
size_t i, mac_count; size_t i, mac_count;
int saved_line = r->line;
/* Restore spec_nodes, which will be full of references to the old /* Restore spec_nodes, which will be full of references to the old
hashtable entries and so will now be invalid. */ hashtable entries and so will now be invalid. */
...@@ -707,7 +706,6 @@ cpp_read_state (cpp_reader *r, const char *name, FILE *f, ...@@ -707,7 +706,6 @@ cpp_read_state (cpp_reader *r, const char *name, FILE *f,
} }
r->state = old_state; r->state = old_state;
r->line = saved_line;
free (defn); free (defn);
defn = NULL; defn = NULL;
......
...@@ -148,7 +148,7 @@ static const uchar * ...@@ -148,7 +148,7 @@ static const uchar *
copy_comment (cpp_reader *pfile, const uchar *cur, int in_define) copy_comment (cpp_reader *pfile, const uchar *cur, int in_define)
{ {
bool unterminated, copy = false; bool unterminated, copy = false;
source_location src_loc = pfile->line; source_location src_loc = pfile->line_table->highest_line;
cpp_buffer *buffer = pfile->buffer; cpp_buffer *buffer = pfile->buffer;
buffer->cur = cur; buffer->cur = cur;
...@@ -271,7 +271,6 @@ _cpp_overlay_buffer (cpp_reader *pfile, const uchar *start, size_t len) ...@@ -271,7 +271,6 @@ _cpp_overlay_buffer (cpp_reader *pfile, const uchar *start, size_t len)
pfile->saved_cur = buffer->cur; pfile->saved_cur = buffer->cur;
pfile->saved_rlimit = buffer->rlimit; pfile->saved_rlimit = buffer->rlimit;
pfile->saved_line_base = buffer->next_line; pfile->saved_line_base = buffer->next_line;
pfile->saved_line = pfile->line;
buffer->need_line = false; buffer->need_line = false;
buffer->cur = start; buffer->cur = start;
...@@ -360,7 +359,7 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro) ...@@ -360,7 +359,7 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro)
CUR (pfile->context) = pfile->buffer->cur; CUR (pfile->context) = pfile->buffer->cur;
RLIMIT (pfile->context) = pfile->buffer->rlimit; RLIMIT (pfile->context) = pfile->buffer->rlimit;
pfile->out.cur = pfile->out.base; pfile->out.cur = pfile->out.base;
pfile->out.first_line = pfile->line; pfile->out.first_line = pfile->line_table->highest_line;
/* start_of_input_line is needed to make sure that directives really, /* start_of_input_line is needed to make sure that directives really,
really start at the first character of the line. */ really start at the first character of the line. */
start_of_input_line = pfile->buffer->cur; start_of_input_line = pfile->buffer->cur;
...@@ -488,7 +487,7 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro) ...@@ -488,7 +487,7 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro)
{ {
maybe_start_funlike (pfile, node, out_start, &fmacro); maybe_start_funlike (pfile, node, out_start, &fmacro);
lex_state = ls_fun_open; lex_state = ls_fun_open;
fmacro.line = pfile->line; fmacro.line = pfile->line_table->highest_line;
continue; continue;
} }
else if (!recursive_macro (pfile, node)) else if (!recursive_macro (pfile, node))
......
...@@ -40,6 +40,7 @@ linemap_init (struct line_maps *set) ...@@ -40,6 +40,7 @@ linemap_init (struct line_maps *set)
set->depth = 0; set->depth = 0;
set->cache = 0; set->cache = 0;
set->highest_location = 0; set->highest_location = 0;
set->highest_line = 0;
set->max_column_hint = 0; set->max_column_hint = 0;
} }
...@@ -154,6 +155,7 @@ linemap_add (struct line_maps *set, enum lc_reason reason, ...@@ -154,6 +155,7 @@ linemap_add (struct line_maps *set, enum lc_reason reason,
set->cache = set->used++; set->cache = set->used++;
map->column_bits = 0; map->column_bits = 0;
set->highest_location = start_location; set->highest_location = start_location;
set->highest_line = start_location;
set->max_column_hint = 0; set->max_column_hint = 0;
if (reason == LC_ENTER) if (reason == LC_ENTER)
...@@ -181,7 +183,7 @@ linemap_line_start (struct line_maps *set, unsigned int to_line, ...@@ -181,7 +183,7 @@ linemap_line_start (struct line_maps *set, unsigned int to_line,
struct line_map *map = &set->maps[set->used - 1]; struct line_map *map = &set->maps[set->used - 1];
source_location highest = set->highest_location; source_location highest = set->highest_location;
source_location r; source_location r;
unsigned int last_line = SOURCE_LINE (map, highest); unsigned int last_line = SOURCE_LINE (map, set->highest_line);
int line_delta = to_line - last_line; int line_delta = to_line - last_line;
bool add_map = false; bool add_map = false;
if (line_delta < 0 if (line_delta < 0
...@@ -196,7 +198,7 @@ linemap_line_start (struct line_maps *set, unsigned int to_line, ...@@ -196,7 +198,7 @@ linemap_line_start (struct line_maps *set, unsigned int to_line,
if (add_map) if (add_map)
{ {
int column_bits; int column_bits;
if (max_column_hint > 1000000 || highest > 0xC0000000) if (max_column_hint > 100000 || highest > 0xC0000000)
{ {
max_column_hint = 0; max_column_hint = 0;
if (highest >0xF0000000) if (highest >0xF0000000)
...@@ -221,12 +223,36 @@ linemap_line_start (struct line_maps *set, unsigned int to_line, ...@@ -221,12 +223,36 @@ linemap_line_start (struct line_maps *set, unsigned int to_line,
else else
r = highest - SOURCE_COLUMN (map, highest) r = highest - SOURCE_COLUMN (map, highest)
+ (line_delta << map->column_bits); + (line_delta << map->column_bits);
set->highest_line = r;
if (r > set->highest_location) if (r > set->highest_location)
set->highest_location = r; set->highest_location = r;
set->max_column_hint = max_column_hint; set->max_column_hint = max_column_hint;
return r; return r;
} }
source_location
linemap_position_for_column (struct line_maps *set, unsigned int to_column)
{
source_location r = set->highest_line;
if (to_column >= set->max_column_hint)
{
if (r >= 0xC000000 || to_column > 100000)
{
/* Running low on source_locations - disable column numbers. */
return r;
}
else
{
struct line_map *map = &set->maps[set->used - 1];
r = linemap_line_start (set, SOURCE_LINE (map, r), to_column + 50);
}
}
r = r + to_column;
if (r >= set->highest_location)
set->highest_location = r;
return r;
}
/* Given a logical line, returns the map from which the corresponding /* Given a logical line, returns the map from which the corresponding
(source file, line) pair can be deduced. Since the set is built (source file, line) pair can be deduced. Since the set is built
chronologically, the logical lines are monotonic increasing, and so chronologically, the logical lines are monotonic increasing, and so
......
...@@ -84,6 +84,9 @@ struct line_maps ...@@ -84,6 +84,9 @@ struct line_maps
/* Highest source_location "given out". */ /* Highest source_location "given out". */
source_location highest_location; source_location highest_location;
/* Start of line of highest source_location "given out". */
source_location highest_line;
/* The maximum column number we can quickly allocate. Higher numbers /* The maximum column number we can quickly allocate. Higher numbers
may require allocating a new line_map. */ may require allocating a new line_map. */
unsigned int max_column_hint; unsigned int max_column_hint;
...@@ -157,32 +160,23 @@ extern void linemap_print_containing_files (struct line_maps *, ...@@ -157,32 +160,23 @@ extern void linemap_print_containing_files (struct line_maps *,
/* Nonzero if the map is at the bottom of the include stack. */ /* Nonzero if the map is at the bottom of the include stack. */
#define MAIN_FILE_P(MAP) ((MAP)->included_from < 0) #define MAIN_FILE_P(MAP) ((MAP)->included_from < 0)
/* Get a source position that for the same line as the most recent /* Set LOC to a source position that is the same line as the most recent
linemap_line_start, but with the specified TO_COLUMN column number. */ linemap_line_start, but with the specified TO_COLUMN column number. */
static inline source_location #define LINEMAP_POSITION_FOR_COLUMN(LOC, SET, TO_COLUMN) { \
linemap_position_for_column (struct line_maps *set, unsigned int to_column) unsigned int to_column = (TO_COLUMN); \
{ struct line_maps *set = (SET); \
struct line_map *map = &set->maps[set->used - 1]; if (__builtin_expect (to_column >= set->max_column_hint, 0)) \
source_location r = set->highest_location; (LOC) = linemap_position_for_column (set, to_column); \
if (__builtin_expect (to_column > set->max_column_hint, 0)) else { \
{ source_location r = set->highest_line; \
if (r >= 0xC000000 || to_column > 1000000) /* FIXME */ r = r + to_column; \
{ if (r >= set->highest_location) \
/* Running low on source_locations - disable column numbers. */ set->highest_location = r; \
return r - SOURCE_COLUMN (map, r); (LOC) = r; \
} }}
else
{
r = linemap_line_start (set, SOURCE_LINE (map, r), to_column + 50); extern source_location
map = &set->maps[set->used - 1]; linemap_position_for_column (struct line_maps *set, unsigned int to_column);
r = set->highest_location;
}
}
r = r - SOURCE_COLUMN (map, r) + to_column;
if (r >= set->highest_location)
set->highest_location = r;
return r;
}
#endif /* !GCC_LINE_MAP_H */ #endif /* !GCC_LINE_MAP_H */
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