if (guard_loc == body_loc || body_loc == next_stmt_loc)
return false;
- const unsigned int tab_width = global_dc->m_tabstop;
+ const unsigned int tab_width = global_dc->get_column_options ().m_tabstop;
/* They must be in the same file. */
if (next_stmt_exploc.file != body_exploc.file)
flag_char8_t = (cxx_dialect >= cxx20) || flag_isoc23;
cpp_opts->unsigned_utf8char = flag_char8_t ? 1 : cpp_opts->unsigned_char;
- cpp_opts->cpp_tabstop = global_dc->m_tabstop;
+ cpp_opts->cpp_tabstop = global_dc->get_column_options ().m_tabstop;
if (flag_extern_tls_init)
{
--- /dev/null
+/* Options relating to the meaning of column numbers.
+ 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_COLUMN_OPTIONS_H
+#define GCC_DIAGNOSTICS_COLUMN_OPTIONS_H
+
+namespace diagnostics {
+
+/* A bundle of options relating to the meaning of column numbers. */
+
+struct column_options
+{
+ int convert_column (file_cache &fc,
+ expanded_location s) const;
+
+ /* 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;
+};
+
+} // namespace diagnostics
+
+#endif /* ! GCC_DIAGNOSTICS_COLUMN_OPTIONS_H */
m_client_aux_data = nullptr;
m_lock = 0;
m_inhibit_notes_p = false;
+
m_source_printing.colorize_source_p = false;
m_source_printing.show_labels_p = false;
m_source_printing.show_line_numbers_p = false;
m_source_printing.min_margin_width = 0;
m_source_printing.show_ruler_p = false;
m_source_printing.show_event_links_p = false;
+
+ m_column_options.m_column_unit = DIAGNOSTICS_COLUMN_UNIT_DISPLAY;
+ m_column_options.m_column_origin = 1;
+ m_column_options.m_tabstop = 8;
+
m_report_bug = false;
m_extra_output_kind = EXTRA_DIAGNOSTIC_OUTPUT_none;
if (const char *var = getenv ("GCC_EXTRA_DIAGNOSTIC_OUTPUT"))
m_extra_output_kind = EXTRA_DIAGNOSTIC_OUTPUT_fixits_v2;
/* Silently ignore unrecognized values. */
}
- m_column_unit = DIAGNOSTICS_COLUMN_UNIT_DISPLAY;
- m_column_origin = 1;
- m_tabstop = 8;
m_escape_format = DIAGNOSTICS_ESCAPE_FORMAT_UNICODE;
m_fixits_change_set = nullptr;
m_diagnostic_groups.m_group_nesting_depth = 0;
}
}
+/* Given an expanded_location, convert the column (which is in 1-based bytes)
+ to the requested units and origin. Return -1 if the column is
+ invalid (<= 0). */
+int
+column_options::convert_column (file_cache &fc,
+ expanded_location s) const
+{
+ int one_based_col = convert_column_unit (fc, m_column_unit, m_tabstop, s);
+ if (one_based_col <= 0)
+ return -1;
+ return one_based_col + (m_column_origin - 1);
+}
+
column_policy::column_policy (const context &dc)
: m_file_cache (dc.get_file_cache ()),
- m_column_unit (dc.m_column_unit),
- m_column_origin (dc.m_column_origin),
- m_tabstop (dc.m_tabstop)
+ m_column_options (dc.get_column_options ())
{
}
int
column_policy::converted_column (expanded_location s) const
{
- int one_based_col = convert_column_unit (m_file_cache,
- m_column_unit, m_tabstop, s);
- if (one_based_col <= 0)
- return -1;
- return one_based_col + (m_column_origin - 1);
+ return m_column_options.convert_column (m_file_cache, s);
}
/* Return a string describing a location e.g. "foo.c:42:10". */
sink_->on_report_diagnostic (*diagnostic, orig_diag_kind);
}
+ const int tabstop = get_column_options ().m_tabstop;
+
switch (m_extra_output_kind)
{
default:
print_parseable_fixits (get_file_cache (),
m_reference_printer, diagnostic->m_richloc,
DIAGNOSTICS_COLUMN_UNIT_BYTE,
- m_tabstop);
+ tabstop);
pp_flush (m_reference_printer);
break;
case EXTRA_DIAGNOSTIC_OUTPUT_fixits_v2:
print_parseable_fixits (get_file_cache (),
m_reference_printer, diagnostic->m_richloc,
DIAGNOSTICS_COLUMN_UNIT_DISPLAY,
- m_tabstop);
+ tabstop);
pp_flush (m_reference_printer);
break;
}
= DIAGNOSTICS_COLUMN_UNIT_BYTE)
{
diagnostics::selftest::test_context dc;
- dc.m_column_unit = column_unit;
- dc.m_column_origin = origin;
+ dc.get_column_options ().m_column_unit = column_unit;
+ dc.get_column_options ().m_column_origin = origin;
expanded_location xloc;
xloc.file = filename;
#include "diagnostics/option-id-manager.h"
#include "diagnostics/context-options.h"
#include "diagnostics/source-printing-options.h"
+#include "diagnostics/column-options.h"
#include "diagnostics/counters.h"
namespace diagnostics {
bool show_column,
bool colorize) const;
- int get_tabstop () const { return m_tabstop; }
+ int get_tabstop () const { return m_column_options.m_tabstop; }
private:
file_cache &m_file_cache;
- enum diagnostics_column_unit m_column_unit;
- int m_column_origin;
- int m_tabstop;
+ column_options m_column_options;
};
/* A bundle of state for printing locations within diagnostics
return m_source_printing;
}
+ column_options &get_column_options () { return m_column_options; }
+ const column_options &get_column_options () const { return m_column_options; }
+
void set_caret_max_width (int value);
private:
bool m_inhibit_notes_p;
source_printing_options m_source_printing;
+ column_options m_column_options;
/* True if -freport-bug option is used. */
bool m_report_bug;
-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;
(std::make_unique<sarif_array_of_unique<sarif_logical_location>> ()),
m_run_graphs
(std::make_unique<sarif_array_of_unique<sarif_graph>> ()),
- m_tabstop (dc.m_tabstop),
+ m_tabstop (dc.get_column_options ().m_tabstop),
m_serialization_format (std::move (serialization_format)),
m_sarif_gen_opts (sarif_gen_opts),
m_next_result_idx (0),
for (int tabstop = 1; tabstop != num_tabstops; ++tabstop)
{
test_context dc;
- dc.m_tabstop = tabstop;
+ dc.get_column_options ().m_tabstop = tabstop;
diagnostics::source_print_policy policy (dc);
layout test_layout (policy, richloc, nullptr);
colorizer col (*dc.get_reference_printer (),
for (int tabstop = 1; tabstop != num_tabstops; ++tabstop)
{
test_context dc;
- dc.m_tabstop = tabstop;
+ dc.get_column_options ().m_tabstop = tabstop;
static const int small_width = 24;
auto &source_printing_opts = dc.get_source_printing_options ();
source_printing_opts.max_width = small_width - 4;
everything too. */
{
test_context dc;
- dc.m_tabstop = tabstop;
+ dc.get_column_options ().m_tabstop = tabstop;
rich_location richloc (line_table,
linemap_position_for_column (line_table,
first_non_ws_byte_col));
as well. */
{
test_context dc;
- dc.m_tabstop = tabstop;
+ dc.get_column_options ().m_tabstop = tabstop;
rich_location richloc (line_table,
linemap_position_for_column (line_table,
right_quote_byte_col));
break;
case OPT_fdiagnostics_column_unit_:
- dc->m_column_unit = (enum diagnostics_column_unit)value;
+ dc->get_column_options ().m_column_unit
+ = (enum diagnostics_column_unit)value;
break;
case OPT_fdiagnostics_column_origin_:
- dc->m_column_origin = value;
+ dc->get_column_options ().m_column_origin = value;
break;
case OPT_fdiagnostics_escape_format_:
case OPT_ftabstop_:
/* It is documented that we silently ignore silly values. */
if (value >= 1 && value <= 100)
- dc->m_tabstop = value;
+ dc->get_column_options ().m_tabstop = value;
break;
case OPT_freport_bug: