No functional change intended.
gcc/ada/ChangeLog:
* gcc-interface/misc.cc: Update for diagnostic_context becoming
diagnostics::context.
gcc/analyzer/ChangeLog:
* program-point.cc: : Update for diagnostic_context becoming
diagnostics::context, and for diagnostic_source_print_policy
becoming diagnostics::source_print_policy.
gcc/c-family/ChangeLog:
* c-common.h: Update for diagnostic_context becoming
diagnostics::context.
* c-opts.cc: Likewise.
gcc/c/ChangeLog:
* c-objc-common.cc: Update for diagnostic_context becoming
diagnostics::context.
* c-tree.h: Likewise.
gcc/ChangeLog:
* coretypes.h: Update for diagnostic_context becoming
diagnostics::context.
* diagnostic-global-context.cc: Likewise.
* diagnostic.cc: Likewise. Also for diagnostic_option_classifier
becoming diagnostics::option_classifier.
* diagnostic.h (diagnostic_text_starter_fn): Rename to...
(diagnostics::text_starter_fn): ...this, and move to
diagnostics/context.h.
(get_printer): Rename to...
(diagnostics::get_printer): ...this, and move to
diagnostics/context.h.
(class diagnostic_option_manager): Rename to...
(class diagnostics::option_manager): ...this, and move to
diagnostics/context.h.
(class diagnostic_option_classifier): Rename to...
(class diagnostics::option_classifier): ...this, and move to
diagnostics/context.h.
(struct diagnostic_source_printing_options): Rename to...
(struct diagnostics::source_printing_options): ...this, and move
to diagnostics/context.h.
(class diagnostic_column_policy): Rename to...
(class diagnostics::column_policy): ...this, and move to
diagnostics/context.h.
(class diagnostic_location_print_policy): Rename to...
(class diagnostics::location_print_policy): ...this, and move to
diagnostics/context.h.
(class html_label_writer): Rename to...
(class diagnostics::html_label_writer): ...this, and move to
diagnostics/context.h.
(class diagnostic_source_print_policy): Rename to...
(class diagnostics::source_print_policy): ...this, and move to
diagnostics/context.h.
(struct diagnostic_counters): Rename to...
(struct diagnostics::counters): ...this, and move to
diagnostics/context.h.
(class diagnostic_context): Rename to...
(class diagnostics::context): ...this, and move to
diagnostics/context.h.
(diagnostic_text_starter): Rename to...
(diagnostics::text_starter): ...this, and move to
diagnostics/context.h.
(diagnostic_start_span): Rename to...
(diagnostics::start_span): ...this, and move to
diagnostics/context.h.
(diagnostic_text_finalizer): Rename to...
(diagnostics::text_finalizer): ...this, and move to
diagnostics/context.h.
Include "diagnostics/context.h".
* diagnostics/buffering.h: Update for diagnostic_context becoming
diagnostics::context; similarly for diagnostic_counters.
* diagnostics/client-data-hooks.h: Likewise.
* diagnostics/context.h: New file, taken from material in
diagnostic.h.
* diagnostics/html-sink.cc: : Update for diagnostic_context
becoming diagnostics::context.
* diagnostics/html-sink.h: Likewise.
* diagnostics/lazy-paths.cc: Likewise for
diagnostic_option_manager.
* diagnostics/output-file.h: Likewise for diagnostic_context.
* diagnostics/output-spec.cc: Likewise.
* diagnostics/output-spec.h: Likewise.
* diagnostics/paths-output.cc: Likewise.
* diagnostics/sarif-sink.cc: Likewise.
* diagnostics/sarif-sink.h: Likewise.
* diagnostics/sink.h: Likewise.
* diagnostics/source-printing.cc: Likewise.
* diagnostics/text-sink.cc: Likewise.
* diagnostics/text-sink.h: Likewise.
* gcc-rich-location.h: Likewise.
* gcc.cc: Likewise.
* gdbinit.in: Likewise.
* langhooks-def.h: Likewise.
* langhooks.cc: Likewise.
* langhooks.h: Likewise.
* libgdiagnostics.cc: Likewise.
* optc-gen.awk: Likewise.
* opth-gen.awk: Likewise.
* opts-common.cc: Likewise.
* opts-diagnostic.cc: Likewise.
* opts-diagnostic.h: Likewise.
* opts-global.cc: Likewise.
* opts.cc: Likewise.
* opts.h: Likewise.
* selftest-diagnostic.cc: Likewise.
* selftest-diagnostic.h: Likewise.
* toplev.cc: Likewise.
* tree-diagnostic-client-data-hooks.cc: Likewise.
* tree-diagnostic.cc: Likewise.
* tree-diagnostic.h: Likewise.
gcc/cp/ChangeLog:
* cp-tree.h: Update for diagnostic_context becoming
diagnostics::context.
* error.cc: Likewise.
* module.cc: Likewise.
gcc/fortran/ChangeLog:
* error.cc: Update for diagnostic_context becoming
diagnostics::context.
gcc/jit/ChangeLog:
* dummy-frontend.cc: Update for diagnostic_context becoming
diagnostics::context.
* jit-playback.h: Likewise.
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-expr.cc: Update for diagnostic_text_finalizer
becoming diagnostics::text_finalizer.
* resolve/rust-late-name-resolver-2.0.cc: Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/plugin/show_template_tree_color_plugin.cc: Update for
moves to namespace diagnostics.
* gcc.dg/plugin/diagnostic_group_plugin.cc: Likewise.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: Likewise.
* gcc.dg/plugin/location_overflow_plugin.cc: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
/* Here is the function to handle the compiler error processing in GCC. */
static void
-internal_error_function (diagnostic_context *context, const char *msgid,
+internal_error_function (diagnostics::context *context, const char *msgid,
va_list *ap)
{
char *buffer, *p, *loc;
return function_point (supernode, from_edge, 0, PK_BEFORE_SUPERNODE);
}
-/* A subclass of diagnostic_context for use by
+/* A subclass of diagnostics::context for use by
program_point::print_source_line. */
-class debug_diagnostic_context : public diagnostic_context
+class debug_diagnostic_context : public diagnostics::context
{
public:
debug_diagnostic_context ()
// TODO: monospace font
debug_diagnostic_context tmp_dc;
gcc_rich_location richloc (stmt->location);
- diagnostic_source_print_policy source_policy (tmp_dc);
+ diagnostics::source_print_policy source_policy (tmp_dc);
gcc_assert (pp);
source_policy.print (*pp, richloc, DK_ERROR, nullptr);
pp_string (pp, pp_formatted_text (tmp_dc.get_reference_printer ()));
extern const unsigned int c_family_lang_mask;
extern unsigned int c_common_option_lang_mask (void);
-extern void c_common_diagnostics_set_defaults (diagnostic_context *);
+extern void c_common_diagnostics_set_defaults (diagnostics::context *);
extern bool c_common_complain_wrong_lang_p (const struct cl_option *);
extern void c_common_init_options_struct (struct gcc_options *);
extern void c_common_init_options (unsigned int, struct cl_decoded_option *);
/* Common default settings for diagnostics. */
void
-c_common_diagnostics_set_defaults (diagnostic_context *context)
+c_common_diagnostics_set_defaults (diagnostics::context *context)
{
- diagnostic_text_finalizer (context) = c_diagnostic_text_finalizer;
+ diagnostics::text_finalizer (context) = c_diagnostic_text_finalizer;
context->set_permissive_option (OPT_fpermissive);
}
}
void
-c_initialize_diagnostics (diagnostic_context *context)
+c_initialize_diagnostics (diagnostics::context *context)
{
context->set_pretty_printer (std::make_unique<c_pretty_printer> ());
c_common_diagnostics_set_defaults (context);
extern bool c_objc_common_init (void);
extern bool c_missing_noreturn_ok_p (tree);
extern bool c_warn_unused_global_decl (const_tree);
-extern void c_initialize_diagnostics (diagnostic_context *);
+extern void c_initialize_diagnostics (diagnostics::context *);
extern bool c_var_mod_p (tree x, tree fn);
extern alias_set_type c_get_alias_set (tree);
extern int c_type_dwarf_attribute (const_tree, int);
struct cl_decoded_option;
struct cl_option_handlers;
class rich_location;
-class diagnostic_context;
-namespace diagnostics { class text_sink; }
+namespace diagnostics {
+ class context;
+ class text_sink;
+} // namespace diagnostics
class pretty_printer;
class diagnostic_event_id_t;
typedef const char * (*diagnostic_input_charset_callback)(const char *);
extern bool cxx_warn_unused_global_decl (const_tree);
extern size_t cp_tree_size (enum tree_code);
extern bool cp_var_mod_type_p (tree, tree);
-extern void cxx_initialize_diagnostics (diagnostic_context *);
+extern void cxx_initialize_diagnostics (diagnostics::context *);
extern int cxx_types_compatible_p (tree, tree);
extern bool cxx_block_may_fallthru (const_tree);
erroneous_templates_t *erroneous_templates;
-/* Callback function diagnostic_context::m_adjust_diagnostic_info.
+/* Callback function diagnostics::context::m_adjust_diagnostic_info.
Errors issued when parsing a template are automatically treated like
permerrors associated with the -Wtemplate-body flag and can be
issue an error if we later need to instantiate the template. */
static void
-cp_adjust_diagnostic_info (diagnostic_context *context,
+cp_adjust_diagnostic_info (diagnostics::context *context,
diagnostic_info *diagnostic)
{
if (diagnostic->m_kind == DK_ERROR)
capacities. */
void
-cxx_initialize_diagnostics (diagnostic_context *context)
+cxx_initialize_diagnostics (diagnostics::context *context)
{
cxx_pretty_printer *pp = new cxx_pretty_printer ();
pp->set_format_postprocessor (std::make_unique<cxx_format_postprocessor> ());
context->set_pretty_printer (std::unique_ptr<pretty_printer> (pp));
c_common_diagnostics_set_defaults (context);
- diagnostic_text_starter (context) = cp_diagnostic_text_starter;
+ diagnostics::text_starter (context) = cp_diagnostic_text_starter;
/* diagnostic_finalizer is already c_diagnostic_text_finalizer. */
context->set_format_decoder (cp_printer);
context->set_adjust_diagnostic_info_callback (cp_adjust_diagnostic_info);
/* The above is true for constraint satisfaction also. */
if (current_failed_constraint)
return;
- diagnostic_context *const context = &text_output.get_context ();
+ diagnostics::context *const context = &text_output.get_context ();
if (diagnostic_last_function_changed (context, diagnostic))
{
pretty_printer *const pp = text_output.get_printer ();
void write_macro_maps (elf_out *to, range_t &, unsigned *crc_ptr);
bool read_macro_maps (line_map_uint_t);
- void write_diagnostic_classification (elf_out *, diagnostic_context *,
+ void write_diagnostic_classification (elf_out *, diagnostics::context *,
unsigned *);
- bool read_diagnostic_classification (diagnostic_context *);
+ bool read_diagnostic_classification (diagnostics::context *);
private:
void write_define (bytes_out &, const cpp_macro *);
void
module_state::write_diagnostic_classification (elf_out *to,
- diagnostic_context *dc,
+ diagnostics::context *dc,
unsigned *crc_p)
{
auto &changes = dc->get_classification_history ();
/* Read any #pragma GCC diagnostic info from the .dgc section. */
bool
-module_state::read_diagnostic_classification (diagnostic_context *dc)
+module_state::read_diagnostic_classification (diagnostics::context *dc)
{
bytes_in sec;
#include "diagnostic.h"
#include "diagnostics/sink.h"
-/* A diagnostic_context surrogate for stderr. */
-static diagnostic_context global_diagnostic_context;
-diagnostic_context *global_dc = &global_diagnostic_context;
+/* A diagnostics::context surrogate for stderr. */
+static diagnostics::context global_diagnostic_context;
+diagnostics::context *global_dc = &global_diagnostic_context;
/* Standard error reporting routines in increasing order of severity. */
va_end (ap);
}
-/* Wrapper around diagnostic_context::diagnostic_impl
+/* Wrapper around diagnostics::context::diagnostic_impl
implying global_dc and taking a variable argument list. */
bool
/* Set caret_max_width to value. */
void
-diagnostic_set_caret_max_width (diagnostic_context *context, int value)
+diagnostic_set_caret_max_width (diagnostics::context *context, int value)
{
/* One minus to account for the leading empty space. */
value = value ? value - 1
}
void
-diagnostic_option_classifier::init (int n_opts)
+diagnostics::option_classifier::init (int n_opts)
{
m_n_opts = n_opts;
m_classify_diagnostic = XNEWVEC (diagnostic_t, n_opts);
}
void
-diagnostic_option_classifier::fini ()
+diagnostics::option_classifier::fini ()
{
XDELETEVEC (m_classify_diagnostic);
m_classify_diagnostic = nullptr;
m_push_list.release ();
}
-/* Save the diagnostic_option_classifier state to F for PCH
+/* Save the diagnostics::option_classifier state to F for PCH
output. Returns 0 on success, -1 on error. */
int
-diagnostic_option_classifier::pch_save (FILE *f)
+diagnostics::option_classifier::pch_save (FILE *f)
{
unsigned int lengths[2] = { m_classification_history.length (),
m_push_list.length () };
if (fwrite (lengths, sizeof (lengths), 1, f) != 1
|| (lengths[0]
&& fwrite (m_classification_history.address (),
- sizeof (diagnostic_classification_change_t),
+ sizeof (classification_change_t),
lengths[0], f) != lengths[0])
|| (lengths[1]
&& fwrite (m_push_list.address (), sizeof (int),
return 0;
}
-/* Read the diagnostic_option_classifier state from F for PCH
+/* Read the diagnostics::option_classifier state from F for PCH
read. Returns 0 on success, -1 on error. */
int
-diagnostic_option_classifier::pch_restore (FILE *f)
+diagnostics::option_classifier::pch_restore (FILE *f)
{
unsigned int lengths[2];
if (fread (lengths, sizeof (lengths), 1, f) != 1)
m_push_list.safe_grow (lengths[1]);
if ((lengths[0]
&& fread (m_classification_history.address (),
- sizeof (diagnostic_classification_change_t),
+ sizeof (classification_change_t),
lengths[0], f) != lengths[0])
|| (lengths[1]
&& fread (m_push_list.address (), sizeof (int),
/* Save all diagnostic classifications in a stack. */
void
-diagnostic_option_classifier::push ()
+diagnostics::option_classifier::push ()
{
m_push_list.safe_push (m_classification_history.length ());
}
is empty, revert to the state based on command line parameters. */
void
-diagnostic_option_classifier::pop (location_t where)
+diagnostics::option_classifier::pop (location_t where)
{
int jump_to;
else
jump_to = 0;
- diagnostic_classification_change_t v = { where, jump_to, DK_POP };
+ classification_change_t v = { where, jump_to, DK_POP };
m_classification_history.safe_push (v);
}
/* Initialize the diagnostic message outputting machinery. */
void
-diagnostic_context::initialize (int n_opts)
+diagnostics::context::initialize (int n_opts)
{
/* Allocate a basic pretty-printer. Clients will replace this a
much more elaborated pretty-printer if they wish. */
without a VALUE, it initializes with DIAGNOSTICS_COLOR_DEFAULT. */
void
-diagnostic_context::color_init (int value)
+diagnostics::context::color_init (int value)
{
/* value == -1 is the default value. */
if (value < 0)
handling "auto". */
void
-diagnostic_context::urls_init (int value)
+diagnostics::context::urls_init (int value)
{
/* value == -1 is the default value. */
if (value < 0)
/* Create the file_cache, if not already created, and tell it how to
translate files on input. */
void
-diagnostic_context::
+diagnostics::context::
initialize_input_context (diagnostic_input_charset_callback ccb,
bool should_skip_bom)
{
/* Do any cleaning up required after the last diagnostic is emitted. */
void
-diagnostic_context::finish ()
+diagnostics::context::finish ()
{
/* We might be handling a fatal error.
Close any active diagnostic groups, which may trigger flushing
m_original_argv = nullptr;
}
-/* Dump state of this diagnostic_context to OUT, for debugging. */
+/* Dump state of this diagnostics::context to OUT, for debugging. */
void
-diagnostic_context::dump (FILE *out) const
+diagnostics::context::dump (FILE *out) const
{
- fprintf (out, "diagnostic_context:\n");
+ fprintf (out, "diagnostics::context:\n");
m_diagnostic_counters.dump (out, 2);
fprintf (out, " reference printer:\n");
m_reference_printer->dump (out, 4);
we ought to exit with a non-zero exit code. */
bool
-diagnostic_context::execution_failed_p () const
+diagnostics::context::execution_failed_p () const
{
/* Equivalent to (seen_error () || werrorcount), but on
this context, rather than global_dc. */
}
void
-diagnostic_context::remove_all_output_sinks ()
+diagnostics::context::remove_all_output_sinks ()
{
while (!m_sinks.is_empty ())
delete m_sinks.pop ();
}
void
-diagnostic_context::set_sink (std::unique_ptr<diagnostics::sink> sink_)
+diagnostics::context::set_sink (std::unique_ptr<diagnostics::sink> sink_)
{
remove_all_output_sinks ();
m_sinks.safe_push (sink_.release ());
}
diagnostics::sink &
-diagnostic_context::get_sink (size_t idx) const
+diagnostics::context::get_sink (size_t idx) const
{
gcc_assert (idx < m_sinks.length ());
gcc_assert (m_sinks[idx]);
}
void
-diagnostic_context::add_sink (std::unique_ptr<diagnostics::sink> sink_)
+diagnostics::context::add_sink (std::unique_ptr<diagnostics::sink> sink_)
{
m_sinks.safe_push (sink_.release ());
}
/* Return true if there are no machine-readable formats writing to stderr. */
bool
-diagnostic_context::supports_fnotice_on_stderr_p () const
+diagnostics::context::supports_fnotice_on_stderr_p () const
{
for (auto sink_ : m_sinks)
if (sink_->machine_readable_stderr_p ())
}
void
-diagnostic_context::set_main_input_filename (const char *filename)
+diagnostics::context::set_main_input_filename (const char *filename)
{
for (auto sink_ : m_sinks)
sink_->set_main_input_filename (filename);
}
void
-diagnostic_context::
+diagnostics::context::
set_client_data_hooks (std::unique_ptr<diagnostics::client_data_hooks> hooks)
{
delete m_client_data_hooks;
}
void
-diagnostic_context::set_original_argv (unique_argv original_argv)
+diagnostics::context::set_original_argv (unique_argv original_argv)
{
/* Ideally we'd use a unique_argv for m_original_argv, but
- diagnostic_context doesn't yet have a ctor/dtor pair. */
+ diagnostics::context doesn't yet have a ctor/dtor pair. */
// Ensure any old value is freed
freeargv (m_original_argv);
}
void
-diagnostic_context::
-set_option_manager (std::unique_ptr<diagnostic_option_manager> mgr,
+diagnostics::context::
+set_option_manager (std::unique_ptr<diagnostics::option_manager> mgr,
unsigned lang_mask)
{
delete m_option_mgr;
}
void
-diagnostic_context::push_owned_urlifier (std::unique_ptr<urlifier> ptr)
+diagnostics::context::push_owned_urlifier (std::unique_ptr<urlifier> ptr)
{
gcc_assert (m_urlifier_stack);
const urlifier_stack_node node = { ptr.release (), true };
}
void
-diagnostic_context::push_borrowed_urlifier (const urlifier &loan)
+diagnostics::context::push_borrowed_urlifier (const urlifier &loan)
{
gcc_assert (m_urlifier_stack);
const urlifier_stack_node node = { const_cast <urlifier *> (&loan), false };
}
void
-diagnostic_context::pop_urlifier ()
+diagnostics::context::pop_urlifier ()
{
gcc_assert (m_urlifier_stack);
gcc_assert (m_urlifier_stack->length () > 0);
}
const diagnostics::logical_locations::manager *
-diagnostic_context::get_logical_location_manager () const
+diagnostics::context::get_logical_location_manager () const
{
if (!m_client_data_hooks)
return nullptr;
}
const urlifier *
-diagnostic_context::get_urlifier () const
+diagnostics::context::get_urlifier () const
{
if (!m_urlifier_stack)
return nullptr;
Refresh all output sinks. */
void
-diagnostic_context::set_pretty_printer (std::unique_ptr<pretty_printer> pp)
+diagnostics::context::set_pretty_printer (std::unique_ptr<pretty_printer> pp)
{
delete m_reference_printer;
m_reference_printer = pp.release ();
/* Give all output sinks a chance to rebuild their pretty_printer. */
void
-diagnostic_context::refresh_output_sinks ()
+diagnostics::context::refresh_output_sinks ()
{
for (auto sink_ : m_sinks)
sink_->update_printer ();
of all output sinks. */
void
-diagnostic_context::set_format_decoder (printer_fn format_decoder)
+diagnostics::context::set_format_decoder (printer_fn format_decoder)
{
pp_format_decoder (m_reference_printer) = format_decoder;
for (auto sink_ : m_sinks)
}
void
-diagnostic_context::set_show_highlight_colors (bool val)
+diagnostics::context::set_show_highlight_colors (bool val)
{
pp_show_highlight_colors (m_reference_printer) = val;
for (auto sink_ : m_sinks)
}
void
-diagnostic_context::set_prefixing_rule (diagnostic_prefixing_rule_t rule)
+diagnostics::context::set_prefixing_rule (diagnostic_prefixing_rule_t rule)
{
pp_prefixing_rule (m_reference_printer) = rule;
for (auto sink_ : m_sinks)
}
void
-diagnostic_context::create_edit_context ()
+diagnostics::context::create_edit_context ()
{
delete m_edit_context_ptr;
gcc_assert (m_file_cache);
}
}
-diagnostic_column_policy::
-diagnostic_column_policy (const diagnostic_context &dc)
+diagnostics::column_policy::column_policy (const diagnostics::context &dc)
: m_file_cache (dc.get_file_cache ()),
m_column_unit (dc.m_column_unit),
m_column_origin (dc.m_column_origin),
to the requested units and origin. Return -1 if the column is
invalid (<= 0). */
int
-diagnostic_column_policy::converted_column (expanded_location s) const
+diagnostics::column_policy::converted_column (expanded_location s) const
{
int one_based_col = convert_column_unit (m_file_cache,
m_column_unit, m_tabstop, s);
/* Return a string describing a location e.g. "foo.c:42:10". */
label_text
-diagnostic_column_policy::get_location_text (const expanded_location &s,
- bool show_column,
- bool colorize) const
+diagnostics::column_policy::get_location_text (const expanded_location &s,
+ bool show_column,
+ bool colorize) const
{
const char *locus_cs = colorize_start (colorize, "locus");
const char *locus_ce = colorize_stop (colorize);
line_col, locus_ce));
}
-diagnostic_location_print_policy::
-diagnostic_location_print_policy (const diagnostic_context &dc)
+diagnostics::location_print_policy::
+location_print_policy (const diagnostics::context &dc)
: m_column_policy (dc),
m_show_column (dc.m_show_column)
{
}
-diagnostic_location_print_policy::
-diagnostic_location_print_policy (const diagnostics::text_sink &text_output)
+diagnostics::location_print_policy::
+location_print_policy (const diagnostics::text_sink &text_output)
:
m_column_policy (text_output.get_context ()),
m_show_column (text_output.get_context ().m_show_column)
/* Check if we've met the maximum error limit, and if so fatally exit
with a message.
- FLUSH indicates whether a diagnostic_context::finish call is needed. */
+ FLUSH indicates whether a diagnostics::context::finish call is needed. */
void
-diagnostic_context::check_max_errors (bool flush)
+diagnostics::context::check_max_errors (bool flush)
{
if (!m_max_errors)
return;
is written out. This function does not always return. */
void
-diagnostic_context::action_after_output (diagnostic_t diag_kind)
+diagnostics::context::action_after_output (diagnostic_t diag_kind)
{
switch (diag_kind)
{
its future children if any. */
void
-diagnostic_context::inhibit_notes_in_group (bool inhibit)
+diagnostics::context::inhibit_notes_in_group (bool inhibit)
{
int curr_depth = (m_diagnostic_groups.m_group_nesting_depth
+ m_diagnostic_groups.m_diagnostic_nesting_level);
/* Return whether notes must be inhibited in the current diagnostic_group. */
bool
-diagnostic_context::notes_inhibited_in_group () const
+diagnostics::context::notes_inhibited_in_group () const
{
if (m_diagnostic_groups.m_inhibiting_notes_from
&& (m_diagnostic_groups.m_group_nesting_depth
range. If OPTION_ID is zero, the new setting is for all the
diagnostics. */
diagnostic_t
-diagnostic_option_classifier::
-classify_diagnostic (const diagnostic_context *context,
+diagnostics::option_classifier::
+classify_diagnostic (const diagnostics::context *context,
diagnostic_option_id option_id,
diagnostic_t new_kind,
location_t where)
m_classify_diagnostic[option_id.m_idx] = old_kind;
}
- diagnostic_classification_change_t *p;
+ classification_change_t *p;
FOR_EACH_VEC_ELT_REVERSE (m_classification_history, i, p)
if (p->option == option_id.m_idx)
{
break;
}
- diagnostic_classification_change_t v
+ classification_change_t v
= { where, option_id.m_idx, new_kind };
m_classification_history.safe_push (v);
}
/* Update the inlining info in this context for a DIAGNOSTIC. */
void
-diagnostic_context::get_any_inlining_info (diagnostic_info *diagnostic)
+diagnostics::context::get_any_inlining_info (diagnostic_info *diagnostic)
{
auto &ilocs = diagnostic->m_iinfo.m_ilocs;
otherwise. */
diagnostic_t
-diagnostic_option_classifier::
+diagnostics::option_classifier::
update_effective_level_from_pragmas (diagnostic_info *diagnostic) const
{
if (m_classification_history.is_empty ())
{
/* FIXME: Stupid search. Optimize later. */
unsigned int i;
- diagnostic_classification_change_t *p;
+ classification_change_t *p;
FOR_EACH_VEC_ELT_REVERSE (m_classification_history, i, p)
{
location_t pragloc = p->location;
as appropriate for #pragma GCC diagnostic and -Werror=foo. */
bool
-diagnostic_context::diagnostic_enabled (diagnostic_info *diagnostic)
+diagnostics::context::diagnostic_enabled (diagnostic_info *diagnostic)
{
/* Update the inlining stack for this diagnostic. */
get_any_inlining_info (diagnostic);
/* Returns whether warning OPTION_ID is enabled at LOC. */
bool
-diagnostic_context::warning_enabled_at (location_t loc,
+diagnostics::context::warning_enabled_at (location_t loc,
diagnostic_option_id option_id)
{
if (!diagnostic_report_warnings_p (this, loc))
/* Emit a diagnostic within a diagnostic group on this context. */
bool
-diagnostic_context::
+diagnostics::context::
emit_diagnostic_with_group (diagnostic_t kind,
rich_location &richloc,
const diagnostics::metadata *metadata,
/* As above, but taking a va_list *. */
bool
-diagnostic_context::
+diagnostics::context::
emit_diagnostic_with_group_va (diagnostic_t kind,
rich_location &richloc,
const diagnostics::metadata *metadata,
}
/* Report a diagnostic message (an error or a warning) as specified by
- this diagnostic_context.
+ this diagnostics::context.
front-end independent format specifiers are exactly those described
in the documentation of output_format.
Return true if a diagnostic was printed, false otherwise. */
bool
-diagnostic_context::report_diagnostic (diagnostic_info *diagnostic)
+diagnostics::context::report_diagnostic (diagnostic_info *diagnostic)
{
diagnostic_t orig_diag_kind = diagnostic->m_kind;
((diagnostic->m_kind == DK_ERROR && orig_diag_kind == DK_WARNING)
? DK_WERROR
: diagnostic->m_kind);
- diagnostic_counters &counters
+ diagnostics::counters &counters
= (m_diagnostic_buffer
? m_diagnostic_buffer->m_diagnostic_counters
: m_diagnostic_counters);
}
void
-diagnostic_context::report_verbatim (text_info &text)
+diagnostics::context::report_verbatim (text_info &text)
{
va_list *orig_args = text.m_args_ptr;
for (auto sink_ : m_sinks)
}
void
-diagnostic_context::
+diagnostics::context::
report_global_digraph (const diagnostics::digraphs::lazy_digraph &ldg)
{
for (auto sink_ : m_sinks)
permerror, error, error_at, error_at, sorry, fatal_error, internal_error,
and internal_error_no_backtrace, as documented and defined below. */
bool
-diagnostic_context::diagnostic_impl (rich_location *richloc,
+diagnostics::context::diagnostic_impl (rich_location *richloc,
const diagnostics::metadata *metadata,
diagnostic_option_id option_id,
const char *gmsgid,
/* Implement inform_n, warning_n, and error_n, as documented and
defined below. */
bool
-diagnostic_context::diagnostic_n_impl (rich_location *richloc,
+diagnostics::context::diagnostic_n_impl (rich_location *richloc,
const diagnostics::metadata *metadata,
diagnostic_option_id option_id,
unsigned HOST_WIDE_INT n,
/* Emit DIAGRAM to this context, respecting the output format. */
void
-diagnostic_context::emit_diagram (const diagnostics::diagram &diag)
+diagnostics::context::emit_diagram (const diagnostics::diagram &diag)
{
if (m_diagrams.m_theme == nullptr)
return;
This mustn't use internal_error, that will cause infinite recursion. */
void
-diagnostic_context::error_recursion ()
+diagnostics::context::error_recursion ()
{
if (m_lock < 3)
pp_newline_and_flush (m_reference_printer);
internal_error ("in %s, at %s:%d", function, trim_filename (file), line);
}
-/* class diagnostic_context. */
+/* class diagnostics::context. */
void
-diagnostic_context::begin_group ()
+diagnostics::context::begin_group ()
{
m_diagnostic_groups.m_group_nesting_depth++;
}
void
-diagnostic_context::end_group ()
+diagnostics::context::end_group ()
{
if (--m_diagnostic_groups.m_group_nesting_depth == 0)
{
}
void
-diagnostic_context::push_nesting_level ()
+diagnostics::context::push_nesting_level ()
{
++m_diagnostic_groups.m_diagnostic_nesting_level;
}
void
-diagnostic_context::pop_nesting_level ()
+diagnostics::context::pop_nesting_level ()
{
--m_diagnostic_groups.m_diagnostic_nesting_level;
/* We're popping one level, so might need to stop inhibiting notes. */
file-based output formats. */
void
-diagnostics::output_format_init (diagnostic_context &context,
+diagnostics::output_format_init (diagnostics::context &context,
const char *main_input_filename_,
const char *base_file_name,
enum diagnostics_output_format format,
(or nullptr for "no diagrams"). */
void
-diagnostic_context::
+diagnostics::context::
set_text_art_charset (enum diagnostic_text_art_charset charset)
{
delete m_diagrams.m_theme;
to this function. */
void
-diagnostic_context::set_diagnostic_buffer (diagnostics::buffer *buffer_)
+diagnostics::context::set_diagnostic_buffer (diagnostics::buffer *buffer_)
{
/* We don't allow changing buffering within a diagnostic group
(to simplify handling of buffered diagnostics within the
/* Clear BUFFER without flushing it. */
void
-diagnostic_context::clear_diagnostic_buffer (diagnostics::buffer &buffer_)
+diagnostics::context::clear_diagnostic_buffer (diagnostics::buffer &buffer_)
{
if (buffer_.m_per_sink_buffers)
for (auto per_sink_buffer_ : *buffer_.m_per_sink_buffers)
/* Flush the diagnostics in BUFFER to this context, clearing BUFFER. */
void
-diagnostic_context::flush_diagnostic_buffer (diagnostics::buffer &buffer_)
+diagnostics::context::flush_diagnostic_buffer (diagnostics::buffer &buffer_)
{
bool had_errors
= (buffer_.m_diagnostic_counters.m_count_for_kind[DK_ERROR] > 0
check_max_errors (true);
}
-/* struct diagnostic_counters. */
+/* struct diagnostics::counters. */
-diagnostic_counters::diagnostic_counters ()
+diagnostics::counters::counters ()
{
clear ();
}
void
-diagnostic_counters::dump (FILE *out, int indent) const
+diagnostics::counters::dump (FILE *out, int indent) const
{
fprintf (out, "%*scounts:\n", indent, "");
bool none = true;
}
void
-diagnostic_counters::move_to (diagnostic_counters &dest)
+diagnostics::counters::move_to (diagnostics::counters &dest)
{
for (int i = 0; i < DK_LAST_DIAGNOSTIC_KIND; i++)
dest.m_count_for_kind[i] += m_count_for_kind[i];
}
void
-diagnostic_counters::clear ()
+diagnostics::counters::clear ()
{
memset (&m_count_for_kind, 0, sizeof m_count_for_kind);
}
/* class diagnostics::buffer. */
-diagnostics::buffer::buffer (diagnostic_context &ctxt)
+diagnostics::buffer::buffer (diagnostics::context &ctxt)
: m_ctxt (ctxt),
m_per_sink_buffers (nullptr)
{
}
/* Verify that
- diagnostic_column_policy::get_location_text (..., SHOW_COLUMN, ...)
+ diagnostics::column_policy::get_location_text (..., SHOW_COLUMN, ...)
generates EXPECTED_LOC_TEXT, given FILENAME, LINE, COLUMN, with
colorization disabled. */
xloc.data = nullptr;
xloc.sysp = false;
- diagnostic_column_policy column_policy (dc);
+ diagnostics::column_policy column_policy (dc);
label_text actual_loc_text
= column_policy.get_location_text (xloc, show_column, false);
ASSERT_STREQ (expected_loc_text, actual_loc_text.get ());
#include "diagnostics/diagnostic-info.h"
typedef diagnostics::diagnostic_info diagnostic_info;
-/* Forward declarations. */
-class diagnostic_location_print_policy;
-class diagnostic_source_print_policy;
-
-typedef void (*diagnostic_text_starter_fn) (diagnostics::text_sink &,
- const diagnostic_info *);
-
-struct to_text;
-struct to_html;
-
-extern pretty_printer *get_printer (to_text &);
-
-template <typename Sink>
-using diagnostic_start_span_fn = void (*) (const diagnostic_location_print_policy &,
- Sink &sink,
- expanded_location);
-
-typedef void (*diagnostic_text_finalizer_fn) (diagnostics::text_sink &,
- const diagnostic_info *,
- diagnostic_t);
-
-/* Abstract base class for the diagnostic subsystem to make queries
- about command-line options. */
-
-class diagnostic_option_manager
-{
-public:
- virtual ~diagnostic_option_manager () {}
-
- /* Return 1 if option OPTION_ID is enabled, 0 if it is disabled,
- or -1 if it isn't a simple on-off switch
- (or if the value is unknown, typically set later in target). */
- virtual int option_enabled_p (diagnostic_option_id option_id) const = 0;
-
- /* Return malloced memory for the name of the option OPTION_ID
- which enabled a diagnostic, originally of type ORIG_DIAG_KIND but
- possibly converted to DIAG_KIND by options such as -Werror.
- May return NULL if no name is to be printed.
- May be passed 0 as well as the index of a particular option. */
- virtual char *make_option_name (diagnostic_option_id option_id,
- diagnostic_t orig_diag_kind,
- diagnostic_t diag_kind) const = 0;
-
- /* Return malloced memory for a URL describing the option that controls
- a diagnostic.
- May return NULL if no URL is available.
- May be passed 0 as well as the index of a particular option. */
- virtual char *make_option_url (diagnostic_option_id option_id) const = 0;
-};
-
-/* A stack of sets of classifications: each entry in the stack is
- a mapping from option index to diagnostic severity that can be changed
- via pragmas. The stack can be pushed and popped. */
-
-class diagnostic_option_classifier
-{
-public:
- void init (int n_opts);
- void fini ();
-
- /* Save all diagnostic classifications in a stack. */
- void push ();
-
- /* Restore the topmost classification set off the stack. If the stack
- is empty, revert to the state based on command line parameters. */
- void pop (location_t where);
-
- bool option_unspecified_p (diagnostic_option_id option_id) const
- {
- return get_current_override (option_id) == DK_UNSPECIFIED;
- }
-
- diagnostic_t get_current_override (diagnostic_option_id option_id) const
- {
- gcc_assert (option_id.m_idx < m_n_opts);
- return m_classify_diagnostic[option_id.m_idx];
- }
-
- diagnostic_t
- classify_diagnostic (const diagnostic_context *context,
- diagnostic_option_id option_id,
- diagnostic_t new_kind,
- location_t where);
-
- diagnostic_t
- update_effective_level_from_pragmas (diagnostic_info *diagnostic) const;
-
- int pch_save (FILE *);
- int pch_restore (FILE *);
-
-private:
- /* Each time a diagnostic's classification is changed with a pragma,
- we record the change and the location of the change in an array of
- these structs. */
- struct diagnostic_classification_change_t
- {
- location_t location;
-
- /* For DK_POP, this is the index of the corresponding push (as stored
- in m_push_list).
- Otherwise, this is an option index. */
- int option;
-
- diagnostic_t kind;
- };
-
- 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
- options), this array may contain a new kind that the diagnostic
- 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 *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. */
- vec<diagnostic_classification_change_t> m_classification_history;
-
- /* For diagnostic_context::get_classification_history, declared later. */
- friend class diagnostic_context;
-
- /* For pragma push/pop. */
- vec<int> m_push_list;
-};
-
-/* A bundle of options relating to printing the user's source code
- (potentially with a margin, underlining, labels, etc). */
-
-struct diagnostic_source_printing_options
-{
- /* True if we should print the source line with a caret indicating
- the location.
- Corresponds to -fdiagnostics-show-caret. */
- bool enabled;
-
- /* Maximum width of the source line printed. */
- int max_width;
-
- /* Character used at the caret when printing source locations. */
- char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES];
-
- /* When printing source code, should the characters at carets and ranges
- be colorized? (assuming colorization is on at all).
- This should be true for frontends that generate range information
- (so that the ranges of code are colorized),
- and false for frontends that merely specify points within the
- source code (to avoid e.g. colorizing just the first character in
- a token, which would look strange). */
- bool colorize_source_p;
-
- /* When printing source code, should labelled ranges be printed?
- Corresponds to -fdiagnostics-show-labels. */
- bool show_labels_p;
-
- /* When printing source code, should there be a left-hand margin
- showing line numbers?
- Corresponds to -fdiagnostics-show-line-numbers. */
- bool show_line_numbers_p;
-
- /* If printing source code, what should the minimum width of the margin
- be? Line numbers will be right-aligned, and padded to this width.
- Corresponds to -fdiagnostics-minimum-margin-width=VALUE. */
- int min_margin_width;
-
- /* Usable by plugins; if true, print a debugging ruler above the
- source output. */
- bool show_ruler_p;
-
- /* When printing events in an inline path, should we print lines
- visualizing links between related events (e.g. for CFG paths)?
- Corresponds to -fdiagnostics-show-event-links. */
- bool show_event_links_p;
-};
-
-/* A bundle of state for determining column numbers in diagnostics
- (tab stops, whether to start at 0 or 1, etc).
- Uses a file_cache to handle tabs. */
-
-class diagnostic_column_policy
-{
-public:
- diagnostic_column_policy (const diagnostic_context &dc);
-
- int converted_column (expanded_location s) const;
-
- label_text get_location_text (const expanded_location &s,
- bool show_column,
- bool colorize) const;
-
- int get_tabstop () const { return m_tabstop; }
-
-private:
- file_cache &m_file_cache;
- enum diagnostics_column_unit m_column_unit;
- int m_column_origin;
- int m_tabstop;
-};
-
-/* A bundle of state for printing locations within diagnostics
- (e.g. "FILENAME:LINE:COLUMN"), to isolate the interactions between
- diagnostic_context and the start_span callbacks. */
-
-class diagnostic_location_print_policy
-{
-public:
- diagnostic_location_print_policy (const diagnostic_context &dc);
- diagnostic_location_print_policy (const diagnostics::text_sink &);
-
- bool show_column_p () const { return m_show_column; }
-
- const diagnostic_column_policy &
- get_column_policy () const { return m_column_policy; }
-
- void
- print_text_span_start (const diagnostic_context &dc,
- pretty_printer &pp,
- const expanded_location &exploc);
-
- void
- print_html_span_start (const diagnostic_context &dc,
- xml::printer &xp,
- const expanded_location &exploc);
-
-private:
- diagnostic_column_policy m_column_policy;
- bool m_show_column;
-};
-
-/* Abstract base class for optionally supplying extra tags when writing
- out annotation labels in HTML output. */
-
-class html_label_writer
-{
-public:
- virtual ~html_label_writer () {}
- virtual void begin_label () = 0;
- virtual void end_label () = 0;
-};
-
-/* A bundle of state for printing source within a diagnostic,
- to isolate the interactions between diagnostic_context and the
- implementation of diagnostic_show_locus. */
-
-class diagnostic_source_print_policy
-{
-public:
- diagnostic_source_print_policy (const diagnostic_context &);
- diagnostic_source_print_policy (const diagnostic_context &,
- const diagnostic_source_printing_options &);
-
- void
- print (pretty_printer &pp,
- const rich_location &richloc,
- diagnostic_t diagnostic_kind,
- diagnostics::source_effect_info *effect_info) const;
-
- void
- print_as_html (xml::printer &xp,
- const rich_location &richloc,
- diagnostic_t diagnostic_kind,
- diagnostics::source_effect_info *effect_info,
- html_label_writer *label_writer) const;
-
- const diagnostic_source_printing_options &
- get_options () const { return m_options; }
-
- diagnostic_start_span_fn<to_text>
- get_text_start_span_fn () const { return m_text_start_span_cb; }
-
- diagnostic_start_span_fn<to_html>
- get_html_start_span_fn () const { return m_html_start_span_cb; }
-
- file_cache &
- get_file_cache () const { return m_file_cache; }
-
- enum diagnostics_escape_format
- get_escape_format () const
- {
- return m_escape_format;
- }
-
- text_art::theme *
- get_diagram_theme () const { return m_diagram_theme; }
-
- const diagnostic_column_policy &get_column_policy () const
- {
- return m_location_policy.get_column_policy ();
- }
-
- const diagnostic_location_print_policy &get_location_policy () const
- {
- return m_location_policy;
- }
-
-private:
- const diagnostic_source_printing_options &m_options;
- class diagnostic_location_print_policy m_location_policy;
- diagnostic_start_span_fn<to_text> m_text_start_span_cb;
- diagnostic_start_span_fn<to_html> m_html_start_span_cb;
- file_cache &m_file_cache;
-
- /* Other data copied from diagnostic_context. */
- text_art::theme *m_diagram_theme;
- enum diagnostics_escape_format m_escape_format;
-};
-
-/* A collection of counters of diagnostics, per-kind
- (e.g. "3 errors and 1 warning"), for use by both diagnostic_context
- and by diagnostics::buffer. */
-
-struct diagnostic_counters
-{
- diagnostic_counters ();
-
- void dump (FILE *out, int indent) const;
- void DEBUG_FUNCTION dump () const { dump (stderr, 0); }
-
- int get_count (diagnostic_t kind) const { return m_count_for_kind[kind]; }
-
- void move_to (diagnostic_counters &dest);
- void clear ();
-
- int m_count_for_kind[DK_LAST_DIAGNOSTIC_KIND];
-};
-
-/* This class encapsulates the state of the diagnostics subsystem
- as a whole (either directly, or via owned objects of other classes, to
- avoid global variables).
-
- It has responsibility for:
- - being a central place for clients to report diagnostics
- - reporting those diagnostics to zero or more output sinks
- (e.g. text vs SARIF)
- - providing a "dump" member function for a debug dump of the state of
- the diagnostics subsytem
- - direct vs buffered diagnostics (see class diagnostics::buffer)
- - tracking the original argv of the program (for SARIF output)
- - crash-handling
-
- It delegates responsibility to various other classes:
- - the various output sinks (instances of diagnostics::sink
- subclasses)
- - formatting of messages (class pretty_printer)
- - an optional urlifier to inject URLs into formatted messages
- - counting the number of diagnostics reported of each kind
- (class diagnostic_counters)
- - calling out to a diagnostic_option_manager to determine if
- a particular warning is enabled or disabled
- - tracking pragmas that enable/disable warnings in a range of
- source code
- - a cache for use when quoting the user's source code (class file_cache)
- - a text_art::theme
- - a diagnostics::edit_context for generating patches from fix-it hints
- - diagnostics::client_data_hooks for metadata.
-
- Try to avoid adding new responsibilities to this class itself, to avoid
- the "blob" anti-pattern. */
-
-class diagnostic_context
-{
-public:
- /* Give access to m_text_callbacks. */
- friend diagnostic_text_starter_fn &
- diagnostic_text_starter (diagnostic_context *context);
- friend diagnostic_start_span_fn<to_text> &
- diagnostic_start_span (diagnostic_context *context);
- friend diagnostic_text_finalizer_fn &
- diagnostic_text_finalizer (diagnostic_context *context);
-
- friend class diagnostic_source_print_policy;
- friend class diagnostics::text_sink;
- friend class diagnostics::buffer;
-
- 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 set_pretty_printer (std::unique_ptr<pretty_printer> pp);
- void refresh_output_sinks ();
-
- void finish ();
-
- void dump (FILE *out) const;
- void DEBUG_FUNCTION dump () const { dump (stderr); }
-
- bool execution_failed_p () const;
-
- void set_original_argv (unique_argv original_argv);
- const char * const *get_original_argv ()
- {
- return const_cast<const char * const *> (m_original_argv);
- }
-
- 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 ();
-
- void push_nesting_level ();
- void pop_nesting_level ();
-
- bool warning_enabled_at (location_t loc, diagnostic_option_id option_id);
-
- bool option_unspecified_p (diagnostic_option_id option_id) const
- {
- return m_option_classifier.option_unspecified_p (option_id);
- }
-
- bool emit_diagnostic_with_group (diagnostic_t kind,
- rich_location &richloc,
- const diagnostics::metadata *metadata,
- diagnostic_option_id option_id,
- const char *gmsgid, ...)
- ATTRIBUTE_GCC_DIAG(6,7);
- bool emit_diagnostic_with_group_va (diagnostic_t kind,
- rich_location &richloc,
- const diagnostics::metadata *metadata,
- diagnostic_option_id option_id,
- const char *gmsgid, va_list *ap)
- ATTRIBUTE_GCC_DIAG(6,0);
-
- bool report_diagnostic (diagnostic_info *);
- void report_verbatim (text_info &);
-
- /* Report a directed graph associated with the run as a whole
- to any sinks that support directed graphs. */
- void
- report_global_digraph (const diagnostics::digraphs::lazy_digraph &);
-
- diagnostic_t
- classify_diagnostic (diagnostic_option_id option_id,
- diagnostic_t new_kind,
- location_t where)
- {
- return m_option_classifier.classify_diagnostic (this,
- option_id,
- new_kind,
- where);
- }
-
- void push_diagnostics (location_t where ATTRIBUTE_UNUSED)
- {
- m_option_classifier.push ();
- }
- void pop_diagnostics (location_t where)
- {
- m_option_classifier.pop (where);
- }
-
- void maybe_show_locus (const rich_location &richloc,
- const diagnostic_source_printing_options &opts,
- diagnostic_t diagnostic_kind,
- pretty_printer &pp,
- diagnostics::source_effect_info *effect_info);
- void maybe_show_locus_as_html (const rich_location &richloc,
- const diagnostic_source_printing_options &opts,
- diagnostic_t diagnostic_kind,
- xml::printer &xp,
- diagnostics::source_effect_info *effect_info,
- html_label_writer *label_writer);
-
- void emit_diagram (const diagnostics::diagram &diag);
-
- /* Various setters for use by option-handling logic. */
- void set_sink (std::unique_ptr<diagnostics::sink> sink_);
- void set_text_art_charset (enum diagnostic_text_art_charset charset);
- void set_client_data_hooks (std::unique_ptr<diagnostics::client_data_hooks> hooks);
-
- void push_owned_urlifier (std::unique_ptr<urlifier>);
- void push_borrowed_urlifier (const urlifier &);
- void pop_urlifier ();
-
- 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_show_highlight_colors (bool 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_format_decoder (printer_fn format_decoder);
- void set_prefixing_rule (diagnostic_prefixing_rule_t rule);
-
- /* 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; }
- diagnostics::sink &get_sink (size_t idx) const;
- 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
- {
- gcc_assert (m_file_cache);
- return *m_file_cache;
- }
-
- diagnostics::edit_context *get_edit_context () const
- {
- return m_edit_context_ptr;
- }
- const diagnostics::client_data_hooks *get_client_data_hooks () const
- {
- return m_client_data_hooks;
- }
-
- const diagnostics::logical_locations::manager *
- get_logical_location_manager () const;
-
- const urlifier *get_urlifier () const;
-
- text_art::theme *get_diagram_theme () const { return m_diagrams.m_theme; }
-
- int &diagnostic_count (diagnostic_t kind)
- {
- return m_diagnostic_counters.m_count_for_kind[kind];
- }
- int diagnostic_count (diagnostic_t kind) const
- {
- return m_diagnostic_counters.get_count (kind);
- }
-
- /* Option-related member functions. */
- inline bool option_enabled_p (diagnostic_option_id option_id) const
- {
- if (!m_option_mgr)
- return true;
- return m_option_mgr->option_enabled_p (option_id);
- }
-
- inline char *make_option_name (diagnostic_option_id option_id,
- diagnostic_t orig_diag_kind,
- diagnostic_t diag_kind) const
- {
- if (!m_option_mgr)
- return nullptr;
- return m_option_mgr->make_option_name (option_id,
- orig_diag_kind,
- diag_kind);
- }
-
- inline char *make_option_url (diagnostic_option_id option_id) const
- {
- if (!m_option_mgr)
- return nullptr;
- return m_option_mgr->make_option_url (option_id);
- }
-
- void
- set_option_manager (std::unique_ptr<diagnostic_option_manager> mgr,
- unsigned lang_mask);
-
- unsigned get_lang_mask () const
- {
- return m_lang_mask;
- }
-
- bool diagnostic_impl (rich_location *, const diagnostics::metadata *,
- diagnostic_option_id, const char *,
- va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(5,0);
- bool diagnostic_n_impl (rich_location *, const diagnostics::metadata *,
- diagnostic_option_id, unsigned HOST_WIDE_INT,
- const char *, const char *, va_list *,
- diagnostic_t) ATTRIBUTE_GCC_DIAG(7,0);
-
- int get_diagnostic_nesting_level () const
- {
- return m_diagnostic_groups.m_diagnostic_nesting_level;
- }
-
- char *build_indent_prefix () const;
-
- int
- pch_save (FILE *f)
- {
- return m_option_classifier.pch_save (f);
- }
-
- int
- pch_restore (FILE *f)
- {
- return m_option_classifier.pch_restore (f);
- }
-
-
- void set_diagnostic_buffer (diagnostics::buffer *);
- diagnostics::buffer *get_diagnostic_buffer () const
- {
- return m_diagnostic_buffer;
- }
- void clear_diagnostic_buffer (diagnostics::buffer &);
- void flush_diagnostic_buffer (diagnostics::buffer &);
-
- std::unique_ptr<pretty_printer> clone_printer () const
- {
- return m_reference_printer->clone ();
- }
-
- pretty_printer *get_reference_printer () const
- {
- return m_reference_printer;
- }
-
- void
- add_sink (std::unique_ptr<diagnostics::sink>);
-
- void remove_all_output_sinks ();
-
- bool supports_fnotice_on_stderr_p () const;
-
- /* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher. */
- void
- set_abort_on_error (bool val)
- {
- m_abort_on_error = val;
- }
-
- /* Accessor for use in serialization, e.g. by C++ modules. */
- auto &
- get_classification_history ()
- {
- return m_option_classifier.m_classification_history;
- }
-
- void set_main_input_filename (const char *filename);
-
- void
- set_permissive_option (diagnostic_option_id opt_permissive)
- {
- m_opt_permissive = opt_permissive;
- }
-
- void
- set_fatal_errors (bool fatal_errors)
- {
- m_fatal_errors = fatal_errors;
- }
-
- void
- set_internal_error_callback (void (*cb) (diagnostic_context *,
- const char *,
- va_list *))
- {
- m_internal_error = cb;
- }
-
- void
- set_adjust_diagnostic_info_callback (void (*cb) (diagnostic_context *,
- diagnostic_info *))
- {
- m_adjust_diagnostic_info = cb;
- }
-
- void
- inhibit_notes () { m_inhibit_notes_p = true; }
-
-private:
- void error_recursion () ATTRIBUTE_NORETURN;
-
- bool diagnostic_enabled (diagnostic_info *diagnostic);
-
- void get_any_inlining_info (diagnostic_info *diagnostic);
-
- void check_max_errors (bool flush);
- void action_after_output (diagnostic_t diag_kind);
-
- /* Data members.
- Ideally, all of these would be private. */
-
-private:
- /* A reference instance of pretty_printer created by the client
- and owned by the context. Used for cloning when creating/adding
- output formats.
- Owned by the context; this would be a std::unique_ptr if
- diagnostic_context had a proper ctor. */
- pretty_printer *m_reference_printer;
-
- /* Cache of source code.
- Owned by the context; this would be a std::unique_ptr if
- diagnostic_context had a proper ctor. */
- file_cache *m_file_cache;
-
- /* The number of times we have issued diagnostics. */
- diagnostic_counters m_diagnostic_counters;
-
- /* True if it has been requested that warnings be treated as errors. */
- bool m_warning_as_error_requested;
-
- /* The number of option indexes that can be passed to warning() et
- al. */
- int m_n_opts;
-
- /* The stack of sets of overridden diagnostic option severities. */
- diagnostic_option_classifier m_option_classifier;
-
- /* True if we should print any CWE identifiers associated with
- diagnostics. */
- bool m_show_cwe;
-
- /* True if we should print any rules associated with diagnostics. */
- bool m_show_rules;
-
- /* How should diagnostics::paths::path objects be printed. */
- enum diagnostic_path_format m_path_format;
-
- /* True if we should print stack depths when printing diagnostic paths. */
- bool m_show_path_depths;
-
- /* True if we should print the command line option which controls
- each diagnostic, if known. */
- bool m_show_option_requested;
-
- /* True if we should raise a SIGABRT on errors. */
- bool m_abort_on_error;
-
-public:
- /* True if we should show the column number on diagnostics. */
- bool m_show_column;
-
- /* True if pedwarns are errors. */
- bool m_pedantic_errors;
-
- /* True if permerrors are warnings. */
- bool m_permissive;
-
-private:
- /* The option to associate with turning permerrors into warnings,
- if any. */
- diagnostic_option_id m_opt_permissive;
-
- /* True if errors are fatal. */
- bool m_fatal_errors;
-
-public:
- /* True if all warnings should be disabled. */
- bool m_inhibit_warnings;
-
- /* True if warnings should be given in system headers. */
- bool m_warn_system_headers;
-
-private:
- /* Maximum number of errors to report. */
- int m_max_errors;
-
- /* Client-supplied callbacks for use in text output. */
- struct {
- /* This function is called before any message is printed out. It is
- responsible for preparing message prefix and such. For example, it
- might say:
- In file included from "/usr/local/include/curses.h:5:
- from "/home/gdr/src/nifty_printer.h:56:
- ...
- */
- diagnostic_text_starter_fn m_begin_diagnostic;
-
- /* This function is called by diagnostic_show_locus in between
- disjoint spans of source code, so that the context can print
- something to indicate that a new span of source code has begun. */
- diagnostic_start_span_fn<to_text> m_text_start_span;
- diagnostic_start_span_fn<to_html> m_html_start_span;
-
- /* This function is called after the diagnostic message is printed. */
- diagnostic_text_finalizer_fn m_end_diagnostic;
- } m_text_callbacks;
-
- /* Client hook to report an internal error. */
- void (*m_internal_error) (diagnostic_context *, const char *, va_list *);
-
- /* Client hook to adjust properties of the given diagnostic that we're
- about to issue, such as its kind. */
- void (*m_adjust_diagnostic_info)(diagnostic_context *, diagnostic_info *);
-
- /* Owned by the context; this would be a std::unique_ptr if
- diagnostic_context had a proper ctor. */
- diagnostic_option_manager *m_option_mgr;
- unsigned m_lang_mask;
-
- /* A stack of optional hooks for adding URLs to quoted text strings in
- diagnostics. Only used for the main diagnostic message.
- Typically a single one owner by the context, but can be temporarily
- overridden by a borrowed urlifier (e.g. on-stack). */
- struct urlifier_stack_node
- {
- urlifier *m_urlifier;
- bool m_owned;
- };
- auto_vec<urlifier_stack_node> *m_urlifier_stack;
-
-public:
- /* Auxiliary data for client. */
- void *m_client_aux_data;
-
- /* Used to detect that the last caret was printed at the same location. */
- location_t m_last_location;
-
-private:
- int m_lock;
-
- bool m_inhibit_notes_p;
-
-public:
- diagnostic_source_printing_options m_source_printing;
-
-private:
- /* True if -freport-bug option is used. */
- 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 m_extra_output_kind;
-
-public:
- /* What units to use when outputting the column number. */
- enum diagnostics_column_unit m_column_unit;
-
- /* The origin for the column number (1-based or 0-based typically). */
- int m_column_origin;
-
- /* The size of the tabstop for tab expansion. */
- 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 m_escape_format;
-
- /* If non-NULL, an edit_context to which fix-it hints should be
- applied, for generating patches.
- Owned by the context; this would be a std::unique_ptr if
- diagnostic_context had a proper ctor. */
- diagnostics::edit_context *m_edit_context_ptr;
-
- /* Fields relating to diagnostic groups. */
- struct {
- /* How many diagnostic_group instances are currently alive. */
- int m_group_nesting_depth;
-
- /* How many nesting levels have been pushed within this group. */
- int m_diagnostic_nesting_level;
-
- /* How many diagnostics have been emitted since the bottommost
- diagnostic_group was pushed. */
- int m_emission_count;
-
- /* The "group+diagnostic" nesting depth from which to inhibit notes. */
- int m_inhibiting_notes_from;
- } m_diagnostic_groups;
-
- void inhibit_notes_in_group (bool inhibit = true);
- bool notes_inhibited_in_group () const;
-
- /* The various sinks to which diagnostics are to be outputted
- (text vs structured formats such as SARIF).
- The sinks are owned by the context; this would be a
- std::vector<std::unique_ptr> if diagnostic_context had a
- proper ctor. */
- auto_vec<diagnostics::sink *> m_sinks;
-
- /* Callback to set the locations of call sites along the inlining
- stack corresponding to a diagnostic location. Needed to traverse
- the BLOCK_SUPERCONTEXT() chain hanging off the LOCATION_BLOCK()
- of a diagnostic's location. */
- set_locations_callback_t m_set_locations_cb;
-
- /* A bundle of hooks for providing data to the context about its client
- e.g. version information, plugins, etc.
- Used by SARIF output to give metadata about the client that's
- producing diagnostics.
- Owned by the context; this would be a std::unique_ptr if
- diagnostic_context had a proper ctor. */
- diagnostics::client_data_hooks *m_client_data_hooks;
-
- /* Support for diagrams. */
- struct
- {
- /* Theme to use when generating diagrams.
- Can be NULL (if text art is disabled).
- Owned by the context; this would be a std::unique_ptr if
- diagnostic_context had a proper ctor. */
- text_art::theme *m_theme;
-
- } m_diagrams;
-
- /* Owned by the context. */
- char **m_original_argv;
-
- /* Borrowed pointer to the active diagnostics::buffer, if any.
- If null (the default), then diagnostics that are reported to the
- context are immediately issued to the output format.
- If non-null, then diagnostics that are reported to the context
- are buffered in the buffer, and may be issued to the output format
- later (if the buffer is flushed), moved to other buffers, or
- discarded (if the buffer is cleared). */
- diagnostics::buffer *m_diagnostic_buffer;
-};
-
-/* Client supplied function to announce a diagnostic
- (for text-based diagnostic output). */
-inline diagnostic_text_starter_fn &
-diagnostic_text_starter (diagnostic_context *context)
-{
- return context->m_text_callbacks.m_begin_diagnostic;
-}
-
-/* Client supplied function called between disjoint spans of source code,
- so that the context can print
- something to indicate that a new span of source code has begun. */
-inline diagnostic_start_span_fn<to_text> &
-diagnostic_start_span (diagnostic_context *context)
-{
- return context->m_text_callbacks.m_text_start_span;
-}
-
-/* Client supplied function called after a diagnostic message is
- displayed (for text-based diagnostic output). */
-inline diagnostic_text_finalizer_fn &
-diagnostic_text_finalizer (diagnostic_context *context)
-{
- return context->m_text_callbacks.m_end_diagnostic;
-}
+#include "diagnostics/context.h"
/* Extension hooks for client. */
#define diagnostic_context_auxiliary_data(DC) (DC)->m_client_aux_data
#define diagnostic_info_auxiliary_data(DI) (DI)->m_x_data
-/* This diagnostic_context is used by front-ends that directly output
+/* This diagnostics::context is used by front-ends that directly output
diagnostic messages without going through `error', `warning',
and similar functions. */
-extern diagnostic_context *global_dc;
+extern diagnostics::context *global_dc;
/* The number of errors that have been issued so far. Ideally, these
- would take a diagnostic_context as an argument. */
+ would take a diagnostics::context as an argument. */
#define errorcount global_dc->diagnostic_count (DK_ERROR)
/* Similarly, but for warnings. */
#define warningcount global_dc->diagnostic_count (DK_WARNING)
/* Diagnostic related functions. */
inline void
-diagnostic_initialize (diagnostic_context *context, int n_opts)
+diagnostic_initialize (diagnostics::context *context, int n_opts)
{
context->initialize (n_opts);
}
inline void
-diagnostic_color_init (diagnostic_context *context, int value = -1)
+diagnostic_color_init (diagnostics::context *context, int value = -1)
{
context->color_init (value);
}
inline void
-diagnostic_urls_init (diagnostic_context *context, int value = -1)
+diagnostic_urls_init (diagnostics::context *context, int value = -1)
{
context->urls_init (value);
}
inline void
-diagnostic_finish (diagnostic_context *context)
+diagnostic_finish (diagnostics::context *context)
{
context->finish ();
}
inline void
-diagnostic_show_locus (diagnostic_context *context,
- const diagnostic_source_printing_options &opts,
+diagnostic_show_locus (diagnostics::context *context,
+ const diagnostics::source_printing_options &opts,
rich_location *richloc,
diagnostic_t diagnostic_kind,
pretty_printer *pp,
}
inline void
-diagnostic_show_locus_as_html (diagnostic_context *context,
- const diagnostic_source_printing_options &opts,
+diagnostic_show_locus_as_html (diagnostics::context *context,
+ const diagnostics::source_printing_options &opts,
rich_location *richloc,
diagnostic_t diagnostic_kind,
xml::printer &xp,
diagnostics::source_effect_info *effect_info = nullptr,
- html_label_writer *label_writer = nullptr)
+ diagnostics::html_label_writer *label_writer = nullptr)
{
gcc_assert (context);
gcc_assert (richloc);
rather skipped as part of the conversion process.) */
inline void
-diagnostic_initialize_input_context (diagnostic_context *context,
+diagnostic_initialize_input_context (diagnostics::context *context,
diagnostic_input_charset_callback ccb,
bool should_skip_bom)
{
/* Force diagnostics controlled by OPTIDX to be kind KIND. */
inline diagnostic_t
-diagnostic_classify_diagnostic (diagnostic_context *context,
+diagnostic_classify_diagnostic (diagnostics::context *context,
diagnostic_option_id option_id,
diagnostic_t kind,
location_t where)
}
inline void
-diagnostic_push_diagnostics (diagnostic_context *context,
+diagnostic_push_diagnostics (diagnostics::context *context,
location_t where)
{
context->push_diagnostics (where);
}
inline void
-diagnostic_pop_diagnostics (diagnostic_context *context,
+diagnostic_pop_diagnostics (diagnostics::context *context,
location_t where)
{
context->pop_diagnostics (where);
Return true if a diagnostic was printed, false otherwise. */
inline bool
-diagnostic_report_diagnostic (diagnostic_context *context,
+diagnostic_report_diagnostic (diagnostics::context *context,
diagnostic_info *diagnostic)
{
context->begin_group ();
void default_text_starter (diagnostics::text_sink &,
const diagnostic_info *);
template <typename Sink>
-void default_start_span_fn (const diagnostic_location_print_policy &,
+void default_start_span_fn (const diagnostics::location_print_policy &,
Sink &sink,
expanded_location);
void default_text_finalizer (diagnostics::text_sink &,
diagnostic_t);
} // namespace diagnostics
-void diagnostic_set_caret_max_width (diagnostic_context *context, int value);
+void diagnostic_set_caret_max_width (diagnostics::context *context, int value);
int get_terminal_width (void);
whether to print one or two caret lines. */
inline bool
-diagnostic_same_line (const diagnostic_context *context,
- expanded_location s1, expanded_location s2)
+diagnostic_same_line (const diagnostics::context *context,
+ expanded_location s1, expanded_location s2)
{
return (s2.column && s1.line == s2.line
&& (context->m_source_printing.max_width - CARET_LINE_MARGIN
class text_sink;
/* Class representing a buffer of zero or more diagnostics that
- have been reported to a diagnostic_context, but which haven't
+ have been reported to a diagnostics::context, but which haven't
yet been flushed.
A diagnostics::buffer can be:
- * flushed to the diagnostic_context, which issues
+ * flushed to the diagnostics::context, which issues
the diagnostics within the buffer to the output format
and checks for limits such as -fmax-errors=, or
Since a buffer needs to contain output-format-specific data,
it's not possible to change the output format of the
- diagnostic_context once any buffers are non-empty.
+ diagnostics::context once any buffers are non-empty.
To simplify implementing output formats, it's not possible
- to change buffering on a diagnostic_context whilst within a
+ to change buffering on a diagnostics::context whilst within a
diagnostic group. */
class buffer
{
public:
- friend class ::diagnostic_context;
+ friend class context;
- buffer (diagnostic_context &ctxt);
+ buffer (context &ctxt);
~buffer ();
void dump (FILE *out, int indent) const;
private:
void ensure_per_sink_buffers ();
- diagnostic_context &m_ctxt;
+ context &m_ctxt;
auto_vec<per_sink_buffer *> *m_per_sink_buffers;
/* The number of buffered diagnostics of each kind. */
- diagnostic_counters m_diagnostic_counters;
+ counters m_diagnostic_counters;
};
/* Implementation detail of diagnostics::buffer.
class sarif_object;
class client_version_info;
-/* A bundle of additional metadata, owned by the diagnostic_context,
+/* A bundle of additional metadata, owned by the diagnostics::context,
for querying things about the client, like version data. */
class client_data_hooks
class client_plugin_info;
-/* Abstract base class for a diagnostic_context to get at
+/* Abstract base class for a diagnostics::context to get at
version information about the client. */
class client_version_info
virtual void for_each_plugin (plugin_visitor &v) const = 0;
};
-/* Abstract base class for a diagnostic_context to get at
+/* Abstract base class for a diagnostics::context to get at
information about a specific plugin within a client. */
class client_plugin_info
--- /dev/null
+/* Declare diagnostics::context and related types.
+ Copyright (C) 2000-2025 Free Software Foundation, Inc.
+
+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_DIAGNOSTICS_CONTEXT_H
+#define GCC_DIAGNOSTICS_CONTEXT_H
+
+namespace diagnostics {
+
+/* Forward declarations. */
+class context;
+class location_print_policy;
+class source_print_policy;
+
+typedef void (*text_starter_fn) (text_sink &,
+ const diagnostic_info *);
+
+struct to_text;
+struct to_html;
+
+extern pretty_printer *get_printer (to_text &);
+
+template <typename Sink>
+using start_span_fn = void (*) (const location_print_policy &,
+ Sink &sink,
+ expanded_location);
+
+typedef void (*text_finalizer_fn) (text_sink &,
+ const diagnostic_info *,
+ diagnostic_t);
+
+/* Abstract base class for the diagnostic subsystem to make queries
+ about command-line options. */
+
+class option_manager
+{
+public:
+ virtual ~option_manager () {}
+
+ /* Return 1 if option OPTION_ID is enabled, 0 if it is disabled,
+ or -1 if it isn't a simple on-off switch
+ (or if the value is unknown, typically set later in target). */
+ virtual int option_enabled_p (diagnostic_option_id option_id) const = 0;
+
+ /* Return malloced memory for the name of the option OPTION_ID
+ which enabled a diagnostic, originally of type ORIG_DIAG_KIND but
+ possibly converted to DIAG_KIND by options such as -Werror.
+ May return NULL if no name is to be printed.
+ May be passed 0 as well as the index of a particular option. */
+ virtual char *make_option_name (diagnostic_option_id option_id,
+ diagnostic_t orig_diag_kind,
+ diagnostic_t diag_kind) const = 0;
+
+ /* Return malloced memory for a URL describing the option that controls
+ a diagnostic.
+ May return NULL if no URL is available.
+ May be passed 0 as well as the index of a particular option. */
+ virtual char *make_option_url (diagnostic_option_id option_id) const = 0;
+};
+
+/* A stack of sets of classifications: each entry in the stack is
+ a mapping from option index to diagnostic severity that can be changed
+ via pragmas. The stack can be pushed and popped. */
+
+class option_classifier
+{
+public:
+ void init (int n_opts);
+ void fini ();
+
+ /* Save all diagnostic classifications in a stack. */
+ void push ();
+
+ /* Restore the topmost classification set off the stack. If the stack
+ is empty, revert to the state based on command line parameters. */
+ void pop (location_t where);
+
+ bool option_unspecified_p (diagnostic_option_id option_id) const
+ {
+ return get_current_override (option_id) == DK_UNSPECIFIED;
+ }
+
+ diagnostic_t get_current_override (diagnostic_option_id option_id) const
+ {
+ gcc_assert (option_id.m_idx < m_n_opts);
+ return m_classify_diagnostic[option_id.m_idx];
+ }
+
+ diagnostic_t
+ classify_diagnostic (const context *context,
+ diagnostic_option_id option_id,
+ diagnostic_t new_kind,
+ location_t where);
+
+ diagnostic_t
+ update_effective_level_from_pragmas (diagnostic_info *diagnostic) const;
+
+ int pch_save (FILE *);
+ int pch_restore (FILE *);
+
+private:
+ /* Each time a diagnostic's classification is changed with a pragma,
+ we record the change and the location of the change in an array of
+ these structs. */
+ struct classification_change_t
+ {
+ location_t location;
+
+ /* For DK_POP, this is the index of the corresponding push (as stored
+ in m_push_list).
+ Otherwise, this is an option index. */
+ int option;
+
+ diagnostic_t kind;
+ };
+
+ 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
+ options), this array may contain a new kind that the diagnostic
+ 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 *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. */
+ vec<classification_change_t> m_classification_history;
+
+ /* For context::get_classification_history, declared later. */
+ friend class context;
+
+ /* For pragma push/pop. */
+ vec<int> m_push_list;
+};
+
+/* A bundle of options relating to printing the user's source code
+ (potentially with a margin, underlining, labels, etc). */
+
+struct source_printing_options
+{
+ /* True if we should print the source line with a caret indicating
+ the location.
+ Corresponds to -fdiagnostics-show-caret. */
+ bool enabled;
+
+ /* Maximum width of the source line printed. */
+ int max_width;
+
+ /* Character used at the caret when printing source locations. */
+ char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES];
+
+ /* When printing source code, should the characters at carets and ranges
+ be colorized? (assuming colorization is on at all).
+ This should be true for frontends that generate range information
+ (so that the ranges of code are colorized),
+ and false for frontends that merely specify points within the
+ source code (to avoid e.g. colorizing just the first character in
+ a token, which would look strange). */
+ bool colorize_source_p;
+
+ /* When printing source code, should labelled ranges be printed?
+ Corresponds to -fdiagnostics-show-labels. */
+ bool show_labels_p;
+
+ /* When printing source code, should there be a left-hand margin
+ showing line numbers?
+ Corresponds to -fdiagnostics-show-line-numbers. */
+ bool show_line_numbers_p;
+
+ /* If printing source code, what should the minimum width of the margin
+ be? Line numbers will be right-aligned, and padded to this width.
+ Corresponds to -fdiagnostics-minimum-margin-width=VALUE. */
+ int min_margin_width;
+
+ /* Usable by plugins; if true, print a debugging ruler above the
+ source output. */
+ bool show_ruler_p;
+
+ /* When printing events in an inline path, should we print lines
+ visualizing links between related events (e.g. for CFG paths)?
+ Corresponds to -fdiagnostics-show-event-links. */
+ bool show_event_links_p;
+};
+
+/* A bundle of state for determining column numbers in diagnostics
+ (tab stops, whether to start at 0 or 1, etc).
+ Uses a file_cache to handle tabs. */
+
+class column_policy
+{
+public:
+ column_policy (const context &dc);
+
+ int converted_column (expanded_location s) const;
+
+ label_text get_location_text (const expanded_location &s,
+ bool show_column,
+ bool colorize) const;
+
+ int get_tabstop () const { return m_tabstop; }
+
+private:
+ file_cache &m_file_cache;
+ enum diagnostics_column_unit m_column_unit;
+ int m_column_origin;
+ int m_tabstop;
+};
+
+/* A bundle of state for printing locations within diagnostics
+ (e.g. "FILENAME:LINE:COLUMN"), to isolate the interactions between
+ context and the start_span callbacks. */
+
+class location_print_policy
+{
+public:
+ location_print_policy (const context &dc);
+ location_print_policy (const text_sink &);
+
+ bool show_column_p () const { return m_show_column; }
+
+ const column_policy &
+ get_column_policy () const { return m_column_policy; }
+
+ void
+ print_text_span_start (const context &dc,
+ pretty_printer &pp,
+ const expanded_location &exploc);
+
+ void
+ print_html_span_start (const context &dc,
+ xml::printer &xp,
+ const expanded_location &exploc);
+
+private:
+ column_policy m_column_policy;
+ bool m_show_column;
+};
+
+/* Abstract base class for optionally supplying extra tags when writing
+ out annotation labels in HTML output. */
+
+class html_label_writer
+{
+public:
+ virtual ~html_label_writer () {}
+ virtual void begin_label () = 0;
+ virtual void end_label () = 0;
+};
+
+/* A bundle of state for printing source within a diagnostic,
+ to isolate the interactions between context and the
+ implementation of diagnostic_show_locus. */
+
+class source_print_policy
+{
+public:
+ source_print_policy (const context &);
+ source_print_policy (const context &,
+ const source_printing_options &);
+
+ void
+ print (pretty_printer &pp,
+ const rich_location &richloc,
+ diagnostic_t diagnostic_kind,
+ source_effect_info *effect_info) const;
+
+ void
+ print_as_html (xml::printer &xp,
+ const rich_location &richloc,
+ diagnostic_t diagnostic_kind,
+ source_effect_info *effect_info,
+ html_label_writer *label_writer) const;
+
+ const source_printing_options &
+ get_options () const { return m_options; }
+
+ start_span_fn<to_text>
+ get_text_start_span_fn () const { return m_text_start_span_cb; }
+
+ start_span_fn<to_html>
+ get_html_start_span_fn () const { return m_html_start_span_cb; }
+
+ file_cache &
+ get_file_cache () const { return m_file_cache; }
+
+ enum diagnostics_escape_format
+ get_escape_format () const
+ {
+ return m_escape_format;
+ }
+
+ text_art::theme *
+ get_diagram_theme () const { return m_diagram_theme; }
+
+ const column_policy &get_column_policy () const
+ {
+ return m_location_policy.get_column_policy ();
+ }
+
+ const location_print_policy &get_location_policy () const
+ {
+ return m_location_policy;
+ }
+
+private:
+ const source_printing_options &m_options;
+ location_print_policy m_location_policy;
+ start_span_fn<to_text> m_text_start_span_cb;
+ start_span_fn<to_html> m_html_start_span_cb;
+ file_cache &m_file_cache;
+
+ /* Other data copied from context. */
+ text_art::theme *m_diagram_theme;
+ enum diagnostics_escape_format m_escape_format;
+};
+
+/* A collection of counters of diagnostics, per-kind
+ (e.g. "3 errors and 1 warning"), for use by both context
+ and by diagnostics::buffer. */
+
+struct counters
+{
+ counters ();
+
+ void dump (FILE *out, int indent) const;
+ void DEBUG_FUNCTION dump () const { dump (stderr, 0); }
+
+ int get_count (diagnostic_t kind) const { return m_count_for_kind[kind]; }
+
+ void move_to (counters &dest);
+ void clear ();
+
+ int m_count_for_kind[DK_LAST_DIAGNOSTIC_KIND];
+};
+
+/* This class encapsulates the state of the diagnostics subsystem
+ as a whole (either directly, or via owned objects of other classes, to
+ avoid global variables).
+
+ It has responsibility for:
+ - being a central place for clients to report diagnostics
+ - reporting those diagnostics to zero or more output sinks
+ (e.g. text vs SARIF)
+ - providing a "dump" member function for a debug dump of the state of
+ the diagnostics subsytem
+ - direct vs buffered diagnostics (see class diagnostics::buffer)
+ - tracking the original argv of the program (for SARIF output)
+ - crash-handling
+
+ It delegates responsibility to various other classes:
+ - the various output sinks (instances of diagnostics::sink
+ subclasses)
+ - formatting of messages (class pretty_printer)
+ - an optional urlifier to inject URLs into formatted messages
+ - counting the number of diagnostics reported of each kind
+ (class diagnostics::counters)
+ - calling out to a option_manager to determine if
+ a particular warning is enabled or disabled
+ - tracking pragmas that enable/disable warnings in a range of
+ source code
+ - a cache for use when quoting the user's source code (class file_cache)
+ - a text_art::theme
+ - a diagnostics::edit_context for generating patches from fix-it hints
+ - diagnostics::client_data_hooks for metadata.
+
+ Try to avoid adding new responsibilities to this class itself, to avoid
+ the "blob" anti-pattern. */
+
+class context
+{
+public:
+ /* Give access to m_text_callbacks. */
+ // FIXME: these need updating
+ friend text_starter_fn &
+ text_starter (context *dc);
+ friend start_span_fn<to_text> &
+ start_span (context *dc);
+ friend text_finalizer_fn &
+ text_finalizer (context *dc);
+
+ friend class source_print_policy;
+ friend class text_sink;
+ friend class buffer;
+
+ typedef void (*set_locations_callback_t) (context *,
+ diagnostic_info *);
+
+ void initialize (int n_opts);
+ void color_init (int value);
+ void urls_init (int value);
+ void set_pretty_printer (std::unique_ptr<pretty_printer> pp);
+ void refresh_output_sinks ();
+
+ void finish ();
+
+ void dump (FILE *out) const;
+ void DEBUG_FUNCTION dump () const { dump (stderr); }
+
+ bool execution_failed_p () const;
+
+ void set_original_argv (unique_argv original_argv);
+ const char * const *get_original_argv ()
+ {
+ return const_cast<const char * const *> (m_original_argv);
+ }
+
+ 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 ();
+
+ void push_nesting_level ();
+ void pop_nesting_level ();
+
+ bool warning_enabled_at (location_t loc, diagnostic_option_id option_id);
+
+ bool option_unspecified_p (diagnostic_option_id option_id) const
+ {
+ return m_option_classifier.option_unspecified_p (option_id);
+ }
+
+ bool emit_diagnostic_with_group (diagnostic_t kind,
+ rich_location &richloc,
+ const metadata *metadata,
+ diagnostic_option_id option_id,
+ const char *gmsgid, ...)
+ ATTRIBUTE_GCC_DIAG(6,7);
+ bool emit_diagnostic_with_group_va (diagnostic_t kind,
+ rich_location &richloc,
+ const metadata *metadata,
+ diagnostic_option_id option_id,
+ const char *gmsgid, va_list *ap)
+ ATTRIBUTE_GCC_DIAG(6,0);
+
+ bool report_diagnostic (diagnostic_info *);
+ void report_verbatim (text_info &);
+
+ /* Report a directed graph associated with the run as a whole
+ to any sinks that support directed graphs. */
+ void
+ report_global_digraph (const digraphs::lazy_digraph &);
+
+ diagnostic_t
+ classify_diagnostic (diagnostic_option_id option_id,
+ diagnostic_t new_kind,
+ location_t where)
+ {
+ return m_option_classifier.classify_diagnostic (this,
+ option_id,
+ new_kind,
+ where);
+ }
+
+ void push_diagnostics (location_t where ATTRIBUTE_UNUSED)
+ {
+ m_option_classifier.push ();
+ }
+ void pop_diagnostics (location_t where)
+ {
+ m_option_classifier.pop (where);
+ }
+
+ void maybe_show_locus (const rich_location &richloc,
+ const source_printing_options &opts,
+ diagnostic_t diagnostic_kind,
+ pretty_printer &pp,
+ source_effect_info *effect_info);
+ void maybe_show_locus_as_html (const rich_location &richloc,
+ const source_printing_options &opts,
+ diagnostic_t diagnostic_kind,
+ xml::printer &xp,
+ source_effect_info *effect_info,
+ html_label_writer *label_writer);
+
+ void emit_diagram (const diagram &diag);
+
+ /* Various setters for use by option-handling logic. */
+ void set_sink (std::unique_ptr<sink> sink_);
+ void set_text_art_charset (enum diagnostic_text_art_charset charset);
+ void set_client_data_hooks (std::unique_ptr<client_data_hooks> hooks);
+
+ void push_owned_urlifier (std::unique_ptr<urlifier>);
+ void push_borrowed_urlifier (const urlifier &);
+ void pop_urlifier ();
+
+ 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_show_highlight_colors (bool 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_format_decoder (printer_fn format_decoder);
+ void set_prefixing_rule (diagnostic_prefixing_rule_t rule);
+
+ /* 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; }
+ sink &get_sink (size_t idx) const;
+ 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
+ {
+ gcc_assert (m_file_cache);
+ return *m_file_cache;
+ }
+
+ edit_context *get_edit_context () const
+ {
+ return m_edit_context_ptr;
+ }
+ const client_data_hooks *get_client_data_hooks () const
+ {
+ return m_client_data_hooks;
+ }
+
+ const logical_locations::manager *
+ get_logical_location_manager () const;
+
+ const urlifier *get_urlifier () const;
+
+ text_art::theme *get_diagram_theme () const { return m_diagrams.m_theme; }
+
+ int &diagnostic_count (diagnostic_t kind)
+ {
+ return m_diagnostic_counters.m_count_for_kind[kind];
+ }
+ int diagnostic_count (diagnostic_t kind) const
+ {
+ return m_diagnostic_counters.get_count (kind);
+ }
+
+ /* Option-related member functions. */
+ inline bool option_enabled_p (diagnostic_option_id option_id) const
+ {
+ if (!m_option_mgr)
+ return true;
+ return m_option_mgr->option_enabled_p (option_id);
+ }
+
+ inline char *make_option_name (diagnostic_option_id option_id,
+ diagnostic_t orig_diag_kind,
+ diagnostic_t diag_kind) const
+ {
+ if (!m_option_mgr)
+ return nullptr;
+ return m_option_mgr->make_option_name (option_id,
+ orig_diag_kind,
+ diag_kind);
+ }
+
+ inline char *make_option_url (diagnostic_option_id option_id) const
+ {
+ if (!m_option_mgr)
+ return nullptr;
+ return m_option_mgr->make_option_url (option_id);
+ }
+
+ void
+ set_option_manager (std::unique_ptr<option_manager> mgr,
+ unsigned lang_mask);
+
+ unsigned get_lang_mask () const
+ {
+ return m_lang_mask;
+ }
+
+ bool diagnostic_impl (rich_location *, const metadata *,
+ diagnostic_option_id, const char *,
+ va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(5,0);
+ bool diagnostic_n_impl (rich_location *, const metadata *,
+ diagnostic_option_id, unsigned HOST_WIDE_INT,
+ const char *, const char *, va_list *,
+ diagnostic_t) ATTRIBUTE_GCC_DIAG(7,0);
+
+ int get_diagnostic_nesting_level () const
+ {
+ return m_diagnostic_groups.m_diagnostic_nesting_level;
+ }
+
+ char *build_indent_prefix () const;
+
+ int
+ pch_save (FILE *f)
+ {
+ return m_option_classifier.pch_save (f);
+ }
+
+ int
+ pch_restore (FILE *f)
+ {
+ return m_option_classifier.pch_restore (f);
+ }
+
+
+ void set_diagnostic_buffer (buffer *);
+ buffer *get_diagnostic_buffer () const
+ {
+ return m_diagnostic_buffer;
+ }
+ void clear_diagnostic_buffer (buffer &);
+ void flush_diagnostic_buffer (buffer &);
+
+ std::unique_ptr<pretty_printer> clone_printer () const
+ {
+ return m_reference_printer->clone ();
+ }
+
+ pretty_printer *get_reference_printer () const
+ {
+ return m_reference_printer;
+ }
+
+ void
+ add_sink (std::unique_ptr<sink>);
+
+ void remove_all_output_sinks ();
+
+ bool supports_fnotice_on_stderr_p () const;
+
+ /* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher. */
+ void
+ set_abort_on_error (bool val)
+ {
+ m_abort_on_error = val;
+ }
+
+ /* Accessor for use in serialization, e.g. by C++ modules. */
+ auto &
+ get_classification_history ()
+ {
+ return m_option_classifier.m_classification_history;
+ }
+
+ void set_main_input_filename (const char *filename);
+
+ void
+ set_permissive_option (diagnostic_option_id opt_permissive)
+ {
+ m_opt_permissive = opt_permissive;
+ }
+
+ void
+ set_fatal_errors (bool fatal_errors)
+ {
+ m_fatal_errors = fatal_errors;
+ }
+
+ void
+ set_internal_error_callback (void (*cb) (context *,
+ const char *,
+ va_list *))
+ {
+ m_internal_error = cb;
+ }
+
+ void
+ set_adjust_diagnostic_info_callback (void (*cb) (context *,
+ diagnostic_info *))
+ {
+ m_adjust_diagnostic_info = cb;
+ }
+
+ void
+ inhibit_notes () { m_inhibit_notes_p = true; }
+
+private:
+ void error_recursion () ATTRIBUTE_NORETURN;
+
+ bool diagnostic_enabled (diagnostic_info *diagnostic);
+
+ void get_any_inlining_info (diagnostic_info *diagnostic);
+
+ void check_max_errors (bool flush);
+ void action_after_output (diagnostic_t diag_kind);
+
+ /* Data members.
+ Ideally, all of these would be private. */
+
+private:
+ /* A reference instance of pretty_printer created by the client
+ and owned by the context. Used for cloning when creating/adding
+ output formats.
+ Owned by the context; this would be a std::unique_ptr if
+ context had a proper ctor. */
+ pretty_printer *m_reference_printer;
+
+ /* Cache of source code.
+ Owned by the context; this would be a std::unique_ptr if
+ context had a proper ctor. */
+ file_cache *m_file_cache;
+
+ /* The number of times we have issued diagnostics. */
+ counters m_diagnostic_counters;
+
+ /* True if it has been requested that warnings be treated as errors. */
+ bool m_warning_as_error_requested;
+
+ /* The number of option indexes that can be passed to warning() et
+ al. */
+ int m_n_opts;
+
+ /* The stack of sets of overridden diagnostic option severities. */
+ option_classifier m_option_classifier;
+
+ /* True if we should print any CWE identifiers associated with
+ diagnostics. */
+ bool m_show_cwe;
+
+ /* True if we should print any rules associated with diagnostics. */
+ bool m_show_rules;
+
+ /* How should diagnostics::paths::path objects be printed. */
+ enum diagnostic_path_format m_path_format;
+
+ /* True if we should print stack depths when printing diagnostic paths. */
+ bool m_show_path_depths;
+
+ /* True if we should print the command line option which controls
+ each diagnostic, if known. */
+ bool m_show_option_requested;
+
+ /* True if we should raise a SIGABRT on errors. */
+ bool m_abort_on_error;
+
+public:
+ /* True if we should show the column number on diagnostics. */
+ bool m_show_column;
+
+ /* True if pedwarns are errors. */
+ bool m_pedantic_errors;
+
+ /* True if permerrors are warnings. */
+ bool m_permissive;
+
+private:
+ /* The option to associate with turning permerrors into warnings,
+ if any. */
+ diagnostic_option_id m_opt_permissive;
+
+ /* True if errors are fatal. */
+ bool m_fatal_errors;
+
+public:
+ /* True if all warnings should be disabled. */
+ bool m_inhibit_warnings;
+
+ /* True if warnings should be given in system headers. */
+ bool m_warn_system_headers;
+
+private:
+ /* Maximum number of errors to report. */
+ int m_max_errors;
+
+ /* Client-supplied callbacks for use in text output. */
+ struct {
+ /* This function is called before any message is printed out. It is
+ responsible for preparing message prefix and such. For example, it
+ might say:
+ In file included from "/usr/local/include/curses.h:5:
+ from "/home/gdr/src/nifty_printer.h:56:
+ ...
+ */
+ text_starter_fn m_begin_diagnostic;
+
+ /* This function is called by diagnostic_show_locus in between
+ disjoint spans of source code, so that the context can print
+ something to indicate that a new span of source code has begun. */
+ start_span_fn<to_text> m_text_start_span;
+ start_span_fn<to_html> m_html_start_span;
+
+ /* This function is called after the diagnostic message is printed. */
+ text_finalizer_fn m_end_diagnostic;
+ } m_text_callbacks;
+
+ /* Client hook to report an internal error. */
+ void (*m_internal_error) (context *, const char *, va_list *);
+
+ /* Client hook to adjust properties of the given diagnostic that we're
+ about to issue, such as its kind. */
+ void (*m_adjust_diagnostic_info)(context *, diagnostic_info *);
+
+ /* Owned by the context; this would be a std::unique_ptr if
+ context had a proper ctor. */
+ option_manager *m_option_mgr;
+ unsigned m_lang_mask;
+
+ /* A stack of optional hooks for adding URLs to quoted text strings in
+ diagnostics. Only used for the main diagnostic message.
+ Typically a single one owner by the context, but can be temporarily
+ overridden by a borrowed urlifier (e.g. on-stack). */
+ struct urlifier_stack_node
+ {
+ urlifier *m_urlifier;
+ bool m_owned;
+ };
+ auto_vec<urlifier_stack_node> *m_urlifier_stack;
+
+public:
+ /* Auxiliary data for client. */
+ void *m_client_aux_data;
+
+ /* Used to detect that the last caret was printed at the same location. */
+ location_t m_last_location;
+
+private:
+ int m_lock;
+
+ bool m_inhibit_notes_p;
+
+public:
+ source_printing_options m_source_printing;
+
+private:
+ /* True if -freport-bug option is used. */
+ 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 m_extra_output_kind;
+
+public:
+ /* What units to use when outputting the column number. */
+ enum diagnostics_column_unit m_column_unit;
+
+ /* The origin for the column number (1-based or 0-based typically). */
+ int m_column_origin;
+
+ /* The size of the tabstop for tab expansion. */
+ 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 m_escape_format;
+
+ /* If non-NULL, an edit_context to which fix-it hints should be
+ applied, for generating patches.
+ Owned by the context; this would be a std::unique_ptr if
+ context had a proper ctor. */
+ edit_context *m_edit_context_ptr;
+
+ /* Fields relating to diagnostic groups. */
+ struct {
+ /* How many diagnostic_group instances are currently alive. */
+ int m_group_nesting_depth;
+
+ /* How many nesting levels have been pushed within this group. */
+ int m_diagnostic_nesting_level;
+
+ /* How many diagnostics have been emitted since the bottommost
+ diagnostic_group was pushed. */
+ int m_emission_count;
+
+ /* The "group+diagnostic" nesting depth from which to inhibit notes. */
+ int m_inhibiting_notes_from;
+ } m_diagnostic_groups;
+
+ void inhibit_notes_in_group (bool inhibit = true);
+ bool notes_inhibited_in_group () const;
+
+ /* The various sinks to which diagnostics are to be outputted
+ (text vs structured formats such as SARIF).
+ The sinks are owned by the context; this would be a
+ std::vector<std::unique_ptr> if context had a
+ proper ctor. */
+ auto_vec<sink *> m_sinks;
+
+ /* Callback to set the locations of call sites along the inlining
+ stack corresponding to a diagnostic location. Needed to traverse
+ the BLOCK_SUPERCONTEXT() chain hanging off the LOCATION_BLOCK()
+ of a diagnostic's location. */
+ set_locations_callback_t m_set_locations_cb;
+
+ /* A bundle of hooks for providing data to the context about its client
+ e.g. version information, plugins, etc.
+ Used by SARIF output to give metadata about the client that's
+ producing diagnostics.
+ Owned by the context; this would be a std::unique_ptr if
+ context had a proper ctor. */
+ client_data_hooks *m_client_data_hooks;
+
+ /* Support for diagrams. */
+ struct
+ {
+ /* Theme to use when generating diagrams.
+ Can be NULL (if text art is disabled).
+ Owned by the context; this would be a std::unique_ptr if
+ context had a proper ctor. */
+ text_art::theme *m_theme;
+
+ } m_diagrams;
+
+ /* Owned by the context. */
+ char **m_original_argv;
+
+ /* Borrowed pointer to the active diagnostics::buffer, if any.
+ If null (the default), then diagnostics that are reported to the
+ context are immediately issued to the output format.
+ If non-null, then diagnostics that are reported to the context
+ are buffered in the buffer, and may be issued to the output format
+ later (if the buffer is flushed), moved to other buffers, or
+ discarded (if the buffer is cleared). */
+ buffer *m_diagnostic_buffer;
+};
+
+/* Client supplied function to announce a diagnostic
+ (for text-based diagnostic output). */
+inline text_starter_fn &
+text_starter (context *dc)
+{
+ return dc->m_text_callbacks.m_begin_diagnostic;
+}
+
+/* Client supplied function called between disjoint spans of source code,
+ so that the context can print
+ something to indicate that a new span of source code has begun. */
+inline start_span_fn<to_text> &
+start_span (context *dc)
+{
+ return dc->m_text_callbacks.m_text_start_span;
+}
+
+/* Client supplied function called after a diagnostic message is
+ displayed (for text-based diagnostic output). */
+inline text_finalizer_fn &
+text_finalizer (context *dc)
+{
+ return dc->m_text_callbacks.m_end_diagnostic;
+}
+
+} // namespace diagnostics
+
+#endif /* ! GCC_DIAGNOSTICS_CONTEXT_H */
public:
friend class html_sink_buffer;
- html_builder (diagnostic_context &context,
+ html_builder (context &dc,
pretty_printer &pp,
const line_maps *line_maps,
const html_generation_options &html_gen_opts);
add_graph (const digraphs::digraph &dg,
xml::element &parent_element);
- diagnostic_context &m_context;
+ context &m_context;
pretty_printer *m_printer;
const line_maps *m_line_maps;
html_generation_options m_html_gen_opts;
/* html_builder's ctor. */
-html_builder::html_builder (diagnostic_context &context,
+html_builder::html_builder (context &dc,
pretty_printer &pp,
const line_maps *line_maps,
const html_generation_options &html_gen_opts)
-: m_context (context),
+: m_context (dc),
m_printer (&pp),
m_line_maps (line_maps),
m_html_gen_opts (html_gen_opts),
{
gcc_assert (m_line_maps);
- if (auto client_data_hooks = context.get_client_data_hooks ())
+ if (auto client_data_hooks = dc.get_client_data_hooks ())
m_logical_loc_mgr = client_data_hooks->get_logical_location_manager ();
m_document = std::make_unique<xml::document> ();
if (s.line)
{
add_labelled_value (xp, "line", "Line", std::to_string (s.line), false);
- diagnostic_column_policy column_policy (m_context);
- int converted_column = column_policy.converted_column (s);
+ column_policy col_policy (m_context);
+ int converted_column = col_policy.converted_column (s);
if (converted_column >= 0)
add_labelled_value (xp, "column", "Column",
std::to_string (converted_column),
html_path_label_writer event_label_writer (xp, *this, *path,
event_id_prefix);
- diagnostic_source_print_policy dspp (m_context);
+ source_print_policy dspp (m_context);
print_path_as_html (xp, *path, m_context, &event_label_writer,
dspp);
return span_metadata;
}
-/* Implementation of diagnostic_context::m_diagrams.m_emission_cb
+/* Implementation of diagnostics::context::m_diagrams.m_emission_cb
for HTML output. */
void
html_builder &get_builder () { return m_builder; }
protected:
- html_sink (diagnostic_context &context,
+ html_sink (context &dc,
const line_maps *line_maps,
const html_generation_options &html_gen_opts)
- : sink (context),
- m_builder (context, *get_printer (), line_maps, html_gen_opts),
+ : sink (dc),
+ m_builder (dc, *get_printer (), line_maps, html_gen_opts),
m_buffer (nullptr)
{}
class html_file_sink : public html_sink
{
public:
- html_file_sink (diagnostic_context &context,
+ html_file_sink (context &dc,
const line_maps *line_maps,
const html_generation_options &html_gen_opts,
output_file output_file_)
- : html_sink (context, line_maps, html_gen_opts),
+ : html_sink (dc, line_maps, html_gen_opts),
m_output_file (std::move (output_file_))
{
gcc_assert (m_output_file.get_open_file ());
/* Attempt to open BASE_FILE_NAME.html for writing.
Return a non-null output_file,
- or return a null output_file and complain to CONTEXT
+ or return a null output_file and complain to DC
using LINE_MAPS. */
output_file
-open_html_output_file (diagnostic_context &context,
+open_html_output_file (context &dc,
line_maps *line_maps,
const char *base_file_name)
{
if (!base_file_name)
{
rich_location richloc (line_maps, UNKNOWN_LOCATION);
- context.emit_diagnostic_with_group
+ dc.emit_diagnostic_with_group
(DK_ERROR, richloc, nullptr, 0,
"unable to determine filename for HTML output");
return output_file ();
if (!outf)
{
rich_location richloc (line_maps, UNKNOWN_LOCATION);
- context.emit_diagnostic_with_group
+ dc.emit_diagnostic_with_group
(DK_ERROR, richloc, nullptr, 0,
"unable to open %qs for HTML output: %m",
filename.get ());
}
std::unique_ptr<sink>
-make_html_sink (diagnostic_context &context,
+make_html_sink (context &dc,
const line_maps &line_maps,
const html_generation_options &html_gen_opts,
output_file output_file_)
{
auto sink
- = std::make_unique<html_file_sink> (context,
+ = std::make_unique<html_file_sink> (dc,
&line_maps,
html_gen_opts,
std::move (output_file_));
class html_buffered_sink : public html_sink
{
public:
- html_buffered_sink (diagnostic_context &context,
+ html_buffered_sink (context &dc,
const line_maps *line_maps,
const html_generation_options &html_gen_opts)
- : html_sink (context, line_maps, html_gen_opts)
+ : html_sink (dc, line_maps, html_gen_opts)
{
}
bool machine_readable_stderr_p () const final override
};
/* Test of reporting a diagnostic at UNKNOWN_LOCATION to a
- diagnostic_context and examining the generated XML document.
+ diagnostics::context and examining the generated XML document.
Verify various basic properties. */
static void
};
extern diagnostics::output_file
-open_html_output_file (diagnostic_context &context,
+open_html_output_file (context &dc,
line_maps *line_maps,
const char *base_file_name);
extern std::unique_ptr<sink>
-make_html_sink (diagnostic_context &context,
+make_html_sink (context &dc,
const line_maps &line_maps,
const html_generation_options &html_gen_opts,
- diagnostics::output_file output_file_);
+ output_file output_file_);
extern void
print_path_as_html (xml::printer &xp,
- const diagnostics::paths::path &path,
- diagnostic_context &dc,
+ const paths::path &path,
+ context &dc,
html_label_writer *event_label_writer,
- const diagnostic_source_print_policy &dspp);
+ const source_print_policy &dspp);
} // namespace diagnostics
"double `free'");
}
-/* Implementation of diagnostic_option_manager for which all
+/* Implementation of diagnostics::option_manager for which all
options are disabled, for use in selftests.
Note that this is *not* called for diagnostic_option_id (0), which
means "always warn" */
-class all_warnings_disabled : public diagnostic_option_manager
+class all_warnings_disabled : public diagnostics::option_manager
{
public:
int option_enabled_p (diagnostic_option_id) const final override
const char *get_filename () const { return m_filename.get (); }
static output_file
- try_to_open (diagnostic_context &context,
+ try_to_open (context &dc,
line_maps *line_maps,
const char *base_file_name,
const char *extension,
virtual std::unique_ptr<sink>
make_sink (const context &ctxt,
- diagnostic_context &dc,
+ diagnostics::context &dc,
const char *unparsed_arg,
const scheme_name_and_params &parsed_arg) const = 0;
std::unique_ptr<sink>
make_sink (const context &ctxt,
- diagnostic_context &dc,
+ diagnostics::context &dc,
const char *unparsed_arg,
const scheme_name_and_params &parsed_arg);
std::unique_ptr<sink>
make_sink (const context &ctxt,
- diagnostic_context &dc,
+ diagnostics::context &dc,
const char *unparsed_arg,
const scheme_name_and_params &parsed_arg) const final override;
};
std::unique_ptr<sink>
make_sink (const context &ctxt,
- diagnostic_context &dc,
+ diagnostics::context &dc,
const char *unparsed_arg,
const scheme_name_and_params &parsed_arg) const final override;
std::unique_ptr<sink>
make_sink (const context &ctxt,
- diagnostic_context &dc,
+ diagnostics::context &dc,
const char *unparsed_arg,
const scheme_name_and_params &parsed_arg) const final override;
};
std::unique_ptr<sink>
context::parse_and_make_sink (const char *unparsed_arg,
- diagnostic_context &dc)
+ diagnostics::context &dc)
{
auto parsed_arg = parse (*this, unparsed_arg);
if (!parsed_arg)
std::unique_ptr<sink>
output_factory::make_sink (const context &ctxt,
- diagnostic_context &dc,
+ diagnostics::context &dc,
const char *unparsed_arg,
const scheme_name_and_params &parsed_arg)
{
std::unique_ptr<sink>
text_scheme_handler::make_sink (const context &ctxt,
- diagnostic_context &dc,
+ diagnostics::context &dc,
const char *unparsed_arg,
const scheme_name_and_params &parsed_arg) const
{
std::unique_ptr<sink>
sarif_scheme_handler::make_sink (const context &ctxt,
- diagnostic_context &dc,
+ diagnostics::context &dc,
const char *unparsed_arg,
const scheme_name_and_params &parsed_arg) const
{
std::unique_ptr<sink>
html_scheme_handler::make_sink (const context &ctxt,
- diagnostic_context &dc,
+ diagnostics::context &dc,
const char *unparsed_arg,
const scheme_name_and_params &parsed_arg) const
{
class test_spec_context : public diagnostics::output_spec::dc_spec_context
{
public:
- test_spec_context (diagnostic_context &dc,
+ test_spec_context (diagnostics::context &dc,
line_maps *location_mgr,
location_t loc,
const char *option_name)
public:
std::unique_ptr<sink>
parse_and_make_sink (const char *,
- diagnostic_context &dc);
+ diagnostics::context &dc);
void
report_error (const char *gmsgid, ...) const
line_maps *m_affected_location_mgr;
};
-/* A subclass that implements reporting errors via a diagnostic_context. */
+/* A subclass that implements reporting errors via a diagnostics::context. */
struct dc_spec_context : public output_spec::context
{
public:
- dc_spec_context (diagnostic_context &dc,
+ dc_spec_context (diagnostics::context &dc,
line_maps *affected_location_mgr,
line_maps *control_location_mgr,
location_t loc,
m_dc.end_group ();
}
- diagnostic_context &m_dc;
+ diagnostics::context &m_dc;
line_maps *m_control_location_mgr;
location_t m_loc;
};
{
}
- path_print_policy (const diagnostic_context &dc)
+ path_print_policy (const diagnostics::context &dc)
: m_source_policy (dc)
{
}
return m_source_policy.get_diagram_theme ();
}
- const diagnostic_source_print_policy &
+ const diagnostics::source_print_policy &
get_source_policy () const { return m_source_policy; }
private:
- diagnostic_source_print_policy m_source_policy;
+ diagnostics::source_print_policy m_source_policy;
};
/* Subclass of range_label for showing a particular event
{
location_t initial_loc = m_initial_event.get_location ();
- diagnostic_context &dc = text_output.get_context ();
+ diagnostics::context &dc = text_output.get_context ();
/* Emit a span indicating the filename (and line/column) if the
line has changed relative to the last call to
(line_table, initial_loc, LOCATION_ASPECT_CARET);
if (exploc.file != LOCATION_FILE (dc.m_last_location))
{
- diagnostic_location_print_policy loc_policy (text_output);
+ diagnostics::location_print_policy loc_policy (text_output);
loc_policy.print_text_span_start (dc, pp, exploc);
}
}
call to diagnostic_show_locus_as_html. */
void print_as_html (xml::printer &xp,
- diagnostic_context &dc,
+ diagnostics::context &dc,
diagnostics::source_effect_info *effect_info,
html_label_writer *event_label_writer)
{
(line_table, initial_loc, LOCATION_ASPECT_CARET);
if (exploc.file != LOCATION_FILE (dc.m_last_location))
{
- diagnostic_location_print_policy loc_policy (dc);
+ diagnostics::location_print_policy loc_policy (dc);
loc_policy.print_html_span_start (dc, xp, exploc);
}
}
}
void
- print_swimlane_for_event_range_as_html (diagnostic_context &dc,
+ print_swimlane_for_event_range_as_html (diagnostics::context &dc,
xml::printer &xp,
html_label_writer *event_label_writer,
event_range *range,
static void
print_path_summary_as_html (const path_summary &ps,
- diagnostic_context &dc,
+ diagnostics::context &dc,
xml::printer &xp,
html_label_writer *event_label_writer,
bool show_depths)
void
diagnostics::print_path_as_html (xml::printer &xp,
const path &path_,
- diagnostic_context &dc,
+ context &dc,
html_label_writer *event_label_writer,
- const diagnostic_source_print_policy &dspp)
+ const source_print_policy &dspp)
{
path_print_policy policy (dc);
const bool check_rich_locations = true;
const bool colorize = false;
- const diagnostic_source_printing_options &source_printing_opts
+ const source_printing_options &source_printing_opts
= dspp.get_options ();
const bool show_event_links = source_printing_opts.show_event_links_p;
path_summary summary (policy,
public:
friend class sarif_sink_buffer;
- sarif_builder (diagnostic_context &context,
+ sarif_builder (diagnostics::context &dc,
pretty_printer &printer,
const line_maps *line_maps,
std::unique_ptr<sarif_serialization_format> serialization_format,
return m_current_code_flow;
}
- diagnostic_context &get_context () const { return m_context; }
+ diagnostics::context &get_context () const { return m_context; }
pretty_printer *get_printer () const { return m_printer; }
token_printer &get_token_printer () { return m_token_printer; }
enum sarif_version get_version () const { return m_sarif_gen_opts.m_version; }
std::unique_ptr<json::object>
make_stack_from_backtrace ();
- diagnostic_context &m_context;
+ diagnostics::context &m_context;
pretty_printer *m_printer;
const line_maps *m_line_maps;
sarif_token_printer m_token_printer;
void
sarif_invocation::prepare_to_flush (sarif_builder &builder)
{
- const diagnostic_context &context = builder.get_context ();
+ const context &dc = builder.get_context ();
/* "executionSuccessful" property (SARIF v2.1.0 section 3.20.14). */
- if (context.execution_failed_p ())
+ if (dc.execution_failed_p ())
m_success = false;
set_bool ("executionSuccessful", m_success);
/* 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 (auto client_data_hooks = context.get_client_data_hooks ())
+ if (auto client_data_hooks = dc.get_client_data_hooks ())
client_data_hooks->add_sarif_invocation_properties (*this);
// "endTimeUtc" property (SARIF v2.1.0 section 3.20.8);
/* sarif_builder's ctor. */
-sarif_builder::sarif_builder (diagnostic_context &context,
+sarif_builder::sarif_builder (diagnostics::context &dc,
pretty_printer &printer,
const line_maps *line_maps,
std::unique_ptr<sarif_serialization_format> serialization_format,
const sarif_generation_options &sarif_gen_opts)
-: m_context (context),
+: m_context (dc),
m_printer (&printer),
m_line_maps (line_maps),
m_token_printer (*this),
m_logical_loc_mgr (nullptr),
m_invocation_obj
(std::make_unique<sarif_invocation> (*this,
- context.get_original_argv ())),
+ dc.get_original_argv ())),
m_results_array (new json::array ()),
m_cur_group_result (nullptr),
m_seen_any_relative_paths (false),
(std::make_unique<sarif_array_of_unique<sarif_logical_location>> ()),
m_run_graphs
(std::make_unique<sarif_array_of_unique<sarif_graph>> ()),
- m_tabstop (context.m_tabstop),
+ m_tabstop (dc.m_tabstop),
m_serialization_format (std::move (serialization_format)),
m_sarif_gen_opts (sarif_gen_opts),
m_next_result_idx (0),
gcc_assert (m_line_maps);
gcc_assert (m_serialization_format);
- if (auto client_data_hooks = context.get_client_data_hooks ())
+ if (auto client_data_hooks = dc.get_client_data_hooks ())
m_logical_loc_mgr = client_data_hooks->get_logical_location_manager ();
}
}
}
-/* Implementation of diagnostic_context::m_diagrams.m_emission_cb
+/* Implementation of diagnostics::context::m_diagrams.m_emission_cb
for SARIF output. */
void
std::unique_ptr<sarif_multiformat_message_string>
render (const sarif_builder &builder) const final override
{
- diagnostic_context dc;
+ diagnostics::context dc;
diagnostic_initialize (&dc, 0);
dc.m_source_printing.enabled = true;
dc.m_source_printing.colorize_source_p = false;
rich_location my_rich_loc (m_richloc);
my_rich_loc.set_escape_on_output (true);
- diagnostic_source_print_policy source_policy (dc);
+ source_print_policy source_policy (dc);
dc.set_escape_format (m_escape_format);
text_sink text_output (dc);
source_policy.print (*text_output.get_printer (),
/* If WHERE was #included from somewhere, add a worklist item
to LOC_MGR to lazily add a location for the #include location,
and relationships between it and the LOCATION_OBJ.
- Compare with diagnostic_context::report_current_module, but rather
+ Compare with diagnostics::context::report_current_module, but rather
than iterating the current chain, we add the next edge and iterate
in the worklist, so that edges are only added once. */
sarif_result &get_result (size_t idx) { return m_builder.get_result (idx); }
protected:
- sarif_sink (diagnostic_context &context,
+ sarif_sink (context &dc,
const line_maps *line_maps,
std::unique_ptr<sarif_serialization_format> serialization_format,
const sarif_generation_options &sarif_gen_opts)
- : sink (context),
- m_builder (context, *get_printer (), line_maps,
+ : sink (dc),
+ m_builder (dc, *get_printer (), line_maps,
std::move (serialization_format), sarif_gen_opts),
m_buffer (nullptr)
{}
class sarif_stream_sink : public sarif_sink
{
public:
- sarif_stream_sink (diagnostic_context &context,
+ sarif_stream_sink (context &dc,
const line_maps *line_maps,
std::unique_ptr<sarif_serialization_format> serialization_format,
const sarif_generation_options &sarif_gen_opts,
FILE *stream)
- : sarif_sink (context, line_maps,
+ : sarif_sink (dc, line_maps,
std::move (serialization_format), sarif_gen_opts),
m_stream (stream)
{
class sarif_file_sink : public sarif_sink
{
public:
- sarif_file_sink (diagnostic_context &context,
+ sarif_file_sink (context &dc,
const line_maps *line_maps,
std::unique_ptr<sarif_serialization_format> serialization_format,
const sarif_generation_options &sarif_gen_opts,
output_file output_file_)
- : sarif_sink (context, line_maps,
+ : sarif_sink (dc, line_maps,
std::move (serialization_format),
sarif_gen_opts),
m_output_file (std::move (output_file_))
Return a reference to *FMT. */
static sink &
-init_sarif_sink (diagnostic_context &context,
+init_sarif_sink (context &dc,
std::unique_ptr<sarif_sink> fmt)
{
gcc_assert (fmt);
fmt->update_printer ();
- context.set_sink (std::move (fmt));
+ dc.set_sink (std::move (fmt));
return out;
}
-/* Populate CONTEXT in preparation for SARIF output to stderr.
+/* Populate DC in preparation for SARIF output to stderr.
Return a reference to the new sink. */
sink &
-init_sarif_stderr (diagnostic_context &context,
+init_sarif_stderr (context &dc,
const line_maps *line_maps,
bool formatted)
{
auto serialization
= std::make_unique<sarif_serialization_format_json> (formatted);
return init_sarif_sink
- (context,
- std::make_unique<sarif_stream_sink> (context,
+ (dc,
+ std::make_unique<sarif_stream_sink> (dc,
line_maps,
std::move (serialization),
sarif_gen_opts,
/* Attempt to open "BASE_FILE_NAME""EXTENSION" for writing.
Return a non-null output_file,
- or return a null output_file and complain to CONTEXT
+ or return a null output_file and complain to DC
using LINE_MAPS. */
output_file
-output_file::try_to_open (diagnostic_context &context,
+output_file::try_to_open (context &dc,
line_maps *line_maps,
const char *base_file_name,
const char *extension,
if (!base_file_name)
{
rich_location richloc (line_maps, UNKNOWN_LOCATION);
- context.emit_diagnostic_with_group
+ dc.emit_diagnostic_with_group
(DK_ERROR, richloc, nullptr, 0,
"unable to determine filename for SARIF output");
return output_file ();
if (!outf)
{
rich_location richloc (line_maps, UNKNOWN_LOCATION);
- context.emit_diagnostic_with_group
+ dc.emit_diagnostic_with_group
(DK_ERROR, richloc, nullptr, 0,
"unable to open %qs for diagnostic output: %m",
filename.get ());
/* Attempt to open BASE_FILE_NAME.sarif for writing JSON.
Return a non-null output_file,
- or return a null output_file and complain to CONTEXT
+ or return a null output_file and complain to DC
using LINE_MAPS. */
output_file
-open_sarif_output_file (diagnostic_context &context,
+open_sarif_output_file (context &dc,
line_maps *line_maps,
const char *base_file_name,
enum sarif_serialization_kind serialization_kind)
break;
}
- return output_file::try_to_open (context,
+ return output_file::try_to_open (dc,
line_maps,
base_file_name,
suffix,
is_binary);
}
-/* Populate CONTEXT in preparation for SARIF output to a file named
+/* Populate DC in preparation for SARIF output to a file named
BASE_FILE_NAME.sarif.
Return a reference to the new sink. */
sink &
-init_sarif_file (diagnostic_context &context,
+init_sarif_file (context &dc,
line_maps *line_maps,
bool formatted,
const char *base_file_name)
gcc_assert (line_maps);
output_file output_file_
- = open_sarif_output_file (context,
+ = open_sarif_output_file (dc,
line_maps,
base_file_name,
sarif_serialization_kind::json);
const sarif_generation_options sarif_gen_opts;
return init_sarif_sink
- (context,
- std::make_unique<sarif_file_sink> (context,
+ (dc,
+ std::make_unique<sarif_file_sink> (dc,
line_maps,
std::move (serialization),
sarif_gen_opts,
std::move (output_file_)));
}
-/* Populate CONTEXT in preparation for SARIF output to STREAM.
+/* Populate DC in preparation for SARIF output to STREAM.
Return a reference to the new sink. */
sink &
-init_sarif_stream (diagnostic_context &context,
+init_sarif_stream (context &dc,
const line_maps *line_maps,
bool formatted,
FILE *stream)
auto serialization
= std::make_unique<sarif_serialization_format_json> (formatted);
return init_sarif_sink
- (context,
- std::make_unique<sarif_stream_sink> (context,
+ (dc,
+ std::make_unique<sarif_stream_sink> (dc,
line_maps,
std::move (serialization),
sarif_gen_opts,
}
std::unique_ptr<sink>
-make_sarif_sink (diagnostic_context &context,
+make_sarif_sink (context &dc,
const line_maps &line_maps,
std::unique_ptr<sarif_serialization_format> serialization,
const sarif_generation_options &sarif_gen_opts,
output_file output_file_)
{
auto sink
- = std::make_unique<sarif_file_sink> (context,
+ = std::make_unique<sarif_file_sink> (dc,
&line_maps,
std::move (serialization),
sarif_gen_opts,
class buffered_sink : public sarif_sink
{
public:
- buffered_sink (diagnostic_context &context,
+ buffered_sink (context &dc,
const line_maps *line_maps,
bool formatted,
const sarif_generation_options &sarif_gen_opts)
- : sarif_sink (context, line_maps,
+ : sarif_sink (dc, line_maps,
std::make_unique<sarif_serialization_format_json> (formatted),
sarif_gen_opts)
{
}
/* Test of reporting a diagnostic at UNKNOWN_LOCATION to a
- diagnostic_context and examining the generated sarif_log.
+ diagnostics::context and examining the generated sarif_log.
Verify various basic properties. */
static void
num_values
};
-extern diagnostics::output_file
-open_sarif_output_file (diagnostic_context &context,
+extern output_file
+open_sarif_output_file (context &dc,
line_maps *line_maps,
const char *base_file_name,
enum sarif_serialization_kind serialization_kind);
extern sink &
-init_sarif_stderr (diagnostic_context &context,
+init_sarif_stderr (context &dc,
const line_maps *line_maps,
bool formatted);
extern sink &
-init_sarif_file (diagnostic_context &context,
+init_sarif_file (context &dc,
line_maps *line_maps,
bool formatted,
const char *base_file_name);
extern sink &
-init_sarif_stream (diagnostic_context &context,
+init_sarif_stream (context &dc,
const line_maps *line_maps,
bool formatted,
FILE *stream);
};
extern std::unique_ptr<sink>
-make_sarif_sink (diagnostic_context &context,
+make_sarif_sink (context &dc,
const line_maps &line_maps,
std::unique_ptr<sarif_serialization_format> serialization_format,
const sarif_generation_options &sarif_gen_opts,
- diagnostics::output_file output_file_);
+ output_file output_file_);
class sarif_builder;
class sarif_location_manager;
public:
void set_logical_location (const char *property_name,
sarif_builder &,
- diagnostics::logical_locations::key logical_loc);
+ logical_locations::key logical_loc);
void set_graph (const char *property_name,
sarif_builder &,
sarif_location_manager *sarif_location_mgr,
- const diagnostics::digraphs::digraph &g);
+ const digraphs::digraph &g);
};
/* Concrete subclass of json::object for SARIF objects that can
make_per_sink_buffer () = 0;
/* Vfunc to be called when call a diagnostics::buffer is set on
- a diagnostic_context, to update this format. The per_sink_buffer
+ a diagnostics::context, to update this format. The per_sink_buffer
will be one created by make_per_sink_buffer above and thus be
of the correct subclass. */
virtual void set_buffer (per_sink_buffer *) = 0;
virtual bool machine_readable_stderr_p () const = 0;
virtual bool follows_reference_printer_p () const = 0;
- /* Vfunc called when the diagnostic_context changes its
+ /* Vfunc called when the diagnostics::context changes its
reference printer (either to a new subclass of pretty_printer
or when color/url options change).
Subclasses should update their m_printer accordingly. */
virtual void
report_global_digraph (const digraphs::lazy_digraph &) = 0;
- diagnostic_context &get_context () const { return m_context; }
+ context &get_context () const { return m_context; }
pretty_printer *get_printer () const { return m_printer.get (); }
text_art::theme *get_diagram_theme () const
void DEBUG_FUNCTION dump () const { dump (stderr, 0); }
protected:
- sink (diagnostic_context &context)
- : m_context (context),
- m_printer (context.clone_printer ())
+ sink (context &dc)
+ : m_context (dc),
+ m_printer (dc.clone_printer ())
{}
protected:
- diagnostic_context &m_context;
+ context &m_context;
std::unique_ptr<pretty_printer> m_printer;
};
extern void
-output_format_init (diagnostic_context &,
+output_format_init (context &,
const char *main_input_filename_,
const char *base_file_name,
enum diagnostics_output_format,
public:
char_display_policy (int tabstop,
int (*width_cb) (cppchar_t c),
- void (*print_text_cb) (to_text &sink,
+ void (*print_text_cb) (diagnostics::to_text &sink,
const cpp_decoded_char &cp),
- void (*print_html_cb) (to_html &sink,
+ void (*print_html_cb) (diagnostics::to_html &sink,
const cpp_decoded_char &cp))
: cpp_char_column_policy (tabstop, width_cb),
m_print_text_cb (print_text_cb),
{
}
- void (*m_print_text_cb) (to_text &sink,
+ void (*m_print_text_cb) (diagnostics::to_text &sink,
const cpp_decoded_char &cp);
- void (*m_print_html_cb) (to_html &sink,
+ void (*m_print_html_cb) (diagnostics::to_html &sink,
const cpp_decoded_char &cp);
};
} // anonymous namespace
+namespace diagnostics {
+
/* This code is written generically to write either:
- text, to a pretty_printer, potentially with colorization codes, or
- html, to an xml::printer, with nested HTML tags.
}
void
- invoke_start_span_fn (const diagnostic_source_print_policy &source_policy,
- const diagnostic_location_print_policy &loc_policy,
+ invoke_start_span_fn (const source_print_policy &source_policy,
+ const location_print_policy &loc_policy,
const expanded_location &exploc)
{
source_policy.get_text_start_span_fn () (loc_policy, *this, exploc);
}
void
- invoke_start_span_fn (const diagnostic_source_print_policy &source_policy,
- const diagnostic_location_print_policy &loc_policy,
+ invoke_start_span_fn (const source_print_policy &source_policy,
+ const location_print_policy &loc_policy,
const expanded_location &exploc)
{
source_policy.get_html_start_span_fn () (loc_policy, *this, exploc);
};
void
-diagnostic_location_print_policy::
-print_text_span_start (const diagnostic_context &dc,
+location_print_policy::
+print_text_span_start (const diagnostics::context &dc,
pretty_printer &pp,
const expanded_location &exploc)
{
to_text sink (pp, nullptr);
- diagnostic_source_print_policy source_policy (dc);
+ source_print_policy source_policy (dc);
source_policy.get_text_start_span_fn () (*this, sink, exploc);
}
void
-diagnostic_location_print_policy::
-print_html_span_start (const diagnostic_context &dc,
+location_print_policy::
+print_html_span_start (const diagnostics::context &dc,
xml::printer &xp,
const expanded_location &exploc)
{
to_html sink (xp, nullptr, nullptr);
- diagnostic_source_print_policy source_policy (dc);
+ source_print_policy source_policy (dc);
source_policy.get_html_start_span_fn () (*this, sink, exploc);
}
template<>
void
-diagnostics::default_start_span_fn<to_text> (const diagnostic_location_print_policy &loc_policy,
- to_text &sink,
- expanded_location exploc)
+default_start_span_fn<to_text> (const location_print_policy &loc_policy,
+ to_text &sink,
+ expanded_location exploc)
{
- const diagnostic_column_policy &column_policy
- = loc_policy.get_column_policy ();
+ const column_policy &column_policy_ = loc_policy.get_column_policy ();
label_text text
- = column_policy.get_location_text (exploc,
- loc_policy.show_column_p (),
- pp_show_color (&sink.m_pp));
+ = column_policy_.get_location_text (exploc,
+ loc_policy.show_column_p (),
+ pp_show_color (&sink.m_pp));
pp_string (&sink.m_pp, text.get ());
pp_newline (&sink.m_pp);
}
template<>
void
-diagnostics::default_start_span_fn<to_html> (const diagnostic_location_print_policy &loc_policy,
- to_html &sink,
- expanded_location exploc)
+default_start_span_fn<to_html> (const location_print_policy &loc_policy,
+ to_html &sink,
+ expanded_location exploc)
{
- const diagnostic_column_policy &column_policy
+ const column_policy &column_policy_
= loc_policy.get_column_policy ();
label_text text
- = column_policy.get_location_text (exploc,
- loc_policy.show_column_p (),
- false);
+ = column_policy_.get_location_text (exploc,
+ loc_policy.show_column_p (),
+ false);
sink.m_xp.push_tag_with_class ("span", "location", true);
sink.m_xp.add_text (text.get ());
sink.m_xp.pop_tag ("span");
}
+} // namespace diagnostics
+
namespace {
/* A class to control the overall layout when printing a diagnostic.
class layout
{
public:
- friend class layout_printer<to_text>;
- friend class layout_printer<to_html>;
+ friend class layout_printer<diagnostics::to_text>;
+ friend class layout_printer<diagnostics::to_html>;
- layout (const diagnostic_source_print_policy &source_policy,
+ layout (const diagnostics::source_print_policy &source_policy,
const rich_location &richloc,
diagnostics::source_effect_info *effect_info = nullptr);
private:
bool compatible_locations_p (location_t loc_a, location_t loc_b) const;
- const diagnostic_source_printing_options &m_options;
+ const diagnostics::source_printing_options &m_options;
const line_maps *m_line_table;
file_cache &m_file_cache;
const text_art::ascii_theme m_fallback_theme;
const layout &layout,
bool is_diagnostic_path);
- void print (const diagnostic_source_print_policy &source_policy);
+ void print (const diagnostics::source_print_policy &source_policy);
private:
- const diagnostic_source_printing_options &
+ const diagnostics::source_printing_options &
get_options () const { return m_layout.m_options; }
const text_art::theme &
/* Populate a char_display_policy based on SOURCE_POLICY and RICHLOC. */
static char_display_policy
-make_char_policy (const diagnostic_source_print_policy &source_policy,
+make_char_policy (const diagnostics::source_print_policy &source_policy,
const rich_location &richloc)
{
/* The default is to not escape non-ASCII bytes. */
char_display_policy result
(source_policy.get_column_policy ().get_tabstop (),
cpp_wcwidth,
- default_print_decoded_ch<to_text>,
- default_print_decoded_ch<to_html>);
+ default_print_decoded_ch<diagnostics::to_text>,
+ default_print_decoded_ch<diagnostics::to_html>);
/* If the diagnostic suggests escaping non-ASCII bytes, then
use policy from user-supplied options. */
gcc_unreachable ();
case DIAGNOSTICS_ESCAPE_FORMAT_UNICODE:
result.m_width_cb = escape_as_unicode_width;
- result.m_print_text_cb = escape_as_unicode_print<to_text>;
- result.m_print_html_cb = escape_as_unicode_print<to_html>;
+ result.m_print_text_cb
+ = escape_as_unicode_print<diagnostics::to_text>;
+ result.m_print_html_cb
+ = escape_as_unicode_print<diagnostics::to_html>;
break;
case DIAGNOSTICS_ESCAPE_FORMAT_BYTES:
result.m_width_cb = escape_as_bytes_width;
- result.m_print_text_cb = escape_as_bytes_print<to_text>;
- result.m_print_html_cb = escape_as_bytes_print<to_html>;
+ result.m_print_text_cb = escape_as_bytes_print<diagnostics::to_text>;
+ result.m_print_html_cb = escape_as_bytes_print<diagnostics::to_html>;
break;
}
}
Determine the range of lines that we will print, splitting them
up into an ordered list of disjoint spans of contiguous line numbers.
Determine m_x_offset_display, to ensure that the primary caret
- will fit within the max_width provided by the diagnostic_context. */
+ will fit within the max_width provided by the diagnostics::context. */
-layout::layout (const diagnostic_source_print_policy &source_policy,
+layout::layout (const diagnostics::source_print_policy &source_policy,
const rich_location &richloc,
diagnostics::source_effect_info *effect_info)
: m_options (source_policy.get_options ()),
template<>
void
-layout_printer<to_text>::print_gap_in_line_numbering ()
+layout_printer<diagnostics::to_text>::print_gap_in_line_numbering ()
{
gcc_assert (m_layout.m_options.show_line_numbers_p);
template<>
void
-layout_printer<to_html>::print_gap_in_line_numbering ()
+layout_printer<diagnostics::to_html>::print_gap_in_line_numbering ()
{
gcc_assert (m_layout.m_options.show_line_numbers_p);
template<>
void
-layout_printer<to_text>::end_line ()
+layout_printer<diagnostics::to_text>::end_line ()
{
m_sink.colorize_text_ensure_normal ();
m_sink.add_newline ();
template<>
void
-layout_printer<to_html>::end_line ()
+layout_printer<diagnostics::to_html>::end_line ()
{
m_sink.pop_html_tag ("td");
m_sink.pop_html_tag ("tr");
template<>
void
-layout_printer<to_text>::begin_label (int range_idx,
- bool is_label_text)
+layout_printer<diagnostics::to_text>::begin_label (int range_idx,
+ bool is_label_text)
{
/* Colorize the text, unless it's for labels for events in a
diagnostic path. */
template<>
void
-layout_printer<to_html>::begin_label (int range_idx,
- bool is_label_text)
+layout_printer<diagnostics::to_html>::begin_label (int range_idx,
+ bool is_label_text)
{
if (is_label_text && m_sink.m_html_label_writer)
m_sink.m_html_label_writer->begin_label ();
template<>
void
-layout_printer<to_text>::end_label (int, bool)
+layout_printer<diagnostics::to_text>::end_label (int, bool)
{
m_sink.colorize_text_ensure_normal ();
}
template<>
void
-layout_printer<to_html>::end_label (int range_idx,
- bool is_label_text)
+layout_printer<diagnostics::to_html>::end_label (int range_idx,
+ bool is_label_text)
{
if (m_sink.get_highlight_color_for_range_idx (range_idx))
m_sink.m_xp.pop_tag ("span");
bool
gcc_rich_location::
-add_location_if_nearby (const diagnostic_source_print_policy &policy,
+add_location_if_nearby (const diagnostics::source_print_policy &policy,
location_t loc,
bool restrict_to_current_line_spans,
const range_label *label)
bool
gcc_rich_location::
-add_location_if_nearby (const diagnostic_context &dc,
+add_location_if_nearby (const diagnostics::context &dc,
location_t loc,
bool restrict_to_current_line_spans,
const range_label *label)
{
- diagnostic_source_print_policy source_policy (dc,
- dc.m_source_printing);
+ diagnostics::source_print_policy source_policy (dc,
+ dc.m_source_printing);
return add_location_if_nearby (source_policy, loc,
restrict_to_current_line_spans, label);
}
+namespace diagnostics {
-/* As per diagnostic_source_print_policy::print, but don't print anything
+/* As per diagnostics::source_print_policy::print, but don't print anything
if source printing is disabled, or if the location hasn't changed. */
void
-diagnostic_context::maybe_show_locus (const rich_location &richloc,
- const diagnostic_source_printing_options &opts,
- diagnostic_t diagnostic_kind,
- pretty_printer &pp,
- diagnostics::source_effect_info *effects)
+context::maybe_show_locus (const rich_location &richloc,
+ const source_printing_options &opts,
+ diagnostic_t diagnostic_kind,
+ pretty_printer &pp,
+ source_effect_info *effects)
{
const location_t loc = richloc.get_loc ();
/* Do nothing if source-printing has been disabled. */
m_last_location = loc;
- diagnostic_source_print_policy source_policy (*this, opts);
+ source_print_policy source_policy (*this, opts);
source_policy.print (pp, richloc, diagnostic_kind, effects);
}
If non-null, use LABEL_WRITER when writing labelled ranges. */
void
-diagnostic_context::maybe_show_locus_as_html (const rich_location &richloc,
- const diagnostic_source_printing_options &opts,
- diagnostic_t diagnostic_kind,
- xml::printer &xp,
- diagnostics::source_effect_info *effects,
- html_label_writer *label_writer)
+context::maybe_show_locus_as_html (const rich_location &richloc,
+ const source_printing_options &opts,
+ diagnostic_t diagnostic_kind,
+ xml::printer &xp,
+ source_effect_info *effects,
+ html_label_writer *label_writer)
{
const location_t loc = richloc.get_loc ();
/* Do nothing if source-printing has been disabled. */
m_last_location = loc;
- diagnostic_source_print_policy source_policy (*this, opts);
+ source_print_policy source_policy (*this, opts);
source_policy.print_as_html (xp, richloc, diagnostic_kind, effects,
label_writer);
}
-diagnostic_source_print_policy::
-diagnostic_source_print_policy (const diagnostic_context &dc)
+source_print_policy::
+source_print_policy (const context &dc)
: m_options (dc.m_source_printing),
m_location_policy (dc),
m_text_start_span_cb (dc.m_text_callbacks.m_text_start_span),
{
}
-diagnostic_source_print_policy::
-diagnostic_source_print_policy (const diagnostic_context &dc,
- const diagnostic_source_printing_options &opts)
+source_print_policy::source_print_policy (const context &dc,
+ const source_printing_options &opts)
: m_options (opts),
m_location_policy (dc),
m_text_start_span_cb (dc.m_text_callbacks.m_text_start_span),
If EFFECTS is non-null, then use and update it. */
void
-diagnostic_source_print_policy::print (pretty_printer &pp,
- const rich_location &richloc,
- diagnostic_t diagnostic_kind,
- diagnostics::source_effect_info *effects)
- const
+source_print_policy::print (pretty_printer &pp,
+ const rich_location &richloc,
+ diagnostic_t diagnostic_kind,
+ source_effect_info *effects) const
{
layout layout (*this, richloc, effects);
colorizer col (pp, richloc, diagnostic_kind);
If non-null, use LABEL_WRITER when writing labelled ranges. */
void
-diagnostic_source_print_policy::print_as_html (xml::printer &xp,
- const rich_location &richloc,
- diagnostic_t diagnostic_kind,
- diagnostics::source_effect_info *effects,
- html_label_writer *label_writer)
- const
+source_print_policy::print_as_html (xml::printer &xp,
+ const rich_location &richloc,
+ diagnostic_t diagnostic_kind,
+ source_effect_info *effects,
+ html_label_writer *label_writer) const
{
layout layout (*this, richloc, effects);
to_html sink (xp, &richloc, label_writer);
lp.print (*this);
}
+} // namespace diagnostics
+
template <typename Sink>
void
-layout_printer<Sink>::print (const diagnostic_source_print_policy &source_policy)
+layout_printer<Sink>::
+print (const diagnostics::source_print_policy &source_policy)
{
typename Sink::auto_check_tag_nesting sentinel (m_sink);
{
expanded_location exploc
= m_layout.get_expanded_location (line_span);
- const diagnostic_location_print_policy &
+ const diagnostics::location_print_policy &
loc_policy = source_policy.get_location_policy ();
m_sink.invoke_start_span_fn (source_policy, loc_policy, exploc);
}
static std::unique_ptr<xml::node>
make_element_for_locus (const rich_location &rich_loc,
diagnostic_t kind,
- diagnostic_context &dc)
+ diagnostics::context &dc)
{
dc.m_last_location = UNKNOWN_LOCATION;
static label_text
make_raw_html_for_locus (const rich_location &rich_loc,
diagnostic_t kind,
- diagnostic_context &dc)
+ diagnostics::context &dc)
{
auto node = make_element_for_locus (rich_loc, kind, dc);
pretty_printer pp;
/* Populate a char_display_policy based on DC and RICHLOC. */
static char_display_policy
-make_char_policy (const diagnostic_context &dc,
+make_char_policy (const diagnostics::context &dc,
const rich_location &richloc)
{
- diagnostic_source_print_policy source_policy (dc);
+ diagnostics::source_print_policy source_policy (dc);
return ::make_char_policy (source_policy, richloc);
}
{
test_diagnostic_context dc;
dc.m_source_printing.max_width = max_width;
- /* diagnostic_context::min_margin_width sets the minimum space reserved for
+ /* min_margin_width sets the minimum space reserved for
the line number plus one space after. */
dc.m_source_printing.min_margin_width = left_margin - test_linenum_sep + 1;
dc.m_source_printing.show_line_numbers_p = true;
- diagnostic_source_print_policy source_policy (dc);
+ diagnostics::source_print_policy source_policy (dc);
rich_location richloc (line_table,
linemap_position_for_column (line_table,
caret_byte_col));
= test_left_margin - test_linenum_sep + 1;
dc.m_source_printing.show_line_numbers_p = true;
dc.m_source_printing.show_ruler_p = true;
- diagnostic_source_print_policy policy (dc);
+ diagnostics::source_print_policy policy (dc);
rich_location richloc (line_table,
linemap_position_for_column (line_table,
emoji_col));
layout test_layout (policy, richloc, nullptr);
colorizer col (*dc.get_reference_printer (),
richloc, DK_ERROR);
- to_text sink (*dc.get_reference_printer (), col);
- layout_printer<to_text> lp (sink, test_layout, false);
+ diagnostics::to_text sink (*dc.get_reference_printer (), col);
+ layout_printer<diagnostics::to_text> lp (sink, test_layout, false);
lp.print (policy);
ASSERT_STREQ (" | 1 \n"
" | 1 \n"
= test_left_margin - test_linenum_sep + 1;
dc.m_source_printing.show_line_numbers_p = true;
dc.m_source_printing.show_ruler_p = true;
- diagnostic_source_print_policy policy (dc);
+ diagnostics::source_print_policy policy (dc);
rich_location richloc (line_table,
linemap_position_for_column (line_table,
emoji_col + 2));
layout test_layout (dc, richloc, nullptr);
colorizer col (*dc.get_reference_printer (),
richloc, DK_ERROR);
- to_text sink (*dc.get_reference_printer (), col);
- layout_printer<to_text> lp (sink, test_layout, false);
+ diagnostics::to_text sink (*dc.get_reference_printer (), col);
+ layout_printer<diagnostics::to_text> lp (sink, test_layout, false);
lp.print (policy);
ASSERT_STREQ (" | 1 1 \n"
" | 1 2 \n"
{
test_diagnostic_context dc;
dc.m_tabstop = tabstop;
- diagnostic_source_print_policy policy (dc);
+ diagnostics::source_print_policy policy (dc);
layout test_layout (policy, richloc, nullptr);
colorizer col (*dc.get_reference_printer (),
richloc, DK_ERROR);
- to_text sink (*dc.get_reference_printer (), col);
- layout_printer<to_text> lp (sink, test_layout, false);
+ diagnostics::to_text sink (*dc.get_reference_printer (), col);
+ layout_printer<diagnostics::to_text> lp (sink, test_layout, false);
lp.print (policy);
const char *out = pp_formatted_text (dc.get_reference_printer ());
ASSERT_EQ (nullptr, strchr (out, '\t'));
dc.m_source_printing.min_margin_width
= test_left_margin - test_linenum_sep + 1;
dc.m_source_printing.show_line_numbers_p = true;
- diagnostic_source_print_policy policy (dc);
+ diagnostics::source_print_policy policy (dc);
layout test_layout (policy, richloc, nullptr);
colorizer col (*dc.get_reference_printer (),
richloc, DK_ERROR);
- to_text sink (*dc.get_reference_printer (), col);
- layout_printer<to_text> lp (sink, test_layout, false);
+ diagnostics::to_text sink (*dc.get_reference_printer (), col);
+ layout_printer<diagnostics::to_text> lp (sink, test_layout, false);
lp.print (policy);
/* We have arranged things so that two columns will be printed before
{
pretty_printer *pp = get_printer ();
- (*diagnostic_text_starter (&m_context)) (*this, &diagnostic);
+ (*text_starter (&m_context)) (*this, &diagnostic);
pp_output_formatted_text (pp, m_context.get_urlifier ());
}
}
- (*diagnostic_text_finalizer (&m_context)) (*this,
- &diagnostic,
- orig_diag_kind);
+ (*text_finalizer (&m_context)) (*this,
+ &diagnostic,
+ orig_diag_kind);
if (m_show_nesting && m_show_locations_in_nesting)
get_context ().m_last_location = diagnostic_location (&diagnostic);
/* Return true if DC's theme supports unicode characters. */
static bool
-use_unicode_p (const diagnostic_context &dc)
+use_unicode_p (const context &dc)
{
if (text_art::theme *theme = dc.get_diagram_theme ())
return theme->unicode_p ();
nested diagnostics. */
static unsigned
-get_bullet_point_unichar (diagnostic_context &dc)
+get_bullet_point_unichar (context &dc)
{
return get_bullet_point_unichar (use_unicode_p (dc));
}
void
text_sink::append_note (location_t location,
- const char * gmsgid, ...)
+ const char * gmsgid, ...)
{
- diagnostic_context *context = &get_context ();
+ context *dc = &get_context ();
diagnostic_info diagnostic;
va_list ap;
va_start (ap, gmsgid);
diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_NOTE);
- if (context->m_inhibit_notes_p)
+ if (dc->m_inhibit_notes_p)
{
va_end (ap);
return;
pp_destroy_prefix (pp);
pp_set_prefix (pp, saved_prefix);
pp_newline (pp);
- diagnostic_show_locus (context, get_source_printing_options (),
+ diagnostic_show_locus (dc, get_source_printing_options (),
&richloc, DK_NOTE, pp);
va_end (ap);
}
}
}
-/* Print any metadata about the option used to control DIAGNOSTIC to CONTEXT's
- printer, e.g. " [-Werror=uninitialized]".
- Subroutine of diagnostic_context::report_diagnostic. */
+/* Print any metadata about the option used to control DIAGNOSTIC to
+ the context's printer, e.g. " [-Werror=uninitialized]". */
void
text_sink::print_option_information (const diagnostic_info &diagnostic,
label_text
text_sink::get_location_text (const expanded_location &s) const
{
- diagnostic_column_policy column_policy (get_context ());
- return column_policy.get_location_text (s,
- show_column_p (),
- pp_show_color (get_printer ()));
+ column_policy column_policy_ (get_context ());
+ return column_policy_.get_location_text (s,
+ show_column_p (),
+ pp_show_color (get_printer ()));
}
/* Helpers for writing lang-specific starters/finalizers for text output. */
/* Subclass of diagnostics::sink for classic text-based output
to stderr.
- Uses diagnostic_context.m_text_callbacks to provide client-specific
+ Uses diagnostics::context.m_text_callbacks to provide client-specific
textual output (e.g. include paths, macro expansions, etc). */
class text_sink : public sink
{
public:
- text_sink (diagnostic_context &context,
- diagnostic_source_printing_options *source_printing = nullptr,
+ text_sink (context &dc,
+ source_printing_options *source_printing = nullptr,
bool follows_reference_printer = false)
- : sink (context),
+ : sink (dc),
m_saved_output_buffer (nullptr),
- m_column_policy (context),
+ m_column_policy (dc),
m_last_module (nullptr),
m_includes_seen (nullptr),
m_source_printing (source_printing
? *source_printing
- : context.m_source_printing),
+ : dc.m_source_printing),
m_follows_reference_printer (follows_reference_printer),
m_show_nesting (false),
m_show_nesting_levels (false)
bool show_column_p () const { return get_context ().m_show_column; }
- const diagnostic_column_policy &get_column_policy () const
+ const column_policy &get_column_policy () const
{
return m_column_policy;
}
- diagnostic_location_print_policy get_location_print_policy () const;
+ location_print_policy get_location_print_policy () const;
bool show_nesting_p () const { return m_show_nesting; }
bool show_locations_in_nesting_p () const
label_text get_location_text (const expanded_location &s) const;
- diagnostic_source_printing_options &get_source_printing_options ()
+ source_printing_options &get_source_printing_options ()
{
return m_source_printing;
}
- const diagnostic_source_printing_options &get_source_printing_options () const
+ const source_printing_options &get_source_printing_options () const
{
return m_source_printing;
}
/* For handling diagnostic_buffer. */
output_buffer *m_saved_output_buffer;
- diagnostic_column_policy m_column_policy;
+ column_policy m_column_policy;
/* Used to detect when the input file stack has changed since last
described. */
include path for. */
hash_set<location_t, false, location_hash> *m_includes_seen;
- diagnostic_source_printing_options &m_source_printing;
+ source_printing_options &m_source_printing;
/* If true, this is the initial default text output format created
- when the diagnostic_context was created, and, in particular, before
+ when the diagnostics::context was created, and, in particular, before
initializations of color and m_url_format. Hence this should follow
the dc's reference printer for these.
If false, this text output was created after the dc was created, and
/* Return a malloc'd string describing the kind of diagnostic. The
caller is responsible for freeing the memory. */
static char *
-gfc_diagnostic_build_kind_prefix (diagnostic_context *context,
+gfc_diagnostic_build_kind_prefix (diagnostics::context *context,
const diagnostic_info *diagnostic)
{
static const char *const diagnostic_kind_text[] = {
/* Return a malloc'd string describing a location. The caller is
responsible for freeing the memory. */
static char *
-gfc_diagnostic_build_locus_prefix (const diagnostic_location_print_policy &loc_policy,
+gfc_diagnostic_build_locus_prefix (const diagnostics::location_print_policy &loc_policy,
expanded_location s,
bool colorize)
{
/* Return a malloc'd string describing two locations. The caller is
responsible for freeing the memory. */
static char *
-gfc_diagnostic_build_locus_prefix (const diagnostic_location_print_policy &loc_policy,
+gfc_diagnostic_build_locus_prefix (const diagnostics::location_print_policy &loc_policy,
expanded_location s, expanded_location s2,
bool colorize)
{
gfc_diagnostic_text_starter (diagnostics::text_sink &text_output,
const diagnostic_info *diagnostic)
{
- diagnostic_context *const context = &text_output.get_context ();
+ diagnostics::context *const context = &text_output.get_context ();
pretty_printer *const pp = text_output.get_printer ();
char * kind_prefix = gfc_diagnostic_build_kind_prefix (context, diagnostic);
same_locus = diagnostic_same_line (context, s1, s2);
}
- diagnostic_location_print_policy loc_policy (text_output);
+ diagnostics::location_print_policy loc_policy (text_output);
const bool colorize = pp_show_color (pp);
char * locus_prefix = (one_locus || !same_locus)
? gfc_diagnostic_build_locus_prefix (loc_policy, s1, colorize)
}
static void
-gfc_diagnostic_start_span (const diagnostic_location_print_policy &loc_policy,
- to_text &sink,
+gfc_diagnostic_start_span (const diagnostics::location_print_policy &loc_policy,
+ diagnostics::to_text &sink,
expanded_location exploc)
{
- pretty_printer *pp = get_printer (sink);
+ pretty_printer *pp = diagnostics::get_printer (sink);
const bool colorize = pp_show_color (pp);
char *locus_prefix
= gfc_diagnostic_build_locus_prefix (loc_policy, exploc, colorize);
void
gfc_diagnostics_init (void)
{
- diagnostic_text_starter (global_dc) = gfc_diagnostic_text_starter;
- diagnostic_start_span (global_dc) = gfc_diagnostic_start_span;
- diagnostic_text_finalizer (global_dc) = gfc_diagnostic_text_finalizer;
+ diagnostics::text_starter (global_dc) = gfc_diagnostic_text_starter;
+ diagnostics::start_span (global_dc) = gfc_diagnostic_start_span;
+ diagnostics::text_finalizer (global_dc) = gfc_diagnostic_text_finalizer;
global_dc->set_format_decoder (gfc_format_decoder);
global_dc->m_source_printing.caret_chars[0] = '1';
global_dc->m_source_printing.caret_chars[1] = '2';
tree_diagnostics_defaults (global_dc);
/* We still want to use the gfc starter and finalizer, not the tree
defaults. */
- diagnostic_text_starter (global_dc) = gfc_diagnostic_text_starter;
- diagnostic_text_finalizer (global_dc) = gfc_diagnostic_text_finalizer;
+ diagnostics::text_starter (global_dc) = gfc_diagnostic_text_starter;
+ diagnostics::text_finalizer (global_dc) = gfc_diagnostic_text_finalizer;
global_dc->m_source_printing.caret_chars[0] = '^';
global_dc->m_source_printing.caret_chars[1] = '^';
delete error_buffer;
#include "rich-location.h"
-class diagnostic_source_print_policy;
+namespace diagnostics { class source_print_policy; }
/* A gcc_rich_location is libcpp's rich_location with additional
helper methods for working with gcc's types. The class is not
Implemented in diagnostics/source-printing.cc. */
- bool add_location_if_nearby (const diagnostic_source_print_policy &policy,
+ bool add_location_if_nearby (const diagnostics::source_print_policy &policy,
location_t loc,
bool restrict_to_current_line_spans = true,
const range_label *label = NULL);
- bool add_location_if_nearby (const diagnostic_context &dc,
+ bool add_location_if_nearby (const diagnostics::context &dc,
location_t loc,
bool restrict_to_current_line_spans = true,
const range_label *label = NULL);
unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
location_t loc,
const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED,
- diagnostic_context *dc,
+ diagnostics::context *dc,
void (*) (void))
{
size_t opt_index = decoded->opt_index;
end
define break-on-diagnostic
-break diagnostic_context::maybe_show_locus
+break diagnostics::context::maybe_show_locus
end
document break-on-diagnostic
-Put a breakpoint on diagnostic_show_locus, called whenever a diagnostic
-is emitted (as opposed to those warnings that are suppressed by
+Put a breakpoint on diagnostics::context::show_locus, called whenever
+a diagnostic is emitted (as opposed to those warnings that are suppressed by
command-line options).
end
class jit_diagnostic_listener : public diagnostics::text_sink
{
public:
- jit_diagnostic_listener (diagnostic_context &dc,
+ jit_diagnostic_listener (diagnostics::context &dc,
gcc::jit::playback::context &playback_ctxt)
: diagnostics::text_sink (dc),
m_playback_ctxt (playback_ctxt)
}
gcc_assert (global_dc);
- diagnostic_text_starter (global_dc) = jit_begin_diagnostic;
- diagnostic_text_finalizer (global_dc) = jit_end_diagnostic;
+ diagnostics::text_starter (global_dc) = jit_begin_diagnostic;
+ diagnostics::text_finalizer (global_dc) = jit_end_diagnostic;
auto sink
= std::make_unique<jit_diagnostic_listener>
(*global_dc,
#include "jit-recording.h"
-class diagnostic_context;
-namespace diagnostics { struct diagnostic_info; }
+namespace diagnostics
+{
+ class context;
+ struct diagnostic_info;
+}
namespace gcc {
extern tree lhd_enum_underlying_base_type (const_tree);
/* Declarations of default tree inlining hooks. */
-extern void lhd_initialize_diagnostics (diagnostic_context *);
+extern void lhd_initialize_diagnostics (diagnostics::context *);
extern void lhd_init_options (unsigned int,
struct cl_decoded_option *);
extern bool lhd_complain_wrong_lang_p (const struct cl_option *);
/* Called to perform language-specific initialization of CTX. */
void
-lhd_initialize_diagnostics (diagnostic_context *ctx ATTRIBUTE_UNUSED)
+lhd_initialize_diagnostics (diagnostics::context *ctx ATTRIBUTE_UNUSED)
{
}
const char *file,
const diagnostic_info *diagnostic)
{
- diagnostic_context *const context = &text_output.get_context ();
+ diagnostics::context *const context = &text_output.get_context ();
if (diagnostic_last_function_changed (context, diagnostic))
{
pretty_printer *const pp = text_output.get_printer ();
/* Callback used to perform language-specific initialization for the
global diagnostic context structure. */
- void (*initialize_diagnostics) (diagnostic_context *);
+ void (*initialize_diagnostics) (diagnostics::context *);
/* Beginning the main source file. */
void (*preprocess_main_file) (cpp_reader *, line_maps *,
FILE *dst_stream,
enum diagnostic_colorize colorize);
- diagnostic_source_printing_options &get_source_printing_options ()
+ diagnostics::source_printing_options &get_source_printing_options ()
{
return m_source_printing;
}
private:
diagnostics::text_sink *m_inner_sink; // borrowed from dc
- diagnostic_source_printing_options m_source_printing;
+ diagnostics::source_printing_options m_source_printing;
};
/* A token_printer that makes a deep copy of the pp_token_list
m_dc.set_client_data_hooks
(std::make_unique<impl_diagnostic_client_data_hooks> (*this));
- diagnostic_text_starter (&m_dc) = diagnostic_text_sink::text_starter;
+ diagnostics::text_starter (&m_dc) = diagnostic_text_sink::text_starter;
m_edit_context
= std::make_unique <diagnostics::edit_context> (m_dc.get_file_cache ());
}
line_maps *get_line_table () { return &m_line_table; }
- diagnostic_context &get_dc () { return m_dc; }
+ diagnostics::context &get_dc () { return m_dc; }
const diagnostics::logical_locations::manager &
get_logical_location_manager () const
return phys_loc;
}
- diagnostic_context m_dc;
+ diagnostics::context m_dc;
line_maps m_line_table;
impl_client_version_info m_client_version_info;
std::vector<std::unique_ptr<sink>> m_sinks;
diag_mgr->set_line_table_global ();
const expanded_location exp_loc (expand_location (cpplib_loc));
- diagnostic_context dc;
+ diagnostics::context dc;
diagnostic_initialize (&dc, 0);
dc.m_show_column = true;
print " unsigned int lang_mask, int kind, "
print " location_t loc, "
print " const struct cl_option_handlers *handlers, "
-print " diagnostic_context *dc) "
+print " diagnostics::context *dc) "
print "{ "
print " size_t scode = decoded->opt_index; "
print " HOST_WIDE_INT value = decoded->value; "
print " unsigned int lang_mask" mark_unused ", int kind" mark_unused ", "
print " location_t loc" mark_unused ", "
print " const struct cl_option_handlers *handlers" mark_unused ", "
- print " diagnostic_context *dc" mark_unused ") "
+ print " diagnostics::context *dc" mark_unused ") "
print "{ "
print " enum opt_code code = (enum opt_code) scode; "
print " "
print " unsigned int lang_mask, int kind, "
print " location_t loc, "
print " const struct cl_option_handlers *handlers, "
-print " diagnostic_context *dc); "
+print " diagnostics::context *dc); "
for (i = 0; i < n_langs; i++) {
lang_name = lang_sanitized_name(langs[i]);
print "bool"
print " unsigned int lang_mask, int kind,"
print " location_t loc,"
print " const struct cl_option_handlers *handlers,"
- print " diagnostic_context *dc);"
+ print " diagnostics::context *dc);"
}
print "void cpp_handle_option_auto (const struct gcc_options * opts, size_t scode,"
print " struct cpp_options * cpp_opts);"
const struct cl_decoded_option *decoded,
unsigned int lang_mask, int kind, location_t loc,
const struct cl_option_handlers *handlers,
- bool generated_p, diagnostic_context *dc)
+ bool generated_p, diagnostics::context *dc)
{
size_t opt_index = decoded->opt_index;
const char *arg = decoded->arg;
size_t opt_index, const char *arg, HOST_WIDE_INT value,
unsigned int lang_mask, int kind, location_t loc,
const struct cl_option_handlers *handlers,
- bool generated_p, diagnostic_context *dc)
+ bool generated_p, diagnostics::context *dc)
{
struct cl_decoded_option decoded;
location_t loc,
unsigned int lang_mask,
const struct cl_option_handlers *handlers,
- diagnostic_context *dc)
+ diagnostics::context *dc)
{
const struct cl_option *option;
const char *opt = decoded->orig_option_with_args_text;
void
set_option (struct gcc_options *opts, struct gcc_options *opts_set,
size_t opt_index, HOST_WIDE_INT value, const char *arg,
- int kind, location_t loc, diagnostic_context *dc,
+ int kind, location_t loc, diagnostics::context *dc,
HOST_WIDE_INT mask /* = 0 */)
{
const struct cl_option *option = &cl_options[opt_index];
const struct cl_option_handlers *handlers,
struct gcc_options *opts,
struct gcc_options *opts_set,
- diagnostic_context *dc)
+ diagnostics::context *dc)
{
if (cl_options[opt_index].alias_target != N_OPTS)
{
{
public:
opt_spec_context (const gcc_options &opts,
- diagnostic_context &dc,
+ diagnostics::context &dc,
line_maps *location_mgr,
location_t loc,
const char *option_name)
void
handle_OPT_fdiagnostics_add_output_ (const gcc_options &opts,
- diagnostic_context &dc,
+ diagnostics::context &dc,
const char *arg,
location_t loc)
{
void
handle_OPT_fdiagnostics_set_output_ (const gcc_options &opts,
- diagnostic_context &dc,
+ diagnostics::context &dc,
const char *arg,
location_t loc)
{
#ifndef GCC_OPTS_DIAGNOSTIC_H
#define GCC_OPTS_DIAGNOSTIC_H
-/* Abstract subclass of diagnostic_option_manager for gcc options. */
+/* Abstract subclass of diagnostics::option_manager for gcc options. */
-class gcc_diagnostic_option_manager : public diagnostic_option_manager
+class gcc_diagnostic_option_manager : public diagnostics::option_manager
{
public:
char *make_option_url (diagnostic_option_id option_id) const final override;
class compiler_diagnostic_option_manager : public gcc_diagnostic_option_manager
{
public:
- compiler_diagnostic_option_manager (const diagnostic_context &context,
+ compiler_diagnostic_option_manager (const diagnostics::context &context,
unsigned lang_mask,
void *opts)
: gcc_diagnostic_option_manager (lang_mask),
diagnostic_t diag_kind) const final override;
private:
- const diagnostic_context &m_context;
+ const diagnostics::context &m_context;
void *m_opts;
};
extern void
handle_OPT_fdiagnostics_add_output_ (const gcc_options &opts,
- diagnostic_context &dc,
+ diagnostics::context &dc,
const char *arg,
location_t loc);
extern void
handle_OPT_fdiagnostics_set_output_ (const gcc_options &opts,
- diagnostic_context &dc,
+ diagnostics::context &dc,
const char *arg,
location_t loc);
#endif
unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
location_t loc,
const struct cl_option_handlers *handlers,
- diagnostic_context *dc,
+ diagnostics::context *dc,
void (*) (void))
{
gcc_assert (opts == &global_options);
location_t loc,
unsigned int lang_mask,
const struct cl_option_handlers *handlers,
- diagnostic_context *dc)
+ diagnostics::context *dc)
{
unsigned int i;
decode_options (struct gcc_options *opts, struct gcc_options *opts_set,
struct cl_decoded_option *decoded_options,
unsigned int decoded_options_count,
- location_t loc, diagnostic_context *dc,
+ location_t loc, diagnostics::context *dc,
void (*target_option_override_hook) (void))
{
struct cl_option_handlers handlers;
location_t loc);
static void set_fast_math_flags (struct gcc_options *opts, int set);
static void decode_d_option (const char *arg, struct gcc_options *opts,
- location_t loc, diagnostic_context *dc);
+ location_t loc, diagnostics::context *dc);
static void set_unsafe_math_optimizations_flags (struct gcc_options *opts,
int set);
static void enable_warning_as_error (const char *arg, int value,
struct gcc_options *opts,
struct gcc_options *opts_set,
location_t loc,
- diagnostic_context *dc);
+ diagnostics::context *dc);
/* Handle a back-end option; arguments and return value as for
handle_option. */
unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
location_t loc,
const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED,
- diagnostic_context *dc, void (*) (void))
+ diagnostics::context *dc, void (*) (void))
{
gcc_assert (dc == global_dc);
gcc_assert (kind == DK_UNSPECIFIED);
unsigned int lang_mask,
const struct cl_option_handlers *handlers,
location_t loc,
- diagnostic_context *dc)
+ diagnostics::context *dc)
{
const struct cl_option *option = &cl_options[default_opt->opt_index];
bool enabled;
unsigned int lang_mask,
const struct cl_option_handlers *handlers,
location_t loc,
- diagnostic_context *dc)
+ diagnostics::context *dc)
{
size_t i;
location_t loc,
unsigned int lang_mask,
const struct cl_option_handlers *handlers,
- diagnostic_context *dc)
+ diagnostics::context *dc)
{
unsigned int i;
int opt2;
unsigned int lang_mask, int kind ATTRIBUTE_UNUSED,
location_t loc,
const struct cl_option_handlers *handlers,
- diagnostic_context *dc,
+ diagnostics::context *dc,
void (*target_option_override_hook) (void))
{
size_t scode = decoded->opt_index;
abort ().) */
static void
-setup_core_dumping (diagnostic_context *dc)
+setup_core_dumping (diagnostics::context *dc)
{
#ifdef SIGABRT
signal (SIGABRT, SIG_DFL);
static void
decode_d_option (const char *arg, struct gcc_options *opts,
- location_t loc, diagnostic_context *dc)
+ location_t loc, diagnostics::context *dc)
{
int c;
const struct cl_option_handlers *handlers,
struct gcc_options *opts,
struct gcc_options *opts_set,
- location_t loc, diagnostic_context *dc)
+ location_t loc, diagnostics::context *dc)
{
char *new_option;
int option_index;
const struct cl_decoded_option *decoded,
unsigned int lang_mask, int kind, location_t loc,
const struct cl_option_handlers *handlers,
- diagnostic_context *dc,
+ diagnostics::context *dc,
void (*target_option_override_hook) (void));
/* The mask that must have some bit in common with the flags for the
struct cl_decoded_option *decoded_options,
unsigned int decoded_options_count,
location_t loc,
- diagnostic_context *dc,
+ diagnostics::context *dc,
void (*target_option_override_hook) (void));
extern int option_enabled (int opt_idx, unsigned lang_mask, void *opts);
extern void set_option (struct gcc_options *opts,
struct gcc_options *opts_set,
size_t opt_index, HOST_WIDE_INT value, const char *arg,
- int kind, location_t loc, diagnostic_context *dc,
+ int kind, location_t loc, diagnostics::context *dc,
HOST_WIDE_INT = 0);
extern void *option_flag_var (int opt_index, struct gcc_options *opts);
bool handle_generated_option (struct gcc_options *opts,
HOST_WIDE_INT value,
unsigned int lang_mask, int kind, location_t loc,
const struct cl_option_handlers *handlers,
- bool generated_p, diagnostic_context *dc);
+ bool generated_p, diagnostics::context *dc);
void generate_option (size_t opt_index, const char *arg, HOST_WIDE_INT value,
unsigned int lang_mask,
struct cl_decoded_option *decoded);
location_t loc,
unsigned int lang_mask,
const struct cl_option_handlers *handlers,
- diagnostic_context *dc);
+ diagnostics::context *dc);
extern void control_warning_option (unsigned int opt_index, int kind,
const char *arg, bool imply, location_t loc,
unsigned int lang_mask,
const struct cl_option_handlers *handlers,
struct gcc_options *opts,
struct gcc_options *opts_set,
- diagnostic_context *dc);
+ diagnostics::context *dc);
extern char *write_langs (unsigned int mask);
extern void print_ignored_options (void);
extern void handle_common_deferred_options (void);
unsigned int lang_mask, int kind,
location_t loc,
const struct cl_option_handlers *handlers,
- diagnostic_context *dc,
+ diagnostics::context *dc,
void (*target_option_override_hook) (void));
extern bool target_handle_option (struct gcc_options *opts,
struct gcc_options *opts_set,
unsigned int lang_mask, int kind,
location_t loc,
const struct cl_option_handlers *handlers,
- diagnostic_context *dc,
+ diagnostics::context *dc,
void (*target_option_override_hook) (void));
extern void finish_options (struct gcc_options *opts,
struct gcc_options *opts_set,
location_t loc,
unsigned int lang_mask,
const struct cl_option_handlers *handlers,
- diagnostic_context *dc);
+ diagnostics::context *dc);
extern void set_struct_debug_option (struct gcc_options *opts,
location_t loc,
const char *value);
resolve. Emit a funny ICE. We set the finalizer to our custom one,
and use the lower-level emit_diagnostic () instead of the more common
internal_error_no_backtrace () in order to pass our locus. */
- diagnostic_text_finalizer (global_dc) = funny_ice_text_finalizer;
+ diagnostics::text_finalizer (global_dc) = funny_ice_text_finalizer;
emit_diagnostic (DK_ICE_NOBT, expr.get_locus (), -1,
"are you trying to break %s? how dare you?",
expr.as_string ().c_str ());
}
else if (funny_error)
{
- diagnostic_text_finalizer (global_dc) = Resolver::funny_ice_text_finalizer;
+ diagnostics::text_finalizer (global_dc) = Resolver::funny_ice_text_finalizer;
emit_diagnostic (DK_ICE_NOBT, expr.get_locus (), -1,
"are you trying to break %s? how dare you?",
expr.as_string ().c_str ());
m_source_printing.enabled = true;
m_source_printing.show_labels_p = true;
m_show_column = true;
- diagnostic_start_span (this) = start_span_cb;
+ diagnostics::start_span (this) = start_span_cb;
m_source_printing.min_margin_width = 6;
m_source_printing.max_width = 80;
pp_buffer (get_sink (0).get_printer ())->m_flush_p = false;
void
test_diagnostic_context::
-start_span_cb (const diagnostic_location_print_policy &loc_policy,
- to_text &sink,
+start_span_cb (const diagnostics::location_print_policy &loc_policy,
+ diagnostics::to_text &sink,
expanded_location exploc)
{
exploc.file = "FILENAME";
- diagnostics::default_start_span_fn<to_text> (loc_policy, sink, exploc);
+ diagnostics::default_start_span_fn<diagnostics::to_text>
+ (loc_policy, sink, exploc);
}
bool
{
pretty_printer *pp = get_reference_printer ();
gcc_assert (pp);
- diagnostic_source_print_policy source_policy (*this);
+ diagnostics::source_print_policy source_policy (*this);
source_policy.print (*pp, richloc, DK_ERROR, nullptr);
return pp_formatted_text (pp);
}
namespace selftest {
-/* Convenience subclass of diagnostic_context for testing
+/* Convenience subclass of diagnostics::context for testing
the diagnostic subsystem. */
-class test_diagnostic_context : public diagnostic_context
+class test_diagnostic_context : public diagnostics::context
{
public:
test_diagnostic_context ();
/* Implementation of diagnostic_start_span_fn, hiding the
real filename (to avoid printing the names of tempfiles). */
static void
- start_span_cb (const diagnostic_location_print_policy &,
- to_text &sink,
+ start_span_cb (const diagnostics::location_print_policy &,
+ diagnostics::to_text &sink,
expanded_location exploc);
/* Report a diagnostic to this context. For a selftest, this
int plugin_is_GPL_compatible;
void
-noop_text_starter_fn (diagnostic_text_output_format &, const diagnostic_info *)
+noop_text_starter_fn (diagnostics::text_sink &, const diagnostic_info *)
{
}
if (!plugin_default_version_check (version, &gcc_version))
return 1;
- diagnostic_text_starter (global_dc) = noop_text_starter_fn;
+ diagnostics::text_starter (global_dc) = noop_text_starter_fn;
return 0;
}
expected output. */
void
-test_diagnostic_start_span_fn (const diagnostic_location_print_policy &,
- to_text &sink,
+test_diagnostic_start_span_fn (const diagnostics::location_print_policy &,
+ diagnostics::to_text &sink,
expanded_location)
{
- pretty_printer *pp = get_printer (sink);
+ pretty_printer *pp = diagnostics::get_printer (sink);
pp_string (pp, "START_SPAN_FN: ");
pp_newline (pp);
}
class custom_test_sink : public diagnostics::text_sink
{
public:
- custom_test_sink (diagnostic_context &context)
+ custom_test_sink (diagnostics::context &context)
: diagnostics::text_sink (context)
{}
if (!plugin_default_version_check (version, &gcc_version))
return 1;
- diagnostic_text_starter (global_dc) = test_diagnostic_text_starter;
- diagnostic_start_span (global_dc) = test_diagnostic_start_span_fn;
+ diagnostics::text_starter (global_dc) = test_diagnostic_text_starter;
+ diagnostics::start_span (global_dc) = test_diagnostic_start_span_fn;
global_dc->set_sink (::std::make_unique<custom_test_sink> (*global_dc));
pass_info.pass = new pass_test_groups (g);
location_t fnstart = fun->function_start_locus;
int fnstart_line = LOCATION_LINE (fnstart);
- diagnostic_text_finalizer (global_dc) = custom_diagnostic_text_finalizer;
+ diagnostics::text_finalizer (global_dc) = custom_diagnostic_text_finalizer;
/* Hardcode the "terminal width", to verify the behavior of
very wide lines. */
/* We add some extra testing during diagnostics by chaining up
to the text finalizer. */
-static diagnostic_text_finalizer_fn original_text_finalizer = NULL;
+static diagnostics::text_finalizer_fn original_text_finalizer = NULL;
static void
verify_unpacked_ranges (diagnostics::text_sink &text_output,
NULL); /* void *user_data */
/* Hack in additional testing, based on the exact value supplied. */
- original_text_finalizer = diagnostic_text_finalizer (global_dc);
+ original_text_finalizer = diagnostics::text_finalizer (global_dc);
switch (base_location)
{
case LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES + 1:
- diagnostic_text_finalizer (global_dc) = verify_unpacked_ranges;
+ diagnostics::text_finalizer (global_dc) = verify_unpacked_ranges;
break;
case LINE_MAP_MAX_LOCATION_WITH_COLS + 1:
- diagnostic_text_finalizer (global_dc) = verify_no_columns;
+ diagnostics::text_finalizer (global_dc) = verify_no_columns;
break;
default:
/* Alternative diagnostics callback for reentered ICE reporting. */
static void
-internal_error_reentered (diagnostic_context *, const char *, va_list *)
+internal_error_reentered (diagnostics::context *, const char *, va_list *)
{
/* Flush the dump file if emergency_dump_function itself caused an ICE. */
if (dump_file)
/* Auxiliary callback for the diagnostics code. */
static void
-internal_error_function (diagnostic_context *, const char *, va_list *)
+internal_error_function (diagnostics::context *, const char *, va_list *)
{
global_dc->set_internal_error_callback (internal_error_reentered);
warn_if_plugins ();
#include "plugin.h"
#include "timevar.h"
-/* Concrete class for supplying a diagnostic_context with information
+/* Concrete class for supplying a diagnostics::context with information
about a specific plugin within the client, when the client is the
compiler (i.e. a GCC plugin). */
to the DIAGNOSTIC location. */
static void
-set_inlining_locations (diagnostic_context *,
+set_inlining_locations (diagnostics::context *,
diagnostic_info *diagnostic)
{
location_t loc = diagnostic_location (diagnostic);
/* Sets CONTEXT to use language independent diagnostics. */
void
-tree_diagnostics_defaults (diagnostic_context *context)
+tree_diagnostics_defaults (diagnostics::context *context)
{
- diagnostic_text_starter (context) = default_tree_diagnostic_text_starter;
- diagnostic_text_finalizer (context) = diagnostics::default_text_finalizer;
+ diagnostics::text_starter (context) = default_tree_diagnostic_text_starter;
+ diagnostics::text_finalizer (context) = diagnostics::default_text_finalizer;
context->set_format_decoder (default_tree_printer);
context->set_set_locations_callback (set_inlining_locations);
context->set_client_data_hooks (make_compiler_data_hooks ());
? diagnostic_abstract_origin (DI) \
: current_function_decl)
-void diagnostic_report_current_function (diagnostic_context *,
+void diagnostic_report_current_function (diagnostics::context *,
const diagnostic_info *);
-void tree_diagnostics_defaults (diagnostic_context *context);
+void tree_diagnostics_defaults (diagnostics::context *);
bool default_tree_printer (pretty_printer *, text_info *, const char *,
int, bool, bool, bool, bool *, pp_token_list &);