From 40c0cd9f96e78543bb5afcd265c7af3ab33cf200 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 12 Mar 2026 13:06:10 -0400
Subject: [PATCH 48/98] FIXME: more not-yet-working SARIF refactoring

---
 gcc/diagnostics/sarif-sink.cc | 82 ++++++++++++++++++++++++-----------
 1 file changed, 56 insertions(+), 26 deletions(-)

diff --git a/gcc/diagnostics/sarif-sink.cc b/gcc/diagnostics/sarif-sink.cc
index 7f0b8da573cb..82c616dd5b20 100644
--- a/gcc/diagnostics/sarif-sink.cc
+++ b/gcc/diagnostics/sarif-sink.cc
@@ -137,8 +137,6 @@ class sarif_artifact_content; // 3.3
 class sarif_artifact_location; // 3.4
 class sarif_message; // 3.11
 class sarif_multiformat_message_string; // 3.12
-class sarif_run; // 3.14
-class sarif_tool; // 3.18
 class sarif_tool_component; // 3.19
 class sarif_invocation; // 3.20
 class sarif_artifact; // 3.24
@@ -194,11 +192,6 @@ class sarif_message : public sarif_object {};
 
 class sarif_multiformat_message_string : public sarif_object {};
 
-/* Subclass of sarif_object for SARIF "run" objects
-   (SARIF v2.1.0 section 3.14).  */
-
-class sarif_run : public sarif_object {};
-
 /* Subclass of sarif_object for SARIF "tool" objects
    (SARIF v2.1.0 section 3.18).  */
 
@@ -667,8 +660,23 @@ public:
 };
 
 namespace sarif {
+
+template <typename Type>
+class array : public std::vector<Type>
+{
+public:
+  std::unique_ptr<json::object>
+  to_json (sarif_builder &builder) const
+  {
+    gcc_unreachable (); // FIXME
+  }
+};
+
 namespace spec {
 
+class run;
+class tool;
+
 class object
 {
 public:
@@ -687,7 +695,28 @@ public:
   std::unique_ptr<json::value>
   to_json (sarif_builder &builder) const;
 
-  std::unique_ptr<json::array> runs;
+  array<run> runs;
+};
+
+// 3.14
+
+class run : public object
+{
+public:
+  std::unique_ptr<json::value>
+  to_json (sarif_builder &builder) const;
+
+  std::unique_ptr<tool> tool; // FIXME
+};
+
+
+// 3.18
+
+class tool : public object
+{
+public:
+  std::unique_ptr<json::value>
+  to_json (sarif_builder &builder) const;
 };
 
 } // namespace diagnostics::sarif::spec
@@ -968,10 +997,10 @@ private:
   spec::sarifLog
   make_top_level_object (std::unique_ptr<sarif_invocation> invocation_obj,
 			 std::unique_ptr<json::array> results);
-  std::unique_ptr<sarif_run>
+  spec::run
   make_run_object (std::unique_ptr<sarif_invocation> invocation_obj,
 		   std::unique_ptr<json::array> results);
-  std::unique_ptr<sarif_tool>
+  spec::tool
   make_tool_object ();
   std::unique_ptr<sarif_tool_component>
   make_driver_tool_component_object ();
@@ -1117,7 +1146,7 @@ spec::sarifLog::to_json (sarif_builder &builder) const
   result->set_string ("version",
 		      sarif_version_to_property (builder.get_version ()));
 
-  result->set ("runs", runs->clone ()); // FIXME
+  result->set ("runs", runs.to_json (builder));
 
   // FIXME
   return result;
@@ -3480,27 +3509,25 @@ make_top_level_object (std::unique_ptr<sarif_invocation> invocation_obj,
   spec::sarifLog result;
 
   /* "runs" property (SARIF v2.1.0 section 3.13.4).  */
-  auto run_arr = std::make_unique<json::array> ();
-  auto run_obj = make_run_object (std::move (invocation_obj),
-				  std::move (results));
-  run_arr->append<sarif_run> (std::move (run_obj));
-  result.runs = std::move (run_arr);
+  spec::run run = make_run_object (std::move (invocation_obj),
+				   std::move (results));
+  result.runs.push_back (std::move (run));
 
   return result;
 }
 
 /* Make a "run" object (SARIF v2.1.0 section 3.14).  */
 
-std::unique_ptr<sarif_run>
+spec::run
 sarif_builder::
 make_run_object (std::unique_ptr<sarif_invocation> invocation_obj,
 		 std::unique_ptr<json::array> results)
 {
-  auto run_obj = std::make_unique<sarif_run> ();
-
-  /* "tool" property (SARIF v2.1.0 section 3.14.6).  */
-  run_obj->set<sarif_tool> ("tool", make_tool_object ());
+  spec::run run;
+  run.tool = make_tool_object ();
 
+  gcc_unreachable (); // FIXME
+#if 0
   /* "taxonomies" property (SARIF v2.1.0 section 3.14.8).  */
   if (auto taxonomies_arr = maybe_make_taxonomies_array ())
     run_obj->set<json::array> ("taxonomies", std::move (taxonomies_arr));
@@ -3550,17 +3577,19 @@ make_run_object (std::unique_ptr<sarif_invocation> invocation_obj,
   if (m_run_graphs->size () > 0)
     run_obj->set<json::array> ("graphs",
 			       std::move (m_run_graphs));
-
-  return run_obj;
+#endif
+  return run;
 }
 
 /* Make a "tool" object (SARIF v2.1.0 section 3.18).  */
 
-std::unique_ptr<sarif_tool>
+spec::tool
 sarif_builder::make_tool_object ()
 {
-  auto tool_obj = std::make_unique<sarif_tool> ();
+  spec::tool tool;
 
+  gcc_unreachable (); // TODO
+#if 0
   /* "driver" property (SARIF v2.1.0 section 3.18.2).  */
   tool_obj->set<sarif_tool_component> ("driver",
 				       make_driver_tool_component_object ());
@@ -3611,8 +3640,9 @@ sarif_builder::make_tool_object ()
 
   /* Perhaps we could also show GMP, MPFR, MPC, isl versions as other
      "extensions" (see toplev.cc: print_version).  */
+#endif
 
-  return tool_obj;
+  return tool;
 }
 
 /* Make a "toolComponent" object (SARIF v2.1.0 section 3.19) for what SARIF
-- 
2.49.0

