]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Introduce gcc_rich_location::add_fixit_misspelled_id
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 14 Jun 2016 23:08:34 +0000 (23:08 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Tue, 14 Jun 2016 23:08:34 +0000 (23:08 +0000)
gcc/c/ChangeLog:
* c-typeck.c (build_component_ref): Simplify fixit code by
using gcc_rich_location::add_fixit_misspelled_id.
(set_init_label): Likewise.

gcc/cp/ChangeLog:
* typeck.c: Include "gcc-rich-location.h".
(finish_class_member_access_expr): Simplify fixit code by
using gcc_rich_location::add_fixit_misspelled_id.

gcc/ChangeLog:
* gcc-rich-location.c
(gcc_rich_location::add_fixit_misspelled_id): New method.
* gcc-rich-location.h
(gcc_rich_location::add_fixit_misspelled_id): Add decl.

From-SVN: r237463

gcc/ChangeLog
gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/gcc-rich-location.c
gcc/gcc-rich-location.h

index 2389681f418a2ed42ff5b6e01d5a293f643b1efa..c0141d6de6a3bfd4523f0a513889741c0dca1dcf 100644 (file)
@@ -1,3 +1,10 @@
+2016-06-14  David Malcolm  <dmalcolm@redhat.com>
+
+       * gcc-rich-location.c
+       (gcc_rich_location::add_fixit_misspelled_id): New method.
+       * gcc-rich-location.h
+       (gcc_rich_location::add_fixit_misspelled_id): Add decl.
+
 2016-06-14  Andreas Tobler  <andreast@gcc.gnu.org>
 
        * config/arm/freebsd.h: Only enable unaligned access for armv6 on
index 08fc250f79a1fa23749f3d091db62072ae353919..85fe5e3562f76e2d6dd3ab5860bd33ec4e4a56a2 100644 (file)
@@ -1,3 +1,9 @@
+2016-06-14  David Malcolm  <dmalcolm@redhat.com>
+
+       * c-typeck.c (build_component_ref): Simplify fixit code by
+       using gcc_rich_location::add_fixit_misspelled_id.
+       (set_init_label): Likewise.
+
 2016-06-13  David Malcolm  <dmalcolm@redhat.com>
 
        * c-parser.c (c_parser_initelt): Provide location of name for new
index ea04d5eed76d719d39db217d2ab74808b766e0a9..f9875087158a9a98a8af9d4ee541c1a59cd1763b 100644 (file)
@@ -2371,14 +2371,9 @@ build_component_ref (location_t loc, tree datum, tree component,
                 we have a valid range for the component.  */
              location_t reported_loc
                = (component_loc != UNKNOWN_LOCATION) ? component_loc : loc;
-             rich_location rich_loc (line_table, reported_loc);
+             gcc_rich_location rich_loc (reported_loc);
              if (component_loc != UNKNOWN_LOCATION)
-               {
-                 source_range component_range =
-                   get_range_from_loc (line_table, component_loc);
-                 rich_loc.add_fixit_replace (component_range,
-                                             IDENTIFIER_POINTER (guessed_id));
-               }
+               rich_loc.add_fixit_misspelled_id (component_loc, guessed_id);
              error_at_rich_loc
                (&rich_loc,
                 "%qT has no member named %qE; did you mean %qE?",
@@ -8234,11 +8229,8 @@ set_init_label (location_t loc, tree fieldname, location_t fieldname_loc,
       tree guessed_id = lookup_field_fuzzy (constructor_type, fieldname);
       if (guessed_id)
        {
-         rich_location rich_loc (line_table, fieldname_loc);
-         source_range component_range =
-           get_range_from_loc (line_table, fieldname_loc);
-         rich_loc.add_fixit_replace (component_range,
-                                     IDENTIFIER_POINTER (guessed_id));
+         gcc_rich_location rich_loc (fieldname_loc);
+         rich_loc.add_fixit_misspelled_id (fieldname_loc, guessed_id);
          error_at_rich_loc
            (&rich_loc,
             "%qT has no member named %qE; did you mean %qE?",
index 54e934af572b4e4606e164f4ed59dfddc6ce6a48..4e4a662faf8e081f07c119e7ccff13f27452fe43 100644 (file)
@@ -1,3 +1,9 @@
+2016-06-14  David Malcolm  <dmalcolm@redhat.com>
+
+       * typeck.c: Include "gcc-rich-location.h".
+       (finish_class_member_access_expr): Simplify fixit code by
+       using gcc_rich_location::add_fixit_misspelled_id.
+
 2016-06-14  Jason Merrill  <jason@redhat.com>
 
        P0145R2: Refining Expression Order for C++.
index f68c2a34024cf14a4f752fe72945d1a54f8c2a0f..2ccd2dad6a14963435da11c8dfca53b9047a49e0 100644 (file)
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "c-family/c-objc.h"
 #include "c-family/c-ubsan.h"
 #include "params.h"
+#include "gcc-rich-location.h"
 
 static tree cp_build_addr_expr_strict (tree, tsubst_flags_t);
 static tree cp_build_function_call (tree, tree, tsubst_flags_t);
@@ -2831,12 +2832,9 @@ finish_class_member_access_expr (cp_expr object, tree name, bool template_p,
                  if (guessed_id)
                    {
                      location_t bogus_component_loc = input_location;
-                     rich_location rich_loc (line_table, bogus_component_loc);
-                     source_range bogus_component_range =
-                       get_range_from_loc (line_table, bogus_component_loc);
-                     rich_loc.add_fixit_replace
-                       (bogus_component_range,
-                        IDENTIFIER_POINTER (guessed_id));
+                     gcc_rich_location rich_loc (bogus_component_loc);
+                     rich_loc.add_fixit_misspelled_id (bogus_component_loc,
+                                                       guessed_id);
                      error_at_rich_loc
                        (&rich_loc,
                         "%q#T has no member named %qE; did you mean %qE?",
index a03ce0ee5fa9d9071a6194280e85fe6e1d5b5c86..15c0700a25b7b110e0c7160b500a3bd77691853f 100644 (file)
@@ -60,3 +60,17 @@ gcc_rich_location::maybe_add_expr (tree t)
   if (EXPR_P (t))
     add_expr (t);
 }
+
+/* Add a fixit hint suggesting replacing the range at MISSPELLED_TOKEN_LOC
+   with the identifier HINT_ID.  */
+
+void
+gcc_rich_location::add_fixit_misspelled_id (location_t misspelled_token_loc,
+                                           tree hint_id)
+{
+  gcc_assert (TREE_CODE (hint_id) == IDENTIFIER_NODE);
+
+  source_range misspelled_token_range
+    = get_range_from_loc (line_table, misspelled_token_loc);
+  add_fixit_replace (misspelled_token_range, IDENTIFIER_POINTER (hint_id));
+}
index fd332deb473c690678bd61705e7447b504483290..9c8a7904c15cc4a390a44b86d76a2290f6029a71 100644 (file)
@@ -42,6 +42,9 @@ class gcc_rich_location : public rich_location
 
   void
   maybe_add_expr (tree t);
+
+  void add_fixit_misspelled_id (location_t misspelled_token_loc,
+                               tree hint_id);
 };
 
 #endif /* GCC_RICH_LOCATION_H */