diff options
author | dmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-08-18 18:52:43 +0000 |
---|---|---|
committer | dmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-08-18 18:52:43 +0000 |
commit | 5c8151fa9160fe2d93ef717fd635038d085c98af (patch) | |
tree | b325fd07e1c9c2f08551326602a989303e28ddfd /libcpp/errors.c | |
parent | 26040f0690707cfdfe08d0ea129efdaf4dc503ef (diff) |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@239585 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp/errors.c')
-rw-r--r-- | libcpp/errors.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/libcpp/errors.c b/libcpp/errors.c index f7d411226eee..3b0a0b414612 100644 --- a/libcpp/errors.c +++ b/libcpp/errors.c @@ -31,6 +31,23 @@ along with this program; see the file COPYING3. If not see ATTRIBUTE_FPTR_PRINTF(5,0) static bool +cpp_diagnostic_at_richloc (cpp_reader * pfile, int level, int reason, + rich_location *richloc, + const char *msgid, va_list *ap) +{ + bool ret; + + if (!pfile->cb.error) + abort (); + ret = pfile->cb.error (pfile, level, reason, richloc, _(msgid), ap); + + return ret; +} + +/* Print a diagnostic at the given location. */ + +ATTRIBUTE_FPTR_PRINTF(5,0) +static bool cpp_diagnostic_at (cpp_reader * pfile, int level, int reason, source_location src_loc, const char *msgid, va_list *ap) @@ -255,6 +272,25 @@ cpp_error_at (cpp_reader * pfile, int level, source_location src_loc, return ret; } +/* As cpp_error, but use RICHLOC as the location of the error, without + a column override. */ + +bool +cpp_error_at_richloc (cpp_reader * pfile, int level, rich_location *richloc, + const char *msgid, ...) +{ + va_list ap; + bool ret; + + va_start (ap, msgid); + + ret = cpp_diagnostic_at_richloc (pfile, level, CPP_W_NONE, richloc, + msgid, &ap); + + va_end (ap); + return ret; +} + /* Print a warning or error, depending on the value of LEVEL. Include information from errno. */ |