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
This commit is contained in:
parent
7419f4417a
commit
7c8f7eaa75
@ -1,3 +1,17 @@
|
||||
2016-07-20 David Malcolm <dmalcolm@redhat.com>
|
||||
|
||||
* 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.
|
||||
|
||||
2016-07-20 Georg-Johann Lay <avr@gjlay.de>
|
||||
|
||||
* config/avr/avr-protos.h (avr_addr_space_supported_p): New prototype.
|
||||
|
@ -1,3 +1,13 @@
|
||||
2016-07-20 David Malcolm <dmalcolm@redhat.com>
|
||||
|
||||
* 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.
|
||||
|
||||
2016-07-20 David Malcolm <dmalcolm@redhat.com>
|
||||
|
||||
* c-decl.c (implicit_decl_warning): Update for conversion of
|
||||
|
@ -3955,45 +3955,6 @@ lookup_name_in_scope (tree name, struct c_scope *scope)
|
||||
return NULL_TREE;
|
||||
}
|
||||
|
||||
/* Specialization of edit_distance_traits for preprocessor macros. */
|
||||
|
||||
template <>
|
||||
struct edit_distance_traits<cpp_hashnode *>
|
||||
{
|
||||
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. */
|
||||
|
||||
typedef best_match<tree, cpp_hashnode *> best_macro_match;
|
||||
|
||||
/* A callback for cpp_forall_identifiers, for use by lookup_name_fuzzy.
|
||||
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;
|
||||
}
|
||||
|
||||
/* Look for the closest match for NAME within the currently valid
|
||||
scopes.
|
||||
|
||||
@ -4068,8 +4029,7 @@ lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind)
|
||||
non-NULL result for best_macro_match if it's better than any of
|
||||
the identifiers already checked, which avoids needless creation
|
||||
of identifiers for macro hashnodes. */
|
||||
best_macro_match bmm (name, bm.get_best_distance ());
|
||||
cpp_forall_identifiers (parse_in, find_closest_macro_cpp_cb, &bmm);
|
||||
best_macro_match bmm (name, bm.get_best_distance (), parse_in);
|
||||
cpp_hashnode *best_macro = bmm.get_best_meaningful_candidate ();
|
||||
/* If a macro is the closest so far to NAME, use it, creating an
|
||||
identifier tree node for it. */
|
||||
|
@ -1280,9 +1280,18 @@ diagnostic_show_locus (diagnostic_context * context,
|
||||
{
|
||||
pp_newline (context->printer);
|
||||
|
||||
if (!context->show_caret
|
||||
|| diagnostic_location (diagnostic, 0) <= BUILTINS_LOCATION
|
||||
|| diagnostic_location (diagnostic, 0) == context->last_location)
|
||||
/* Do nothing if source-printing has been disabled. */
|
||||
if (!context->show_caret)
|
||||
return;
|
||||
|
||||
/* Don't attempt to print source for UNKNOWN_LOCATION and for builtins. */
|
||||
if (diagnostic_location (diagnostic, 0) <= BUILTINS_LOCATION)
|
||||
return;
|
||||
|
||||
/* Don't print the same source location twice in a row, unless we have
|
||||
fix-it hints. */
|
||||
if (diagnostic_location (diagnostic, 0) == context->last_location
|
||||
&& diagnostic->richloc->get_num_fixit_hints () == 0)
|
||||
return;
|
||||
|
||||
context->last_location = diagnostic_location (diagnostic, 0);
|
||||
|
@ -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 {
|
||||
|
@ -48,4 +48,30 @@ struct edit_distance_traits<tree>
|
||||
}
|
||||
};
|
||||
|
||||
/* Specialization of edit_distance_traits for preprocessor macros. */
|
||||
|
||||
template <>
|
||||
struct edit_distance_traits<cpp_hashnode *>
|
||||
{
|
||||
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<tree, cpp_hashnode *>
|
||||
{
|
||||
public:
|
||||
best_macro_match (tree goal, edit_distance_t best_distance_so_far,
|
||||
cpp_reader *reader);
|
||||
};
|
||||
|
||||
#endif /* GCC_SPELLCHECK_TREE_H */
|
||||
|
Loading…
Reference in New Issue
Block a user