diff options
author | Per Bothner <per@bothner.com> | 2004-02-11 07:29:30 -0800 |
---|---|---|
committer | Per Bothner <bothner@gcc.gnu.org> | 2004-02-11 07:29:30 -0800 |
commit | 12f9df4ec55a2004a9c9201886440d9503b6a858 (patch) | |
tree | a9c4a3f1215b61026ad26cff4b8f9fc9396740cf /gcc/c-lex.c | |
parent | 8914b65e213507d28c235ddeeff22e4867c2e2c0 (diff) | |
download | gcc-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/c-lex.c')
-rw-r--r-- | gcc/c-lex.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/gcc/c-lex.c b/gcc/c-lex.c index aba571f..cbd5573 100644 --- a/gcc/c-lex.c +++ b/gcc/c-lex.c @@ -42,9 +42,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "splay-tree.h" #include "debug.h" -/* The current line map. */ -static const struct line_map *map; - /* We may keep statistics about how long which files took to compile. */ static int header_time, body_time; static splay_tree file_info_tree; @@ -194,28 +191,27 @@ static void cb_line_change (cpp_reader *pfile ATTRIBUTE_UNUSED, const cpp_token *token, int parsing_args) { - if (token->type == CPP_EOF || parsing_args) - return; - - input_line = SOURCE_LINE (map, token->line); + if (token->type != CPP_EOF && !parsing_args) + { + source_location loc = token->src_loc; + const struct line_map *map = linemap_lookup (&line_table, loc); + input_line = SOURCE_LINE (map, loc); + } } void fe_file_change (const struct line_map *new_map) { if (new_map == NULL) - { - map = NULL; - return; - } + return; if (new_map->reason == LC_ENTER) { /* Don't stack the main buffer on the input stack; we already did in compile_file. */ - if (map != NULL) + if (! MAIN_FILE_P (new_map)) { - int included_at = SOURCE_LINE (new_map - 1, new_map->from_line - 1); + int included_at = LAST_SOURCE_LINE (new_map - 1); input_line = included_at; push_srcloc (new_map->to_file, 1); @@ -250,20 +246,20 @@ fe_file_change (const struct line_map *new_map) in_system_header = new_map->sysp != 0; input_filename = new_map->to_file; input_line = new_map->to_line; - map = new_map; /* Hook for C++. */ extract_interface_info (); } static void -cb_def_pragma (cpp_reader *pfile, unsigned int line) +cb_def_pragma (cpp_reader *pfile, source_location loc) { /* Issue a warning message if we have been asked to do so. Ignore unknown pragmas in system headers unless an explicit -Wunknown-pragmas has been given. */ if (warn_unknown_pragmas > in_system_header) { + const struct line_map *map = linemap_lookup (&line_table, loc); const unsigned char *space, *name; const cpp_token *s; @@ -277,25 +273,27 @@ cb_def_pragma (cpp_reader *pfile, unsigned int line) name = cpp_token_as_text (pfile, s); } - input_line = SOURCE_LINE (map, line); + input_line = SOURCE_LINE (map, loc); warning ("ignoring #pragma %s %s", space, name); } } /* #define callback for DWARF and DWARF2 debug info. */ static void -cb_define (cpp_reader *pfile, unsigned int line, cpp_hashnode *node) +cb_define (cpp_reader *pfile, source_location loc, cpp_hashnode *node) { - (*debug_hooks->define) (SOURCE_LINE (map, line), + const struct line_map *map = linemap_lookup (&line_table, loc); + (*debug_hooks->define) (SOURCE_LINE (map, loc), (const char *) cpp_macro_definition (pfile, node)); } /* #undef callback for DWARF and DWARF2 debug info. */ static void -cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, unsigned int line, +cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location loc, cpp_hashnode *node) { - (*debug_hooks->undef) (SOURCE_LINE (map, line), + const struct line_map *map = linemap_lookup (&line_table, loc); + (*debug_hooks->undef) (SOURCE_LINE (map, loc), (const char *) NODE_NAME (node)); } |