Machine-readable diagnostic output (PR other/19165)
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 15 Nov 2018 14:32:41 +0000 (14:32 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Thu, 15 Nov 2018 14:32:41 +0000 (14:32 +0000)
commit478dd60ddcf17773ebd1af367c9dcaee2401f797
tree9504f45599f1a9e4f54c7ffbbe41f73bc1c04e12
parentef190c93b07f04d61e28d70bb9a360fd2f3efbde
Machine-readable diagnostic output (PR other/19165)

This patch implements a -fdiagnostics-format=json option which
converts the diagnostics to be output to stderr in a JSON format;
see the documentation in invoke.texi.

Logically-related diagnostics are nested at the JSON level, using
the auto_diagnostic_group mechanism.

gcc/ChangeLog:
PR other/19165
* Makefile.in (OBJS): Move json.o to...
(OBJS-libcommon): ...here and add diagnostic-format-json.o.
* common.opt (fdiagnostics-format=): New option.
(diagnostics_output_format): New enum.
* diagnostic-format-json.cc: New file.
* diagnostic.c (default_diagnostic_final_cb): New function, taken
from start of diagnostic_finish.
(diagnostic_initialize): Initialize final_cb to
default_diagnostic_final_cb.
(diagnostic_finish): Move "being treated as errors" messages to
default_diagnostic_final_cb.  Call any final_cb.
(default_diagnostic_finalizer): Add diagnostic_t param.
(diagnostic_report_diagnostic): Pass "orig_diag_kind" to
diagnostic_finalizer callback.
* diagnostic.h (enum diagnostics_output_format): New enum.
(diagnostic_finalizer_fn): Reimplement, adding diagnostic_t param.
(struct diagnostic_context): Add "final_cb".
(default_diagnostic_finalizer): Add diagnostic_t param.
(diagnostic_output_format_init): New decl.
* doc/invoke.texi (-fdiagnostics-format): New option.
* dwarf2out.c (gen_producer_string): Ignore
OPT_fdiagnostics_format_.
* gcc.c (driver_handle_option): Handle OPT_fdiagnostics_format_.
* lto-wrapper.c (append_diag_options): Ignore it.
* opts.c (common_handle_option): Handle it.

gcc/c-family/ChangeLog:
PR other/19165
* c-opts.c (c_diagnostic_finalizer): Add diagnostic_t param.

gcc/fortran/ChangeLog:
PR other/19165
* error.c (gfc_diagnostic_finalizer): Add diagnostic_t param.

gcc/jit/ChangeLog:
PR other/19165
* dummy-frontend.c (jit_begin_diagnostic): Add diagnostic_t param.

gcc/testsuite/ChangeLog:
PR other/19165
* c-c++-common/diagnostic-format-json-1.c: New test.
* c-c++-common/diagnostic-format-json-2.c: New test.
* c-c++-common/diagnostic-format-json-3.c: New test.
* c-c++-common/diagnostic-format-json-4.c: New test.
* c-c++-common/diagnostic-format-json-5.c: New test.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
(custom_diagnostic_finalizer): Add diagnostic_t param.
* gcc.dg/plugin/location_overflow_plugin.c
(verify_unpacked_ranges): Likewise.
(verify_no_columns): Likewise.
* gfortran.dg/diagnostic-format-json-1.F90: New test.
* gfortran.dg/diagnostic-format-json-2.F90: New test.
* gfortran.dg/diagnostic-format-json-3.F90: New test.

From-SVN: r266186
28 files changed:
gcc/ChangeLog
gcc/Makefile.in
gcc/c-family/ChangeLog
gcc/c-family/c-opts.c
gcc/common.opt
gcc/diagnostic-format-json.cc [new file with mode: 0644]
gcc/diagnostic.c
gcc/diagnostic.h
gcc/doc/invoke.texi
gcc/dwarf2out.c
gcc/fortran/ChangeLog
gcc/fortran/error.c
gcc/gcc.c
gcc/jit/ChangeLog
gcc/jit/dummy-frontend.c
gcc/lto-wrapper.c
gcc/opts.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/diagnostic-format-json-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/diagnostic-format-json-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/diagnostic-format-json-3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/diagnostic-format-json-4.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/diagnostic-format-json-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.c
gcc/testsuite/gfortran.dg/diagnostic-format-json-1.F90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/diagnostic-format-json-2.F90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/diagnostic-format-json-3.F90 [new file with mode: 0644]