https://gcc.gnu.org/g:268ec60da01c67d346df9504fb2a60050259738d

commit r16-2762-g268ec60da01c67d346df9504fb2a60050259738d
Author: David Malcolm <dmalc...@redhat.com>
Date:   Mon Aug 4 10:45:30 2025 -0400

    diagnostics: rename option_manager to option_id_manager and split out from 
context.h
    
    This patch splits out class option_manager to its own header,
    and renames it to class option_id_manager to better describe its
    purpose.
    
    No functional change intended.
    
    gcc/ChangeLog:
            * diagnostics/context.cc: Update for renaming of option_manager to
            option_id_manager and of context::m_option_mgr to
            context::m_option_id_mgr.
            * diagnostics/context.h: Likewise, moving class declaration to a
            new diagnostics/option-id-manager.h.
            * diagnostics/lazy-paths.cc: Likewise.
            * diagnostics/option-id-manager.h: New file, from material in
            diagnostics/context.h.
            * lto-wrapper.cc: Update for renaming of option_manager to
            option_id_manager.
            * opts-common.cc: Likewise.
            * opts-diagnostic.h: Likewise.
            * opts.cc: Likewise.
            * toplev.cc: Likewise.
    
    Signed-off-by: David Malcolm <dmalc...@redhat.com>

Diff:
---
 gcc/diagnostics/context.cc          | 14 +++++-----
 gcc/diagnostics/context.h           | 54 +++++++++--------------------------
 gcc/diagnostics/lazy-paths.cc       |  6 ++--
 gcc/diagnostics/option-id-manager.h | 56 +++++++++++++++++++++++++++++++++++++
 gcc/lto-wrapper.cc                  | 13 +++++----
 gcc/opts-common.cc                  |  2 +-
 gcc/opts-diagnostic.h               | 19 +++++++------
 gcc/opts.cc                         |  4 +--
 gcc/toplev.cc                       |  8 +++---
 9 files changed, 103 insertions(+), 73 deletions(-)

diff --git a/gcc/diagnostics/context.cc b/gcc/diagnostics/context.cc
index 85f7d2a357ac..4d33f97017f7 100644
--- a/gcc/diagnostics/context.cc
+++ b/gcc/diagnostics/context.cc
@@ -170,7 +170,7 @@ context::initialize (int n_opts)
   m_text_callbacks.m_html_start_span
     = default_start_span_fn<to_html>;
   m_text_callbacks.m_end_diagnostic = default_text_finalizer;
-  m_option_mgr = nullptr;
+  m_option_id_mgr = nullptr;
   m_urlifier_stack = new auto_vec<urlifier_stack_node> ();
   m_last_location = UNKNOWN_LOCATION;
   m_client_aux_data = nullptr;
@@ -337,8 +337,8 @@ context::finish ()
       m_client_data_hooks = nullptr;
     }
 
-  delete m_option_mgr;
-  m_option_mgr = nullptr;
+  delete m_option_id_mgr;
+  m_option_id_mgr = nullptr;
 
   if (m_urlifier_stack)
     {
@@ -465,11 +465,11 @@ context::set_original_argv (unique_argv original_argv)
 }
 
 void
-context::set_option_manager (std::unique_ptr<option_manager> mgr,
-                            unsigned lang_mask)
+context::set_option_id_manager (std::unique_ptr<option_id_manager> mgr,
+                               unsigned lang_mask)
 {
-  delete m_option_mgr;
-  m_option_mgr = mgr.release ();
+  delete m_option_id_mgr;
+  m_option_id_mgr = mgr.release ();
   m_lang_mask = lang_mask;
 }
 
diff --git a/gcc/diagnostics/context.h b/gcc/diagnostics/context.h
index f47370b11973..1a26431ff6c4 100644
--- a/gcc/diagnostics/context.h
+++ b/gcc/diagnostics/context.h
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "lazily-created.h"
 #include "unique-argv.h"
 #include "diagnostics/option-classifier.h"
+#include "diagnostics/option-id-manager.h"
 #include "diagnostics/context-options.h"
 
 namespace diagnostics {
@@ -81,35 +82,6 @@ typedef void (*text_finalizer_fn) (text_sink &,
                                   const diagnostic_info *,
                                   enum kind);
 
-/* Abstract base class for the diagnostic subsystem to make queries
-   about command-line options.  */
-
-class option_manager
-{
-public:
-  virtual ~option_manager () {}
-
-  /* Return 1 if option OPT_ID is enabled, 0 if it is disabled,
-     or -1 if it isn't a simple on-off switch
-     (or if the value is unknown, typically set later in target).  */
-  virtual int option_enabled_p (option_id opt_id) const = 0;
-
-  /* Return malloced memory for the name of the option OPT_ID
-     which enabled a diagnostic, originally of type ORIG_DIAG_KIND but
-     possibly converted to DIAG_KIND by options such as -Werror.
-     May return NULL if no name is to be printed.
-     May be passed 0 as well as the index of a particular option.  */
-  virtual char *make_option_name (option_id opt_id,
-                                 enum kind orig_diag_kind,
-                                 enum kind diag_kind) const = 0;
-
-  /* Return malloced memory for a URL describing the option that controls
-     a diagnostic.
-     May return NULL if no URL is available.
-     May be passed 0 as well as the index of a particular option.  */
-  virtual char *make_option_url (option_id opt_id) const = 0;
-};
-
 /* A bundle of options relating to printing the user's source code
    (potentially with a margin, underlining, labels, etc).  */
 
@@ -334,7 +306,7 @@ struct counters
    - an optional urlifier to inject URLs into formatted messages
    - counting the number of diagnostics reported of each kind
      (class diagnostics::counters)
-   - calling out to a option_manager to determine if
+   - calling out to a option_id_manager to determine if
      a particular warning is enabled or disabled
    - tracking pragmas that enable/disable warnings in a range of
      source code
@@ -546,32 +518,32 @@ public:
   /* Option-related member functions.  */
   inline bool option_enabled_p (option_id opt_id) const
   {
-    if (!m_option_mgr)
+    if (!m_option_id_mgr)
       return true;
-    return m_option_mgr->option_enabled_p (opt_id);
+    return m_option_id_mgr->option_enabled_p (opt_id);
   }
 
   inline char *make_option_name (option_id opt_id,
                                 enum kind orig_diag_kind,
                                 enum kind diag_kind) const
   {
-    if (!m_option_mgr)
+    if (!m_option_id_mgr)
       return nullptr;
-    return m_option_mgr->make_option_name (opt_id,
-                                          orig_diag_kind,
-                                          diag_kind);
+    return m_option_id_mgr->make_option_name (opt_id,
+                                             orig_diag_kind,
+                                             diag_kind);
   }
 
   inline char *make_option_url (option_id opt_id) const
   {
-    if (!m_option_mgr)
+    if (!m_option_id_mgr)
       return nullptr;
-    return m_option_mgr->make_option_url (opt_id);
+    return m_option_id_mgr->make_option_url (opt_id);
   }
 
   void
-  set_option_manager (std::unique_ptr<option_manager> mgr,
-                     unsigned lang_mask);
+  set_option_id_manager (std::unique_ptr<option_id_manager> option_id_mgr,
+                        unsigned lang_mask);
 
   unsigned get_lang_mask () const
   {
@@ -808,7 +780,7 @@ private:
 
   /* Owned by the context; this would be a std::unique_ptr if
      context had a proper ctor.  */
-  option_manager *m_option_mgr;
+  option_id_manager *m_option_id_mgr;
   unsigned m_lang_mask;
 
   /* A stack of optional hooks for adding URLs to quoted text strings in
diff --git a/gcc/diagnostics/lazy-paths.cc b/gcc/diagnostics/lazy-paths.cc
index 4934651c3229..f246eea94205 100644
--- a/gcc/diagnostics/lazy-paths.cc
+++ b/gcc/diagnostics/lazy-paths.cc
@@ -125,12 +125,12 @@ test_intraprocedural_path (pretty_printer *event_pp)
                "double `free'");
 }
 
-/* Implementation of diagnostics::option_manager for which all
+/* Implementation of diagnostics::option_id_manager for which all
    options are disabled, for use in selftests.
    Note that this is *not* called for option_id (0), which
    means "always warn"  */
 
-class all_warnings_disabled : public diagnostics::option_manager
+class all_warnings_disabled : public diagnostics::option_id_manager
 {
 public:
   int option_enabled_p (diagnostics::option_id) const final override
@@ -168,7 +168,7 @@ test_emission (pretty_printer *event_pp)
      is skipped.  */
   {
     test_context dc;
-    dc.set_option_manager (std::make_unique<all_warnings_disabled> (), 0);
+    dc.set_option_id_manager (std::make_unique<all_warnings_disabled> (), 0);
 
     test_rich_location rich_loc (*event_pp);
     ASSERT_FALSE (rich_loc.m_path.generated_p ());
diff --git a/gcc/diagnostics/option-id-manager.h 
b/gcc/diagnostics/option-id-manager.h
new file mode 100644
index 000000000000..08add5bbc269
--- /dev/null
+++ b/gcc/diagnostics/option-id-manager.h
@@ -0,0 +1,56 @@
+/* Hooks for giving client-specific meaning to option ids.
+   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_OPTION_ID_MANAGER_H
+#define GCC_DIAGNOSTICS_OPTION_ID_MANAGER_H
+
+namespace diagnostics {
+
+/* Abstract base class for the diagnostic subsystem to make queries
+   about command-line options.  */
+
+class option_id_manager
+{
+public:
+  virtual ~option_id_manager () {}
+
+  /* Return 1 if option OPT_ID is enabled, 0 if it is disabled,
+     or -1 if it isn't a simple on-off switch
+     (or if the value is unknown, typically set later in target).  */
+  virtual int option_enabled_p (option_id opt_id) const = 0;
+
+  /* Return malloced memory for the name of the option OPT_ID
+     which enabled a diagnostic, originally of type ORIG_DIAG_KIND but
+     possibly converted to DIAG_KIND by options such as -Werror.
+     May return NULL if no name is to be printed.
+     May be passed 0 as well as the index of a particular option.  */
+  virtual char *make_option_name (option_id opt_id,
+                                 enum kind orig_diag_kind,
+                                 enum kind diag_kind) const = 0;
+
+  /* Return malloced memory for a URL describing the option that controls
+     a diagnostic.
+     May return NULL if no URL is available.
+     May be passed 0 as well as the index of a particular option.  */
+  virtual char *make_option_url (option_id opt_id) const = 0;
+};
+
+} // namespace diagnostics
+
+#endif /* ! GCC_DIAGNOSTICS_OPTION_ID_MANAGER_H */
diff --git a/gcc/lto-wrapper.cc b/gcc/lto-wrapper.cc
index cb293f210993..03fca978645e 100644
--- a/gcc/lto-wrapper.cc
+++ b/gcc/lto-wrapper.cc
@@ -2265,13 +2265,14 @@ cont:
   obstack_free (&argv_obstack, NULL);
 }
 
-/* Concrete implementation of diagnostic_option_manager for LTO.  */
+/* Concrete implementation of diagnostics::option_id_manager for LTO.  */
 
-class lto_diagnostic_option_manager : public gcc_diagnostic_option_manager
+class lto_diagnostic_option_id_manager
+  : public gcc_diagnostic_option_id_manager
 {
 public:
-  lto_diagnostic_option_manager ()
-  : gcc_diagnostic_option_manager (0 /* lang_mask */)
+  lto_diagnostic_option_id_manager ()
+  : gcc_diagnostic_option_id_manager (0 /* lang_mask */)
   {
   }
   int option_enabled_p (diagnostics::option_id) const final override
@@ -2307,8 +2308,8 @@ main (int argc, char *argv[])
   diagnostic_initialize (global_dc, 0);
   diagnostic_color_init (global_dc);
   diagnostic_urls_init (global_dc);
-  global_dc->set_option_manager
-    (::make_unique<lto_diagnostic_option_manager> (), 0);
+  global_dc->set_option_id_manager
+    (::make_unique<lto_diagnostic_option_id_manager> (), 0);
 
   if (atexit (lto_wrapper_cleanup) != 0)
     fatal_error (input_location, "%<atexit%> failed");
diff --git a/gcc/opts-common.cc b/gcc/opts-common.cc
index 91cad49b9bd7..e6d7f4d7b504 100644
--- a/gcc/opts-common.cc
+++ b/gcc/opts-common.cc
@@ -1876,7 +1876,7 @@ option_enabled (int opt_idx, unsigned lang_mask, void 
*opts)
 }
 
 int
-compiler_diagnostic_option_manager::
+compiler_diagnostic_option_id_manager::
 option_enabled_p (diagnostics::option_id opt_id) const
 {
   return option_enabled (opt_id.m_idx, m_lang_mask, m_opts);
diff --git a/gcc/opts-diagnostic.h b/gcc/opts-diagnostic.h
index 4fa4ea8a6f5a..25ade867ef24 100644
--- a/gcc/opts-diagnostic.h
+++ b/gcc/opts-diagnostic.h
@@ -20,30 +20,31 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_OPTS_DIAGNOSTIC_H
 #define GCC_OPTS_DIAGNOSTIC_H
 
-/* Abstract subclass of diagnostics::option_manager for gcc options.  */
+/* Abstract subclass of diagnostics::option_id_manager for gcc options.  */
 
-class gcc_diagnostic_option_manager : public diagnostics::option_manager
+class gcc_diagnostic_option_id_manager : public diagnostics::option_id_manager
 {
 public:
   char *make_option_url (diagnostics::option_id option_id) const final 
override;
 
 protected:
-  gcc_diagnostic_option_manager (unsigned lang_mask)
+  gcc_diagnostic_option_id_manager (unsigned lang_mask)
   : m_lang_mask (lang_mask)
   {}
 
   unsigned m_lang_mask;
 };
 
-/* Concrete implementation of diagnostic_option_manager for compiler.  */
+/* Concrete implementation of diagnostics::option_id_manager for compiler.  */
 
-class compiler_diagnostic_option_manager : public gcc_diagnostic_option_manager
+class compiler_diagnostic_option_id_manager
+  : public gcc_diagnostic_option_id_manager
 {
 public:
-  compiler_diagnostic_option_manager (const diagnostics::context &context,
-                                     unsigned lang_mask,
-                                     void *opts)
-  : gcc_diagnostic_option_manager (lang_mask),
+  compiler_diagnostic_option_id_manager (const diagnostics::context &context,
+                                        unsigned lang_mask,
+                                        void *opts)
+  : gcc_diagnostic_option_id_manager (lang_mask),
     m_context (context),
     m_opts (opts)
   {
diff --git a/gcc/opts.cc b/gcc/opts.cc
index c21e66ba9171..b6d25bfd1702 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -3744,7 +3744,7 @@ enable_warning_as_error (const char *arg, int value, 
unsigned int lang_mask,
    as -Werror.  */
 
 char *
-compiler_diagnostic_option_manager::
+compiler_diagnostic_option_id_manager::
 make_option_name (diagnostics::option_id option_id,
                  enum diagnostics::kind orig_diag_kind,
                  enum diagnostics::kind diag_kind) const
@@ -3823,7 +3823,7 @@ get_option_url_suffix (int option_index, unsigned 
lang_mask)
    which enabled a diagnostic.  */
 
 char *
-gcc_diagnostic_option_manager::
+gcc_diagnostic_option_id_manager::
 make_option_url (diagnostics::option_id option_id) const
 {
   if (option_id.m_idx)
diff --git a/gcc/toplev.cc b/gcc/toplev.cc
index 70dbb3e717f6..d349d83ebad9 100644
--- a/gcc/toplev.cc
+++ b/gcc/toplev.cc
@@ -1096,10 +1096,10 @@ general_init (const char *argv0, bool init_signals, 
unique_argv original_argv)
     (global_options_init.x_flag_diagnostics_show_highlight_colors);
   global_dc->set_internal_error_callback (internal_error_function);
   const unsigned lang_mask = lang_hooks.option_lang_mask ();
-  global_dc->set_option_manager
-    (std::make_unique<compiler_diagnostic_option_manager> (*global_dc,
-                                                          lang_mask,
-                                                          &global_options),
+  global_dc->set_option_id_manager
+    (std::make_unique<compiler_diagnostic_option_id_manager> (*global_dc,
+                                                             lang_mask,
+                                                             &global_options),
      lang_mask);
   global_dc->push_owned_urlifier (make_gcc_urlifier (lang_mask));

Reply via email to