From fd6876758e1249ec6fed153b252dfabdd7a489b4 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 9 Sep 2015 10:57:58 -0400
Subject: [PATCH 54/56] FIXME: convert source_range to a class, with ctors

---
 gcc/c-family/c-common.c                            |  4 +--
 gcc/fortran/error.c                                |  7 +++--
 gcc/pretty-print.h                                 |  4 +--
 .../plugin/diagnostic_plugin_test_show_locus.c     |  5 ++--
 libcpp/include/line-map.h                          | 30 +++++++++++-----------
 libcpp/line-map.c                                  | 13 +++++-----
 6 files changed, 29 insertions(+), 34 deletions(-)

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index a430bee..d900386 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -10515,9 +10515,7 @@ c_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, int reason,
       gcc_unreachable ();
     }
   if (done_lexing)
-    richloc->set_range (0,
-			source_range::from_location (input_location),
-			true);
+    richloc->set_range (0, input_location, true);
   diagnostic_set_info_translated (&diagnostic, msg, ap,
 				  richloc, dlevel);
   diagnostic_override_option_index (&diagnostic,
diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c
index b5b7beb..1fdc0f5 100644
--- a/gcc/fortran/error.c
+++ b/gcc/fortran/error.c
@@ -941,10 +941,9 @@ gfc_format_decoder (pretty_printer *pp,
 	   processed one of %C/%L.  */
 	int loc_num = text->get_location (0) == UNKNOWN_LOCATION ? 0 : 1;
 	source_range range
-	  = source_range::from_location (
-	      linemap_position_for_loc_and_offset (line_table,
-						   loc->lb->location,
-						   offset));
+	  (linemap_position_for_loc_and_offset (line_table,
+						loc->lb->location,
+						offset));
 	text->set_range (loc_num, range, true);
 	pp_string (pp, result[loc_num]);
 	return true;
diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h
index d10272c..7c8f4f3 100644
--- a/gcc/pretty-print.h
+++ b/gcc/pretty-print.h
@@ -39,9 +39,7 @@ struct text_info
 
   inline void set_location (unsigned int idx, location_t loc, bool caret_p)
   {
-    source_range src_range;
-    src_range.m_start = loc;
-    src_range.m_finish = loc;
+    source_range src_range (loc);
     set_range (idx, src_range, caret_p);
   }
   void set_range (unsigned int idx, source_range range, bool caret_p);
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 f724ef4..15c19743 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
@@ -300,9 +300,8 @@ test_show_locus (function *fun)
   if (0 == strcmp (fnname, "test6"))
     {
       const int line = fnstart_line + 2;
-      source_range src_range;
-      src_range.m_start = get_loc (line, 12);
-      src_range.m_finish = get_loc (line, 16);
+      source_range src_range (get_loc (line, 12),
+			      get_loc (line, 16));
       gcc_rich_location richloc (src_range);
       warning_at_rich_loc (&richloc, 0, "test 6");
     }
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index 857d6f3..3c134f9 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -126,25 +126,25 @@ typedef unsigned int source_location;
 
    We may need a more compact way to store these, but for now,
    let's do it the simple way, as a pair.  */
-struct GTY(()) source_range
+class GTY(()) source_range
 {
-  source_location m_start;
-  source_location m_finish;
+ public:
+  /* Constructing a source_range from a point.  */
+  source_range (source_location loc)
+    : m_start (loc), m_finish (loc) {}
 
-  void debug (const char *msg) const;
+  /* Constructing a source_range from a pair of points.  */
+  source_range (source_location start, source_location finish)
+    : m_start (start), m_finish (finish) {}
 
-  /* We avoid using constructors, since various structs that
-     don't yet have constructors will embed instances of
-     source_range.  */
+  source_location get_start () const { return m_start; }
+  source_location get_finish () const { return m_finish; }
 
-  /* Make a source_range from a source_location.  */
-  static source_range from_location (source_location loc)
-  {
-    source_range result;
-    result.m_start = loc;
-    result.m_finish = loc;
-    return result;
-  }
+  void debug (const char *msg) const;
+
+ private:
+  source_location m_start;
+  source_location m_finish;
 };
 
 /* Memory allocation function typedef.  Works like xrealloc.  */
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index ac6a635..55853b1 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -1765,7 +1765,7 @@ rich_location::rich_location (source_location loc) :
    initial range.  */
 
 rich_location::rich_location (source_range src_range)
-: m_loc (src_range.m_start),
+: m_loc (src_range.get_start ()),
   m_num_ranges (0),
   m_have_expanded_location (false),
   m_num_fixit_hints (0)
@@ -1883,7 +1883,7 @@ rich_location::add_range (source_range src_range, bool show_caret_p)
 {
   linemap_assert (m_num_ranges < MAX_RANGES);
 
-  add_range (src_range.m_start, src_range.m_finish,
+  add_range (src_range.get_start (), src_range.get_finish (),
 	     NULL, BUFFER_OWNERSHIP_GIVEN,
 	     show_caret_p);
 }
@@ -1899,7 +1899,8 @@ rich_location::add_range (source_range src_range,
 {
   linemap_assert (m_num_ranges < MAX_RANGES);
 
-  add_range (src_range.m_start, src_range.m_finish, caption, ownership,
+  add_range (src_range.get_start (), src_range.get_finish (),
+	     caption, ownership,
 	     false);
 }
 
@@ -1938,9 +1939,9 @@ rich_location::set_range (unsigned int idx, source_range src_range,
 
   location_range *locrange = &m_ranges[idx];
   locrange->m_start
-    = linemap_client_expand_location_to_spelling_point (src_range.m_start);
+    = linemap_client_expand_location_to_spelling_point (src_range.get_start ());
   locrange->m_finish
-    = linemap_client_expand_location_to_spelling_point (src_range.m_finish);
+    = linemap_client_expand_location_to_spelling_point (src_range.get_finish ());
 
   locrange->m_show_caret_p = show_caret_p;
 
@@ -1953,7 +1954,7 @@ rich_location::set_range (unsigned int idx, source_range src_range,
 
   if (idx == 0)
     {
-      m_loc = src_range.m_start;
+      m_loc = src_range.get_start ();
       /* Mark any cached value here as dirty.  */
       m_have_expanded_location = false;
     }
-- 
1.8.5.3

