The class also has responsibility for tracking which of the above is
active, filtering out unnecessary changes. This allows
- layout::print_source_line and layout::print_annotation_line
+ layout_printer::print_source_line and layout_printer::print_annotation_line
to simply request a colorization code for *every* character they print,
via this class, and have the filtering be done for them here. */
class colorizer
{
public:
- colorizer (pretty_printer *pp,
+ colorizer (pretty_printer &pp,
const rich_location &richloc,
diagnostic_t diagnostic_kind);
~colorizer ();
void set_range (int range_idx)
{
/* If we have a specific highlight color for the range, use it. */
- if (pp_show_highlight_colors (m_pp))
+ if (pp_show_highlight_colors (&m_pp))
{
const location_range *const loc_range = m_richloc.get_range (range_idx);
if (loc_range->m_highlight_color)
static const int STATE_FIXIT_DELETE = -3;
static const int STATE_NAMED_COLOR = -4;
- pretty_printer *m_pp;
+ pretty_printer &m_pp;
const rich_location &m_richloc;
diagnostic_t m_diagnostic_kind;
int m_current_state;
/* A class to control the overall layout when printing a diagnostic.
The layout is determined within the constructor.
- It is then printed by repeatedly calling the "print_source_line",
- "print_annotation_line" and "print_any_fixits" methods.
+
+ Printing the layout is handled by class layout_printer. This separation
+ is to avoid depending on the pretty_printer in the layout.
We assume we have disjoint ranges. */
class layout
{
public:
- layout (const diagnostic_context &context,
+ friend class layout_printer;
+
+ layout (const diagnostic_source_print_policy &source_policy,
const rich_location &richloc,
- diagnostic_t diagnostic_kind,
- pretty_printer *pp,
diagnostic_source_effect_info *effect_info = nullptr);
bool maybe_add_location_range (const location_range *loc_range,
int get_linenum_width () const { return m_linenum_width; }
int get_x_offset_display () const { return m_x_offset_display; }
- void print_gap_in_line_numbering ();
bool print_heading_for_line_span_index_p (int line_span_idx) const;
expanded_location get_expanded_location (const line_span *) const;
- void print_line (linenum_type row);
-
- void print_any_right_to_left_edge_lines ();
-
void on_bad_codepoint (const char *ptr, cppchar_t ch, size_t ch_sz);
- void update_any_effects () const;
-
private:
bool will_show_line_p (linenum_type row) const;
- void print_leading_fixits (linenum_type row);
- line_bounds print_source_line (linenum_type row, const char *line,
- int line_bytes);
bool should_print_annotation_line_p (linenum_type row) const;
- void print_leftmost_column ();
- void start_annotation_line (char margin_char = ' ');
- void print_annotation_line (linenum_type row, const line_bounds lbounds);
- void print_any_labels (linenum_type row);
- void print_trailing_fixits (linenum_type row);
bool annotation_line_showed_range_p (linenum_type line, int start_column,
int finish_column) const;
- void show_ruler (int max_column);
-
bool validate_fixit_hint_p (const fixit_hint *hint);
void calculate_line_spans ();
void calculate_linenum_width ();
void calculate_x_offset_display ();
- void print_newline ();
-
bool
get_state_at_point (/* Inputs. */
linenum_type row, int column,
int first_non_ws, int last_non_ws,
enum column_unit col_unit,
/* Outputs. */
- point_state *out_state);
+ point_state *out_state) const;
int
get_x_bound_for_row (linenum_type row, int caret_column,
- int last_non_ws);
-
- void
- move_to_column (int *column, int dest_column, bool add_left_margin);
+ int last_non_ws) const;
private:
bool compatible_locations_p (location_t loc_a, location_t loc_b) const;
const diagnostic_source_printing_options &m_options;
const line_maps *m_line_table;
file_cache &m_file_cache;
- pretty_printer *m_pp;
const text_art::ascii_theme m_fallback_theme;
const text_art::theme &m_theme;
diagnostic_source_effect_info *m_effect_info;
- char_display_policy m_policy;
+ char_display_policy m_char_policy;
location_t m_primary_loc;
exploc_with_display_col m_exploc;
- colorizer m_colorizer;
- bool m_diagnostic_path_p;
auto_vec <layout_range> m_layout_ranges;
auto_vec <const fixit_hint *> m_fixit_hints;
auto_vec <line_span> m_line_spans;
int m_linenum_width;
int m_x_offset_display;
bool m_escape_on_output;
+};
+
+/* A bundle of state for printing a particular layout
+ to a particular pretty_printer. */
+
+class layout_printer
+{
+public:
+ layout_printer (pretty_printer &pp,
+ const layout &layout,
+ const rich_location &richloc,
+ diagnostic_t diagnostic_kind);
+
+ void print (const diagnostic_source_print_policy &source_policy);
+
+private:
+ const diagnostic_source_printing_options &
+ get_options () const { return m_layout.m_options; }
+
+ const text_art::theme &
+ get_theme () const { return m_layout.m_theme; }
+
+ void show_ruler (int max_column);
+ void print_gap_in_line_numbering ();
+ void print_leading_fixits (linenum_type row);
+ void print_line (linenum_type row);
+ line_bounds print_source_line (linenum_type row, const char *line,
+ int line_bytes);
+ void print_leftmost_column ();
+ void start_annotation_line (char margin_char = ' ');
+ void print_annotation_line (linenum_type row, const line_bounds lbounds);
+ void print_any_labels (linenum_type row);
+ void print_trailing_fixits (linenum_type row);
+ void print_newline ();
+
+ void
+ move_to_column (int *column, int dest_column, bool add_left_margin);
+
+ void print_any_right_to_left_edge_lines ();
+
+private:
+ pretty_printer &m_pp;
+ const layout &m_layout;
+ colorizer m_colorizer;
+ bool m_is_diagnostic_path;
/* Fields for handling links between labels (e.g. for showing CFG edges
in execution paths).
/* The constructor for "colorizer". Lookup and store color codes for the
different kinds of things we might need to print. */
-colorizer::colorizer (pretty_printer *pp,
+colorizer::colorizer (pretty_printer &pp,
const rich_location &richloc,
diagnostic_t diagnostic_kind) :
m_pp (pp),
m_range2 = get_color_by_name ("range2");
m_fixit_insert = get_color_by_name ("fixit-insert");
m_fixit_delete = get_color_by_name ("fixit-delete");
- m_stop_color = colorize_stop (pp_show_color (m_pp));
+ m_stop_color = colorize_stop (pp_show_color (&m_pp));
}
/* The destructor for "colorize". If colorization is on, print a code to
{
finish_state (m_current_state);
m_current_state = STATE_NAMED_COLOR;
- pp_string (m_pp, colorize_start (pp_show_color (m_pp), color));
+ pp_string (&m_pp, colorize_start (pp_show_color (&m_pp), color));
}
/* Update state, printing color codes if necessary if there's a state
break;
case STATE_FIXIT_INSERT:
- pp_string (m_pp, m_fixit_insert);
+ pp_string (&m_pp, m_fixit_insert);
break;
case STATE_FIXIT_DELETE:
- pp_string (m_pp, m_fixit_delete);
+ pp_string (&m_pp, m_fixit_delete);
break;
case STATE_NAMED_COLOR:
/* Make range 0 be the same color as the "kind" text
(error vs warning vs note). */
pp_string
- (m_pp,
- colorize_start (pp_show_color (m_pp),
+ (&m_pp,
+ colorize_start (pp_show_color (&m_pp),
diagnostic_get_color_for_kind (m_diagnostic_kind)));
break;
case 1:
- pp_string (m_pp, m_range1);
+ pp_string (&m_pp, m_range1);
break;
case 2:
- pp_string (m_pp, m_range2);
+ pp_string (&m_pp, m_range2);
break;
default:
/* For ranges beyond 2, alternate between color 1 and color 2. */
{
gcc_assert (state > 2);
- pp_string (m_pp,
+ pp_string (&m_pp,
state % 2 ? m_range1 : m_range2);
}
break;
colorizer::finish_state (int state)
{
if (state != STATE_NORMAL_TEXT)
- pp_string (m_pp, m_stop_color);
+ pp_string (&m_pp, m_stop_color);
}
/* Get the color code for NAME (or the empty string if
const char *
colorizer::get_color_by_name (const char *name)
{
- return colorize_start (pp_show_color (m_pp), name);
+ return colorize_start (pp_show_color (&m_pp), name);
}
/* Implementation of class layout_range. */
}
}
-/* Populate a char_display_policy based on DC and RICHLOC. */
+/* Populate a char_display_policy based on SOURCE_POLICY and RICHLOC. */
static char_display_policy
-make_policy (const diagnostic_context &dc,
- const rich_location &richloc)
+make_char_policy (const diagnostic_source_print_policy &source_policy,
+ const rich_location &richloc)
{
/* The default is to not escape non-ASCII bytes. */
char_display_policy result
- (dc.m_tabstop, cpp_wcwidth, default_print_decoded_ch);
+ (source_policy.get_column_policy ().get_tabstop (),
+ cpp_wcwidth,
+ default_print_decoded_ch);
/* If the diagnostic suggests escaping non-ASCII bytes, then
use policy from user-supplied options. */
if (richloc.escape_on_output_p ())
{
result.m_undecoded_byte_width = width_per_escaped_byte;
- switch (dc.get_escape_format ())
+ switch (source_policy.get_escape_format ())
{
default:
gcc_unreachable ();
Determine m_x_offset_display, to ensure that the primary caret
will fit within the max_width provided by the diagnostic_context. */
-layout::layout (const diagnostic_context &context,
+layout::layout (const diagnostic_source_print_policy &source_policy,
const rich_location &richloc,
- diagnostic_t diagnostic_kind,
- pretty_printer *pp,
diagnostic_source_effect_info *effect_info)
-: m_options (context.m_source_printing),
+: m_options (source_policy.get_options ()),
m_line_table (richloc.get_line_table ()),
- m_file_cache (context.get_file_cache ()),
- m_pp (pp ? pp : context.m_printer),
+ m_file_cache (source_policy.get_file_cache ()),
/* Ensure we have a non-null m_theme. */
- m_theme (context.get_diagram_theme ()
- ? *context.get_diagram_theme ()
+ m_theme (source_policy.get_diagram_theme ()
+ ? *source_policy.get_diagram_theme ()
: *static_cast <const text_art::theme *> (&m_fallback_theme)),
m_effect_info (effect_info),
- m_policy (make_policy (context, richloc)),
+ m_char_policy (make_char_policy (source_policy, richloc)),
m_primary_loc (richloc.get_range (0)->m_loc),
m_exploc (m_file_cache,
- richloc.get_expanded_location (0), m_policy,
+ richloc.get_expanded_location (0), m_char_policy,
LOCATION_ASPECT_CARET),
- m_colorizer (m_pp, richloc, diagnostic_kind),
- m_diagnostic_path_p (diagnostic_kind == DK_DIAGNOSTIC_PATH),
m_layout_ranges (richloc.get_num_locations ()),
m_fixit_hints (richloc.get_num_fixit_hints ()),
m_line_spans (1 + richloc.get_num_locations ()),
m_linenum_width (0),
m_x_offset_display (0),
- m_escape_on_output (richloc.escape_on_output_p ()),
- m_link_lhs_state (link_lhs_state::none),
- m_link_rhs_column (-1)
+ m_escape_on_output (richloc.escape_on_output_p ())
{
- if (m_options.show_event_links_p)
- if (effect_info)
- if (effect_info->m_leading_in_edge_column)
- m_link_rhs_column = effect_info->m_leading_in_edge_column;
-
for (unsigned int idx = 0; idx < richloc.get_num_locations (); idx++)
{
/* This diagnostic printer can only cope with "sufficiently sane" ranges.
calculate_line_spans ();
calculate_linenum_width ();
calculate_x_offset_display ();
-
- if (m_options.show_ruler_p)
- show_ruler (m_x_offset_display + m_options.max_width);
}
/* Everything is now known to be in the correct source file,
but it may require further sanitization. */
layout_range ri (exploc_with_display_col (m_file_cache,
- start, m_policy,
+ start, m_char_policy,
LOCATION_ASPECT_START),
exploc_with_display_col (m_file_cache,
- finish, m_policy,
+ finish, m_char_policy,
LOCATION_ASPECT_FINISH),
range_display_kind,
exploc_with_display_col (m_file_cache,
- caret, m_policy,
+ caret, m_char_policy,
LOCATION_ASPECT_CARET),
original_idx, loc_range->m_label);
between two line spans. */
void
-layout::print_gap_in_line_numbering ()
+layout_printer::print_gap_in_line_numbering ()
{
- gcc_assert (m_options.show_line_numbers_p);
+ gcc_assert (m_layout.m_options.show_line_numbers_p);
- pp_emit_prefix (m_pp);
+ pp_emit_prefix (&m_pp);
- for (int i = 0; i < m_linenum_width + 1; i++)
- pp_character (m_pp, '.');
+ for (int i = 0; i < m_layout.get_linenum_width () + 1; i++)
+ pp_character (&m_pp, '.');
- pp_newline (m_pp);
+ pp_newline (&m_pp);
}
/* Return true iff we should print a heading when starting the
= get_line_bytes_without_trailing_whitespace (line.get_buffer (),
line.length ());
int eol_display_column
- = cpp_display_width (line.get_buffer (), line_bytes, m_policy);
+ = cpp_display_width (line.get_buffer (), line_bytes, m_char_policy);
if (caret_display_column > eol_display_column
|| !caret_display_column)
{
both byte and display column units. */
line_bounds
-layout::print_source_line (linenum_type row, const char *line, int line_bytes)
+layout_printer::print_source_line (linenum_type row, const char *line, int line_bytes)
{
m_colorizer.set_normal_text ();
- pp_emit_prefix (m_pp);
- if (m_options.show_line_numbers_p)
+ pp_emit_prefix (&m_pp);
+ if (m_layout.m_options.show_line_numbers_p)
{
int width = num_digits (row);
- for (int i = 0; i < m_linenum_width - width; i++)
- pp_space (m_pp);
- pp_printf (m_pp, "%i |", row);
+ for (int i = 0; i < m_layout.get_linenum_width () - width; i++)
+ pp_space (&m_pp);
+ pp_printf (&m_pp, "%i |", row);
}
print_leftmost_column ();
/* This object helps to keep track of which display column we are at, which is
necessary for computing the line bounds in display units, for doing
tab expansion, and for implementing m_x_offset_display. */
- cpp_display_width_computation dw (line, line_bytes, m_policy);
+ cpp_display_width_computation dw (line, line_bytes, m_layout.m_char_policy);
/* Skip the first m_x_offset_display display columns. In case the leading
portion that will be skipped ends with a character with wcwidth > 1, then
character to be skipped over; the tab is effectively replaced by the
correct number of trailing spaces needed to offset by the desired number of
display columns. */
- for (int skipped_display_cols = dw.advance_display_cols (m_x_offset_display);
- skipped_display_cols > m_x_offset_display; --skipped_display_cols)
- pp_space (m_pp);
+ for (int skipped_display_cols
+ = dw.advance_display_cols (m_layout.m_x_offset_display);
+ skipped_display_cols > m_layout.m_x_offset_display; --skipped_display_cols)
+ pp_space (&m_pp);
/* Print the line and compute the line_bounds. */
line_bounds lbounds;
For frontends that only generate carets, we don't colorize the
characters above them, since this would look strange (e.g.
colorizing just the first character in a token). */
- if (m_options.colorize_source_p)
+ if (m_layout.m_options.colorize_source_p)
{
bool in_range_p;
point_state state;
const int start_byte_col = dw.bytes_processed () + 1;
- in_range_p = get_state_at_point (row, start_byte_col,
- 0, INT_MAX,
- CU_BYTES,
- &state);
+ in_range_p = m_layout.get_state_at_point (row, start_byte_col,
+ 0, INT_MAX,
+ CU_BYTES,
+ &state);
if (in_range_p)
m_colorizer.set_range (state.range_idx);
else
/* The returned display width is the number of spaces into which the
tab should be expanded. */
for (int i = 0; i != this_display_width; ++i)
- pp_space (m_pp);
+ pp_space (&m_pp);
continue;
}
}
/* Output the character. */
- m_policy.m_print_cb (m_pp, cp);
+ m_layout.m_char_policy.m_print_cb (&m_pp, cp);
c = dw.next_byte ();
}
print_newline ();
links between labels (e.g. for CFG edges in execution paths). */
void
-layout::print_leftmost_column ()
+layout_printer::print_leftmost_column ()
{
- if (!m_options.show_event_links_p)
+ if (!get_options ().show_event_links_p)
gcc_assert (m_link_lhs_state == link_lhs_state::none);
switch (m_link_lhs_state)
default:
gcc_unreachable ();
case link_lhs_state::none:
- pp_space (m_pp);
+ pp_space (&m_pp);
break;
case link_lhs_state::rewinding_to_lhs:
{
m_colorizer.set_cfg_edge ();
- const cppchar_t ch= m_theme.get_cppchar
+ const cppchar_t ch = get_theme ().get_cppchar
(text_art::theme::cell_kind::CFG_FROM_LEFT_TO_DOWN);
- pp_unicode_character (m_pp, ch);
+ pp_unicode_character (&m_pp, ch);
m_colorizer.set_normal_text ();
}
break;
case link_lhs_state::at_lhs:
{
m_colorizer.set_cfg_edge ();
- const cppchar_t ch= m_theme.get_cppchar
+ const cppchar_t ch = get_theme ().get_cppchar
(text_art::theme::cell_kind::CFG_DOWN);
- pp_unicode_character (m_pp, ch);
+ pp_unicode_character (&m_pp, ch);
m_colorizer.set_normal_text ();
}
break;
case link_lhs_state::indenting_to_dest:
{
m_colorizer.set_cfg_edge ();
- const cppchar_t ch= m_theme.get_cppchar
+ const cppchar_t ch = get_theme ().get_cppchar
(text_art::theme::cell_kind::CFG_FROM_DOWN_TO_RIGHT);
- pp_unicode_character (m_pp, ch);
+ pp_unicode_character (&m_pp, ch);
m_colorizer.set_normal_text ();
}
break;
showing links between labels (e.g. for CFG edges in execution paths). */
void
-layout::start_annotation_line (char margin_char)
+layout_printer::start_annotation_line (char margin_char)
{
- pp_emit_prefix (m_pp);
- if (m_options.show_line_numbers_p)
+ pp_emit_prefix (&m_pp);
+ if (get_options ().show_line_numbers_p)
{
/* Print the margin. If MARGIN_CHAR != ' ', then print up to 3
of it, right-aligned, padded with spaces. */
int i;
- for (i = 0; i < m_linenum_width - 3; i++)
- pp_space (m_pp);
- for (; i < m_linenum_width; i++)
- pp_character (m_pp, margin_char);
- pp_string (m_pp, " |");
+ for (i = 0; i < m_layout.m_linenum_width - 3; i++)
+ pp_space (&m_pp);
+ for (; i < m_layout.m_linenum_width; i++)
+ pp_character (&m_pp, margin_char);
+ pp_string (&m_pp, " |");
}
if (margin_char == ' ')
print_leftmost_column ();
else
- pp_character (m_pp, margin_char);
+ pp_character (&m_pp, margin_char);
}
/* Print a line consisting of the caret/underlines for the given
source line. */
void
-layout::print_annotation_line (linenum_type row, const line_bounds lbounds)
+layout_printer::print_annotation_line (linenum_type row,
+ const line_bounds lbounds)
{
- int x_bound = get_x_bound_for_row (row, m_exploc.m_display_col,
- lbounds.m_last_non_ws_disp_col);
+ int x_bound = m_layout.get_x_bound_for_row (row,
+ m_layout.m_exploc.m_display_col,
+ lbounds.m_last_non_ws_disp_col);
start_annotation_line ();
- for (int column = 1 + m_x_offset_display; column < x_bound; column++)
+ for (int column = 1 + m_layout.m_x_offset_display; column < x_bound; column++)
{
bool in_range_p;
point_state state;
- in_range_p = get_state_at_point (row, column,
- lbounds.m_first_non_ws_disp_col,
- lbounds.m_last_non_ws_disp_col,
- CU_DISPLAY_COLS,
- &state);
+ in_range_p = m_layout.get_state_at_point (row, column,
+ lbounds.m_first_non_ws_disp_col,
+ lbounds.m_last_non_ws_disp_col,
+ CU_DISPLAY_COLS,
+ &state);
if (in_range_p)
{
/* Within a range. Draw either the caret or an underline. */
/* Draw the caret. */
char caret_char;
if (state.range_idx < rich_location::STATICALLY_ALLOCATED_RANGES)
- caret_char = m_options.caret_chars[state.range_idx];
+ caret_char = get_options ().caret_chars[state.range_idx];
else
caret_char = '^';
- pp_character (m_pp, caret_char);
+ pp_character (&m_pp, caret_char);
}
else
- pp_character (m_pp, '~');
+ pp_character (&m_pp, '~');
}
else
{
/* Not in a range. */
m_colorizer.set_normal_text ();
- pp_character (m_pp, ' ');
+ pp_character (&m_pp, ' ');
}
}
print_newline ();
/* Print any labels in this row. */
void
-layout::print_any_labels (linenum_type row)
+layout_printer::print_any_labels (linenum_type row)
{
int i;
auto_vec<line_label> labels;
/* Gather the labels that are to be printed into "labels". */
{
layout_range *range;
- FOR_EACH_VEC_ELT (m_layout_ranges, i, range)
+ FOR_EACH_VEC_ELT (m_layout.m_layout_ranges, i, range)
{
/* Most ranges don't have labels, so reject this first. */
if (range->m_label == NULL)
/* Reject labels that aren't fully visible due to clipping
by m_x_offset_display. */
const int disp_col = range->m_caret.m_columns[CU_DISPLAY_COLS];
- if (disp_col <= m_x_offset_display)
+ if (disp_col <= m_layout.m_x_offset_display)
continue;
label_text text;
}
label->m_label_line = max_label_line;
- if (m_options.show_event_links_p)
+ if (get_options ().show_event_links_p)
if (label->m_has_in_edge)
label_line_with_in_edge = max_label_line;
next_column = label->m_column;
{
if (label_line == label_line_with_in_edge)
{
- gcc_assert (m_options.show_event_links_p);
+ gcc_assert (get_options ().show_event_links_p);
m_link_lhs_state = link_lhs_state::indenting_to_dest;
}
start_annotation_line ();
- int column = 1 + m_x_offset_display;
+ int column = 1 + m_layout.m_x_offset_display;
line_label *label;
FOR_EACH_VEC_ELT (labels, i, label)
{
.|+----------->(10) ...to here
. ^~~~~~~~~~~~~
. this text. */
- gcc_assert (m_options.show_event_links_p);
+ gcc_assert (get_options ().show_event_links_p);
m_colorizer.set_cfg_edge ();
- const cppchar_t right= m_theme.get_cppchar
+ const cppchar_t right= get_theme ().get_cppchar
(text_art::theme::cell_kind::CFG_RIGHT);
while (column < label->m_column - 1)
{
- pp_unicode_character (m_pp, right);
+ pp_unicode_character (&m_pp, right);
column++;
}
if (column == label->m_column - 1)
{
- pp_character (m_pp, '>');
+ pp_character (&m_pp, '>');
column++;
}
m_colorizer.set_normal_text ();
gcc_assert (column == label->m_column);
/* Colorize the text, unless it's for events in a
diagnostic_path. */
- if (!m_diagnostic_path_p)
+ if (!m_is_diagnostic_path)
m_colorizer.set_range (label->m_state_idx);
- pp_string (m_pp, label->m_text.m_buffer);
+ pp_string (&m_pp, label->m_text.m_buffer);
m_colorizer.set_normal_text ();
column += label->m_display_width;
- if (m_options.show_event_links_p && label->m_has_out_edge)
+ if (get_options ().show_event_links_p && label->m_has_out_edge)
{
/* Print a suffix showing the start of a linkage
to another label e.g. " ->-+" which will be the
. |
. |
. */
- const cppchar_t right= m_theme.get_cppchar
+ const cppchar_t right= get_theme ().get_cppchar
(text_art::theme::cell_kind::CFG_RIGHT);
- const cppchar_t from_right_to_down= m_theme.get_cppchar
+ const cppchar_t from_right_to_down= get_theme ().get_cppchar
(text_art::theme::cell_kind::CFG_FROM_RIGHT_TO_DOWN);
m_colorizer.set_cfg_edge ();
- pp_space (m_pp);
- pp_unicode_character (m_pp, right);
- pp_unicode_character (m_pp, '>');
- pp_unicode_character (m_pp, right);
- pp_unicode_character (m_pp, from_right_to_down);
+ pp_space (&m_pp);
+ pp_unicode_character (&m_pp, right);
+ pp_unicode_character (&m_pp, '>');
+ pp_unicode_character (&m_pp, right);
+ pp_unicode_character (&m_pp, from_right_to_down);
m_colorizer.set_normal_text ();
column += 5;
m_link_rhs_column = column - 1;
gcc_assert (column <= label->m_column);
move_to_column (&column, label->m_column, true);
m_colorizer.set_range (label->m_state_idx);
- pp_character (m_pp, '|');
+ pp_character (&m_pp, '|');
m_colorizer.set_normal_text ();
column++;
}
{
move_to_column (&column, m_link_rhs_column, true);
m_colorizer.set_cfg_edge ();
- const cppchar_t down= m_theme.get_cppchar
+ const cppchar_t down= get_theme ().get_cppchar
(text_art::theme::cell_kind::CFG_DOWN);
- pp_unicode_character (m_pp, down);
+ pp_unicode_character (&m_pp, down);
m_colorizer.set_normal_text ();
}
annotation line showing the vertical line. */
if (m_link_rhs_column != -1)
{
- int column = 1 + m_x_offset_display;
+ int column = 1 + m_layout.m_x_offset_display;
start_annotation_line ();
move_to_column (&column, m_link_rhs_column, true);
m_colorizer.set_cfg_edge ();
- const cppchar_t down= m_theme.get_cppchar
+ const cppchar_t down= get_theme ().get_cppchar
(text_art::theme::cell_kind::CFG_DOWN);
- pp_unicode_character (m_pp, down);
+ pp_unicode_character (&m_pp, down);
m_colorizer.set_normal_text ();
print_newline ();
}
itself, with a leading '+'. */
void
-layout::print_leading_fixits (linenum_type row)
+layout_printer::print_leading_fixits (linenum_type row)
{
- for (unsigned int i = 0; i < m_fixit_hints.length (); i++)
+ for (unsigned int i = 0; i < m_layout.m_fixit_hints.length (); i++)
{
- const fixit_hint *hint = m_fixit_hints[i];
+ const fixit_hint *hint = m_layout.m_fixit_hints[i];
if (!hint->ends_with_newline_p ())
/* Not a newline fixit; print it in print_trailing_fixits. */
gcc_assert (hint->insertion_p ());
- if (hint->affects_line_p (m_line_table, m_exploc.file, row))
+ if (hint->affects_line_p (m_layout.m_line_table,
+ m_layout.m_exploc.file,
+ row))
{
/* Printing the '+' with normal colorization
and the inserted line with "insert" colorization
We have to print the newline separately to avoid
getting additional pp prefixes printed. */
for (size_t i = 0; i < hint->get_length () - 1; i++)
- pp_character (m_pp, hint->get_string ()[i]);
+ pp_character (&m_pp, hint->get_string ()[i]);
m_colorizer.set_normal_text ();
- pp_newline (m_pp);
+ pp_newline (&m_pp);
}
}
}
in layout::print_leading_fixits. */
void
-layout::print_trailing_fixits (linenum_type row)
+layout_printer::print_trailing_fixits (linenum_type row)
{
/* Build a list of correction instances for the line,
potentially consolidating hints (for the sake of readability). */
- line_corrections corrections (m_file_cache, m_policy, m_exploc.file, row);
- for (unsigned int i = 0; i < m_fixit_hints.length (); i++)
+ line_corrections corrections (m_layout.m_file_cache, m_layout.m_char_policy,
+ m_layout.m_exploc.file, row);
+ for (unsigned int i = 0; i < m_layout.m_fixit_hints.length (); i++)
{
- const fixit_hint *hint = m_fixit_hints[i];
+ const fixit_hint *hint = m_layout.m_fixit_hints[i];
/* Newline fixits are handled by layout::print_leading_fixits. */
if (hint->ends_with_newline_p ())
continue;
- if (hint->affects_line_p (m_line_table, m_exploc.file, row))
+ if (hint->affects_line_p (m_layout.m_line_table,
+ m_layout.m_exploc.file,
+ row))
corrections.add_hint (hint);
}
/* Now print the corrections. */
unsigned i;
correction *c;
- int column = 1 + m_x_offset_display;
+ int column = 1 + m_layout.m_x_offset_display;
if (!corrections.m_corrections.is_empty ())
start_annotation_line ();
int start_column = c->m_printed_columns.start;
move_to_column (&column, start_column, true);
m_colorizer.set_fixit_insert ();
- pp_string (m_pp, c->m_text);
+ pp_string (&m_pp, c->m_text);
m_colorizer.set_normal_text ();
column += c->m_display_cols;
}
Always show it for removals. */
int start_column = c->m_affected_columns.start;
int finish_column = c->m_affected_columns.finish;
- if (!annotation_line_showed_range_p (row, start_column,
- finish_column)
+ if (!m_layout.annotation_line_showed_range_p (row, start_column,
+ finish_column)
|| c->m_byte_length == 0)
{
move_to_column (&column, start_column, true);
m_colorizer.set_fixit_delete ();
for (; column <= finish_column; column++)
- pp_character (m_pp, '-');
+ pp_character (&m_pp, '-');
m_colorizer.set_normal_text ();
}
/* Print the replacement text. REPLACE also covers
{
move_to_column (&column, start_column, true);
m_colorizer.set_fixit_insert ();
- pp_string (m_pp, c->m_text);
+ pp_string (&m_pp, c->m_text);
m_colorizer.set_normal_text ();
column += c->m_display_cols;
}
}
/* Add a trailing newline, if necessary. */
- move_to_column (&column, 1 + m_x_offset_display, false);
+ move_to_column (&column, 1 + m_layout.m_x_offset_display, false);
}
/* Disable any colorization and emit a newline. */
void
-layout::print_newline ()
+layout_printer::print_newline ()
{
m_colorizer.set_normal_text ();
- pp_newline (m_pp);
+ pp_newline (&m_pp);
}
/* Return true if (ROW/COLUMN) is within a range of the layout.
int first_non_ws, int last_non_ws,
enum column_unit col_unit,
/* Outputs. */
- point_state *out_state)
+ point_state *out_state) const
{
layout_range *range;
int i;
int
layout::get_x_bound_for_row (linenum_type row, int caret_column,
- int last_non_ws_column)
+ int last_non_ws_column) const
{
int result = caret_column + 1;
left margin after any newline. */
void
-layout::move_to_column (int *column, int dest_column, bool add_left_margin)
+layout_printer::move_to_column (int *column,
+ int dest_column,
+ bool add_left_margin)
{
/* Start a new line if we need to. */
if (*column > dest_column)
print_newline ();
if (add_left_margin)
start_annotation_line ();
- *column = 1 + m_x_offset_display;
+ *column = 1 + m_layout.m_x_offset_display;
}
while (*column < dest_column)
{
/* For debugging column issues, it can be helpful to replace this
pp_space call with
- pp_character (m_pp, '0' + (*column % 10));
+ pp_character (&m_pp, '0' + (*column % 10));
to visualize the changing value of "*column". */
- pp_space (m_pp);
+ pp_space (&m_pp);
(*column)++;
}
}
(after the 1-column indent). */
void
-layout::show_ruler (int max_column)
+layout_printer::show_ruler (int max_column)
{
/* Hundreds. */
if (max_column > 99)
{
start_annotation_line ();
- for (int column = 1 + m_x_offset_display; column <= max_column; column++)
+ for (int column = 1 + m_layout.m_x_offset_display;
+ column <= max_column;
+ ++column)
if (column % 10 == 0)
- pp_character (m_pp, '0' + (column / 100) % 10);
+ pp_character (&m_pp, '0' + (column / 100) % 10);
else
- pp_space (m_pp);
- pp_newline (m_pp);
+ pp_space (&m_pp);
+ pp_newline (&m_pp);
}
/* Tens. */
start_annotation_line ();
- for (int column = 1 + m_x_offset_display; column <= max_column; column++)
+ for (int column = 1 + m_layout.m_x_offset_display;
+ column <= max_column;
+ ++column)
if (column % 10 == 0)
- pp_character (m_pp, '0' + (column / 10) % 10);
+ pp_character (&m_pp, '0' + (column / 10) % 10);
else
- pp_space (m_pp);
- pp_newline (m_pp);
+ pp_space (&m_pp);
+ pp_newline (&m_pp);
/* Units. */
start_annotation_line ();
- for (int column = 1 + m_x_offset_display; column <= max_column; column++)
- pp_character (m_pp, '0' + (column % 10));
- pp_newline (m_pp);
+ for (int column = 1 + m_layout.m_x_offset_display;
+ column <= max_column;
+ ++column)
+ pp_character (&m_pp, '0' + (column % 10));
+ pp_newline (&m_pp);
}
/* Print leading fix-its (for new lines inserted before the source line)
consisting of any caret/underlines, then any fixits.
If the source line can't be read, print nothing. */
void
-layout::print_line (linenum_type row)
+layout_printer::print_line (linenum_type row)
{
- char_span line = m_file_cache.get_source_line (m_exploc.file, row);
+ char_span line
+ = m_layout.m_file_cache.get_source_line (m_layout.m_exploc.file, row);
if (!line)
return;
print_leading_fixits (row);
const line_bounds lbounds
= print_source_line (row, line.get_buffer (), line.length ());
- if (should_print_annotation_line_p (row))
+ if (m_layout.should_print_annotation_line_p (row))
print_annotation_line (row, lbounds);
- if (m_options.show_labels_p)
+ if (get_options ().show_labels_p)
print_any_labels (row);
print_trailing_fixits (row);
}
at the bottom left. */
void
-layout::print_any_right_to_left_edge_lines ()
+layout_printer::print_any_right_to_left_edge_lines ()
{
if (m_link_rhs_column == -1)
/* Can also happen if the out-edge had UNKNOWN_LOCATION. */
return;
- gcc_assert (m_options.show_event_links_p);
+ gcc_assert (get_options ().show_event_links_p);
/* Print the line with "|". */
start_annotation_line ();
- int column = 1 + m_x_offset_display;
+ int column = 1 + m_layout.m_x_offset_display;
move_to_column (&column, m_link_rhs_column, true);
m_colorizer.set_cfg_edge ();
- const cppchar_t down= m_theme.get_cppchar
+ const cppchar_t down= get_theme ().get_cppchar
(text_art::theme::cell_kind::CFG_DOWN);
- pp_unicode_character (m_pp, down);
+ pp_unicode_character (&m_pp, down);
m_colorizer.set_normal_text ();
- pp_newline (m_pp);
+ pp_newline (&m_pp);
/* Print the line with "┌──────────────────────────────────────────┘". */
m_link_lhs_state = link_lhs_state::rewinding_to_lhs;
start_annotation_line ();
m_colorizer.set_cfg_edge ();
- const cppchar_t left= m_theme.get_cppchar
+ const cppchar_t left= get_theme ().get_cppchar
(text_art::theme::cell_kind::CFG_LEFT);
- for (int column = 1 + m_x_offset_display; column < m_link_rhs_column;
- column++)
- pp_unicode_character (m_pp, left);
- const cppchar_t from_down_to_left = m_theme.get_cppchar
+ for (int column = 1 + m_layout.m_x_offset_display;
+ column < m_link_rhs_column;
+ ++column)
+ pp_unicode_character (&m_pp, left);
+ const cppchar_t from_down_to_left = get_theme ().get_cppchar
(text_art::theme::cell_kind::CFG_FROM_DOWN_TO_LEFT);
- pp_unicode_character (m_pp, from_down_to_left);
+ pp_unicode_character (&m_pp, from_down_to_left);
m_colorizer.set_normal_text ();
- pp_newline (m_pp);
+ pp_newline (&m_pp);
/* We now have a link line on the LHS,
and no longer have one on the RHS. */
m_link_rhs_column = -1;
}
-/* Update this layout's m_effect_info (if any) after printing this
- layout. */
-
-void
-layout::update_any_effects () const
+layout_printer::layout_printer (pretty_printer &pp,
+ const layout &layout,
+ const rich_location &richloc,
+ diagnostic_t diagnostic_kind)
+: m_pp (pp),
+ m_layout (layout),
+ m_colorizer (m_pp, richloc, diagnostic_kind),
+ m_is_diagnostic_path (diagnostic_kind == DK_DIAGNOSTIC_PATH),
+ m_link_lhs_state (link_lhs_state::none),
+ m_link_rhs_column (-1)
{
- if (m_effect_info)
- m_effect_info->m_trailing_out_edge_column = m_link_rhs_column;
+ if (get_options ().show_event_links_p)
+ if (auto effect_info = m_layout.m_effect_info)
+ if (effect_info->m_leading_in_edge_column)
+ m_link_rhs_column = effect_info->m_leading_in_edge_column;
}
} /* End of anonymous namespace. */
Otherwise return false.
- Use CTXT for determining how spans of lines would be printed. */
+ Use POLICY for determining how spans of lines would be printed. */
bool
-gcc_rich_location::add_location_if_nearby (const diagnostic_context &ctxt,
- location_t loc,
- bool restrict_to_current_line_spans,
- const range_label *label)
+gcc_rich_location::
+add_location_if_nearby (const diagnostic_source_print_policy &policy,
+ location_t loc,
+ bool restrict_to_current_line_spans,
+ const range_label *label)
{
/* Use the layout location-handling logic to sanitize LOC,
filtering it to the current line spans within a temporary
layout instance. */
- layout layout (ctxt, *this, DK_ERROR, nullptr);
+
+ layout layout (policy, *this);
location_range loc_range;
loc_range.m_loc = loc;
loc_range.m_range_display_kind = SHOW_RANGE_WITHOUT_CARET;
return true;
}
-/* As per diagnostic_context::show_locus, but don't print anything
+bool
+gcc_rich_location::
+add_location_if_nearby (const diagnostic_context &dc,
+ location_t loc,
+ bool restrict_to_current_line_spans,
+ const range_label *label)
+{
+ diagnostic_source_print_policy source_policy (dc);
+ return add_location_if_nearby (source_policy, loc,
+ restrict_to_current_line_spans, label);
+}
+
+
+/* As per diagnostic_source_print_policy::print, but don't print anything
if source printing is disabled, or if the location hasn't changed. */
void
m_last_location = loc;
- show_locus (richloc, diagnostic_kind, pp, effects);
+ if (!pp)
+ pp = m_printer;
+ gcc_assert (pp);
+
+ diagnostic_source_print_policy source_policy (*this);
+ source_policy.print (*pp, richloc, diagnostic_kind, effects);
+}
+
+diagnostic_source_print_policy::
+diagnostic_source_print_policy (const diagnostic_context &dc)
+: m_options (dc.m_source_printing),
+ m_location_policy (dc),
+ m_start_span_cb (dc.m_text_callbacks.m_start_span),
+ m_file_cache (dc.get_file_cache ()),
+ m_diagram_theme (dc.get_diagram_theme ()),
+ m_escape_format (dc.get_escape_format ())
+{
}
-/* Print the physical source code corresponding to the location of
- this diagnostic, with additional annotations.
- If PP is non-null, then use it rather than this context's printer.
+/* Print to PP the physical source code corresponding to the location(s)
+ in RICHLOC, with additional annotations, as if for a diagnostic of the
+ given DIAGNOSTIC_KIND.
If EFFECTS is non-null, then use and update it. */
void
-diagnostic_context::show_locus (const rich_location &richloc,
- diagnostic_t diagnostic_kind,
- pretty_printer *pp,
- diagnostic_source_effect_info *effects)
+diagnostic_source_print_policy::print (pretty_printer &pp,
+ const rich_location &richloc,
+ diagnostic_t diagnostic_kind,
+ diagnostic_source_effect_info *effects)
+ const
+{
+ layout layout (*this, richloc, effects);
+ layout_printer lp (pp, layout, richloc, diagnostic_kind);
+ lp.print (*this);
+}
+
+void
+layout_printer::print (const diagnostic_source_print_policy &source_policy)
{
- layout layout (*this, richloc, diagnostic_kind, pp, effects);
+ if (get_options ().show_ruler_p)
+ show_ruler (m_layout.m_x_offset_display + get_options ().max_width);
- for (int line_span_idx = 0; line_span_idx < layout.get_num_line_spans ();
+ for (int line_span_idx = 0; line_span_idx < m_layout.get_num_line_spans ();
line_span_idx++)
{
- const line_span *line_span = layout.get_line_span (line_span_idx);
- if (m_source_printing.show_line_numbers_p)
+ const line_span *line_span = m_layout.get_line_span (line_span_idx);
+ if (get_options ().show_line_numbers_p)
{
/* With line numbers, we should show whenever the line-numbering
"jumps". */
if (line_span_idx > 0)
- layout.print_gap_in_line_numbering ();
+ print_gap_in_line_numbering ();
}
else
{
/* Without line numbers, we print headings for some line spans. */
- if (layout.print_heading_for_line_span_index_p (line_span_idx))
+ if (m_layout.print_heading_for_line_span_index_p (line_span_idx))
{
expanded_location exploc
- = layout.get_expanded_location (line_span);
- m_text_callbacks.m_start_span (this, exploc);
+ = m_layout.get_expanded_location (line_span);
+ const diagnostic_location_print_policy &
+ loc_policy = source_policy.get_location_policy ();
+ source_policy.get_start_span_fn () (loc_policy, &m_pp, exploc);
}
}
/* Iterate over the lines within this span (using linenum_arith_t to
linenum_arith_t last_line = line_span->get_last_line ();
for (linenum_arith_t row = line_span->get_first_line ();
row <= last_line; row++)
- layout.print_line (row);
+ print_line (row);
}
- layout.update_any_effects ();
+ if (auto effect_info = m_layout.m_effect_info)
+ effect_info->m_trailing_out_edge_column = m_link_rhs_column;
}
#if CHECKING_P
m_tmp_source_file.get_filename (), 1);
}
+/* Populate a char_display_policy based on DC and RICHLOC. */
+
+static char_display_policy
+make_char_policy (const diagnostic_context &dc,
+ const rich_location &richloc)
+{
+ diagnostic_source_print_policy source_policy (dc);
+ return ::make_char_policy (source_policy, richloc);
+}
+
/* Verify that cpp_display_width correctly handles escaping. */
static void
/* No escaping. */
{
test_diagnostic_context dc;
- char_display_policy policy (make_policy (dc, richloc));
+ char_display_policy policy (make_char_policy (dc, richloc));
ASSERT_EQ (cpp_display_width (pi, strlen (pi), policy), 1);
ASSERT_EQ (cpp_display_width (emoji, strlen (emoji), policy), 2);
ASSERT_EQ (cpp_display_width (stray, strlen (stray), policy), 1);
{
test_diagnostic_context dc;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
- char_display_policy policy (make_policy (dc, richloc));
+ char_display_policy policy (make_char_policy (dc, richloc));
ASSERT_EQ (cpp_display_width (pi, strlen (pi), policy), 8);
ASSERT_EQ (cpp_display_width (emoji, strlen (emoji), policy), 9);
ASSERT_EQ (cpp_display_width (stray, strlen (stray), policy), 4);
{
test_diagnostic_context dc;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
- char_display_policy policy (make_policy (dc, richloc));
+ char_display_policy policy (make_char_policy (dc, richloc));
ASSERT_EQ (cpp_display_width (pi, strlen (pi), policy), 8);
ASSERT_EQ (cpp_display_width (emoji, strlen (emoji), policy), 16);
ASSERT_EQ (cpp_display_width (stray, strlen (stray), policy), 4);
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);
rich_location richloc (line_table,
linemap_position_for_column (line_table,
caret_byte_col));
- layout test_layout (dc, richloc, DK_ERROR, nullptr);
+ layout test_layout (source_policy, richloc, nullptr);
ASSERT_EQ (left_margin - test_linenum_sep,
test_layout.get_linenum_width ());
ASSERT_EQ (expected_x_offset_display,
= 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);
rich_location richloc (line_table,
linemap_position_for_column (line_table,
emoji_col));
- layout test_layout (dc, richloc, DK_ERROR, nullptr);
- test_layout.print_line (1);
+ layout test_layout (policy, richloc, nullptr);
+ layout_printer lp (*dc.m_printer, test_layout, richloc, DK_ERROR);
+ lp.print (policy);
ASSERT_STREQ (" | 1 \n"
" | 1 \n"
" | 234567890123456789\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);
rich_location richloc (line_table,
linemap_position_for_column (line_table,
emoji_col + 2));
- layout test_layout (dc, richloc, DK_ERROR, nullptr);
- test_layout.print_line (1);
+ layout test_layout (dc, richloc, nullptr);
+ layout_printer lp (*dc.m_printer, test_layout, richloc, DK_ERROR);
+ lp.print (policy);
ASSERT_STREQ (" | 1 1 \n"
" | 1 2 \n"
" | 3456789012345678901\n"
{
test_diagnostic_context dc;
dc.m_tabstop = tabstop;
- layout test_layout (dc, richloc, DK_ERROR, nullptr);
- test_layout.print_line (1);
+ diagnostic_source_print_policy policy (dc);
+ layout test_layout (policy, richloc, nullptr);
+ layout_printer lp (*dc.m_printer, test_layout, richloc, DK_ERROR);
+ lp.print (policy);
const char *out = pp_formatted_text (dc.m_printer);
ASSERT_EQ (NULL, strchr (out, '\t'));
const char *left_quote = strchr (out, '`');
dc.m_source_printing.min_margin_width
= test_left_margin - test_linenum_sep + 1;
dc.m_source_printing.show_line_numbers_p = true;
- layout test_layout (dc, richloc, DK_ERROR, nullptr);
- test_layout.print_line (1);
+ diagnostic_source_print_policy policy (dc);
+ layout test_layout (policy, richloc, nullptr);
+ layout_printer lp (*dc.m_printer, test_layout, richloc, DK_ERROR);
+ lp.print (policy);
/* We have arranged things so that two columns will be printed before
the caret. If the tab results in more than one space, this should
{
test_diagnostic_context dc;
rich_location richloc (line_table, UNKNOWN_LOCATION);
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ ("", pp_formatted_text (dc.m_printer));
}
test_diagnostic_context dc;
location_t caret = linemap_position_for_column (line_table, 10);
rich_location richloc (line_table, caret);
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^\n",
pp_formatted_text (dc.m_printer));
test_diagnostic_context dc;
location_t caret = linemap_position_for_column (line_table, 0);
rich_location richloc (line_table, caret);
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n",
pp_formatted_text (dc.m_printer));
}
location_t finish = linemap_position_for_column (line_table, 15);
location_t loc = make_location (caret, start, finish);
rich_location richloc (line_table, loc);
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ~~~^~~~~~\n",
pp_formatted_text (dc.m_printer));
rich_location richloc (line_table, foo);
richloc.add_range (bar, SHOW_RANGE_WITH_CARET);
richloc.add_range (field, SHOW_RANGE_WITH_CARET);
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ~A~ ~B~ ~~C~~\n",
pp_formatted_text (dc.m_printer));
location_t caret = linemap_position_for_column (line_table, 7);
rich_location richloc (line_table, caret);
richloc.add_fixit_insert_before ("&");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^\n"
" &\n",
location_t foo = make_location (start, start, finish);
rich_location richloc (line_table, foo);
richloc.add_fixit_insert_after ("[0]");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~\n"
" [0]\n",
/* Normal. */
{
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~~~~\n"
" ------\n",
test_diagnostic_context dc;
pp_prefixing_rule (dc.m_printer) = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
pp_set_prefix (dc.m_printer, xstrdup ("TEST PREFIX:"));
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ ("TEST PREFIX: foo = bar.field;\n"
"TEST PREFIX: ^~~~~~\n"
"TEST PREFIX: ------\n",
test_diagnostic_context dc;
dc.m_source_printing.show_ruler_p = true;
dc.m_source_printing.max_width = 104;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" 0 0 0 0 0 0 0 0 0 1 \n"
" 1 2 3 4 5 6 7 8 9 0 \n"
" 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234\n"
dc.m_source_printing.max_width = 50;
pp_prefixing_rule (dc.m_printer) = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
pp_set_prefix (dc.m_printer, xstrdup ("TEST PREFIX:"));
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ ("TEST PREFIX: 1 2 3 4 5\n"
"TEST PREFIX: 12345678901234567890123456789012345678901234567890\n"
"TEST PREFIX: foo = bar.field;\n"
dc.m_source_printing.show_line_numbers_p = true;
pp_prefixing_rule (dc.m_printer) = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
pp_set_prefix (dc.m_printer, xstrdup ("TEST PREFIX:"));
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ ("TEST PREFIX: | 1 2 3 4 5\n"
"TEST PREFIX: | 12345678901234567890123456789012345678901234567890\n"
"TEST PREFIX: 1 | foo = bar.field;\n"
location_t field = make_location (start, start, finish);
rich_location richloc (line_table, field);
richloc.add_fixit_replace ("m_field");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~~~\n"
" m_field\n",
range.m_start = start;
range.m_finish = finish;
richloc.add_fixit_replace (range, "m_field");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
/* The replacement range is not indicated in the annotation line, so
it should be indicated via an additional underline. */
ASSERT_STREQ (" foo = bar.field;\n"
location_t field = make_location (start, start, finish);
richloc.add_range (field);
richloc.add_fixit_replace (field, "m_field");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
/* The replacement range is indicated in the annotation line,
so it shouldn't be indicated via an additional underline. */
ASSERT_STREQ (" foo = bar.field;\n"
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~~~~~~~~ \n"
" test\n",
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~~~~~~~~ \n"
" -----------------------------------------\n",
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~~~~~~~~ \n"
" test\n",
for (int i = 0; i < 19; i++)
richloc.add_fixit_insert_before ("a");
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^\n"
" aaaaaaaaaaaaaaaaaaa\n",
richloc.add_fixit_insert_before (loc, "a");
}
ASSERT_EQ (19, richloc.get_num_fixit_hints ());
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^\n"
" a a a a a a a a a a a a a a a a a a a\n",
{
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~ ~~~ ~~~~~\n"
" | | |\n"
{
test_diagnostic_context dc;
dc.m_source_printing.show_labels_p = false;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~ ~~~ ~~~~~\n",
pp_formatted_text (dc.m_printer));
richloc.add_range (field, SHOW_RANGE_WITHOUT_CARET, &label2);
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~ ~~~ ~~~~~\n"
" | | |\n"
richloc.add_range (field, SHOW_RANGE_WITHOUT_CARET, &label2);
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~ ~~~ ~~~~~\n"
" | | |\n"
richloc.add_range (foo, SHOW_RANGE_WITHOUT_CARET, &label2);
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ~~~ ~~~ ^~~~~\n"
" | | |\n"
richloc.add_range (bar, SHOW_RANGE_WITHOUT_CARET, &label2);
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~\n"
" |\n"
richloc.add_range (foo, SHOW_RANGE_WITHOUT_CARET, &label_2c);
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ~~~ ~~~ ^~~~~\n"
" | | |\n"
gcc_rich_location richloc (bar, &label, nullptr);
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar.field;\n"
" ^~~\n",
pp_formatted_text (dc.m_printer));
test_diagnostic_context dc;
location_t caret = linemap_position_for_column (line_table, 18);
rich_location richloc (line_table, caret);
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
location_t finish = linemap_position_for_column (line_table, 30);
location_t loc = make_location (caret, start, finish);
rich_location richloc (line_table, loc);
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
rich_location richloc (line_table, foo);
richloc.add_range (bar, SHOW_RANGE_WITH_CARET);
richloc.add_range (field, SHOW_RANGE_WITH_CARET);
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
location_t caret = linemap_position_for_column (line_table, 12);
rich_location richloc (line_table, caret);
richloc.add_fixit_insert_before ("&");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
location_t foo = make_location (start, start, finish);
rich_location richloc (line_table, foo);
richloc.add_fixit_insert_after ("[0]");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
location_t dot = make_location (start, start, finish);
rich_location richloc (line_table, dot);
richloc.add_fixit_remove ();
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
location_t field = make_location (start, start, finish);
rich_location richloc (line_table, field);
richloc.add_fixit_replace ("m_\xf0\x9f\x98\x82_field\xcf\x80");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
range.m_start = start;
range.m_finish = finish;
richloc.add_fixit_replace (range, "m_\xf0\x9f\x98\x82_field\xcf\x80");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
/* The replacement range is not indicated in the annotation line, so
it should be indicated via an additional underline. */
ASSERT_STREQ (" \xf0\x9f\x98\x82"
location_t field = make_location (start, start, finish);
richloc.add_range (field);
richloc.add_fixit_replace (field, "m_\xf0\x9f\x98\x82_field\xcf\x80");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
/* The replacement range is indicated in the annotation line,
so it shouldn't be indicated via an additional underline. */
ASSERT_STREQ (" \xf0\x9f\x98\x82"
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
for (int i = 0; i < 19; i++)
richloc.add_fixit_insert_before (i & 1 ? "@" : "\xcf\x80");
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
}
ASSERT_EQ (nlocs, richloc.get_num_fixit_hints ());
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
{
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
richloc.add_range (field, SHOW_RANGE_WITHOUT_CARET, &label2);
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
richloc.add_range (field, SHOW_RANGE_WITHOUT_CARET, &label2);
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" \xf0\x9f\x98\x82"
"_foo = \xcf\x80"
"_bar.\xf0\x9f\x98\x82"
{
test_diagnostic_context dc;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" <U+1F602>_foo = <U+03C0>_bar.<U+1F602>_field<U+03C0>;\n"
" ^~~~~~~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~\n"
" | | |\n"
{
test_diagnostic_context dc;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ
(" <f0><9f><98><82>_foo = <cf><80>_bar.<f0><9f><98><82>_field<cf><80>;\n"
" ^~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
diagnostic_color_init (&dc, DIAGNOSTICS_COLOR_YES);
const location_t pi = linemap_position_for_column (line_table, 12);
rich_location richloc (line_table, pi);
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
/* In order to avoid having the test depend on exactly how the colorization
was effected, just confirm there are two pi characters in the output. */
matching_open_brace_1_18);
ASSERT_TRUE (added);
ASSERT_EQ (2, richloc.get_num_locations ());
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" struct same_line { double x; double y; ;\n"
" ~ ^\n",
pp_formatted_text (dc.m_printer));
rich_location richloc (line_table, colon);
richloc.add_fixit_insert_before (x, ".");
richloc.add_fixit_replace (colon, "=");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" struct point origin = {x: 0.0,\n"
" ^\n"
" .=\n",
rich_location richloc (line_table, colon);
richloc.add_fixit_insert_before (y, ".");
richloc.add_fixit_replace (colon, "=");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ ("FILENAME:3:24:\n"
" y\n"
" .\n"
richloc.add_fixit_replace (colon, "=");
test_diagnostic_context dc;
dc.m_source_printing.show_line_numbers_p = true;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" 3 | y\n"
" | .\n"
"......\n"
richloc.add_fixit_replace (close_paren, "> (");
richloc.add_fixit_insert_after (")");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n"
" ^~~~~~~~~~\n"
" -----------------\n"
pp_formatted_text (dc.m_printer));
/* Unit-test the line_corrections machinery. */
- char_display_policy policy (make_policy (dc, richloc));
+ char_display_policy policy (make_char_policy (dc, richloc));
ASSERT_EQ (3, richloc.get_num_fixit_hints ());
const fixit_hint *hint_0 = richloc.get_fixit_hint (0);
ASSERT_EQ (column_range (12, 12),
richloc.add_fixit_replace (close_paren, ") (");
richloc.add_fixit_insert_after (")");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n"
" ^~~~~~~~~~\n"
" -\n"
richloc.add_fixit_replace (close_paren, ") (");
richloc.add_fixit_insert_after (")");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n"
" ^~~~~~~~~~\n"
" -\n"
rather than by line_corrections. */
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n"
" ^~~~~~~~~~\n"
" -------\n"
ASSERT_EQ (2, richloc.get_num_fixit_hints ());
/* But the corrections are. */
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n"
" ^~~~~~~~~~\n"
" -----------------\n"
/* The first insertion is long enough that if printed naively,
it would overlap with the second.
Verify that they are printed as a single replacement. */
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo *f = (foo *)ptr->field;\n"
" ^~~~~~~~~~\n"
" -------\n"
richloc.add_fixit_replace (close_paren, "> (");
richloc.add_fixit_insert_after (")");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" f\xf0\x9f\x98\x82"
" *f = (f\xf0\x9f\x98\x82"
" *)ptr->field\xcf\x80"
pp_formatted_text (dc.m_printer));
/* Unit-test the line_corrections machinery. */
- char_display_policy policy (make_policy (dc, richloc));
+ char_display_policy policy (make_char_policy (dc, richloc));
ASSERT_EQ (3, richloc.get_num_fixit_hints ());
const fixit_hint *hint_0 = richloc.get_fixit_hint (0);
ASSERT_EQ (column_range (14, 14),
richloc.add_fixit_replace (close_paren, ") (");
richloc.add_fixit_insert_after (")");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" f\xf0\x9f\x98\x82"
" *f = (f\xf0\x9f\x98\x82"
" *)ptr->field\xcf\x80"
richloc.add_fixit_replace (close_paren, ") (");
richloc.add_fixit_insert_after (")");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" f\xf0\x9f\x98\x82"
" *f = (f\xf0\x9f\x98\x82"
" *)ptr->field\xcf\x80"
rather than by line_corrections. */
ASSERT_EQ (1, richloc.get_num_fixit_hints ());
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" f\xf0\x9f\x98\x82"
" *f = (f\xf0\x9f\x98\x82"
" *)ptr->field\xcf\x80"
ASSERT_EQ (2, richloc.get_num_fixit_hints ());
/* But the corrections are. */
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" f\xf0\x9f\x98\x82"
" *f = (f\xf0\x9f\x98\x82"
" *)ptr->field\xcf\x80"
/* The first insertion is long enough that if printed naively,
it would overlap with the second.
Verify that they are printed as a single replacement. */
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" f\xf0\x9f\x98\x82"
" *f = (f\xf0\x9f\x98\x82"
" *)ptr->field\xcf\x80"
richloc.add_fixit_insert_before (col_21, "}");
/* These fixits should be accepted; they can't be consolidated. */
- char_display_policy policy (make_policy (dc, richloc));
+ char_display_policy policy (make_char_policy (dc, richloc));
ASSERT_EQ (2, richloc.get_num_fixit_hints ());
const fixit_hint *hint_0 = richloc.get_fixit_hint (0);
ASSERT_EQ (column_range (23, 22),
ASSERT_EQ (column_range (21, 21), get_printed_columns (fc, policy, hint_1));
/* Verify that they're printed correctly. */
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" int a5[][0][0] = { 1, 2 };\n"
" ^\n"
" } {\n",
richloc.add_fixit_insert_before (col_21, "}");
richloc.add_fixit_insert_before (col_1, "{");
richloc.add_fixit_insert_before (col_25, "}");
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" int a5[][0][0] = { 1, 2 };\n"
" ^\n"
" { -----\n"
/* Without line numbers. */
{
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" x = a;\n"
"+ break;\n"
" case 'b':\n"
{
test_diagnostic_context dc;
dc.m_source_printing.show_line_numbers_p = true;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" 2 | x = a;\n"
" +++ |+ break;\n"
" 3 | case 'b':\n"
richloc.add_fixit_insert_before (case_start, "break;\n");
ASSERT_TRUE (richloc.seen_impossible_fixit_p ());
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" case 'b':\n"
" ^~~~~~~~~\n",
pp_formatted_text (dc.m_printer));
{
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ ("FILENAME:1:1:\n"
"+#include <stdio.h>\n"
" test (int ch)\n"
{
test_diagnostic_context dc;
dc.m_source_printing.show_line_numbers_p = true;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" +++ |+#include <stdio.h>\n"
" 1 | test (int ch)\n"
" 2 | {\n"
return;
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar ();\n"
" ^\n",
pp_formatted_text (dc.m_printer));
return;
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" foo = bar (\n"
" ~^\n"
" );\n"
rich_location richloc (line_table,
linemap_position_for_column (line_table,
first_non_ws_byte_col));
- layout test_layout (dc, richloc, DK_ERROR, nullptr);
- test_layout.print_line (1);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" This: ` ' is a tab.\n"
" ^\n",
pp_formatted_text (dc.m_printer));
rich_location richloc (line_table,
linemap_position_for_column (line_table,
right_quote_byte_col));
- layout test_layout (dc, richloc, DK_ERROR, nullptr);
- test_layout.print_line (1);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" This: ` ' is a tab.\n"
" ^\n",
pp_formatted_text (dc.m_printer));
{
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" before \1\2\3\v\x80\xff""after\n"
" ^ ~\n",
pp_formatted_text (dc.m_printer));
{
test_diagnostic_context dc;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ
(" before<U+0000><U+0001><U+0002><U+0003><U+000B><80><ff>after\n"
" ^~~~~~~~ ~~~~~~~~\n",
{
test_diagnostic_context dc;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" before<00><01><02><03><0b><80><ff>after\n"
" ^~~~ ~~~~\n",
pp_formatted_text (dc.m_printer));
{
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" after\n"
" ^\n",
pp_formatted_text (dc.m_printer));
{
test_diagnostic_context dc;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" <U+0000>after\n"
" ^~~~~~~~\n",
pp_formatted_text (dc.m_printer));
{
test_diagnostic_context dc;
dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" <00>after\n"
" ^~~~\n",
pp_formatted_text (dc.m_printer));
dc.m_source_printing.show_line_numbers_p = true;
dc.m_source_printing.min_margin_width = 0;
gcc_rich_location richloc (loc);
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ dc.test_show_locus (richloc);
ASSERT_STREQ (" 9 | this is line 9\n"
" | ~~~~~~\n"
"10 | this is line 10\n"