]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add range_idx param to range_label::get_text
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 17 Sep 2018 23:32:12 +0000 (23:32 +0000)
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 17 Sep 2018 23:32:12 +0000 (23:32 +0000)
This patch updates the pure virtual function range_label::get_text
(and its implementations) so that the index of the range is passed
in, allowing for one label instance to be shared by multiple ranges.

gcc/c-family/ChangeLog:
* c-format.c (range_label_for_format_type_mismatch::get_text):
Update for new param.

gcc/c/ChangeLog:
* c-objc-common.c (range_label_for_type_mismatch::get_text):
Update for new param.
* c-typeck.c (maybe_range_label_for_tree_type_mismatch::get_text):
Likewise.

gcc/cp/ChangeLog:
* error.c (range_label_for_type_mismatch::get_text): Update for
new param.

gcc/ChangeLog:
* diagnostic-show-locus.c (class layout_range): Add field
"m_original_idx".
(layout_range::layout_range): Add "original_idx" param and use it
to initialize new field.
(make_range): Use 0 for original_idx.
(layout::layout): Pass in index to calls to
maybe_add_location_range.
(layout::maybe_add_location_range): Add param "original_idx" and
pass it on to layout_range.
(layout::print_any_labels): Pass on range->m_original_idx to
get_text call.
(gcc_rich_location::add_location_if_nearby): Use 0 for
original_idx.
* gcc-rich-location.h (text_range_label::get_text): Update for new
param.
(range_label_for_type_mismatch::get_text): Likewise.

libcpp/ChangeLog:
* include/line-map.h (range_label::get_text): Add param
"range_idx".

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@264376 138bc75d-0d04-0410-961f-82ee72b054a4

12 files changed:
gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-format.c
gcc/c/ChangeLog
gcc/c/c-objc-common.c
gcc/c/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/error.c
gcc/diagnostic-show-locus.c
gcc/gcc-rich-location.h
libcpp/ChangeLog
libcpp/include/line-map.h

index 626c69d8f9407cfe05df403f9454e5720b79f63c..d236d68e5015e3a684d3b2078d8ff222877295a1 100644 (file)
@@ -1,3 +1,22 @@
+2018-09-17  David Malcolm  <dmalcolm@redhat.com>
+
+       * diagnostic-show-locus.c (class layout_range): Add field
+       "m_original_idx".
+       (layout_range::layout_range): Add "original_idx" param and use it
+       to initialize new field.
+       (make_range): Use 0 for original_idx.
+       (layout::layout): Pass in index to calls to
+       maybe_add_location_range.
+       (layout::maybe_add_location_range): Add param "original_idx" and
+       pass it on to layout_range.
+       (layout::print_any_labels): Pass on range->m_original_idx to
+       get_text call.
+       (gcc_rich_location::add_location_if_nearby): Use 0 for
+       original_idx.
+       * gcc-rich-location.h (text_range_label::get_text): Update for new
+       param.
+       (range_label_for_type_mismatch::get_text): Likewise.
+
 2018-09-17  Uros Bizjak  <ubizjak@gmail.com>
 
        * config/i386/i386.c (ix86_emit_i387_log1p): Emit fldln2 earlier.
index b70d77a72193da517e89a5f1f614aa38505536a1..f2ec39424162a12b2ee0ce86a5071e2736936c76 100644 (file)
@@ -1,3 +1,8 @@
+2018-09-17  David Malcolm  <dmalcolm@redhat.com>
+
+       * c-format.c (range_label_for_format_type_mismatch::get_text):
+       Update for new param.
+
 2018-09-17  David Malcolm  <dmalcolm@redhat.com>
 
        * c-format.c (format_warning_at_char): Update for introduction of
index a7edfca4aa947216a736ff4b418bde1e9c59cacd..a1133c75d93d1e7176f4abf722b49546e6db96ae 100644 (file)
@@ -3597,9 +3597,9 @@ class range_label_for_format_type_mismatch
   {
   }
 
-  label_text get_text () const FINAL OVERRIDE
+  label_text get_text (unsigned range_idx) const FINAL OVERRIDE
   {
-    label_text text = range_label_for_type_mismatch::get_text ();
+    label_text text = range_label_for_type_mismatch::get_text (range_idx);
     if (text.m_buffer == NULL)
       return text;
 
index 3133ca6b6b074384f27c0deb1a356d0097c80b8f..6fd76cfe970379d542b9d8de8f621149b5afa808 100644 (file)
@@ -1,3 +1,10 @@
+2018-09-17  David Malcolm  <dmalcolm@redhat.com>
+
+       * c-objc-common.c (range_label_for_type_mismatch::get_text):
+       Update for new param.
+       * c-typeck.c (maybe_range_label_for_tree_type_mismatch::get_text):
+       Likewise.
+
 2018-09-17  Martin Jambor  <mjambor@suse.cz>
 
        PR c/63886
index 12e777a48455948a461acf8bb190fb13f6feff77..fee52689e2dbc0c6fd67873ac73cf66f933f58de 100644 (file)
@@ -218,7 +218,7 @@ c_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
    range_label_for_type_mismatch.  */
 
 label_text
-range_label_for_type_mismatch::get_text () const
+range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const
 {
   if (m_labelled_type == NULL_TREE)
     return label_text (NULL, false);
index a7e2538e1ac9cb68f6dfa4f418e3dbbe0d9736fd..a5a7da0084c72793e71b072dd0a0919decd852bc 100644 (file)
@@ -11056,7 +11056,7 @@ class maybe_range_label_for_tree_type_mismatch : public range_label
   {
   }
 
-  label_text get_text () const FINAL OVERRIDE
+  label_text get_text (unsigned range_idx) const FINAL OVERRIDE
   {
     if (m_expr == NULL_TREE
        || !EXPR_P (m_expr))
@@ -11068,7 +11068,7 @@ class maybe_range_label_for_tree_type_mismatch : public range_label
       other_type = TREE_TYPE (m_other_expr);
 
    range_label_for_type_mismatch inner (expr_type, other_type);
-   return inner.get_text ();
+   return inner.get_text (range_idx);
   }
 
  private:
index 1d1d59a87ec29530b08df3d7183f9ab2c0d67635..cec08bfd712ca4496d6f3e1f7d91d9fcfdd17d54 100644 (file)
@@ -1,3 +1,8 @@
+2018-09-17  David Malcolm  <dmalcolm@redhat.com>
+
+       * error.c (range_label_for_type_mismatch::get_text): Update for
+       new param.
+
 2018-09-13  Bernd Edlinger  <bernd.edlinger@hotmail.de>
 
        * typeck2.c (digest_init_r): Fix overlength strings.
index 5bab3f345ed8d8ebf0a191f27a491cc9e5c6cf8a..601f6d2c264ee4fd05c81bc983346307213b4b23 100644 (file)
@@ -4289,7 +4289,7 @@ qualified_name_lookup_error (tree scope, tree name,
    Compare with print_template_differences above.  */
 
 label_text
-range_label_for_type_mismatch::get_text () const
+range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const
 {
   if (m_labelled_type == NULL_TREE)
     return label_text (NULL, false);
index 6ce8a0f4a9b7e1bc949c95797dc10e3be19a69e9..7dfb0a036cd6f541dcd161202a382f77f40795ab 100644 (file)
@@ -128,6 +128,7 @@ class layout_range
                const expanded_location *finish_exploc,
                enum range_display_kind range_display_kind,
                const expanded_location *caret_exploc,
+               unsigned original_idx,
                const range_label *label);
 
   bool contains_point (linenum_type row, int column) const;
@@ -137,6 +138,7 @@ class layout_range
   layout_point m_finish;
   enum range_display_kind m_range_display_kind;
   layout_point m_caret;
+  unsigned m_original_idx;
   const range_label *m_label;
 };
 
@@ -236,6 +238,7 @@ class layout
          diagnostic_t diagnostic_kind);
 
   bool maybe_add_location_range (const location_range *loc_range,
+                                unsigned original_idx,
                                 bool restrict_to_current_line_spans);
 
   int get_num_line_spans () const { return m_line_spans.length (); }
@@ -414,11 +417,13 @@ layout_range::layout_range (const expanded_location *start_exploc,
                            const expanded_location *finish_exploc,
                            enum range_display_kind range_display_kind,
                            const expanded_location *caret_exploc,
+                           unsigned original_idx,
                            const range_label *label)
 : m_start (*start_exploc),
   m_finish (*finish_exploc),
   m_range_display_kind (range_display_kind),
   m_caret (*caret_exploc),
+  m_original_idx (original_idx),
   m_label (label)
 {
 }
@@ -546,7 +551,7 @@ make_range (int start_line, int start_col, int end_line, int end_col)
   const expanded_location finish_exploc
     = {"test.c", end_line, end_col, NULL, false};
   return layout_range (&start_exploc, &finish_exploc, SHOW_RANGE_WITHOUT_CARET,
-                      &start_exploc, NULL);
+                      &start_exploc, 0, NULL);
 }
 
 /* Selftests for layout_range::contains_point and
@@ -899,7 +904,7 @@ layout::layout (diagnostic_context * context,
       /* This diagnostic printer can only cope with "sufficiently sane" ranges.
         Ignore any ranges that are awkward to handle.  */
       const location_range *loc_range = richloc->get_range (idx);
-      maybe_add_location_range (loc_range, false);
+      maybe_add_location_range (loc_range, idx, false);
     }
 
   /* Populate m_fixit_hints, filtering to only those that are in the
@@ -953,6 +958,9 @@ layout::layout (diagnostic_context * context,
 /* Attempt to add LOC_RANGE to m_layout_ranges, filtering them to
    those that we can sanely print.
 
+   ORIGINAL_IDX is the index of LOC_RANGE within its rich_location,
+   (for use as extrinsic state by label ranges FIXME).
+
    If RESTRICT_TO_CURRENT_LINE_SPANS is true, then LOC_RANGE is also
    filtered against this layout instance's current line spans: it
    will only be added if the location is fully within the lines
@@ -962,6 +970,7 @@ layout::layout (diagnostic_context * context,
 
 bool
 layout::maybe_add_location_range (const location_range *loc_range,
+                                 unsigned original_idx,
                                  bool restrict_to_current_line_spans)
 {
   gcc_assert (loc_range);
@@ -1001,7 +1010,7 @@ layout::maybe_add_location_range (const location_range *loc_range,
   /* Everything is now known to be in the correct source file,
      but it may require further sanitization.  */
   layout_range ri (&start, &finish, loc_range->m_range_display_kind, &caret,
-                  loc_range->m_label);
+                  original_idx, loc_range->m_label);
 
   /* If we have a range that finishes before it starts (perhaps
      from something built via macro expansion), printing the
@@ -1488,7 +1497,7 @@ layout::print_any_labels (linenum_type row)
          continue;
 
        label_text text;
-       text = range->m_label->get_text ();
+       text = range->m_label->get_text (range->m_original_idx);
 
        /* Allow for labels that return NULL from their get_text
           implementation (so e.g. such labels can control their own
@@ -2277,7 +2286,7 @@ gcc_rich_location::add_location_if_nearby (location_t loc)
   location_range loc_range;
   loc_range.m_loc = loc;
   loc_range.m_range_display_kind = SHOW_RANGE_WITHOUT_CARET;
-  if (!layout.maybe_add_location_range (&loc_range, true))
+  if (!layout.maybe_add_location_range (&loc_range, 0, true))
     return false;
 
   add_range (loc);
index dc11ee87552d9208426d49c9bd660b9eadc62557..e55dd76f4c6cf91394d0fc66bd30139c24e44fb4 100644 (file)
@@ -109,7 +109,7 @@ class text_range_label : public range_label
  public:
   text_range_label (const char *text) : m_text (text) {}
 
-  label_text get_text () const FINAL OVERRIDE
+  label_text get_text (unsigned /*range_idx*/) const FINAL OVERRIDE
   {
     return label_text (const_cast <char *> (m_text), false);
   }
@@ -155,7 +155,7 @@ class range_label_for_type_mismatch : public range_label
   {
   }
 
-  label_text get_text () const OVERRIDE;
+  label_text get_text (unsigned range_idx) const OVERRIDE;
 
  protected:
   tree m_labelled_type;
index 59052be1ba6a1132ebafbe2f69f5378f46e3e5d5..ef96824f7ef388d08ec089efae1ab260d45d45c8 100644 (file)
@@ -1,3 +1,8 @@
+2018-09-17  David Malcolm  <dmalcolm@redhat.com>
+
+       * include/line-map.h (range_label::get_text): Add param
+       "range_idx".
+
 2018-08-30  Nathan Sidwell  <nathan@acm.org>
 
        * include/line-map.h (enum lc_reason): Comment each member
index fd067589b63e8d56de85d27795f279869b31485d..c479dfa2b3ce4c11097bb45f61980b6e1b470ae8 100644 (file)
@@ -1808,8 +1808,10 @@ class range_label
  public:
   virtual ~range_label () {}
 
-  /* Get localized text for the label.  */
-  virtual label_text get_text () const = 0;
+  /* Get localized text for the label.
+     The RANGE_IDX is provided, allowing for range_label instances to be
+     shared by multiple ranges if need be (the "flyweight" design pattern).  */
+  virtual label_text get_text (unsigned range_idx) const = 0;
 };
 
 /* A fix-it hint: a suggested insertion, replacement, or deletion of text.