diagnostics: convert diagnostic_context to a class

This patch:
- converts "struct diagnostic_context" to "class diagnostic_context".
- ensures all data members have an "m_" prefix, except for "printer",
  which has so many uses that renaming would be painful.
- makes most of the data members private
- converts much of the diagnostic_* functions to member functions of
  diagnostic_context, adding compatibility wrappers for users such as
  the Fortran frontend, and making as many as possible private.

No functional change intended.

gcc/ChangeLog:
	* common.opt (fdiagnostics-text-art-charset=): Remove refererence
	to diagnostic-text-art.h.
	* coretypes.h (struct diagnostic_context): Replace forward decl
	with...
	(class diagnostic_context): ...this.
	* diagnostic-format-json.cc: Update for changes to
	diagnostic_context.
	* diagnostic-format-sarif.cc: Likewise.
	* diagnostic-show-locus.cc: Likewise.
	* diagnostic-text-art.h: Deleted file, moving content...
	(enum diagnostic_text_art_charset): ...to diagnostic.h,
	(DIAGNOSTICS_TEXT_ART_CHARSET_DEFAULT): ...deleting,
	(diagnostics_text_art_charset_init): ...deleting in favor of
	diagnostic_context::set_text_art_charset.
	* diagnostic.cc: Remove include of "diagnostic-text-art.h".
	(pedantic_warning_kind): Update for field renaming.
	(permissive_error_kind): Likewise.
	(permissive_error_option): Likewise.
	(diagnostic_initialize): Convert to...
	(diagnostic_context::initialize): ...this, updating for field
	renamings.
	(diagnostic_color_init): Convert to...
	(diagnostic_context::color_init): ...this.
	(diagnostic_urls_init): Convert to...
	(diagnostic_context::urls_init): ...this.
	(diagnostic_initialize_input_context): Convert to...
	(diagnostic_context::initialize_input_context): ...this.
	(diagnostic_finish): Convert to...
	(diagnostic_context::finish): ...this, updating for field
	renamings.
	(diagnostic_context::set_output_format): New.
	(diagnostic_context::set_client_data_hooks): New.
	(diagnostic_context::create_edit_context): New.
	(diagnostic_converted_column): Convert to...
	(diagnostic_context::converted_column): ...this.
	(diagnostic_get_location_text): Update for field renaming.
	(diagnostic_check_max_errors): Convert to...
	(diagnostic_context::check_max_errors): ...this, updating for
	field renamings.
	(diagnostic_action_after_output): Convert to...
	(diagnostic_context::action_after_output): ...this, updating for
	field renamings.
	(last_module_changed_p): Delete.
	(set_last_module): Delete.
	(includes_seen): Convert to...
	(diagnostic_context::includes_seen_p): ...this, updating for field
	renamings.
	(diagnostic_report_current_module): Convert to...
	(diagnostic_context::report_current_module): ...this, updating for
	field renamings, and replacing uses of last_module_changed_p and
	set_last_module to simple field accesses.
	(diagnostic_show_any_path): Convert to...
	(diagnostic_context::show_any_path): ...this.
	(diagnostic_classify_diagnostic): Convert to...
	(diagnostic_context::classify_diagnostic): ...this, updating for
	field renamings.
	(diagnostic_push_diagnostics): Convert to...
	(diagnostic_context::push_diagnostics): ...this, updating for field
	renamings.
	(diagnostic_pop_diagnostics): Convert to...
	(diagnostic_context::pop_diagnostics): ...this, updating for field
	renamings.
	(get_any_inlining_info): Convert to...
	(diagnostic_context::get_any_inlining_info): ...this, updating for
	field renamings.
	(update_effective_level_from_pragmas): Convert to...
	(diagnostic_context::update_effective_level_from_pragmas):
	...this, updating for field renamings.
	(print_any_cwe): Convert to...
	(diagnostic_context::print_any_cwe): ...this.
	(print_any_rules): Convert to...
	(diagnostic_context::print_any_rules): ...this.
	(print_option_information): Convert to...
	(diagnostic_context::print_option_information): ...this, updating
	for field renamings.
	(diagnostic_enabled): Convert to...
	(diagnostic_context::diagnostic_enabled): ...this, updating for
	field renamings.
	(warning_enabled_at): Convert to...
	(diagnostic_context::warning_enabled_at): ...this.
	(diagnostic_report_diagnostic): Convert to...
	(diagnostic_context::report_diagnostic): ...this, updating for
	field renamings and conversions to member functions.
	(diagnostic_append_note): Update for field renaming.
	(diagnostic_impl): Use diagnostic_context::report_diagnostic
	directly.
	(diagnostic_n_impl): Likewise.
	(diagnostic_emit_diagram): Convert to...
	(diagnostic_context::emit_diagram): ...this, updating for field
	renamings.
	(error_recursion): Convert to...
	(diagnostic_context::error_recursion): ...this.
	(diagnostic_text_output_format::~diagnostic_text_output_format):
	Use accessor.
	(diagnostics_text_art_charset_init): Convert to...
	(diagnostic_context::set_text_art_charset): ...this.
	(assert_location_text): Update for field renamings.
	* diagnostic.h (enum diagnostic_text_art_charset): Move here from
	diagnostic-text-art.h.
	(struct diagnostic_context): Convert to...
	(class diagnostic_context): ...this.
	(diagnostic_context::ice_handler_callback_t): New typedef.
	(diagnostic_context::set_locations_callback_t): New typedef.
	(diagnostic_context::initialize): New decl.
	(diagnostic_context::color_init): New decl.
	(diagnostic_context::urls_init): New decl.
	(diagnostic_context::file_cache_init): New decl.
	(diagnostic_context::finish): New decl.
	(diagnostic_context::set_set_locations_callback): New.
	(diagnostic_context::initialize_input_context): New decl.
	(diagnostic_context::warning_enabled_at): New decl.
	(diagnostic_context::option_unspecified_p): New.
	(diagnostic_context::report_diagnostic): New decl.
	(diagnostic_context::report_current_module): New decl.
	(diagnostic_context::check_max_errors): New decl.
	(diagnostic_context::action_after_output): New decl.
	(diagnostic_context::classify_diagnostic): New decl.
	(diagnostic_context::push_diagnostics): New decl.
	(diagnostic_context::pop_diagnostics): New decl.
	(diagnostic_context::emit_diagram): New decl.
	(diagnostic_context::set_output_format): New decl.
	(diagnostic_context::set_text_art_charset): New decl.
	(diagnostic_context::set_client_data_hooks): New decl.
	(diagnostic_context::create_edit_context): New decl.
	(diagnostic_context::set_warning_as_error_requested): New.
	(diagnostic_context::set_report_bug): New.
	(diagnostic_context::set_extra_output_kind): New.
	(diagnostic_context::set_show_cwe): New.
	(diagnostic_context::set_show_rules): New.
	(diagnostic_context::set_path_format): New.
	(diagnostic_context::set_show_path_depths): New.
	(diagnostic_context::set_show_option_requested): New.
	(diagnostic_context::set_max_errors): New.
	(diagnostic_context::set_escape_format): New.
	(diagnostic_context::set_ice_handler_callback): New.
	(diagnostic_context::warning_as_error_requested_p): New.
	(diagnostic_context::show_path_depths_p): New.
	(diagnostic_context::get_path_format): New.
	(diagnostic_context::get_escape_format): New.
	(diagnostic_context::get_file_cache): New.
	(diagnostic_context::get_edit_context): New.
	(diagnostic_context::get_client_data_hooks): New.
	(diagnostic_context::get_diagram_theme): New.
	(diagnostic_context::converted_column): New decl.
	(diagnostic_context::diagnostic_count): New.
	(diagnostic_context::includes_seen_p): New decl.
	(diagnostic_context::print_any_cwe): New decl.
	(diagnostic_context::print_any_rules): New decl.
	(diagnostic_context::print_option_information): New decl.
	(diagnostic_context::show_any_path): New decl.
	(diagnostic_context::error_recursion): New decl.
	(diagnostic_context::diagnostic_enabled): New decl.
	(diagnostic_context::get_any_inlining_info): New decl.
	(diagnostic_context::update_effective_level_from_pragmas): New
	decl.
	(diagnostic_context::m_file_cache): Make private.
	(diagnostic_context::diagnostic_count): Rename to...
	(diagnostic_context::m_diagnostic_count): ...this and make
	private.
	(diagnostic_context::warning_as_error_requested): Rename to...
	(diagnostic_context::m_warning_as_error_requested): ...this and
	make private.
	(diagnostic_context::n_opts): Rename to...
	(diagnostic_context::m_n_opts): ...this and make private.
	(diagnostic_context::classify_diagnostic): Rename to...
	(diagnostic_context::m_classify_diagnostic): ...this and make
	private.
	(diagnostic_context::classification_history): Rename to...
	(diagnostic_context::m_classification_history): ...this and make
	private.
	(diagnostic_context::n_classification_history): Rename to...
	(diagnostic_context::m_n_classification_history): ...this and make
	private.
	(diagnostic_context::push_list): Rename to...
	(diagnostic_context::m_push_list): ...this and make private.
	(diagnostic_context::n_push): Rename to...
	(diagnostic_context::m_n_push): ...this and make private.
	(diagnostic_context::show_cwe): Rename to...
	(diagnostic_context::m_show_cwe): ...this and make private.
	(diagnostic_context::show_rules): Rename to...
	(diagnostic_context::m_show_rules): ...this and make private.
	(diagnostic_context::path_format): Rename to...
	(diagnostic_context::m_path_format): ...this and make private.
	(diagnostic_context::show_path_depths): Rename to...
	(diagnostic_context::m_show_path_depths): ...this and make
	private.
	(diagnostic_context::show_option_requested): Rename to...
	(diagnostic_context::m_show_option_requested): ...this and make
	private.
	(diagnostic_context::abort_on_error): Rename to...
	(diagnostic_context::m_abort_on_error): ...this.
	(diagnostic_context::show_column): Rename to...
	(diagnostic_context::m_show_column): ...this.
	(diagnostic_context::pedantic_errors): Rename to...
	(diagnostic_context::m_pedantic_errors): ...this.
	(diagnostic_context::permissive): Rename to...
	(diagnostic_context::m_permissive): ...this.
	(diagnostic_context::opt_permissive): Rename to...
	(diagnostic_context::m_opt_permissive): ...this.
	(diagnostic_context::fatal_errors): Rename to...
	(diagnostic_context::m_fatal_errors): ...this.
	(diagnostic_context::dc_inhibit_warnings): Rename to...
	(diagnostic_context::m_inhibit_warnings): ...this.
	(diagnostic_context::dc_warn_system_headers): Rename to...
	(diagnostic_context::m_warn_system_headers): ...this.
	(diagnostic_context::max_errors): Rename to...
	(diagnostic_context::m_max_errors): ...this and make private.
	(diagnostic_context::internal_error): Rename to...
	(diagnostic_context::m_internal_error): ...this.
	(diagnostic_context::option_enabled): Rename to...
	(diagnostic_context::m_option_enabled): ...this.
	(diagnostic_context::option_state): Rename to...
	(diagnostic_context::m_option_state): ...this.
	(diagnostic_context::option_name): Rename to...
	(diagnostic_context::m_option_name): ...this.
	(diagnostic_context::get_option_url): Rename to...
	(diagnostic_context::m_get_option_url): ...this.
	(diagnostic_context::print_path): Rename to...
	(diagnostic_context::m_print_path): ...this.
	(diagnostic_context::make_json_for_path): Rename to...
	(diagnostic_context::m_make_json_for_path): ...this.
	(diagnostic_context::x_data): Rename to...
	(diagnostic_context::m_client_aux_data): ...this.
	(diagnostic_context::last_location): Rename to...
	(diagnostic_context::m_last_location): ...this.
	(diagnostic_context::last_module): Rename to...
	(diagnostic_context::m_last_module): ...this and make private.
	(diagnostic_context::lock): Rename to...
	(diagnostic_context::m_lock): ...this and make private.
	(diagnostic_context::lang_mask): Rename to...
	(diagnostic_context::m_lang_mask): ...this.
	(diagnostic_context::inhibit_notes_p): Rename to...
	(diagnostic_context::m_inhibit_notes_p): ...this.
	(diagnostic_context::report_bug): Rename to...
	(diagnostic_context::m_report_bug): ...this and make private.
	(diagnostic_context::extra_output_kind): Rename to...
	(diagnostic_context::m_extra_output_kind): ...this and make
	private.
	(diagnostic_context::column_unit): Rename to...
	(diagnostic_context::m_column_unit): ...this and make private.
	(diagnostic_context::column_origin): Rename to...
	(diagnostic_context::m_column_origin): ...this and make private.
	(diagnostic_context::tabstop): Rename to...
	(diagnostic_context::m_tabstop): ...this and make private.
	(diagnostic_context::escape_format): Rename to...
	(diagnostic_context::m_escape_format): ...this and make private.
	(diagnostic_context::edit_context_ptr): Rename to...
	(diagnostic_context::m_edit_context_ptr): ...this and make
	private.
	(diagnostic_context::set_locations_cb): Rename to...
	(diagnostic_context::m_set_locations_cb): ...this and make
	private.
	(diagnostic_context::ice_handler_cb): Rename to...
	(diagnostic_context::m_ice_handler_cb): ...this and make private.
	(diagnostic_context::includes_seen): Rename to...
	(diagnostic_context::m_includes_seen): ...this and make private.
	(diagnostic_inhibit_notes): Update for field renaming.
	(diagnostic_context_auxiliary_data): Likewise.
	(diagnostic_abort_on_error): Convert from macro to inline function
	and update for field renaming.
	(diagnostic_kind_count): Convert from macro to inline function and
	use diagnostic_count accessor.
	(diagnostic_report_warnings_p): Update for field renaming.
	(diagnostic_initialize): Convert decl to inline function calling
	into diagnostic_context.
	(diagnostic_color_init): Likewise.
	(diagnostic_urls_init): Likewise.
	(diagnostic_urls_init): Likewise.
	(diagnostic_finish): Likewise.
	(diagnostic_report_current_module): Likewise.
	(diagnostic_show_any_path): Delete decl.
	(diagnostic_initialize_input_context): Convert decl to inline
	function calling into diagnostic_context.
	(diagnostic_classify_diagnostic): Likewise.
	(diagnostic_push_diagnostics): Likewise.
	(diagnostic_pop_diagnostics): Likewise.
	(diagnostic_report_diagnostic): Likewise.
	(diagnostic_action_after_output): Likewise.
	(diagnostic_check_max_errors): Likewise.
	(diagnostic_file_cache_fini): Delete decl.
	(diagnostic_converted_column): Delete decl.
	(warning_enabled_at): Convert decl to inline function calling into
	diagnostic_context.
	(option_unspecified_p): New.
	(diagnostic_emit_diagram): Delete decl.
	* gcc.cc: Remove include of "diagnostic-text-art.h".
	Update for changes to diagnostic_context.
	* input.cc (diagnostic_file_cache_init): Move implementation
	to...
	(diagnostic_context::file_cache_init): ...this new member
	function.
	(diagnostic_file_cache_fini): Delete.
	(diagnostics_file_cache_forcibly_evict_file): Update for
	m_file_cache becoming private.
	(location_get_source_line): Likewise.
	(get_source_file_content): Likewise.
	(location_missing_trailing_newline): Likewise.
	* input.h (diagnostics_file_cache_fini): Delete.
	* langhooks.cc: Update for changes to diagnostic_context.
	* lto-wrapper.cc: Likewise.
	* opts.cc: Remove include of "diagnostic-text-art.h".
	Update for changes to diagnostic_context.
	* selftest-diagnostic.cc: Update for changes to
	diagnostic_context.
	* toplev.cc: Likewise.
	* tree-diagnostic-path.cc: Likewise.
	* tree-diagnostic.cc: Likewise.

gcc/ada/ChangeLog:
	* gcc-interface/misc.cc: Update for changes to diagnostic_context.

gcc/analyzer/ChangeLog:
	* bounds-checking.cc: Update for changes to diagnostic_context.

gcc/c-family/ChangeLog:
	* c-common.cc: Update for changes to diagnostic_context.
	* c-indentation.cc: Likewise.
	* c-opts.cc: Likewise.
	* c-warn.cc: Likewise.

gcc/cp/ChangeLog:
	* call.cc: Update for changes to diagnostic_context.
	* class.cc: Likewise.
	* decl.cc: Likewise.
	* error.cc: Likewise.
	* except.cc: Likewise.
	* pt.cc: Likewise.

gcc/fortran/ChangeLog:
	* cpp.cc: Update for changes to diagnostic_context.
	* error.cc: Likewise.
	* options.cc: Likewise.

gcc/jit/ChangeLog:
	* jit-playback.cc: Update for changes to diagnostic_context.
	* jit-playback.h: Likewise.

gcc/testsuite/ChangeLog:
	* gcc.dg/plugin/diagnostic_group_plugin.c: Update for changes to
	diagnostic_context.
	* gcc.dg/plugin/diagnostic_plugin_test_text_art.c: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
This commit is contained in:
David Malcolm 2023-11-03 21:46:47 -04:00
parent 38904b732c
commit 8200cd97c9
37 changed files with 849 additions and 687 deletions

View file

@ -336,7 +336,7 @@ internal_error_function (diagnostic_context *context, const char *msgid,
else
{
xloc = expand_location (input_location);
if (context->show_column && xloc.column != 0)
if (context->m_show_column && xloc.column != 0)
loc = xasprintf ("%s:%d:%d", xloc.file, xloc.line, xloc.column);
else
loc = xasprintf ("%s:%d", xloc.file, xloc.line);
@ -375,7 +375,7 @@ gnat_init (void)
line_table->default_range_bits = 0;
/* Register our internal error function. */
global_dc->internal_error = &internal_error_function;
global_dc->m_internal_error = &internal_error_function;
return true;
}

View file

@ -163,7 +163,7 @@ protected:
if (op.get_valid_bits ().empty_p ())
return;
if (const text_art::theme *theme = global_dc->m_diagrams.m_theme)
if (const text_art::theme *theme = global_dc->get_diagram_theme ())
{
text_art::style_manager sm;
text_art::canvas canvas (make_access_diagram (op, sm, *theme, logger));
@ -177,7 +177,7 @@ protected:
(canvas,
/* Alt text. */
_("Diagram visualizing the predicted out-of-bounds access"));
diagnostic_emit_diagram (global_dc, diagram);
global_dc->emit_diagram (diagram);
}
}

View file

@ -6694,7 +6694,7 @@ c_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED,
{
diagnostic_info diagnostic;
diagnostic_t dlevel;
bool save_warn_system_headers = global_dc->dc_warn_system_headers;
bool save_warn_system_headers = global_dc->m_warn_system_headers;
bool ret;
switch (level)
@ -6702,7 +6702,7 @@ c_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED,
case CPP_DL_WARNING_SYSHDR:
if (flag_no_output)
return false;
global_dc->dc_warn_system_headers = 1;
global_dc->m_warn_system_headers = 1;
/* Fall through. */
case CPP_DL_WARNING:
if (flag_no_output)
@ -6738,7 +6738,7 @@ c_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED,
c_option_controlling_cpp_diagnostic (reason));
ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
if (level == CPP_DL_WARNING_SYSHDR)
global_dc->dc_warn_system_headers = save_warn_system_headers;
global_dc->m_warn_system_headers = save_warn_system_headers;
return ret;
}

View file

@ -331,7 +331,7 @@ should_warn_for_misleading_indentation (const token_indent_info &guard_tinfo,
if (guard_loc == body_loc || body_loc == next_stmt_loc)
return false;
const unsigned int tab_width = global_dc->tabstop;
const unsigned int tab_width = global_dc->m_tabstop;
/* They must be in the same file. */
if (next_stmt_exploc.file != body_exploc.file)

View file

@ -186,7 +186,7 @@ void
c_common_diagnostics_set_defaults (diagnostic_context *context)
{
diagnostic_finalizer (context) = c_diagnostic_finalizer;
context->opt_permissive = OPT_fpermissive;
context->m_opt_permissive = OPT_fpermissive;
}
/* Input charset configuration for diagnostics. */
@ -523,7 +523,7 @@ c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
case OPT_fpermissive:
flag_permissive = value;
global_dc->permissive = value;
global_dc->m_permissive = value;
break;
case OPT_fpreprocessed:

View file

@ -1350,9 +1350,9 @@ conversion_warning (location_t loc, tree type, tree expr, tree result)
break;
if (arith_ops
&& global_dc->option_enabled (warnopt,
global_dc->lang_mask,
global_dc->option_state))
&& global_dc->m_option_enabled (warnopt,
global_dc->m_lang_mask,
global_dc->m_option_state))
{
for (int i = 0; i < arith_ops; ++i)
{

View file

@ -1514,10 +1514,6 @@ fdiagnostics-text-art-charset=
Driver Common Joined RejectNegative Var(flag_diagnostics_text_art_charset) Enum(diagnostic_text_art_charset) Init(DIAGNOSTICS_TEXT_ART_CHARSET_EMOJI)
-fdiagnostics-text-art-charset=[none|ascii|unicode|emoji] Determine which characters to use in text arg diagrams.
; Required for these enum values.
SourceInclude
diagnostic-text-art.h
Enum
Name(diagnostic_text_art_charset) Type(int)

View file

@ -156,7 +156,7 @@ struct cl_optimization;
struct cl_option;
struct cl_decoded_option;
struct cl_option_handlers;
struct diagnostic_context;
class diagnostic_context;
class pretty_printer;
class diagnostic_event_id_t;
typedef const char * (*diagnostic_input_charset_callback)(const char *);

View file

@ -13960,9 +13960,9 @@ maybe_warn_dangling_reference (const_tree decl, tree init)
a system header. If the DECL is not in a system header, or if
-Wsystem-headers was provided, warn. */
auto wsh
= make_temp_override (global_dc->dc_warn_system_headers,
= make_temp_override (global_dc->m_warn_system_headers,
(!in_system_header_at (DECL_SOURCE_LOCATION (decl))
|| global_dc->dc_warn_system_headers));
|| global_dc->m_warn_system_headers));
if (tree call = do_warn_dangling_reference (init, /*arg_p=*/false))
{
auto_diagnostic_group d;

View file

@ -9122,7 +9122,7 @@ note_name_declared_in_class (tree name, tree decl)
A name N used in a class S shall refer to the same declaration
in its context and when re-evaluated in the completed scope of
S. */
auto ov = make_temp_override (global_dc->pedantic_errors);
auto ov = make_temp_override (global_dc->m_pedantic_errors);
if (TREE_CODE (decl) == TYPE_DECL
&& TREE_CODE (olddecl) == TYPE_DECL
&& same_type_p (TREE_TYPE (decl), TREE_TYPE (olddecl)))
@ -9131,7 +9131,7 @@ note_name_declared_in_class (tree name, tree decl)
/* Let -fpermissive make it a warning like past versions. */;
else
/* Make it an error. */
global_dc->pedantic_errors = 1;
global_dc->m_pedantic_errors = 1;
if (pedwarn (location_of (decl), OPT_Wchanges_meaning,
"declaration of %q#D changes meaning of %qD",
decl, OVL_NAME (decl)))

View file

@ -18308,9 +18308,9 @@ finish_function (bool inline_p)
&& current_class_ref
&& same_type_ignoring_top_level_qualifiers_p
(TREE_TYPE (valtype), TREE_TYPE (current_class_ref))
&& global_dc->option_enabled (OPT_Wreturn_type,
global_dc->lang_mask,
global_dc->option_state))
&& global_dc->m_option_enabled (OPT_Wreturn_type,
global_dc->m_lang_mask,
global_dc->m_option_state))
add_return_star_this_fixit (&richloc, fndecl);
}
if (cxx_dialect >= cxx14

View file

@ -3636,7 +3636,7 @@ cp_print_error_function (diagnostic_context *context,
pp_newline (context->printer);
if (s.file != NULL)
{
if (context->show_column && s.column != 0)
if (context->m_show_column && s.column != 0)
pp_printf (context->printer,
_(" inlined from %qD at %r%s:%d:%d%R"),
fndecl,
@ -3737,7 +3737,7 @@ print_instantiation_partial_context_line (diagnostic_context *context,
expanded_location xloc = expand_location (loc);
if (context->show_column)
if (context->m_show_column)
pp_verbatim (context->printer, _("%r%s:%d:%d:%R "),
"locus", xloc.file, xloc.line, xloc.column);
else
@ -3816,7 +3816,7 @@ print_instantiation_partial_context (diagnostic_context *context,
{
expanded_location xloc;
xloc = expand_location (loc);
if (context->show_column)
if (context->m_show_column)
pp_verbatim (context->printer,
_("%r%s:%d:%d:%R [ skipping %d instantiation "
"contexts, use -ftemplate-backtrace-limit=0 to "
@ -3876,7 +3876,7 @@ maybe_print_constexpr_context (diagnostic_context *context)
{
expanded_location xloc = expand_location (EXPR_LOCATION (t));
const char *s = expr_as_string (t, 0);
if (context->show_column)
if (context->m_show_column)
pp_verbatim (context->printer,
_("%r%s:%d:%d:%R in %<constexpr%> expansion of %qs"),
"locus", xloc.file, xloc.line, xloc.column, s);
@ -3893,7 +3893,7 @@ static void
print_location (diagnostic_context *context, location_t loc)
{
expanded_location xloc = expand_location (loc);
if (context->show_column)
if (context->m_show_column)
pp_verbatim (context->printer, _("%r%s:%d:%d:%R "),
"locus", xloc.file, xloc.line, xloc.column);
else

View file

@ -1117,9 +1117,9 @@ maybe_noexcept_warning (tree fn)
{
if (TREE_NOTHROW (fn)
&& (!DECL_IN_SYSTEM_HEADER (fn)
|| global_dc->dc_warn_system_headers))
|| global_dc->m_warn_system_headers))
{
auto s = make_temp_override (global_dc->dc_warn_system_headers, true);
auto s = make_temp_override (global_dc->m_warn_system_headers, true);
auto_diagnostic_group d;
if (warning (OPT_Wnoexcept, "noexcept-expression evaluates to %<false%> "
"because of a call to %qD", fn))

View file

@ -30469,7 +30469,7 @@ do_class_deduction (tree ptype, tree tmpl, tree init,
if (fndecl != error_mark_node && !any_dguides_p && (complain & tf_warning))
{
if ((!DECL_IN_SYSTEM_HEADER (fndecl)
|| global_dc->dc_warn_system_headers)
|| global_dc->m_warn_system_headers)
&& warning (OPT_Wctad_maybe_unsupported,
"%qT may not intend to support class template argument "
"deduction", type))

View file

@ -97,7 +97,7 @@ json_from_expanded_location (diagnostic_context *context, location_t loc)
result->set ("file", new json::string (exploc.file));
result->set ("line", new json::integer_number (exploc.line));
const enum diagnostics_column_unit orig_unit = context->column_unit;
const enum diagnostics_column_unit orig_unit = context->m_column_unit;
struct
{
const char *name;
@ -109,15 +109,15 @@ json_from_expanded_location (diagnostic_context *context, location_t loc)
int the_column = INT_MIN;
for (int i = 0; i != ARRAY_SIZE (column_fields); ++i)
{
context->column_unit = column_fields[i].unit;
const int col = diagnostic_converted_column (context, exploc);
context->m_column_unit = column_fields[i].unit;
const int col = context->converted_column (exploc);
result->set (column_fields[i].name, new json::integer_number (col));
if (column_fields[i].unit == orig_unit)
the_column = col;
}
gcc_assert (the_column != INT_MIN);
result->set ("column", new json::integer_number (the_column));
context->column_unit = orig_unit;
context->m_column_unit = orig_unit;
return result;
}
@ -220,18 +220,18 @@ json_output_format::on_end_diagnostic (diagnostic_info *diagnostic,
pp_clear_output_area (m_context.printer);
char *option_text;
option_text = m_context.option_name (&m_context, diagnostic->option_index,
orig_diag_kind, diagnostic->kind);
option_text = m_context.m_option_name (&m_context, diagnostic->option_index,
orig_diag_kind, diagnostic->kind);
if (option_text)
{
diag_obj->set ("option", new json::string (option_text));
free (option_text);
}
if (m_context.get_option_url)
if (m_context.m_get_option_url)
{
char *option_url = m_context.get_option_url (&m_context,
diagnostic->option_index);
char *option_url = m_context.m_get_option_url (&m_context,
diagnostic->option_index);
if (option_url)
{
diag_obj->set ("option_url", new json::string (option_url));
@ -255,7 +255,7 @@ json_output_format::on_end_diagnostic (diagnostic_info *diagnostic,
m_cur_children_array = new json::array ();
diag_obj->set ("children", m_cur_children_array);
diag_obj->set ("column-origin",
new json::integer_number (m_context.column_origin));
new json::integer_number (m_context.m_column_origin));
}
const rich_location *richloc = diagnostic->richloc;
@ -296,9 +296,10 @@ json_output_format::on_end_diagnostic (diagnostic_info *diagnostic,
}
const diagnostic_path *path = richloc->get_path ();
if (path && m_context.make_json_for_path)
if (path && m_context.m_make_json_for_path)
{
json::value *path_value = m_context.make_json_for_path (&m_context, path);
json::value *path_value
= m_context.m_make_json_for_path (&m_context, path);
diag_obj->set ("path", path_value);
}
@ -359,14 +360,14 @@ static void
diagnostic_output_format_init_json (diagnostic_context *context)
{
/* Override callbacks. */
context->print_path = NULL; /* handled in json_end_diagnostic. */
context->m_print_path = nullptr; /* handled in json_end_diagnostic. */
/* The metadata is handled in JSON format, rather than as text. */
context->show_cwe = false;
context->show_rules = false;
context->set_show_cwe (false);
context->set_show_rules (false);
/* The option is handled in JSON format, rather than as text. */
context->show_option_requested = false;
context->set_show_option_requested (false);
/* Don't colorize the text. */
pp_show_color (context->printer) = false;
@ -378,8 +379,7 @@ void
diagnostic_output_format_init_json_stderr (diagnostic_context *context)
{
diagnostic_output_format_init_json (context);
delete context->m_output_format;
context->m_output_format = new json_stderr_output_format (*context);
context->set_output_format (new json_stderr_output_format (*context));
}
/* Populate CONTEXT in preparation for JSON output to a file named
@ -390,9 +390,8 @@ diagnostic_output_format_init_json_file (diagnostic_context *context,
const char *base_file_name)
{
diagnostic_output_format_init_json (context);
delete context->m_output_format;
context->m_output_format = new json_file_output_format (*context,
base_file_name);
context->set_output_format (new json_file_output_format (*context,
base_file_name));
}
#if CHECKING_P

View file

@ -296,8 +296,8 @@ sarif_invocation::prepare_to_flush (diagnostic_context *context)
/* Call client hook, allowing it to create a custom property bag for
this object (SARIF v2.1.0 section 3.8) e.g. for recording time vars. */
if (context->m_client_data_hooks)
context->m_client_data_hooks->add_sarif_invocation_properties (*this);
if (auto client_data_hooks = context->get_client_data_hooks ())
client_data_hooks->add_sarif_invocation_properties (*this);
}
/* class sarif_result : public sarif_object. */
@ -408,7 +408,7 @@ sarif_builder::sarif_builder (diagnostic_context *context)
m_seen_any_relative_paths (false),
m_rule_id_set (),
m_rules_arr (new json::array ()),
m_tabstop (context->tabstop)
m_tabstop (context->m_tabstop)
{
}
@ -536,8 +536,8 @@ sarif_builder::make_result_object (diagnostic_context *context,
/* "ruleId" property (SARIF v2.1.0 section 3.27.5). */
/* Ideally we'd have an option_name for these. */
if (char *option_text
= context->option_name (context, diagnostic->option_index,
orig_diag_kind, diagnostic->kind))
= context->m_option_name (context, diagnostic->option_index,
orig_diag_kind, diagnostic->kind))
{
/* Lazily create reportingDescriptor objects for and add to m_rules_arr.
Set ruleId referencing them. */
@ -639,10 +639,10 @@ make_reporting_descriptor_object_for_warning (diagnostic_context *context,
it seems redundant compared to "id". */
/* "helpUri" property (SARIF v2.1.0 section 3.49.12). */
if (context->get_option_url)
if (context->m_get_option_url)
{
char *option_url
= context->get_option_url (context, diagnostic->option_index);
= context->m_get_option_url (context, diagnostic->option_index);
if (option_url)
{
reporting_desc->set ("helpUri", new json::string (option_url));
@ -730,9 +730,8 @@ sarif_builder::make_locations_arr (diagnostic_info *diagnostic)
{
json::array *locations_arr = new json::array ();
const logical_location *logical_loc = NULL;
if (m_context->m_client_data_hooks)
logical_loc
= m_context->m_client_data_hooks->get_current_logical_location ();
if (auto client_data_hooks = m_context->get_client_data_hooks ())
logical_loc = client_data_hooks->get_current_logical_location ();
json::object *location_obj
= make_location_object (*diagnostic->richloc, logical_loc);
@ -1361,9 +1360,9 @@ sarif_builder::make_tool_object () const
/* Report plugins via the "extensions" property
(SARIF v2.1.0 section 3.18.3). */
if (m_context->m_client_data_hooks)
if (auto client_data_hooks = m_context->get_client_data_hooks ())
if (const client_version_info *vinfo
= m_context->m_client_data_hooks->get_any_version_info ())
= client_data_hooks->get_any_version_info ())
{
class my_plugin_visitor : public client_version_info :: plugin_visitor
{
@ -1414,9 +1413,9 @@ sarif_builder::make_driver_tool_component_object () const
{
json::object *driver_obj = new json::object ();
if (m_context->m_client_data_hooks)
if (auto client_data_hooks = m_context->get_client_data_hooks ())
if (const client_version_info *vinfo
= m_context->m_client_data_hooks->get_any_version_info ())
= client_data_hooks->get_any_version_info ())
{
/* "name" property (SARIF v2.1.0 section 3.19.8). */
if (const char *name = vinfo->get_tool_name ())
@ -1525,10 +1524,9 @@ sarif_builder::make_artifact_object (const char *filename)
artifact_obj->set ("contents", artifact_content_obj);
/* "sourceLanguage" property (SARIF v2.1.0 section 3.24.10). */
if (m_context->m_client_data_hooks)
if (auto client_data_hooks = m_context->get_client_data_hooks ())
if (const char *source_lang
= m_context->m_client_data_hooks->maybe_get_sarif_source_language
(filename))
= client_data_hooks->maybe_get_sarif_source_language (filename))
artifact_obj->set ("sourceLanguage", new json::string (source_lang));
return artifact_obj;
@ -1542,7 +1540,7 @@ sarif_builder::maybe_make_artifact_content_object (const char *filename) const
{
/* Let input.cc handle any charset conversion. */
char_span utf8_content
= m_context->m_file_cache->get_source_file_content (filename);
= m_context->get_file_cache ()->get_source_file_content (filename);
if (!utf8_content)
return NULL;
@ -1570,7 +1568,7 @@ sarif_builder::get_source_lines (const char *filename,
for (int line = start_line; line <= end_line; line++)
{
char_span line_content
= m_context->m_file_cache->get_source_line (filename, line);
= m_context->get_file_cache ()->get_source_line (filename, line);
if (!line_content.get_buffer ())
return NULL;
result.reserve (line_content.length () + 1);
@ -1791,15 +1789,15 @@ static void
diagnostic_output_format_init_sarif (diagnostic_context *context)
{
/* Override callbacks. */
context->print_path = NULL; /* handled in sarif_end_diagnostic. */
context->ice_handler_cb = sarif_ice_handler;
context->m_print_path = nullptr; /* handled in sarif_end_diagnostic. */
context->set_ice_handler_callback (sarif_ice_handler);
/* The metadata is handled in SARIF format, rather than as text. */
context->show_cwe = false;
context->show_rules = false;
context->set_show_cwe (false);
context->set_show_rules (false);
/* The option is handled in SARIF format, rather than as text. */
context->show_option_requested = false;
context->set_show_option_requested (false);
/* Don't colorize the text. */
pp_show_color (context->printer) = false;
@ -1811,8 +1809,8 @@ void
diagnostic_output_format_init_sarif_stderr (diagnostic_context *context)
{
diagnostic_output_format_init_sarif (context);
delete context->m_output_format;
context->m_output_format = new sarif_stream_output_format (*context, stderr);
context->set_output_format (new sarif_stream_output_format (*context,
stderr));
}
/* Populate CONTEXT in preparation for SARIF output to a file named
@ -1823,9 +1821,8 @@ diagnostic_output_format_init_sarif_file (diagnostic_context *context,
const char *base_file_name)
{
diagnostic_output_format_init_sarif (context);
delete context->m_output_format;
context->m_output_format = new sarif_file_output_format (*context,
base_file_name);
context->set_output_format (new sarif_file_output_format (*context,
base_file_name));
}
/* Populate CONTEXT in preparation for SARIF output to STREAM. */
@ -1835,7 +1832,6 @@ diagnostic_output_format_init_sarif_stream (diagnostic_context *context,
FILE *stream)
{
diagnostic_output_format_init_sarif (context);
delete context->m_output_format;
context->m_output_format = new sarif_stream_output_format (*context,
stream);
context->set_output_format (new sarif_stream_output_format (*context,
stream));
}

View file

@ -1146,14 +1146,14 @@ make_policy (const diagnostic_context &dc,
{
/* The default is to not escape non-ASCII bytes. */
char_display_policy result
(dc.tabstop, cpp_wcwidth, default_print_decoded_ch);
(dc.m_tabstop, cpp_wcwidth, default_print_decoded_ch);
/* If the diagnostic suggests escaping non-ASCII bytes, then
use policy from user-supplied options. */
if (richloc.escape_on_output_p ())
{
result.m_undecoded_byte_width = width_per_escaped_byte;
switch (dc.escape_format)
switch (dc.get_escape_format ())
{
default:
gcc_unreachable ();
@ -2849,13 +2849,13 @@ diagnostic_show_locus (diagnostic_context * context,
/* Don't print the same source location twice in a row, unless we have
fix-it hints, or multiple locations, or a label. */
if (loc == context->last_location
if (loc == context->m_last_location
&& richloc->get_num_fixit_hints () == 0
&& richloc->get_num_locations () == 1
&& richloc->get_range (0)->m_label == NULL)
return;
context->last_location = loc;
context->m_last_location = loc;
layout layout (context, richloc, diagnostic_kind, pp);
for (int line_span_idx = 0; line_span_idx < layout.get_num_line_spans ();
@ -2924,7 +2924,7 @@ test_display_widths ()
{
test_diagnostic_context dc;
dc.escape_format = DIAGNOSTICS_ESCAPE_FORMAT_UNICODE;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
char_display_policy policy (make_policy (dc, richloc));
ASSERT_EQ (cpp_display_width (pi, strlen (pi), policy), 8);
ASSERT_EQ (cpp_display_width (emoji, strlen (emoji), policy), 9);
@ -2936,7 +2936,7 @@ test_display_widths ()
{
test_diagnostic_context dc;
dc.escape_format = DIAGNOSTICS_ESCAPE_FORMAT_BYTES;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
char_display_policy policy (make_policy (dc, richloc));
ASSERT_EQ (cpp_display_width (pi, strlen (pi), policy), 8);
ASSERT_EQ (cpp_display_width (emoji, strlen (emoji), policy), 16);
@ -3185,7 +3185,7 @@ test_layout_x_offset_display_tab (const line_table_case &case_)
for (int tabstop = 1; tabstop != num_tabstops; ++tabstop)
{
test_diagnostic_context dc;
dc.tabstop = tabstop;
dc.m_tabstop = tabstop;
layout test_layout (&dc, &richloc, DK_ERROR);
test_layout.print_line (1);
const char *out = pp_formatted_text (dc.printer);
@ -3203,7 +3203,7 @@ test_layout_x_offset_display_tab (const line_table_case &case_)
for (int tabstop = 1; tabstop != num_tabstops; ++tabstop)
{
test_diagnostic_context dc;
dc.tabstop = tabstop;
dc.m_tabstop = tabstop;
static const int small_width = 24;
dc.m_source_printing.max_width = small_width - 4;
dc.m_source_printing.min_margin_width
@ -4321,7 +4321,7 @@ test_one_liner_labels_utf8 ()
{
test_diagnostic_context dc;
dc.escape_format = DIAGNOSTICS_ESCAPE_FORMAT_UNICODE;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
diagnostic_show_locus (&dc, &richloc, DK_ERROR);
ASSERT_STREQ (" <U+1F602>_foo = <U+03C0>_bar.<U+1F602>_field<U+03C0>;\n"
" ^~~~~~~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~\n"
@ -4333,7 +4333,7 @@ test_one_liner_labels_utf8 ()
}
{
test_diagnostic_context dc;
dc.escape_format = DIAGNOSTICS_ESCAPE_FORMAT_BYTES;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
diagnostic_show_locus (&dc, &richloc, DK_ERROR);
ASSERT_STREQ
(" <f0><9f><98><82>_foo = <cf><80>_bar.<f0><9f><98><82>_field<cf><80>;\n"
@ -5517,7 +5517,7 @@ test_tab_expansion (const line_table_case &case_)
everything too. */
{
test_diagnostic_context dc;
dc.tabstop = tabstop;
dc.m_tabstop = tabstop;
rich_location richloc (line_table,
linemap_position_for_column (line_table,
first_non_ws_byte_col));
@ -5532,7 +5532,7 @@ test_tab_expansion (const line_table_case &case_)
as well. */
{
test_diagnostic_context dc;
dc.tabstop = tabstop;
dc.m_tabstop = tabstop;
rich_location richloc (line_table,
linemap_position_for_column (line_table,
right_quote_byte_col));
@ -5583,7 +5583,7 @@ test_escaping_bytes_1 (const line_table_case &case_)
richloc.set_escape_on_output (true);
{
test_diagnostic_context dc;
dc.escape_format = DIAGNOSTICS_ESCAPE_FORMAT_UNICODE;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
diagnostic_show_locus (&dc, &richloc, DK_ERROR);
ASSERT_STREQ
(" before<U+0000><U+0001><U+0002><U+0003><U+000B><80><ff>after\n"
@ -5592,7 +5592,7 @@ test_escaping_bytes_1 (const line_table_case &case_)
}
{
test_diagnostic_context dc;
dc.escape_format = DIAGNOSTICS_ESCAPE_FORMAT_BYTES;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
diagnostic_show_locus (&dc, &richloc, DK_ERROR);
ASSERT_STREQ (" before<00><01><02><03><0b><80><ff>after\n"
" ^~~~ ~~~~\n",
@ -5636,7 +5636,7 @@ test_escaping_bytes_2 (const line_table_case &case_)
richloc.set_escape_on_output (true);
{
test_diagnostic_context dc;
dc.escape_format = DIAGNOSTICS_ESCAPE_FORMAT_UNICODE;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
diagnostic_show_locus (&dc, &richloc, DK_ERROR);
ASSERT_STREQ (" <U+0000>after\n"
" ^~~~~~~~\n",
@ -5644,7 +5644,7 @@ test_escaping_bytes_2 (const line_table_case &case_)
}
{
test_diagnostic_context dc;
dc.escape_format = DIAGNOSTICS_ESCAPE_FORMAT_BYTES;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
diagnostic_show_locus (&dc, &richloc, DK_ERROR);
ASSERT_STREQ (" <00>after\n"
" ^~~~\n",

View file

@ -1,49 +0,0 @@
/* Copyright (C) 2023 Free Software Foundation, Inc.
Contributed by David Malcolm <dmalcolm@redhat.com>.
This file is part of GCC.
GCC 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.
GCC 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 GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#ifndef GCC_DIAGNOSTIC_TEXT_ART_H
#define GCC_DIAGNOSTIC_TEXT_ART_H
/* Values for -fdiagnostics-text-art-charset=. */
enum diagnostic_text_art_charset
{
/* No text art diagrams shall be emitted. */
DIAGNOSTICS_TEXT_ART_CHARSET_NONE,
/* Use pure ASCII for text art diagrams. */
DIAGNOSTICS_TEXT_ART_CHARSET_ASCII,
/* Use ASCII + conservative use of other unicode characters
in text art diagrams. */
DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE,
/* Use Emoji. */
DIAGNOSTICS_TEXT_ART_CHARSET_EMOJI
};
const enum diagnostic_text_art_charset DIAGNOSTICS_TEXT_ART_CHARSET_DEFAULT
= DIAGNOSTICS_TEXT_ART_CHARSET_EMOJI;
extern void
diagnostics_text_art_charset_init (diagnostic_context *context,
enum diagnostic_text_art_charset charset);
#endif /* ! GCC_DIAGNOSTIC_TEXT_ART_H */

File diff suppressed because it is too large Load diff

View file

@ -110,6 +110,24 @@ enum diagnostics_extra_output_kind
EXTRA_DIAGNOSTIC_OUTPUT_fixits_v2
};
/* Values for -fdiagnostics-text-art-charset=. */
enum diagnostic_text_art_charset
{
/* No text art diagrams shall be emitted. */
DIAGNOSTICS_TEXT_ART_CHARSET_NONE,
/* Use pure ASCII for text art diagrams. */
DIAGNOSTICS_TEXT_ART_CHARSET_ASCII,
/* Use ASCII + conservative use of other unicode characters
in text art diagrams. */
DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE,
/* Use Emoji. */
DIAGNOSTICS_TEXT_ART_CHARSET_EMOJI
};
/* A diagnostic is described by the MESSAGE to send, the FILE and LINE of
its context and its KIND (ice, error, warning, note, ...) See complete
list in diagnostic.def. */
@ -224,29 +242,163 @@ public:
/* This data structure bundles altogether any information relevant to
the context of a diagnostic message. */
struct diagnostic_context
class diagnostic_context
{
public:
typedef void (*ice_handler_callback_t) (diagnostic_context *);
typedef void (*set_locations_callback_t) (diagnostic_context *,
diagnostic_info *);
void initialize (int n_opts);
void color_init (int value);
void urls_init (int value);
void file_cache_init ();
void finish ();
void set_set_locations_callback (set_locations_callback_t cb)
{
m_set_locations_cb = cb;
}
void
initialize_input_context (diagnostic_input_charset_callback ccb,
bool should_skip_bom);
void begin_group ();
void end_group ();
public:
bool warning_enabled_at (location_t loc, int opt);
bool option_unspecified_p (int opt) const
{
gcc_assert (opt < m_n_opts);
return m_classify_diagnostic[opt] == DK_UNSPECIFIED;
}
bool report_diagnostic (diagnostic_info *);
void report_current_module (location_t where);
void check_max_errors (bool flush);
void action_after_output (diagnostic_t diag_kind);
diagnostic_t
classify_diagnostic (int option_index,
diagnostic_t new_kind,
location_t where);
void push_diagnostics (location_t where ATTRIBUTE_UNUSED);
void pop_diagnostics (location_t where);
void emit_diagram (const diagnostic_diagram &diagram);
/* Various setters for use by option-handling logic. */
void set_output_format (diagnostic_output_format *output_format);
void set_text_art_charset (enum diagnostic_text_art_charset charset);
void set_client_data_hooks (diagnostic_client_data_hooks *hooks);
void create_edit_context ();
void set_warning_as_error_requested (bool val)
{
m_warning_as_error_requested = val;
}
void set_report_bug (bool val) { m_report_bug = val; }
void set_extra_output_kind (enum diagnostics_extra_output_kind kind)
{
m_extra_output_kind = kind;
}
void set_show_cwe (bool val) { m_show_cwe = val; }
void set_show_rules (bool val) { m_show_rules = val; }
void set_path_format (enum diagnostic_path_format val)
{
m_path_format = val;
}
void set_show_path_depths (bool val) { m_show_path_depths = val; }
void set_show_option_requested (bool val) { m_show_option_requested = val; }
void set_max_errors (int val) { m_max_errors = val; }
void set_escape_format (enum diagnostics_escape_format val)
{
m_escape_format = val;
}
void set_ice_handler_callback (ice_handler_callback_t cb)
{
m_ice_handler_cb = cb;
}
/* Various accessors. */
bool warning_as_error_requested_p () const
{
return m_warning_as_error_requested;
}
bool show_path_depths_p () const { return m_show_path_depths; }
enum diagnostic_path_format get_path_format () const { return m_path_format; }
enum diagnostics_escape_format get_escape_format () const
{
return m_escape_format;
}
file_cache *
get_file_cache () const
{
return m_file_cache;
}
edit_context *get_edit_context () const
{
return m_edit_context_ptr;
}
const diagnostic_client_data_hooks *get_client_data_hooks ()
{
return m_client_data_hooks;
}
text_art::theme *get_diagram_theme () const { return m_diagrams.m_theme; }
int converted_column (expanded_location s) const;
int &diagnostic_count (diagnostic_t kind)
{
return m_diagnostic_count[kind];
}
private:
bool includes_seen_p (const line_map_ordinary *map);
void print_any_cwe (const diagnostic_info &diagnostic);
void print_any_rules (const diagnostic_info &diagnostic);
void print_option_information (const diagnostic_info &diagnostic,
diagnostic_t orig_diag_kind);
void show_any_path (const diagnostic_info &diagnostic);
void error_recursion () ATTRIBUTE_NORETURN;
bool diagnostic_enabled (diagnostic_info *diagnostic);
void get_any_inlining_info (diagnostic_info *diagnostic);
diagnostic_t
update_effective_level_from_pragmas (diagnostic_info *diagnostic);
/* Data members.
Ideally, all of these would be private and have "m_" prefixes. */
public:
/* Where most of the diagnostic formatting work is done. */
pretty_printer *printer;
private:
/* Cache of source code. */
file_cache *m_file_cache;
/* The number of times we have issued diagnostics. */
int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND];
int m_diagnostic_count[DK_LAST_DIAGNOSTIC_KIND];
/* True if it has been requested that warnings be treated as errors. */
bool warning_as_error_requested;
bool m_warning_as_error_requested;
/* The number of option indexes that can be passed to warning() et
al. */
int n_opts;
int m_n_opts;
/* For each option index that can be passed to warning() et al
(OPT_* from options.h when using this code with the core GCC
@ -254,67 +406,70 @@ public:
should be changed to before reporting, or DK_UNSPECIFIED to leave
it as the reported kind, or DK_IGNORED to not report it at
all. */
diagnostic_t *classify_diagnostic;
diagnostic_t *m_classify_diagnostic;
/* History of all changes to the classifications above. This list
is stored in location-order, so we can search it, either
binary-wise or end-to-front, to find the most recent
classification for a given diagnostic, given the location of the
diagnostic. */
diagnostic_classification_change_t *classification_history;
diagnostic_classification_change_t *m_classification_history;
/* The size of the above array. */
int n_classification_history;
int m_n_classification_history;
/* For pragma push/pop. */
int *push_list;
int n_push;
int *m_push_list;
int m_n_push;
/* True if we should print any CWE identifiers associated with
diagnostics. */
bool show_cwe;
bool m_show_cwe;
/* True if we should print any rules associated with diagnostics. */
bool show_rules;
bool m_show_rules;
/* How should diagnostic_path objects be printed. */
enum diagnostic_path_format path_format;
enum diagnostic_path_format m_path_format;
/* True if we should print stack depths when printing diagnostic paths. */
bool show_path_depths;
bool m_show_path_depths;
/* True if we should print the command line option which controls
each diagnostic, if known. */
bool show_option_requested;
bool m_show_option_requested;
public:
/* True if we should raise a SIGABRT on errors. */
bool abort_on_error;
bool m_abort_on_error;
/* True if we should show the column number on diagnostics. */
bool show_column;
bool m_show_column;
/* True if pedwarns are errors. */
bool pedantic_errors;
bool m_pedantic_errors;
/* True if permerrors are warnings. */
bool permissive;
bool m_permissive;
/* The index of the option to associate with turning permerrors into
warnings. */
int opt_permissive;
int m_opt_permissive;
/* True if errors are fatal. */
bool fatal_errors;
bool m_fatal_errors;
/* True if all warnings should be disabled. */
bool dc_inhibit_warnings;
bool m_inhibit_warnings;
/* True if warnings should be given in system headers. */
bool dc_warn_system_headers;
bool m_warn_system_headers;
private:
/* Maximum number of errors to report. */
int max_errors;
int m_max_errors;
public:
/* Client-supplied callbacks for use in text output. */
struct {
/* This function is called before any message is printed out. It is
@ -336,15 +491,15 @@ public:
} m_text_callbacks;
/* Client hook to report an internal error. */
void (*internal_error) (diagnostic_context *, const char *, va_list *);
void (*m_internal_error) (diagnostic_context *, const char *, va_list *);
/* Client hook to say whether the option controlling a diagnostic is
enabled. Returns nonzero if enabled, zero if disabled. */
int (*option_enabled) (int, unsigned, void *);
int (*m_option_enabled) (int, unsigned, void *);
/* Client information to pass as second argument to
option_enabled. */
void *option_state;
void *m_option_state;
/* Client hook to return the name of an option that controls a
diagnostic. Returns malloced memory. The first diagnostic_t
@ -352,33 +507,39 @@ public:
(of warnings as errors, etc.); the second is the kind after any
reclassification. May return NULL if no name is to be printed.
May be passed 0 as well as the index of a particular option. */
char *(*option_name) (diagnostic_context *, int, diagnostic_t, diagnostic_t);
char *(*m_option_name) (diagnostic_context *,
int,
diagnostic_t,
diagnostic_t);
/* Client hook to return a URL describing the option that controls
a diagnostic. Returns malloced memory. May return NULL if no URL
is available. May be passed 0 as well as the index of a
particular option. */
char *(*get_option_url) (diagnostic_context *, int);
char *(*m_get_option_url) (diagnostic_context *, int);
void (*print_path) (diagnostic_context *, const diagnostic_path *);
json::value *(*make_json_for_path) (diagnostic_context *, const diagnostic_path *);
void (*m_print_path) (diagnostic_context *, const diagnostic_path *);
json::value *(*m_make_json_for_path) (diagnostic_context *,
const diagnostic_path *);
/* Auxiliary data for client. */
void *x_data;
void *m_client_aux_data;
/* Used to detect that the last caret was printed at the same location. */
location_t last_location;
location_t m_last_location;
private:
/* Used to detect when the input file stack has changed since last
described. */
const line_map_ordinary *last_module;
const line_map_ordinary *m_last_module;
int lock;
int m_lock;
public:
/* A copy of lang_hooks.option_lang_mask (). */
unsigned lang_mask;
unsigned m_lang_mask;
bool inhibit_notes_p;
bool m_inhibit_notes_p;
/* Fields relating to printing the user's source code (potentially with
a margin, underlining, labels, etc). */
@ -424,30 +585,33 @@ public:
} m_source_printing;
private:
/* True if -freport-bug option is used. */
bool report_bug;
bool m_report_bug;
/* Used to specify additional diagnostic output to be emitted after the
rest of the diagnostic. This is for implementing
-fdiagnostics-parseable-fixits and GCC_EXTRA_DIAGNOSTIC_OUTPUT. */
enum diagnostics_extra_output_kind extra_output_kind;
enum diagnostics_extra_output_kind m_extra_output_kind;
public:
/* What units to use when outputting the column number. */
enum diagnostics_column_unit column_unit;
enum diagnostics_column_unit m_column_unit;
/* The origin for the column number (1-based or 0-based typically). */
int column_origin;
int m_column_origin;
/* The size of the tabstop for tab expansion. */
int tabstop;
int m_tabstop;
private:
/* How should non-ASCII/non-printable bytes be escaped when
a diagnostic suggests escaping the source code on output. */
enum diagnostics_escape_format escape_format;
enum diagnostics_escape_format m_escape_format;
/* If non-NULL, an edit_context to which fix-it hints should be
applied, for generating patches. */
edit_context *edit_context_ptr;
edit_context *m_edit_context_ptr;
/* Fields relating to diagnostic groups. */
struct {
@ -467,14 +631,14 @@ public:
stack corresponding to a diagnostic location. Needed to traverse
the BLOCK_SUPERCONTEXT() chain hanging off the LOCATION_BLOCK()
of a diagnostic's location. */
void (*set_locations_cb)(diagnostic_context *, diagnostic_info *);
set_locations_callback_t m_set_locations_cb;
/* Optional callback for attempting to handle ICEs gracefully. */
void (*ice_handler_cb) (diagnostic_context *context);
ice_handler_callback_t m_ice_handler_cb;
/* Include files that diagnostic_report_current_module has already listed the
include path for. */
hash_set<location_t, false, location_hash> *includes_seen;
hash_set<location_t, false, location_hash> *m_includes_seen;
/* A bundle of hooks for providing data to the context about its client
e.g. version information, plugins, etc.
@ -495,7 +659,7 @@ public:
inline void
diagnostic_inhibit_notes (diagnostic_context * context)
{
context->inhibit_notes_p = true;
context->m_inhibit_notes_p = true;
}
@ -508,7 +672,7 @@ diagnostic_inhibit_notes (diagnostic_context * context)
#define diagnostic_finalizer(DC) (DC)->m_text_callbacks.end_diagnostic
/* Extension hooks for client. */
#define diagnostic_context_auxiliary_data(DC) (DC)->x_data
#define diagnostic_context_auxiliary_data(DC) (DC)->m_client_aux_data
#define diagnostic_info_auxiliary_data(DI) (DI)->x_data
/* Same as pp_format_decoder. Works on 'diagnostic_context *'. */
@ -518,8 +682,11 @@ diagnostic_inhibit_notes (diagnostic_context * context)
#define diagnostic_prefixing_rule(DC) ((DC)->printer->wrapping.rule)
/* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher. */
#define diagnostic_abort_on_error(DC) \
(DC)->abort_on_error = true
inline void
diagnostic_abort_on_error (diagnostic_context *context)
{
context->m_abort_on_error = true;
}
/* This diagnostic_context is used by front-ends that directly output
diagnostic messages without going through `error', `warning',
@ -531,7 +698,13 @@ extern diagnostic_context *global_dc;
#define diagnostic_ready_p() (global_dc->printer != NULL)
/* The total count of a KIND of diagnostics emitted so far. */
#define diagnostic_kind_count(DC, DK) (DC)->diagnostic_count[(int) (DK)]
inline int &
diagnostic_kind_count (diagnostic_context *context,
diagnostic_t kind)
{
return context->diagnostic_count (kind);
}
/* The number of errors that have been issued so far. Ideally, these
would take a diagnostic_context as an argument. */
@ -545,8 +718,8 @@ extern diagnostic_context *global_dc;
/* Returns nonzero if warnings should be emitted. */
#define diagnostic_report_warnings_p(DC, LOC) \
(!(DC)->dc_inhibit_warnings \
&& !(in_system_header_at (LOC) && !(DC)->dc_warn_system_headers))
(!(DC)->m_inhibit_warnings \
&& !(in_system_header_at (LOC) && !(DC)->m_warn_system_headers))
/* Override the option index to be used for reporting a
diagnostic. */
@ -558,16 +731,42 @@ diagnostic_override_option_index (diagnostic_info *info, int optidx)
}
/* Diagnostic related functions. */
extern void diagnostic_initialize (diagnostic_context *, int);
extern void diagnostic_color_init (diagnostic_context *, int value = -1);
extern void diagnostic_urls_init (diagnostic_context *, int value = -1);
extern void diagnostic_finish (diagnostic_context *);
extern void diagnostic_report_current_module (diagnostic_context *, location_t);
inline void
diagnostic_initialize (diagnostic_context *context, int n_opts)
{
context->initialize (n_opts);
}
inline void
diagnostic_color_init (diagnostic_context *context, int value = -1)
{
context->color_init (value);
}
inline void
diagnostic_urls_init (diagnostic_context *context, int value = -1)
{
context->urls_init (value);
}
inline void
diagnostic_finish (diagnostic_context *context)
{
context->finish ();
}
inline void
diagnostic_report_current_module (diagnostic_context *context,
location_t where)
{
context->report_current_module (where);
}
extern void diagnostic_show_locus (diagnostic_context *,
rich_location *richloc,
diagnostic_t diagnostic_kind,
pretty_printer *pp = nullptr);
extern void diagnostic_show_any_path (diagnostic_context *, diagnostic_info *);
/* Because we read source files a second time after the frontend did it the
first time, we need to know how the frontend handled things like character
@ -584,19 +783,51 @@ extern void diagnostic_show_any_path (diagnostic_context *, diagnostic_info *);
beginning of the file. (In case a conversion was performed, the BOM is
rather skipped as part of the conversion process.) */
void diagnostic_initialize_input_context (diagnostic_context *context,
diagnostic_input_charset_callback ccb,
bool should_skip_bom);
inline void
diagnostic_initialize_input_context (diagnostic_context *context,
diagnostic_input_charset_callback ccb,
bool should_skip_bom)
{
context->initialize_input_context (ccb, should_skip_bom);
}
/* Force diagnostics controlled by OPTIDX to be kind KIND. */
extern diagnostic_t diagnostic_classify_diagnostic (diagnostic_context *,
int /* optidx */,
diagnostic_t /* kind */,
location_t);
extern void diagnostic_push_diagnostics (diagnostic_context *, location_t);
extern void diagnostic_pop_diagnostics (diagnostic_context *, location_t);
extern bool diagnostic_report_diagnostic (diagnostic_context *,
diagnostic_info *);
inline diagnostic_t
diagnostic_classify_diagnostic (diagnostic_context *context,
int optidx,
diagnostic_t kind,
location_t where)
{
return context->classify_diagnostic (optidx, kind, where);
}
inline void
diagnostic_push_diagnostics (diagnostic_context *context,
location_t where)
{
context->push_diagnostics (where);
}
inline void
diagnostic_pop_diagnostics (diagnostic_context *context,
location_t where)
{
context->pop_diagnostics (where);
}
/* Report a diagnostic message (an error or a warning) as specified by
DC. This function is *the* subroutine in terms of which front-ends
should implement their specific diagnostic handling modules. The
front-end independent format specifiers are exactly those described
in the documentation of output_format.
Return true if a diagnostic was printed, false otherwise. */
inline bool
diagnostic_report_diagnostic (diagnostic_context *context,
diagnostic_info *diagnostic)
{
return context->report_diagnostic (diagnostic);
}
#ifdef ATTRIBUTE_GCC_DIAG
extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *,
rich_location *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0);
@ -614,10 +845,19 @@ void default_diagnostic_start_span_fn (diagnostic_context *,
void default_diagnostic_finalizer (diagnostic_context *, diagnostic_info *,
diagnostic_t);
void diagnostic_set_caret_max_width (diagnostic_context *context, int value);
void diagnostic_action_after_output (diagnostic_context *, diagnostic_t);
void diagnostic_check_max_errors (diagnostic_context *, bool flush = false);
void diagnostic_file_cache_fini (void);
inline void
diagnostic_action_after_output (diagnostic_context *context,
diagnostic_t diag_kind)
{
context->action_after_output (diag_kind);
}
inline void
diagnostic_check_max_errors (diagnostic_context *context, bool flush = false)
{
context->check_max_errors (flush);
}
int get_terminal_width (void);
@ -667,8 +907,6 @@ diagnostic_same_line (const diagnostic_context *context,
}
extern const char *diagnostic_get_color_for_kind (diagnostic_t kind);
extern int diagnostic_converted_column (diagnostic_context *context,
expanded_location s);
/* Pure text formatting support functions. */
extern char *file_name_as_prefix (diagnostic_context *, const char *);
@ -693,11 +931,18 @@ extern int num_digits (int);
extern json::value *json_from_expanded_location (diagnostic_context *context,
location_t loc);
extern bool warning_enabled_at (location_t, int);
inline bool
warning_enabled_at (location_t loc, int opt)
{
return global_dc->warning_enabled_at (loc, opt);
}
inline bool
option_unspecified_p (int opt)
{
return global_dc->option_unspecified_p (opt);
}
extern char *get_cwe_url (int cwe);
extern void diagnostic_emit_diagram (diagnostic_context *context,
const diagnostic_diagram &diagram);
#endif /* ! GCC_DIAGNOSTIC_H */

View file

@ -1084,13 +1084,13 @@ cb_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED,
{
diagnostic_info diagnostic;
diagnostic_t dlevel;
bool save_warn_system_headers = global_dc->dc_warn_system_headers;
bool save_warn_system_headers = global_dc->m_warn_system_headers;
bool ret;
switch (level)
{
case CPP_DL_WARNING_SYSHDR:
global_dc->dc_warn_system_headers = 1;
global_dc->m_warn_system_headers = 1;
/* Fall through. */
case CPP_DL_WARNING:
dlevel = DK_WARNING;
@ -1119,7 +1119,7 @@ cb_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED,
cb_cpp_diagnostic_cpp_option (reason));
ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
if (level == CPP_DL_WARNING_SYSHDR)
global_dc->dc_warn_system_headers = save_warn_system_headers;
global_dc->m_warn_system_headers = save_warn_system_headers;
return ret;
}

View file

@ -871,7 +871,7 @@ gfc_clear_pp_buffer (output_buffer *this_buffer)
pp->buffer = tmp_buffer;
/* We need to reset last_location, otherwise we may skip caret lines
when we actually give a diagnostic. */
global_dc->last_location = UNKNOWN_LOCATION;
global_dc->m_last_location = UNKNOWN_LOCATION;
}
/* The currently-printing diagnostic, for use by gfc_format_decoder,
@ -903,7 +903,7 @@ gfc_warning (int opt, const char *gmsgid, va_list ap)
diagnostic_info diagnostic;
rich_location rich_loc (line_table, UNKNOWN_LOCATION);
bool fatal_errors = global_dc->fatal_errors;
bool fatal_errors = global_dc->m_fatal_errors;
pretty_printer *pp = global_dc->printer;
output_buffer *tmp_buffer = pp->buffer;
@ -912,7 +912,7 @@ gfc_warning (int opt, const char *gmsgid, va_list ap)
if (buffered_p)
{
pp->buffer = pp_warning_buffer;
global_dc->fatal_errors = false;
global_dc->m_fatal_errors = false;
/* To prevent -fmax-errors= triggering. */
--werrorcount;
}
@ -925,7 +925,7 @@ gfc_warning (int opt, const char *gmsgid, va_list ap)
if (buffered_p)
{
pp->buffer = tmp_buffer;
global_dc->fatal_errors = fatal_errors;
global_dc->m_fatal_errors = fatal_errors;
warningcount_buffered = 0;
werrorcount_buffered = 0;
@ -1156,7 +1156,7 @@ gfc_diagnostic_build_locus_prefix (diagnostic_context *context,
? build_message_string ("%s%s:%s", locus_cs, progname, locus_ce )
: !strcmp (s.file, special_fname_builtin ())
? build_message_string ("%s%s:%s", locus_cs, s.file, locus_ce)
: context->show_column
: context->m_show_column
? build_message_string ("%s%s:%d:%d:%s", locus_cs, s.file, s.line,
s.column, locus_ce)
: build_message_string ("%s%s:%d:%s", locus_cs, s.file, s.line, locus_ce));
@ -1176,7 +1176,7 @@ gfc_diagnostic_build_locus_prefix (diagnostic_context *context,
? build_message_string ("%s%s:%s", locus_cs, progname, locus_ce )
: !strcmp (s.file, special_fname_builtin ())
? build_message_string ("%s%s:%s", locus_cs, s.file, locus_ce)
: context->show_column
: context->m_show_column
? build_message_string ("%s%s:%d:%d-%d:%s", locus_cs, s.file, s.line,
MIN (s.column, s2.column),
MAX (s.column, s2.column), locus_ce)
@ -1224,7 +1224,7 @@ gfc_diagnostic_starter (diagnostic_context *context,
if (!context->m_source_printing.enabled
|| diagnostic_location (diagnostic, 0) <= BUILTINS_LOCATION
|| diagnostic_location (diagnostic, 0) == context->last_location)
|| diagnostic_location (diagnostic, 0) == context->m_last_location)
{
pp_set_prefix (context->printer,
concat (locus_prefix, " ", kind_prefix, NULL));
@ -1437,7 +1437,7 @@ gfc_error_opt (int opt, const char *gmsgid, va_list ap)
diagnostic_info diagnostic;
rich_location richloc (line_table, UNKNOWN_LOCATION);
bool fatal_errors = global_dc->fatal_errors;
bool fatal_errors = global_dc->m_fatal_errors;
pretty_printer *pp = global_dc->printer;
output_buffer *tmp_buffer = pp->buffer;
@ -1447,10 +1447,10 @@ gfc_error_opt (int opt, const char *gmsgid, va_list ap)
{
/* To prevent -dH from triggering an abort on a buffered error,
save abort_on_error and restore it below. */
saved_abort_on_error = global_dc->abort_on_error;
global_dc->abort_on_error = false;
saved_abort_on_error = global_dc->m_abort_on_error;
global_dc->m_abort_on_error = false;
pp->buffer = pp_error_buffer;
global_dc->fatal_errors = false;
global_dc->m_fatal_errors = false;
/* To prevent -fmax-errors= triggering, we decrease it before
report_diagnostic increases it. */
--errorcount;
@ -1462,8 +1462,8 @@ gfc_error_opt (int opt, const char *gmsgid, va_list ap)
if (buffered_p)
{
pp->buffer = tmp_buffer;
global_dc->fatal_errors = fatal_errors;
global_dc->abort_on_error = saved_abort_on_error;
global_dc->m_fatal_errors = fatal_errors;
global_dc->m_abort_on_error = saved_abort_on_error;
}

View file

@ -389,8 +389,7 @@ gfc_post_options (const char **pfilename)
/* Enable -Werror=line-truncation when -Werror and -Wno-error have
not been set. */
if (warn_line_truncation && !OPTION_SET_P (warnings_are_errors)
&& (global_dc->classify_diagnostic[OPT_Wline_truncation] ==
DK_UNSPECIFIED))
&& option_unspecified_p (OPT_Wline_truncation))
diagnostic_classify_diagnostic (global_dc, OPT_Wline_truncation,
DK_ERROR, UNKNOWN_LOCATION);
}

View file

@ -46,7 +46,6 @@ compilation is specified by a string called a "spec". */
#include "spellcheck.h"
#include "opts-jobserver.h"
#include "common/common-target.h"
#include "diagnostic-text-art.h"
#ifndef MATH_LIBRARY
#define MATH_LIBRARY "m"
@ -4355,8 +4354,7 @@ driver_handle_option (struct gcc_options *opts,
}
case OPT_fdiagnostics_text_art_charset_:
diagnostics_text_art_charset_init (dc,
(enum diagnostic_text_art_charset)value);
dc->set_text_art_charset ((enum diagnostic_text_art_charset)value);
break;
case OPT_Wa_:

View file

@ -294,21 +294,14 @@ static void
diagnostic_file_cache_init (void)
{
gcc_assert (global_dc);
if (global_dc->m_file_cache == NULL)
global_dc->m_file_cache = new file_cache ();
global_dc->file_cache_init ();
}
/* Free the resources used by the set of cache used for files accessed
by caret diagnostic. */
void
diagnostic_file_cache_fini (void)
diagnostic_context::file_cache_init ()
{
if (global_dc->m_file_cache)
{
delete global_dc->m_file_cache;
global_dc->m_file_cache = NULL;
}
if (m_file_cache == nullptr)
m_file_cache = new file_cache ();
}
/* Return the total lines number that have been read so far by the
@ -366,10 +359,10 @@ diagnostics_file_cache_forcibly_evict_file (const char *file_path)
{
gcc_assert (file_path);
if (!global_dc->m_file_cache)
auto file_cache = global_dc->get_file_cache ();
if (!file_cache)
return;
global_dc->m_file_cache->forcibly_evict_file (file_path);
file_cache->forcibly_evict_file (file_path);
}
void
@ -978,7 +971,7 @@ char_span
location_get_source_line (const char *file_path, int line)
{
diagnostic_file_cache_init ();
return global_dc->m_file_cache->get_source_line (file_path, line);
return global_dc->get_file_cache ()->get_source_line (file_path, line);
}
/* Return a NUL-terminated copy of the source text between two locations, or
@ -1091,7 +1084,7 @@ char_span
get_source_file_content (const char *file_path)
{
diagnostic_file_cache_init ();
return global_dc->m_file_cache->get_source_file_content (file_path);
return global_dc->get_file_cache ()->get_source_file_content (file_path);
}
/* Determine if FILE_PATH missing a trailing newline on its final line.
@ -1103,7 +1096,7 @@ location_missing_trailing_newline (const char *file_path)
{
diagnostic_file_cache_init ();
file_cache_slot *c = global_dc->m_file_cache->lookup_or_add_file (file_path);
file_cache_slot *c = global_dc->get_file_cache ()->lookup_or_add_file (file_path);
if (c == NULL)
return false;

View file

@ -254,8 +254,6 @@ void dump_line_table_statistics (void);
void dump_location_info (FILE *stream);
void diagnostics_file_cache_fini (void);
void diagnostics_file_cache_forcibly_evict_file (const char *file_path);
class GTY(()) string_concat

View file

@ -3512,7 +3512,7 @@ add_error_va (location *loc, const char *fmt, va_list ap)
void
playback::context::
add_diagnostic (struct diagnostic_context *diag_context,
add_diagnostic (diagnostic_context *diag_context,
struct diagnostic_info *diagnostic)
{
/* At this point the text has been formatted into the pretty-printer's

View file

@ -28,7 +28,7 @@ along with GCC; see the file COPYING3. If not see
#include "jit-recording.h"
struct diagnostic_context;
class diagnostic_context;
struct diagnostic_info;
namespace gcc {
@ -247,7 +247,7 @@ public:
get_first_error () const;
void
add_diagnostic (struct diagnostic_context *context,
add_diagnostic (diagnostic_context *context,
struct diagnostic_info *diagnostic);
void

View file

@ -444,7 +444,7 @@ lhd_print_error_function (diagnostic_context *context, const char *file,
pp_newline (context->printer);
if (s.file != NULL)
{
if (context->show_column)
if (context->m_show_column)
pp_printf (context->printer,
_(" inlined from %qs at %r%s:%d:%d%R"),
identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)),

View file

@ -1355,7 +1355,7 @@ void
print_lto_docs_link ()
{
bool print_url = global_dc->printer->url_format != URL_FORMAT_NONE;
const char *url = global_dc->get_option_url (global_dc, OPT_flto);
const char *url = global_dc->m_get_option_url (global_dc, OPT_flto);
pretty_printer pp;
pp.url_format = URL_FORMAT_DEFAULT;
@ -2146,7 +2146,7 @@ main (int argc, char *argv[])
diagnostic_initialize (global_dc, 0);
diagnostic_color_init (global_dc);
diagnostic_urls_init (global_dc);
global_dc->get_option_url = get_option_url;
global_dc->m_get_option_url = get_option_url;
if (atexit (lto_wrapper_cleanup) != 0)
fatal_error (input_location, "%<atexit%> failed");

View file

@ -35,7 +35,6 @@ along with GCC; see the file COPYING3. If not see
#include "version.h"
#include "selftest.h"
#include "file-prefix-map.h"
#include "diagnostic-text-art.h"
/* In this file all option sets are explicit. */
#undef OPTION_SET_P
@ -2773,7 +2772,7 @@ common_handle_option (struct gcc_options *opts,
break;
case OPT_Werror:
dc->warning_as_error_requested = value;
dc->set_warning_as_error_requested (value);
break;
case OPT_Werror_:
@ -2785,7 +2784,7 @@ common_handle_option (struct gcc_options *opts,
break;
case OPT_Wfatal_errors:
dc->fatal_errors = value;
dc->m_fatal_errors = value;
break;
case OPT_Wstack_usage_:
@ -2803,7 +2802,7 @@ common_handle_option (struct gcc_options *opts,
break;
case OPT_Wsystem_headers:
dc->dc_warn_system_headers = value;
dc->m_warn_system_headers = value;
break;
case OPT_aux_info:
@ -2893,46 +2892,45 @@ common_handle_option (struct gcc_options *opts,
}
case OPT_fdiagnostics_text_art_charset_:
diagnostics_text_art_charset_init (dc,
(enum diagnostic_text_art_charset)value);
dc->set_text_art_charset ((enum diagnostic_text_art_charset)value);
break;
case OPT_fdiagnostics_parseable_fixits:
dc->extra_output_kind = (value
? EXTRA_DIAGNOSTIC_OUTPUT_fixits_v1
: EXTRA_DIAGNOSTIC_OUTPUT_none);
dc->set_extra_output_kind (value
? EXTRA_DIAGNOSTIC_OUTPUT_fixits_v1
: EXTRA_DIAGNOSTIC_OUTPUT_none);
break;
case OPT_fdiagnostics_column_unit_:
dc->column_unit = (enum diagnostics_column_unit)value;
dc->m_column_unit = (enum diagnostics_column_unit)value;
break;
case OPT_fdiagnostics_column_origin_:
dc->column_origin = value;
dc->m_column_origin = value;
break;
case OPT_fdiagnostics_escape_format_:
dc->escape_format = (enum diagnostics_escape_format)value;
dc->set_escape_format ((enum diagnostics_escape_format)value);
break;
case OPT_fdiagnostics_show_cwe:
dc->show_cwe = value;
dc->set_show_cwe (value);
break;
case OPT_fdiagnostics_show_rules:
dc->show_rules = value;
dc->set_show_rules (value);
break;
case OPT_fdiagnostics_path_format_:
dc->path_format = (enum diagnostic_path_format)value;
dc->set_path_format ((enum diagnostic_path_format)value);
break;
case OPT_fdiagnostics_show_path_depths:
dc->show_path_depths = value;
dc->set_show_path_depths (value);
break;
case OPT_fdiagnostics_show_option:
dc->show_option_requested = value;
dc->set_show_option_requested (value);
break;
case OPT_fdiagnostics_minimum_margin_width_:
@ -3071,7 +3069,7 @@ common_handle_option (struct gcc_options *opts,
break;
case OPT_fshow_column:
dc->show_column = value;
dc->m_show_column = value;
break;
case OPT_frandom_seed:
@ -3199,7 +3197,7 @@ common_handle_option (struct gcc_options *opts,
break;
case OPT_pedantic_errors:
dc->pedantic_errors = 1;
dc->m_pedantic_errors = 1;
control_warning_option (OPT_Wpedantic, DK_ERROR, NULL, value,
loc, lang_mask,
handlers, opts, opts_set,
@ -3220,11 +3218,11 @@ common_handle_option (struct gcc_options *opts,
break;
case OPT_w:
dc->dc_inhibit_warnings = true;
dc->m_inhibit_warnings = true;
break;
case OPT_fmax_errors_:
dc->max_errors = value;
dc->set_max_errors (value);
break;
case OPT_fuse_ld_bfd:
@ -3284,11 +3282,11 @@ common_handle_option (struct gcc_options *opts,
case OPT_ftabstop_:
/* It is documented that we silently ignore silly values. */
if (value >= 1 && value <= 100)
dc->tabstop = value;
dc->m_tabstop = value;
break;
case OPT_freport_bug:
dc->report_bug = value;
dc->set_report_bug (value);
break;
case OPT_fmultiflags:
@ -3636,7 +3634,7 @@ option_name (diagnostic_context *context, int option_index,
/* A warning without option classified as an error. */
else if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN
|| diag_kind == DK_WARNING)
&& context->warning_as_error_requested)
&& context->warning_as_error_requested_p ())
return xstrdup (cl_options[OPT_Werror].opt_text);
else
return NULL;

View file

@ -38,7 +38,7 @@ test_diagnostic_context::test_diagnostic_context ()
diagnostic_initialize (this, 0);
m_source_printing.enabled = true;
m_source_printing.show_labels_p = true;
show_column = true;
m_show_column = true;
m_text_callbacks.start_span = start_span_cb;
m_source_printing.min_margin_width = 6;
m_source_printing.max_width = 80;

View file

@ -225,7 +225,7 @@ plugin_init (struct plugin_name_args *plugin_info,
diagnostic_starter (global_dc) = test_diagnostic_starter;
global_dc->m_text_callbacks.start_span = test_diagnostic_start_span_fn;
global_dc->m_output_format = new test_output_format (*global_dc);
global_dc->set_output_format (new test_output_format (*global_dc));
pass_info.pass = new pass_test_groups (g);
pass_info.reference_pass_name = "*warn_function_noreturn";

View file

@ -23,7 +23,7 @@ static void
emit_canvas (const canvas &c, const char *alt_text)
{
diagnostic_diagram diagram (c, alt_text);
diagnostic_emit_diagram (global_dc, diagram);
global_dc->emit_diagram (diagram);
}
static void
@ -149,7 +149,7 @@ test_chessboard ()
static void
emit_table (const table &table, const style_manager &sm, const char *alt_text)
{
const text_art::theme *theme = global_dc->m_diagrams.m_theme;
const text_art::theme *theme = global_dc->get_diagram_theme ();
if (!theme)
return;
canvas c (table.to_canvas (*theme, sm));

View file

@ -714,7 +714,7 @@ init_asm_output (const char *name)
"cannot open %qs for writing: %m", asm_file_name);
}
if (!flag_syntax_only && !(global_dc->lang_mask & CL_LTODump))
if (!flag_syntax_only && !(global_dc->m_lang_mask & CL_LTODump))
{
targetm.asm_out.file_start ();
@ -986,7 +986,7 @@ internal_error_reentered (diagnostic_context *, const char *, va_list *)
static void
internal_error_function (diagnostic_context *, const char *, va_list *)
{
global_dc->internal_error = internal_error_reentered;
global_dc->m_internal_error = internal_error_reentered;
warn_if_plugins ();
emergency_dump_function ();
}
@ -1019,7 +1019,7 @@ general_init (const char *argv0, bool init_signals)
/* Initialize the diagnostics reporting machinery, so option parsing
can give warnings and errors. */
diagnostic_initialize (global_dc, N_OPTS);
global_dc->lang_mask = lang_hooks.option_lang_mask ();
global_dc->m_lang_mask = lang_hooks.option_lang_mask ();
/* Set a default printer. Language specific initializations will
override it later. */
tree_diagnostics_defaults (global_dc);
@ -1030,25 +1030,24 @@ general_init (const char *argv0, bool init_signals)
= global_options_init.x_flag_diagnostics_show_labels;
global_dc->m_source_printing.show_line_numbers_p
= global_options_init.x_flag_diagnostics_show_line_numbers;
global_dc->show_cwe
= global_options_init.x_flag_diagnostics_show_cwe;
global_dc->show_rules
= global_options_init.x_flag_diagnostics_show_rules;
global_dc->path_format
= (enum diagnostic_path_format)global_options_init.x_flag_diagnostics_path_format;
global_dc->show_path_depths
= global_options_init.x_flag_diagnostics_show_path_depths;
global_dc->show_option_requested
= global_options_init.x_flag_diagnostics_show_option;
global_dc->set_show_cwe (global_options_init.x_flag_diagnostics_show_cwe);
global_dc->set_show_rules (global_options_init.x_flag_diagnostics_show_rules);
global_dc->set_path_format
((enum diagnostic_path_format)
global_options_init.x_flag_diagnostics_path_format);
global_dc->set_show_path_depths
(global_options_init.x_flag_diagnostics_show_path_depths);
global_dc->set_show_option_requested
(global_options_init.x_flag_diagnostics_show_option);
global_dc->m_source_printing.min_margin_width
= global_options_init.x_diagnostics_minimum_margin_width;
global_dc->show_column
global_dc->m_show_column
= global_options_init.x_flag_show_column;
global_dc->internal_error = internal_error_function;
global_dc->option_enabled = option_enabled;
global_dc->option_state = &global_options;
global_dc->option_name = option_name;
global_dc->get_option_url = get_option_url;
global_dc->m_internal_error = internal_error_function;
global_dc->m_option_enabled = option_enabled;
global_dc->m_option_state = &global_options;
global_dc->m_option_name = option_name;
global_dc->m_get_option_url = get_option_url;
if (init_signals)
{
@ -1235,7 +1234,7 @@ process_options ()
input_location = saved_location;
if (flag_diagnostics_generate_patch)
global_dc->edit_context_ptr = new edit_context ();
global_dc->create_edit_context ();
/* Avoid any informative notes in the second run of -fcompare-debug. */
if (flag_compare_debug)
@ -1664,13 +1663,11 @@ process_options ()
if (!OPTION_SET_P (warnings_are_errors))
{
if (warn_coverage_mismatch
&& (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] ==
DK_UNSPECIFIED))
&& option_unspecified_p (OPT_Wcoverage_mismatch))
diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
DK_ERROR, UNKNOWN_LOCATION);
if (warn_coverage_invalid_linenum
&& (global_dc->classify_diagnostic[OPT_Wcoverage_invalid_line_number] ==
DK_UNSPECIFIED))
&& option_unspecified_p (OPT_Wcoverage_invalid_line_number))
diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_invalid_line_number,
DK_ERROR, UNKNOWN_LOCATION);
}
@ -2303,11 +2300,12 @@ toplev::main (int argc, char **argv)
if (flag_diagnostics_generate_patch)
{
gcc_assert (global_dc->edit_context_ptr);
auto edit_context_ptr = global_dc->get_edit_context ();
gcc_assert (edit_context_ptr);
pretty_printer pp;
pp_show_color (&pp) = pp_show_color (global_dc->printer);
global_dc->edit_context_ptr->print_diff (&pp, true);
edit_context_ptr->print_diff (&pp, true);
pp_flush (&pp);
}

View file

@ -205,7 +205,7 @@ struct event_range
expanded_location exploc
= linemap_client_expand_location_to_spelling_point
(initial_loc, LOCATION_ASPECT_CARET);
if (exploc.file != LOCATION_FILE (dc->last_location))
if (exploc.file != LOCATION_FILE (dc->m_last_location))
dc->m_text_callbacks.start_span (dc, exploc);
}
@ -599,7 +599,7 @@ default_tree_diagnostic_path_printer (diagnostic_context *context,
const unsigned num_events = path->num_events ();
switch (context->path_format)
switch (context->get_path_format ())
{
case DPF_NONE:
/* Do nothing. */
@ -614,7 +614,7 @@ default_tree_diagnostic_path_printer (diagnostic_context *context,
label_text event_text (event.get_desc (false));
gcc_assert (event_text.get ());
diagnostic_event_id_t event_id (i);
if (context->show_path_depths)
if (context->show_path_depths_p ())
{
int stack_depth = event.get_stack_depth ();
tree fndecl = event.get_fndecl ();
@ -646,7 +646,7 @@ default_tree_diagnostic_path_printer (diagnostic_context *context,
char *saved_prefix = pp_take_prefix (context->printer);
pp_set_prefix (context->printer, NULL);
print_path_summary_as_text (&summary, context,
context->show_path_depths);
context->show_path_depths_p ());
pp_flush (context->printer);
pp_set_prefix (context->printer, saved_prefix);
}

View file

@ -374,9 +374,8 @@ tree_diagnostics_defaults (diagnostic_context *context)
diagnostic_starter (context) = default_tree_diagnostic_starter;
diagnostic_finalizer (context) = default_diagnostic_finalizer;
diagnostic_format_decoder (context) = default_tree_printer;
context->print_path = default_tree_diagnostic_path_printer;
context->make_json_for_path = default_tree_make_json_for_path;
context->set_locations_cb = set_inlining_locations;
delete context->m_client_data_hooks;
context->m_client_data_hooks = make_compiler_data_hooks ();
context->m_print_path = default_tree_diagnostic_path_printer;
context->m_make_json_for_path = default_tree_make_json_for_path;
context->set_set_locations_callback (set_inlining_locations);
context->set_client_data_hooks (make_compiler_data_hooks ());
}