#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. */
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. */
}
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);
}
public:
void (*m_print_path) (diagnostic_context *, const diagnostic_path *);
- json::value *(*m_make_json_for_path) (diagnostic_context *,
- const diagnostic_path *);
/* Auxiliary data for client. */
void *m_client_aux_data;
#include "tree-diagnostic.h"
#include "intl.h"
#include "diagnostic-path.h"
-#include "json.h"
#include "gcc-rich-location.h"
#include "diagnostic-color.h"
#include "diagnostic-event-id.h"
}
}
-/* This has to be here, rather than diagnostic-format-json.cc,
- since diagnostic-format-json.o is within OBJS-libcommon and thus
- doesn't have access to trees (for m_fndecl). */
-
-json::value *
-default_tree_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;
-}
-
#if CHECKING_P
namespace selftest {
diagnostic_finalizer (context) = default_diagnostic_finalizer;
diagnostic_format_decoder (context) = default_tree_printer;
context->m_print_path = default_tree_diagnostic_path_printer;
- context->m_make_json_for_path = default_tree_make_json_for_path;
context->set_set_locations_callback (set_inlining_locations);
context->set_client_data_hooks (make_compiler_data_hooks ());
}
extern void default_tree_diagnostic_path_printer (diagnostic_context *,
const diagnostic_path *);
-extern json::value *default_tree_make_json_for_path (diagnostic_context *,
- const diagnostic_path *);
extern void maybe_unwind_expanded_macro_loc (diagnostic_context *context,
location_t where);