summaryrefslogtreecommitdiff
path: root/gcc/diagnostic.c
diff options
context:
space:
mode:
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2016-09-02 19:41:17 +0000
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2016-09-02 19:41:17 +0000
commit40a431fa1b60546aa99d26090ecdda5e56e108f5 (patch)
tree1c48b3da48c0d917939aeb557e3ff941f07bf978 /gcc/diagnostic.c
parent0b80c4b2d7a168c3da186901ff8f4b9b53eaab4a (diff)
downloadgcc-40a431fa1b60546aa99d26090ecdda5e56e108f5.tar.gz
Add -fdiagnostics-generate-patch
gcc/ChangeLog: * common.opt (fdiagnostics-generate-patch): New option. * diagnostic.c: Include "edit-context.h". (diagnostic_initialize): Initialize context->edit_context_ptr. (diagnostic_finish): Delete context->edit_context_ptr. (diagnostic_report_diagnostic): Add fix-it hints from the diagnostic to context->edit_context_ptr, if any. * diagnostic.h (class edit_context): Add forward decl. (struct diagnostic_context): Add field "edit_context_ptr". * doc/invoke.texi (Diagnostic Message Formatting Options): Add -fdiagnostics-generate-patch. (-fdiagnostics-generate-patch): New item. * toplev.c: Include "edit-context.h". (process_options): Set global_dc->edit_context_ptr to a new edit_context if the options need one. (toplev::main): Handle -fdiagnostics-generate-patch by using global_dc->edit_context_ptr. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic-test-show-locus-generate-patch.c: New test case. * gcc.dg/plugin/plugin.exp (plugin_test_list): Add diagnostic-test-show-locus-generate-patch.c to the sources for diagnostic_plugin_test_show_locus.c. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@239965 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/diagnostic.c')
-rw-r--r--gcc/diagnostic.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index 47b4c79ebcc..46cdb629e8d 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see
#include "backtrace.h"
#include "diagnostic.h"
#include "diagnostic-color.h"
+#include "edit-context.h"
#include "selftest.h"
#ifdef HAVE_TERMIOS_H
@@ -174,6 +175,7 @@ diagnostic_initialize (diagnostic_context *context, int n_opts)
context->colorize_source_p = false;
context->show_ruler_p = false;
context->parseable_fixits_p = false;
+ context->edit_context_ptr = NULL;
}
/* Maybe initialize the color support. We require clients to do this
@@ -235,6 +237,12 @@ diagnostic_finish (diagnostic_context *context)
context->printer->~pretty_printer ();
XDELETE (context->printer);
context->printer = NULL;
+
+ if (context->edit_context_ptr)
+ {
+ delete context->edit_context_ptr;
+ context->edit_context_ptr = NULL;
+ }
}
/* Initialize DIAGNOSTIC, where the message MSG has already been
@@ -943,6 +951,9 @@ diagnostic_report_diagnostic (diagnostic_context *context,
diagnostic->message.format_spec = saved_format_spec;
diagnostic->x_data = NULL;
+ if (context->edit_context_ptr)
+ context->edit_context_ptr->add_fixits (diagnostic->richloc);
+
context->lock--;
return true;