From b09649fdc609c79ea5acb9668636c7d8a5f64a7c Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 9 Jun 2017 20:57:38 +0000 Subject: Add support for mutually-incompatible fix-it hints This patch adds a method: rich_location::fixits_cannot_be_auto_applied for ensuring that mutually-incompatible fix-its hints don't lead to insane output from -fdiagnostics-generate-patch. Fix-it hints within such rich_location instances are printed as normal by diagnostic_show_locus, but don't affect the output of -fdiagnostics-generate-patch. gcc/ChangeLog: * diagnostic.c (diagnostic_report_diagnostic): Only add fixits to the edit_context if they can be auto-applied. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic-test-show-locus-bw.c (test_mutually_exclusive_suggestions): New test function. * gcc.dg/plugin/diagnostic-test-show-locus-generate-patch.c (test_mutually_exclusive_suggestions): New test function. * gcc.dg/plugin/diagnostic-test-show-locus-parseable-fixits.c (test_mutually_exclusive_suggestions): New test function. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (test_show_locus): Add special-case for "test_mutually_exclusive_suggestions". libcpp/ChangeLog: * include/line-map.h (rich_location::fixits_cannot_be_auto_applied): New method. (rich_location::fixits_can_be_auto_applied_p): New accessor. (rich_location::m_fixits_cannot_be_auto_applied): New field. * line-map.c (rich_location::rich_location): Initialize new field. From-SVN: r249081 --- libcpp/include/line-map.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'libcpp/include/line-map.h') diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 90d65d7..be3041d 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -1663,6 +1663,27 @@ class rich_location fixit_hint *get_last_fixit_hint () const; bool seen_impossible_fixit_p () const { return m_seen_impossible_fixit; } + /* Set this if the fix-it hints are not suitable to be + automatically applied. + + For example, if you are suggesting more than one + mutually exclusive solution to a problem, then + it doesn't make sense to apply all of the solutions; + manual intervention is required. + + If set, then the fix-it hints in the rich_location will + be printed, but will not be added to generated patches, + or affect the modified version of the file. */ + void fixits_cannot_be_auto_applied () + { + m_fixits_cannot_be_auto_applied = true; + } + + bool fixits_can_be_auto_applied_p () const + { + return !m_fixits_cannot_be_auto_applied; + } + private: bool reject_impossible_fixit (source_location where); void stop_supporting_fixits (); @@ -1686,6 +1707,7 @@ protected: semi_embedded_vec m_fixit_hints; bool m_seen_impossible_fixit; + bool m_fixits_cannot_be_auto_applied; }; /* A fix-it hint: a suggested insertion, replacement, or deletion of text. -- cgit v1.1