From 5adaabb3c76ceb1bb9eb34baedd884188d682984 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 4 Dec 2015 15:07:38 -0500
Subject: [PATCH 11/31] FIXME: Allow calling diagnostic_show_locus without a
 diagnostic_info

---
 gcc/c-family/c-opts.c                              |  2 +-
 gcc/diagnostic-show-locus.c                        | 38 ++++++++++++----------
 gcc/diagnostic.c                                   |  4 +--
 gcc/diagnostic.h                                   |  4 ++-
 gcc/fortran/error.c                                |  2 +-
 .../plugin/diagnostic_plugin_test_show_locus.c     |  2 +-
 6 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index ff6339c..9a956c2 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -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);
diff --git a/gcc/diagnostic-show-locus.c b/gcc/diagnostic-show-locus.c
index 7aab658..11588b0 100644
--- a/gcc/diagnostic-show-locus.c
+++ b/gcc/diagnostic-show-locus.c
@@ -74,7 +74,7 @@ class colorizer
 {
  public:
   colorizer (diagnostic_context *context,
-	     const diagnostic_info *diagnostic);
+	     diagnostic_t diagnostic_kind);
   ~colorizer ();
 
   void set_range (int range_idx) { set_state (range_idx); }
@@ -90,7 +90,7 @@ class colorizer
   static const int STATE_NORMAL_TEXT = -1;
 
   diagnostic_context *m_context;
-  const diagnostic_info *m_diagnostic;
+  diagnostic_t m_diagnostic_kind;
   int m_current_state;
   const char *m_caret_cs;
   const char *m_caret_ce;
@@ -187,7 +187,8 @@ class layout
 {
  public:
   layout (diagnostic_context *context,
-	  const diagnostic_info *diagnostic);
+	  rich_location *richloc,
+	  diagnostic_t diagnostic_kind);
 
   int get_num_line_spans () const { return m_line_spans.length (); }
   const line_span *get_line_span (int idx) const { return &m_line_spans[idx]; }
@@ -239,9 +240,9 @@ class layout
    different kinds of things we might need to print.  */
 
 colorizer::colorizer (diagnostic_context *context,
-		      const diagnostic_info *diagnostic) :
+		      diagnostic_t diagnostic_kind) :
   m_context (context),
-  m_diagnostic (diagnostic),
+  m_diagnostic_kind (diagnostic_kind),
   m_current_state (STATE_NORMAL_TEXT)
 {
   m_caret_ce = colorize_stop (pp_show_color (context->printer));
@@ -288,7 +289,7 @@ colorizer::begin_state (int state)
       pp_string
 	(m_context->printer,
 	 colorize_start (pp_show_color (m_context->printer),
-			 diagnostic_get_color_for_kind (m_diagnostic->kind)));
+			 diagnostic_get_color_for_kind (m_diagnostic_kind)));
       break;
 
     case 1:
@@ -699,18 +700,18 @@ compatible_locations_p (location_t loc_a, location_t loc_b)
    will fit within the max_width provided by the diagnostic_context.  */
 
 layout::layout (diagnostic_context * context,
-		const diagnostic_info *diagnostic)
+		rich_location *richloc,
+		diagnostic_t diagnostic_kind)
 : m_context (context),
   m_pp (context->printer),
-  m_diagnostic_kind (diagnostic->kind),
-  m_exploc (diagnostic->richloc->get_expanded_location (0)),
-  m_colorizer (context, diagnostic),
+  m_diagnostic_kind (diagnostic_kind),
+  m_exploc (richloc->get_expanded_location (0)),
+  m_colorizer (context, diagnostic_kind),
   m_colorize_source_p (context->colorize_source_p),
   m_layout_ranges (rich_location::MAX_RANGES),
   m_line_spans (1 + rich_location::MAX_RANGES),
   m_x_offset (0)
 {
-  rich_location *richloc = diagnostic->richloc;
   source_location primary_loc = richloc->get_range (0)->m_loc;
 
   for (unsigned int idx = 0; idx < richloc->get_num_locations (); idx++)
@@ -1276,21 +1277,22 @@ layout::show_ruler (int max_column) const
 
 void
 diagnostic_show_locus (diagnostic_context * context,
-		       const diagnostic_info *diagnostic)
+		       rich_location *richloc,
+		       diagnostic_t diagnostic_kind)
 {
   pp_newline (context->printer);
-
+  location_t loc = richloc->get_loc ();
   if (!context->show_caret
-      || diagnostic_location (diagnostic, 0) <= BUILTINS_LOCATION
-      || diagnostic_location (diagnostic, 0) == context->last_location)
+      || loc <= BUILTINS_LOCATION
+      || loc == context->last_location)
     return;
 
-  context->last_location = diagnostic_location (diagnostic, 0);
+  context->last_location = loc;
 
   const char *saved_prefix = pp_get_prefix (context->printer);
   pp_set_prefix (context->printer, NULL);
 
-  layout layout (context, diagnostic);
+  layout layout (context, richloc, diagnostic_kind);
   for (int line_span_idx = 0; line_span_idx < layout.get_num_line_spans ();
        line_span_idx++)
     {
@@ -1310,7 +1312,7 @@ diagnostic_show_locus (diagnostic_context * context,
 	  if (layout.print_source_line (row, &lbounds))
 	    {
 	      layout.print_annotation_line (row, lbounds);
-	      layout.print_any_fixits (row, diagnostic->richloc);
+	      layout.print_any_fixits (row, richloc);
 	    }
 	}
     }
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index 8467aaa..5501f6d 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -574,7 +574,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);
 }
@@ -913,7 +913,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);
 }
 
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index 58d77df..66eaf93 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -280,7 +280,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 *,
diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c
index 6cfe019..589f5e8 100644
--- a/gcc/fortran/error.c
+++ b/gcc/fortran/error.c
@@ -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);
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
index a5f8f0c..d57400d 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
@@ -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);
-- 
1.8.5.3

