Commit cc015f3a by David Malcolm Committed by David Malcolm

Allow calling diagnostic_show_locus without a diagnostic_info

Much of diagnostic-show-locus.c currently expects a diagnostic_info *,
but it only uses the rich_location and the diagnostic_t.

Change the signature of diagnostic_show_locus from:

  void
  diagnostic_show_locus (diagnostic_context *,
                         const diagnostic_info *);

to:

  void
  diagnostic_show_locus (diagnostic_context *,
                         rich_location *richloc,
                         diagnostic_t diagnostic_kind);

so that it can be used for things other than diagnostics.

Use this flexibility to add selftests for diagnostic_show_locus.

gcc/c-family/ChangeLog:
	* c-opts.c (c_diagnostic_finalizer): Update for change to
	diagnostic_show_locus.

gcc/ChangeLog:
	* diagnostic-show-locus.c (colorizer::colorizer): Replace diagnostic
	param with diagnostic_kind.
	(class colorizer): Similarly replace field m_diagnostic with
	m_diagnostic_kind.
	(colorizer::colorizer): Replace diagnostic
	param with diagnostic_kind.
	(colorizer::begin_state): Update for above field change.
	(layout::layout): Replace diagnostic param with rich_location *
	and diagnostic_kind.
	(diagnostic_show_locus): Replace diagnostic param with richloc
	and diagnostic_kind.
	(class selftest::test_diagnostic_context): New class.
	(selftest::test_diagnostic_show_locus_unknown_location): New
	function.
	(selftest::test_one_liner_simple_caret): New function.
	(selftest::test_one_liner_caret_and_range): New function.
	(selftest::test_one_liner_multiple_carets_and_ranges): New
	function.
	(selftest::test_one_liner_fixit_remove): New function.
	(selftest::test_one_liner_fixit_replace): New function.
	(selftest::test_diagnostic_show_locus_one_liner): New function.
	(selftest::diagnostic_show_locus_c_tests): Call the new test
	functions.
	* diagnostic.c (diagnostic_initialize): Initialize
	colorize_source_p, show_ruler_p and parseable_fixits_p.
	(default_diagnostic_finalizer): Update for change to
	diagnostic_show_locus.
	(diagnostic_append_note): Likewise.
	* diagnostic.h (diagnostic_show_locus): Replace
	const diagnostic_info * param with location * and diagnostic_t.

gcc/fortran/ChangeLog:
	* error.c (gfc_diagnostic_starter): Update for change to
	diagnostic_show_locus.

gcc/testsuite/ChangeLog:
	* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
	(custom_diagnostic_finalizer): Update for change to
	diagnostic_show_locus.

From-SVN: r239586
parent cb18fd07
2016-08-18 David Malcolm <dmalcolm@redhat.com>
* diagnostic-show-locus.c (colorizer::colorizer): Replace diagnostic
param with diagnostic_kind.
(class colorizer): Similarly replace field m_diagnostic with
m_diagnostic_kind.
(colorizer::colorizer): Replace diagnostic
param with diagnostic_kind.
(colorizer::begin_state): Update for above field change.
(layout::layout): Replace diagnostic param with rich_location *
and diagnostic_kind.
(diagnostic_show_locus): Replace diagnostic param with richloc
and diagnostic_kind.
(class selftest::test_diagnostic_context): New class.
(selftest::test_diagnostic_show_locus_unknown_location): New
function.
(selftest::test_one_liner_simple_caret): New function.
(selftest::test_one_liner_caret_and_range): New function.
(selftest::test_one_liner_multiple_carets_and_ranges): New
function.
(selftest::test_one_liner_fixit_remove): New function.
(selftest::test_one_liner_fixit_replace): New function.
(selftest::test_diagnostic_show_locus_one_liner): New function.
(selftest::diagnostic_show_locus_c_tests): Call the new test
functions.
* diagnostic.c (diagnostic_initialize): Initialize
colorize_source_p, show_ruler_p and parseable_fixits_p.
(default_diagnostic_finalizer): Update for change to
diagnostic_show_locus.
(diagnostic_append_note): Likewise.
* diagnostic.h (diagnostic_show_locus): Replace
const diagnostic_info * param with location * and diagnostic_t.
2016-08-18 David Malcolm <dmalcolm@redhat.com>
* input.c (saved_line_table): New global.
(class selftest::temp_line_table): Rename to line_table_test and
move declaration to selftest.h, and drop field m_old_line_table.
......
2016-08-18 David Malcolm <dmalcolm@redhat.com>
* c-opts.c (c_diagnostic_finalizer): Update for change to
diagnostic_show_locus.
2016-08-18 David Malcolm <dmalcolm@redhat.com>
* c-common.c: Include "spellcheck.h".
(cb_get_suggestion): New function.
* c-common.h (cb_get_suggestion): New decl.
......
......@@ -164,7 +164,7 @@ static void
c_diagnostic_finalizer (diagnostic_context *context,
diagnostic_info *diagnostic)
{
diagnostic_show_locus (context, diagnostic);
diagnostic_show_locus (context, diagnostic->richloc, diagnostic->kind);
/* By default print macro expansion contexts in the diagnostic
finalizer -- for tokens resulting from macro expansion. */
virt_loc_aware_diagnostic_finalizer (context, diagnostic);
......
......@@ -171,6 +171,9 @@ diagnostic_initialize (diagnostic_context *context, int n_opts)
context->x_data = NULL;
context->lock = 0;
context->inhibit_notes_p = false;
context->colorize_source_p = false;
context->show_ruler_p = false;
context->parseable_fixits_p = false;
}
/* Maybe initialize the color support. We require clients to do this
......@@ -575,7 +578,7 @@ void
default_diagnostic_finalizer (diagnostic_context *context,
diagnostic_info *diagnostic)
{
diagnostic_show_locus (context, diagnostic);
diagnostic_show_locus (context, diagnostic->richloc, diagnostic->kind);
pp_destroy_prefix (context->printer);
pp_flush (context->printer);
}
......@@ -1025,7 +1028,7 @@ diagnostic_append_note (diagnostic_context *context,
pp_output_formatted_text (context->printer);
pp_destroy_prefix (context->printer);
pp_set_prefix (context->printer, saved_prefix);
diagnostic_show_locus (context, &diagnostic);
diagnostic_show_locus (context, &richloc, DK_NOTE);
va_end (ap);
}
......
......@@ -284,7 +284,9 @@ extern void diagnostic_initialize (diagnostic_context *, int);
extern void diagnostic_color_init (diagnostic_context *, int value = -1);
extern void diagnostic_finish (diagnostic_context *);
extern void diagnostic_report_current_module (diagnostic_context *, location_t);
extern void diagnostic_show_locus (diagnostic_context *, const diagnostic_info *);
extern void diagnostic_show_locus (diagnostic_context *,
rich_location *richloc,
diagnostic_t diagnostic_kind);
/* Force diagnostics controlled by OPTIDX to be kind KIND. */
extern diagnostic_t diagnostic_classify_diagnostic (diagnostic_context *,
......
2016-08-18 David Malcolm <dmalcolm@redhat.com>
* error.c (gfc_diagnostic_starter): Update for change to
diagnostic_show_locus.
2016-08-17 Jakub Jelinek <jakub@redhat.com>
PR fortran/67496
......
......@@ -1093,7 +1093,7 @@ gfc_diagnostic_starter (diagnostic_context *context,
free (locus_prefix);
/* Fortran uses an empty line between locus and caret line. */
pp_newline (context->printer);
diagnostic_show_locus (context, diagnostic);
diagnostic_show_locus (context, diagnostic->richloc, diagnostic->kind);
/* If the caret line was shown, the prefix does not contain the
locus. */
pp_set_prefix (context->printer, kind_prefix);
......
2016-08-18 David Malcolm <dmalcolm@redhat.com>
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
(custom_diagnostic_finalizer): Update for change to
diagnostic_show_locus.
2016-08-18 David Malcolm <dmalcolm@redhat.com>
* gcc.dg/cpp/misspelled-directive-1.c: New testcase.
* gcc.dg/cpp/misspelled-directive-2.c: New testcase.
......
......@@ -133,7 +133,7 @@ custom_diagnostic_finalizer (diagnostic_context *context,
bool old_show_color = pp_show_color (context->printer);
if (force_show_locus_color)
pp_show_color (context->printer) = true;
diagnostic_show_locus (context, diagnostic);
diagnostic_show_locus (context, diagnostic->richloc, diagnostic->kind);
pp_show_color (context->printer) = old_show_color;
pp_destroy_prefix (context->printer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment