From 7c8f7eaa75d53ca642203178fb2c6bbe800bc2ea Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Wed, 20 Jul 2016 14:03:03 +0000 Subject: Enabling work for C++ handling of misspelled identifiers and typenames gcc/c/ChangeLog: * c-decl.c (struct edit_distance_traits): 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): 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 --- gcc/spellcheck-tree.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'gcc/spellcheck-tree.h') diff --git a/gcc/spellcheck-tree.h b/gcc/spellcheck-tree.h index 0d5e253..0e43d14 100644 --- a/gcc/spellcheck-tree.h +++ b/gcc/spellcheck-tree.h @@ -48,4 +48,30 @@ struct edit_distance_traits } }; +/* Specialization of edit_distance_traits for preprocessor macros. */ + +template <> +struct edit_distance_traits +{ + static size_t get_length (cpp_hashnode *hashnode) + { + return hashnode->ident.len; + } + + static const char *get_string (cpp_hashnode *hashnode) + { + return (const char *)hashnode->ident.str; + } +}; + +/* Specialization of best_match<> for finding the closest preprocessor + macro to a given identifier. */ + +class best_macro_match : public best_match +{ + public: + best_macro_match (tree goal, edit_distance_t best_distance_so_far, + cpp_reader *reader); +}; + #endif /* GCC_SPELLCHECK_TREE_H */ -- cgit v1.1