No functional change intended.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r14-5459-g353f146cebbf22.

gcc/c-family/ChangeLog:
        * c-warn.cc (conversion_warning): Update call to
        global_dc->m_option_enabled to use option_enabled_p.

gcc/cp/ChangeLog:
        * decl.cc (finish_function): Update call to
        global_dc->m_option_enabled to use option_enabled_p.

gcc/ChangeLog:
        * diagnostic-format-json.cc
        (json_output_format::on_end_diagnostic): Update calls to m_context
        callbacks to use member functions; tighten up scopes.
        * diagnostic-format-sarif.cc (sarif_builder::make_result_object):
        Likewise.
        (sarif_builder::make_reporting_descriptor_object_for_warning):
        Likewise.
        * diagnostic.cc (diagnostic_context::initialize): Update for
        callbacks being moved into m_option_callbacks and being renamed.
        (diagnostic_context::set_option_hooks): New.
        (diagnostic_option_classifier::classify_diagnostic): Update call
        to global_dc->m_option_enabled to use option_enabled_p.
        (diagnostic_context::print_option_information): Update calls to
        m_context callbacks to use member functions; tighten up scopes.
        (diagnostic_context::diagnostic_enabled): Likewise.
        * diagnostic.h (diagnostic_option_enabled_cb): New typedef.
        (diagnostic_make_option_name_cb): New typedef.
        (diagnostic_make_option_url_cb): New typedef.
        (diagnostic_context::option_enabled_p): New.
        (diagnostic_context::make_option_name): New.
        (diagnostic_context::make_option_url): New.
        (diagnostic_context::set_option_hooks): New decl.
        (diagnostic_context::m_option_enabled): Rename to
        m_option_enabled_cb and move within m_option_callbacks, using
        typedef.
        (diagnostic_context::m_option_state): Move within
        m_option_callbacks.
        (diagnostic_context::m_option_name): Rename to
        m_make_option_name_cb and move within m_option_callbacks, using
        typedef.
        (diagnostic_context::m_get_option_url): Likewise, renaming to
        m_make_option_url_cb.
        * lto-wrapper.cc (print_lto_docs_link): Update call to m_context
        callback to use member function.
        (main): Use diagnostic_context::set_option_hooks.
        * opts-diagnostic.h (option_name): Make context param const.
        (get_option_url): Likewise.
        * opts.cc (option_name): Likewise.
        (get_option_url): Likewise.
        * toplev.cc (general_init): Use
        diagnostic_context::set_option_hooks.
---
 gcc/c-family/c-warn.cc         |  4 +-
 gcc/cp/decl.cc                 |  4 +-
 gcc/diagnostic-format-json.cc  | 18 +++----
 gcc/diagnostic-format-sarif.cc | 15 ++----
 gcc/diagnostic.cc              | 45 ++++++++--------
 gcc/diagnostic.h               | 93 +++++++++++++++++++++++++---------
 gcc/lto-wrapper.cc             |  7 ++-
 gcc/opts-diagnostic.h          |  5 +-
 gcc/opts.cc                    |  4 +-
 gcc/toplev.cc                  |  8 +--
 10 files changed, 119 insertions(+), 84 deletions(-)

diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc
index b1bd8ba9f422..d2938b91043d 100644
--- a/gcc/c-family/c-warn.cc
+++ b/gcc/c-family/c-warn.cc
@@ -1350,9 +1350,7 @@ conversion_warning (location_t loc, tree type, tree expr, 
tree result)
          break;
 
        if (arith_ops
-           && global_dc->m_option_enabled (warnopt,
-                                           global_dc->m_lang_mask,
-                                           global_dc->m_option_state))
+           && global_dc->option_enabled_p (warnopt))
          {
            for (int i = 0; i < arith_ops; ++i)
              {
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 4a07c7e879b1..d2ed46b14531 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -18308,9 +18308,7 @@ finish_function (bool inline_p)
              && current_class_ref
              && same_type_ignoring_top_level_qualifiers_p
                  (TREE_TYPE (valtype), TREE_TYPE (current_class_ref))
-             && global_dc->m_option_enabled (OPT_Wreturn_type,
-                                             global_dc->m_lang_mask,
-                                             global_dc->m_option_state))
+             && global_dc->option_enabled_p (OPT_Wreturn_type))
            add_return_star_this_fixit (&richloc, fndecl);
        }
       if (cxx_dialect >= cxx14
diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
index 7c5a126786e6..141075b7dee8 100644
--- a/gcc/diagnostic-format-json.cc
+++ b/gcc/diagnostic-format-json.cc
@@ -217,24 +217,18 @@ json_output_format::on_end_diagnostic (diagnostic_info 
*diagnostic,
   diag_obj->set_string ("message", pp_formatted_text (m_context.printer));
   pp_clear_output_area (m_context.printer);
 
-  char *option_text;
-  option_text = m_context.m_option_name (&m_context, diagnostic->option_index,
-                                        orig_diag_kind, diagnostic->kind);
-  if (option_text)
+  if (char *option_text = m_context.make_option_name (diagnostic->option_index,
+                                                     orig_diag_kind,
+                                                     diagnostic->kind))
     {
       diag_obj->set_string ("option", option_text);
       free (option_text);
     }
 
-  if (m_context.m_get_option_url)
+  if (char *option_url = m_context.make_option_url (diagnostic->option_index))
     {
-      char *option_url = m_context.m_get_option_url (&m_context,
-                                                    diagnostic->option_index);
-      if (option_url)
-       {
-         diag_obj->set_string ("option_url", option_url);
-         free (option_url);
-       }
+      diag_obj->set_string ("option_url", option_url);
+      free (option_url);
     }
 
   /* If we've already emitted a diagnostic within this auto_diagnostic_group,
diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index 9510f4add80f..1bb728654e6c 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -536,8 +536,8 @@ sarif_builder::make_result_object (diagnostic_context 
*context,
   /* "ruleId" property (SARIF v2.1.0 section 3.27.5).  */
   /* Ideally we'd have an option_name for these.  */
   if (char *option_text
-       = context->m_option_name (context, diagnostic->option_index,
-                                 orig_diag_kind, diagnostic->kind))
+       = context->make_option_name (diagnostic->option_index,
+                                    orig_diag_kind, diagnostic->kind))
     {
       /* Lazily create reportingDescriptor objects for and add to m_rules_arr.
         Set ruleId referencing them.  */
@@ -639,15 +639,10 @@ make_reporting_descriptor_object_for_warning 
(diagnostic_context *context,
      it seems redundant compared to "id".  */
 
   /* "helpUri" property (SARIF v2.1.0 section 3.49.12).  */
-  if (context->m_get_option_url)
+  if (char *option_url = context->make_option_url (diagnostic->option_index))
     {
-      char *option_url
-       = context->m_get_option_url (context, diagnostic->option_index);
-      if (option_url)
-       {
-         reporting_desc->set_string ("helpUri", option_url);
-         free (option_url);
-       }
+      reporting_desc->set_string ("helpUri", option_url);
+      free (option_url);
     }
 
   return reporting_desc;
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index ccca2d2150f7..eb0df6890564 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -238,10 +238,10 @@ diagnostic_context::initialize (int n_opts)
   m_text_callbacks.m_begin_diagnostic = default_diagnostic_starter;
   m_text_callbacks.m_start_span = default_diagnostic_start_span_fn;
   m_text_callbacks.m_end_diagnostic = default_diagnostic_finalizer;
-  m_option_enabled = nullptr;
-  m_option_state = nullptr;
-  m_option_name = nullptr;
-  m_get_option_url = nullptr;
+  m_option_callbacks.m_option_enabled_cb = nullptr;
+  m_option_callbacks.m_option_state = nullptr;
+  m_option_callbacks.m_make_option_name_cb = nullptr;
+  m_option_callbacks.m_make_option_url_cb = nullptr;
   m_urlifier = nullptr;
   m_last_location = UNKNOWN_LOCATION;
   m_last_module = nullptr;
@@ -418,6 +418,19 @@ diagnostic_context::set_client_data_hooks 
(diagnostic_client_data_hooks *hooks)
   m_client_data_hooks = hooks;
 }
 
+void
+diagnostic_context::
+set_option_hooks (diagnostic_option_enabled_cb option_enabled_cb,
+                 void *option_state,
+                 diagnostic_make_option_name_cb make_option_name_cb,
+                 diagnostic_make_option_url_cb make_option_url_cb)
+{
+  m_option_callbacks.m_option_enabled_cb = option_enabled_cb;
+  m_option_callbacks.m_option_state = option_state;
+  m_option_callbacks.m_make_option_name_cb = make_option_name_cb;
+  m_option_callbacks.m_make_option_url_cb = make_option_url_cb;
+}
+
 void
 diagnostic_context::set_urlifier (urlifier *urlifier)
 {
@@ -1124,9 +1137,7 @@ classify_diagnostic (const diagnostic_context *context,
       /* Record the command-line status, so we can reset it back on DK_POP. */
       if (old_kind == DK_UNSPECIFIED)
        {
-         old_kind = !context->m_option_enabled (option_index,
-                                                context->m_lang_mask,
-                                                context->m_option_state)
+         old_kind = !context->option_enabled_p (option_index)
            ? DK_IGNORED : (context->warning_as_error_requested_p ()
                            ? DK_ERROR : DK_WARNING);
          m_classify_diagnostic[option_index] = old_kind;
@@ -1412,18 +1423,12 @@ void
 diagnostic_context::print_option_information (const diagnostic_info 
&diagnostic,
                                              diagnostic_t orig_diag_kind)
 {
-  char *option_text;
-
-  option_text = m_option_name (this, diagnostic.option_index,
-                              orig_diag_kind, diagnostic.kind);
-
-  if (option_text)
+  if (char *option_text = make_option_name (diagnostic.option_index,
+                                           orig_diag_kind, diagnostic.kind))
     {
-      char *option_url = NULL;
-      if (m_get_option_url
-         && this->printer->url_format != URL_FORMAT_NONE)
-       option_url = m_get_option_url (this,
-                                      diagnostic.option_index);
+      char *option_url = nullptr;
+      if (this->printer->url_format != URL_FORMAT_NONE)
+       option_url = make_option_url (diagnostic.option_index);
       pretty_printer * const pp = this->printer;
       pp_string (pp, " [");
       pp_string (pp, colorize_start (pp_show_color (pp),
@@ -1458,9 +1463,7 @@ diagnostic_context::diagnostic_enabled (diagnostic_info 
*diagnostic)
 
   /* This tests if the user provided the appropriate -Wfoo or
      -Wno-foo option.  */
-  if (! m_option_enabled (diagnostic->option_index,
-                         m_lang_mask,
-                         m_option_state))
+  if (!option_enabled_p (diagnostic->option_index))
     return false;
 
   /* This tests for #pragma diagnostic changes.  */
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index 57c5ed4f582a..db61b0e27477 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -179,6 +179,14 @@ typedef void (*diagnostic_finalizer_fn) 
(diagnostic_context *,
                                         diagnostic_info *,
                                         diagnostic_t);
 
+typedef int (*diagnostic_option_enabled_cb) (int, unsigned, void *);
+typedef char *(*diagnostic_make_option_name_cb) (const diagnostic_context *,
+                                                int,
+                                                diagnostic_t,
+                                                diagnostic_t);
+typedef char *(*diagnostic_make_option_url_cb) (const diagnostic_context *,
+                                               int);
+
 class edit_context;
 namespace json { class value; }
 class diagnostic_client_data_hooks;
@@ -491,6 +499,41 @@ public:
     return m_diagnostic_count[kind];
   }
 
+  /* Option-related member functions.  */
+  inline bool option_enabled_p (int option_index) const
+  {
+    if (!m_option_callbacks.m_option_enabled_cb)
+      return true;
+    return m_option_callbacks.m_option_enabled_cb
+      (option_index,
+       m_lang_mask,
+       m_option_callbacks.m_option_state);
+  }
+
+  inline char *make_option_name (int option_index,
+                               diagnostic_t orig_diag_kind,
+                               diagnostic_t diag_kind) const
+  {
+    if (!m_option_callbacks.m_make_option_name_cb)
+      return nullptr;
+    return m_option_callbacks.m_make_option_name_cb (this, option_index,
+                                                    orig_diag_kind,
+                                                    diag_kind);
+  }
+
+  inline char *make_option_url (int option_index) const
+  {
+    if (!m_option_callbacks.m_make_option_url_cb)
+      return nullptr;
+    return m_option_callbacks.m_make_option_url_cb (this, option_index);
+  }
+
+  void
+  set_option_hooks (diagnostic_option_enabled_cb option_enabled_cb,
+                   void *option_state,
+                   diagnostic_make_option_name_cb make_option_name_cb,
+                   diagnostic_make_option_url_cb make_option_url_cb);
+
 private:
   bool includes_seen_p (const line_map_ordinary *map);
 
@@ -606,32 +649,32 @@ public:
   /* Client hook to report an internal error.  */
   void (*m_internal_error) (diagnostic_context *, const char *, va_list *);
 
-  /* Client hook to say whether the option controlling a diagnostic is
-     enabled.  Returns nonzero if enabled, zero if disabled.  */
-  int (*m_option_enabled) (int, unsigned, void *);
-
-  /* Client information to pass as second argument to
-     option_enabled.  */
-  void *m_option_state;
-
-  /* Client hook to return the name of an option that controls a
-     diagnostic.  Returns malloced memory.  The first diagnostic_t
-     argument is the kind of diagnostic before any reclassification
-     (of warnings as errors, etc.); the second is the kind after any
-     reclassification.  May return NULL if no name is to be printed.
-     May be passed 0 as well as the index of a particular option.  */
-  char *(*m_option_name) (diagnostic_context *,
-                         int,
-                         diagnostic_t,
-                         diagnostic_t);
-
-  /* Client hook to return a URL describing the option that controls
-     a diagnostic.  Returns malloced memory.  May return NULL if no URL
-     is available.  May be passed 0 as well as the index of a
-     particular option.  */
-  char *(*m_get_option_url) (diagnostic_context *, int);
-
 private:
+  /* Client-supplied callbacks for working with options.  */
+  struct {
+    /* Client hook to say whether the option controlling a diagnostic is
+       enabled.  Returns nonzero if enabled, zero if disabled.  */
+    diagnostic_option_enabled_cb m_option_enabled_cb;
+
+    /* Client information to pass as second argument to
+       m_option_enabled_cb.  */
+    void *m_option_state;
+
+    /* Client hook to return the name of an option that controls a
+       diagnostic.  Returns malloced memory.  The first diagnostic_t
+       argument is the kind of diagnostic before any reclassification
+       (of warnings as errors, etc.); the second is the kind after any
+       reclassification.  May return NULL if no name is to be printed.
+       May be passed 0 as well as the index of a particular option.  */
+    diagnostic_make_option_name_cb m_make_option_name_cb;
+
+    /* Client hook to return a URL describing the option that controls
+       a diagnostic.  Returns malloced memory.  May return NULL if no URL
+       is available.  May be passed 0 as well as the index of a
+       particular option.  */
+    diagnostic_make_option_url_cb m_make_option_url_cb;
+  } m_option_callbacks;
+
   /* An optional hook for adding URLs to quoted text strings in
      diagnostics.  Only used for the main diagnostic message.  */
   urlifier *m_urlifier;
diff --git a/gcc/lto-wrapper.cc b/gcc/lto-wrapper.cc
index a92fed3d25b0..7c76635ef213 100644
--- a/gcc/lto-wrapper.cc
+++ b/gcc/lto-wrapper.cc
@@ -1355,7 +1355,7 @@ void
 print_lto_docs_link ()
 {
   bool print_url = global_dc->printer->url_format != URL_FORMAT_NONE;
-  const char *url = global_dc->m_get_option_url (global_dc, OPT_flto);
+  const char *url = global_dc->make_option_url (OPT_flto);
 
   pretty_printer pp;
   pp.url_format = URL_FORMAT_DEFAULT;
@@ -2146,7 +2146,10 @@ main (int argc, char *argv[])
   diagnostic_initialize (global_dc, 0);
   diagnostic_color_init (global_dc);
   diagnostic_urls_init (global_dc);
-  global_dc->m_get_option_url = get_option_url;
+  global_dc->set_option_hooks (nullptr,
+                              nullptr,
+                              nullptr,
+                              get_option_url);
 
   if (atexit (lto_wrapper_cleanup) != 0)
     fatal_error (input_location, "%<atexit%> failed");
diff --git a/gcc/opts-diagnostic.h b/gcc/opts-diagnostic.h
index b36fb46cc929..8c3b695f07a2 100644
--- a/gcc/opts-diagnostic.h
+++ b/gcc/opts-diagnostic.h
@@ -20,9 +20,10 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_OPTS_DIAGNOSTIC_H
 #define GCC_OPTS_DIAGNOSTIC_H
 
-extern char *option_name (diagnostic_context *context, int option_index,
+extern char *option_name (const diagnostic_context *context, int option_index,
                          diagnostic_t orig_diag_kind, diagnostic_t diag_kind);
 
-extern char *get_option_url (diagnostic_context *context, int option_index);
+extern char *get_option_url (const diagnostic_context *context,
+                            int option_index);
 
 #endif
diff --git a/gcc/opts.cc b/gcc/opts.cc
index 32fdfc3e3ce1..33165c9e74ff 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -3615,7 +3615,7 @@ enable_warning_as_error (const char *arg, int value, 
unsigned int lang_mask,
    as -Werror.  */
 
 char *
-option_name (diagnostic_context *context, int option_index,
+option_name (const diagnostic_context *context, int option_index,
             diagnostic_t orig_diag_kind, diagnostic_t diag_kind)
 {
   if (option_index)
@@ -3674,7 +3674,7 @@ get_option_html_page (int option_index)
    which enabled a diagnostic (context CONTEXT).  */
 
 char *
-get_option_url (diagnostic_context *, int option_index)
+get_option_url (const diagnostic_context *, int option_index)
 {
   if (option_index)
     return concat (/* DOCUMENTATION_ROOT_URL should be supplied via
diff --git a/gcc/toplev.cc b/gcc/toplev.cc
index d8e8978dd555..ae2f3d52602b 100644
--- a/gcc/toplev.cc
+++ b/gcc/toplev.cc
@@ -1045,10 +1045,10 @@ general_init (const char *argv0, bool init_signals)
   global_dc->m_show_column
     = global_options_init.x_flag_show_column;
   global_dc->m_internal_error = internal_error_function;
-  global_dc->m_option_enabled = option_enabled;
-  global_dc->m_option_state = &global_options;
-  global_dc->m_option_name = option_name;
-  global_dc->m_get_option_url = get_option_url;
+  global_dc->set_option_hooks (option_enabled,
+                              &global_options,
+                              option_name,
+                              get_option_url);
   global_dc->set_urlifier (make_gcc_urlifier ());
 
   if (init_signals)
-- 
2.26.3

Reply via email to