Spelling suggestions for misspelled preprocessor directives
This patch allows the preprocessor to offer suggestions for misspelled directives, taking us from e.g.: test.c:5:2: error: invalid preprocessing directive #endfi #endfi ^~~~~ to: test.c:5:2: error: invalid preprocessing directive #endfi; did you mean #endif? #endfi ^~~~~ endif gcc/c-family/ChangeLog: * c-common.c: Include "spellcheck.h". (cb_get_suggestion): New function. * c-common.h (cb_get_suggestion): New decl. * c-lex.c (init_c_lex): Initialize cb->get_suggestion to cb_get_suggestion. gcc/testsuite/ChangeLog: * gcc.dg/cpp/misspelled-directive-1.c: New testcase. * gcc.dg/cpp/misspelled-directive-2.c: New testcase. libcpp/ChangeLog: * directives.c (directive_names): New array. (_cpp_handle_directive): Offer spelling suggestions for misspelled directives. * errors.c (cpp_diagnostic_at_richloc): New function. (cpp_error_at_richloc): New function. * include/cpplib.h (struct cpp_callbacks): Add field "get_suggestion". (cpp_error_at_richloc): New decl. From-SVN: r239585
This commit is contained in:
parent
a76989dc7c
commit
cb18fd07f2
11 changed files with 163 additions and 2 deletions
|
@ -597,6 +597,9 @@ struct cpp_callbacks
|
|||
|
||||
/* Callback to parse SOURCE_DATE_EPOCH from environment. */
|
||||
time_t (*get_source_date_epoch) (cpp_reader *);
|
||||
|
||||
/* Callback for providing suggestions for misspelled directives. */
|
||||
const char *(*get_suggestion) (cpp_reader *, const char *, const char *const *);
|
||||
};
|
||||
|
||||
#ifdef VMS
|
||||
|
@ -1066,6 +1069,11 @@ extern bool cpp_error_at (cpp_reader * pfile, int level,
|
|||
source_location src_loc, const char *msgid, ...)
|
||||
ATTRIBUTE_PRINTF_4;
|
||||
|
||||
extern bool cpp_error_at_richloc (cpp_reader * pfile, int level,
|
||||
rich_location *richloc, const char *msgid,
|
||||
...)
|
||||
ATTRIBUTE_PRINTF_4;
|
||||
|
||||
/* In lex.c */
|
||||
extern int cpp_ideq (const cpp_token *, const char *);
|
||||
extern void cpp_output_line (cpp_reader *, FILE *);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue