summaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2015-11-20 01:26:00 +0000
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2015-11-20 01:26:00 +0000
commit11d8dd6fe925464af9dc8283360e196c55c48e17 (patch)
tree3572616c35cc69549b3ff9761e6d1af8fb70780b /gcc/c
parentaf44a72df6662100baea4ddfd36dc5fe945640ae (diff)
downloadgcc-11d8dd6fe925464af9dc8283360e196c55c48e17.tar.gz
C++ FE: offer suggestions for misspelled field names
gcc/c/ChangeLog: * c-typeck.c (lookup_field_fuzzy): Move determination of closest candidate into a new function, find_closest_identifier. gcc/cp/ChangeLog: * cp-tree.h (lookup_member_fuzzy): New decl. * search.c: Include spellcheck.h. (class lookup_field_fuzzy_info): New class. (lookup_field_fuzzy_info::fuzzy_lookup_fnfields): New. (lookup_field_fuzzy_info::fuzzy_lookup_field): New. (lookup_field_fuzzy_r): New. (lookup_member_fuzzy): New. * typeck.c (finish_class_member_access_expr): When issuing a "has no member named" error, call lookup_member_fuzzy, and offer any result as a suggestion. gcc/ChangeLog: * spellcheck-tree.c (find_closest_identifier): New function, taken from c/c-typeck.c:lookup_field_fuzzy, with NULL corrected to NULL_TREE in two places. * spellcheck.h (find_closest_identifier): New decl. gcc/testsuite/ChangeLog: * g++.dg/spellcheck-fields.C: New file. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@230638 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog5
-rw-r--r--gcc/c/c-typeck.c28
2 files changed, 6 insertions, 27 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index a0cab878d6f..9399053a7f9 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,8 @@
+2015-11-19 David Malcolm <dmalcolm@redhat.com>
+
+ * c-typeck.c (lookup_field_fuzzy): Move determination of closest
+ candidate into a new function, find_closest_identifier.
+
2015-11-19 Marek Polacek <polacek@redhat.com>
PR c/68412
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 5cb0f7e622e..9284bfcea66 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -2274,33 +2274,7 @@ lookup_field_fuzzy (tree type, tree component)
lookup_field_fuzzy_find_candidates (type, component,
&candidates);
- /* Now determine which is closest. */
- int i;
- tree identifier;
- tree best_identifier = NULL;
- edit_distance_t best_distance = MAX_EDIT_DISTANCE;
- FOR_EACH_VEC_ELT (candidates, i, identifier)
- {
- gcc_assert (TREE_CODE (identifier) == IDENTIFIER_NODE);
- edit_distance_t dist = levenshtein_distance (component, identifier);
- if (dist < best_distance)
- {
- best_distance = dist;
- best_identifier = identifier;
- }
- }
-
- /* If more than half of the letters were misspelled, the suggestion is
- likely to be meaningless. */
- if (best_identifier)
- {
- unsigned int cutoff = MAX (IDENTIFIER_LENGTH (component),
- IDENTIFIER_LENGTH (best_identifier)) / 2;
- if (best_distance > cutoff)
- return NULL;
- }
-
- return best_identifier;
+ return find_closest_identifier (component, &candidates);
}
/* Make an expression to refer to the COMPONENT field of structure or