diff options
author | David Malcolm <dmalcolm@redhat.com> | 2024-06-18 10:59:55 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2024-06-18 10:59:55 -0400 |
commit | d3878c85f331c7a378245b636d5d230735b87347 (patch) | |
tree | 22686fb7a8760d2886a8a85eae4485533ecc3448 /gcc/diagnostic-format-json.cc | |
parent | 164ac58fabc6430eed45dda7500dfba64be2bd87 (diff) | |
download | gcc-d3878c85f331c7a378245b636d5d230735b87347.zip gcc-d3878c85f331c7a378245b636d5d230735b87347.tar.gz gcc-d3878c85f331c7a378245b636d5d230735b87347.tar.bz2 |
diagnostics: eliminate diagnostic_context::m_make_json_for_path
Now that the path-handling code for json_output_format no longer
needs "tree", and thus can be in OBJS-libcommon we can move it
from tree-diagnostic-path.cc to diagnostic-format-json.cc where it
should have been all along.
No functional change intended.
gcc/ChangeLog:
* diagnostic-format-json.cc: Include "diagnostic-path.h" and
"logical-location.h".
(make_json_for_path): Move tree-diagnostic-path.cc's
default_tree_make_json_for_path here, renaming it and making it
static.
(json_output_format::on_end_diagnostic): Replace call of
m_context's m_make_json_for_path callback with a direct call to
make_json_for_path.
* diagnostic.h (diagnostic_context::m_make_json_for_path): Drop
field.
* tree-diagnostic-path.cc: Drop include of "json.h".
(default_tree_make_json_for_path): Rename to make_json_for_path
and move to diagnostic-format-json.cc.
* tree-diagnostic.cc (tree_diagnostics_defaults): Drop
initialization of m_make_json_for_path.
* tree-diagnostic.h (default_tree_make_json_for): Delete decl.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/diagnostic-format-json.cc')
-rw-r--r-- | gcc/diagnostic-format-json.cc | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc index 0782ae8..2bdc2c1 100644 --- a/gcc/diagnostic-format-json.cc +++ b/gcc/diagnostic-format-json.cc @@ -25,8 +25,10 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic.h" #include "selftest-diagnostic.h" #include "diagnostic-metadata.h" +#include "diagnostic-path.h" #include "json.h" #include "selftest.h" +#include "logical-location.h" /* Subclass of diagnostic_output_format for JSON output. */ @@ -187,6 +189,36 @@ json_from_metadata (const diagnostic_metadata *metadata) return metadata_obj; } +/* Make a JSON value for PATH. */ + +static json::value * +make_json_for_path (diagnostic_context *context, + const diagnostic_path *path) +{ + json::array *path_array = new json::array (); + for (unsigned i = 0; i < path->num_events (); i++) + { + const diagnostic_event &event = path->get_event (i); + + json::object *event_obj = new json::object (); + if (event.get_location ()) + event_obj->set ("location", + json_from_expanded_location (context, + event.get_location ())); + label_text event_text (event.get_desc (false)); + event_obj->set_string ("description", event_text.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 ()); + } + event_obj->set_integer ("depth", event.get_stack_depth ()); + path_array->append (event_obj); + } + return path_array; +} + + /* Implementation of "on_end_diagnostic" vfunc for JSON output. Generate a JSON object for DIAGNOSTIC, and store for output within current diagnostic group. */ @@ -291,10 +323,9 @@ json_output_format::on_end_diagnostic (const diagnostic_info &diagnostic, } const diagnostic_path *path = richloc->get_path (); - if (path && m_context.m_make_json_for_path) + if (path) { - json::value *path_value - = m_context.m_make_json_for_path (&m_context, path); + json::value *path_value = make_json_for_path (&m_context, path); diag_obj->set ("path", path_value); } |