aboutsummaryrefslogtreecommitdiff
path: root/gcc/spellcheck-tree.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-07-20 14:03:03 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-07-20 14:03:03 +0000
commit7c8f7eaa75d53ca642203178fb2c6bbe800bc2ea (patch)
tree4295610e81aed46c2605b630ee7f4d3963766ac1 /gcc/spellcheck-tree.c
parent7419f4417a33ff9143317794aa985f7681d1e2a0 (diff)
downloadgcc-7c8f7eaa75d53ca642203178fb2c6bbe800bc2ea.zip
gcc-7c8f7eaa75d53ca642203178fb2c6bbe800bc2ea.tar.gz
gcc-7c8f7eaa75d53ca642203178fb2c6bbe800bc2ea.tar.bz2
Enabling work for C++ handling of misspelled identifiers and typenames
gcc/c/ChangeLog: * c-decl.c (struct edit_distance_traits<cpp_hashnode *>): Move to spellcheck-tree.h (best_macro_match): Likewise, converting from a typedef to a subclass. (find_closest_macro_cpp_cb): Move to spellcheck-tree.c. (lookup_name_fuzzy): Update for change of best_macro_match to a subclass with a ctor that calls cpp_forall_identifiers. gcc/ChangeLog: * diagnostic-show-locus.c (diagnostic_show_locus): If this is the same location as last time, don't skip if we have fix-it hints. Clarify the skipping logic by converting it from one "if" clause to repeated "if" clauses. * spellcheck-tree.c: Include "cpplib.h". (find_closest_macro_cpp_cb): Move here from c/c-decl.c. (best_macro_match::best_macro_match): New constructor. * spellcheck-tree.h (struct edit_distance_traits<cpp_hashnode *>): Move here from c/c-decl.c. (class best_macro_match): Move here from c/c-decl.c, converting from a typedef to a subclass, gaining a ctor. From-SVN: r238522
Diffstat (limited to 'gcc/spellcheck-tree.c')
-rw-r--r--gcc/spellcheck-tree.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/gcc/spellcheck-tree.c b/gcc/spellcheck-tree.c
index 63fb1a8..ef1e689 100644
--- a/gcc/spellcheck-tree.c
+++ b/gcc/spellcheck-tree.c
@@ -22,6 +22,7 @@ along with GCC; see the file COPYING3. If not see
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
+#include "cpplib.h"
#include "spellcheck-tree.h"
#include "selftest.h"
#include "stringpool.h"
@@ -65,6 +66,36 @@ find_closest_identifier (tree target, const auto_vec<tree> *candidates)
return bm.get_best_meaningful_candidate ();
}
+/* A callback for cpp_forall_identifiers, for use by best_macro_match's ctor.
+ Process HASHNODE and update the best_macro_match instance pointed to be
+ USER_DATA. */
+
+static int
+find_closest_macro_cpp_cb (cpp_reader *, cpp_hashnode *hashnode,
+ void *user_data)
+{
+ if (hashnode->type != NT_MACRO)
+ return 1;
+
+ best_macro_match *bmm = (best_macro_match *)user_data;
+ bmm->consider (hashnode);
+
+ /* Keep iterating. */
+ return 1;
+}
+
+/* Constructor for best_macro_match.
+ Use find_closest_macro_cpp_cb to find the closest matching macro to
+ NAME within distance < best_distance_so_far. */
+
+best_macro_match::best_macro_match (tree goal,
+ edit_distance_t best_distance_so_far,
+ cpp_reader *reader)
+ : best_match (goal, best_distance_so_far)
+{
+ cpp_forall_identifiers (reader, find_closest_macro_cpp_cb, this);
+}
+
#if CHECKING_P
namespace selftest {