c-family: add name_hint/deferred_diagnostic
commitdd008336e8fdd7aed8566741696fd8d594a3106d
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 20 Nov 2017 18:37:05 +0000 (20 18:37 +0000)
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 20 Nov 2017 18:37:05 +0000 (20 18:37 +0000)
tree733042f52e9275c5054c79cb9da0c33989b71861
parent8bd7380106a0505f45fb9d81a8c4e878618c36b4
c-family: add name_hint/deferred_diagnostic

In various places we use lookup_name_fuzzy to provide a hint,
and can report messages of the form:
  error: unknown foo named 'bar'
or:
  error: unknown foo named 'bar'; did you mean 'SUGGESTION?

This patch provides a way for lookup_name_fuzzy to provide
both the suggestion above, and (optionally) additional hints
that can be printed e.g.

  note: did you forget to include <SOME_HEADER.h>?

This patch provides the mechanism and ports existing users
of lookup_name_fuzzy to the new return type.
There are no uses of such hints in this patch, but followup
patches provide various front-end specific uses of this.

gcc/c-family/ChangeLog:
* c-common.h (enum lookup_name_fuzzy_kind): Move to name-hint.h.
(lookup_name_fuzzy): Likewise.  Convert return type from
const char * to name_hint.  Add location_t param.
* name-hint.h: New header.

gcc/c/ChangeLog:
* c-decl.c: Define INCLUDE_UNIQUE_PTR before including system.h.
Include "c-family/name-hint.h"
(implicit_decl_warning): Convert "hint" from
const char * to name_hint.  Pass location to
lookup_name_fuzzy.  Suppress any deferred diagnostic if the
warning was not printed.
(undeclared_variable): Likewise for "guessed_id".
(lookup_name_fuzzy): Convert return type from const char *
to name_hint.  Add location_t param.
* c-parser.c: Define INCLUDE_UNIQUE_PTR before including system.h.
Include "c-family/name-hint.h"
(c_parser_declaration_or_fndef): Convert "hint" from
const char * to name_hint.  Pass location to lookup_name_fuzzy.
(c_parser_parameter_declaration): Likewise.

gcc/cp/ChangeLog:
* name-lookup.c: Define INCLUDE_UNIQUE_PTR before including system.h.
Include "c-family/name-hint.h"
(suggest_alternatives_for): Convert "fuzzy_name" from const char *
to name_hint, and rename to "hint".  Pass location to
lookup_name_fuzzy.
(lookup_name_fuzzy): Convert return type from const char *
to name_hint.  Add location_t param.
* parser.c: Define INCLUDE_UNIQUE_PTR before including system.h.
Include "c-family/name-hint.h"
(cp_parser_diagnose_invalid_type_name): Convert
"suggestion" from const char * to name_hint, and rename to "hint".
Pass location to lookup_name_fuzzy.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254963 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/c-family/ChangeLog
gcc/c-family/c-common.h
gcc/c-family/name-hint.h [new file with mode: 0644]
gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/c/c-parser.c
gcc/cp/ChangeLog
gcc/cp/name-lookup.c
gcc/cp/parser.c