diff options
author | bothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-02-11 15:29:30 +0000 |
---|---|---|
committer | bothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-02-11 15:29:30 +0000 |
commit | 610625e3c4be5447ccc066a0193d08b441dcccba (patch) | |
tree | a9c4a3f1215b61026ad26cff4b8f9fc9396740cf /gcc/c-ppoutput.c | |
parent | 18afd0f3d9272a5ea7f4f6b542bd8e9b77ea563a (diff) | |
download | gcc-610625e3c4be5447ccc066a0193d08b441dcccba.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@77663 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-ppoutput.c')
-rw-r--r-- | gcc/c-ppoutput.c | 99 |
1 files changed, 50 insertions, 49 deletions
diff --git a/gcc/c-ppoutput.c b/gcc/c-ppoutput.c index 6b5aa990ee0..2d32445d4fe 100644 --- a/gcc/c-ppoutput.c +++ b/gcc/c-ppoutput.c @@ -32,10 +32,9 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ static struct { FILE *outf; /* Stream to write to. */ - const struct line_map *map; /* Logical to physical line mappings. */ const cpp_token *prev; /* Previous token. */ const cpp_token *source; /* Source token for spacing. */ - fileline line; /* Line currently being written. */ + int src_line; /* Line number currently being written. */ unsigned char printed; /* Nonzero if something output at line. */ } print; @@ -45,8 +44,8 @@ static void scan_translation_unit_trad (cpp_reader *); static void account_for_newlines (const unsigned char *, size_t); static int dump_macro (cpp_reader *, cpp_hashnode *, void *); -static void print_line (const struct line_map *, fileline, const char *); -static void maybe_print_line (const struct line_map *, fileline); +static void print_line (source_location, const char *); +static void maybe_print_line (source_location); /* Callback routines for the parser. Most of these are active only in specific modes. */ @@ -112,13 +111,12 @@ init_pp_output (FILE *out_stream) cb->undef = cb_undef; } - /* Initialize the print structure. Setting print.line to -1 here is + /* Initialize the print structure. Setting print.src_line to -1 here is a trick to guarantee that the first token of the file will cause a linemarker to be output by maybe_print_line. */ - print.line = (fileline) -1; + print.src_line = -1; print.printed = 0; print.prev = 0; - print.map = 0; print.outf = out_stream; } @@ -171,13 +169,13 @@ scan_translation_unit (cpp_reader *pfile) } } -/* Adjust print.line for newlines embedded in output. */ +/* Adjust print.src_line for newlines embedded in output. */ static void account_for_newlines (const unsigned char *str, size_t len) { while (len--) if (*str++ == '\n') - print.line++; + print.src_line++; } /* Writes out a traditionally preprocessed file. */ @@ -187,7 +185,7 @@ scan_translation_unit_trad (cpp_reader *pfile) while (_cpp_read_logical_line_trad (pfile)) { size_t len = pfile->out.cur - pfile->out.base; - maybe_print_line (print.map, pfile->out.first_line); + maybe_print_line (pfile->out.first_line); fwrite (pfile->out.base, 1, len, print.outf); print.printed = 1; if (!CPP_OPTION (pfile, discard_comments)) @@ -199,52 +197,56 @@ scan_translation_unit_trad (cpp_reader *pfile) different line to the current one, output the required newlines or a line marker, and return 1. Otherwise return 0. */ static void -maybe_print_line (const struct line_map *map, fileline line) +maybe_print_line (source_location src_loc) { + const struct line_map *map = linemap_lookup (&line_table, src_loc); + int src_line = SOURCE_LINE (map, src_loc); /* End the previous line of text. */ if (print.printed) { putc ('\n', print.outf); - print.line++; + print.src_line++; print.printed = 0; } - if (line >= print.line && line < print.line + 8) + if (src_line >= print.src_line && src_line < print.src_line + 8) { - while (line > print.line) + while (src_line > print.src_line) { putc ('\n', print.outf); - print.line++; + print.src_line++; } } else - print_line (map, line, ""); + print_line (src_loc, ""); } /* Output a line marker for logical line LINE. Special flags are "1" or "2" indicating entering or leaving a file. */ static void -print_line (const struct line_map *map, fileline line, const char *special_flags) +print_line (source_location src_loc, const char *special_flags) { /* End any previous line of text. */ if (print.printed) putc ('\n', print.outf); print.printed = 0; - print.line = line; if (!flag_no_line_commands) { + const struct line_map *map = linemap_lookup (&line_table, src_loc); + size_t to_file_len = strlen (map->to_file); unsigned char *to_file_quoted = alloca (to_file_len * 4 + 1); unsigned char *p; + print.src_line = SOURCE_LINE (map, src_loc); + /* cpp_quote_string does not nul-terminate, so we have to do it ourselves. */ p = cpp_quote_string (to_file_quoted, (unsigned char *)map->to_file, to_file_len); *p = '\0'; - fprintf (print.outf, "# %u \"%s\"%s", - SOURCE_LINE (map, print.line), + fprintf (print.outf, "# %u \"%s\"%s", print.src_line, to_file_quoted, special_flags); if (map->sysp == 2) @@ -262,10 +264,12 @@ static void cb_line_change (cpp_reader *pfile, const cpp_token *token, int parsing_args) { + source_location src_loc = token->src_loc; + if (token->type == CPP_EOF || parsing_args) return; - maybe_print_line (print.map, token->line); + maybe_print_line (src_loc); print.prev = 0; print.source = 0; @@ -276,14 +280,12 @@ cb_line_change (cpp_reader *pfile, const cpp_token *token, ought to care. Some things do care; the fault lies with them. */ if (!CPP_OPTION (pfile, traditional)) { + const struct line_map *map = linemap_lookup (&line_table, src_loc); + int spaces = SOURCE_COLUMN (map, src_loc) - 2; print.printed = 1; - if (token->col > 2) - { - unsigned int spaces = token->col - 2; - while (spaces--) - putc (' ', print.outf); - } + while (-- spaces >= 0) + putc (' ', print.outf); } } @@ -291,15 +293,15 @@ static void cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, fileline line, const cpp_string *str) { - maybe_print_line (print.map, line); + maybe_print_line (line); fprintf (print.outf, "#ident \"%s\"\n", str->text); - print.line++; + print.src_line++; } static void cb_define (cpp_reader *pfile, fileline line, cpp_hashnode *node) { - maybe_print_line (print.map, line); + maybe_print_line (line); fputs ("#define ", print.outf); /* 'D' is whole definition; 'N' is name only. */ @@ -310,28 +312,28 @@ cb_define (cpp_reader *pfile, fileline line, cpp_hashnode *node) fputs ((const char *) NODE_NAME (node), print.outf); putc ('\n', print.outf); - print.line++; + print.src_line++; } static void -cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, fileline line, +cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, cpp_hashnode *node) { - maybe_print_line (print.map, line); + maybe_print_line (line); fprintf (print.outf, "#undef %s\n", NODE_NAME (node)); - print.line++; + print.src_line++; } static void -cb_include (cpp_reader *pfile ATTRIBUTE_UNUSED, fileline line, +cb_include (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, const unsigned char *dir, const char *header, int angle_brackets) { - maybe_print_line (print.map, line); + maybe_print_line (line); if (angle_brackets) fprintf (print.outf, "#%s <%s>\n", dir, header); else fprintf (print.outf, "#%s \"%s\"\n", dir, header); - print.line++; + print.src_line++; } /* Callback called when -fworking-director and -E to emit working @@ -351,8 +353,7 @@ pp_dir_change (cpp_reader *pfile ATTRIBUTE_UNUSED, const char *dir) } /* The file name, line number or system header flags have changed, as - described in MAP. From this point on, the old print.map might be - pointing to freed memory, and so must not be dereferenced. */ + described in MAP. */ void pp_file_change (const struct line_map *map) @@ -365,37 +366,37 @@ pp_file_change (const struct line_map *map) if (map != NULL) { /* First time? */ - if (print.map == NULL) + if (MAIN_FILE_P (map)) { /* Avoid printing foo.i when the main file is foo.c. */ if (!cpp_get_options (parse_in)->preprocessed) - print_line (map, map->from_line, flags); + print_line (map->start_location, flags); } else { /* Bring current file to correct line when entering a new file. */ if (map->reason == LC_ENTER) - maybe_print_line (map - 1, map->from_line - 1); - + { + const struct line_map *from = INCLUDED_FROM (&line_table, map); + maybe_print_line (LAST_SOURCE_LINE_LOCATION (from)); + } if (map->reason == LC_ENTER) flags = " 1"; else if (map->reason == LC_LEAVE) flags = " 2"; - print_line (map, map->from_line, flags); + print_line (map->start_location, flags); } } - - print.map = map; } /* Copy a #pragma directive to the preprocessed output. */ static void cb_def_pragma (cpp_reader *pfile, fileline line) { - maybe_print_line (print.map, line); + maybe_print_line (line); fputs ("#pragma ", print.outf); cpp_output_line (pfile, print.outf); - print.line++; + print.src_line++; } /* Dump out the hash table. */ @@ -408,7 +409,7 @@ dump_macro (cpp_reader *pfile, cpp_hashnode *node, void *v ATTRIBUTE_UNUSED) fputs ((const char *) cpp_macro_definition (pfile, node), print.outf); putc ('\n', print.outf); - print.line++; + print.src_line++; } return 1; |