diff options
author | David Malcolm <dmalcolm@redhat.com> | 2015-11-06 19:50:50 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2015-11-06 19:50:50 +0000 |
commit | 8a64515099e64564542cbd09be7c9a21c2f580f3 (patch) | |
tree | de618a78e7240cd1dec5c9b663ed1464c2775915 /gcc/diagnostic.h | |
parent | 277ec793cbb5053626a75bcfdb82af03fc735b3e (diff) | |
download | gcc-8a64515099e64564542cbd09be7c9a21c2f580f3.zip gcc-8a64515099e64564542cbd09be7c9a21c2f580f3.tar.gz gcc-8a64515099e64564542cbd09be7c9a21c2f580f3.tar.bz2 |
Reimplement diagnostic_show_locus, introducing rich_location classes
gcc/ChangeLog:
* diagnostic-color.c (color_dict): Eliminate "caret"; add "range1"
and "range2".
(parse_gcc_colors): Update comment to describe default GCC_COLORS.
* diagnostic-core.h (warning_at_rich_loc): New declaration.
(error_at_rich_loc): New declaration.
(permerror_at_rich_loc): New declaration.
(inform_at_rich_loc): New declaration.
* diagnostic-show-locus.c (adjust_line): Delete.
(struct point_state): New struct.
(class colorizer): New class.
(class layout_point): New class.
(class layout_range): New class.
(struct line_bounds): New.
(class layout): New class.
(colorizer::colorizer): New ctor.
(colorizer::~colorizer): New dtor.
(layout::layout): New ctor.
(layout::print_source_line): New method.
(layout::print_annotation_line): New method.
(layout::get_state_at_point): New method.
(layout::get_x_bound_for_row): New method.
(diagnostic_show_locus): Reimplement in terms of class layout.
(diagnostic_print_caret_line): Delete.
* diagnostic.c (diagnostic_initialize): Replace
MAX_LOCATIONS_PER_MESSAGE with rich_location::MAX_RANGES.
(diagnostic_set_info_translated): Convert param from location_t
to rich_location *. Eliminate calls to set_location on the
message in favor of storing the rich_location ptr there.
(diagnostic_set_info): Convert param from location_t to
rich_location *.
(diagnostic_build_prefix): Break out array into...
(diagnostic_kind_color): New variable.
(diagnostic_get_color_for_kind): New function.
(diagnostic_report_diagnostic): Colorize the option_text
using the color for the severity.
(diagnostic_append_note): Update for change in signature of
diagnostic_set_info.
(diagnostic_append_note_at_rich_loc): New function.
(emit_diagnostic): Update for change in signature of
diagnostic_set_info.
(inform): Likewise.
(inform_at_rich_loc): New function.
(inform_n): Update for change in signature of diagnostic_set_info.
(warning): Likewise.
(warning_at): Likewise.
(warning_at_rich_loc): New function.
(warning_n): Update for change in signature of diagnostic_set_info.
(pedwarn): Likewise.
(permerror): Likewise.
(permerror_at_rich_loc): New function.
(error): Update for change in signature of diagnostic_set_info.
(error_n): Likewise.
(error_at): Likewise.
(error_at_rich_loc): New function.
(sorry): Update for change in signature of diagnostic_set_info.
(fatal_error): Likewise.
(internal_error): Likewise.
(internal_error_no_backtrace): Likewise.
(source_range::debug): New function.
* diagnostic.h (struct diagnostic_info): Eliminate field
"override_column". Add field "richloc".
(struct diagnostic_context): Add field "colorize_source_p".
(diagnostic_override_column): Delete.
(diagnostic_set_info): Convert param from location_t to
rich_location *.
(diagnostic_set_info_translated): Likewise.
(diagnostic_append_note_at_rich_loc): New function.
(diagnostic_num_locations): New function.
(diagnostic_expand_location): Get the location from the
rich_location.
(diagnostic_print_caret_line): Delete.
(diagnostic_get_color_for_kind): New declaration.
* genmatch.c (linemap_client_expand_location_to_spelling_point): New.
(error_cb): Update for change in signature of "error" callback.
(fatal_at): Likewise.
(warning_at): Likewise.
* input.c (linemap_client_expand_location_to_spelling_point): New.
* pretty-print.c (text_info::set_range): New method.
(text_info::get_location): New method.
* pretty-print.h (MAX_LOCATIONS_PER_MESSAGE): Eliminate this macro.
(struct text_info): Eliminate "locations" array in favor of
"m_richloc", a rich_location *.
(textinfo::set_location): Add a "caret_p" param, and reimplement
in terms of a call to set_range.
(textinfo::get_location): Eliminate inline implementation in favor of
an out-of-line reimplementation.
(textinfo::set_range): New method.
* rtl-error.c (diagnostic_for_asm): Update for change in signature
of diagnostic_set_info.
* tree-diagnostic.c (default_tree_printer): Update for new
"caret_p" param for textinfo::set_location.
* tree-pretty-print.c (percent_K_format): Likewise.
gcc/c-family/ChangeLog:
* c-common.c (c_cpp_error): Convert parameter from location_t to
rich_location *. Eliminate the "column_override" parameter and
the call to diagnostic_override_column.
Update the "done_lexing" clause to set range 0
on the rich_location, rather than overwriting a location_t.
* c-common.h (c_cpp_error): Convert parameter from location_t to
rich_location *. Eliminate the "column_override" parameter.
gcc/c/ChangeLog:
* c-decl.c (warn_defaults_to): Update for change in signature
of diagnostic_set_info.
* c-errors.c (pedwarn_c99): Likewise.
(pedwarn_c90): Likewise.
* c-objc-common.c (c_tree_printer): Update for new "caret_p" param
for textinfo::set_location.
gcc/cp/ChangeLog:
* error.c (cp_printer): Update for new "caret_p" param for
textinfo::set_location.
(pedwarn_cxx98): Update for change in signature of
diagnostic_set_info.
gcc/fortran/ChangeLog:
* cpp.c (cb_cpp_error): Convert parameter from location_t to
rich_location *. Eliminate the "column_override" parameter.
* error.c (gfc_warning): Update for change in signature of
diagnostic_set_info.
(gfc_format_decoder): Update handling of %C/%L for changes
to struct text_info.
(gfc_diagnostic_starter): Use richloc when determining whether to
print one locus or two. When handling a location that will
involve a call to diagnostic_show_locus, only attempt to print the
locus for the primary location, and don't call into
diagnostic_print_caret_line.
(gfc_warning_now_at): Update for change in signature of
diagnostic_set_info.
(gfc_warning_now): Likewise.
(gfc_error_now): Likewise.
(gfc_fatal_error): Likewise.
(gfc_error): Likewise.
(gfc_internal_error): Likewise.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic-test-show-locus-bw.c: New file.
* gcc.dg/plugin/diagnostic-test-show-locus-color.c: New file.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: New file.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add the above.
* lib/gcc-dg.exp: Load multiline.exp.
libcpp/ChangeLog:
* errors.c (cpp_diagnostic): Update for change in signature
of "error" callback.
(cpp_diagnostic_with_line): Likewise, calling override_column
on the rich_location.
* include/cpplib.h (struct cpp_callbacks): Within "error"
callback, convert param from source_location to rich_location *,
and drop column_override param.
* include/line-map.h (struct source_range): New struct.
(struct location_range): New struct.
(class rich_location): New class.
(linemap_client_expand_location_to_spelling_point): New declaration.
* line-map.c (rich_location::rich_location): New ctors.
(rich_location::lazily_expand_location): New method.
(rich_location::override_column): New method.
(rich_location::add_range): New methods.
(rich_location::set_range): New method.
From-SVN: r229884
Diffstat (limited to 'gcc/diagnostic.h')
-rw-r--r-- | gcc/diagnostic.h | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index 7fcb6a8..9096e16 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -29,10 +29,12 @@ along with GCC; see the file COPYING3. If not see list in diagnostic.def. */ struct diagnostic_info { - /* Text to be formatted. It also contains the location(s) for this - diagnostic. */ + /* Text to be formatted. */ text_info message; - unsigned int override_column; + + /* The location at which the diagnostic is to be reported. */ + rich_location *richloc; + /* Auxiliary data for client. */ void *x_data; /* The kind of diagnostic it is about. */ @@ -102,8 +104,8 @@ struct diagnostic_context /* Maximum width of the source line printed. */ int caret_max_width; - /* Characters used for caret diagnostics. */ - char caret_chars[MAX_LOCATIONS_PER_MESSAGE]; + /* Character used for caret diagnostics. */ + char caret_chars[rich_location::MAX_RANGES]; /* True if we should print the command line option which controls each diagnostic, if known. */ @@ -181,6 +183,15 @@ struct diagnostic_context int lock; bool inhibit_notes_p; + + /* When printing source code, should the characters at carets and ranges + be colorized? (assuming colorization is on at all). + This should be true for frontends that generate range information + (so that the ranges of code are colorized), + and false for frontends that merely specify points within the + source code (to avoid e.g. colorizing just the first character in + a token, which would look strange). */ + bool colorize_source_p; }; static inline void @@ -252,10 +263,6 @@ extern diagnostic_context *global_dc; #define report_diagnostic(D) diagnostic_report_diagnostic (global_dc, D) -/* Override the column number to be used for reporting a - diagnostic. */ -#define diagnostic_override_column(DI, COL) (DI)->override_column = (COL) - /* Override the option index to be used for reporting a diagnostic. */ #define diagnostic_override_option_index(DI, OPTIDX) \ @@ -279,13 +286,17 @@ extern bool diagnostic_report_diagnostic (diagnostic_context *, diagnostic_info *); #ifdef ATTRIBUTE_GCC_DIAG extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *, - location_t, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0); + rich_location *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0); extern void diagnostic_set_info_translated (diagnostic_info *, const char *, - va_list *, location_t, + va_list *, rich_location *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0); extern void diagnostic_append_note (diagnostic_context *, location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); +extern void diagnostic_append_note_at_rich_loc (diagnostic_context *, + rich_location *, + const char *, ...) + ATTRIBUTE_GCC_DIAG(3,4); #endif extern char *diagnostic_build_prefix (diagnostic_context *, const diagnostic_info *); void default_diagnostic_starter (diagnostic_context *, diagnostic_info *); @@ -306,6 +317,14 @@ diagnostic_location (const diagnostic_info * diagnostic, int which = 0) return diagnostic->message.get_location (which); } +/* Return the number of locations to be printed in DIAGNOSTIC. */ + +static inline unsigned int +diagnostic_num_locations (const diagnostic_info * diagnostic) +{ + return diagnostic->message.m_richloc->get_num_locations (); +} + /* Expand the location of this diagnostic. Use this function for consistency. Parameter WHICH specifies which location. By default, expand the first one. */ @@ -313,12 +332,7 @@ diagnostic_location (const diagnostic_info * diagnostic, int which = 0) static inline expanded_location diagnostic_expand_location (const diagnostic_info * diagnostic, int which = 0) { - expanded_location s - = expand_location_to_spelling_point (diagnostic_location (diagnostic, - which)); - if (which == 0 && diagnostic->override_column) - s.column = diagnostic->override_column; - return s; + return diagnostic->richloc->get_range (which)->m_caret; } /* This is somehow the right-side margin of a caret line, that is, we @@ -338,11 +352,7 @@ diagnostic_same_line (const diagnostic_context *context, && context->caret_max_width - CARET_LINE_MARGIN > abs (s1.column - s2.column); } -void -diagnostic_print_caret_line (diagnostic_context * context, - expanded_location xloc1, - expanded_location xloc2, - char caret1, char caret2); +extern const char *diagnostic_get_color_for_kind (diagnostic_t kind); /* Pure text formatting support functions. */ extern char *file_name_as_prefix (diagnostic_context *, const char *); |