64a5912c9e
Adding a fix-it hint currently involves changing e.g.: error_at (token->location, "unknown type name %qE; did you mean %qs?", token->value, hint); to: gcc_rich_location richloc (token->location); richloc.add_fixit_replace (hint); error_at_rich_loc (&richloc, "unknown type name %qE; did you mean %qs?", token->value, hint); to make the change from taking a location_t to a rich_location *. This patch renames the "*_at_rich_loc" diagnostic entrypoints to use the same function names for rich_location * as for location_t, via overloading, to simplify the above change to just changing from: error_at (token->location, "unknown type name %qE; did you mean %qs?", token->value, hint); to: gcc_rich_location richloc (token->location); richloc.add_fixit_replace (hint); error_at (&richloc, "unknown type name %qE; did you mean %qs?", token->value, hint); thus saving space (and typing) and usually avoiding the need to reindent the "error_at" invocation. With this change, 0 is no longer acceptable as a location_t to these entrypoints, as e.g.: ../../src/gcc/auto-profile.c:855:37: error: call of overloaded 'inform(int, const char [18])' is ambiguous inform (0, "Not expected TAG."); ^ In file included from ../../src/gcc/auto-profile.c:35:0: ../../src/gcc/diagnostic-core.h:88:13: note: candidate: 'void inform(location_t, const char*, ...)' extern void inform (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); ^~~~~~ ../../src/gcc/diagnostic-core.h:89:13: note: candidate: 'void inform(rich_location*, const char*, ...)' extern void inform (rich_location *, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); ^~~~~~ Such locations now need to be spelled out as UNKNOWN_LOCATION, rather than 0. I considered making the API take a rich_location & rather than a rich_location *, but doing so would mean replacing diagnostic_set_info and diagnostic_set_info_translated with a constructor for diagnostic_info, which was a more invasive change. Maybe in the future. gcc/ChangeLog: * auto-profile.c (autofdo_source_profile::read): Use UNKNOWN_LOCATION rather than 0. * diagnostic-core.h (warning_at_rich_loc): Rename to... (warning_at): ...this overload. (warning_at_rich_loc_n): Rename to... (warning_n): ...this overload. (error_at_rich_loc): Rename to... (error_at): ...this overload. (pedwarn_at_rich_loc): Rename to... (pedwarn): ...this overload. (permerror_at_rich_loc): Rename to... (permerror): ...this overload. (inform_at_rich_loc): Rename to... (inform): ...this overload. * diagnostic.c: (diagnostic_n_impl): Delete location_t-based decl. (diagnostic_n_impl_richloc): Rename to... (diagnostic_n_impl): ...this rich_location *-based decl. (inform_at_rich_loc): Rename to... (inform): ...this, and add an assertion. (inform_n): Update for removal of location_t-based diagnostic_n_impl. (warning_at_rich_loc): Rename to... (warning_at): ...this, and add an assertion. (warning_at_rich_loc_n): Rename to... (warning_n): ...this, and add an assertion. (warning_n): Update location_t-based implementation for removal of location_t-based diagnostic_n_impl. (pedwarn_at_rich_loc): Rename to... (pedwarn): ...this, and add an assertion. (permerror_at_rich_loc): Rename to... (permerror): ...this, and add an assertion. (error_n): Update for removal of location_t-based diagnostic_n_impl. (error_at_rich_loc): Rename to... (error_at): ...this, and add an assertion. * gcc.c (do_spec_1): Use UNKNOWN_LOCATION rather than 0. (driver::do_spec_on_infiles): Likewise. * substring-locations.c (format_warning_va): Update for renaming of inform_at_rich_loc. gcc/c-family/ChangeLog: * c-common.c (binary_op_error): Update for renaming of error_at_rich_loc. (c_parse_error): Likewise. * c-warn.c (warn_logical_not_parentheses): Likewise for renaming of inform_at_rich_loc. (warn_for_restrict): Likewise for renaming of warning_at_rich_loc_n. gcc/c/ChangeLog: * c-decl.c (implicit_decl_warning): Update for renaming of pedwarn_at_rich_loc and warning_at_rich_loc. (implicitly_declare): Likewise for renaming of inform_at_rich_loc. (undeclared_variable): Likewise for renaming of error_at_rich_loc. * c-parser.c (c_parser_declaration_or_fndef): Likewise. (c_parser_struct_or_union_specifier): Likewise for renaming of pedwarn_at_rich_loc. (c_parser_parameter_declaration): Likewise for renaming of error_at_rich_loc. * c-typeck.c (build_component_ref): Likewise. (build_unary_op): Likewise for renaming of inform_at_rich_loc. (pop_init_level): Likewise for renaming of warning_at_rich_loc. (set_init_label): Likewise for renaming of error_at_rich_loc. gcc/cp/ChangeLog: * class.c (explain_non_literal_class): Use UNKNOWN_LOCATION rather than 0. * name-lookup.c (suggest_alternatives_for): Update for renaming of inform_at_rich_loc. (maybe_suggest_missing_header): Likewise. (suggest_alternative_in_explicit_scope): Likewise. * parser.c (cp_parser_diagnose_invalid_type_name): Likewise for renaming of error_at_rich_loc. (cp_parser_string_literal): Likewise. (cp_parser_nested_name_specifier_opt): Likewise. (cp_parser_cast_expression): Likewise for renaming of warning_at_rich_loc. (cp_parser_decl_specifier_seq): Likewise for renaming of error_at_rich_loc and warning_at_rich_loc. (cp_parser_elaborated_type_specifier): Likewise for renaming of pedwarn_at_rich_loc. (cp_parser_cv_qualifier_seq_opt): Likewise for renaming of error_at_rich_loc. (cp_parser_virt_specifier_seq_opt): Likewise. (cp_parser_class_specifier_1): Likewise. (cp_parser_class_head): Likewise. (cp_parser_member_declaration): Likewise for renaming of pedwarn_at_rich_loc, warning_at_rich_loc, and error_at_rich_loc. (cp_parser_enclosed_template_argument_list): Likewise for renaming of error_at_rich_loc. (set_and_check_decl_spec_loc): Likewise. * pt.c (listify): Likewise. * rtti.c (typeid_ok_p): Likewise. * semantics.c (process_outer_var_ref): Use UNKNOWN_LOCATION rather than 0. * typeck.c (access_failure_info::maybe_suggest_accessor): Update for renaming of inform_at_rich_loc. (finish_class_member_access_expr): Likewise for renaming of error_at_rich_loc. gcc/objc/ChangeLog: * objc-gnu-runtime-abi-01.c (objc_gnu_runtime_abi_01_init): Use UNKNOWN_LOCATION rather than 0. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_show_trees.c (show_tree): Update for renaming of error_at_rich_loc and inform_at_rich_loc. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (test_show_locus): Likewise for renaming of warning_at_rich_loc. libcpp/ChangeLog: * directives.c (_cpp_handle_directive): Update for renaming of cpp_error_at_richloc to cpp_error_at. * errors.c (cpp_diagnostic_at_richloc): Rename to... (cpp_diagnostic_at): ...this, dropping the location_t-based implementation. (cpp_diagnostic): Update for removal of location_t-based cpp_diagnostic_at. (cpp_error_at): Likewise. (cpp_error_at_richloc): Rename to... (cpp_error_at): ...this, and update for renaming of cpp_diagnostic_at_richloc. * include/cpplib.h (cpp_error_at_richloc): Rename to... (cpp_error_at): ...this. From-SVN: r254280
301 lines
7.2 KiB
C
301 lines
7.2 KiB
C
/* Default error handlers for CPP Library.
|
|
Copyright (C) 1986-2017 Free Software Foundation, Inc.
|
|
Written by Per Bothner, 1994.
|
|
Based on CCCP program by Paul Rubin, June 1986
|
|
Adapted to ANSI C, Richard Stallman, Jan 1987
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
under the terms of the GNU General Public License as published by the
|
|
Free Software Foundation; either version 3, or (at your option) any
|
|
later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; see the file COPYING3. If not see
|
|
<http://www.gnu.org/licenses/>.
|
|
|
|
In other words, you are welcome to use, share and improve this program.
|
|
You are forbidden to forbid anyone else to use, share and improve
|
|
what you give them. Help stamp out software-hoarding! */
|
|
|
|
#include "config.h"
|
|
#include "system.h"
|
|
#include "cpplib.h"
|
|
#include "internal.h"
|
|
|
|
/* Print a diagnostic at the given location. */
|
|
|
|
ATTRIBUTE_FPTR_PRINTF(5,0)
|
|
static bool
|
|
cpp_diagnostic_at (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 location of the previously lexed token. */
|
|
|
|
ATTRIBUTE_FPTR_PRINTF(4,0)
|
|
static bool
|
|
cpp_diagnostic (cpp_reader * pfile, int level, int reason,
|
|
const char *msgid, va_list *ap)
|
|
{
|
|
source_location src_loc;
|
|
|
|
if (CPP_OPTION (pfile, traditional))
|
|
{
|
|
if (pfile->state.in_directive)
|
|
src_loc = pfile->directive_line;
|
|
else
|
|
src_loc = pfile->line_table->highest_line;
|
|
}
|
|
/* We don't want to refer to a token before the beginning of the
|
|
current run -- that is invalid. */
|
|
else if (pfile->cur_token == pfile->cur_run->base)
|
|
{
|
|
src_loc = 0;
|
|
}
|
|
else
|
|
{
|
|
src_loc = pfile->cur_token[-1].src_loc;
|
|
}
|
|
rich_location richloc (pfile->line_table, src_loc);
|
|
return cpp_diagnostic_at (pfile, level, reason, &richloc, msgid, ap);
|
|
}
|
|
|
|
/* Print a warning or error, depending on the value of LEVEL. */
|
|
|
|
bool
|
|
cpp_error (cpp_reader * pfile, int level, const char *msgid, ...)
|
|
{
|
|
va_list ap;
|
|
bool ret;
|
|
|
|
va_start (ap, msgid);
|
|
|
|
ret = cpp_diagnostic (pfile, level, CPP_W_NONE, msgid, &ap);
|
|
|
|
va_end (ap);
|
|
return ret;
|
|
}
|
|
|
|
/* Print a warning. The warning reason may be given in REASON. */
|
|
|
|
bool
|
|
cpp_warning (cpp_reader * pfile, int reason, const char *msgid, ...)
|
|
{
|
|
va_list ap;
|
|
bool ret;
|
|
|
|
va_start (ap, msgid);
|
|
|
|
ret = cpp_diagnostic (pfile, CPP_DL_WARNING, reason, msgid, &ap);
|
|
|
|
va_end (ap);
|
|
return ret;
|
|
}
|
|
|
|
/* Print a pedantic warning. The warning reason may be given in REASON. */
|
|
|
|
bool
|
|
cpp_pedwarning (cpp_reader * pfile, int reason, const char *msgid, ...)
|
|
{
|
|
va_list ap;
|
|
bool ret;
|
|
|
|
va_start (ap, msgid);
|
|
|
|
ret = cpp_diagnostic (pfile, CPP_DL_PEDWARN, reason, msgid, &ap);
|
|
|
|
va_end (ap);
|
|
return ret;
|
|
}
|
|
|
|
/* Print a warning, including system headers. The warning reason may be
|
|
given in REASON. */
|
|
|
|
bool
|
|
cpp_warning_syshdr (cpp_reader * pfile, int reason, const char *msgid, ...)
|
|
{
|
|
va_list ap;
|
|
bool ret;
|
|
|
|
va_start (ap, msgid);
|
|
|
|
ret = cpp_diagnostic (pfile, CPP_DL_WARNING_SYSHDR, reason, msgid, &ap);
|
|
|
|
va_end (ap);
|
|
return ret;
|
|
}
|
|
|
|
/* Print a diagnostic at a specific location. */
|
|
|
|
ATTRIBUTE_FPTR_PRINTF(6,0)
|
|
static bool
|
|
cpp_diagnostic_with_line (cpp_reader * pfile, int level, int reason,
|
|
source_location src_loc, unsigned int column,
|
|
const char *msgid, va_list *ap)
|
|
{
|
|
bool ret;
|
|
|
|
if (!pfile->cb.error)
|
|
abort ();
|
|
rich_location richloc (pfile->line_table, src_loc);
|
|
if (column)
|
|
richloc.override_column (column);
|
|
ret = pfile->cb.error (pfile, level, reason, &richloc, _(msgid), ap);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/* Print a warning or error, depending on the value of LEVEL. */
|
|
|
|
bool
|
|
cpp_error_with_line (cpp_reader *pfile, int level,
|
|
source_location src_loc, unsigned int column,
|
|
const char *msgid, ...)
|
|
{
|
|
va_list ap;
|
|
bool ret;
|
|
|
|
va_start (ap, msgid);
|
|
|
|
ret = cpp_diagnostic_with_line (pfile, level, CPP_W_NONE, src_loc,
|
|
column, msgid, &ap);
|
|
|
|
va_end (ap);
|
|
return ret;
|
|
}
|
|
|
|
/* Print a warning. The warning reason may be given in REASON. */
|
|
|
|
bool
|
|
cpp_warning_with_line (cpp_reader *pfile, int reason,
|
|
source_location src_loc, unsigned int column,
|
|
const char *msgid, ...)
|
|
{
|
|
va_list ap;
|
|
bool ret;
|
|
|
|
va_start (ap, msgid);
|
|
|
|
ret = cpp_diagnostic_with_line (pfile, CPP_DL_WARNING, reason, src_loc,
|
|
column, msgid, &ap);
|
|
|
|
va_end (ap);
|
|
return ret;
|
|
}
|
|
|
|
/* Print a pedantic warning. The warning reason may be given in REASON. */
|
|
|
|
bool
|
|
cpp_pedwarning_with_line (cpp_reader *pfile, int reason,
|
|
source_location src_loc, unsigned int column,
|
|
const char *msgid, ...)
|
|
{
|
|
va_list ap;
|
|
bool ret;
|
|
|
|
va_start (ap, msgid);
|
|
|
|
ret = cpp_diagnostic_with_line (pfile, CPP_DL_PEDWARN, reason, src_loc,
|
|
column, msgid, &ap);
|
|
|
|
va_end (ap);
|
|
return ret;
|
|
}
|
|
|
|
/* Print a warning, including system headers. The warning reason may be
|
|
given in REASON. */
|
|
|
|
bool
|
|
cpp_warning_with_line_syshdr (cpp_reader *pfile, int reason,
|
|
source_location src_loc, unsigned int column,
|
|
const char *msgid, ...)
|
|
{
|
|
va_list ap;
|
|
bool ret;
|
|
|
|
va_start (ap, msgid);
|
|
|
|
ret = cpp_diagnostic_with_line (pfile, CPP_DL_WARNING_SYSHDR, reason, src_loc,
|
|
column, msgid, &ap);
|
|
|
|
va_end (ap);
|
|
return ret;
|
|
}
|
|
|
|
/* As cpp_error, but use SRC_LOC as the location of the error, without
|
|
a column override. */
|
|
|
|
bool
|
|
cpp_error_at (cpp_reader * pfile, int level, source_location src_loc,
|
|
const char *msgid, ...)
|
|
{
|
|
va_list ap;
|
|
bool ret;
|
|
|
|
va_start (ap, msgid);
|
|
|
|
rich_location richloc (pfile->line_table, src_loc);
|
|
ret = cpp_diagnostic_at (pfile, level, CPP_W_NONE, &richloc,
|
|
msgid, &ap);
|
|
|
|
va_end (ap);
|
|
return ret;
|
|
}
|
|
|
|
/* As cpp_error, but use RICHLOC as the location of the error, without
|
|
a column override. */
|
|
|
|
bool
|
|
cpp_error_at (cpp_reader * pfile, int level, rich_location *richloc,
|
|
const char *msgid, ...)
|
|
{
|
|
va_list ap;
|
|
bool ret;
|
|
|
|
va_start (ap, msgid);
|
|
|
|
ret = cpp_diagnostic_at (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. */
|
|
|
|
bool
|
|
cpp_errno (cpp_reader *pfile, int level, const char *msgid)
|
|
{
|
|
return cpp_error (pfile, level, "%s: %s", _(msgid), xstrerror (errno));
|
|
}
|
|
|
|
/* Print a warning or error, depending on the value of LEVEL. Include
|
|
information from errno. Unlike cpp_errno, the argument is a filename
|
|
that is not localized, but "" is replaced with localized "stdout". */
|
|
|
|
bool
|
|
cpp_errno_filename (cpp_reader *pfile, int level, const char *filename,
|
|
source_location loc)
|
|
{
|
|
if (filename[0] == '\0')
|
|
filename = _("stdout");
|
|
|
|
return cpp_error_at (pfile, level, loc, "%s: %s", filename,
|
|
xstrerror (errno));
|
|
}
|