From: David Malcolm Date: Fri, 25 Jul 2025 19:13:37 +0000 (-0400) Subject: diagnostics: move/rename output formats to diagnostics as "sinks" X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ac3308484c78a7c4fa2a798df587a8bd507f030;p=thirdparty%2Fgcc.git diagnostics: move/rename output formats to diagnostics as "sinks" Within gcc/ move diagnostic-buffer.h to diagnostics/buffering.h move diagnostic-format-html.cc to diagnostics/html-sink.cc move diagnostic-format-html.h to diagnostics/html-sink.h move diagnostic-format-sarif.cc to diagnostics/sarif-sink.cc move diagnostic-format-sarif.h to diagnostics/sarif-sink.h move diagnostic-format.h to diagnostics/sink.h move diagnostic-format-text.cc to diagnostics/text-sink.cc move diagnostic-format-text.h to diagnostics/text-sink.h renaming various types including: Old name: New name: diagnostic_output_format diagnostics::sink diagnostic_buffer diagnostics::buffer diagnostic_per_format_buffer diagnostics::per_sink_buffer diagnostic_text_output_format diagnostics::text_sink sarif_output_format diagnostics::sarif_sink diagnostic_sarif_format_buffer diagnostics::sarif_sink_buffer html_output_format diagnostics::html_sink diagnostic_html_format_buffer diagnostics::html_sink_buffer No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS): Replace diagnostic-format-html.o with diagnostics/html-sink.o, diagnostic-format-sarif.o with diagnostics/sarif-sink.o, and diagnostic-format-text.o with diagnostics/text-sink.o. * coretypes.h (class diagnostic_text_output_format): Replace with... (class diagnostics::text_sink): ...this. * diagnostic-global-context.cc: Update for move of diagnostics output formats into namespace "diagnostics", as "sinks". * diagnostic-macro-unwinding.cc: Likewise. * diagnostic-macro-unwinding.h: Likewise. * diagnostic-show-locus.cc: Likewise. * diagnostic.cc: Likewise. * diagnostic.h: Likewise. * diagnostic-buffer.h: Rename to... * diagnostics/buffering.h: ...this, updating for above changes. * diagnostics/client-data-hooks.h: Likewise. * diagnostics/digraphs.cc: Likewise. * diagnostic-format-html.cc: Rename to... * diagnostics/html-sink.cc: ...this, updating for above changes. * diagnostic-format-html.h: Rename to... * diagnostics/html-sink.h: ...this, updating for above changes. * diagnostics/lazy-paths.cc: Likewise. * diagnostics/metadata.h: Likewise. * diagnostics/output-spec.cc: Likewise. * diagnostics/output-spec.h: Likewise. * diagnostics/paths-output.cc: Likewise. * diagnostics/paths.h: Likewise. * diagnostic-format-sarif.cc: Rename to... * diagnostics/sarif-sink.cc: ...this, updating for above changes. * diagnostic-format-sarif.h: Rename to... * diagnostics/sarif-sink.h: ...this, updating for above changes. * diagnostic-format.h: Rename to... * diagnostics/sink.h: ...this, updating for above changes. * diagnostics/state-graphs-to-dot.cc: Likewise. * diagnostic-format-text.cc: Rename to... * diagnostics/text-sink.cc: ...this, updating for above changes. * diagnostic-format-text.h: Rename to... * diagnostics/text-sink.h: ...this, updating for above changes. * gcc.cc: Likewise. * langhooks-def.h: Likewise. * langhooks.cc: Likewise. * langhooks.h: Likewise. * libgdiagnostics.cc: Likewise. * opts-diagnostic.cc: Likewise. * opts.cc: Likewise. * selftest-diagnostic.cc: Likewise. * selftest-run-tests.cc: Likewise. * selftest.h: Likewise. * tree-diagnostic-client-data-hooks.cc: Likewise. * tree-diagnostic.cc: Likewise. gcc/analyzer/ChangeLog: * ana-state-to-diagnostic-state.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". * bounds-checking.cc: Likewise. * call-details.cc: Likewise. * checker-event.cc: Likewise. * checker-event.h: Likewise. * diagnostic-manager.cc: Likewise. * diagnostic-manager.h: Likewise. * infinite-loop.cc: Likewise. * infinite-recursion.cc: Likewise. * pending-diagnostic.h: Likewise. * region-model.cc: Likewise. * sm-taint.cc: Likewise. gcc/c-family/ChangeLog: * c-opts.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". gcc/cp/ChangeLog: * cp-tree.h: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". * error.cc: Likewise. gcc/fortran/ChangeLog: * error.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". * gfortran.h: Likewise. gcc/jit/ChangeLog: * dummy-frontend.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". gcc/rust/ChangeLog: * resolve/rust-ice-finalizer.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". * resolve/rust-ice-finalizer.h: Likewise. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_group_plugin.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: Likewise. * gcc.dg/plugin/location_overflow_plugin.cc: Likewise. libcc1/ChangeLog: * context.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". Signed-off-by: David Malcolm --- diff --git a/gcc/Makefile.in b/gcc/Makefile.in index d501e235cb7f..f475a2e7dde6 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1853,15 +1853,15 @@ OBJS = \ # Objects in libcommon.a, potentially used by all host binaries and with # no target dependencies. OBJS-libcommon = diagnostic-spec.o diagnostic.o diagnostic-color.o \ - diagnostic-format-html.o \ - diagnostic-format-sarif.o \ - diagnostic-format-text.o \ diagnostic-global-context.o \ diagnostic-macro-unwinding.o \ diagnostic-show-locus.o \ diagnostics/digraphs.o \ diagnostics/edit-context.o \ diagnostics/output-spec.o \ + diagnostics/html-sink.o \ + diagnostics/sarif-sink.o \ + diagnostics/text-sink.o \ diagnostics/paths.o \ diagnostics/paths-output.o \ diagnostics/state-graphs.o \ diff --git a/gcc/analyzer/ana-state-to-diagnostic-state.cc b/gcc/analyzer/ana-state-to-diagnostic-state.cc index 2604e09883d5..996538c37852 100644 --- a/gcc/analyzer/ana-state-to-diagnostic-state.cc +++ b/gcc/analyzer/ana-state-to-diagnostic-state.cc @@ -24,7 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/common.h" #include "diagnostics/state-graphs.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/sarif-sink.h" #include "analyzer/region-model.h" #include "analyzer/program-state.h" diff --git a/gcc/analyzer/bounds-checking.cc b/gcc/analyzer/bounds-checking.cc index ca53607c4046..921ad16307e9 100644 --- a/gcc/analyzer/bounds-checking.cc +++ b/gcc/analyzer/bounds-checking.cc @@ -21,7 +21,7 @@ along with GCC; see the file COPYING3. If not see #include "intl.h" #include "diagnostics/diagram.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/sarif-sink.h" #include "analyzer/analyzer-logging.h" #include "analyzer/region-model.h" @@ -101,10 +101,11 @@ public: *this)); } - void maybe_add_sarif_properties (sarif_object &result_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const override { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/out_of_bounds/" props.set_string (PROPERTY_PREFIX "dir", get_dir () == access_direction::read ? "read" : "write"); @@ -228,11 +229,11 @@ public: && m_out_of_bounds_bits == other.m_out_of_bounds_bits); } - void maybe_add_sarif_properties (sarif_object &result_obj) + void maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const override { out_of_bounds::maybe_add_sarif_properties (result_obj); - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/concrete_out_of_bounds/" props.set (PROPERTY_PREFIX "out_of_bounds_bits", m_out_of_bounds_bits.to_json ()); @@ -294,11 +295,11 @@ public: *this)); } - void maybe_add_sarif_properties (sarif_object &result_obj) + void maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const final override { concrete_out_of_bounds::maybe_add_sarif_properties (result_obj); - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/concrete_past_the_end/" props.set (PROPERTY_PREFIX "bit_bound", tree_to_json (m_bit_bound)); @@ -966,11 +967,12 @@ public: && pending_diagnostic::same_tree_p (m_capacity, other.m_capacity)); } - void maybe_add_sarif_properties (sarif_object &result_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const final override { out_of_bounds::maybe_add_sarif_properties (result_obj); - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/symbolic_past_the_end/" props.set (PROPERTY_PREFIX "offset", tree_to_json (m_offset)); props.set (PROPERTY_PREFIX "num_bytes", tree_to_json (m_num_bytes)); diff --git a/gcc/analyzer/call-details.cc b/gcc/analyzer/call-details.cc index cb958436b334..ede1229a41d9 100644 --- a/gcc/analyzer/call-details.cc +++ b/gcc/analyzer/call-details.cc @@ -25,7 +25,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-pretty-print.h" #include "stringpool.h" #include "attribs.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/sarif-sink.h" #include "analyzer/analyzer-logging.h" #include "analyzer/region-model.h" @@ -528,10 +528,10 @@ public: return true; } - void maybe_add_sarif_properties (sarif_object &result_obj) + void maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const final override { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/overlapping_buffers/" props.set (PROPERTY_PREFIX "bytes_range_a", m_byte_range_a.to_json ()); diff --git a/gcc/analyzer/checker-event.cc b/gcc/analyzer/checker-event.cc index e0af97fca048..4eac9450469f 100644 --- a/gcc/analyzer/checker-event.cc +++ b/gcc/analyzer/checker-event.cc @@ -27,7 +27,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-iterator.h" #include "inlining-iterator.h" #include "tree-logical-location.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/sarif-sink.h" #include "diagnostics/state-graphs.h" #include "analyzer/analyzer-logging.h" @@ -145,10 +145,10 @@ checker_event::get_meaning () const void checker_event:: -maybe_add_sarif_properties (sarif_builder &builder, - sarif_object &thread_flow_loc_obj) const +maybe_add_sarif_properties (diagnostics::sarif_builder &builder, + diagnostics::sarif_object &thread_flow_loc_obj) const { - sarif_property_bag &props = thread_flow_loc_obj.get_or_create_properties (); + auto &props = thread_flow_loc_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/checker_event/" props.set (PROPERTY_PREFIX "emission_id", diagnostic_event_id_to_json (m_emission_id)); @@ -534,12 +534,13 @@ state_change_event::get_meaning () const for superedge_event. */ void -superedge_event::maybe_add_sarif_properties (sarif_builder &builder, - sarif_object &thread_flow_loc_obj) +superedge_event:: +maybe_add_sarif_properties (diagnostics::sarif_builder &builder, + diagnostics::sarif_object &thread_flow_loc_obj) const { checker_event::maybe_add_sarif_properties (builder, thread_flow_loc_obj); - sarif_property_bag &props = thread_flow_loc_obj.get_or_create_properties (); + auto &props = thread_flow_loc_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/superedge_event/" if (m_sedge) props.set (PROPERTY_PREFIX "superedge", m_sedge->to_json ()); diff --git a/gcc/analyzer/checker-event.h b/gcc/analyzer/checker-event.h index 41d8dee76dbc..909e3889e28a 100644 --- a/gcc/analyzer/checker-event.h +++ b/gcc/analyzer/checker-event.h @@ -114,8 +114,9 @@ public: } void - maybe_add_sarif_properties (sarif_builder &, - sarif_object &thread_flow_loc_obj) const override; + maybe_add_sarif_properties (diagnostics::sarif_builder &, + diagnostics::sarif_object &thread_flow_loc_obj) + const override; /* Additional functionality. */ enum event_kind get_kind () const { return m_kind; } @@ -423,8 +424,9 @@ public: class superedge_event : public checker_event { public: - void maybe_add_sarif_properties (sarif_builder &, - sarif_object &thread_flow_loc_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_builder &, + diagnostics::sarif_object &thread_flow_loc_obj) const override; /* Mark this edge event as being either an interprocedural call or diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index 220a30b78ee0..88f72d17b03b 100644 --- a/gcc/analyzer/diagnostic-manager.cc +++ b/gcc/analyzer/diagnostic-manager.cc @@ -29,7 +29,7 @@ along with GCC; see the file COPYING3. If not see #include "cgraph.h" #include "digraph.h" #include "gcc-rich-location.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/sarif-sink.h" #include "analyzer/analyzer-logging.h" #include "analyzer/sm.h" @@ -1017,9 +1017,10 @@ saved_diagnostic::emit_any_notes () const This extra data is intended for use when debugging the analyzer. */ void -saved_diagnostic::maybe_add_sarif_properties (sarif_object &result_obj) const +saved_diagnostic:: +maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/saved_diagnostic/" if (m_sm) props.set_string (PROPERTY_PREFIX "sm", m_sm->get_name ()); @@ -1044,7 +1045,7 @@ saved_diagnostic::maybe_add_sarif_properties (sarif_object &result_obj) const auto duplicates_arr = std::make_unique (); for (auto iter : m_duplicates) { - auto sd_obj = std::make_unique (); + auto sd_obj = std::make_unique (); iter->maybe_add_sarif_properties (*sd_obj); duplicates_arr->append (std::move (sd_obj)); } @@ -1555,7 +1556,8 @@ public: } void - maybe_add_sarif_properties (sarif_object &result_obj) const override + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) + const override { m_sd.maybe_add_sarif_properties (result_obj); } diff --git a/gcc/analyzer/diagnostic-manager.h b/gcc/analyzer/diagnostic-manager.h index 440a184f55b6..d9cf109080f7 100644 --- a/gcc/analyzer/diagnostic-manager.h +++ b/gcc/analyzer/diagnostic-manager.h @@ -67,7 +67,8 @@ public: void emit_any_notes () const; - void maybe_add_sarif_properties (sarif_object &result_obj) const; + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const; //private: const state_machine *m_sm; diff --git a/gcc/analyzer/infinite-loop.cc b/gcc/analyzer/infinite-loop.cc index ec0b07947bf4..a53807c2ddb6 100644 --- a/gcc/analyzer/infinite-loop.cc +++ b/gcc/analyzer/infinite-loop.cc @@ -25,7 +25,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-pretty-print.h" #include "cgraph.h" #include "digraph.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/sarif-sink.h" #include "analyzer/analyzer-logging.h" #include "analyzer/call-string.h" @@ -307,10 +307,11 @@ public: } } - void maybe_add_sarif_properties (sarif_object &result_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const final override { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/infinite_loop_diagnostic/" props.set (PROPERTY_PREFIX "inf_loop", m_inf_loop->to_json ()); #undef PROPERTY_PREFIX diff --git a/gcc/analyzer/infinite-recursion.cc b/gcc/analyzer/infinite-recursion.cc index b80b94a0c5b7..960b4872ee60 100644 --- a/gcc/analyzer/infinite-recursion.cc +++ b/gcc/analyzer/infinite-recursion.cc @@ -25,6 +25,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-pretty-print.h" #include "cgraph.h" #include "digraph.h" +#include "diagnostics/sarif-sink.h" #include "analyzer/analyzer-logging.h" #include "analyzer/call-string.h" @@ -40,7 +41,6 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/exploded-graph.h" #include "analyzer/checker-path.h" #include "analyzer/feasible-graph.h" -#include "diagnostic-format-sarif.h" /* A subclass of pending_diagnostic for complaining about suspected infinite recursion. */ @@ -223,10 +223,11 @@ public: return false; } - void maybe_add_sarif_properties (sarif_object &result_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const final override { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/infinite_recursion_diagnostic/" props.set_integer (PROPERTY_PREFIX "prev_entry_enode", m_prev_entry_enode->m_index); diff --git a/gcc/analyzer/pending-diagnostic.h b/gcc/analyzer/pending-diagnostic.h index d911f562db67..b5d90a22ae1f 100644 --- a/gcc/analyzer/pending-diagnostic.h +++ b/gcc/analyzer/pending-diagnostic.h @@ -401,7 +401,8 @@ class pending_diagnostic the opportunity to add diagnostic-specific properties to the SARIF "result" object for the diagnostic. This is intended for use when debugging a diagnostic. */ - virtual void maybe_add_sarif_properties (sarif_object &/*result_obj*/) const + virtual void + maybe_add_sarif_properties (diagnostics::sarif_object &/*result_obj*/) const { /* Default no-op implementation. */ } diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 412f1c4a5523..618d96b6b7c1 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -40,7 +40,7 @@ along with GCC; see the file COPYING3. If not see #include "is-a.h" #include "gcc-rich-location.h" #include "gcc-urlifier.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/sarif-sink.h" #include "tree-pretty-print.h" #include "fold-const.h" #include "selftest-tree.h" @@ -907,9 +907,10 @@ public: } void - maybe_add_sarif_properties (sarif_object &result_obj) const final override + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) + const final override { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/poisoned_value_diagnostic/" props.set (PROPERTY_PREFIX "expr", tree_to_json (m_expr)); props.set_string (PROPERTY_PREFIX "kind", poison_kind_to_str (m_pkind)); @@ -3835,10 +3836,11 @@ public: interest->add_region_creation (m_rhs); } - void maybe_add_sarif_properties (sarif_object &result_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const final override { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/dubious_allocation_size/" props.set (PROPERTY_PREFIX "lhs", m_lhs->to_json ()); props.set (PROPERTY_PREFIX "rhs", m_rhs->to_json ()); @@ -7595,9 +7597,10 @@ public: } void - maybe_add_sarif_properties (sarif_object &result_obj) const final override + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) + const final override { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/-Wanalyzer-exposure-through-uninit-copy/" props.set (PROPERTY_PREFIX "src_region", m_src_region->to_json ()); props.set (PROPERTY_PREFIX "dest_region", m_dest_region->to_json ()); diff --git a/gcc/analyzer/sm-taint.cc b/gcc/analyzer/sm-taint.cc index af937f876185..f2a94e8a4f61 100644 --- a/gcc/analyzer/sm-taint.cc +++ b/gcc/analyzer/sm-taint.cc @@ -30,7 +30,7 @@ along with GCC; see the file COPYING3. If not see #include "stringpool.h" #include "attribs.h" #include "fold-const.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/sarif-sink.h" #include "gcc-urlifier.h" #include "analyzer/analyzer-logging.h" @@ -220,10 +220,11 @@ public: return event::meaning (); } - void maybe_add_sarif_properties (sarif_object &result_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const override { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/taint_diagnostic/" props.set (PROPERTY_PREFIX "arg", tree_to_json (m_arg)); props.set_string (PROPERTY_PREFIX "has_bounds", @@ -496,11 +497,12 @@ public: } } - void maybe_add_sarif_properties (sarif_object &result_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const final override { taint_diagnostic::maybe_add_sarif_properties (result_obj); - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/tainted_offset/" props.set (PROPERTY_PREFIX "offset", m_offset->to_json ()); #undef PROPERTY_PREFIX @@ -865,11 +867,12 @@ public: } } - void maybe_add_sarif_properties (sarif_object &result_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const final override { taint_diagnostic::maybe_add_sarif_properties (result_obj); - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/tainted_allocation_size/" props.set (PROPERTY_PREFIX "size_in_bytes", m_size_in_bytes->to_json ()); #undef PROPERTY_PREFIX diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index 795f5a355af6..a211992e1b54 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -43,7 +43,7 @@ along with GCC; see the file COPYING3. If not see #include "dumpfile.h" #include "file-prefix-map.h" /* add_*_prefix_map() */ #include "context.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" #ifndef DOLLARS_IN_IDENTIFIERS # define DOLLARS_IN_IDENTIFIERS true @@ -169,7 +169,7 @@ c_common_option_lang_mask (void) /* Diagnostic finalizer for C/C++/Objective-C/Objective-C++. */ static void -c_diagnostic_text_finalizer (diagnostic_text_output_format &text_output, +c_diagnostic_text_finalizer (diagnostics::text_sink &text_output, const diagnostic_info *diagnostic, diagnostic_t) { diff --git a/gcc/coretypes.h b/gcc/coretypes.h index a11ebd1509b5..169a612f643b 100644 --- a/gcc/coretypes.h +++ b/gcc/coretypes.h @@ -165,7 +165,7 @@ struct cl_decoded_option; struct cl_option_handlers; class rich_location; class diagnostic_context; -class diagnostic_text_output_format; +namespace diagnostics { class text_sink; } class pretty_printer; class diagnostic_event_id_t; typedef const char * (*diagnostic_input_charset_callback)(const char *); diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 01112aa894e0..6315a10a859d 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -8463,7 +8463,7 @@ extern void cxx_print_xnode (FILE *, tree, int); extern void cxx_print_decl (FILE *, tree, int); extern void cxx_print_type (FILE *, tree, int); extern void cxx_print_identifier (FILE *, tree, int); -extern void cxx_print_error_function (diagnostic_text_output_format &, +extern void cxx_print_error_function (diagnostics::text_sink &, const char *, const diagnostic_info *); diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc index 177f28fa1650..a93a77026faa 100644 --- a/gcc/cp/error.cc +++ b/gcc/cp/error.cc @@ -38,7 +38,7 @@ along with GCC; see the file COPYING3. If not see #include "cp-name-hint.h" #include "attribs.h" #include "pretty-print-format-impl.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" #define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',') #define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';') @@ -96,16 +96,16 @@ static void dump_scope (cxx_pretty_printer *, tree, int); static void dump_template_parms (cxx_pretty_printer *, tree, int, int); static int get_non_default_template_args_count (tree, int); static const char *function_category (tree); -static void maybe_print_constexpr_context (diagnostic_text_output_format &); -static void maybe_print_instantiation_context (diagnostic_text_output_format &); -static void print_instantiation_full_context (diagnostic_text_output_format &); -static void print_instantiation_partial_context (diagnostic_text_output_format &, +static void maybe_print_constexpr_context (diagnostics::text_sink &); +static void maybe_print_instantiation_context (diagnostics::text_sink &); +static void print_instantiation_full_context (diagnostics::text_sink &); +static void print_instantiation_partial_context (diagnostics::text_sink &, struct tinst_level *, location_t); -static void maybe_print_constraint_context (diagnostic_text_output_format &); -static void cp_diagnostic_text_starter (diagnostic_text_output_format &, +static void maybe_print_constraint_context (diagnostics::text_sink &); +static void cp_diagnostic_text_starter (diagnostics::text_sink &, const diagnostic_info *); -static void cp_print_error_function (diagnostic_text_output_format &, +static void cp_print_error_function (diagnostics::text_sink &, const diagnostic_info *); static bool cp_printer (pretty_printer *, text_info *, const char *, @@ -3761,7 +3761,7 @@ eh_spec_to_string (tree p, int /*v*/) /* Langhook for print_error_function. */ void -cxx_print_error_function (diagnostic_text_output_format &text_output, +cxx_print_error_function (diagnostics::text_sink &text_output, const char *file, const diagnostic_info *diagnostic) { @@ -3777,7 +3777,7 @@ cxx_print_error_function (diagnostic_text_output_format &text_output, } static void -cp_diagnostic_text_starter (diagnostic_text_output_format &text_output, +cp_diagnostic_text_starter (diagnostics::text_sink &text_output, const diagnostic_info *diagnostic) { pp_set_prefix (text_output.get_printer (), @@ -3794,7 +3794,7 @@ cp_diagnostic_text_starter (diagnostic_text_output_format &text_output, /* Print current function onto BUFFER, in the process of reporting a diagnostic message. Called from cp_diagnostic_starter. */ static void -cp_print_error_function (diagnostic_text_output_format &text_output, +cp_print_error_function (diagnostics::text_sink &text_output, const diagnostic_info *diagnostic) { /* If we are in an instantiation context, current_function_decl is likely @@ -3942,7 +3942,7 @@ function_category (tree fn) /* Report the full context of a current template instantiation, onto BUFFER. */ static void -print_instantiation_full_context (diagnostic_text_output_format &text_output) +print_instantiation_full_context (diagnostics::text_sink &text_output) { struct tinst_level *p = current_instantiation (); location_t location = input_location; @@ -3970,7 +3970,7 @@ print_instantiation_full_context (diagnostic_text_output_format &text_output) } static void -print_location (diagnostic_text_output_format &text_output, +print_location (diagnostics::text_sink &text_output, location_t loc) { expanded_location xloc = expand_location (loc); @@ -3984,7 +3984,7 @@ print_location (diagnostic_text_output_format &text_output, } /* A RAII class for use when emitting a line of contextual information - via pp_verbatim to a diagnostic_text_output_format to add before/after + via pp_verbatim to a diagnostics::text_sink to add before/after behaviors to the pp_verbatim calls. If the text output has show_nesting_p (), then the ctor prints @@ -3999,7 +3999,7 @@ print_location (diagnostic_text_output_format &text_output, class auto_context_line { public: - auto_context_line (diagnostic_text_output_format &text_output, + auto_context_line (diagnostics::text_sink &text_output, location_t loc, bool show_locus = false) : m_text_output (text_output), @@ -4047,7 +4047,7 @@ public: } } private: - diagnostic_text_output_format &m_text_output; + diagnostics::text_sink &m_text_output; location_t m_loc; bool m_show_locus; }; @@ -4056,7 +4056,7 @@ private: prints a single line of instantiation context. */ static void -print_instantiation_partial_context_line (diagnostic_text_output_format &text_output, +print_instantiation_partial_context_line (diagnostics::text_sink &text_output, struct tinst_level *t, location_t loc, bool recursive_p) { @@ -4094,7 +4094,7 @@ print_instantiation_partial_context_line (diagnostic_text_output_format &text_ou /* Same as print_instantiation_full_context but less verbose. */ static void -print_instantiation_partial_context (diagnostic_text_output_format &text_output, +print_instantiation_partial_context (diagnostics::text_sink &text_output, struct tinst_level *t0, location_t loc) { struct tinst_level *t; @@ -4165,7 +4165,7 @@ print_instantiation_partial_context (diagnostic_text_output_format &text_output, /* Called from cp_thing to print the template context for an error. */ static void -maybe_print_instantiation_context (diagnostic_text_output_format &text_output) +maybe_print_instantiation_context (diagnostics::text_sink &text_output) { if (!problematic_instantiation_changed () || current_instantiation () == 0) return; @@ -4177,7 +4177,7 @@ maybe_print_instantiation_context (diagnostic_text_output_format &text_output) /* Report what constexpr call(s) we're trying to expand, if any. */ void -maybe_print_constexpr_context (diagnostic_text_output_format &text_output) +maybe_print_constexpr_context (diagnostics::text_sink &text_output) { vec call_stack = cx_error_context (); unsigned ix; @@ -4197,7 +4197,7 @@ maybe_print_constexpr_context (diagnostic_text_output_format &text_output) static void -print_constrained_decl_info (diagnostic_text_output_format &text_output, +print_constrained_decl_info (diagnostics::text_sink &text_output, tree decl) { auto_context_line sentinel (text_output, DECL_SOURCE_LOCATION (decl)); @@ -4206,7 +4206,7 @@ print_constrained_decl_info (diagnostic_text_output_format &text_output, } static void -print_concept_check_info (diagnostic_text_output_format &text_output, +print_concept_check_info (diagnostics::text_sink &text_output, tree expr, tree map, tree args) { gcc_assert (concept_check_p (expr)); @@ -4231,7 +4231,7 @@ print_concept_check_info (diagnostic_text_output_format &text_output, context, if any. */ static tree -print_constraint_context_head (diagnostic_text_output_format &text_output, +print_constraint_context_head (diagnostics::text_sink &text_output, tree cxt, tree args) { tree src = TREE_VALUE (cxt); @@ -4255,7 +4255,7 @@ print_constraint_context_head (diagnostic_text_output_format &text_output, } static void -print_requires_expression_info (diagnostic_text_output_format &text_output, +print_requires_expression_info (diagnostics::text_sink &text_output, tree constr, tree args) { @@ -4285,7 +4285,7 @@ print_requires_expression_info (diagnostic_text_output_format &text_output, } void -maybe_print_single_constraint_context (diagnostic_text_output_format &text_output, +maybe_print_single_constraint_context (diagnostics::text_sink &text_output, tree failed) { if (!failed) @@ -4316,7 +4316,7 @@ maybe_print_single_constraint_context (diagnostic_text_output_format &text_outpu } void -maybe_print_constraint_context (diagnostic_text_output_format &text_output) +maybe_print_constraint_context (diagnostics::text_sink &text_output) { if (!current_failed_constraint) return; diff --git a/gcc/diagnostic-global-context.cc b/gcc/diagnostic-global-context.cc index 5eba3aa894aa..ff647c244a50 100644 --- a/gcc/diagnostic-global-context.cc +++ b/gcc/diagnostic-global-context.cc @@ -27,7 +27,7 @@ along with GCC; see the file COPYING3. If not see #include "coretypes.h" #include "intl.h" #include "diagnostic.h" -#include "diagnostic-format.h" +#include "diagnostics/sink.h" /* A diagnostic_context surrogate for stderr. */ static diagnostic_context global_diagnostic_context; diff --git a/gcc/diagnostic-macro-unwinding.cc b/gcc/diagnostic-macro-unwinding.cc index aa1b81645b6b..765060684041 100644 --- a/gcc/diagnostic-macro-unwinding.cc +++ b/gcc/diagnostic-macro-unwinding.cc @@ -23,7 +23,7 @@ along with GCC; see the file COPYING3. If not see #include "tree.h" #include "diagnostic.h" #include "diagnostic-macro-unwinding.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" #include "intl.h" /* This is a pair made of a location and the line map it originated @@ -73,7 +73,7 @@ struct loc_map_pair function. */ void -maybe_unwind_expanded_macro_loc (diagnostic_text_output_format &text_output, +maybe_unwind_expanded_macro_loc (diagnostics::text_sink &text_output, location_t where) { const struct line_map *map; @@ -215,7 +215,7 @@ maybe_unwind_expanded_macro_loc (diagnostic_text_output_format &text_output, that is similar to what is done for function call stacks, or template instantiation contexts. */ void -virt_loc_aware_diagnostic_finalizer (diagnostic_text_output_format &text_output, +virt_loc_aware_diagnostic_finalizer (diagnostics::text_sink &text_output, const diagnostic_info *diagnostic) { maybe_unwind_expanded_macro_loc (text_output, diagnostic_location (diagnostic)); diff --git a/gcc/diagnostic-macro-unwinding.h b/gcc/diagnostic-macro-unwinding.h index ef1e55daff5a..b2173bcee256 100644 --- a/gcc/diagnostic-macro-unwinding.h +++ b/gcc/diagnostic-macro-unwinding.h @@ -20,10 +20,10 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_DIAGNOSTIC_MACRO_UNWINDING_H #define GCC_DIAGNOSTIC_MACRO_UNWINDING_H -void virt_loc_aware_diagnostic_finalizer (diagnostic_text_output_format &, +void virt_loc_aware_diagnostic_finalizer (diagnostics::text_sink &, const diagnostic_info *); -extern void maybe_unwind_expanded_macro_loc (diagnostic_text_output_format &, +extern void maybe_unwind_expanded_macro_loc (diagnostics::text_sink &, location_t where); #endif /* ! GCC_DIAGNOSTIC_MACRO_UNWINDING_H */ diff --git a/gcc/diagnostic-show-locus.cc b/gcc/diagnostic-show-locus.cc index 492d94f13c5d..a688d9e4bb68 100644 --- a/gcc/diagnostic-show-locus.cc +++ b/gcc/diagnostic-show-locus.cc @@ -716,9 +716,9 @@ get_printer (to_text &sink) template<> void -default_diagnostic_start_span_fn (const diagnostic_location_print_policy &loc_policy, - to_text &sink, - expanded_location exploc) +diagnostics::default_start_span_fn (const diagnostic_location_print_policy &loc_policy, + to_text &sink, + expanded_location exploc) { const diagnostic_column_policy &column_policy = loc_policy.get_column_policy (); @@ -732,9 +732,9 @@ default_diagnostic_start_span_fn (const diagnostic_location_print_polic template<> void -default_diagnostic_start_span_fn (const diagnostic_location_print_policy &loc_policy, - to_html &sink, - expanded_location exploc) +diagnostics::default_start_span_fn (const diagnostic_location_print_policy &loc_policy, + to_html &sink, + expanded_location exploc) { const diagnostic_column_policy &column_policy = loc_policy.get_column_policy (); diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index b5858b218eda..b5ef93e70bc4 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -37,9 +37,9 @@ along with GCC; see the file COPYING3. If not see #include "diagnostics/paths.h" #include "diagnostics/client-data-hooks.h" #include "diagnostics/diagram.h" -#include "diagnostic-format.h" -#include "diagnostic-format-sarif.h" -#include "diagnostic-format-text.h" +#include "diagnostics/sink.h" +#include "diagnostics/sarif-sink.h" +#include "diagnostics/text-sink.h" #include "diagnostics/edit-context.h" #include "selftest.h" #include "selftest-diagnostic.h" @@ -48,7 +48,7 @@ along with GCC; see the file COPYING3. If not see #include "text-art/theme.h" #include "pretty-print-urlifier.h" #include "diagnostics/logical-locations.h" -#include "diagnostic-buffer.h" +#include "diagnostics/buffering.h" #ifdef HAVE_TERMIOS_H # include @@ -249,12 +249,12 @@ diagnostic_context::initialize (int n_opts) m_max_errors = 0; m_internal_error = nullptr; m_adjust_diagnostic_info = nullptr; - m_text_callbacks.m_begin_diagnostic = default_diagnostic_text_starter; + m_text_callbacks.m_begin_diagnostic = diagnostics::default_text_starter; m_text_callbacks.m_text_start_span - = default_diagnostic_start_span_fn; + = diagnostics::default_start_span_fn; m_text_callbacks.m_html_start_span - = default_diagnostic_start_span_fn; - m_text_callbacks.m_end_diagnostic = default_diagnostic_text_finalizer; + = diagnostics::default_start_span_fn; + m_text_callbacks.m_end_diagnostic = diagnostics::default_text_finalizer; m_option_mgr = nullptr; m_urlifier_stack = new auto_vec (); m_last_location = UNKNOWN_LOCATION; @@ -286,8 +286,7 @@ diagnostic_context::initialize (int n_opts) m_diagnostic_groups.m_diagnostic_nesting_level = 0; m_diagnostic_groups.m_emission_count = 0; m_diagnostic_groups.m_inhibiting_notes_from = 0; - m_output_sinks.safe_push - (new diagnostic_text_output_format (*this, nullptr, true)); + m_sinks.safe_push (new diagnostics::text_sink (*this, nullptr, true)); m_set_locations_cb = nullptr; m_client_data_hooks = nullptr; m_diagrams.m_theme = nullptr; @@ -332,9 +331,9 @@ diagnostic_context::color_init (int value) } pp_show_color (m_reference_printer) = colorize_init ((diagnostic_color_rule_t) value); - for (auto sink : m_output_sinks) - if (sink->follows_reference_printer_p ()) - pp_show_color (sink->get_printer ()) + for (auto sink_ : m_sinks) + if (sink_->follows_reference_printer_p ()) + pp_show_color (sink_->get_printer ()) = pp_show_color (m_reference_printer); } @@ -364,9 +363,9 @@ diagnostic_context::urls_init (int value) m_reference_printer->set_url_format (determine_url_format ((diagnostic_url_rule_t) value)); - for (auto sink : m_output_sinks) - if (sink->follows_reference_printer_p ()) - sink->get_printer ()->set_url_format + for (auto sink_ : m_sinks) + if (sink_->follows_reference_printer_p ()) + sink_->get_printer ()->set_url_format (m_reference_printer->get_url_format ()); } @@ -395,8 +394,8 @@ diagnostic_context::finish () /* Clean ups. */ - while (!m_output_sinks.is_empty ()) - delete m_output_sinks.pop (); + while (!m_sinks.is_empty ()) + delete m_sinks.pop (); if (m_diagrams.m_theme) { @@ -449,12 +448,12 @@ diagnostic_context::dump (FILE *out) const fprintf (out, " reference printer:\n"); m_reference_printer->dump (out, 4); fprintf (out, " output sinks:\n"); - if (m_output_sinks.length () > 0) + if (m_sinks.length () > 0) { - for (unsigned i = 0; i < m_output_sinks.length (); ++i) + for (unsigned i = 0; i < m_sinks.length (); ++i) { fprintf (out, " sink %i:\n", i); - m_output_sinks[i]->dump (out, 4); + m_sinks[i]->dump (out, 4); } } else @@ -487,30 +486,29 @@ diagnostic_context::execution_failed_p () const void diagnostic_context::remove_all_output_sinks () { - while (!m_output_sinks.is_empty ()) - delete m_output_sinks.pop (); + while (!m_sinks.is_empty ()) + delete m_sinks.pop (); } void -diagnostic_context:: -set_output_format (std::unique_ptr output_format) +diagnostic_context::set_sink (std::unique_ptr sink_) { remove_all_output_sinks (); - m_output_sinks.safe_push (output_format.release ()); + m_sinks.safe_push (sink_.release ()); } -diagnostic_output_format & -diagnostic_context::get_output_format (size_t idx) const +diagnostics::sink & +diagnostic_context::get_sink (size_t idx) const { - gcc_assert (idx < m_output_sinks.length ()); - gcc_assert (m_output_sinks[idx]); - return *m_output_sinks[idx]; + gcc_assert (idx < m_sinks.length ()); + gcc_assert (m_sinks[idx]); + return *m_sinks[idx]; } void -diagnostic_context::add_sink (std::unique_ptr sink) +diagnostic_context::add_sink (std::unique_ptr sink_) { - m_output_sinks.safe_push (sink.release ()); + m_sinks.safe_push (sink_.release ()); } /* Return true if there are no machine-readable formats writing to stderr. */ @@ -518,8 +516,8 @@ diagnostic_context::add_sink (std::unique_ptr sink) bool diagnostic_context::supports_fnotice_on_stderr_p () const { - for (auto sink : m_output_sinks) - if (sink->machine_readable_stderr_p ()) + for (auto sink_ : m_sinks) + if (sink_->machine_readable_stderr_p ()) return false; return true; } @@ -527,8 +525,8 @@ diagnostic_context::supports_fnotice_on_stderr_p () const void diagnostic_context::set_main_input_filename (const char *filename) { - for (auto sink : m_output_sinks) - sink->set_main_input_filename (filename); + for (auto sink_ : m_sinks) + sink_->set_main_input_filename (filename); } void @@ -625,8 +623,8 @@ diagnostic_context::set_pretty_printer (std::unique_ptr pp) void diagnostic_context::refresh_output_sinks () { - for (auto sink : m_output_sinks) - sink->update_printer (); + for (auto sink_ : m_sinks) + sink_->update_printer (); } /* Set FORMAT_DECODER on the reference printer and on the pretty_printer @@ -636,26 +634,26 @@ void diagnostic_context::set_format_decoder (printer_fn format_decoder) { pp_format_decoder (m_reference_printer) = format_decoder; - for (auto sink : m_output_sinks) - pp_format_decoder (sink->get_printer ()) = format_decoder; + for (auto sink_ : m_sinks) + pp_format_decoder (sink_->get_printer ()) = format_decoder; } void diagnostic_context::set_show_highlight_colors (bool val) { pp_show_highlight_colors (m_reference_printer) = val; - for (auto sink : m_output_sinks) - if (sink->follows_reference_printer_p ()) - pp_show_highlight_colors (sink->get_printer ()) = val; + for (auto sink_ : m_sinks) + if (sink_->follows_reference_printer_p ()) + pp_show_highlight_colors (sink_->get_printer ()) = val; } void diagnostic_context::set_prefixing_rule (diagnostic_prefixing_rule_t rule) { pp_prefixing_rule (m_reference_printer) = rule; - for (auto sink : m_output_sinks) - if (sink->follows_reference_printer_p ()) - pp_prefixing_rule (sink->get_printer ()) = rule; + for (auto sink_ : m_sinks) + if (sink_->follows_reference_printer_p ()) + pp_prefixing_rule (sink_->get_printer ()) = rule; } void @@ -781,7 +779,7 @@ diagnostic_column_policy::get_location_text (const expanded_location &s, col = converted_column (s); } - const char *line_col = maybe_line_and_column (line, col); + const char *line_col = diagnostics::maybe_line_and_column (line, col); return label_text::take (build_message_string ("%s%s%s:%s", locus_cs, file, line_col, locus_ce)); } @@ -794,7 +792,7 @@ diagnostic_location_print_policy (const diagnostic_context &dc) } diagnostic_location_print_policy:: -diagnostic_location_print_policy (const diagnostic_text_output_format &text_output) +diagnostic_location_print_policy (const diagnostics::text_sink &text_output) : m_column_policy (text_output.get_context ()), m_show_column (text_output.get_context ().m_show_column) @@ -1538,12 +1536,12 @@ diagnostic_context::report_diagnostic (diagnostic_info *diagnostic) /* Is this the initial diagnostic within the stack of groups? */ if (m_diagnostic_groups.m_emission_count == 0) - for (auto sink : m_output_sinks) - sink->on_begin_group (); + for (auto sink_ : m_sinks) + sink_->on_begin_group (); m_diagnostic_groups.m_emission_count++; va_list *orig_args = diagnostic->message.m_args_ptr; - for (auto sink : m_output_sinks) + for (auto sink_ : m_sinks) { /* Formatting the message is done per-output-format, so that each output format gets its own set of pp_token_lists @@ -1563,12 +1561,12 @@ diagnostic_context::report_diagnostic (diagnostic_info *diagnostic) va_list copied_args; va_copy (copied_args, *orig_args); diagnostic->message.m_args_ptr = &copied_args; - pp_format (sink->get_printer (), &diagnostic->message); + pp_format (sink_->get_printer (), &diagnostic->message); va_end (copied_args); /* Call vfunc in the output format. This is responsible for phase 3 of formatting, and for printing the result. */ - sink->on_report_diagnostic (*diagnostic, orig_diag_kind); + sink_->on_report_diagnostic (*diagnostic, orig_diag_kind); } switch (m_extra_output_kind) @@ -1604,8 +1602,8 @@ diagnostic_context::report_diagnostic (diagnostic_info *diagnostic) m_lock--; if (!m_diagnostic_buffer) - for (auto sink : m_output_sinks) - sink->after_diagnostic (*diagnostic); + for (auto sink_ : m_sinks) + sink_->after_diagnostic (*diagnostic); return true; } @@ -1614,12 +1612,12 @@ void diagnostic_context::report_verbatim (text_info &text) { va_list *orig_args = text.m_args_ptr; - for (auto sink : m_output_sinks) + for (auto sink_ : m_sinks) { va_list copied_args; va_copy (copied_args, *orig_args); text.m_args_ptr = &copied_args; - sink->on_report_verbatim (text); + sink_->on_report_verbatim (text); va_end (copied_args); } } @@ -1628,8 +1626,8 @@ void diagnostic_context:: report_global_digraph (const diagnostics::digraphs::lazy_digraph &ldg) { - for (auto sink : m_output_sinks) - sink->report_global_digraph (ldg); + for (auto sink_ : m_sinks) + sink_->report_global_digraph (ldg); } /* Get the number of digits in the decimal representation of VALUE. */ @@ -1749,8 +1747,8 @@ diagnostic_context::emit_diagram (const diagnostics::diagram &diag) if (m_diagrams.m_theme == nullptr) return; - for (auto sink : m_output_sinks) - sink->on_diagram (diag); + for (auto sink_ : m_sinks) + sink_->on_diagram (diag); } /* Inform the user that an error occurred while trying to report some @@ -1835,8 +1833,8 @@ diagnostic_context::end_group () If any diagnostics were emitted, give the context a chance to do something. */ if (m_diagnostic_groups.m_emission_count > 0) - for (auto sink : m_output_sinks) - sink->on_end_group (); + for (auto sink_ : m_sinks) + sink_->on_end_group (); m_diagnostic_groups.m_emission_count = 0; } /* We're popping one level, so might need to stop inhibiting notes. */ @@ -1858,14 +1856,14 @@ diagnostic_context::pop_nesting_level () } void -diagnostic_output_format::dump (FILE *out, int indent) const +diagnostics::sink::dump (FILE *out, int indent) const { fprintf (out, "%*sprinter:\n", indent, ""); m_printer->dump (out, indent + 2); } void -diagnostic_output_format::on_report_verbatim (text_info &) +diagnostics::sink::on_report_verbatim (text_info &) { /* No-op. */ } @@ -1874,13 +1872,13 @@ diagnostic_output_format::on_report_verbatim (text_info &) file-based output formats. */ void -diagnostic_output_format_init (diagnostic_context &context, - const char *main_input_filename_, - const char *base_file_name, - enum diagnostics_output_format format, - bool json_formatting) +diagnostics::output_format_init (diagnostic_context &context, + const char *main_input_filename_, + const char *base_file_name, + enum diagnostics_output_format format, + bool json_formatting) { - diagnostic_output_format *new_sink = nullptr; + diagnostics::sink *new_sink = nullptr; switch (format) { default: @@ -1890,16 +1888,16 @@ diagnostic_output_format_init (diagnostic_context &context, break; case DIAGNOSTICS_OUTPUT_FORMAT_SARIF_STDERR: - new_sink = &diagnostic_output_format_init_sarif_stderr (context, - line_table, - json_formatting); + new_sink = &diagnostics::init_sarif_stderr (context, + line_table, + json_formatting); break; case DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE: - new_sink = &diagnostic_output_format_init_sarif_file (context, - line_table, - json_formatting, - base_file_name); + new_sink = &diagnostics::init_sarif_file (context, + line_table, + json_formatting, + base_file_name); break; } if (new_sink) @@ -1945,7 +1943,7 @@ set_text_art_charset (enum diagnostic_text_art_charset charset) to this function. */ void -diagnostic_context::set_diagnostic_buffer (diagnostic_buffer *buffer) +diagnostic_context::set_diagnostic_buffer (diagnostics::buffer *buffer_) { /* We don't allow changing buffering within a diagnostic group (to simplify handling of buffered diagnostics within the @@ -1956,36 +1954,36 @@ diagnostic_context::set_diagnostic_buffer (diagnostic_buffer *buffer) at nesting level 0. */ gcc_assert (m_diagnostic_groups.m_diagnostic_nesting_level == 0); - m_diagnostic_buffer = buffer; + m_diagnostic_buffer = buffer_; - if (buffer) + if (buffer_) { - buffer->ensure_per_format_buffers (); - gcc_assert (buffer->m_per_format_buffers); - gcc_assert (buffer->m_per_format_buffers->length () - == m_output_sinks.length ()); - for (unsigned idx = 0; idx < m_output_sinks.length (); ++idx) + buffer_->ensure_per_sink_buffers (); + gcc_assert (buffer_->m_per_sink_buffers); + gcc_assert (buffer_->m_per_sink_buffers->length () + == m_sinks.length ()); + for (unsigned idx = 0; idx < m_sinks.length (); ++idx) { - auto sink = m_output_sinks[idx]; - auto per_format_buffer = (*buffer->m_per_format_buffers)[idx]; - sink->set_buffer (per_format_buffer); + auto sink_ = m_sinks[idx]; + auto per_sink_buffer = (*buffer_->m_per_sink_buffers)[idx]; + sink_->set_buffer (per_sink_buffer); } } else - for (auto sink : m_output_sinks) - sink->set_buffer (nullptr); + for (auto sink_ : m_sinks) + sink_->set_buffer (nullptr); } /* Clear BUFFER without flushing it. */ void -diagnostic_context::clear_diagnostic_buffer (diagnostic_buffer &buffer) +diagnostic_context::clear_diagnostic_buffer (diagnostics::buffer &buffer_) { - if (buffer.m_per_format_buffers) - for (auto per_format_buffer : *buffer.m_per_format_buffers) - per_format_buffer->clear (); + if (buffer_.m_per_sink_buffers) + for (auto per_sink_buffer_ : *buffer_.m_per_sink_buffers) + per_sink_buffer_->clear (); - buffer.m_diagnostic_counters.clear (); + buffer_.m_diagnostic_counters.clear (); /* We need to reset last_location, otherwise we may skip caret lines when we actually give a diagnostic. */ @@ -1995,15 +1993,15 @@ diagnostic_context::clear_diagnostic_buffer (diagnostic_buffer &buffer) /* Flush the diagnostics in BUFFER to this context, clearing BUFFER. */ void -diagnostic_context::flush_diagnostic_buffer (diagnostic_buffer &buffer) +diagnostic_context::flush_diagnostic_buffer (diagnostics::buffer &buffer_) { bool had_errors - = (buffer.m_diagnostic_counters.m_count_for_kind[DK_ERROR] > 0 - || buffer.m_diagnostic_counters.m_count_for_kind[DK_WERROR] > 0); - if (buffer.m_per_format_buffers) - for (auto per_format_buffer : *buffer.m_per_format_buffers) - per_format_buffer->flush (); - buffer.m_diagnostic_counters.move_to (m_diagnostic_counters); + = (buffer_.m_diagnostic_counters.m_count_for_kind[DK_ERROR] > 0 + || buffer_.m_diagnostic_counters.m_count_for_kind[DK_WERROR] > 0); + if (buffer_.m_per_sink_buffers) + for (auto per_sink_buffer_ : *buffer_.m_per_sink_buffers) + per_sink_buffer_->flush (); + buffer_.m_diagnostic_counters.move_to (m_diagnostic_counters); action_after_output (had_errors ? DK_ERROR : DK_WARNING); check_max_errors (true); @@ -2048,76 +2046,76 @@ diagnostic_counters::clear () memset (&m_count_for_kind, 0, sizeof m_count_for_kind); } -/* class diagnostic_buffer. */ +/* class diagnostics::buffer. */ -diagnostic_buffer::diagnostic_buffer (diagnostic_context &ctxt) +diagnostics::buffer::buffer (diagnostic_context &ctxt) : m_ctxt (ctxt), - m_per_format_buffers (nullptr) + m_per_sink_buffers (nullptr) { } -diagnostic_buffer::~diagnostic_buffer () +diagnostics::buffer::~buffer () { - if (m_per_format_buffers) + if (m_per_sink_buffers) { - for (auto iter : *m_per_format_buffers) + for (auto iter : *m_per_sink_buffers) delete iter; - delete m_per_format_buffers; + delete m_per_sink_buffers; } } void -diagnostic_buffer::dump (FILE *out, int indent) const +diagnostics::buffer::dump (FILE *out, int indent) const { m_diagnostic_counters.dump (out, indent + 2); - fprintf (out, "%*sm_per_format_buffers:\n", indent, ""); - if (m_per_format_buffers) - for (auto per_format_buffer : *m_per_format_buffers) - per_format_buffer->dump (out, indent + 2); + fprintf (out, "%*sm_per_sink_buffers:\n", indent, ""); + if (m_per_sink_buffers) + for (auto per_sink_buffer_ : *m_per_sink_buffers) + per_sink_buffer_->dump (out, indent + 2); else fprintf (out, "%*s(none)\n", indent + 2, ""); } bool -diagnostic_buffer::empty_p () const +diagnostics::buffer::empty_p () const { - if (m_per_format_buffers) - for (auto per_format_buffer : *m_per_format_buffers) + if (m_per_sink_buffers) + for (auto per_sink_buffer_ : *m_per_sink_buffers) /* Query initial buffer. */ - return per_format_buffer->empty_p (); + return per_sink_buffer_->empty_p (); return true; } void -diagnostic_buffer::move_to (diagnostic_buffer &dest) +diagnostics::buffer::move_to (diagnostics::buffer &dest) { /* Bail if there's nothing to move. */ - if (!m_per_format_buffers) + if (!m_per_sink_buffers) return; m_diagnostic_counters.move_to (dest.m_diagnostic_counters); - if (!dest.m_per_format_buffers) + if (!dest.m_per_sink_buffers) { /* Optimization for the "move to empty" case: simply move the vec to the dest. */ - dest.m_per_format_buffers = m_per_format_buffers; - m_per_format_buffers = nullptr; + dest.m_per_sink_buffers = m_per_sink_buffers; + m_per_sink_buffers = nullptr; return; } - dest.ensure_per_format_buffers (); - gcc_assert (m_per_format_buffers); - gcc_assert (m_per_format_buffers->length () - == m_ctxt.m_output_sinks.length ()); - gcc_assert (dest.m_per_format_buffers); - gcc_assert (dest.m_per_format_buffers->length () - == m_ctxt.m_output_sinks.length ()); - for (unsigned idx = 0; idx < m_ctxt.m_output_sinks.length (); ++idx) + dest.ensure_per_sink_buffers (); + gcc_assert (m_per_sink_buffers); + gcc_assert (m_per_sink_buffers->length () + == m_ctxt.m_sinks.length ()); + gcc_assert (dest.m_per_sink_buffers); + gcc_assert (dest.m_per_sink_buffers->length () + == m_ctxt.m_sinks.length ()); + for (unsigned idx = 0; idx < m_ctxt.m_sinks.length (); ++idx) { - auto per_format_buffer_src = (*m_per_format_buffers)[idx]; - auto per_format_buffer_dest = (*dest.m_per_format_buffers)[idx]; - per_format_buffer_src->move_to (*per_format_buffer_dest); + auto per_sink_buffer_src = (*m_per_sink_buffers)[idx]; + auto per_sink_buffer_dest = (*dest.m_per_sink_buffers)[idx]; + per_sink_buffer_src->move_to (*per_sink_buffer_dest); } } @@ -2127,21 +2125,21 @@ diagnostic_buffer::move_to (diagnostic_buffer &dest) way to update all diagnostic_buffer instances for that context. */ void -diagnostic_buffer::ensure_per_format_buffers () +diagnostics::buffer::ensure_per_sink_buffers () { - if (!m_per_format_buffers) + if (!m_per_sink_buffers) { - m_per_format_buffers = new auto_vec (); - for (unsigned idx = 0; idx < m_ctxt.m_output_sinks.length (); ++idx) + m_per_sink_buffers = new auto_vec (); + for (unsigned idx = 0; idx < m_ctxt.m_sinks.length (); ++idx) { - auto sink = m_ctxt.m_output_sinks[idx]; - auto per_format_buffer = sink->make_per_format_buffer (); - m_per_format_buffers->safe_push (per_format_buffer.release ()); + auto sink_ = m_ctxt.m_sinks[idx]; + auto per_sink_buffer = sink_->make_per_sink_buffer (); + m_per_sink_buffers->safe_push (per_sink_buffer.release ()); } } - gcc_assert (m_per_format_buffers); - gcc_assert (m_per_format_buffers->length () - == m_ctxt.m_output_sinks.length ()); + gcc_assert (m_per_sink_buffers); + gcc_assert (m_per_sink_buffers->length () + == m_ctxt.m_sinks.length ()); } /* Really call the system 'abort'. This has to go right at the end of @@ -2396,8 +2394,8 @@ test_get_location_text () assert_location_text ("foo.c:42:", "foo.c", 42, 10, false); assert_location_text ("foo.c:", "foo.c", 0, 10, false); - maybe_line_and_column (INT_MAX, INT_MAX); - maybe_line_and_column (INT_MIN, INT_MIN); + diagnostics::maybe_line_and_column (INT_MAX, INT_MAX); + diagnostics::maybe_line_and_column (INT_MIN, INT_MIN); { /* In order to test display columns vs byte columns, we need to create a diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index 13f7525344e6..c9d4cc04b0ee 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -38,9 +38,12 @@ namespace diagnostics { class manager; } // namespace diagnostics::logical_locations + class buffer; class client_data_hooks; class diagram; class edit_context; + class sink; + class text_sink; } // namespace diagnostics @@ -191,7 +194,7 @@ struct diagnostic_info class diagnostic_location_print_policy; class diagnostic_source_print_policy; -typedef void (*diagnostic_text_starter_fn) (diagnostic_text_output_format &, +typedef void (*diagnostic_text_starter_fn) (diagnostics::text_sink &, const diagnostic_info *); struct to_text; @@ -204,7 +207,7 @@ using diagnostic_start_span_fn = void (*) (const diagnostic_location_print_polic Sink &sink, expanded_location); -typedef void (*diagnostic_text_finalizer_fn) (diagnostic_text_output_format &, +typedef void (*diagnostic_text_finalizer_fn) (diagnostics::text_sink &, const diagnostic_info *, diagnostic_t); @@ -238,9 +241,6 @@ public: }; class diagnostic_source_effect_info; -class diagnostic_output_format; - class diagnostic_text_output_format; -class diagnostic_buffer; /* A stack of sets of classifications: each entry in the stack is a mapping from option index to diagnostic severity that can be changed @@ -403,7 +403,7 @@ class diagnostic_location_print_policy { public: diagnostic_location_print_policy (const diagnostic_context &dc); - diagnostic_location_print_policy (const diagnostic_text_output_format &); + diagnostic_location_print_policy (const diagnostics::text_sink &); bool show_column_p () const { return m_show_column; } @@ -505,7 +505,7 @@ private: /* A collection of counters of diagnostics, per-kind (e.g. "3 errors and 1 warning"), for use by both diagnostic_context - and by diagnostic_buffer. */ + and by diagnostics::buffer. */ struct diagnostic_counters { @@ -532,12 +532,12 @@ struct diagnostic_counters (e.g. text vs SARIF) - providing a "dump" member function for a debug dump of the state of the diagnostics subsytem - - direct vs buffered diagnostics (see class diagnostic_buffer) + - direct vs buffered diagnostics (see class diagnostics::buffer) - tracking the original argv of the program (for SARIF output) - crash-handling It delegates responsibility to various other classes: - - the various output sinks (instances of diagnostic_output_format + - the various output sinks (instances of diagnostics::sink subclasses) - formatting of messages (class pretty_printer) - an optional urlifier to inject URLs into formatted messages @@ -567,8 +567,8 @@ public: diagnostic_text_finalizer (diagnostic_context *context); friend class diagnostic_source_print_policy; - friend class diagnostic_text_output_format; - friend class diagnostic_buffer; + friend class diagnostics::text_sink; + friend class diagnostics::buffer; typedef void (*set_locations_callback_t) (diagnostic_context *, diagnostic_info *); @@ -670,7 +670,7 @@ public: void emit_diagram (const diagnostics::diagram &diag); /* Various setters for use by option-handling logic. */ - void set_output_format (std::unique_ptr output_format); + void set_sink (std::unique_ptr sink_); void set_text_art_charset (enum diagnostic_text_art_charset charset); void set_client_data_hooks (std::unique_ptr hooks); @@ -712,7 +712,7 @@ public: return m_warning_as_error_requested; } bool show_path_depths_p () const { return m_show_path_depths; } - diagnostic_output_format &get_output_format (size_t idx) const; + diagnostics::sink &get_sink (size_t idx) const; enum diagnostic_path_format get_path_format () const { return m_path_format; } enum diagnostics_escape_format get_escape_format () const { @@ -814,13 +814,13 @@ public: } - void set_diagnostic_buffer (diagnostic_buffer *); - diagnostic_buffer *get_diagnostic_buffer () const + void set_diagnostic_buffer (diagnostics::buffer *); + diagnostics::buffer *get_diagnostic_buffer () const { return m_diagnostic_buffer; } - void clear_diagnostic_buffer (diagnostic_buffer &); - void flush_diagnostic_buffer (diagnostic_buffer &); + void clear_diagnostic_buffer (diagnostics::buffer &); + void flush_diagnostic_buffer (diagnostics::buffer &); std::unique_ptr clone_printer () const { @@ -833,7 +833,7 @@ public: } void - add_sink (std::unique_ptr); + add_sink (std::unique_ptr); void remove_all_output_sinks (); @@ -1086,7 +1086,7 @@ private: The sinks are owned by the context; this would be a std::vector if diagnostic_context had a proper ctor. */ - auto_vec m_output_sinks; + auto_vec m_sinks; /* Callback to set the locations of call sites along the inlining stack corresponding to a diagnostic location. Needed to traverse @@ -1116,14 +1116,14 @@ private: /* Owned by the context. */ char **m_original_argv; - /* Borrowed pointer to the active diagnostic_buffer, if any. + /* Borrowed pointer to the active diagnostics::buffer, if any. If null (the default), then diagnostics that are reported to the context are immediately issued to the output format. If non-null, then diagnostics that are reported to the context are buffered in the buffer, and may be issued to the output format later (if the buffer is flushed), moved to other buffers, or discarded (if the buffer is cleared). */ - diagnostic_buffer *m_diagnostic_buffer; + diagnostics::buffer *m_diagnostic_buffer; }; /* Client supplied function to announce a diagnostic @@ -1311,15 +1311,20 @@ extern void diagnostic_set_info_translated (diagnostic_info *, const char *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0); #endif -void default_diagnostic_text_starter (diagnostic_text_output_format &, - const diagnostic_info *); + +namespace diagnostics { + +void default_text_starter (diagnostics::text_sink &, + const diagnostic_info *); template -void default_diagnostic_start_span_fn (const diagnostic_location_print_policy &, - Sink &sink, - expanded_location); -void default_diagnostic_text_finalizer (diagnostic_text_output_format &, - const diagnostic_info *, - diagnostic_t); +void default_start_span_fn (const diagnostic_location_print_policy &, + Sink &sink, + expanded_location); +void default_text_finalizer (diagnostics::text_sink &, + const diagnostic_info *, + diagnostic_t); +} // namespace diagnostics + void diagnostic_set_caret_max_width (diagnostic_context *context, int value); int get_terminal_width (void); @@ -1394,6 +1399,10 @@ extern char *get_cwe_url (int cwe); extern const char *get_diagnostic_kind_text (diagnostic_t kind); +namespace diagnostics { + const char *maybe_line_and_column (int line, int col); +} // namespace diagnostics + #endif /* ! GCC_DIAGNOSTIC_H */ diff --git a/gcc/diagnostic-buffer.h b/gcc/diagnostics/buffering.h similarity index 72% rename from gcc/diagnostic-buffer.h rename to gcc/diagnostics/buffering.h index e766a3b46ffb..8a9353eb36e4 100644 --- a/gcc/diagnostic-buffer.h +++ b/gcc/diagnostics/buffering.h @@ -18,26 +18,28 @@ You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see . */ -#ifndef GCC_DIAGNOSTIC_BUFFER_H -#define GCC_DIAGNOSTIC_BUFFER_H +#ifndef GCC_DIAGNOSTICS_BUFFERING_H +#define GCC_DIAGNOSTICS_BUFFERING_H #include "diagnostic.h" -class diagnostic_per_format_buffer; -class diagnostic_output_format; - class diagnostic_text_output_format; +namespace diagnostics { + +class per_sink_buffer; +class sink; + class text_sink; /* Class representing a buffer of zero or more diagnostics that have been reported to a diagnostic_context, but which haven't yet been flushed. - A diagnostic_buffer can be: + A diagnostics::buffer can be: * flushed to the diagnostic_context, which issues the diagnostics within the buffer to the output format and checks for limits such as -fmax-errors=, or - * moved to another diagnostic_buffer, which moves the diagnostics + * moved to another diagnostics::buffer, which moves the diagnostics within the first buffer to the other buffer, appending them after any existing diagnostics within the destination buffer, emptying the source buffer, or @@ -53,13 +55,13 @@ class diagnostic_output_format; to change buffering on a diagnostic_context whilst within a diagnostic group. */ -class diagnostic_buffer +class buffer { public: - friend class diagnostic_context; + friend class ::diagnostic_context; - diagnostic_buffer (diagnostic_context &ctxt); - ~diagnostic_buffer (); + buffer (diagnostic_context &ctxt); + ~buffer (); void dump (FILE *out, int indent) const; void DEBUG_FUNCTION dump () const { dump (stderr, 0); } @@ -71,39 +73,41 @@ class diagnostic_buffer bool empty_p () const; - void move_to (diagnostic_buffer &dest); + void move_to (buffer &dest); private: - void ensure_per_format_buffers (); + void ensure_per_sink_buffers (); diagnostic_context &m_ctxt; - auto_vec *m_per_format_buffers; + auto_vec *m_per_sink_buffers; /* The number of buffered diagnostics of each kind. */ diagnostic_counters m_diagnostic_counters; }; -/* Implementation detail of diagnostic_buffer. +/* Implementation detail of diagnostics::buffer. Abstract base class describing how to represent zero of more - buffered diagnostics for a particular diagnostic_output_format + buffered diagnostics for a particular diagnostics::sink (e.g. text vs SARIF). - Each diagnostic_output_format subclass should implement its own - subclass for handling diagnostic_buffer. */ + Each diagnostics::sink subclass should implement its own + subclass for handling diagnostics::buffer. */ -class diagnostic_per_format_buffer +class per_sink_buffer { public: - virtual ~diagnostic_per_format_buffer () {} + virtual ~per_sink_buffer () {} virtual void dump (FILE *out, int indent) const = 0; void DEBUG_FUNCTION dump () const { dump (stderr, 0); } virtual bool empty_p () const = 0; - virtual void move_to (diagnostic_per_format_buffer &dest) = 0; + virtual void move_to (per_sink_buffer &dest) = 0; virtual void clear () = 0; virtual void flush () = 0; }; -#endif /* ! GCC_DIAGNOSTIC_BUFFER_H */ +} // namespace diagnostics + +#endif /* ! GCC_DIAGNOSTICS_BUFFERING_H */ diff --git a/gcc/diagnostics/client-data-hooks.h b/gcc/diagnostics/client-data-hooks.h index d7c549f3d258..139173f17a94 100644 --- a/gcc/diagnostics/client-data-hooks.h +++ b/gcc/diagnostics/client-data-hooks.h @@ -23,10 +23,9 @@ along with GCC; see the file COPYING3. If not see #include "diagnostics/logical-locations.h" -class sarif_object; - namespace diagnostics { +class sarif_object; class client_version_info; /* A bundle of additional metadata, owned by the diagnostic_context, diff --git a/gcc/diagnostics/digraphs.cc b/gcc/diagnostics/digraphs.cc index 5571c007802d..6a5b86c28263 100644 --- a/gcc/diagnostics/digraphs.cc +++ b/gcc/diagnostics/digraphs.cc @@ -29,7 +29,7 @@ along with GCC; see the file COPYING3. If not see #include "graphviz.h" #include "diagnostics/digraphs.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/sarif-sink.h" #include "selftest.h" diff --git a/gcc/diagnostic-format-html.cc b/gcc/diagnostics/html-sink.cc similarity index 93% rename from gcc/diagnostic-format-html.cc rename to gcc/diagnostics/html-sink.cc index 03421166ff64..2075a6cf71b5 100644 --- a/gcc/diagnostic-format-html.cc +++ b/gcc/diagnostics/html-sink.cc @@ -26,12 +26,12 @@ along with GCC; see the file COPYING3. If not see #include "coretypes.h" #include "diagnostic.h" #include "diagnostics/metadata.h" -#include "diagnostic-format.h" -#include "diagnostic-format-html.h" -#include "diagnostic-format-text.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/sink.h" +#include "diagnostics/html-sink.h" +#include "diagnostics/text-sink.h" +#include "diagnostics/sarif-sink.h" #include "diagnostics/output-file.h" -#include "diagnostic-buffer.h" +#include "diagnostics/buffering.h" #include "diagnostics/paths.h" #include "diagnostics/client-data-hooks.h" #include "selftest.h" @@ -48,7 +48,7 @@ along with GCC; see the file COPYING3. If not see #include "json.h" #include "selftest-xml.h" -using namespace diagnostics; +namespace diagnostics { // struct html_generation_options @@ -65,19 +65,19 @@ class html_builder; /* Concrete buffering implementation subclass for HTML output. */ -class diagnostic_html_format_buffer : public diagnostic_per_format_buffer +class html_sink_buffer : public per_sink_buffer { public: friend class html_builder; - friend class html_output_format; + friend class html_sink; - diagnostic_html_format_buffer (html_builder &builder) + html_sink_buffer (html_builder &builder) : m_builder (builder) {} void dump (FILE *out, int indent) const final override; bool empty_p () const final override; - void move_to (diagnostic_per_format_buffer &dest) final override; + void move_to (per_sink_buffer &dest) final override; void clear () final override; void flush () final override; @@ -109,7 +109,7 @@ private: class html_builder { public: - friend class diagnostic_html_format_buffer; + friend class html_sink_buffer; html_builder (diagnostic_context &context, pretty_printer &pp, @@ -121,7 +121,7 @@ public: void on_report_diagnostic (const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind, - diagnostic_html_format_buffer *buffer); + html_sink_buffer *buffer); void emit_diagram (const diagram &d); void emit_global_graph (const digraphs::lazy_digraph &); @@ -218,12 +218,12 @@ make_span (std::string class_) return span; } -/* class diagnostic_html_format_buffer : public diagnostic_per_format_buffer. */ +/* class html_sink_buffer : public per_sink_buffer. */ void -diagnostic_html_format_buffer::dump (FILE *out, int indent) const +html_sink_buffer::dump (FILE *out, int indent) const { - fprintf (out, "%*sdiagnostic_html_format_buffer:\n", indent, ""); + fprintf (out, "%*shtml_sink_buffer:\n", indent, ""); int idx = 0; for (auto &result : m_results) { @@ -235,29 +235,29 @@ diagnostic_html_format_buffer::dump (FILE *out, int indent) const } bool -diagnostic_html_format_buffer::empty_p () const +html_sink_buffer::empty_p () const { return m_results.empty (); } void -diagnostic_html_format_buffer::move_to (diagnostic_per_format_buffer &base) +html_sink_buffer::move_to (per_sink_buffer &base) { - diagnostic_html_format_buffer &dest - = static_cast (base); + html_sink_buffer &dest + = static_cast (base); for (auto &&result : m_results) dest.m_results.push_back (std::move (result)); m_results.clear (); } void -diagnostic_html_format_buffer::clear () +html_sink_buffer::clear () { m_results.clear (); } void -diagnostic_html_format_buffer::flush () +html_sink_buffer::flush () { for (auto &&result : m_results) m_builder.m_diagnostics_element->add_child (std::move (result)); @@ -497,7 +497,7 @@ html_builder::add_stylesheet (std::string url) void html_builder::on_report_diagnostic (const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind, - diagnostic_html_format_buffer *buffer) + html_sink_buffer *buffer) { if (diagnostic.kind == DK_ICE || diagnostic.kind == DK_ICE_NOBT) { @@ -1313,10 +1313,10 @@ html_builder::flush_to_file (FILE *outf) fprintf (outf, "\n"); } -class html_output_format : public diagnostic_output_format +class html_sink : public sink { public: - ~html_output_format () + ~html_sink () { /* Any diagnostics should have been handled by now. If not, then something's gone wrong with diagnostic @@ -1328,8 +1328,8 @@ public: void dump (FILE *out, int indent) const override { - fprintf (out, "%*shtml_output_format\n", indent, ""); - diagnostic_output_format::dump (out, indent); + fprintf (out, "%*shtml_sink\n", indent, ""); + sink::dump (out, indent); } void @@ -1338,15 +1338,15 @@ public: m_builder.set_main_input_filename (name); } - std::unique_ptr - make_per_format_buffer () final override + std::unique_ptr + make_per_sink_buffer () final override { - return std::make_unique (m_builder); + return std::make_unique (m_builder); } - void set_buffer (diagnostic_per_format_buffer *base_buffer) final override + void set_buffer (per_sink_buffer *base_buffer) final override { - diagnostic_html_format_buffer *buffer - = static_cast (base_buffer); + html_sink_buffer *buffer + = static_cast (base_buffer); m_buffer = buffer; } @@ -1404,41 +1404,41 @@ public: html_builder &get_builder () { return m_builder; } protected: - html_output_format (diagnostic_context &context, - const line_maps *line_maps, - const html_generation_options &html_gen_opts) - : diagnostic_output_format (context), + html_sink (diagnostic_context &context, + const line_maps *line_maps, + const html_generation_options &html_gen_opts) + : sink (context), m_builder (context, *get_printer (), line_maps, html_gen_opts), m_buffer (nullptr) {} html_builder m_builder; - diagnostic_html_format_buffer *m_buffer; + html_sink_buffer *m_buffer; }; -class html_file_output_format : public html_output_format +class html_file_sink : public html_sink { public: - html_file_output_format (diagnostic_context &context, - const line_maps *line_maps, - const html_generation_options &html_gen_opts, - output_file output_file_) - : html_output_format (context, line_maps, html_gen_opts), + html_file_sink (diagnostic_context &context, + const line_maps *line_maps, + const html_generation_options &html_gen_opts, + output_file output_file_) + : html_sink (context, line_maps, html_gen_opts), m_output_file (std::move (output_file_)) { gcc_assert (m_output_file.get_open_file ()); gcc_assert (m_output_file.get_filename ()); } - ~html_file_output_format () + ~html_file_sink () { m_builder.flush_to_file (m_output_file.get_open_file ()); } void dump (FILE *out, int indent) const override { - fprintf (out, "%*shtml_file_output_format: %s\n", + fprintf (out, "%*shtml_file_sink: %s\n", indent, "", m_output_file.get_filename ()); - diagnostic_output_format::dump (out, indent); + sink::dump (out, indent); } bool machine_readable_stderr_p () const final override { @@ -1455,9 +1455,9 @@ private: using LINE_MAPS. */ output_file -diagnostic_output_format_open_html_file (diagnostic_context &context, - line_maps *line_maps, - const char *base_file_name) +open_html_output_file (diagnostic_context &context, + line_maps *line_maps, + const char *base_file_name) { if (!base_file_name) { @@ -1484,25 +1484,29 @@ diagnostic_output_format_open_html_file (diagnostic_context &context, return output_file (outf, true, std::move (filename)); } -std::unique_ptr +std::unique_ptr make_html_sink (diagnostic_context &context, const line_maps &line_maps, const html_generation_options &html_gen_opts, output_file output_file_) { auto sink - = std::make_unique (context, - &line_maps, - html_gen_opts, - std::move (output_file_)); + = std::make_unique (context, + &line_maps, + html_gen_opts, + std::move (output_file_)); sink->update_printer (); return sink; } +} // namespace diagnostics + #if CHECKING_P namespace selftest { +using namespace diagnostics; + /* Helper for writing tests of html_token_printer. Printing to m_pp will appear as HTML within m_top_element, a
. */ @@ -1559,7 +1563,7 @@ test_token_printer () } } -/* A subclass of html_output_format for writing selftests. +/* A subclass of html_sink for writing selftests. The XML output is cached internally, rather than written out to a file. */ @@ -1571,14 +1575,14 @@ public: html_generation_options html_gen_opts; html_gen_opts.m_css = false; html_gen_opts.m_javascript = false; - auto sink = std::make_unique (*this, - line_table, - html_gen_opts); + auto sink = std::make_unique (*this, + line_table, + html_gen_opts); sink->update_printer (); sink->set_main_input_filename ("(main input filename)"); m_format = sink.get (); // borrowed - set_output_format (std::move (sink)); + set_sink (std::move (sink)); } const xml::document &get_document () const @@ -1592,13 +1596,13 @@ public: } private: - class html_buffered_output_format : public html_output_format + class html_buffered_sink : public html_sink { public: - html_buffered_output_format (diagnostic_context &context, - const line_maps *line_maps, - const html_generation_options &html_gen_opts) - : html_output_format (context, line_maps, html_gen_opts) + html_buffered_sink (diagnostic_context &context, + const line_maps *line_maps, + const html_generation_options &html_gen_opts) + : html_sink (context, line_maps, html_gen_opts) { } bool machine_readable_stderr_p () const final override @@ -1607,7 +1611,7 @@ private: } }; - html_output_format *m_format; // borrowed + html_sink *m_format; // borrowed }; /* Test of reporting a diagnostic at UNKNOWN_LOCATION to a @@ -1691,7 +1695,7 @@ test_metadata () /* Run all of the selftests within this file. */ void -diagnostic_format_html_cc_tests () +diagnostics_html_sink_cc_tests () { auto_fix_quotes fix_quotes; test_token_printer (); diff --git a/gcc/diagnostic-format-html.h b/gcc/diagnostics/html-sink.h similarity index 82% rename from gcc/diagnostic-format-html.h rename to gcc/diagnostics/html-sink.h index 8e3a2f89dc96..67a2565db94e 100644 --- a/gcc/diagnostic-format-html.h +++ b/gcc/diagnostics/html-sink.h @@ -18,12 +18,14 @@ You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see . */ -#ifndef GCC_DIAGNOSTIC_FORMAT_HTML_H -#define GCC_DIAGNOSTIC_FORMAT_HTML_H +#ifndef GCC_DIAGNOSTICS_HTML_SINK_H +#define GCC_DIAGNOSTICS_HTML_SINK_H -#include "diagnostic-format.h" +#include "diagnostics/sink.h" #include "diagnostics/output-file.h" +namespace diagnostics { + struct html_generation_options { html_generation_options (); @@ -44,11 +46,11 @@ struct html_generation_options }; extern diagnostics::output_file -diagnostic_output_format_open_html_file (diagnostic_context &context, - line_maps *line_maps, - const char *base_file_name); +open_html_output_file (diagnostic_context &context, + line_maps *line_maps, + const char *base_file_name); -extern std::unique_ptr +extern std::unique_ptr make_html_sink (diagnostic_context &context, const line_maps &line_maps, const html_generation_options &html_gen_opts, @@ -61,4 +63,6 @@ print_path_as_html (xml::printer &xp, html_label_writer *event_label_writer, const diagnostic_source_print_policy &dspp); -#endif /* ! GCC_DIAGNOSTIC_FORMAT_HTML_H */ +} // namespace diagnostics + +#endif /* ! GCC_DIAGNOSTICS_HTML_SINK_H */ diff --git a/gcc/diagnostics/lazy-paths.cc b/gcc/diagnostics/lazy-paths.cc index 8de5db42a211..c842f7e71406 100644 --- a/gcc/diagnostics/lazy-paths.cc +++ b/gcc/diagnostics/lazy-paths.cc @@ -32,7 +32,7 @@ along with GCC; see the file COPYING3. If not see #include "selftest-diagnostic.h" #include "simple-diagnostic-path.h" #include "gcc-rich-location.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" using namespace diagnostics::paths; @@ -202,10 +202,10 @@ test_emission (pretty_printer *event_pp) /* Verify that the path works as expected. */ dc.set_path_format (DPF_INLINE_EVENTS); - diagnostic_text_output_format sink (dc); - pp_buffer (sink.get_printer ())->m_flush_p = false; - sink.print_path (rich_loc.m_path); - ASSERT_STREQ (pp_formatted_text (sink.get_printer ()), + diagnostics::text_sink sink_ (dc); + pp_buffer (sink_.get_printer ())->m_flush_p = false; + sink_.print_path (rich_loc.m_path); + ASSERT_STREQ (pp_formatted_text (sink_.get_printer ()), " `foo': event 1\n" " (1): first `free'\n" " `foo': event 2\n" diff --git a/gcc/diagnostics/metadata.h b/gcc/diagnostics/metadata.h index d0b4220c9059..cdca105ebdfd 100644 --- a/gcc/diagnostics/metadata.h +++ b/gcc/diagnostics/metadata.h @@ -21,10 +21,10 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_DIAGNOSTICS_METADATA_H #define GCC_DIAGNOSTICS_METADATA_H -class sarif_object; - namespace diagnostics { + class sarif_object; + namespace digraphs { class lazy_digraphs; } // namespace digraphs diff --git a/gcc/diagnostics/output-spec.cc b/gcc/diagnostics/output-spec.cc index 35d593e11dbb..6a468dc570c3 100644 --- a/gcc/diagnostics/output-spec.cc +++ b/gcc/diagnostics/output-spec.cc @@ -33,10 +33,10 @@ along with GCC; see the file COPYING3. If not see #include "intl.h" #include "diagnostic.h" #include "diagnostic-color.h" -#include "diagnostic-format.h" -#include "diagnostic-format-html.h" -#include "diagnostic-format-text.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/sink.h" +#include "diagnostics/html-sink.h" +#include "diagnostics/text-sink.h" +#include "diagnostics/sarif-sink.h" #include "selftest.h" #include "selftest-diagnostic.h" #include "pretty-print-markup.h" @@ -57,7 +57,7 @@ struct scheme_name_and_params }; /* Class for parsing the arguments of -fdiagnostics-add-output= and - -fdiagnostics-set-output=, and making diagnostic_output_format + -fdiagnostics-set-output=, and making sink instances (or issuing errors). */ class output_factory @@ -73,7 +73,7 @@ public: const std::string &get_scheme_name () const { return m_scheme_name; } - virtual std::unique_ptr + virtual std::unique_ptr make_sink (const context &ctxt, diagnostic_context &dc, const char *unparsed_arg, @@ -146,7 +146,7 @@ public: output_factory (); - std::unique_ptr + std::unique_ptr make_sink (const context &ctxt, diagnostic_context &dc, const char *unparsed_arg, @@ -163,7 +163,7 @@ class text_scheme_handler : public output_factory::scheme_handler public: text_scheme_handler () : scheme_handler ("text") {} - std::unique_ptr + std::unique_ptr make_sink (const context &ctxt, diagnostic_context &dc, const char *unparsed_arg, @@ -175,7 +175,7 @@ class sarif_scheme_handler : public output_factory::scheme_handler public: sarif_scheme_handler () : scheme_handler ("sarif") {} - std::unique_ptr + std::unique_ptr make_sink (const context &ctxt, diagnostic_context &dc, const char *unparsed_arg, @@ -195,7 +195,7 @@ class html_scheme_handler : public output_factory::scheme_handler public: html_scheme_handler () : scheme_handler ("experimental-html") {} - std::unique_ptr + std::unique_ptr make_sink (const context &ctxt, diagnostic_context &dc, const char *unparsed_arg, @@ -304,7 +304,7 @@ parse (const context &ctxt, const char *unparsed_arg) return std::make_unique (std::move (result)); } -std::unique_ptr +std::unique_ptr context::parse_and_make_sink (const char *unparsed_arg, diagnostic_context &dc) { @@ -336,7 +336,7 @@ output_factory::get_scheme_handler (const std::string &scheme_name) return nullptr; } -std::unique_ptr +std::unique_ptr output_factory::make_sink (const context &ctxt, diagnostic_context &dc, const char *unparsed_arg, @@ -361,7 +361,7 @@ output_factory::make_sink (const context &ctxt, /* class text_scheme_handler : public output_factory::scheme_handler. */ -std::unique_ptr +std::unique_ptr text_scheme_handler::make_sink (const context &ctxt, diagnostic_context &dc, const char *unparsed_arg, @@ -413,7 +413,7 @@ text_scheme_handler::make_sink (const context &ctxt, return nullptr; } - auto sink = std::make_unique (dc); + auto sink = std::make_unique (dc); sink->set_show_nesting (show_nesting); sink->set_show_locations_in_nesting (show_locations_in_nesting); sink->set_show_nesting_levels (show_levels); @@ -422,7 +422,7 @@ text_scheme_handler::make_sink (const context &ctxt, /* class sarif_scheme_handler : public output_factory::scheme_handler. */ -std::unique_ptr +std::unique_ptr sarif_scheme_handler::make_sink (const context &ctxt, diagnostic_context &dc, const char *unparsed_arg, @@ -505,11 +505,10 @@ sarif_scheme_handler::make_sink (const context &ctxt, return nullptr; } output_file_ - = diagnostic_output_format_open_sarif_file - (dc, - ctxt.get_affected_location_mgr (), - basename, - serialization_kind); + = open_sarif_output_file (dc, + ctxt.get_affected_location_mgr (), + basename, + serialization_kind); } if (!output_file_) return nullptr; @@ -552,7 +551,7 @@ make_sarif_serialization_object (enum sarif_serialization_kind kind) /* class html_scheme_handler : public output_factory::scheme_handler. */ -std::unique_ptr +std::unique_ptr html_scheme_handler::make_sink (const context &ctxt, diagnostic_context &dc, const char *unparsed_arg, @@ -638,7 +637,7 @@ html_scheme_handler::make_sink (const context &ctxt, return nullptr; } output_file_ - = diagnostic_output_format_open_html_file + = open_html_output_file (dc, ctxt.get_affected_location_mgr (), basename); @@ -715,7 +714,7 @@ struct parser_test parser_test () : m_dc (), m_ctxt (m_dc, line_table, UNKNOWN_LOCATION, "-fOPTION="), - m_fmt (m_dc.get_output_format (0)) + m_fmt (m_dc.get_sink (0)) { pp_buffer (m_fmt.get_printer ())->m_flush_p = false; } @@ -740,7 +739,7 @@ struct parser_test private: test_diagnostic_context m_dc; test_spec_context m_ctxt; - diagnostic_output_format &m_fmt; + diagnostics::sink &m_fmt; }; /* Selftests. */ diff --git a/gcc/diagnostics/output-spec.h b/gcc/diagnostics/output-spec.h index 49a84b283181..9212efd7f062 100644 --- a/gcc/diagnostics/output-spec.h +++ b/gcc/diagnostics/output-spec.h @@ -21,7 +21,7 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_DIAGNOSTICS_OUTPUT_SPEC_H #define GCC_DIAGNOSTICS_OUTPUT_SPEC_H -#include "diagnostic-format.h" +#include "diagnostics/sink.h" #include "diagnostics/output-file.h" namespace diagnostics { @@ -33,7 +33,7 @@ namespace output_spec { class context { public: - std::unique_ptr + std::unique_ptr parse_and_make_sink (const char *, diagnostic_context &dc); diff --git a/gcc/diagnostics/paths-output.cc b/gcc/diagnostics/paths-output.cc index c3e152fa07ef..8d9eb99b8d01 100644 --- a/gcc/diagnostics/paths-output.cc +++ b/gcc/diagnostics/paths-output.cc @@ -38,8 +38,8 @@ along with GCC; see the file COPYING3. If not see #include "selftest-diagnostic.h" #include "diagnostics/selftest-paths.h" #include "text-art/theme.h" -#include "diagnostic-format-text.h" -#include "diagnostic-format-html.h" +#include "diagnostics/text-sink.h" +#include "diagnostics/html-sink.h" #include "xml.h" #include "xml-printer.h" @@ -62,7 +62,7 @@ using namespace diagnostics::paths; class path_print_policy { public: - path_print_policy (const diagnostic_text_output_format &text_output) + path_print_policy (const diagnostics::text_sink &text_output) : m_source_policy (text_output.get_context ()) { } @@ -593,7 +593,7 @@ struct event_range call to diagnostic_show_locus. */ void print_as_text (pretty_printer &pp, - diagnostic_text_output_format &text_output, + diagnostics::text_sink &text_output, diagnostic_source_effect_info *effect_info) { location_t initial_loc = m_initial_event.get_location (); @@ -883,7 +883,7 @@ public: } void - print_swimlane_for_event_range_as_text (diagnostic_text_output_format &text_output, + print_swimlane_for_event_range_as_text (diagnostics::text_sink &text_output, pretty_printer *pp, const logical_locations::manager &logical_loc_mgr, event_range *range, @@ -1109,7 +1109,7 @@ private: static void print_path_summary_as_text (const path_summary &ps, - diagnostic_text_output_format &text_output, + diagnostics::text_sink &text_output, bool show_depths) { pretty_printer *const pp = text_output.get_printer (); @@ -1305,7 +1305,7 @@ private: /* Print PATH according to the context's path_format. */ void -diagnostic_text_output_format::print_path (const path &path_) +diagnostics::text_sink::print_path (const path &path_) { const unsigned num_events = path_.num_events (); @@ -1382,11 +1382,11 @@ diagnostic_text_output_format::print_path (const path &path_) If non-null, use EVENT_LABEL_WRITER when writing events. */ void -print_path_as_html (xml::printer &xp, - const path &path_, - diagnostic_context &dc, - html_label_writer *event_label_writer, - const diagnostic_source_print_policy &dspp) +diagnostics::print_path_as_html (xml::printer &xp, + const path &path_, + diagnostic_context &dc, + html_label_writer *event_label_writer, + const diagnostic_source_print_policy &dspp) { path_print_policy policy (dc); const bool check_rich_locations = true; @@ -1438,7 +1438,7 @@ test_empty_path (pretty_printer *event_pp) ASSERT_FALSE (path.interprocedural_p ()); test_diagnostic_context dc; - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, false); ASSERT_EQ (summary.get_num_ranges (), 0); @@ -1461,7 +1461,7 @@ test_intraprocedural_path (pretty_printer *event_pp) ASSERT_FALSE (path.interprocedural_p ()); test_diagnostic_context dc; - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, false, false, false); ASSERT_EQ (summary.get_num_ranges (), 1); @@ -1498,7 +1498,7 @@ test_interprocedural_path_1 (pretty_printer *event_pp) { test_diagnostic_context dc; - diagnostic_text_output_format text_output (dc, nullptr, false); + diagnostics::text_sink text_output (dc, nullptr, false); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, false); ASSERT_EQ (summary.get_num_ranges (), 9); @@ -1560,7 +1560,7 @@ test_interprocedural_path_1 (pretty_printer *event_pp) { test_diagnostic_context dc; dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE); - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, false); print_path_summary_as_text (summary, text_output, true); @@ -1637,7 +1637,7 @@ test_interprocedural_path_2 (pretty_printer *event_pp) { test_diagnostic_context dc; - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, false); ASSERT_EQ (summary.get_num_ranges (), 5); @@ -1674,7 +1674,7 @@ test_interprocedural_path_2 (pretty_printer *event_pp) { test_diagnostic_context dc; dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE); - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, false); print_path_summary_as_text (summary, text_output, true); @@ -1726,7 +1726,7 @@ test_recursion (pretty_printer *event_pp) test_diagnostic_context dc; dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII); - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, false); ASSERT_EQ (summary.get_num_ranges (), 4); @@ -1758,7 +1758,7 @@ test_recursion (pretty_printer *event_pp) test_diagnostic_context dc; dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE); - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, false); print_path_summary_as_text (summary, text_output, true); @@ -1880,7 +1880,7 @@ test_control_flow_1 (const line_table_case &case_, test_diagnostic_context dc; dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII); dc.m_source_printing.show_event_links_p = true; - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, true); print_path_summary_as_text (summary, text_output, false); @@ -1906,7 +1906,7 @@ test_control_flow_1 (const line_table_case &case_, test_diagnostic_context dc; dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII); dc.m_source_printing.show_event_links_p = false; - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, true); print_path_summary_as_text (summary, text_output, false); @@ -1930,7 +1930,7 @@ test_control_flow_1 (const line_table_case &case_, dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII); dc.m_source_printing.show_line_numbers_p = true; dc.m_source_printing.show_event_links_p = true; - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, true); print_path_summary_as_text (summary, text_output, false); @@ -1957,7 +1957,7 @@ test_control_flow_1 (const line_table_case &case_, dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII); dc.m_source_printing.show_line_numbers_p = true; dc.m_source_printing.show_event_links_p = false; - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, true); print_path_summary_as_text (summary, text_output, false); @@ -1980,7 +1980,7 @@ test_control_flow_1 (const line_table_case &case_, test_diagnostic_context dc; dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE); dc.m_source_printing.show_event_links_p = true; - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, true); print_path_summary_as_text (summary, text_output, false); @@ -2007,7 +2007,7 @@ test_control_flow_1 (const line_table_case &case_, dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE); dc.m_source_printing.show_event_links_p = true; dc.m_source_printing.show_line_numbers_p = true; - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, true); print_path_summary_as_text (summary, text_output, false); @@ -2078,7 +2078,7 @@ test_control_flow_2 (const line_table_case &case_, dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII); dc.m_source_printing.show_event_links_p = true; dc.m_source_printing.show_line_numbers_p = true; - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, true); print_path_summary_as_text (summary, text_output, false); @@ -2165,7 +2165,7 @@ test_control_flow_3 (const line_table_case &case_, dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII); dc.m_source_printing.show_event_links_p = true; dc.m_source_printing.show_line_numbers_p = true; - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, true); print_path_summary_as_text (summary, text_output, false); @@ -2223,7 +2223,7 @@ assert_cfg_edge_path_streq (const location &loc, dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII); dc.m_source_printing.show_event_links_p = true; dc.m_source_printing.show_line_numbers_p = true; - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, true); print_path_summary_as_text (summary, text_output, false); @@ -2547,7 +2547,7 @@ test_control_flow_5 (const line_table_case &case_, dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII); dc.m_source_printing.show_event_links_p = true; dc.m_source_printing.show_line_numbers_p = true; - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, true); print_path_summary_as_text (summary, text_output, false); @@ -2636,7 +2636,7 @@ test_control_flow_6 (const line_table_case &case_, dc.set_text_art_charset (DIAGNOSTICS_TEXT_ART_CHARSET_ASCII); dc.m_source_printing.show_event_links_p = true; dc.m_source_printing.show_line_numbers_p = true; - diagnostic_text_output_format text_output (dc); + diagnostics::text_sink text_output (dc); path_print_policy policy (text_output); path_summary summary (policy, *event_pp, path, true); print_path_summary_as_text (summary, text_output, false); diff --git a/gcc/diagnostics/paths.h b/gcc/diagnostics/paths.h index 2de99b06dab1..d30c4203ec5e 100644 --- a/gcc/diagnostics/paths.h +++ b/gcc/diagnostics/paths.h @@ -25,11 +25,6 @@ along with GCC; see the file COPYING3. If not see #include "diagnostics/event-id.h" #include "diagnostics/logical-locations.h" -namespace xml { class document; } - -class sarif_builder; -class sarif_object; - namespace diagnostics { namespace digraphs { class digraph; @@ -37,6 +32,8 @@ namespace diagnostics { namespace logical_locations { class manager; } // logical_locations + class sarif_builder; + class sarif_object; } //namespace diagnostics namespace diagnostics { diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostics/sarif-sink.cc similarity index 96% rename from gcc/diagnostic-format-sarif.cc rename to gcc/diagnostics/sarif-sink.cc index bc6f19fae2e0..79c4bf3e6789 100644 --- a/gcc/diagnostic-format-sarif.cc +++ b/gcc/diagnostics/sarif-sink.cc @@ -31,16 +31,16 @@ along with GCC; see the file COPYING3. If not see #include "diagnostics/digraphs.h" #include "diagnostics/state-graphs.h" #include "diagnostics/paths.h" -#include "diagnostic-format.h" -#include "diagnostic-buffer.h" +#include "diagnostics/sink.h" +#include "diagnostics/buffering.h" #include "json.h" #include "cpplib.h" #include "diagnostics/logical-locations.h" #include "diagnostics/client-data-hooks.h" #include "diagnostics/diagram.h" #include "text-art/canvas.h" -#include "diagnostic-format-sarif.h" -#include "diagnostic-format-text.h" +#include "diagnostics/sarif-sink.h" +#include "diagnostics/text-sink.h" #include "ordered-hash-map.h" #include "sbitmap.h" #include "selftest.h" @@ -54,7 +54,7 @@ along with GCC; see the file COPYING3. If not see #include "backtrace.h" #include "xml.h" -using namespace diagnostics; +namespace diagnostics { /* A json::array where the values are "unique" as per SARIF v2.1.0 section 3.7.3 ("Array properties with unique values"). */ @@ -662,20 +662,20 @@ public: render (const sarif_builder &builder) const = 0; }; -/* Concrete buffering implementation subclass for JSON output. */ +/* Concrete buffering implementation subclass for SARIF output. */ -class diagnostic_sarif_format_buffer : public diagnostic_per_format_buffer +class sarif_sink_buffer : public per_sink_buffer { public: - friend class sarif_output_format; + friend class sarif_sink; - diagnostic_sarif_format_buffer (sarif_builder &builder) + sarif_sink_buffer (sarif_builder &builder) : m_builder (builder) {} void dump (FILE *out, int indent) const final override; bool empty_p () const final override; - void move_to (diagnostic_per_format_buffer &dest) final override; + void move_to (per_sink_buffer &dest) final override; void clear () final override; void flush () final override; @@ -751,7 +751,7 @@ sarif_serialization_format_json::write_to_file (FILE *outf, class sarif_builder { public: - friend class diagnostic_sarif_format_buffer; + friend class sarif_sink_buffer; sarif_builder (diagnostic_context &context, pretty_printer &printer, @@ -776,7 +776,7 @@ public: void on_report_diagnostic (const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind, - diagnostic_sarif_format_buffer *buffer); + sarif_sink_buffer *buffer); void emit_diagram (const diagram &d); void end_group (); @@ -1841,7 +1841,7 @@ sarif_builder::set_main_input_filename (const char *name) void sarif_builder::on_report_diagnostic (const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind, - diagnostic_sarif_format_buffer *buffer) + sarif_sink_buffer *buffer) { pp_output_formatted_text (m_printer, m_context.get_urlifier ()); @@ -2279,7 +2279,7 @@ sarif_builder::make_location_object (sarif_location_manager *loc_mgr, diagnostic_source_print_policy source_policy (dc); dc.set_escape_format (m_escape_format); - diagnostic_text_output_format text_output (dc); + text_sink text_output (dc); source_policy.print (*text_output.get_printer (), my_rich_loc, DK_ERROR, nullptr); @@ -3797,12 +3797,12 @@ sarif_builder::make_artifact_content_object (const char *text) const return content_obj; } -/* class diagnostic_sarif_format_buffer : public diagnostic_per_format_buffer. */ +/* class sarif_sink_buffer : public per_sink_buffer. */ void -diagnostic_sarif_format_buffer::dump (FILE *out, int indent) const +sarif_sink_buffer::dump (FILE *out, int indent) const { - fprintf (out, "%*sdiagnostic_sarif_format_buffer:\n", indent, ""); + fprintf (out, "%*ssarif_sink_buffer:\n", indent, ""); int idx = 0; for (auto &result : m_results) { @@ -3814,29 +3814,29 @@ diagnostic_sarif_format_buffer::dump (FILE *out, int indent) const } bool -diagnostic_sarif_format_buffer::empty_p () const +sarif_sink_buffer::empty_p () const { return m_results.empty (); } void -diagnostic_sarif_format_buffer::move_to (diagnostic_per_format_buffer &base) +sarif_sink_buffer::move_to (per_sink_buffer &base) { - diagnostic_sarif_format_buffer &dest - = static_cast (base); + sarif_sink_buffer &dest + = static_cast (base); for (auto &&result : m_results) dest.m_results.push_back (std::move (result)); m_results.clear (); } void -diagnostic_sarif_format_buffer::clear () +sarif_sink_buffer::clear () { m_results.clear (); } void -diagnostic_sarif_format_buffer::flush () +sarif_sink_buffer::flush () { for (auto &&result : m_results) { @@ -3846,10 +3846,10 @@ diagnostic_sarif_format_buffer::flush () m_results.clear (); } -class sarif_output_format : public diagnostic_output_format +class sarif_sink : public sink { public: - ~sarif_output_format () + ~sarif_sink () { /* Any sarifResult objects should have been handled by now. If not, then something's gone wrong with diagnostic @@ -3861,8 +3861,8 @@ public: void dump (FILE *out, int indent) const override { - fprintf (out, "%*ssarif_output_format\n", indent, ""); - diagnostic_output_format::dump (out, indent); + fprintf (out, "%*ssarif_sink\n", indent, ""); + sink::dump (out, indent); } void @@ -3871,15 +3871,15 @@ public: m_builder.set_main_input_filename (name); } - std::unique_ptr - make_per_format_buffer () final override + std::unique_ptr + make_per_sink_buffer () final override { - return std::make_unique (m_builder); + return std::make_unique (m_builder); } - void set_buffer (diagnostic_per_format_buffer *base_buffer) final override + void set_buffer (per_sink_buffer *base_buffer) final override { - diagnostic_sarif_format_buffer *buffer - = static_cast (base_buffer); + sarif_sink_buffer *buffer + = static_cast (base_buffer); m_buffer = buffer; } @@ -3940,34 +3940,34 @@ public: sarif_result &get_result (size_t idx) { return m_builder.get_result (idx); } protected: - sarif_output_format (diagnostic_context &context, - const line_maps *line_maps, - std::unique_ptr serialization_format, - const sarif_generation_options &sarif_gen_opts) - : diagnostic_output_format (context), + sarif_sink (diagnostic_context &context, + const line_maps *line_maps, + std::unique_ptr serialization_format, + const sarif_generation_options &sarif_gen_opts) + : sink (context), m_builder (context, *get_printer (), line_maps, std::move (serialization_format), sarif_gen_opts), m_buffer (nullptr) {} sarif_builder m_builder; - diagnostic_sarif_format_buffer *m_buffer; + sarif_sink_buffer *m_buffer; }; -class sarif_stream_output_format : public sarif_output_format +class sarif_stream_sink : public sarif_sink { public: - sarif_stream_output_format (diagnostic_context &context, - const line_maps *line_maps, - std::unique_ptr serialization_format, - const sarif_generation_options &sarif_gen_opts, - FILE *stream) - : sarif_output_format (context, line_maps, - std::move (serialization_format), sarif_gen_opts), + sarif_stream_sink (diagnostic_context &context, + const line_maps *line_maps, + std::unique_ptr serialization_format, + const sarif_generation_options &sarif_gen_opts, + FILE *stream) + : sarif_sink (context, line_maps, + std::move (serialization_format), sarif_gen_opts), m_stream (stream) { } - ~sarif_stream_output_format () + ~sarif_stream_sink () { m_builder.flush_to_file (m_stream); } @@ -3979,31 +3979,32 @@ private: FILE *m_stream; }; -class sarif_file_output_format : public sarif_output_format +class sarif_file_sink : public sarif_sink { public: - sarif_file_output_format (diagnostic_context &context, - const line_maps *line_maps, - std::unique_ptr serialization_format, - const sarif_generation_options &sarif_gen_opts, - output_file output_file_) - : sarif_output_format (context, line_maps, - std::move (serialization_format), sarif_gen_opts), + sarif_file_sink (diagnostic_context &context, + const line_maps *line_maps, + std::unique_ptr serialization_format, + const sarif_generation_options &sarif_gen_opts, + output_file output_file_) + : sarif_sink (context, line_maps, + std::move (serialization_format), + sarif_gen_opts), m_output_file (std::move (output_file_)) { gcc_assert (m_output_file.get_open_file ()); gcc_assert (m_output_file.get_filename ()); } - ~sarif_file_output_format () + ~sarif_file_sink () { m_builder.flush_to_file (m_output_file.get_open_file ()); } void dump (FILE *out, int indent) const override { - fprintf (out, "%*ssarif_file_output_format: %s\n", + fprintf (out, "%*ssarif_file_sink: %s\n", indent, "", m_output_file.get_filename ()); - diagnostic_output_format::dump (out, indent); + sink::dump (out, indent); } bool machine_readable_stderr_p () const final override { @@ -4134,16 +4135,16 @@ sarif_builder::sarif_token_printer::print_tokens (pretty_printer *pp, to a file). Return a reference to *FMT. */ -static diagnostic_output_format & -diagnostic_output_format_init_sarif (diagnostic_context &context, - std::unique_ptr fmt) +static sink & +init_sarif_sink (diagnostic_context &context, + std::unique_ptr fmt) { gcc_assert (fmt); - diagnostic_output_format &out = *fmt; + sink &out = *fmt; fmt->update_printer (); - context.set_output_format (std::move (fmt)); + context.set_sink (std::move (fmt)); return out; } @@ -4151,22 +4152,22 @@ diagnostic_output_format_init_sarif (diagnostic_context &context, /* Populate CONTEXT in preparation for SARIF output to stderr. Return a reference to the new sink. */ -diagnostic_output_format & -diagnostic_output_format_init_sarif_stderr (diagnostic_context &context, - const line_maps *line_maps, - bool formatted) +sink & +init_sarif_stderr (diagnostic_context &context, + const line_maps *line_maps, + bool formatted) { gcc_assert (line_maps); const sarif_generation_options sarif_gen_opts; auto serialization = std::make_unique (formatted); - return diagnostic_output_format_init_sarif + return init_sarif_sink (context, - std::make_unique (context, - line_maps, - std::move (serialization), - sarif_gen_opts, - stderr)); + std::make_unique (context, + line_maps, + std::move (serialization), + sarif_gen_opts, + stderr)); } /* Attempt to open "BASE_FILE_NAME""EXTENSION" for writing. @@ -4215,10 +4216,10 @@ output_file::try_to_open (diagnostic_context &context, using LINE_MAPS. */ output_file -diagnostic_output_format_open_sarif_file (diagnostic_context &context, - line_maps *line_maps, - const char *base_file_name, - enum sarif_serialization_kind serialization_kind) +open_sarif_output_file (diagnostic_context &context, + line_maps *line_maps, + const char *base_file_name, + enum sarif_serialization_kind serialization_kind) { const char *suffix; bool is_binary; @@ -4243,55 +4244,55 @@ diagnostic_output_format_open_sarif_file (diagnostic_context &context, BASE_FILE_NAME.sarif. Return a reference to the new sink. */ -diagnostic_output_format & -diagnostic_output_format_init_sarif_file (diagnostic_context &context, - line_maps *line_maps, - bool formatted, - const char *base_file_name) +sink & +init_sarif_file (diagnostic_context &context, + line_maps *line_maps, + bool formatted, + const char *base_file_name) { gcc_assert (line_maps); output_file output_file_ - = diagnostic_output_format_open_sarif_file (context, - line_maps, - base_file_name, - sarif_serialization_kind::json); + = open_sarif_output_file (context, + line_maps, + base_file_name, + sarif_serialization_kind::json); auto serialization = std::make_unique (formatted); const sarif_generation_options sarif_gen_opts; - return diagnostic_output_format_init_sarif + return init_sarif_sink (context, - std::make_unique (context, - line_maps, - std::move (serialization), - sarif_gen_opts, - std::move (output_file_))); + std::make_unique (context, + line_maps, + std::move (serialization), + sarif_gen_opts, + std::move (output_file_))); } /* Populate CONTEXT in preparation for SARIF output to STREAM. Return a reference to the new sink. */ -diagnostic_output_format & -diagnostic_output_format_init_sarif_stream (diagnostic_context &context, - const line_maps *line_maps, - bool formatted, - FILE *stream) +sink & +init_sarif_stream (diagnostic_context &context, + const line_maps *line_maps, + bool formatted, + FILE *stream) { gcc_assert (line_maps); const sarif_generation_options sarif_gen_opts; auto serialization = std::make_unique (formatted); - return diagnostic_output_format_init_sarif + return init_sarif_sink (context, - std::make_unique (context, - line_maps, - std::move (serialization), - sarif_gen_opts, - stream)); + std::make_unique (context, + line_maps, + std::move (serialization), + sarif_gen_opts, + stream)); } -std::unique_ptr +std::unique_ptr make_sarif_sink (diagnostic_context &context, const line_maps &line_maps, std::unique_ptr serialization, @@ -4299,11 +4300,11 @@ make_sarif_sink (diagnostic_context &context, output_file output_file_) { auto sink - = std::make_unique (context, - &line_maps, - std::move (serialization), - sarif_gen_opts, - std::move (output_file_)); + = std::make_unique (context, + &line_maps, + std::move (serialization), + sarif_gen_opts, + std::move (output_file_)); sink->update_printer (); return sink; } @@ -4316,10 +4317,14 @@ sarif_generation_options::sarif_generation_options () { } +} // namespace diagnostics + #if CHECKING_P namespace selftest { +using namespace diagnostics; + static void test_sarif_array_of_unique_1 () { @@ -4390,7 +4395,7 @@ test_sarif_array_of_unique_2 () ASSERT_JSON_INT_PROPERTY_EQ (arr[1], "index", 1); } -/* A subclass of sarif_output_format for writing selftests. +/* A subclass of sarif_sink for writing selftests. The JSON output is cached internally, rather than written out to a file. */ @@ -4400,35 +4405,34 @@ public: test_sarif_diagnostic_context (const char *main_input_filename, const sarif_generation_options &sarif_gen_opts) { - auto format = std::make_unique (*this, - line_table, - true, - sarif_gen_opts); - m_format = format.get (); // borrowed - diagnostic_output_format_init_sarif (*this, std::move (format)); - m_format->set_main_input_filename (main_input_filename); + auto sink_ = std::make_unique (*this, + line_table, + true, + sarif_gen_opts); + m_sink = sink_.get (); // borrowed + init_sarif_sink (*this, std::move (sink_)); + m_sink->set_main_input_filename (main_input_filename); } std::unique_ptr flush_to_object () { - return m_format->flush_to_object (); + return m_sink->flush_to_object (); } - size_t num_results () const { return m_format->num_results (); } - sarif_result &get_result (size_t idx) { return m_format->get_result (idx); } + size_t num_results () const { return m_sink->num_results (); } + sarif_result &get_result (size_t idx) { return m_sink->get_result (idx); } private: - class buffered_output_format : public sarif_output_format + class buffered_sink : public sarif_sink { public: - buffered_output_format (diagnostic_context &context, - const line_maps *line_maps, - bool formatted, - const sarif_generation_options &sarif_gen_opts) - : sarif_output_format (context, line_maps, - std::make_unique - (formatted), - sarif_gen_opts) + buffered_sink (diagnostic_context &context, + const line_maps *line_maps, + bool formatted, + const sarif_generation_options &sarif_gen_opts) + : sarif_sink (context, line_maps, + std::make_unique (formatted), + sarif_gen_opts) { } bool machine_readable_stderr_p () const final override @@ -4441,7 +4445,7 @@ private: } }; - buffered_output_format *m_format; // borrowed + buffered_sink *m_sink; // borrowed }; /* Test making a sarif_location for a complex rich_location @@ -4940,8 +4944,8 @@ test_buffering (const sarif_generation_options &sarif_gen_opts) { test_sarif_diagnostic_context dc ("test.c", sarif_gen_opts); - diagnostic_buffer buf_a (dc); - diagnostic_buffer buf_b (dc); + diagnostics::buffer buf_a (dc); + diagnostics::buffer buf_b (dc); rich_location rich_loc (line_table, UNKNOWN_LOCATION); @@ -5052,7 +5056,7 @@ run_line_table_case_tests_per_version (const line_table_case &case_) /* Run all of the selftests within this file. */ void -diagnostic_format_sarif_cc_tests () +diagnostics_sarif_sink_cc_tests () { test_sarif_array_of_unique_1 (); test_sarif_array_of_unique_2 (); diff --git a/gcc/diagnostic-format-sarif.h b/gcc/diagnostics/sarif-sink.h similarity index 78% rename from gcc/diagnostic-format-sarif.h rename to gcc/diagnostics/sarif-sink.h index b5efd7aab578..f4eda7b5fbfa 100644 --- a/gcc/diagnostic-format-sarif.h +++ b/gcc/diagnostics/sarif-sink.h @@ -18,14 +18,22 @@ You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see . */ -#ifndef GCC_DIAGNOSTIC_FORMAT_SARIF_H -#define GCC_DIAGNOSTIC_FORMAT_SARIF_H +#ifndef GCC_DIAGNOSTICS_SARIF_SINK_H +#define GCC_DIAGNOSTICS_SARIF_SINK_H #include "json.h" -#include "diagnostic-format.h" +#include "diagnostics/sink.h" #include "diagnostics/output-file.h" #include "diagnostics/logical-locations.h" +namespace diagnostics { + +namespace digraphs { + class digraph; + class node; + class edge; +} + /* Enum for choosing what format to serializing the generated SARIF into. */ enum class sarif_serialization_kind @@ -36,25 +44,25 @@ enum class sarif_serialization_kind }; extern diagnostics::output_file -diagnostic_output_format_open_sarif_file (diagnostic_context &context, - line_maps *line_maps, - const char *base_file_name, - enum sarif_serialization_kind serialization_kind); - -extern diagnostic_output_format & -diagnostic_output_format_init_sarif_stderr (diagnostic_context &context, - const line_maps *line_maps, - bool formatted); -extern diagnostic_output_format & -diagnostic_output_format_init_sarif_file (diagnostic_context &context, - line_maps *line_maps, - bool formatted, - const char *base_file_name); -extern diagnostic_output_format & -diagnostic_output_format_init_sarif_stream (diagnostic_context &context, - const line_maps *line_maps, - bool formatted, - FILE *stream); +open_sarif_output_file (diagnostic_context &context, + line_maps *line_maps, + const char *base_file_name, + enum sarif_serialization_kind serialization_kind); + +extern sink & +init_sarif_stderr (diagnostic_context &context, + const line_maps *line_maps, + bool formatted); +extern sink & +init_sarif_file (diagnostic_context &context, + line_maps *line_maps, + bool formatted, + const char *base_file_name); +extern sink & +init_sarif_stream (diagnostic_context &context, + const line_maps *line_maps, + bool formatted, + FILE *stream); /* Abstract base class for handling JSON output vs other kinds of serialization of the json tree. */ @@ -104,7 +112,7 @@ struct sarif_generation_options bool m_state_graph; }; -extern std::unique_ptr +extern std::unique_ptr make_sarif_sink (diagnostic_context &context, const line_maps &line_maps, std::unique_ptr serialization_format, @@ -114,13 +122,6 @@ make_sarif_sink (diagnostic_context &context, class sarif_builder; class sarif_location_manager; -namespace diagnostics { -namespace digraphs { - class digraph; - class node; - class edge; -}} - /* Concrete subclass of json::object for SARIF property bags (SARIF v2.1.0 section 3.8). */ @@ -170,17 +171,19 @@ class sarif_edge : public sarif_object }; extern std::unique_ptr -make_sarif_graph (const diagnostics::digraphs::digraph &g, +make_sarif_graph (const digraphs::digraph &g, sarif_builder *builder, sarif_location_manager *sarif_location_mgr); extern std::unique_ptr -make_sarif_node (const diagnostics::digraphs::node &n, +make_sarif_node (const digraphs::node &n, sarif_builder *builder, sarif_location_manager *sarif_location_mgr); extern std::unique_ptr -make_sarif_edge (const diagnostics::digraphs::edge &e, +make_sarif_edge (const digraphs::edge &e, sarif_builder *builder); -#endif /* ! GCC_DIAGNOSTIC_FORMAT_SARIF_H */ +} // namespace diagnostics + +#endif /* ! GCC_DIAGNOSTICS_SARIF_SINK_H */ diff --git a/gcc/diagnostic-format.h b/gcc/diagnostics/sink.h similarity index 71% rename from gcc/diagnostic-format.h rename to gcc/diagnostics/sink.h index 113e7ba554a9..71e41330e236 100644 --- a/gcc/diagnostic-format.h +++ b/gcc/diagnostics/sink.h @@ -18,21 +18,23 @@ You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see . */ -#ifndef GCC_DIAGNOSTIC_FORMAT_H -#define GCC_DIAGNOSTIC_FORMAT_H +#ifndef GCC_DIAGNOSTICS_SINK_H +#define GCC_DIAGNOSTICS_SINK_H #include "diagnostic.h" -class diagnostic_per_format_buffer; +namespace diagnostics { + +class per_sink_buffer; /* Abstract base class for a particular output format for diagnostics; each value of -fdiagnostics-output-format= will have its own implementation. */ -class diagnostic_output_format +class sink { public: - virtual ~diagnostic_output_format () {} + virtual ~sink () {} virtual void dump (FILE *out, int indent) const; @@ -40,16 +42,16 @@ public: e.g. for titles of HTML, for SARIF's artifact metadata. */ virtual void set_main_input_filename (const char *) {} - /* Vfunc for making an appropriate diagnostic_per_format_buffer + /* Vfunc for making an appropriate per_sink_buffer subclass for this format. */ - virtual std::unique_ptr - make_per_format_buffer () = 0; + virtual std::unique_ptr + make_per_sink_buffer () = 0; - /* Vfunc to be called when call a diagnostic_buffer is set on - a diagnostic_context, to update this format. The per_format_buffer - will be one created by make_per_format_buffer above and thus be + /* Vfunc to be called when call a diagnostics::buffer is set on + a diagnostic_context, to update this format. The per_sink_buffer + will be one created by make_per_sink_buffer above and thus be of the correct subclass. */ - virtual void set_buffer (diagnostic_per_format_buffer *) = 0; + virtual void set_buffer (per_sink_buffer *) = 0; virtual void on_begin_group () = 0; virtual void on_end_group () = 0; @@ -61,7 +63,7 @@ public: virtual void on_report_verbatim (text_info &); - virtual void on_diagram (const diagnostics::diagram &diag) = 0; + virtual void on_diagram (const diagram &diag) = 0; virtual void after_diagnostic (const diagnostic_info &) = 0; virtual bool machine_readable_stderr_p () const = 0; virtual bool follows_reference_printer_p () const = 0; @@ -73,7 +75,7 @@ public: virtual void update_printer () = 0; virtual void - report_global_digraph (const diagnostics::digraphs::lazy_digraph &) = 0; + report_global_digraph (const digraphs::lazy_digraph &) = 0; diagnostic_context &get_context () const { return m_context; } pretty_printer *get_printer () const { return m_printer.get (); } @@ -86,7 +88,7 @@ public: void DEBUG_FUNCTION dump () const { dump (stderr, 0); } protected: - diagnostic_output_format (diagnostic_context &context) + sink (diagnostic_context &context) : m_context (context), m_printer (context.clone_printer ()) {} @@ -97,10 +99,12 @@ protected: }; extern void -diagnostic_output_format_init (diagnostic_context &, - const char *main_input_filename_, - const char *base_file_name, - enum diagnostics_output_format, - bool json_formatting); +output_format_init (diagnostic_context &, + const char *main_input_filename_, + const char *base_file_name, + enum diagnostics_output_format, + bool json_formatting); + +} // namespace diagnostics -#endif /* ! GCC_DIAGNOSTIC_FORMAT_H */ +#endif /* ! GCC_DIAGNOSTICS_SINK_H */ diff --git a/gcc/diagnostics/state-graphs-to-dot.cc b/gcc/diagnostics/state-graphs-to-dot.cc index c07ff41a5107..2d80e6b283f6 100644 --- a/gcc/diagnostics/state-graphs-to-dot.cc +++ b/gcc/diagnostics/state-graphs-to-dot.cc @@ -269,12 +269,12 @@ private: default: gcc_unreachable (); case style::h1: - // from diagnostic-format-html.cc: HTML_STYLE .linenum + // from diagnostics/html-sink.cc: HTML_STYLE .linenum bgcolor = "#0088ce"; color = "white"; break; case style::h2: - // from diagnostic-format-html.cc: HTML_STYLE .events-hdr + // from diagnostics/html-sink.cc: HTML_STYLE .events-hdr bgcolor = "#393f44"; // pf-black-800 color = "white"; break; diff --git a/gcc/diagnostic-format-text.cc b/gcc/diagnostics/text-sink.cc similarity index 83% rename from gcc/diagnostic-format-text.cc rename to gcc/diagnostics/text-sink.cc index f39381f1bd19..67da98cec0d8 100644 --- a/gcc/diagnostic-format-text.cc +++ b/gcc/diagnostics/text-sink.cc @@ -31,8 +31,8 @@ along with GCC; see the file COPYING3. If not see #include "diagnostics/paths.h" #include "diagnostics/client-data-hooks.h" #include "diagnostics/diagram.h" -#include "diagnostic-format-text.h" -#include "diagnostic-buffer.h" +#include "diagnostics/text-sink.h" +#include "diagnostics/buffering.h" #include "text-art/theme.h" /* Disable warnings about quoting issues in the pp_xxx calls below @@ -42,56 +42,55 @@ along with GCC; see the file COPYING3. If not see # pragma GCC diagnostic ignored "-Wformat-diag" #endif -using namespace diagnostics; +namespace diagnostics { -/* Concrete buffering implementation subclass for JSON output. */ +/* Concrete buffering implementation subclass for text output. */ -class diagnostic_text_format_buffer : public diagnostic_per_format_buffer +class text_sink_buffer : public per_sink_buffer { public: - friend class diagnostic_text_output_format; + friend class text_sink; - diagnostic_text_format_buffer (diagnostic_output_format &format); + text_sink_buffer (sink &sink_); void dump (FILE *out, int indent) const final override; bool empty_p () const final override; - void move_to (diagnostic_per_format_buffer &dest) final override; + void move_to (per_sink_buffer &dest) final override; void clear () final override; void flush () final override; private: - diagnostic_output_format &m_format; + sink &m_sink; output_buffer m_output_buffer; }; -/* class diagnostic_text_format_buffer : public diagnostic_per_format_buffer. */ +/* class text_sink_buffer : public per_sink_buffer. */ -diagnostic_text_format_buffer:: -diagnostic_text_format_buffer (diagnostic_output_format &format) -: m_format (format) +text_sink_buffer::text_sink_buffer (sink &sink_) +: m_sink (sink_) { m_output_buffer.m_flush_p = false; } void -diagnostic_text_format_buffer::dump (FILE *out, int indent) const +text_sink_buffer::dump (FILE *out, int indent) const { - fprintf (out, "%*sdiagnostic_text_format_buffer:\n", indent, ""); + fprintf (out, "%*stext_sink_buffer:\n", indent, ""); m_output_buffer.dump (out, indent + 2); } bool -diagnostic_text_format_buffer::empty_p () const +text_sink_buffer::empty_p () const { return output_buffer_last_position_in_text (&m_output_buffer) == nullptr; } void -diagnostic_text_format_buffer::move_to (diagnostic_per_format_buffer &base_dest) +text_sink_buffer::move_to (per_sink_buffer &base_dest) { - diagnostic_text_format_buffer &dest - = static_cast (base_dest); + text_sink_buffer &dest + = static_cast (base_dest); const char *str = output_buffer_formatted_text (&m_output_buffer); output_buffer_append_r (&dest.m_output_buffer, str, strlen (str)); @@ -101,9 +100,9 @@ diagnostic_text_format_buffer::move_to (diagnostic_per_format_buffer &base_dest) } void -diagnostic_text_format_buffer::clear () +text_sink_buffer::clear () { - pretty_printer *const pp = m_format.get_printer (); + pretty_printer *const pp = m_sink.get_printer (); output_buffer *const old_output_buffer = pp_buffer (pp); pp_buffer (pp) = &m_output_buffer; @@ -115,9 +114,9 @@ diagnostic_text_format_buffer::clear () } void -diagnostic_text_format_buffer::flush () +text_sink_buffer::flush () { - pretty_printer *const pp = m_format.get_printer (); + pretty_printer *const pp = m_sink.get_printer (); output_buffer *const old_output_buffer = pp_buffer (pp); pp_buffer (pp) = &m_output_buffer; @@ -128,9 +127,9 @@ diagnostic_text_format_buffer::flush () pp_buffer (pp) = old_output_buffer; } -/* class diagnostic_text_output_format : public diagnostic_output_format. */ +/* class diagnostics::text_sink : public diagnostics::sink. */ -diagnostic_text_output_format::~diagnostic_text_output_format () +text_sink::~text_sink () { /* Some of the errors may actually have been warnings. */ if (m_context.diagnostic_count (DK_WERROR)) @@ -157,13 +156,13 @@ diagnostic_text_output_format::~diagnostic_text_output_format () } void -diagnostic_text_output_format::dump (FILE *out, int indent) const +text_sink::dump (FILE *out, int indent) const { - fprintf (out, "%*sdiagnostic_text_output_format\n", indent, ""); + fprintf (out, "%*stext_sink\n", indent, ""); fprintf (out, "%*sm_follows_reference_printer: %s\n", indent, "", m_follows_reference_printer ? "true" : "false"); - diagnostic_output_format::dump (out, indent); + sink::dump (out, indent); fprintf (out, "%*ssaved_output_buffer:\n", indent + 2, ""); if (m_saved_output_buffer) m_saved_output_buffer->dump (out, indent + 4); @@ -172,10 +171,10 @@ diagnostic_text_output_format::dump (FILE *out, int indent) const } void -diagnostic_text_output_format::set_buffer (diagnostic_per_format_buffer *base) +text_sink::set_buffer (per_sink_buffer *base) { - diagnostic_text_format_buffer * const buffer - = static_cast (base); + text_sink_buffer * const buffer + = static_cast (base); pretty_printer *const pp = get_printer (); @@ -191,19 +190,18 @@ diagnostic_text_output_format::set_buffer (diagnostic_per_format_buffer *base) } } -std::unique_ptr -diagnostic_text_output_format::make_per_format_buffer () +std::unique_ptr +text_sink::make_per_sink_buffer () { - return std::make_unique (*this); + return std::make_unique (*this); } -/* Implementation of diagnostic_output_format::on_report_diagnostic vfunc +/* Implementation of diagnostics::sink::on_report_diagnostic vfunc for GCC's standard textual output. */ void -diagnostic_text_output_format:: -on_report_diagnostic (const diagnostic_info &diagnostic, - diagnostic_t orig_diag_kind) +text_sink::on_report_diagnostic (const diagnostic_info &diagnostic, + diagnostic_t orig_diag_kind) { pretty_printer *pp = get_printer (); @@ -253,14 +251,14 @@ on_report_diagnostic (const diagnostic_info &diagnostic, } void -diagnostic_text_output_format::on_report_verbatim (text_info &text) +text_sink::on_report_verbatim (text_info &text) { pp_format_verbatim (get_printer (), &text); pp_newline_and_flush (get_printer ()); } void -diagnostic_text_output_format::on_diagram (const diagnostics::diagram &d) +text_sink::on_diagram (const diagnostics::diagram &d) { pretty_printer *const pp = get_printer (); @@ -276,7 +274,7 @@ diagnostic_text_output_format::on_diagram (const diagnostics::diagram &d) } void -diagnostic_text_output_format:: +text_sink:: after_diagnostic (const diagnostic_info &diagnostic) { if (const paths::path *path = diagnostic.richloc->get_path ()) @@ -291,8 +289,7 @@ after_diagnostic (const diagnostic_info &diagnostic) The caller is responsible for freeing the memory. */ char * -diagnostic_text_output_format:: -build_prefix (const diagnostic_info &diagnostic) const +text_sink::build_prefix (const diagnostic_info &diagnostic) const { gcc_assert (diagnostic.kind < DK_LAST_DIAGNOSTIC_KIND); @@ -332,7 +329,7 @@ build_prefix (const diagnostic_info &diagnostic) const /* Same as build_prefix, but only the source FILE is given. */ char * -diagnostic_text_output_format::file_name_as_prefix (const char *f) const +text_sink::file_name_as_prefix (const char *f) const { pretty_printer *const pp = get_printer (); const char *locus_cs @@ -384,7 +381,7 @@ get_bullet_point_unichar (diagnostic_context &dc) The caller is responsible for freeing the memory. */ char * -diagnostic_text_output_format::build_indent_prefix (bool with_bullet) const +text_sink::build_indent_prefix (bool with_bullet) const { if (!m_show_nesting) return xstrdup (""); @@ -409,7 +406,7 @@ diagnostic_text_output_format::build_indent_prefix (bool with_bullet) const /* Add a purely textual note with text GMSGID and with LOCATION. */ void -diagnostic_text_output_format::append_note (location_t location, +text_sink::append_note (location_t location, const char * gmsgid, ...) { diagnostic_context *context = &get_context (); @@ -439,14 +436,13 @@ diagnostic_text_output_format::append_note (location_t location, } bool -diagnostic_text_output_format::follows_reference_printer_p () const +text_sink::follows_reference_printer_p () const { return m_follows_reference_printer; } void -diagnostic_text_output_format:: -update_printer () +text_sink::update_printer () { pretty_printer *copy_from_pp = (m_follows_reference_printer @@ -471,7 +467,7 @@ update_printer () description of the security issue. */ void -diagnostic_text_output_format::print_any_cwe (const diagnostic_info &diagnostic) +text_sink::print_any_cwe (const diagnostic_info &diagnostic) { if (!diagnostic.metadata) return; @@ -506,8 +502,7 @@ diagnostic_text_output_format::print_any_cwe (const diagnostic_info &diagnostic) with any URL provided by the rule. */ void -diagnostic_text_output_format:: -print_any_rules (const diagnostic_info &diagnostic) +text_sink::print_any_rules (const diagnostic_info &diagnostic) { if (!diagnostic.metadata) return; @@ -549,9 +544,8 @@ print_any_rules (const diagnostic_info &diagnostic) Subroutine of diagnostic_context::report_diagnostic. */ void -diagnostic_text_output_format:: -print_option_information (const diagnostic_info &diagnostic, - diagnostic_t orig_diag_kind) +text_sink::print_option_information (const diagnostic_info &diagnostic, + diagnostic_t orig_diag_kind) { if (char *option_text = m_context.make_option_name (diagnostic.option_id, @@ -581,7 +575,7 @@ print_option_information (const diagnostic_info &diagnostic, /* Only dump the "In file included from..." stack once for each file. */ bool -diagnostic_text_output_format::includes_seen_p (const line_map_ordinary *map) +text_sink::includes_seen_p (const line_map_ordinary *map) { /* No include path for main. */ if (MAIN_FILE_P (map)) @@ -604,8 +598,7 @@ diagnostic_text_output_format::includes_seen_p (const line_map_ordinary *map) } label_text -diagnostic_text_output_format:: -get_location_text (const expanded_location &s) const +text_sink::get_location_text (const expanded_location &s) const { diagnostic_column_policy column_policy (get_context ()); return column_policy.get_location_text (s, @@ -638,7 +631,7 @@ maybe_line_and_column (int line, int col) } void -diagnostic_text_output_format::report_current_module (location_t where) +text_sink::report_current_module (location_t where) { pretty_printer *pp = get_printer (); const line_map_ordinary *map = nullptr; @@ -706,8 +699,8 @@ diagnostic_text_output_format::report_current_module (location_t where) } void -default_diagnostic_text_starter (diagnostic_text_output_format &text_output, - const diagnostic_info *diagnostic) +default_text_starter (text_sink &text_output, + const diagnostic_info *diagnostic) { text_output.report_current_module (diagnostic_location (diagnostic)); pretty_printer *const pp = text_output.get_printer (); @@ -715,9 +708,9 @@ default_diagnostic_text_starter (diagnostic_text_output_format &text_output, } void -default_diagnostic_text_finalizer (diagnostic_text_output_format &text_output, - const diagnostic_info *diagnostic, - diagnostic_t) +default_text_finalizer (text_sink &text_output, + const diagnostic_info *diagnostic, + diagnostic_t) { pretty_printer *const pp = text_output.get_printer (); char *saved_prefix = pp_take_prefix (pp); @@ -733,3 +726,5 @@ default_diagnostic_text_finalizer (diagnostic_text_output_format &text_output, #if __GNUC__ >= 10 # pragma GCC diagnostic pop #endif + +} // namespace diagnostics diff --git a/gcc/diagnostic-format-text.h b/gcc/diagnostics/text-sink.h similarity index 84% rename from gcc/diagnostic-format-text.h rename to gcc/diagnostics/text-sink.h index d4771967ff71..e54a85d87cc7 100644 --- a/gcc/diagnostic-format-text.h +++ b/gcc/diagnostics/text-sink.h @@ -18,24 +18,26 @@ You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see . */ -#ifndef GCC_DIAGNOSTIC_FORMAT_TEXT_H -#define GCC_DIAGNOSTIC_FORMAT_TEXT_H +#ifndef GCC_DIAGNOSTICS_TEXT_SINK_H +#define GCC_DIAGNOSTICS_TEXT_SINK_H -#include "diagnostic-format.h" +#include "diagnostics/sink.h" -/* Subclass of diagnostic_output_format for classic text-based output +namespace diagnostics { + +/* Subclass of diagnostics::sink for classic text-based output to stderr. Uses diagnostic_context.m_text_callbacks to provide client-specific textual output (e.g. include paths, macro expansions, etc). */ -class diagnostic_text_output_format : public diagnostic_output_format +class text_sink : public sink { public: - diagnostic_text_output_format (diagnostic_context &context, - diagnostic_source_printing_options *source_printing = nullptr, - bool follows_reference_printer = false) - : diagnostic_output_format (context), + text_sink (diagnostic_context &context, + diagnostic_source_printing_options *source_printing = nullptr, + bool follows_reference_printer = false) + : sink (context), m_saved_output_buffer (nullptr), m_column_policy (context), m_last_module (nullptr), @@ -47,20 +49,20 @@ public: m_show_nesting (false), m_show_nesting_levels (false) {} - ~diagnostic_text_output_format (); + ~text_sink (); void dump (FILE *out, int indent) const override; - std::unique_ptr - make_per_format_buffer () final override; - void set_buffer (diagnostic_per_format_buffer *) final override; + std::unique_ptr + make_per_sink_buffer () final override; + void set_buffer (per_sink_buffer *) final override; void on_begin_group () override {} void on_end_group () override {} void on_report_diagnostic (const diagnostic_info &, diagnostic_t orig_diag_kind) override; void on_report_verbatim (text_info &) final override; - void on_diagram (const diagnostics::diagram &d) override; + void on_diagram (const diagram &d) override; void after_diagnostic (const diagnostic_info &) override; bool machine_readable_stderr_p () const final override { @@ -71,7 +73,7 @@ public: void update_printer () override; void - report_global_digraph (const diagnostics::digraphs::lazy_digraph &) final override + report_global_digraph (const digraphs::lazy_digraph &) final override { // no-op for text } @@ -87,7 +89,7 @@ public: char *build_indent_prefix (bool with_bullet) const; - void print_path (const diagnostics::paths::path &path); + void print_path (const paths::path &path); bool show_column_p () const { return get_context ().m_show_column; } @@ -168,4 +170,6 @@ protected: bool m_show_nesting_levels; }; -#endif /* ! GCC_DIAGNOSTIC_FORMAT_TEXT_H */ +} // namespace diagnostics + +#endif /* ! GCC_DIAGNOSTICS_TEXT_SINK_H */ diff --git a/gcc/fortran/error.cc b/gcc/fortran/error.cc index 004a4b26c2f4..98c67fd952ff 100644 --- a/gcc/fortran/error.cc +++ b/gcc/fortran/error.cc @@ -33,7 +33,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic.h" #include "diagnostic-color.h" #include "tree-diagnostic.h" /* tree_diagnostics_defaults */ -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" static int suppress_errors = 0; @@ -43,7 +43,7 @@ static bool warnings_not_errors = false; static bool buffered_p; static gfc_error_buffer *error_buffer; -static diagnostic_buffer *pp_error_buffer, *pp_warning_buffer; +static diagnostics::buffer *pp_error_buffer, *pp_warning_buffer; gfc_error_buffer::gfc_error_buffer () : flag (false), buffer (*global_dc) @@ -228,7 +228,7 @@ gfc_print_wide_char (gfc_char_t c) it to global_dc. */ static void -gfc_clear_diagnostic_buffer (diagnostic_buffer *this_buffer) +gfc_clear_diagnostic_buffer (diagnostics::buffer *this_buffer) { gcc_assert (this_buffer); global_dc->clear_diagnostic_buffer (*this_buffer); @@ -263,7 +263,7 @@ gfc_warning (int opt, const char *gmsgid, va_list ap) diagnostic_info diagnostic; rich_location rich_loc (line_table, UNKNOWN_LOCATION); - diagnostic_buffer *old_buffer = global_dc->get_diagnostic_buffer (); + diagnostics::buffer *old_buffer = global_dc->get_diagnostic_buffer (); gcc_assert (!old_buffer); gfc_clear_diagnostic_buffer (pp_warning_buffer); @@ -548,7 +548,7 @@ gfc_diagnostic_build_locus_prefix (const diagnostic_location_print_policy &loc_p [locus of primary range]: Error: Some error at (1) and (2) */ static void -gfc_diagnostic_text_starter (diagnostic_text_output_format &text_output, +gfc_diagnostic_text_starter (diagnostics::text_sink &text_output, const diagnostic_info *diagnostic) { diagnostic_context *const context = &text_output.get_context (); @@ -634,7 +634,7 @@ gfc_diagnostic_start_span (const diagnostic_location_print_policy &loc_policy, static void -gfc_diagnostic_text_finalizer (diagnostic_text_output_format &text_output, +gfc_diagnostic_text_finalizer (diagnostics::text_sink &text_output, const diagnostic_info *diagnostic ATTRIBUTE_UNUSED, diagnostic_t orig_diag_kind ATTRIBUTE_UNUSED) { @@ -778,7 +778,7 @@ gfc_error_opt (int opt, const char *gmsgid, va_list ap) diagnostic_info diagnostic; rich_location richloc (line_table, UNKNOWN_LOCATION); - diagnostic_buffer *old_buffer = global_dc->get_diagnostic_buffer (); + diagnostics::buffer *old_buffer = global_dc->get_diagnostic_buffer (); gcc_assert (!old_buffer); gfc_clear_diagnostic_buffer (pp_error_buffer); @@ -885,8 +885,8 @@ static void gfc_move_error_buffer_from_to (gfc_error_buffer * buffer_from, gfc_error_buffer * buffer_to) { - diagnostic_buffer * from = &(buffer_from->buffer); - diagnostic_buffer * to = &(buffer_to->buffer); + diagnostics::buffer * from = &(buffer_from->buffer); + diagnostics::buffer * to = &(buffer_to->buffer); buffer_to->flag = buffer_from->flag; buffer_from->flag = false; @@ -956,7 +956,7 @@ gfc_diagnostics_init (void) global_dc->set_format_decoder (gfc_format_decoder); global_dc->m_source_printing.caret_chars[0] = '1'; global_dc->m_source_printing.caret_chars[1] = '2'; - pp_warning_buffer = new diagnostic_buffer (*global_dc); + pp_warning_buffer = new diagnostics::buffer (*global_dc); error_buffer = new gfc_error_buffer (); pp_error_buffer = &(error_buffer->buffer); } diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index d85095c4da91..85feb18be8ca 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -3594,11 +3594,11 @@ bool gfc_notify_std (int, const char *, ...) ATTRIBUTE_GCC_GFC(2,3); #define gfc_syntax_error(ST) \ gfc_error ("Syntax error in %s statement at %C", gfc_ascii_statement (ST)); -#include "diagnostic-buffer.h" /* For diagnostic_buffer. */ +#include "diagnostics/buffering.h" /* For diagnostics::buffer. */ struct gfc_error_buffer { bool flag; - diagnostic_buffer buffer; + diagnostics::buffer buffer; gfc_error_buffer(); }; diff --git a/gcc/gcc.cc b/gcc/gcc.cc index 235fe8019880..6227c32d7822 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -43,7 +43,7 @@ compilation is specified by a string called a "spec". */ #include "opt-suggestions.h" #include "gcc.h" #include "diagnostic.h" -#include "diagnostic-format.h" +#include "diagnostics/sink.h" #include "pretty-print-urlifier.h" #include "flags.h" #include "opts.h" @@ -4367,10 +4367,10 @@ driver_handle_option (struct gcc_options *opts, const char *basename = (opts->x_dump_base_name ? opts->x_dump_base_name : opts->x_main_input_basename); gcc_assert (dc); - diagnostic_output_format_init (*dc, - opts->x_main_input_filename, basename, - (enum diagnostics_output_format)value, - opts->x_flag_diagnostics_json_formatting); + diagnostics::output_format_init (*dc, + opts->x_main_input_filename, basename, + (enum diagnostics_output_format)value, + opts->x_flag_diagnostics_json_formatting); break; } diff --git a/gcc/jit/dummy-frontend.cc b/gcc/jit/dummy-frontend.cc index bf31a9db83c6..e6ad4cf91fbb 100644 --- a/gcc/jit/dummy-frontend.cc +++ b/gcc/jit/dummy-frontend.cc @@ -32,7 +32,7 @@ along with GCC; see the file COPYING3. If not see #include "attribs.h" #include "cgraph.h" #include "target.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" #include "print-tree.h" #include @@ -993,16 +993,16 @@ struct ggc_root_tab jit_root_tab[] = LAST_GGC_ROOT_TAB }; -/* Subclass of diagnostic_output_format for libgccjit: like text +/* Subclass of diagnostics::text_sink for libgccjit: like text output, but capture the message and call add_diagnostic with it on the active playback context. */ -class jit_diagnostic_listener : public diagnostic_text_output_format +class jit_diagnostic_listener : public diagnostics::text_sink { public: jit_diagnostic_listener (diagnostic_context &dc, gcc::jit::playback::context &playback_ctxt) - : diagnostic_text_output_format (dc), + : diagnostics::text_sink (dc), m_playback_ctxt (playback_ctxt) { } @@ -1021,7 +1021,7 @@ public: JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ()); /* Let the text output format do most of the work. */ - diagnostic_text_output_format::on_report_diagnostic (info, orig_diag_kind); + diagnostics::text_sink::on_report_diagnostic (info, orig_diag_kind); const char *text = pp_formatted_text (get_printer ()); @@ -1041,7 +1041,7 @@ private: /* Implementation of "begin_diagnostic". */ static void -jit_begin_diagnostic (diagnostic_text_output_format &, +jit_begin_diagnostic (diagnostics::text_sink &, const diagnostic_info */*diagnostic*/) { gcc_assert (gcc::jit::active_playback_ctxt); @@ -1054,7 +1054,7 @@ jit_begin_diagnostic (diagnostic_text_output_format &, /* Implementation of "end_diagnostic". */ static void -jit_end_diagnostic (diagnostic_text_output_format &, +jit_end_diagnostic (diagnostics::text_sink &, const diagnostic_info *, diagnostic_t) { @@ -1087,7 +1087,7 @@ jit_langhook_init (void) = std::make_unique (*global_dc, *gcc::jit::active_playback_ctxt); - global_dc->set_output_format (std::move (sink)); + global_dc->set_sink (std::move (sink)); build_common_tree_nodes (flag_signed_char); diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h index 010aaedd9de1..e03f00aa0302 100644 --- a/gcc/langhooks-def.h +++ b/gcc/langhooks-def.h @@ -49,7 +49,7 @@ extern void lhd_print_tree_nothing (FILE *, tree, int); extern const char *lhd_decl_printable_name (tree, int); extern const char *lhd_dwarf_name (tree, int); extern int lhd_types_compatible_p (tree, tree); -extern void lhd_print_error_function (diagnostic_text_output_format &, +extern void lhd_print_error_function (diagnostics::text_sink &, const char *, const struct diagnostic_info *); extern void lhd_set_decl_assembler_name (tree decl); diff --git a/gcc/langhooks.cc b/gcc/langhooks.cc index 194701fc6c99..95ea94cce349 100644 --- a/gcc/langhooks.cc +++ b/gcc/langhooks.cc @@ -38,7 +38,7 @@ along with GCC; see the file COPYING3. If not see #include "stor-layout.h" #include "cgraph.h" #include "debug.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" /* Do nothing; in many cases the default hook. */ @@ -369,7 +369,7 @@ lhd_handle_option (size_t code ATTRIBUTE_UNUSED, /* The default function to print out name of current function that caused an error. */ void -lhd_print_error_function (diagnostic_text_output_format &text_output, +lhd_print_error_function (diagnostics::text_sink &text_output, const char *file, const diagnostic_info *diagnostic) { diff --git a/gcc/langhooks.h b/gcc/langhooks.h index cb03c8348e3c..7433170e997d 100644 --- a/gcc/langhooks.h +++ b/gcc/langhooks.h @@ -547,7 +547,7 @@ struct lang_hooks /* Called by diagnostic_report_current_function to print out function name for textual diagnostic output. */ - void (*print_error_function) (diagnostic_text_output_format &, + void (*print_error_function) (diagnostics::text_sink &, const char *, const struct diagnostic_info *); diff --git a/gcc/libgdiagnostics.cc b/gcc/libgdiagnostics.cc index bc309c10c4e8..67420c700b6b 100644 --- a/gcc/libgdiagnostics.cc +++ b/gcc/libgdiagnostics.cc @@ -30,8 +30,8 @@ along with GCC; see the file COPYING3. If not see #include "diagnostics/metadata.h" #include "diagnostics/paths.h" #include "diagnostics/client-data-hooks.h" -#include "diagnostic-format-sarif.h" -#include "diagnostic-format-text.h" +#include "diagnostics/sarif-sink.h" +#include "diagnostics/text-sink.h" #include "diagnostics/output-spec.h" #include "diagnostics/digraphs.h" #include "diagnostics/state-graphs.h" @@ -241,11 +241,11 @@ public: set_colorize (enum diagnostic_colorize colorize); static void - text_starter (diagnostic_text_output_format &text_output, + text_starter (diagnostics::text_sink &text_output, const diagnostic_info *diagnostic); private: - diagnostic_text_output_format *m_inner_sink; // borrowed from dc + diagnostics::text_sink *m_inner_sink; // borrowed from dc diagnostic_source_printing_options m_source_printing; }; @@ -346,7 +346,7 @@ public: sarif_sink (diagnostic_manager &mgr, FILE *dst_stream, const diagnostic_file *main_input_file, - const sarif_generation_options &sarif_gen_opts); + const diagnostics::sarif_generation_options &sarif_gen_opts); }; struct diagnostic_message_buffer @@ -588,7 +588,8 @@ public: const char * maybe_get_sarif_source_language (const char *filename) const final override; - void add_sarif_invocation_properties (sarif_object &invocation_obj) + void + add_sarif_invocation_properties (diagnostics::sarif_object &invocation_obj) const final override; private: @@ -1398,7 +1399,7 @@ maybe_get_sarif_source_language (const char *filename) const void impl_diagnostic_client_data_hooks:: -add_sarif_invocation_properties (sarif_object &) const +add_sarif_invocation_properties (diagnostics::sarif_object &) const { // No-op. } @@ -1412,7 +1413,7 @@ diagnostic_text_sink::diagnostic_text_sink (diagnostic_manager &mgr, m_source_printing (mgr.get_dc ().m_source_printing) { auto inner_sink - = std::make_unique (mgr.get_dc (), + = std::make_unique (mgr.get_dc (), &m_source_printing); inner_sink->get_printer ()->set_output_stream (dst_stream); m_inner_sink = inner_sink.get (); @@ -1442,7 +1443,7 @@ diagnostic_text_sink::set_colorize (enum diagnostic_colorize colorize) } void -diagnostic_text_sink::text_starter (diagnostic_text_output_format &text_output, +diagnostic_text_sink::text_starter (diagnostics::text_sink &text_output, const diagnostic_info *info) { gcc_assert (info->x_data); @@ -1512,15 +1513,17 @@ diagnostic_text_sink::text_starter (diagnostic_text_output_format &text_output, /* class sarif_sink : public sink. */ -sarif_sink::sarif_sink (diagnostic_manager &mgr, - FILE *dst_stream, - const diagnostic_file *main_input_file, - const sarif_generation_options &sarif_gen_opts) +sarif_sink:: +sarif_sink (diagnostic_manager &mgr, + FILE *dst_stream, + const diagnostic_file *main_input_file, + const diagnostics::sarif_generation_options &sarif_gen_opts) : sink (mgr) { diagnostics::output_file output_file (dst_stream, false, label_text::borrow ("sarif_sink")); - auto serialization = std::make_unique (true); + auto serialization + = std::make_unique (true); auto inner_sink = make_sarif_sink (mgr.get_dc (), *mgr.get_line_table (), std::move (serialization), @@ -1818,7 +1821,7 @@ diagnostic_manager_add_sarif_sink (diagnostic_manager *diag_mgr, FAIL_IF_NULL (dst_stream); FAIL_IF_NULL (main_input_file); - sarif_generation_options sarif_gen_opts; + diagnostics::sarif_generation_options sarif_gen_opts; switch (version) { default: @@ -1826,10 +1829,11 @@ diagnostic_manager_add_sarif_sink (diagnostic_manager *diag_mgr, __func__, (int)version); abort (); case DIAGNOSTIC_SARIF_VERSION_2_1_0: - sarif_gen_opts.m_version = sarif_version::v2_1_0; + sarif_gen_opts.m_version = diagnostics::sarif_version::v2_1_0; break; case DIAGNOSTIC_SARIF_VERSION_2_2_PRERELEASE: - sarif_gen_opts.m_version = sarif_version::v2_2_prerelease_2024_08_08; + sarif_gen_opts.m_version + = diagnostics::sarif_version::v2_2_prerelease_2024_08_08; break; } @@ -1963,8 +1967,8 @@ diagnostic_manager_debug_dump_location (const diagnostic_manager *diag_mgr, diagnostic_initialize (&dc, 0); dc.m_show_column = true; - diagnostic_text_output_format text_format (dc); - label_text loc_text = text_format.get_location_text (exp_loc); + diagnostics::text_sink text_output (dc); + label_text loc_text = text_output.get_location_text (exp_loc); fprintf (out, "%s", loc_text.get ()); diagnostic_finish (&dc); diff --git a/gcc/opts-diagnostic.cc b/gcc/opts-diagnostic.cc index 9c08f8b647da..0c4b5e182ab3 100644 --- a/gcc/opts-diagnostic.cc +++ b/gcc/opts-diagnostic.cc @@ -103,5 +103,5 @@ handle_OPT_fdiagnostics_set_output_ (const gcc_options &opts, return; sink->set_main_input_filename (opts.x_main_input_filename); - dc.set_output_format (std::move (sink)); + dc.set_sink (std::move (sink)); } diff --git a/gcc/opts.cc b/gcc/opts.cc index 063fbd01ba8b..341f0e3284bb 100644 --- a/gcc/opts.cc +++ b/gcc/opts.cc @@ -32,7 +32,7 @@ along with GCC; see the file COPYING3. If not see #include "spellcheck.h" #include "opt-suggestions.h" #include "diagnostic-color.h" -#include "diagnostic-format.h" +#include "diagnostics/sink.h" #include "version.h" #include "selftest.h" #include "file-prefix-map.h" @@ -2985,10 +2985,10 @@ common_handle_option (struct gcc_options *opts, const char *basename = (opts->x_dump_base_name ? opts->x_dump_base_name : opts->x_main_input_basename); gcc_assert (dc); - diagnostic_output_format_init (*dc, - opts->x_main_input_filename, basename, - (enum diagnostics_output_format)value, - opts->x_flag_diagnostics_json_formatting); + diagnostics::output_format_init (*dc, + opts->x_main_input_filename, basename, + (enum diagnostics_output_format)value, + opts->x_flag_diagnostics_json_formatting); break; } diff --git a/gcc/rust/resolve/rust-ice-finalizer.cc b/gcc/rust/resolve/rust-ice-finalizer.cc index bd4763f8c76c..9e71531a6add 100644 --- a/gcc/rust/resolve/rust-ice-finalizer.cc +++ b/gcc/rust/resolve/rust-ice-finalizer.cc @@ -22,12 +22,12 @@ namespace Rust { namespace Resolver { void ATTRIBUTE_NORETURN -funny_ice_text_finalizer (diagnostic_text_output_format &text_output, +funny_ice_text_finalizer (diagnostics::text_sink &text_output, const diagnostic_info *diagnostic, diagnostic_t diag_kind) { gcc_assert (diag_kind == DK_ICE_NOBT); - default_diagnostic_text_finalizer (text_output, diagnostic, diag_kind); + diagnostics::default_text_finalizer (text_output, diagnostic, diag_kind); fnotice (stderr, "You have broken GCC Rust. This is a feature.\n"); exit (ICE_EXIT_CODE); } diff --git a/gcc/rust/resolve/rust-ice-finalizer.h b/gcc/rust/resolve/rust-ice-finalizer.h index 85ab88ff7146..6759e67c739c 100644 --- a/gcc/rust/resolve/rust-ice-finalizer.h +++ b/gcc/rust/resolve/rust-ice-finalizer.h @@ -55,7 +55,7 @@ namespace Resolver { the default bug reporting instructions, as there is no bug to report. */ void ATTRIBUTE_NORETURN -funny_ice_text_finalizer (diagnostic_text_output_format &text_output, +funny_ice_text_finalizer (diagnostics::text_sink &text_output, const diagnostic_info *diagnostic, diagnostic_t diag_kind); diff --git a/gcc/selftest-diagnostic.cc b/gcc/selftest-diagnostic.cc index 3687d603941f..2f16d0a3fc81 100644 --- a/gcc/selftest-diagnostic.cc +++ b/gcc/selftest-diagnostic.cc @@ -21,7 +21,7 @@ along with GCC; see the file COPYING3. If not see #include "system.h" #include "coretypes.h" #include "diagnostic.h" -#include "diagnostic-format.h" +#include "diagnostics/sink.h" #include "selftest.h" #include "selftest-diagnostic.h" @@ -44,7 +44,7 @@ test_diagnostic_context::test_diagnostic_context () diagnostic_start_span (this) = start_span_cb; m_source_printing.min_margin_width = 6; m_source_printing.max_width = 80; - pp_buffer (get_output_format (0).get_printer ())->m_flush_p = false; + pp_buffer (get_sink (0).get_printer ())->m_flush_p = false; } test_diagnostic_context::~test_diagnostic_context () @@ -62,7 +62,7 @@ start_span_cb (const diagnostic_location_print_policy &loc_policy, expanded_location exploc) { exploc.file = "FILENAME"; - default_diagnostic_start_span_fn (loc_policy, sink, exploc); + diagnostics::default_start_span_fn (loc_policy, sink, exploc); } bool diff --git a/gcc/selftest-run-tests.cc b/gcc/selftest-run-tests.cc index ec34cb774c7e..956be00114be 100644 --- a/gcc/selftest-run-tests.cc +++ b/gcc/selftest-run-tests.cc @@ -100,8 +100,8 @@ selftest::run_tests () rely on. */ diagnostic_color_cc_tests (); diagnostic_show_locus_cc_tests (); - diagnostic_format_html_cc_tests (); - diagnostic_format_sarif_cc_tests (); + diagnostics_html_sink_cc_tests (); + diagnostics_sarif_sink_cc_tests (); diagnostics_digraphs_cc_tests (); diagnostics_output_spec_cc_tests (); diagnostics_state_graphs_cc_tests (); diff --git a/gcc/selftest.h b/gcc/selftest.h index 9ca67d9e42ea..d21abe369187 100644 --- a/gcc/selftest.h +++ b/gcc/selftest.h @@ -222,13 +222,13 @@ extern void cgraph_cc_tests (); extern void convert_cc_tests (); extern void dbgcnt_cc_tests (); extern void diagnostic_color_cc_tests (); -extern void diagnostic_format_html_cc_tests (); -extern void diagnostic_format_sarif_cc_tests (); extern void diagnostic_show_locus_cc_tests (); extern void diagnostics_digraphs_cc_tests (); +extern void diagnostics_html_sink_cc_tests (); extern void diagnostics_lazy_paths_cc_tests (); extern void diagnostics_output_spec_cc_tests (); extern void diagnostics_paths_output_cc_tests (); +extern void diagnostics_sarif_sink_cc_tests (); extern void diagnostics_selftest_logical_locations_cc_tests (); extern void diagnostics_state_graphs_cc_tests (); extern void digraph_cc_tests (); diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.cc index 4ade2328dd51..d1bdb09fd2ef 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.cc @@ -27,7 +27,7 @@ #include "plugin-version.h" #include "c-family/c-common.h" #include "diagnostic.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" #include "context.h" int plugin_is_GPL_compatible; @@ -165,7 +165,7 @@ pass_test_groups::execute (function *fun) expected output. */ void -test_diagnostic_text_starter (diagnostic_text_output_format &text_output, +test_diagnostic_text_starter (diagnostics::text_sink &text_output, const diagnostic_info *diagnostic) { pp_set_prefix (text_output.get_printer (), xstrdup ("PREFIX: ")); @@ -184,13 +184,13 @@ test_diagnostic_start_span_fn (const diagnostic_location_print_policy &, pp_newline (pp); } -/* Custom output format subclass. */ +/* Custom text_sink subclass. */ -class test_output_format : public diagnostic_text_output_format +class custom_test_sink : public diagnostics::text_sink { public: - test_output_format (diagnostic_context &context) - : diagnostic_text_output_format (context) + custom_test_sink (diagnostic_context &context) + : diagnostics::text_sink (context) {} void on_begin_group () final override @@ -230,8 +230,7 @@ plugin_init (struct plugin_name_args *plugin_info, diagnostic_text_starter (global_dc) = test_diagnostic_text_starter; diagnostic_start_span (global_dc) = test_diagnostic_start_span_fn; - global_dc->set_output_format - (::std::make_unique (*global_dc)); + global_dc->set_sink (::std::make_unique (*global_dc)); pass_info.pass = new pass_test_groups (g); pass_info.reference_pass_name = "*warn_function_noreturn"; diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc index cd3834b21000..4d2057c5e602 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc @@ -62,7 +62,7 @@ #include "print-tree.h" #include "gcc-rich-location.h" #include "text-range-label.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" int plugin_is_GPL_compatible; @@ -125,12 +125,12 @@ static bool force_show_locus_color = false; /* We want to verify the colorized output of diagnostic_show_locus, but turning on colorization for everything confuses "dg-warning" etc. Hence we special-case it within this plugin by using this modified - version of default_diagnostic_text_finalizer, which, if "color" is + version of diagnostics::default_text_finalizer, which, if "color" is passed in as a plugin argument turns on colorization, but just for diagnostic_show_locus. */ static void -custom_diagnostic_text_finalizer (diagnostic_text_output_format &text_output, +custom_diagnostic_text_finalizer (diagnostics::text_sink &text_output, const diagnostic_info *diagnostic, diagnostic_t) { diff --git a/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.cc b/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.cc index f770d35ea518..89d6590512da 100644 --- a/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.cc @@ -7,7 +7,7 @@ #include "coretypes.h" #include "spellcheck.h" #include "diagnostic.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" int plugin_is_GPL_compatible; @@ -42,7 +42,7 @@ on_pragma_registration (void */*gcc_data*/, void */*user_data*/) static diagnostic_text_finalizer_fn original_text_finalizer = NULL; static void -verify_unpacked_ranges (diagnostic_text_output_format &text_output, +verify_unpacked_ranges (diagnostics::text_sink &text_output, const diagnostic_info *diagnostic, diagnostic_t orig_diag_kind) { @@ -56,7 +56,7 @@ verify_unpacked_ranges (diagnostic_text_output_format &text_output, } static void -verify_no_columns (diagnostic_text_output_format &text_output, +verify_no_columns (diagnostics::text_sink &text_output, const diagnostic_info *diagnostic, diagnostic_t orig_diag_kind) { diff --git a/gcc/tree-diagnostic-client-data-hooks.cc b/gcc/tree-diagnostic-client-data-hooks.cc index 2010600bf787..84fbb7921f56 100644 --- a/gcc/tree-diagnostic-client-data-hooks.cc +++ b/gcc/tree-diagnostic-client-data-hooks.cc @@ -27,7 +27,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic.h" #include "tree-logical-location.h" #include "diagnostics/client-data-hooks.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/sarif-sink.h" #include "langhooks.h" #include "plugin.h" #include "timevar.h" @@ -143,13 +143,13 @@ public: } void - add_sarif_invocation_properties (sarif_object &invocation_obj) + add_sarif_invocation_properties (diagnostics::sarif_object &invocation_obj) const final override { if (g_timer) if (auto timereport_val = g_timer->make_json ()) { - sarif_property_bag &bag_obj + auto &bag_obj = invocation_obj.get_or_create_properties (); bag_obj.set ("gcc/timeReport", std::move (timereport_val)); diff --git a/gcc/tree-diagnostic.cc b/gcc/tree-diagnostic.cc index 34c3de85d2e3..3f706ac04f00 100644 --- a/gcc/tree-diagnostic.cc +++ b/gcc/tree-diagnostic.cc @@ -30,12 +30,12 @@ along with GCC; see the file COPYING3. If not see #include "diagnostics/client-data-hooks.h" #include "langhooks.h" #include "intl.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" /* Prints out, if necessary, the name of the current function that caused an error. */ void -diagnostic_report_current_function (diagnostic_text_output_format &text_output, +diagnostic_report_current_function (diagnostics::text_sink &text_output, const diagnostic_info *diagnostic) { location_t loc = diagnostic_location (diagnostic); @@ -44,7 +44,7 @@ diagnostic_report_current_function (diagnostic_text_output_format &text_output, } static void -default_tree_diagnostic_text_starter (diagnostic_text_output_format &text_output, +default_tree_diagnostic_text_starter (diagnostics::text_sink &text_output, const diagnostic_info *diagnostic) { pretty_printer *const pp = text_output.get_printer (); @@ -178,7 +178,7 @@ void tree_diagnostics_defaults (diagnostic_context *context) { diagnostic_text_starter (context) = default_tree_diagnostic_text_starter; - diagnostic_text_finalizer (context) = default_diagnostic_text_finalizer; + diagnostic_text_finalizer (context) = diagnostics::default_text_finalizer; context->set_format_decoder (default_tree_printer); context->set_set_locations_callback (set_inlining_locations); context->set_client_data_hooks (make_compiler_data_hooks ()); diff --git a/libcc1/context.cc b/libcc1/context.cc index af5884b3db99..6cfe254f9b05 100644 --- a/libcc1/context.cc +++ b/libcc1/context.cc @@ -39,7 +39,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic.h" #include "langhooks.h" #include "langhooks-def.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" #include "gcc-interface.h" @@ -63,7 +63,7 @@ cc1_plugin::plugin_context *cc1_plugin::current_context; // This is put into the lang hooks when the plugin starts. static void -plugin_print_error_function (diagnostic_text_output_format &text_output, +plugin_print_error_function (diagnostics::text_sink &text_output, const char *file, const diagnostic_info *diagnostic) {