aboutsummaryrefslogtreecommitdiff
path: root/gcc/line-map.c
diff options
context:
space:
mode:
authorPer Bothner <per@bothner.com>2004-02-11 07:29:30 -0800
committerPer Bothner <bothner@gcc.gnu.org>2004-02-11 07:29:30 -0800
commit12f9df4ec55a2004a9c9201886440d9503b6a858 (patch)
treea9c4a3f1215b61026ad26cff4b8f9fc9396740cf /gcc/line-map.c
parent8914b65e213507d28c235ddeeff22e4867c2e2c0 (diff)
downloadgcc-12f9df4ec55a2004a9c9201886440d9503b6a858.zip
gcc-12f9df4ec55a2004a9c9201886440d9503b6a858.tar.gz
gcc-12f9df4ec55a2004a9c9201886440d9503b6a858.tar.bz2
Represent column numbers using line-map's source_location.
The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
Diffstat (limited to 'gcc/line-map.c')
-rw-r--r--gcc/line-map.c98
1 files changed, 82 insertions, 16 deletions
diff --git a/gcc/line-map.c b/gcc/line-map.c
index be8cf27..a7398bb 100644
--- a/gcc/line-map.c
+++ b/gcc/line-map.c
@@ -39,8 +39,24 @@ linemap_init (struct line_maps *set)
set->trace_includes = false;
set->depth = 0;
set->cache = 0;
+ set->highest_location = 0;
+ set->max_column_hint = 0;
}
+/* Check for and warn about line_maps entered but not exited. */
+
+void
+linemap_check_files_exited (struct line_maps *set)
+{
+ struct line_map *map;
+ /* Depending upon whether we are handling preprocessed input or
+ not, this can be a user error or an ICE. */
+ for (map = &set->maps[set->used - 1]; ! MAIN_FILE_P (map);
+ map = INCLUDED_FROM (set, map))
+ fprintf (stderr, "line-map.c: file \"%s\" entered but not left\n",
+ map->to_file);
+}
+
/* Free a line map set. */
void
@@ -48,14 +64,7 @@ linemap_free (struct line_maps *set)
{
if (set->maps)
{
- struct line_map *map;
-
- /* Depending upon whether we are handling preprocessed input or
- not, this can be a user error or an ICE. */
- for (map = CURRENT_LINE_MAP (set); ! MAIN_FILE_P (map);
- map = INCLUDED_FROM (set, map))
- fprintf (stderr, "line-map.c: file \"%s\" entered but not left\n",
- map->to_file);
+ linemap_check_files_exited (set);
free (set->maps);
}
@@ -72,16 +81,17 @@ linemap_free (struct line_maps *set)
FROM_LINE should be monotonic increasing across calls to this
function. A call to this function can relocate the previous set of
+ A call to this function can relocate the previous set of
maps, so any stored line_map pointers should not be used. */
const struct line_map *
linemap_add (struct line_maps *set, enum lc_reason reason,
- unsigned int sysp, source_location from_line,
- const char *to_file, unsigned int to_line)
+ unsigned int sysp, const char *to_file, unsigned int to_line)
{
struct line_map *map;
+ source_location start_location = set->highest_location + 1;
- if (set->used && from_line < set->maps[set->used - 1].from_line)
+ if (set->used && start_location < set->maps[set->used - 1].start_location)
abort ();
if (set->used == set->allocated)
@@ -131,17 +141,20 @@ linemap_add (struct line_maps *set, enum lc_reason reason,
if (error || to_file == NULL)
{
to_file = from->to_file;
- to_line = LAST_SOURCE_LINE (from) + 1;
+ to_line = SOURCE_LINE (from, from[1].start_location);
sysp = from->sysp;
}
}
map->reason = reason;
map->sysp = sysp;
- map->from_line = from_line;
+ map->start_location = start_location;
map->to_file = to_file;
map->to_line = to_line;
set->cache = set->used++;
+ map->column_bits = 0;
+ set->highest_location = start_location;
+ set->max_column_hint = 0;
if (reason == LC_ENTER)
{
@@ -161,6 +174,59 @@ linemap_add (struct line_maps *set, enum lc_reason reason,
return map;
}
+source_location
+linemap_line_start (struct line_maps *set, unsigned int to_line,
+ unsigned int max_column_hint)
+{
+ struct line_map *map = &set->maps[set->used - 1];
+ source_location highest = set->highest_location;
+ source_location r;
+ unsigned int last_line = SOURCE_LINE (map, highest);
+ int line_delta = to_line - last_line;
+ bool add_map = false;
+ if (line_delta < 0
+ || (line_delta > 10 && line_delta * map->column_bits > 1000)
+ || (max_column_hint >= (1U << map->column_bits))
+ || (max_column_hint <= 80 && map->column_bits >= 10))
+ {
+ add_map = true;
+ }
+ else
+ max_column_hint = set->max_column_hint;
+ if (add_map)
+ {
+ int column_bits;
+ if (max_column_hint > 1000000 || highest > 0xC0000000)
+ {
+ max_column_hint = 0;
+ if (highest >0xF0000000)
+ return 0;
+ column_bits = 0;
+ }
+ else
+ {
+ column_bits = 7;
+ while (max_column_hint >= (1U << column_bits))
+ column_bits++;
+ max_column_hint = 1U << column_bits;
+ }
+ if (line_delta < 0
+ || last_line != map->to_line
+ || SOURCE_COLUMN (map, highest) >= (1U << column_bits))
+ map = (struct line_map*) linemap_add (set, LC_RENAME, map->sysp,
+ map->to_file, to_line);
+ map->column_bits = column_bits;
+ r = map->start_location;
+ }
+ else
+ r = highest - SOURCE_COLUMN (map, highest)
+ + (line_delta << map->column_bits);
+ if (r > set->highest_location)
+ set->highest_location = r;
+ set->max_column_hint = max_column_hint;
+ return r;
+}
+
/* Given a logical line, returns the map from which the corresponding
(source file, line) pair can be deduced. Since the set is built
chronologically, the logical lines are monotonic increasing, and so
@@ -177,9 +243,9 @@ linemap_lookup (struct line_maps *set, source_location line)
cached = &set->maps[mn];
/* We should get a segfault if no line_maps have been added yet. */
- if (line >= cached->from_line)
+ if (line >= cached->start_location)
{
- if (mn + 1 == mx || line < cached[1].from_line)
+ if (mn + 1 == mx || line < cached[1].start_location)
return cached;
}
else
@@ -191,7 +257,7 @@ linemap_lookup (struct line_maps *set, source_location line)
while (mx - mn > 1)
{
md = (mn + mx) / 2;
- if (set->maps[md].from_line > line)
+ if (set->maps[md].start_location > line)
mx = md;
else
mn = md;