aboutsummaryrefslogtreecommitdiff
path: root/libcpp/include
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-08-30 13:54:48 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-08-30 13:54:48 +0000
commitf90877980167d64fe479ff8a2877628c60b7d550 (patch)
treeb3644a6d4633c240f2961d55a0f178b387bbe50d /libcpp/include
parent43ed860c2abbccdcc836bf68bd07d97f482924d1 (diff)
downloadgcc-f90877980167d64fe479ff8a2877628c60b7d550.zip
gcc-f90877980167d64fe479ff8a2877628c60b7d550.tar.gz
gcc-f90877980167d64fe479ff8a2877628c60b7d550.tar.bz2
rich_location: add convenience overloads for adding fix-it hints
Adding a fix-it hint to a diagnostic usually follows one of these patterns: (a) an insertion fix-its, with the insertion at the primary caret location (b) a removals/replacements, affecting the range of the primary location (other cases are possible, e.g. multiple fix-its, and affecting other locations, but these are the common ones) Given these common cases, this patch adds overloads of the rich_location methods for adding fix-it hints, so that the location information can be omitted if it matches that of the primary location within the rich_location. Similarly when adding "remove" and "replace" fix-it hints to a diagnostic, it's tedious to have to extract the source_range from a location_t (aka source_location). To make this more convenient, this patch adds overload of the rich_location::add_fixit_remove/replace methods, accepting a source_location directly. The patch updates the various in-tree users of fix-it hints to use the new simpler API where appropriate. I didn't touch the case where there are multiple fix-its in one rich_location, as it seems better to be more explicit about locations for this case (adding a pair of parens in warn_logical_not_parentheses). The above makes the gcc_rich_location::add_fixit_misspelled_id overload taking a const char * rather redundant, so I eliminated it. gcc/c/ChangeLog: * c-decl.c (implicit_decl_warning): Use add_fixit_replace rather than add_fixit_misspelled_id. (undeclared_variable): Likewise. * c-parser.c (c_parser_declaration_or_fndef): Likewise. Remove now-redundant "here" params from add_fixit_insert method calls. (c_parser_parameter_declaration): Likewise. * c-typeck.c (build_component_ref): Remove now-redundant range param from add_fixit_replace method calls. gcc/cp/ChangeLog: * name-lookup.c (suggest_alternatives_for): Use add_fixit_replace rather than add_fixit_misspelled_id. * parser.c (cp_parser_diagnose_invalid_type_name): Likewise. gcc/ChangeLog: * diagnostic-show-locus.c (test_one_liner_fixit_insert): Remove redundant location param. (test_one_liner_fixit_remove): Likewise. (test_one_liner_fixit_replace): Likewise. (test_one_liner_fixit_replace_equal_secondary_range): Likewise. * gcc-rich-location.c (gcc_rich_location::add_fixit_misspelled_id): Eliminate call to get_range_from_loc. Drop overload taking a const char *. * gcc-rich-location.h (gcc_rich_location::add_fixit_misspelled_id): Drop overload taking a const char *. libcpp/ChangeLog: * include/line-map.h (rich_location::add_fixit_insert): Add comments. Add overload omitting the source_location param. (rich_location::add_fixit_remove): Add comments. Add overloads omitting the range, and accepting a source_location. (rich_location::add_fixit_replace): Likewise. * line-map.c (rich_location::add_fixit_insert): Add comments. Add overload omitting the source_location param. (rich_location::add_fixit_remove): Add comments. Add overloads omitting the range, and accepting a source_location. (rich_location::add_fixit_replace): Likewise. From-SVN: r239861
Diffstat (limited to 'libcpp/include')
-rw-r--r--libcpp/include/line-map.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index d9c31de..122e474 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -1401,13 +1401,47 @@ class rich_location
override_column (int column);
/* Fix-it hints. */
+
+ /* Methods for adding insertion fix-it hints. */
+
+ /* Suggest inserting NEW_CONTENT at the primary range's caret. */
+ void
+ add_fixit_insert (const char *new_content);
+
+ /* Suggest inserting NEW_CONTENT at WHERE. */
void
add_fixit_insert (source_location where,
const char *new_content);
+ /* Methods for adding removal fix-it hints. */
+
+ /* Suggest removing the content covered by range 0. */
+ void
+ add_fixit_remove ();
+
+ /* Suggest removing the content covered between the start and finish
+ of WHERE. */
+ void
+ add_fixit_remove (source_location where);
+
+ /* Suggest removing the content covered by SRC_RANGE. */
void
add_fixit_remove (source_range src_range);
+ /* Methods for adding "replace" fix-it hints. */
+
+ /* Suggest replacing the content covered by range 0 with NEW_CONTENT. */
+ void
+ add_fixit_replace (const char *new_content);
+
+ /* Suggest replacing the content between the start and finish of
+ WHERE with NEW_CONTENT. */
+ void
+ add_fixit_replace (source_location where,
+ const char *new_content);
+
+ /* Suggest replacing the content covered by SRC_RANGE with
+ NEW_CONTENT. */
void
add_fixit_replace (source_range src_range,
const char *new_content);