From 5a73e0713fcfd633abab78da6c2a27d48068bde0 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Mon, 4 Aug 2025 16:56:16 -0400
Subject: [PATCH 75/98] FIXME: non-working WIP on using enum class in
 diagnostics/context-options.h

---
 gcc/common.opt                     | 48 ++++++++--------
 gcc/diagnostics/column-options.h   |  2 +-
 gcc/diagnostics/context-options.h  | 46 +++++++--------
 gcc/diagnostics/context.cc         | 91 +++++++++++++++---------------
 gcc/diagnostics/context.h          | 22 ++++----
 gcc/diagnostics/lazy-paths.cc      |  2 +-
 gcc/diagnostics/paths-output.cc    | 40 ++++++-------
 gcc/diagnostics/sarif-sink.cc      |  6 +-
 gcc/diagnostics/sink.h             |  2 +-
 gcc/diagnostics/source-printing.cc | 20 +++----
 gcc/opts.cc                        |  8 +--
 11 files changed, 143 insertions(+), 144 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index 88b79bbf8f56..232323eaa13b 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1501,7 +1501,7 @@ EnumValue
 Enum(diagnostic_url_rule) String(auto) Value(DIAGNOSTICS_URL_AUTO)
 
 fdiagnostics-column-unit=
-Common Joined RejectNegative Enum(diagnostics_column_unit)
+Common Joined RejectNegative Enum(diagnostics::column_unit)
 -fdiagnostics-column-unit=[display|byte]	Select whether column numbers are output as display columns (default) or raw bytes.
 
 fdiagnostics-column-origin=
@@ -1509,7 +1509,7 @@ Common Joined RejectNegative UInteger
 -fdiagnostics-column-origin=<number>	Set the number of the first column.  The default is 1-based as per GNU style, but some utilities may expect 0-based, for example.
 
 fdiagnostics-format=
-Common Joined RejectNegative Enum(diagnostics_output_format)
+Common Joined RejectNegative Enum(diagnostics::output_format)
 -fdiagnostics-format=[text|sarif-stderr|sarif-file]	Select output format.
 
 fdiagnostics-add-output=
@@ -1521,7 +1521,7 @@ Common Joined RejectNegative
 Set output format.
 
 fdiagnostics-escape-format=
-Common Joined RejectNegative Enum(diagnostics_escape_format)
+Common Joined RejectNegative Enum(diagnostics::escape_format)
 -fdiagnostics-escape-format=[unicode|bytes]	Select how to escape non-printable-ASCII bytes in the source for diagnostics that suggest it.
 
 ; Required for these enum values.
@@ -1529,34 +1529,34 @@ SourceInclude
 diagnostic.h
 
 Enum
-Name(diagnostics_column_unit) Type(int)
+Name(diagnostics::column_unit) Type(int)
 
 EnumValue
-Enum(diagnostics_column_unit) String(display) Value(DIAGNOSTICS_COLUMN_UNIT_DISPLAY)
+Enum(diagnostics::column_unit) String(display) Value(diagnostics::column_unit::display)
 
 EnumValue
-Enum(diagnostics_column_unit) String(byte) Value(DIAGNOSTICS_COLUMN_UNIT_BYTE)
+Enum(diagnostics::column_unit) String(byte) Value(diagnostics::column_unit::byte)
 
 Enum
-Name(diagnostics_escape_format) Type(int)
+Name(diagnostics::escape_format) Type(int)
 
 EnumValue
-Enum(diagnostics_escape_format) String(unicode) Value(DIAGNOSTICS_ESCAPE_FORMAT_UNICODE)
+Enum(diagnostics::escape_format) String(unicode) Value(diagnostics::escape_format::unicode)
 
 EnumValue
-Enum(diagnostics_escape_format) String(bytes) Value(DIAGNOSTICS_ESCAPE_FORMAT_BYTES)
+Enum(diagnostics::escape_format) String(bytes) Value(diagnostics::escape_format::bytes)
 
 Enum
-Name(diagnostics_output_format) Type(int)
+Name(diagnosticss::output_format) Type(int)
 
 EnumValue
-Enum(diagnostics_output_format) String(text) Value(DIAGNOSTICS_OUTPUT_FORMAT_TEXT)
+Enum(diagnostics::output_format) String(text) Value(diagnostics::output_format::text)
 
 EnumValue
-Enum(diagnostics_output_format) String(sarif-stderr) Value(DIAGNOSTICS_OUTPUT_FORMAT_SARIF_STDERR)
+Enum(diagnostics::output_format) String(sarif-stderr) Value(diagnostics::output_format::sarif_stderr)
 
 EnumValue
-Enum(diagnostics_output_format) String(sarif-file) Value(DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE)
+Enum(diagnostics::output_format) String(sarif-file) Value(diagnostics::output_format::sarif_file)
 
 fdiagnostics-parseable-fixits
 Common Var(flag_diagnostics_parseable_fixits)
@@ -1583,7 +1583,7 @@ Common Var(flag_diagnostics_show_highlight_colors) Init(1)
 Use color within diagnostic messages to highlight pertinent information.
 
 fdiagnostics-path-format=
-Common Joined RejectNegative Var(flag_diagnostics_path_format) Enum(diagnostic_path_format) Init(DPF_INLINE_EVENTS)
+Common Joined RejectNegative Var(flag_diagnostics_path_format) Enum(diagnostics::path_format) Init(diagnostics::path_format::inline_events)
 Specify how to print any control-flow path associated with a diagnostic.
 
 fdiagnostics-plain-output
@@ -1595,39 +1595,39 @@ Common Joined RejectNegative UInteger
 -ftabstop=<number>      Distance between tab stops for column reporting.
 
 Enum
-Name(diagnostic_path_format) Type(int)
+Name(diagnostics::path_format) Type(int)
 
 EnumValue
-Enum(diagnostic_path_format) String(none) Value(DPF_NONE)
+Enum(diagnostics::path_format) String(none) Value(diagnostics::path_format::none)
 
 EnumValue
-Enum(diagnostic_path_format) String(separate-events) Value(DPF_SEPARATE_EVENTS)
+Enum(diagnostics::path_format) String(separate-events) Value(diagnostics::path_format::separate_events)
 
 EnumValue
-Enum(diagnostic_path_format) String(inline-events) Value(DPF_INLINE_EVENTS)
+Enum(diagnostics::path_format) String(inline-events) Value(diagnostics::path_format::inline_events)
 
 fdiagnostics-show-path-depths
 Common Var(flag_diagnostics_show_path_depths) Init(0)
 Show stack depths of events in paths.
 
 fdiagnostics-text-art-charset=
-Driver Common Joined RejectNegative Var(flag_diagnostics_text_art_charset) Enum(diagnostic_text_art_charset) Init(DIAGNOSTICS_TEXT_ART_CHARSET_EMOJI)
+Driver Common Joined RejectNegative Var(flag_diagnostics_text_art_charset) Enum(diagnostics::text_art_charset) Init(text_art_charset::emoji)
 -fdiagnostics-text-art-charset=[none|ascii|unicode|emoji]	Determine which characters to use in text arg diagrams.
 
 Enum
-Name(diagnostic_text_art_charset) Type(int)
+Name(diagnostics::text_art_charset) Type(int)
 
 EnumValue
-Enum(diagnostic_text_art_charset) String(none) Value(DIAGNOSTICS_TEXT_ART_CHARSET_NONE)
+Enum(diagnostics::text_art_charset) String(none) Value(diagnostics::text_art_charset::none)
 
 EnumValue
-Enum(diagnostic_text_art_charset) String(ascii) Value(DIAGNOSTICS_TEXT_ART_CHARSET_ASCII)
+Enum(diagnostics::text_art_charset) String(ascii) Value(diagnostics::text_art_charset::ascii)
 
 EnumValue
-Enum(diagnostic_text_art_charset) String(unicode) Value(DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE)
+Enum(diagnostics::text_art_charset) String(unicode) Value(diagnostics::text_art_charset::unicode)
 
 EnumValue
-Enum(diagnostic_text_art_charset) String(emoji) Value(DIAGNOSTICS_TEXT_ART_CHARSET_EMOJI)
+Enum(diagnostics::text_art_charset) String(emoji) Value(diagnostics::text_art_charset::emoji)
 
 fdiagnostics-minimum-margin-width=
 Common Joined RejectNegative UInteger Var(diagnostics_minimum_margin_width) Init(6)
diff --git a/gcc/diagnostics/column-options.h b/gcc/diagnostics/column-options.h
index 4389566d54ee..f3a43d247c38 100644
--- a/gcc/diagnostics/column-options.h
+++ b/gcc/diagnostics/column-options.h
@@ -30,7 +30,7 @@ struct column_options
 		      expanded_location s) const;
 
   /* What units to use when outputting the column number.  */
-  enum diagnostics_column_unit m_column_unit;
+  enum column_unit m_column_unit;
 
   /* The origin for the column number (1-based or 0-based typically).  */
   int m_column_origin;
diff --git a/gcc/diagnostics/context-options.h b/gcc/diagnostics/context-options.h
index cc488a6d51b3..f829609c308e 100644
--- a/gcc/diagnostics/context-options.h
+++ b/gcc/diagnostics/context-options.h
@@ -25,92 +25,92 @@ along with GCC; see the file COPYING3.  If not see
    Tabs will be expanded or not according to the value of -ftabstop.  The origin
    (default 1) is controlled by -fdiagnostics-column-origin.  */
 
-enum diagnostics_column_unit
+enum class column_unit
 {
   /* The default from GCC 11 onwards: display columns.  */
-  DIAGNOSTICS_COLUMN_UNIT_DISPLAY,
+  display,
 
   /* The behavior in GCC 10 and earlier: simple bytes.  */
-  DIAGNOSTICS_COLUMN_UNIT_BYTE
+  byte
 };
 
 /* An enum for controlling how to print non-ASCII characters/bytes when
    a diagnostic suggests escaping the source code on output.  */
 
-enum diagnostics_escape_format
+enum class escape_format
 {
   /* Escape non-ASCII Unicode characters in the form <U+XXXX> and
      non-UTF-8 bytes in the form <XX>.  */
-  DIAGNOSTICS_ESCAPE_FORMAT_UNICODE,
+  unicode,
 
   /* Escape non-ASCII bytes in the form <XX> (thus showing the underlying
      encoding of non-ASCII Unicode characters).  */
-  DIAGNOSTICS_ESCAPE_FORMAT_BYTES
+  bytes
 };
 
 /* Enum for overriding the standard output format.  */
 
-enum diagnostics_output_format
+enum class output_format
 {
   /* The default: textual output.  */
-  DIAGNOSTICS_OUTPUT_FORMAT_TEXT,
+  text,
 
   /* SARIF-based output, as JSON to stderr.  */
-  DIAGNOSTICS_OUTPUT_FORMAT_SARIF_STDERR,
+  sarif_stderr,
 
   /* SARIF-based output, to a JSON file.  */
-  DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE
+  sarif_file
 };
 
 /* An enum for controlling how diagnostic paths should be printed.  */
-enum diagnostic_path_format
+enum class path_format
 {
   /* Don't print diagnostic paths.  */
-  DPF_NONE,
+   none,
 
   /* Print diagnostic paths by emitting a separate "note" for every event
      in the path.  */
-  DPF_SEPARATE_EVENTS,
+  separate_events,
 
   /* Print diagnostic paths by consolidating events together where they
      are close enough, and printing such runs of events with multiple
      calls to diagnostic_show_locus, showing the individual events in
      each run via labels in the source.  */
-  DPF_INLINE_EVENTS
+  inline_events
 };
 
 /* An enum for capturing values of GCC_EXTRA_DIAGNOSTIC_OUTPUT,
    and for -fdiagnostics-parseable-fixits.  */
 
-enum diagnostics_extra_output_kind
+enum class extra_output_kind
 {
   /* No extra output, or an unrecognized value.  */
-  EXTRA_DIAGNOSTIC_OUTPUT_none,
+  none,
 
   /* Emit fix-it hints using the "fixits-v1" format, equivalent to
      -fdiagnostics-parseable-fixits.  */
-  EXTRA_DIAGNOSTIC_OUTPUT_fixits_v1,
+  fixits_v1,
 
   /* Emit fix-it hints using the "fixits-v2" format.  */
-  EXTRA_DIAGNOSTIC_OUTPUT_fixits_v2
+  fixits_v2
 };
 
 /* Values for -fdiagnostics-text-art-charset=.  */
 
-enum diagnostic_text_art_charset
+enum class text_art_charset
 {
   /* No text art diagrams shall be emitted.  */
-  DIAGNOSTICS_TEXT_ART_CHARSET_NONE,
+  none,
 
   /* Use pure ASCII for text art diagrams.  */
-  DIAGNOSTICS_TEXT_ART_CHARSET_ASCII,
+  ascii,
 
   /* Use ASCII + conservative use of other unicode characters
      in text art diagrams.  */
-  DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE,
+  unicode,
 
   /* Use Emoji.  */
-  DIAGNOSTICS_TEXT_ART_CHARSET_EMOJI
+  emoji
 };
 
 #endif /* ! GCC_DIAGNOSTICS_CONTEXT_OPTIONS_H */
diff --git a/gcc/diagnostics/context.cc b/gcc/diagnostics/context.cc
index 98af6ecb1b66..d482d2dedcdf 100644
--- a/gcc/diagnostics/context.cc
+++ b/gcc/diagnostics/context.cc
@@ -152,7 +152,7 @@ context::initialize (int n_opts)
     m_source_printing.caret_chars[i] = '^';
   m_show_cwe = false;
   m_show_rules = false;
-  m_path_format = DPF_NONE;
+  m_path_format = path_format::none;
   m_show_path_depths = false;
   m_show_option_requested = false;
   m_abort_on_error = false;
@@ -186,21 +186,21 @@ context::initialize (int n_opts)
   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_unit = 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;
+  m_extra_output_kind = extra_output_kind::none;
   if (const char *var = getenv ("GCC_EXTRA_DIAGNOSTIC_OUTPUT"))
     {
       if (!strcmp (var, "fixits-v1"))
-	m_extra_output_kind = EXTRA_DIAGNOSTIC_OUTPUT_fixits_v1;
+	m_extra_output_kind = extra_output_kind::fixits_v1;
       else if (!strcmp (var, "fixits-v2"))
-	m_extra_output_kind = EXTRA_DIAGNOSTIC_OUTPUT_fixits_v2;
+	m_extra_output_kind = extra_output_kind::fixits_v2;
       /* Silently ignore unrecognized values.  */
     }
-  m_escape_format = DIAGNOSTICS_ESCAPE_FORMAT_UNICODE;
+  m_escape_format = escape_format::unicode;
   m_fixits_change_set = nullptr;
   m_diagnostic_groups.m_group_nesting_depth = 0;
   m_diagnostic_groups.m_diagnostic_nesting_level = 0;
@@ -214,16 +214,16 @@ context::initialize (int n_opts)
   m_diagnostic_buffer = nullptr;
   m_logger = nullptr;
 
-  enum diagnostic_text_art_charset text_art_charset
-    = DIAGNOSTICS_TEXT_ART_CHARSET_EMOJI;
+  enum text_art_charset ta_charset
+    = text_art_charset::emoji;
   if (const char *lang = getenv ("LANG"))
     {
       /* For LANG=C, don't assume the terminal supports anything
 	 other than ASCII.  */
       if (!strcmp (lang, "C"))
-	text_art_charset = DIAGNOSTICS_TEXT_ART_CHARSET_ASCII;
+	ta_charset = text_art_charset::ascii;
     }
-  set_text_art_charset (text_art_charset);
+  set_text_art_charset (ta_charset);
 
   if (const char *name = getenv ("GCC_DIAGNOSTICS_LOG"))
     {
@@ -760,25 +760,25 @@ get_color_for_kind (enum kind kind)
 
 static int
 convert_column_unit (file_cache &fc,
-		     enum diagnostics_column_unit column_unit,
+		     enum column_unit col_unit,
 		     int tabstop,
 		     expanded_location s)
 {
   if (s.column <= 0)
     return -1;
 
-  switch (column_unit)
+  switch (col_unit)
     {
     default:
       gcc_unreachable ();
 
-    case DIAGNOSTICS_COLUMN_UNIT_DISPLAY:
+    case column_unit::display:
       {
 	cpp_char_column_policy policy (tabstop, cpp_wcwidth);
 	return location_compute_display_column (fc, s, policy);
       }
 
-    case DIAGNOSTICS_COLUMN_UNIT_BYTE:
+    case column_unit::byte:
       return s.column;
     }
 }
@@ -1174,13 +1174,13 @@ print_escaped_string (pretty_printer *pp, const char *text)
 /* Implementation of -fdiagnostics-parseable-fixits and
    GCC_EXTRA_DIAGNOSTIC_OUTPUT.
    Print a machine-parseable version of all fixits in RICHLOC to PP,
-   using COLUMN_UNIT to express columns.
-   Use TABSTOP when handling DIAGNOSTICS_COLUMN_UNIT_DISPLAY.  */
+   using COL_UNIT to express columns.
+   Use TABSTOP when handling column_unit::display.  */
 
 static void
 print_parseable_fixits (file_cache &fc,
 			pretty_printer *pp, rich_location *richloc,
-			enum diagnostics_column_unit column_unit,
+			enum column_unit col_unit,
 			int tabstop)
 {
   gcc_assert (pp);
@@ -1200,9 +1200,9 @@ print_parseable_fixits (file_cache &fc,
       location_t next_loc = hint->get_next_loc ();
       expanded_location next_exploc = expand_location (next_loc);
       int start_col
-	= convert_column_unit (fc, column_unit, tabstop, start_exploc);
+	= convert_column_unit (fc, col_unit, tabstop, start_exploc);
       int next_col
-	= convert_column_unit (fc, column_unit, tabstop, next_exploc);
+	= convert_column_unit (fc, col_unit, tabstop, next_exploc);
       pp_printf (pp, ":{%i:%i-%i:%i}:",
 		 start_exploc.line, start_col,
 		 next_exploc.line, next_col);
@@ -1541,17 +1541,17 @@ context::report_diagnostic (diagnostic_info *diagnostic)
     {
     default:
       break;
-    case EXTRA_DIAGNOSTIC_OUTPUT_fixits_v1:
+    case extra_output_kind::fixits_v1:
       print_parseable_fixits (get_file_cache (),
 			      m_reference_printer, diagnostic->m_richloc,
-			      DIAGNOSTICS_COLUMN_UNIT_BYTE,
+			      column_unit::byte,
 			      tabstop);
       pp_flush (m_reference_printer);
       break;
-    case EXTRA_DIAGNOSTIC_OUTPUT_fixits_v2:
+    case extra_output_kind::fixits_v2:
       print_parseable_fixits (get_file_cache (),
 			      m_reference_printer, diagnostic->m_richloc,
-			      DIAGNOSTICS_COLUMN_UNIT_DISPLAY,
+			      column_unit::display,
 			      tabstop);
       pp_flush (m_reference_printer);
       break;
@@ -1899,7 +1899,7 @@ void
 output_format_init (context &dc,
 		    const char *main_input_filename_,
 		    const char *base_file_name,
-		    enum diagnostics_output_format format,
+		    enum output_format format,
 		    bool json_formatting)
 {
   sink *new_sink = nullptr;
@@ -1907,17 +1907,17 @@ output_format_init (context &dc,
     {
     default:
       gcc_unreachable ();
-    case DIAGNOSTICS_OUTPUT_FORMAT_TEXT:
+    case output_format::text:
       /* The default; do nothing.  */
       break;
 
-    case DIAGNOSTICS_OUTPUT_FORMAT_SARIF_STDERR:
+    case output_format::sarif_stderr:
       new_sink = &init_sarif_stderr (dc,
 				     line_table,
 				     json_formatting);
       break;
 
-    case DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE:
+    case output_format::sarif_file:
       new_sink = &init_sarif_file (dc,
 				   line_table,
 				   json_formatting,
@@ -1933,7 +1933,7 @@ output_format_init (context &dc,
    (or nullptr for "no diagrams").  */
 
 void
-context::set_text_art_charset (enum diagnostic_text_art_charset charset)
+context::set_text_art_charset (enum text_art_charset charset)
 {
   delete m_diagrams.m_theme;
   switch (charset)
@@ -1941,19 +1941,19 @@ context::set_text_art_charset (enum diagnostic_text_art_charset charset)
     default:
       gcc_unreachable ();
 
-    case DIAGNOSTICS_TEXT_ART_CHARSET_NONE:
+    case text_art_charset::none:
       m_diagrams.m_theme = nullptr;
       break;
 
-    case DIAGNOSTICS_TEXT_ART_CHARSET_ASCII:
+    case text_art_charset::ascii:
       m_diagrams.m_theme = new text_art::ascii_theme ();
       break;
 
-    case DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE:
+    case text_art_charset::unicode:
       m_diagrams.m_theme = new text_art::unicode_theme ();
       break;
 
-    case DIAGNOSTICS_TEXT_ART_CHARSET_EMOJI:
+    case text_art_charset::emoji:
       m_diagrams.m_theme = new text_art::emoji_theme ();
       break;
     }
@@ -2065,7 +2065,7 @@ test_print_parseable_fixits_none ()
   file_cache fc;
   rich_location richloc (line_table, UNKNOWN_LOCATION);
 
-  print_parseable_fixits (fc, &pp, &richloc, DIAGNOSTICS_COLUMN_UNIT_BYTE, 8);
+  print_parseable_fixits (fc, &pp, &richloc, column_unit::byte, 8);
   ASSERT_STREQ ("", pp_formatted_text (&pp));
 }
 
@@ -2085,7 +2085,7 @@ test_print_parseable_fixits_insert ()
   location_t where = linemap_position_for_column (line_table, 10);
   richloc.add_fixit_insert_before (where, "added content");
 
-  print_parseable_fixits (fc, &pp, &richloc, DIAGNOSTICS_COLUMN_UNIT_BYTE, 8);
+  print_parseable_fixits (fc, &pp, &richloc, column_unit::byte, 8);
   ASSERT_STREQ ("fix-it:\"test.c\":{5:10-5:10}:\"added content\"\n",
 		pp_formatted_text (&pp));
 }
@@ -2108,7 +2108,7 @@ test_print_parseable_fixits_remove ()
   where.m_finish = linemap_position_for_column (line_table, 20);
   richloc.add_fixit_remove (where);
 
-  print_parseable_fixits (fc, &pp, &richloc, DIAGNOSTICS_COLUMN_UNIT_BYTE, 8);
+  print_parseable_fixits (fc, &pp, &richloc, column_unit::byte, 8);
   ASSERT_STREQ ("fix-it:\"test.c\":{5:10-5:21}:\"\"\n",
 		pp_formatted_text (&pp));
 }
@@ -2131,13 +2131,13 @@ test_print_parseable_fixits_replace ()
   where.m_finish = linemap_position_for_column (line_table, 20);
   richloc.add_fixit_replace (where, "replacement");
 
-  print_parseable_fixits (fc, &pp, &richloc, DIAGNOSTICS_COLUMN_UNIT_BYTE, 8);
+  print_parseable_fixits (fc, &pp, &richloc, column_unit::byte, 8);
   ASSERT_STREQ ("fix-it:\"test.c\":{5:10-5:21}:\"replacement\"\n",
 		pp_formatted_text (&pp));
 }
 
 /* Verify that print_parseable_fixits correctly handles
-   DIAGNOSTICS_COLUMN_UNIT_BYTE vs DIAGNOSTICS_COLUMN_UNIT_COLUMN.  */
+   column_unit::byte vs column_unit::COLUMN.  */
 
 static void
 test_print_parseable_fixits_bytes_vs_display_columns ()
@@ -2173,7 +2173,7 @@ test_print_parseable_fixits_bytes_vs_display_columns ()
   {
     pretty_printer pp;
     print_parseable_fixits (fc, &pp, &richloc,
-			    DIAGNOSTICS_COLUMN_UNIT_BYTE,
+			    column_unit::byte,
 			    tabstop);
     snprintf (expected, buf_len,
 	      "fix-it:%s:{1:12-1:18}:\"color\"\n", escaped_fname);
@@ -2182,7 +2182,7 @@ test_print_parseable_fixits_bytes_vs_display_columns ()
   {
     pretty_printer pp;
     print_parseable_fixits (fc, &pp, &richloc,
-			    DIAGNOSTICS_COLUMN_UNIT_DISPLAY,
+			    column_unit::display,
 			    tabstop);
     snprintf (expected, buf_len,
 	      "fix-it:%s:{1:10-1:16}:\"color\"\n", escaped_fname);
@@ -2203,11 +2203,10 @@ assert_location_text (const char *expected_loc_text,
 		      const char *filename, int line, int column,
 		      bool show_column,
 		      int origin = 1,
-		      enum diagnostics_column_unit column_unit
-			= DIAGNOSTICS_COLUMN_UNIT_BYTE)
+		      enum column_unit col_unit = column_unit::byte)
 {
   diagnostics::selftest::test_context dc;
-  dc.get_column_options ().m_column_unit = column_unit;
+  dc.get_column_options ().m_column_unit = col_unit;
   dc.get_column_options ().m_column_origin = origin;
 
   expanded_location xloc;
@@ -2264,19 +2263,19 @@ test_get_location_text ()
 
     snprintf (expected, buf_len, "%s:1:%d:", fname, line_bytes);
     assert_location_text (expected, fname, 1, line_bytes, true,
-			  1, DIAGNOSTICS_COLUMN_UNIT_BYTE);
+			  1, column_unit::byte);
 
     snprintf (expected, buf_len, "%s:1:%d:", fname, line_bytes - 1);
     assert_location_text (expected, fname, 1, line_bytes, true,
-			  0, DIAGNOSTICS_COLUMN_UNIT_BYTE);
+			  0, column_unit::byte);
 
     snprintf (expected, buf_len, "%s:1:%d:", fname, display_width);
     assert_location_text (expected, fname, 1, line_bytes, true,
-			  1, DIAGNOSTICS_COLUMN_UNIT_DISPLAY);
+			  1, column_unit::display);
 
     snprintf (expected, buf_len, "%s:1:%d:", fname, display_width - 1);
     assert_location_text (expected, fname, 1, line_bytes, true,
-			  0, DIAGNOSTICS_COLUMN_UNIT_DISPLAY);
+			  0, column_unit::display);
 
     XDELETEVEC (expected);
   }
diff --git a/gcc/diagnostics/context.h b/gcc/diagnostics/context.h
index afb8e9e0b91b..e170b12d6cce 100644
--- a/gcc/diagnostics/context.h
+++ b/gcc/diagnostics/context.h
@@ -186,7 +186,7 @@ public:
   file_cache &
   get_file_cache () const { return m_file_cache; }
 
-  enum diagnostics_escape_format
+  enum escape_format
   get_escape_format () const
   {
     return m_escape_format;
@@ -214,7 +214,7 @@ private:
 
   /* Other data copied from context.  */
   text_art::theme *m_diagram_theme;
-  enum diagnostics_escape_format m_escape_format;
+  enum escape_format m_escape_format;
 };
 
 /* This class encapsulates the state of the diagnostics subsystem
@@ -392,7 +392,7 @@ public:
 
   /* 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_text_art_charset (enum text_art_charset charset);
 
   std::unique_ptr<client_data_hooks>
   set_client_data_hooks (std::unique_ptr<client_data_hooks> hooks);
@@ -407,14 +407,14 @@ public:
     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)
+  void set_extra_output_kind (enum 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)
+  void set_path_format (enum path_format val)
   {
     m_path_format = val;
   }
@@ -424,7 +424,7 @@ public:
   void set_show_nesting_locations (bool val);
   void set_show_nesting_levels (bool val);
   void set_max_errors (int val) { m_max_errors = val; }
-  void set_escape_format (enum diagnostics_escape_format val)
+  void set_escape_format (enum escape_format val)
   {
     m_escape_format = val;
   }
@@ -439,8 +439,8 @@ public:
   }
   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
+  enum path_format get_path_format () const { return m_path_format; }
+  enum escape_format get_escape_format () const
   {
     return m_escape_format;
   }
@@ -675,7 +675,7 @@ private:
   bool m_show_rules;
 
   /* How should diagnostics::paths::path objects be printed.  */
-  enum diagnostic_path_format m_path_format;
+  enum path_format m_path_format;
 
   /* True if we should print stack depths when printing diagnostic paths.  */
   bool m_show_path_depths;
@@ -781,11 +781,11 @@ private:
   /* 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;
+  enum extra_output_kind m_extra_output_kind;
 
   /* 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;
+  enum escape_format m_escape_format;
 
   /* If non-NULL, a diagnostics::changes::change_set to which fix-it hints
      should be applied, for generating patches.
diff --git a/gcc/diagnostics/lazy-paths.cc b/gcc/diagnostics/lazy-paths.cc
index 0320110e3608..64152a41a9fd 100644
--- a/gcc/diagnostics/lazy-paths.cc
+++ b/gcc/diagnostics/lazy-paths.cc
@@ -200,7 +200,7 @@ test_emission (pretty_printer *event_pp)
     ASSERT_TRUE (rich_loc.m_path.generated_p ());
 
     /* Verify that the path works as expected.  */
-    dc.set_path_format (DPF_INLINE_EVENTS);
+    dc.set_path_format (path_format::inline_events);
     diagnostics::text_sink sink_ (dc);
     pp_buffer (sink_.get_printer ())->m_flush_p = false;
     sink_.print_path (rich_loc.m_path);
diff --git a/gcc/diagnostics/paths-output.cc b/gcc/diagnostics/paths-output.cc
index a89b3a46f74c..278f51dc1de8 100644
--- a/gcc/diagnostics/paths-output.cc
+++ b/gcc/diagnostics/paths-output.cc
@@ -1364,11 +1364,11 @@ diagnostics::text_sink::print_path (const path &path_)
 
   switch (get_context ().get_path_format ())
     {
-    case DPF_NONE:
+    case path_format::none:
       /* Do nothing.  */
       return;
 
-    case DPF_SEPARATE_EVENTS:
+    case path_format::separate_events:
       {
 	/* A note per event.  */
 	auto &logical_loc_mgr = path_.get_logical_location_manager ();
@@ -1406,7 +1406,7 @@ diagnostics::text_sink::print_path (const path &path_)
       }
       break;
 
-    case DPF_INLINE_EVENTS:
+    case path_format::inline_events:
       {
 	/* Consolidate related events.  */
 	path_print_policy policy (*this);
@@ -1568,7 +1568,7 @@ test_interprocedural_path_1 (pretty_printer *event_pp)
     path_summary summary (policy, *event_pp, path, false);
     ASSERT_EQ (summary.get_num_ranges (), 9);
 
-    dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
+    dc.set_text_art_charset (text_art_charset::ascii);
     print_path_summary_as_text (summary, text_output, true);
     ASSERT_STREQ
       ("  `test': events 1-2 (depth 0)\n"
@@ -1624,7 +1624,7 @@ test_interprocedural_path_1 (pretty_printer *event_pp)
   }
   {
     selftest::test_context dc;
-    dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE);
+    dc.set_text_art_charset (text_art_charset::unicode);
     text_sink text_output (dc);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, false);
@@ -1707,7 +1707,7 @@ test_interprocedural_path_2 (pretty_printer *event_pp)
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, false);
     ASSERT_EQ (summary.get_num_ranges (), 5);
-    dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
+    dc.set_text_art_charset (text_art_charset::ascii);
     print_path_summary_as_text (summary, text_output, true);
     ASSERT_STREQ
       ("  `foo': events 1-2 (depth 0)\n"
@@ -1739,7 +1739,7 @@ test_interprocedural_path_2 (pretty_printer *event_pp)
   }
   {
     selftest::test_context dc;
-    dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE);
+    dc.set_text_art_charset (text_art_charset::unicode);
     text_sink text_output (dc);
     path_print_policy policy (text_output);
     path_summary summary (policy, *event_pp, path, false);
@@ -1791,7 +1791,7 @@ test_recursion (pretty_printer *event_pp)
 
   {
     selftest::test_context dc;
-    dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
+    dc.set_text_art_charset (text_art_charset::ascii);
 
     text_sink text_output (dc);
     path_print_policy policy (text_output);
@@ -1823,7 +1823,7 @@ test_recursion (pretty_printer *event_pp)
   }
   {
     selftest::test_context dc;
-    dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE);
+    dc.set_text_art_charset (text_art_charset::unicode);
 
     text_sink text_output (dc);
     path_print_policy policy (text_output);
@@ -1946,7 +1946,7 @@ test_control_flow_1 (const line_table_case &case_,
 
   {
     selftest::test_context dc;
-    dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
+    dc.set_text_art_charset (text_art_charset::ascii);
     dc.show_event_links (true);
     text_sink text_output (dc);
     path_print_policy policy (text_output);
@@ -1972,7 +1972,7 @@ test_control_flow_1 (const line_table_case &case_,
   }
   {
     selftest::test_context dc;
-    dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
+    dc.set_text_art_charset (text_art_charset::ascii);
     dc.show_event_links (false);
     text_sink text_output (dc);
     path_print_policy policy (text_output);
@@ -1995,7 +1995,7 @@ test_control_flow_1 (const line_table_case &case_,
   }
   {
     selftest::test_context dc;
-    dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
+    dc.set_text_art_charset (text_art_charset::ascii);
     dc.show_line_numbers (true);
     dc.show_event_links (true);
     text_sink text_output (dc);
@@ -2022,7 +2022,7 @@ test_control_flow_1 (const line_table_case &case_,
   }
   {
     selftest::test_context dc;
-    dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
+    dc.set_text_art_charset (text_art_charset::ascii);
     dc.show_line_numbers (true);
     dc.show_event_links (false);
     text_sink text_output (dc);
@@ -2046,7 +2046,7 @@ test_control_flow_1 (const line_table_case &case_,
   }
   {
     selftest::test_context dc;
-    dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE);
+    dc.set_text_art_charset (text_art_charset::unicode);
     dc.show_event_links (true);
     text_sink text_output (dc);
     path_print_policy policy (text_output);
@@ -2072,7 +2072,7 @@ test_control_flow_1 (const line_table_case &case_,
   }
   {
     selftest::test_context dc;
-    dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE);
+    dc.set_text_art_charset (text_art_charset::unicode);
     dc.show_event_links (true);
     dc.show_line_numbers (true);
     text_sink text_output (dc);
@@ -2144,7 +2144,7 @@ test_control_flow_2 (const line_table_case &case_,
 
   {
     selftest::test_context dc;
-    dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
+    dc.set_text_art_charset (text_art_charset::ascii);
     dc.show_event_links (true);
     dc.show_line_numbers (true);
     text_sink text_output (dc);
@@ -2232,7 +2232,7 @@ test_control_flow_3 (const line_table_case &case_,
 
   {
     selftest::test_context dc;
-    dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
+    dc.set_text_art_charset (text_art_charset::ascii);
     dc.show_event_links (true);
     dc.show_line_numbers (true);
     text_sink text_output (dc);
@@ -2291,7 +2291,7 @@ assert_cfg_edge_path_streq (const location &loc,
     return;
 
   selftest::test_context dc;
-  dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
+  dc.set_text_art_charset (text_art_charset::ascii);
   dc.show_event_links (true);
   dc.show_line_numbers (true);
   text_sink text_output (dc);
@@ -2616,7 +2616,7 @@ test_control_flow_5 (const line_table_case &case_,
 
   {
     selftest::test_context dc;
-    dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
+    dc.set_text_art_charset (text_art_charset::ascii);
     dc.show_event_links (true);
     dc.show_line_numbers (true);
     text_sink text_output (dc);
@@ -2706,7 +2706,7 @@ test_control_flow_6 (const line_table_case &case_,
 
   {
     selftest::test_context dc;
-    dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII);
+    dc.set_text_art_charset (text_art_charset::ascii);
     dc.show_event_links (true);
     dc.show_line_numbers (true);
     text_sink text_output (dc);
diff --git a/gcc/diagnostics/sarif-sink.cc b/gcc/diagnostics/sarif-sink.cc
index 3f032a0a70e1..ef85abea8f62 100644
--- a/gcc/diagnostics/sarif-sink.cc
+++ b/gcc/diagnostics/sarif-sink.cc
@@ -2450,9 +2450,9 @@ sarif_builder::make_location_object (sarif_location_manager *loc_mgr,
   {
   public:
     escape_nonascii_renderer (const rich_location &richloc,
-			      enum diagnostics_escape_format escape_format)
+			      enum escape_format escape_format_)
     : m_richloc (richloc),
-      m_escape_format (escape_format)
+      m_escape_format (escape_format_)
     {}
 
     std::unique_ptr<sarif_multiformat_message_string>
@@ -2485,7 +2485,7 @@ sarif_builder::make_location_object (sarif_location_manager *loc_mgr,
     }
   private:
     const rich_location &m_richloc;
-    enum diagnostics_escape_format m_escape_format;
+    enum escape_format m_escape_format;
   } the_renderer (rich_loc,
 		  m_context.get_escape_format ());
 
diff --git a/gcc/diagnostics/sink.h b/gcc/diagnostics/sink.h
index bf33037f963f..decd5640caf9 100644
--- a/gcc/diagnostics/sink.h
+++ b/gcc/diagnostics/sink.h
@@ -145,7 +145,7 @@ extern void
 output_format_init (context &,
 		    const char *main_input_filename_,
 		    const char *base_file_name,
-		    enum diagnostics_output_format,
+		    enum output_format,
 		    bool json_formatting);
 
 } // namespace diagnostics
diff --git a/gcc/diagnostics/source-printing.cc b/gcc/diagnostics/source-printing.cc
index db9b3c1f2410..6e0be68efdf9 100644
--- a/gcc/diagnostics/source-printing.cc
+++ b/gcc/diagnostics/source-printing.cc
@@ -1714,14 +1714,14 @@ make_char_policy (const diagnostics::source_print_policy &source_policy,
 	{
 	default:
 	  gcc_unreachable ();
-	case DIAGNOSTICS_ESCAPE_FORMAT_UNICODE:
+	case escape_format::unicode:
 	  result.m_width_cb = escape_as_unicode_width;
 	  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:
+	case escape_format::bytes:
 	  result.m_width_cb = escape_as_bytes_width;
 	  result.m_print_text_cb = escape_as_bytes_print<diagnostics::to_text>;
 	  result.m_print_html_cb = escape_as_bytes_print<diagnostics::to_html>;
@@ -4135,7 +4135,7 @@ test_display_widths ()
 
   {
     test_context dc;
-    dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
+    dc.set_escape_format (escape_format::unicode);
     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);
@@ -4147,7 +4147,7 @@ test_display_widths ()
 
   {
     test_context dc;
-    dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
+    dc.set_escape_format (escape_format::bytes);
     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);
@@ -5654,7 +5654,7 @@ test_one_liner_labels_utf8 ()
 
     {
       test_context dc;
-      dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
+      dc.set_escape_format (escape_format::unicode);
       ASSERT_STREQ (" <U+1F602>_foo = <U+03C0>_bar.<U+1F602>_field<U+03C0>;\n"
 		    " ^~~~~~~~~~~~~   ~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~\n"
 		    " |               |            |\n"
@@ -5665,7 +5665,7 @@ test_one_liner_labels_utf8 ()
     }
     {
       test_context dc;
-      dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
+      dc.set_escape_format (escape_format::bytes);
       ASSERT_STREQ
 	(" <f0><9f><98><82>_foo = <cf><80>_bar.<f0><9f><98><82>_field<cf><80>;\n"
 	 " ^~~~~~~~~~~~~~~~~~~~   ~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
@@ -6894,7 +6894,7 @@ test_escaping_bytes_1 (const line_table_case &case_)
   richloc.set_escape_on_output (true);
   {
     test_context dc;
-    dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
+    dc.set_escape_format (escape_format::unicode);
     ASSERT_STREQ
       (" before<U+0000><U+0001><U+0002><U+0003><U+000B><80><ff>after\n"
        "       ^~~~~~~~                        ~~~~~~~~\n",
@@ -6902,7 +6902,7 @@ test_escaping_bytes_1 (const line_table_case &case_)
   }
   {
     test_context dc;
-    dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
+    dc.set_escape_format (escape_format::bytes);
     ASSERT_STREQ (" before<00><01><02><03><0b><80><ff>after\n"
 		  "       ^~~~            ~~~~\n",
 		  dc.test_show_locus (richloc));
@@ -6944,14 +6944,14 @@ test_escaping_bytes_2 (const line_table_case &case_)
   richloc.set_escape_on_output (true);
   {
     test_context dc;
-    dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_UNICODE);
+    dc.set_escape_format (escape_format::unicode);
     ASSERT_STREQ (" <U+0000>after\n"
 		  " ^~~~~~~~\n",
 		  dc.test_show_locus (richloc));
   }
   {
     test_context dc;
-    dc.set_escape_format (DIAGNOSTICS_ESCAPE_FORMAT_BYTES);
+    dc.set_escape_format (escape_format::bytes);
     ASSERT_STREQ (" <00>after\n"
 		  " ^~~~\n",
 		  dc.test_show_locus (richloc));
diff --git a/gcc/opts.cc b/gcc/opts.cc
index 09baa411cfd1..39464c455d5a 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -3048,7 +3048,7 @@ common_handle_option (struct gcc_options *opts,
 	  gcc_assert (dc);
 	  diagnostics::output_format_init (*dc,
 					   opts->x_main_input_filename, basename,
-					   (enum diagnostics_output_format)value,
+					   (enum diagnostics::output_format)value,
 					   opts->x_flag_diagnostics_json_formatting);
 	  break;
 	}
@@ -3062,13 +3062,13 @@ common_handle_option (struct gcc_options *opts,
       break;
 
     case OPT_fdiagnostics_text_art_charset_:
-      dc->set_text_art_charset ((enum diagnostic_text_art_charset)value);
+      dc->set_text_art_charset ((enum diagnostic::text_art_charset)value);
       break;
 
     case OPT_fdiagnostics_parseable_fixits:
       dc->set_extra_output_kind (value
-				 ? EXTRA_DIAGNOSTIC_OUTPUT_fixits_v1
-				 : EXTRA_DIAGNOSTIC_OUTPUT_none);
+				 ? diagnostics::extra_output_kind::fixits_v1
+				 : diagnostics::extra_output_kind::none);
       break;
 
     case OPT_fdiagnostics_column_unit_:
-- 
2.49.0

