to a file). */
static void
-diagnostic_output_format_init_json (diagnostic_context &context)
+diagnostic_output_format_init_json (diagnostic_context &context,
+ std::unique_ptr<json_output_format> fmt)
{
/* Suppress normal textual path output. */
context.set_path_format (DPF_NONE);
/* Don't colorize the text. */
- pp_show_color (context.m_printer) = false;
+ pp_show_color (fmt->get_printer ()) = false;
context.set_show_highlight_colors (false);
+
+ context.set_output_format (fmt.release ());
}
/* Populate CONTEXT in preparation for JSON output to stderr. */
diagnostic_output_format_init_json_stderr (diagnostic_context &context,
bool formatted)
{
- diagnostic_output_format_init_json (context);
- context.set_output_format (new json_stderr_output_format (context,
- formatted));
+ diagnostic_output_format_init_json
+ (context,
+ ::make_unique<json_stderr_output_format> (context,
+ formatted));
}
/* Populate CONTEXT in preparation for JSON output to a file named
bool formatted,
const char *base_file_name)
{
- diagnostic_output_format_init_json (context);
- context.set_output_format (new json_file_output_format (context,
- formatted,
- base_file_name));
+ diagnostic_output_format_init_json
+ (context,
+ ::make_unique<json_file_output_format> (context,
+ formatted,
+ base_file_name));
}
#if CHECKING_P
context.set_ice_handler_callback (sarif_ice_handler);
/* Don't colorize the text. */
- pp_show_color (context.m_printer) = false;
+ pp_show_color (fmt->get_printer ()) = false;
context.set_show_highlight_colors (false);
context.m_printer->set_token_printer
print_path_summary_as_text (summary, text_output, true);
ASSERT_STREQ ("",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
/* Verify that print_path_summary works on a purely intraprocedural path. */
ASSERT_STREQ (" `foo': events 1-2 (depth 0)\n"
" (1): first `free'\n"
" (2): double `free'\n",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
/* Verify that print_path_summary works on an interprocedural path. */
" | (17): entering `wrapped_free'\n"
" | (18): calling free\n"
" |\n",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
{
test_diagnostic_context dc;
" │ (17): entering `wrapped_free'\n"
" │ (18): calling free\n"
" │\n",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
}
" |\n"
" | (8): entering `baz'\n"
" |\n",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
{
test_diagnostic_context dc;
" │\n"
" │ (8): entering `baz'\n"
" │\n",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
}
" |\n"
" | (7): entering `factorial'\n"
" |\n",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
{
test_diagnostic_context dc;
" │\n"
" │ (7): entering `factorial'\n"
" │\n",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
}
"| |\n"
"+-------->(2) ...to here\n"
" (3) dereference of NULL `p'\n",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
{
test_diagnostic_context dc;
" |\n"
" (2) ...to here\n"
" (3) dereference of NULL `p'\n",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
{
test_diagnostic_context dc;
" || |\n"
" |+-------->(2) ...to here\n"
" | (3) dereference of NULL `p'\n",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
{
test_diagnostic_context dc;
" | |\n"
" | (2) ...to here\n"
" | (3) dereference of NULL `p'\n",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
{
test_diagnostic_context dc;
"│ |\n"
"└────────>(2) ...to here\n"
" (3) dereference of NULL `p'\n",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
{
test_diagnostic_context dc;
" |│ |\n"
" |└────────>(2) ...to here\n"
" | (3) dereference of NULL `p'\n",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
}
" || ^~~~\n"
" || |\n"
" |+----------------------------->(5) ...to here\n",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
}
" || ^\n"
" || |\n"
" |+----------------->(5) ...to here\n",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
}
path_summary summary (text_output, path, true);
print_path_summary_as_text (summary, text_output, false);
ASSERT_STREQ_AT (loc, expected_str,
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
/* Assert that if we make a path with an event with "from here..." at SRC_LOC
" || ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
" || | |\n"
" |+----------->(4) ...to here (5) allocated here\n",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
}
" || ~~~~~~~~~~~~~\n"
" || |\n"
" |+------------->(5) ...to here\n",
- pp_formatted_text (dc.m_printer));
+ pp_formatted_text (text_output.get_printer ()));
}
}
void on_begin_group () final override
{
/* Loudly announce a new diagnostic group. */
- pp_string (m_context.m_printer,
+ pretty_printer *const pp = get_printer ();
+ pp_string (pp,
"================================= BEGIN GROUP ==============================");
- pp_newline (m_context.m_printer);
+ pp_newline (pp);
}
void on_end_group () final override
{
/* Loudly announce the end of a diagnostic group. */
- pp_set_prefix (m_context.m_printer, NULL);
- pp_string (m_context.m_printer,
+ pretty_printer *const pp = get_printer ();
+ pp_set_prefix (pp, NULL);
+ pp_string (pp,
"---------------------------------- END GROUP -------------------------------");
- pp_newline_and_flush (m_context.m_printer);
+ pp_newline_and_flush (pp);
}
};
{
public:
xhtml_builder (diagnostic_context &context,
+ pretty_printer &pp,
const line_maps *line_maps);
- void on_report_diagnostic (diagnostic_context &context,
- const diagnostic_info &diagnostic,
+ void on_report_diagnostic (const diagnostic_info &diagnostic,
diagnostic_t orig_diag_kind);
- void emit_diagram (diagnostic_context &context,
- const diagnostic_diagram &diagram);
+ void emit_diagram (const diagnostic_diagram &diagram);
void end_group ();
std::unique_ptr<xml::element> take_current_diagnostic ()
private:
std::unique_ptr<xml::element>
- make_element_for_diagnostic (diagnostic_context &context,
- const diagnostic_info &diagnostic,
+ make_element_for_diagnostic (const diagnostic_info &diagnostic,
diagnostic_t orig_diag_kind);
diagnostic_context &m_context;
+ pretty_printer &m_printer;
const line_maps *m_line_maps;
std::unique_ptr<xml::document> m_document;
/* xhtml_builder's ctor. */
xhtml_builder::xhtml_builder (diagnostic_context &context,
+ pretty_printer &pp,
const line_maps *line_maps)
: m_context (context),
+ m_printer (pp),
m_line_maps (line_maps)
{
gcc_assert (m_line_maps);
/* Implementation of "on_report_diagnostic" for XHTML output. */
void
-xhtml_builder::on_report_diagnostic (diagnostic_context &context,
- const diagnostic_info &diagnostic,
+xhtml_builder::on_report_diagnostic (const diagnostic_info &diagnostic,
diagnostic_t orig_diag_kind)
{
// TODO: handle (diagnostic.kind == DK_ICE || diagnostic.kind == DK_ICE_NOBT)
auto diag_element
- = make_element_for_diagnostic (context, diagnostic, orig_diag_kind);
+ = make_element_for_diagnostic (diagnostic, orig_diag_kind);
if (m_cur_diagnostic_element)
/* Nested diagnostic. */
m_cur_diagnostic_element->add_child (std::move (diag_element));
}
std::unique_ptr<xml::element>
-xhtml_builder::make_element_for_diagnostic (diagnostic_context &context,
- const diagnostic_info &diagnostic,
+xhtml_builder::make_element_for_diagnostic (const diagnostic_info &diagnostic,
diagnostic_t orig_diag_kind)
{
class xhtml_token_printer : public token_printer
auto message_span = make_span (label_text::borrow ("gcc-message"));
xhtml_token_printer tok_printer (*this, *message_span.get ());
- context.m_printer->set_token_printer (&tok_printer);
- pp_output_formatted_text (context.m_printer, context.get_urlifier ());
- context.m_printer->set_token_printer (nullptr);
- pp_clear_output_area (context.m_printer);
+ m_printer.set_token_printer (&tok_printer);
+ pp_output_formatted_text (&m_printer, m_context.get_urlifier ());
+ m_printer.set_token_printer (nullptr);
+ pp_clear_output_area (&m_printer);
diag_element->add_child (std::move (message_span));
if (diagnostic.metadata)
auto pre = ::make_unique<xml::element> ("pre", true);
pre->set_attr ("class", label_text::borrow ("gcc-annotated-source"));
// TODO: ideally we'd like to capture elements within the following:
- diagnostic_show_locus (&context, diagnostic.richloc, diagnostic.kind);
+ diagnostic_show_locus (&m_context, diagnostic.richloc, diagnostic.kind,
+ &m_printer);
pre->add_text
- (label_text::take (xstrdup (pp_formatted_text (context.m_printer))));
- pp_clear_output_area (context.m_printer);
+ (label_text::take (xstrdup (pp_formatted_text (&m_printer))));
+ pp_clear_output_area (&m_printer);
diag_element->add_child (std::move (pre));
}
for XHTML output. */
void
-xhtml_builder::emit_diagram (diagnostic_context &/*context*/,
- const diagnostic_diagram &/*diagram*/)
+xhtml_builder::emit_diagram (const diagnostic_diagram &/*diagram*/)
{
/* We must be within the emission of a top-level diagnostic. */
gcc_assert (m_cur_diagnostic_element);
on_report_diagnostic (const diagnostic_info &diagnostic,
diagnostic_t orig_diag_kind) final override
{
- m_builder.on_report_diagnostic (m_context, diagnostic, orig_diag_kind);
+ m_builder.on_report_diagnostic (diagnostic, orig_diag_kind);
}
void on_diagram (const diagnostic_diagram &diagram) final override
{
- m_builder.emit_diagram (m_context, diagram);
+ m_builder.emit_diagram (diagram);
}
void after_diagnostic (const diagnostic_info &)
{
xhtml_output_format (diagnostic_context &context,
const line_maps *line_maps)
: diagnostic_output_format (context),
- m_builder (context, line_maps)
+ m_builder (context, *get_printer (), line_maps)
{}
xhtml_builder m_builder;
context.set_ice_handler_callback (xhtml_ice_handler);
/* Don't colorize the text. */
- pp_show_color (context.m_printer) = false;
+ pp_show_color (fmt->get_printer ()) = false;
context.set_show_highlight_colors (false);
context.set_output_format (fmt.release ());