I believe these are needed by one of the rule-handling patches.

gcc/ChangeLog:
        * diagnostic-format-sarif.cc (sarif_builder::sarif_builder):
        Defer population of m_driver_obj until...
        (sarif_builder::make_tool_object): ...here.
        (sarif_builder::make_driver_tool_component_object): Replace
        with...
        (sarif_builder::populate_driver_object): ...this.

Signed-off-by: David Malcolm <dmalc...@redhat.com>
---
 gcc/diagnostic-format-sarif.cc | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc
index a409abf648b..9c304fd8e49 100644
--- a/gcc/diagnostic-format-sarif.cc
+++ b/gcc/diagnostic-format-sarif.cc
@@ -158,7 +158,7 @@ private:
   json::object *make_top_level_object (json::array *results);
   json::object *make_run_object (json::array *results);
   json::object *make_tool_object ();
-  sarif_tool_component *make_driver_tool_component_object () const;
+  void populate_driver_object () const;
   json::array *maybe_make_taxonomies_array () const;
   json::object *maybe_make_cwe_taxonomy_object () const;
   json::object *make_tool_component_reference_object_for_cwe () const;
@@ -289,7 +289,7 @@ sarif_builder::sarif_builder (diagnostic_context *context)
   m_extensions_arr (NULL),
   m_tabstop (context->tabstop)
 {
-  m_driver_obj = make_driver_tool_component_object ();
+  m_driver_obj = new sarif_tool_component ();
   m_extensions_arr = new json::array ();
 }
 
@@ -1256,6 +1256,7 @@ sarif_builder::make_tool_object ()
 
   /* "driver" property (SARIF v2.1.0 section 3.18.2).  */
   tool_obj->set ("driver", m_driver_obj);
+  populate_driver_object ();
 
   /* Report plugins via the "extensions" property
      (SARIF v2.1.0 section 3.18.3).  */
@@ -1288,42 +1289,40 @@ sarif_builder::make_tool_object ()
   return tool_obj;
 }
 
-/* Make a toolComponent object (SARIF v2.1.0 section 3.19) for what SARIF
-   calls the "driver" (see SARIF v2.1.0 section 3.18.1).  */
+/* Populate the toolComponent object (SARIF v2.1.0 section 3.19) for what SARIF
+   calls the "driver" (see SARIF v2.1.0 section 3.18.1).
+   We delay this to ensure that the m_client_data_hooks is set up (e.g. for
+   roundtripping from SARIF to SARIF).  */
 
-sarif_tool_component *
-sarif_builder::make_driver_tool_component_object () const
+void
+sarif_builder::populate_driver_object () const
 {
-  sarif_tool_component *driver_obj = new sarif_tool_component ();
-
   if (m_context->m_client_data_hooks)
     if (const client_version_info *vinfo
          = m_context->m_client_data_hooks->get_any_version_info ())
       {
        /* "name" property (SARIF v2.1.0 section 3.19.8).  */
        if (const char *name = vinfo->get_tool_name ())
-         driver_obj->set ("name", new json::string (name));
+         m_driver_obj->set ("name", new json::string (name));
 
        /* "fullName" property (SARIF v2.1.0 section 3.19.9).  */
        if (char *full_name = vinfo->maybe_make_full_name ())
          {
-           driver_obj->set ("fullName", new json::string (full_name));
+           m_driver_obj->set ("fullName", new json::string (full_name));
            free (full_name);
          }
 
        /* "version" property (SARIF v2.1.0 section 3.19.13).  */
        if (const char *version = vinfo->get_version_string ())
-         driver_obj->set ("version", new json::string (version));
+         m_driver_obj->set ("version", new json::string (version));
 
        /* "informationUri" property (SARIF v2.1.0 section 3.19.17).  */
        if (char *version_url =  vinfo->maybe_make_version_url ())
          {
-           driver_obj->set ("informationUri", new json::string (version_url));
+           m_driver_obj->set ("informationUri", new json::string 
(version_url));
            free (version_url);
          }
       }
-
-  return driver_obj;
 }
 
 /* If we've seen any CWE IDs, make an array for the "taxonomies" property
-- 
2.26.3

Reply via email to