aboutsummaryrefslogtreecommitdiff
path: root/gcc/diagnostic-format-json.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/diagnostic-format-json.cc')
-rw-r--r--gcc/diagnostic-format-json.cc36
1 files changed, 23 insertions, 13 deletions
diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
index c28804e..fb54897 100644
--- a/gcc/diagnostic-format-json.cc
+++ b/gcc/diagnostic-format-json.cc
@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see
#include "diagnostic-buffer.h"
#include "json.h"
#include "selftest.h"
+#include "diagnostic-client-data-hooks.h"
#include "logical-location.h"
class json_output_format;
@@ -272,11 +273,13 @@ make_json_for_path (diagnostic_context &context,
auto pp = ref_pp->clone ();
event.print_desc (*pp.get ());
event_obj->set_string ("description", pp_formatted_text (pp.get ()));
- if (const logical_location *logical_loc = event.get_logical_location ())
- {
- label_text name (logical_loc->get_name_for_path_output ());
- event_obj->set_string ("function", name.get ());
- }
+ if (logical_location logical_loc = event.get_logical_location ())
+ if (auto hooks = context.get_client_data_hooks ())
+ if (auto mgr = hooks->get_logical_location_manager ())
+ {
+ label_text name (mgr->get_name_for_path_output (logical_loc));
+ event_obj->set_string ("function", name.get ());
+ }
event_obj->set_integer ("depth", event.get_stack_depth ());
path_array->append (std::move (event_obj));
}
@@ -502,40 +505,47 @@ private:
};
/* Populate CONTEXT in preparation for JSON output (either to stderr, or
- to a file). */
+ to a file) using FMT. Return a reference to *FMT. */
-static void
+static diagnostic_output_format &
diagnostic_output_format_init_json (diagnostic_context &context,
std::unique_ptr<json_output_format> fmt)
{
+ gcc_assert (fmt);
+ diagnostic_output_format &out = *fmt;
+
/* Don't colorize the text. */
pp_show_color (fmt->get_printer ()) = false;
context.set_show_highlight_colors (false);
context.set_output_format (std::move (fmt));
+
+ return out;
}
-/* Populate CONTEXT in preparation for JSON output to stderr. */
+/* Populate CONTEXT in preparation for JSON output to stderr.
+ Return a reference to the context's new sink. */
-void
+diagnostic_output_format &
diagnostic_output_format_init_json_stderr (diagnostic_context &context,
bool formatted)
{
- diagnostic_output_format_init_json
+ return diagnostic_output_format_init_json
(context,
std::make_unique<json_stderr_output_format> (context,
formatted));
}
/* Populate CONTEXT in preparation for JSON output to a file named
- BASE_FILE_NAME.gcc.json. */
+ BASE_FILE_NAME.gcc.json.
+ Return a reference to the context's new sink. */
-void
+diagnostic_output_format &
diagnostic_output_format_init_json_file (diagnostic_context &context,
bool formatted,
const char *base_file_name)
{
- diagnostic_output_format_init_json
+ return diagnostic_output_format_init_json
(context,
std::make_unique<json_file_output_format> (context,
formatted,