diff options
author | David Malcolm <dmalcolm@redhat.com> | 2016-09-02 18:00:57 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2016-09-02 18:00:57 +0000 |
commit | c65236d682789b6a33510aaebfd7e83fe0f30d1a (patch) | |
tree | 796b73d02c02186aeafa76ffa1d0047c651425fa /gcc/input.c | |
parent | bad9b2889af54110857416e4f9e65f4032f2f5f4 (diff) | |
download | gcc-c65236d682789b6a33510aaebfd7e83fe0f30d1a.zip gcc-c65236d682789b6a33510aaebfd7e83fe0f30d1a.tar.gz gcc-c65236d682789b6a33510aaebfd7e83fe0f30d1a.tar.bz2 |
Introduce class edit_context
gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Add edit-context.o.
* diagnostic-color.c (color_dict): Add "diff-filename",
"diff-hunk", "diff-delete", and "diff-insert".
(parse_gcc_colors): Update default value of GCC_COLORS in comment
to reflect above changes.
* doc/invoke.texi (-fdiagnostics-color): Update description of
default GCC_COLORS, and of the supported capabilities.
* edit-context.c: New file.
* edit-context.h: New file.
* input.c (struct fcache): Add field "missing_trailing_newline".
(diagnostics_file_cache_forcibly_evict_file): Initialize it to
true.
(add_file_to_cache_tab): Likewise.
(fcache::fcache): Likewise.
(get_next_line): Update c->missing_trailing_newline.
(location_missing_trailing_newline): New function.
* input.h (location_missing_trailing_newline): New decl.
* selftest-run-tests.c (selftest::run_tests): Call
edit_context_c_tests.
* selftest.h (edit_context_c_tests): New decl.
libcpp/ChangeLog:
* include/line-map.h (rich_location::seen_impossible_fixit_p): New
accessor.
From-SVN: r239963
Diffstat (limited to 'gcc/input.c')
-rw-r--r-- | gcc/input.c | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/gcc/input.c b/gcc/input.c index 2ff7cb8..55bff48 100644 --- a/gcc/input.c +++ b/gcc/input.c @@ -95,6 +95,11 @@ struct fcache before the line map has seen the end of the file. */ size_t total_lines; + /* Could this file be missing a trailing newline on its final line? + Initially true (to cope with empty files), set to true/false + as each line is read. */ + bool missing_trailing_newline; + /* This is a record of the beginning and end of the lines we've seen while reading the file. This is useful to avoid walking the data from the beginning when we are asked to read a line that is @@ -280,6 +285,7 @@ diagnostics_file_cache_forcibly_evict_file (const char *file_path) r->line_record.truncate (0); r->use_count = 0; r->total_lines = 0; + r->missing_trailing_newline = true; } /* Return the file cache that has been less used, recently, or the @@ -348,6 +354,7 @@ add_file_to_cache_tab (const char *file_path) add_file_to_cache_tab is called. */ r->use_count = ++highest_use_count; r->total_lines = total_lines_num (file_path); + r->missing_trailing_newline = true; return r; } @@ -372,7 +379,7 @@ lookup_or_add_file_to_cache_tab (const char *file_path) fcache::fcache () : use_count (0), file_path (NULL), fp (NULL), data (0), size (0), nb_read (0), line_start_idx (0), line_num (0), - total_lines (0) + total_lines (0), missing_trailing_newline (true) { line_record.create (0); } @@ -507,16 +514,24 @@ get_next_line (fcache *c, char **line, ssize_t *line_len) } } if (line_end == NULL) - /* We've loadded all the file into the cache and still no - '\n'. Let's say the line ends up at one byte passed the - end of the file. This is to stay consistent with the case - of when the line ends up with a '\n' and line_end points to - that terminal '\n'. That consistency is useful below in - the len calculation. */ - line_end = c->data + c->nb_read ; + { + /* We've loadded all the file into the cache and still no + '\n'. Let's say the line ends up at one byte passed the + end of the file. This is to stay consistent with the case + of when the line ends up with a '\n' and line_end points to + that terminal '\n'. That consistency is useful below in + the len calculation. */ + line_end = c->data + c->nb_read ; + c->missing_trailing_newline = true; + } + else + c->missing_trailing_newline = false; } else - next_line_start = line_end + 1; + { + next_line_start = line_end + 1; + c->missing_trailing_newline = false; + } if (ferror (c->fp)) return -1; @@ -751,6 +766,20 @@ location_get_source_line (const char *file_path, int line, return read ? buffer : NULL; } +/* Determine if FILE_PATH missing a trailing newline on its final line. + Only valid to call once all of the file has been loaded, by + requesting a line number beyond the end of the file. */ + +bool +location_missing_trailing_newline (const char *file_path) +{ + fcache *c = lookup_or_add_file_to_cache_tab (file_path); + if (c == NULL) + return false; + + return c->missing_trailing_newline; +} + /* Test if the location originates from the spelling location of a builtin-tokens. That is, return TRUE if LOC is a (possibly virtual) location of a built-in token that appears in the expansion |