public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH 11/12] Fixups to diagnostic-format-sarif.cc
Date: Wed, 22 Jun 2022 18:34:46 -0400	[thread overview]
Message-ID: <20220622223447.2462880-12-dmalcolm@redhat.com> (raw)
In-Reply-To: <20220622223447.2462880-1-dmalcolm@redhat.com>

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 <dmalcolm@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


  parent reply	other threads:[~2022-06-22 22:34 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-22 22:34 [PATCH 00/12] RFC: Replay of serialized diagnostics David Malcolm
2022-06-22 22:34 ` [PATCH 01/12] diagnostics: add ability to associate diagnostics with rules from coding standards David Malcolm
2022-06-23 19:04   ` David Malcolm
2022-06-22 22:34 ` [PATCH 02/12] diagnostics: associate rules with plugins in SARIF output David Malcolm
2022-06-22 22:34 ` [PATCH 03/12] Add more emit_diagnostic overloads David Malcolm
2022-06-23 16:39   ` Joseph Myers
2022-06-22 22:34 ` [PATCH 04/12] json: add json parsing support David Malcolm
2022-06-22 22:34 ` [PATCH 05/12] Placeholder libcpp fixups David Malcolm
2022-06-22 22:34 ` [PATCH 06/12] prune.exp: move multiline-handling to before other pruning David Malcolm
2022-06-22 22:34 ` [PATCH 07/12] Add deferred-locations.h/cc David Malcolm
2022-06-22 22:34 ` [PATCH 08/12] Add json-reader.h/cc David Malcolm
2022-06-22 22:34 ` [PATCH 09/12] Add json frontend David Malcolm
2022-06-22 22:34 ` [PATCH 10/12] Add sarif frontend David Malcolm
2022-06-22 22:34 ` David Malcolm [this message]
2022-06-22 22:34 ` [PATCH 12/12] Work-in-progress of path remapping David Malcolm
2022-07-08 18:40 ` [PATCH 00/12] RFC: Replay of serialized diagnostics David Malcolm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220622223447.2462880-12-dmalcolm@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).