https://gcc.gnu.org/g:1743dd35a7705ebf76ee505796f71c3ec0d9a39c
commit r16-2521-g1743dd35a7705ebf76ee505796f71c3ec0d9a39c Author: David Malcolm <dmalc...@redhat.com> Date: Fri Jul 25 15:13:34 2025 -0400 diagnostics: move logical locations into "diagnostics" This patch moves gcc/logical-locations.h into gcc/diagnostics and moves the classes into "namespace diagnostics", to better indicate that this is part of the shared diagnostics code. The type "logical_location" becomes diagnostics::logical_locations::key, the class logical_location_manager becomes class diagnostics::logical_locations::manager, and the enum enum logical_location_kind becomes enum diagnostics::logical_locations::kind. Note that tree-logical-locations.{h,cc} are *not* part of "namespace diagnostics", as they use tree. renamed: gcc/logical-location.h -> gcc/diagnostics/logical-locations.h renamed: gcc/selftest-logical-location.cc -> gcc/diagnostics/selftest-logical-locations.cc renamed: gcc/selftest-logical-location.h -> gcc/diagnostics/selftest-logical-locations.h No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Replace selftest-logical-location.o with diagnostics/selftest-logical-locations.o. * diagnostic-client-data-hooks.h: Update #include for move of "logical-location.h" to "diagnostics/logical-locations.h". Update for conversion of logical_location_manager to diagnostics::logical_locations::manager, and of logical_location to diagnostics::logical_locations::key. * diagnostic-format-html.cc: Add "using namespace diagnostics;", and drop now-redundant "diagnostics::" prefixes. Update for conversion of logical_location_manager to diagnostics::logical_locations::manager, of logical_location to diagnostics::logical_locations::key, and of enum logical_location_kind to enum diagnostics::logical_locations::kind. * diagnostic-format-sarif.cc: Update #include for move of "logical-location.h" to "diagnostics/logical-locations.h". Add "using namespace diagnostics;", and drop now-redundant "diagnostics::" prefixes. Update for conversion of logical_location_manager to diagnostics::logical_locations::manager, of logical_location to diagnostics::logical_locations::key, and of enum logical_location_kind to enum diagnostics::logical_locations::kind. * diagnostic-format-sarif.h: Update #include for move of "logical-location.h" to "diagnostics/logical-locations.h". Update for conversion of logical_location to diagnostics::logical_locations::key. * diagnostic-path-output.cc: Add "using namespace diagnostics;". Update for conversion of logical_location_manager to diagnostics::logical_locations::manager, and of logical_location to diagnostics::logical_locations::key, * diagnostic-path.cc: Add "using namespace diagnostics;". Update for conversion of logical_location to diagnostics::logical_locations::key. * diagnostic-path.h: Update #include for move of "logical-location.h" to "diagnostics/logical-locations.h". Update for conversion of logical_location_manager to diagnostics::logical_locations::manager, and of logical_location to diagnostics::logical_locations::key, * diagnostic.cc: Update #include for move of "logical-location.h" to "diagnostics/logical-locations.h". Update for conversion of logical_location_manager to diagnostics::logical_locations::manager and of enum logical_location_kind to enum diagnostics::logical_locations::kind. * diagnostic.h: Reorganize forward decls. (class logical_location_manager): Replace this forward decl with... (class diagnostics::logical_locations::manager): ...this. (diagnostic_context::get_logical_location_manager): Update return type. * diagnostics/digraphs.h: : Update #include for move of "logical-location.h" to "diagnostics/logical-locations.h". Update for conversion of logical_location to diagnostics::logical_locations::key. * logical-location.h: Move to... * diagnostics/logical-locations.h: ...here. (enum class logical_location_kind): Convert to... (enum class diagnostics::logical_locations::kind): ... this. (class logical_location_manager::key): Convert to... (class diagnostics::logical_locations::key): ... this. (class logical_location_manager): Convert to... (class diagnostics::logical_locations::manager): ... this. (logical_location): Drop this typedef in favor of diagnostics::logical_locations::key. * selftest-logical-location.cc: Move to... * diagnostics/selftest-logical-locations.cc: ...here. Update #include for move of "selftest-logical-location.h" to "diagnostics/selftest-logical-locations.h". Update for conversion of logical_location_manager to diagnostics::logical_locations::manager, of logical_location to diagnostics::logical_locations::key, and of enum logical_location_kind to enum diagnostics::logical_locations::kind. (selftest_logical_location_cc_tests): Rename to... (diagnostics_selftest_logical_locations_cc_tests): ...this. * selftest-logical-location.h: Move to... * diagnostics/selftest-logical-locations.h: ...here, updating include guard. Update for conversion of logical_location_manager to diagnostics::logical_locations::manager, of logical_location to diagnostics::logical_locations::key, and of enum logical_location_kind to enum diagnostics::logical_locations::kind. * diagnostics/state-graphs-to-dot.cc: Add "using namespace diagnostics;" and drop now-redundant "diagnostics::" prefixes. Update for conversion of logical_location_manager to diagnostics::logical_locations::manager. * diagnostics/state-graphs.h: Update #include for move of "logical-location.h" to "diagnostics/logical-locations.h". Update for conversion of logical_location_manager to diagnostics::logical_locations::manager, of logical_location to diagnostics::logical_locations::key. * libgdiagnostics.cc: Update #include for move of "logical-location.h" to "diagnostics/logical-locations.h". Update for conversion of logical_location_manager to diagnostics::logical_locations::manager, and of logical_location to diagnostics::logical_locations::key. * selftest-diagnostic-path.cc: Update for conversion of logical_location to diagnostics::logical_locations::key. * selftest-diagnostic-path.h: Update #include for move of "logical-location.h" to "diagnostics/logical-locations.h". Update for conversion of logical_location to diagnostics::logical_locations::key. * selftest-run-tests.cc (selftest::run_tests): Update for renaming of selftest_logical_location_cc_tests to diagnostics_selftest_logical_locations_cc_tests. * selftest.h: Likewise. * simple-diagnostic-path.h: Update for conversion of logical_location to diagnostics::logical_locations::key. * tree-diagnostic-client-data-hooks.cc: Update for conversion of logical_location_manager to diagnostics::logical_locations::manager, and of logical_location to diagnostics::logical_locations::key. * tree-logical-location.cc: Update for conversions. Update for conversion of logical_location to diagnostics::logical_locations::key, and of enum logical_location_kind to enum diagnostics::logical_locations::kind. * tree-logical-location.h: Update #include for move of "logical-location.h" to "diagnostics/logical-locations.h". Update for conversion of logical_location_manager to diagnostics::logical_locations::manager, of logical_location to diagnostics::logical_locations::key, and of enum logical_location_kind to enum diagnostics::logical_locations::kind. gcc/analyzer/ChangeLog: * checker-event.h (checker_event::get_logical_location): Update for conversion of logical_location to diagnostics::logical_locations::key. (checker_event::m_logical_loc): Likewise. * diagnostic-manager.cc (diagnostic_manager::get_logical_location_manager): Likewise. * diagnostic-manager.h (diagnostic_manager::get_logical_location_manager): Likewise. Signed-off-by: David Malcolm <dmalc...@redhat.com> Diff: --- gcc/Makefile.in | 2 +- gcc/analyzer/checker-event.h | 5 +- gcc/analyzer/diagnostic-manager.cc | 2 +- gcc/analyzer/diagnostic-manager.h | 2 +- gcc/diagnostic-client-data-hooks.h | 16 +-- gcc/diagnostic-format-html.cc | 65 +++++------ gcc/diagnostic-format-sarif.cc | 96 ++++++++-------- gcc/diagnostic-format-sarif.h | 4 +- gcc/diagnostic-path-output.cc | 28 ++--- gcc/diagnostic-path.cc | 4 +- gcc/diagnostic-path.h | 6 +- gcc/diagnostic.cc | 26 ++--- gcc/diagnostic.h | 13 ++- gcc/diagnostics/digraphs.h | 8 +- .../logical-locations.h} | 127 +++++++++++---------- .../selftest-logical-locations.cc} | 18 +-- .../selftest-logical-locations.h} | 30 ++--- gcc/diagnostics/state-graphs-to-dot.cc | 21 ++-- gcc/diagnostics/state-graphs.h | 6 +- gcc/libgdiagnostics.cc | 69 ++++++----- gcc/selftest-diagnostic-path.cc | 2 +- gcc/selftest-diagnostic-path.h | 6 +- gcc/selftest-run-tests.cc | 2 +- gcc/selftest.h | 2 +- gcc/simple-diagnostic-path.h | 5 +- gcc/tree-diagnostic-client-data-hooks.cc | 6 +- gcc/tree-logical-location.cc | 29 ++--- gcc/tree-logical-location.h | 22 ++-- 28 files changed, 337 insertions(+), 285 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 7391a18a351d..fc5ffc72df72 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1865,6 +1865,7 @@ OBJS-libcommon = diagnostic-spec.o diagnostic.o diagnostic-color.o \ diagnostics/digraphs.o \ diagnostics/state-graphs.o \ diagnostics/state-graphs-to-dot.o \ + diagnostics/selftest-logical-locations.o \ edit-context.o \ graphviz.o pex.o \ pretty-print.o intl.o \ @@ -1875,7 +1876,6 @@ OBJS-libcommon = diagnostic-spec.o diagnostic.o diagnostic-color.o \ selftest.o selftest-diagnostic.o sort.o \ selftest-diagnostic-path.o \ selftest-json.o \ - selftest-logical-location.o \ text-art/box-drawing.o \ text-art/canvas.o \ text-art/ruler.o \ diff --git a/gcc/analyzer/checker-event.h b/gcc/analyzer/checker-event.h index d3b64e33a193..c513742ef9ec 100644 --- a/gcc/analyzer/checker-event.h +++ b/gcc/analyzer/checker-event.h @@ -101,7 +101,8 @@ public: location_t get_location () const final override { return m_loc; } int get_stack_depth () const final override { return m_effective_depth; } - logical_location get_logical_location () const final override + diagnostics::logical_locations::key + get_logical_location () const final override { return m_logical_loc; } @@ -161,7 +162,7 @@ protected: int m_effective_depth; pending_diagnostic *m_pending_diagnostic; diagnostic_event_id_t m_emission_id; // only set once all pruning has occurred - logical_location m_logical_loc; + diagnostics::logical_locations::key m_logical_loc; }; /* A concrete event subclass for a purely textual event, for use in diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index c083b8c21be4..a3bec727c8b9 100644 --- a/gcc/analyzer/diagnostic-manager.cc +++ b/gcc/analyzer/diagnostic-manager.cc @@ -1663,7 +1663,7 @@ diagnostic_manager::emit_saved_diagnostic (const exploded_graph &eg, } } -const logical_location_manager & +const diagnostics::logical_locations::manager & diagnostic_manager::get_logical_location_manager () const { gcc_assert (global_dc); diff --git a/gcc/analyzer/diagnostic-manager.h b/gcc/analyzer/diagnostic-manager.h index aa0bd79faedb..440a184f55b6 100644 --- a/gcc/analyzer/diagnostic-manager.h +++ b/gcc/analyzer/diagnostic-manager.h @@ -191,7 +191,7 @@ public: } private: - const logical_location_manager & + const diagnostics::logical_locations::manager & get_logical_location_manager () const; void build_emission_path (const path_builder &pb, diff --git a/gcc/diagnostic-client-data-hooks.h b/gcc/diagnostic-client-data-hooks.h index 990917278198..32cda19d1b62 100644 --- a/gcc/diagnostic-client-data-hooks.h +++ b/gcc/diagnostic-client-data-hooks.h @@ -21,7 +21,7 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_DIAGNOSTIC_CLIENT_DATA_HOOKS_H #define GCC_DIAGNOSTIC_CLIENT_DATA_HOOKS_H -#include "logical-location.h" +#include "diagnostics/logical-locations.h" class sarif_object; class client_version_info; @@ -37,13 +37,15 @@ class diagnostic_client_data_hooks /* Get version info for this client, or NULL. */ virtual const client_version_info *get_any_version_info () const = 0; - /* Get the current logical_location_manager for this client, or NULL. */ - virtual const logical_location_manager *get_logical_location_manager () const = 0; + /* Get the current logical_locations::manager for this client, or null. */ + virtual const diagnostics::logical_locations::manager * + get_logical_location_manager () const = 0; - /* Get the current logical_location, or null. - If this returns a non-null logical_location, then - get_logical_location_manager must return non-NULL. */ - virtual logical_location get_current_logical_location () const = 0; + /* Get the current logical location, or null. + If this returns a non-null logical location, then + get_logical_location_manager must return non-null. */ + virtual diagnostics::logical_locations::key + get_current_logical_location () const = 0; /* Get a sourceLanguage value for FILENAME, or return NULL. See SARIF v2.1.0 Appendix J for suggested values. */ diff --git a/gcc/diagnostic-format-html.cc b/gcc/diagnostic-format-html.cc index bac99260ec33..945be3e08a87 100644 --- a/gcc/diagnostic-format-html.cc +++ b/gcc/diagnostic-format-html.cc @@ -48,6 +48,8 @@ along with GCC; see the file COPYING3. If not see #include "json.h" #include "selftest-xml.h" +using namespace diagnostics; + // struct html_generation_options html_generation_options::html_generation_options () @@ -121,7 +123,7 @@ public: diagnostic_t orig_diag_kind, diagnostic_html_format_buffer *buffer); void emit_diagram (const diagnostic_diagram &diagram); - void emit_global_graph (const diagnostics::digraphs::lazy_digraph &); + void emit_global_graph (const digraphs::lazy_digraph &); void end_group (); @@ -177,14 +179,14 @@ private: pop_nesting_level (); void - add_graph (const diagnostics::digraphs::digraph &dg, + add_graph (const digraphs::digraph &dg, xml::element &parent_element); diagnostic_context &m_context; pretty_printer *m_printer; const line_maps *m_line_maps; html_generation_options m_html_gen_opts; - const logical_location_manager *m_logical_loc_mgr; + const logical_locations::manager *m_logical_loc_mgr; std::unique_ptr<xml::document> m_document; xml::element *m_head_element; @@ -195,7 +197,7 @@ private: std::vector<xml::element *> m_cur_nesting_levels; int m_next_diag_id; // for handing out unique IDs json::array m_ui_focus_ids; - logical_location m_last_logical_location; + logical_locations::key m_last_logical_location; location_t m_last_location; expanded_location m_last_expanded_location; }; @@ -512,7 +514,7 @@ html_builder::on_report_diagnostic (const diagnostic_info &diagnostic, if (m_cur_diagnostic_element && nesting_level > 0) alert = false; if (!m_cur_diagnostic_element) - m_last_logical_location = logical_location (); + m_last_logical_location = logical_locations::key (); auto diag_element = make_element_for_diagnostic (diagnostic, orig_diag_kind, alert); if (buffer) @@ -622,8 +624,7 @@ html_builder::maybe_make_state_diagram (const diagnostic_event &event) return nullptr; // Convert it to .dot AST - auto dot_graph - = diagnostics::state_graphs::make_dot_graph (*state_graph, + auto dot_graph = state_graphs::make_dot_graph (*state_graph, *m_logical_loc_mgr); gcc_assert (dot_graph); @@ -771,57 +772,57 @@ get_pf_class_for_alert_icon (diagnostic_t diag_kind) } static const char * -get_label_for_logical_location_kind (enum logical_location_kind kind) +get_label_for_logical_location_kind (enum logical_locations::kind kind) { switch (kind) { default: gcc_unreachable (); - case logical_location_kind::unknown: + case logical_locations::kind::unknown: return nullptr; /* Kinds within executable code. */ - case logical_location_kind::function: + case logical_locations::kind::function: return "Function"; - case logical_location_kind::member: + case logical_locations::kind::member: return "Member"; - case logical_location_kind::module_: + case logical_locations::kind::module_: return "Module"; - case logical_location_kind::namespace_: + case logical_locations::kind::namespace_: return "Namespace"; - case logical_location_kind::type: + case logical_locations::kind::type: return "Type"; - case logical_location_kind::return_type: + case logical_locations::kind::return_type: return "Return type"; - case logical_location_kind::parameter: + case logical_locations::kind::parameter: return "Parameter"; - case logical_location_kind::variable: + case logical_locations::kind::variable: return "Variable"; /* Kinds within XML or HTML documents. */ - case logical_location_kind::element: + case logical_locations::kind::element: return "Element"; - case logical_location_kind::attribute: + case logical_locations::kind::attribute: return "Attribute"; - case logical_location_kind::text: + case logical_locations::kind::text: return "Text"; - case logical_location_kind::comment: + case logical_locations::kind::comment: return "Comment"; - case logical_location_kind::processing_instruction: + case logical_locations::kind::processing_instruction: return "Processing Instruction"; - case logical_location_kind::dtd: + case logical_locations::kind::dtd: return "DTD"; - case logical_location_kind::declaration: + case logical_locations::kind::declaration: return "Declaration"; /* Kinds within JSON documents. */ - case logical_location_kind::object: + case logical_locations::kind::object: return "Object"; - case logical_location_kind::array: + case logical_locations::kind::array: return "Array"; - case logical_location_kind::property: + case logical_locations::kind::property: return "Property"; - case logical_location_kind::value: + case logical_locations::kind::value: return "Value"; } } @@ -1062,7 +1063,7 @@ html_builder::make_element_for_diagnostic (const diagnostic_info &diagnostic, if (auto logical_loc = client_data_hooks->get_current_logical_location ()) if (logical_loc != m_last_logical_location) { - enum logical_location_kind kind + enum logical_locations::kind kind = m_logical_loc_mgr->get_kind (logical_loc);; if (const char *label = get_label_for_logical_location_kind (kind)) if (const char *name_with_scope @@ -1248,7 +1249,7 @@ html_builder::emit_diagram (const diagnostic_diagram &/*diagram*/) } void -html_builder::add_graph (const diagnostics::digraphs::digraph &dg, +html_builder::add_graph (const digraphs::digraph &dg, xml::element &parent_element) { if (auto dot_graph = dg.make_dot_graph ()) @@ -1269,7 +1270,7 @@ html_builder::add_graph (const diagnostics::digraphs::digraph &dg, } void -html_builder::emit_global_graph (const diagnostics::digraphs::lazy_digraph &ldg) +html_builder::emit_global_graph (const digraphs::lazy_digraph &ldg) { auto &dg = ldg.get_or_create_digraph (); gcc_assert (m_body_element); @@ -1390,7 +1391,7 @@ public: } void - report_global_digraph (const diagnostics::digraphs::lazy_digraph &ldg) final override + report_global_digraph (const digraphs::lazy_digraph &ldg) final override { m_builder.emit_global_graph (ldg); } diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc index dd8b07939402..2a9956ba91a3 100644 --- a/gcc/diagnostic-format-sarif.cc +++ b/gcc/diagnostic-format-sarif.cc @@ -35,7 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic-buffer.h" #include "json.h" #include "cpplib.h" -#include "logical-location.h" +#include "diagnostics/logical-locations.h" #include "diagnostic-client-data-hooks.h" #include "diagnostic-diagram.h" #include "text-art/canvas.h" @@ -54,6 +54,8 @@ along with GCC; see the file COPYING3. If not see #include "backtrace.h" #include "xml.h" +using 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"). */ @@ -763,7 +765,7 @@ public: m_printer = &printer; } - const logical_location_manager * + const logical_locations::manager * get_logical_location_manager () const { return m_logical_loc_mgr; @@ -779,7 +781,7 @@ public: void end_group (); void - report_global_digraph (const diagnostics::digraphs::lazy_digraph &); + report_global_digraph (const digraphs::lazy_digraph &); std::unique_ptr<sarif_result> take_current_result () { @@ -796,7 +798,7 @@ public: std::unique_ptr<sarif_location> make_location_object (sarif_location_manager *loc_mgr, const rich_location &rich_loc, - logical_location logical_loc, + logical_locations::key logical_loc, enum diagnostic_artifact_role role); std::unique_ptr<sarif_location> make_location_object (sarif_location_manager &loc_mgr, @@ -834,7 +836,7 @@ public: const sarif_generation_options &get_opts () const { return m_sarif_gen_opts; } std::unique_ptr<sarif_logical_location> - make_minimal_sarif_logical_location (logical_location); + make_minimal_sarif_logical_location (logical_locations::key); private: class sarif_token_printer : public token_printer @@ -860,7 +862,7 @@ private: location_t where); void set_any_logical_locs_arr (sarif_location &location_obj, - logical_location logical_loc); + logical_locations::key logical_loc); std::unique_ptr<sarif_location> make_location_object (sarif_location_manager &loc_mgr, const diagnostic_event &event, @@ -895,7 +897,7 @@ private: make_region_object_for_hint (const fixit_hint &hint) const; int - ensure_sarif_logical_location_for (logical_location k); + ensure_sarif_logical_location_for (logical_locations::key k); std::unique_ptr<sarif_multiformat_message_string> make_multiformat_message_string (const char *msg) const; @@ -953,7 +955,7 @@ private: const line_maps *m_line_maps; sarif_token_printer m_token_printer; - const logical_location_manager *m_logical_loc_mgr; + const logical_locations::manager *m_logical_loc_mgr; /* The JSON object for the invocation object. */ std::unique_ptr<sarif_invocation> m_invocation_obj; @@ -1313,7 +1315,7 @@ sarif_result::on_nested_diagnostic (const diagnostic_info &diagnostic, often they won't. */ auto location_obj = builder.make_location_object (this, *diagnostic.richloc, - logical_location (), + logical_locations::key (), diagnostic_artifact_role::result_file); auto message_obj = builder.make_message_object (pp_formatted_text (builder.get_printer ())); @@ -1906,7 +1908,7 @@ sarif_builder::end_group () void sarif_builder:: -report_global_digraph (const diagnostics::digraphs::lazy_digraph &ldg) +report_global_digraph (const digraphs::lazy_digraph &ldg) { auto &dg = ldg.get_or_create_digraph (); @@ -2204,7 +2206,7 @@ sarif_builder::make_locations_arr (sarif_location_manager &loc_mgr, enum diagnostic_artifact_role role) { auto locations_arr = std::make_unique<json::array> (); - logical_location logical_loc; + logical_locations::key logical_loc; if (auto client_data_hooks = m_context.get_client_data_hooks ()) logical_loc = client_data_hooks->get_current_logical_location (); @@ -2224,7 +2226,7 @@ sarif_builder::make_locations_arr (sarif_location_manager &loc_mgr, void sarif_builder:: set_any_logical_locs_arr (sarif_location &location_obj, - logical_location logical_loc) + logical_locations::key logical_loc) { if (!logical_loc) return; @@ -2250,7 +2252,7 @@ set_any_logical_locs_arr (sarif_location &location_obj, std::unique_ptr<sarif_location> sarif_builder::make_location_object (sarif_location_manager *loc_mgr, const rich_location &rich_loc, - logical_location logical_loc, + logical_locations::key logical_loc, enum diagnostic_artifact_role role) { class escape_nonascii_renderer : public content_renderer @@ -2445,7 +2447,7 @@ sarif_builder::make_location_object (sarif_location_manager &loc_mgr, std::move (phs_loc_obj)); /* "logicalLocations" property (SARIF v2.1.0 section 3.28.4). */ - logical_location logical_loc = event.get_logical_location (); + logical_locations::key logical_loc = event.get_logical_location (); set_any_logical_locs_arr (*location_obj, logical_loc); /* "message" property (SARIF v2.1.0 section 3.28.5). */ @@ -2766,57 +2768,59 @@ sarif_builder::make_region_object_for_hint (const fixit_hint &hint) const Return nullptr if unknown. */ static const char * -maybe_get_sarif_kind (enum logical_location_kind kind) +maybe_get_sarif_kind (enum logical_locations::kind kind) { + using namespace logical_locations; + switch (kind) { default: gcc_unreachable (); - case logical_location_kind::unknown: + case logical_locations::kind::unknown: return nullptr; /* Kinds within executable code. */ - case logical_location_kind::function: + case logical_locations::kind::function: return "function"; - case logical_location_kind::member: + case logical_locations::kind::member: return "member"; - case logical_location_kind::module_: + case logical_locations::kind::module_: return "module"; - case logical_location_kind::namespace_: + case logical_locations::kind::namespace_: return "namespace"; - case logical_location_kind::type: + case logical_locations::kind::type: return "type"; - case logical_location_kind::return_type: + case logical_locations::kind::return_type: return "returnType"; - case logical_location_kind::parameter: + case logical_locations::kind::parameter: return "parameter"; - case logical_location_kind::variable: + case logical_locations::kind::variable: return "variable"; /* Kinds within XML or HTML documents. */ - case logical_location_kind::element: + case logical_locations::kind::element: return "element"; - case logical_location_kind::attribute: + case logical_locations::kind::attribute: return "attribute"; - case logical_location_kind::text: + case logical_locations::kind::text: return "text"; - case logical_location_kind::comment: + case logical_locations::kind::comment: return "comment"; - case logical_location_kind::processing_instruction: + case logical_locations::kind::processing_instruction: return "processingInstruction"; - case logical_location_kind::dtd: + case logical_locations::kind::dtd: return "dtd"; - case logical_location_kind::declaration: + case logical_locations::kind::declaration: return "declaration"; /* Kinds within JSON documents. */ - case logical_location_kind::object: + case logical_locations::kind::object: return "object"; - case logical_location_kind::array: + case logical_locations::kind::array: return "array"; - case logical_location_kind::property: + case logical_locations::kind::property: return "property"; - case logical_location_kind::value: + case logical_locations::kind::value: return "value"; } } @@ -2828,7 +2832,7 @@ maybe_get_sarif_kind (enum logical_location_kind kind) void sarif_property_bag::set_logical_location (const char *property_name, sarif_builder &builder, - logical_location logical_loc) + logical_locations::key logical_loc) { set<sarif_logical_location> (property_name, @@ -2836,7 +2840,7 @@ sarif_property_bag::set_logical_location (const char *property_name, } static void -copy_any_property_bag (const diagnostics::digraphs::object &input_obj, +copy_any_property_bag (const digraphs::object &input_obj, sarif_object &output_obj) { if (input_obj.get_property_bag ()) @@ -2853,7 +2857,7 @@ copy_any_property_bag (const diagnostics::digraphs::object &input_obj, } std::unique_ptr<sarif_graph> -make_sarif_graph (const diagnostics::digraphs::digraph &g, +make_sarif_graph (const digraphs::digraph &g, sarif_builder *builder, sarif_location_manager *sarif_location_mgr) { @@ -2887,7 +2891,7 @@ make_sarif_graph (const diagnostics::digraphs::digraph &g, } std::unique_ptr<sarif_node> -make_sarif_node (const diagnostics::digraphs::node &n, +make_sarif_node (const digraphs::node &n, sarif_builder *builder, sarif_location_manager *sarif_location_mgr) { @@ -2936,7 +2940,7 @@ make_sarif_node (const diagnostics::digraphs::node &n, } std::unique_ptr<sarif_edge> -make_sarif_edge (const diagnostics::digraphs::edge &e, +make_sarif_edge (const digraphs::edge &e, sarif_builder *builder) { auto result = std::make_unique<sarif_edge> (); @@ -2965,7 +2969,7 @@ void sarif_property_bag::set_graph (const char *property_name, sarif_builder &builder, sarif_location_manager *sarif_location_mgr, - const diagnostics::digraphs::digraph &g) + const digraphs::digraph &g) { set<sarif_graph> (property_name, make_sarif_graph (g, &builder, sarif_location_mgr)); @@ -2977,7 +2981,7 @@ sarif_property_bag::set_graph (const char *property_name, int sarif_builder:: -ensure_sarif_logical_location_for (logical_location k) +ensure_sarif_logical_location_for (logical_locations::key k) { gcc_assert (m_logical_loc_mgr); @@ -2995,7 +2999,7 @@ ensure_sarif_logical_location_for (logical_location k) sarif_logical_loc->set_string ("decoratedName", internal_name); /* "kind" property (SARIF v2.1.0 section 3.33.7). */ - enum logical_location_kind kind = m_logical_loc_mgr->get_kind (k); + enum logical_locations::kind kind = m_logical_loc_mgr->get_kind (k); if (const char *sarif_kind_str = maybe_get_sarif_kind (kind)) sarif_logical_loc->set_string ("kind", sarif_kind_str); @@ -3021,7 +3025,7 @@ ensure_sarif_logical_location_for (logical_location k) std::unique_ptr<sarif_logical_location> sarif_builder:: -make_minimal_sarif_logical_location (logical_location logical_loc) +make_minimal_sarif_logical_location (logical_locations::key logical_loc) { gcc_assert (m_logical_loc_mgr); @@ -3921,7 +3925,7 @@ public: } void - report_global_digraph (const diagnostics::digraphs::lazy_digraph &lazy_digraph) final override + report_global_digraph (const digraphs::lazy_digraph &lazy_digraph) final override { m_builder.report_global_digraph (lazy_digraph); } @@ -4486,7 +4490,7 @@ test_make_location_object (const sarif_generation_options &sarif_gen_opts, std::unique_ptr<sarif_location> location_obj = builder.make_location_object - (&result, richloc, logical_location (), + (&result, richloc, logical_locations::key (), diagnostic_artifact_role::analysis_target); ASSERT_NE (location_obj, nullptr); diff --git a/gcc/diagnostic-format-sarif.h b/gcc/diagnostic-format-sarif.h index 60657c63225c..29ee9a84b554 100644 --- a/gcc/diagnostic-format-sarif.h +++ b/gcc/diagnostic-format-sarif.h @@ -24,7 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "json.h" #include "diagnostic-format.h" #include "diagnostic-output-file.h" -#include "logical-location.h" +#include "diagnostics/logical-locations.h" /* Enum for choosing what format to serializing the generated SARIF into. */ @@ -129,7 +129,7 @@ class sarif_property_bag : public json::object public: void set_logical_location (const char *property_name, sarif_builder &, - logical_location logical_loc); + diagnostics::logical_locations::key logical_loc); void set_graph (const char *property_name, sarif_builder &, sarif_location_manager *sarif_location_mgr, diff --git a/gcc/diagnostic-path-output.cc b/gcc/diagnostic-path-output.cc index 439fd3331c3a..a05319c81acc 100644 --- a/gcc/diagnostic-path-output.cc +++ b/gcc/diagnostic-path-output.cc @@ -54,6 +54,8 @@ along with GCC; see the file COPYING3. If not see namespace { +using namespace diagnostics; + /* A bundle of state for printing a path. */ class path_print_policy @@ -238,7 +240,7 @@ class per_thread_summary { public: per_thread_summary (const diagnostic_path &path, - const logical_location_manager &logical_loc_mgr, + const logical_locations::manager &logical_loc_mgr, label_text name, unsigned swimlane_idx) : m_path (path), m_logical_loc_mgr (logical_loc_mgr), @@ -268,7 +270,7 @@ private: friend struct event_range; const diagnostic_path &m_path; - const logical_location_manager &m_logical_loc_mgr; + const logical_locations::manager &m_logical_loc_mgr; const label_text m_name; @@ -291,7 +293,7 @@ private: struct stack_frame { stack_frame (std::unique_ptr<stack_frame> parent, - logical_location logical_loc, + logical_locations::key logical_loc, int stack_depth) : m_parent (std::move (parent)), m_logical_loc (logical_loc), @@ -299,7 +301,7 @@ struct stack_frame {} std::unique_ptr<stack_frame> m_parent; - logical_location m_logical_loc; + logical_locations::key m_logical_loc; const int m_stack_depth; }; @@ -309,9 +311,9 @@ struct stack_frame static std::unique_ptr<stack_frame> begin_html_stack_frame (xml::printer &xp, std::unique_ptr<stack_frame> parent, - logical_location logical_loc, + logical_locations::key logical_loc, int stack_depth, - const logical_location_manager *logical_loc_mgr) + const logical_locations::manager *logical_loc_mgr) { if (logical_loc) { @@ -707,7 +709,7 @@ struct event_range const diagnostic_path &m_path; const diagnostic_event &m_initial_event; - logical_location m_logical_loc; + logical_locations::key m_logical_loc; int m_stack_depth; unsigned m_start_idx; unsigned m_end_idx; @@ -733,7 +735,7 @@ struct path_summary bool colorize = false, bool show_event_links = true); - const logical_location_manager &get_logical_location_manager () const + const logical_locations::manager &get_logical_location_manager () const { return m_logical_loc_mgr; } @@ -748,7 +750,7 @@ struct path_summary return **slot; } - const logical_location_manager &m_logical_loc_mgr; + const logical_locations::manager &m_logical_loc_mgr; auto_delete_vec <event_range> m_ranges; auto_delete_vec <per_thread_summary> m_per_thread_summary; hash_map<int_hash<diagnostic_thread_id_t, -1, -2>, @@ -883,7 +885,7 @@ public: void print_swimlane_for_event_range_as_text (diagnostic_text_output_format &text_output, pretty_printer *pp, - const logical_location_manager &logical_loc_mgr, + const logical_locations::manager &logical_loc_mgr, event_range *range, diagnostic_source_effect_info *effect_info) { @@ -1158,7 +1160,7 @@ print_path_summary_as_html (const path_summary &ps, for (auto t : ps.m_per_thread_summary) thread_event_printers.push_back (thread_event_printer (*t, show_depths)); - const logical_location_manager *logical_loc_mgr + const logical_locations::manager *logical_loc_mgr = dc.get_logical_location_manager (); xp.push_tag_with_class ("div", "event-ranges", false); @@ -1173,7 +1175,7 @@ print_path_summary_as_html (const path_summary &ps, const int swimlane_idx = range->m_per_thread_summary.get_swimlane_index (); - const logical_location this_logical_loc = range->m_logical_loc; + const logical_locations::key this_logical_loc = range->m_logical_loc; const int this_depth = range->m_stack_depth; if (curr_frame) { @@ -1328,7 +1330,7 @@ diagnostic_text_output_format::print_path (const diagnostic_path &path) /* -fdiagnostics-path-format=separate-events doesn't print fndecl information, so with -fdiagnostics-show-path-depths print the fndecls too, if any. */ - if (logical_location logical_loc + if (logical_locations::key logical_loc = event.get_logical_location ()) { label_text name diff --git a/gcc/diagnostic-path.cc b/gcc/diagnostic-path.cc index e55a11cb54e9..86ada604b7cb 100644 --- a/gcc/diagnostic-path.cc +++ b/gcc/diagnostic-path.cc @@ -36,6 +36,8 @@ along with GCC; see the file COPYING3. If not see # pragma GCC diagnostic ignored "-Wformat-diag" #endif +using namespace diagnostics; + /* class diagnostic_event. */ /* struct diagnostic_event::meaning. */ @@ -180,7 +182,7 @@ diagnostic_path::get_first_event_in_a_function (unsigned *out_idx) const for (unsigned i = 0; i < num; i++) { const diagnostic_event &event = get_event (i); - if (logical_location logical_loc = event.get_logical_location ()) + if (logical_locations::key logical_loc = event.get_logical_location ()) if (m_logical_loc_mgr.function_p (logical_loc)) { *out_idx = i; diff --git a/gcc/diagnostic-path.h b/gcc/diagnostic-path.h index ca2628eda691..18b33271cca4 100644 --- a/gcc/diagnostic-path.h +++ b/gcc/diagnostic-path.h @@ -23,7 +23,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic.h" /* for ATTRIBUTE_GCC_DIAG. */ #include "diagnostic-event-id.h" -#include "logical-location.h" +#include "diagnostics/logical-locations.h" namespace xml { class document; } @@ -160,7 +160,7 @@ class diagnostic_event virtual void print_desc (pretty_printer &pp) const = 0; /* Get a logical location for this event, or null if there is none. */ - virtual logical_location get_logical_location () const = 0; + virtual diagnostics::logical_locations::key get_logical_location () const = 0; virtual meaning get_meaning () const = 0; @@ -203,6 +203,8 @@ public: class diagnostic_path { public: + using logical_location_manager = diagnostics::logical_locations::manager; + virtual ~diagnostic_path () {} virtual unsigned num_events () const = 0; virtual const diagnostic_event & get_event (int idx) const = 0; diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index 7e5ac878cfea..9eab7bacebcd 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -47,7 +47,7 @@ along with GCC; see the file COPYING3. If not see #include "cpplib.h" #include "text-art/theme.h" #include "pretty-print-urlifier.h" -#include "logical-location.h" +#include "diagnostics/logical-locations.h" #include "diagnostic-buffer.h" #ifdef HAVE_TERMIOS_H @@ -590,7 +590,7 @@ diagnostic_context::pop_urlifier () delete node.m_urlifier; } -const logical_location_manager * +const diagnostics::logical_locations::manager * diagnostic_context::get_logical_location_manager () const { if (!m_client_data_hooks) @@ -1055,28 +1055,28 @@ diagnostic_context::notes_inhibited_in_group () const return false; } -/* class logical_location_manager. */ +/* class diagnostics::logical_locations::manager. */ /* Return true iff this is a function or method. */ bool -logical_location_manager::function_p (key k) const +diagnostics::logical_locations::manager::function_p (key k) const { switch (get_kind (k)) { default: gcc_unreachable (); - case logical_location_kind::unknown: - case logical_location_kind::module_: - case logical_location_kind::namespace_: - case logical_location_kind::type: - case logical_location_kind::return_type: - case logical_location_kind::parameter: - case logical_location_kind::variable: + case kind::unknown: + case kind::module_: + case kind::namespace_: + case kind::type: + case kind::return_type: + case kind::parameter: + case kind::variable: return false; - case logical_location_kind::function: - case logical_location_kind::member: + case kind::function: + case kind::member: return true; } } diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index 04eb2b116567..5ccf30ca0295 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -27,9 +27,17 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic-core.h" namespace diagnostics { + + // diagnostics::digraphs namespace digraphs { class lazy_digraph; - } // namespace digraphs + } // namespace diagnostics::digraphs + + // diagnostics::logical_locations + namespace logical_locations { + class manager; + } // namespace diagnostics::logical_locations + } // namespace diagnostics namespace text_art @@ -227,7 +235,6 @@ public: class edit_context; class diagnostic_client_data_hooks; -class logical_location_manager; class diagnostic_diagram; class diagnostic_source_effect_info; class diagnostic_output_format; @@ -727,7 +734,7 @@ public: return m_client_data_hooks; } - const logical_location_manager * + const diagnostics::logical_locations::manager * get_logical_location_manager () const; const urlifier *get_urlifier () const; diff --git a/gcc/diagnostics/digraphs.h b/gcc/diagnostics/digraphs.h index 5c07fa866c90..fc73f6e73623 100644 --- a/gcc/diagnostics/digraphs.h +++ b/gcc/diagnostics/digraphs.h @@ -22,7 +22,7 @@ along with GCC; see the file COPYING3. If not see #define GCC_DIAGNOSTICS_DIGRAPHS_H #include "json.h" -#include "logical-location.h" +#include "diagnostics/logical-locations.h" class graphviz_out; @@ -276,14 +276,14 @@ class node : public object m_physical_loc = physical_loc; } - logical_location + logical_locations::key get_logical_loc () const { return m_logical_loc; } void - set_logical_loc (logical_location logical_loc) + set_logical_loc (logical_locations::key logical_loc) { m_logical_loc = logical_loc; } @@ -305,7 +305,7 @@ class node : public object std::unique_ptr<std::string> m_label; std::vector<std::unique_ptr<node>> m_children; location_t m_physical_loc; - logical_location m_logical_loc; + logical_locations::key m_logical_loc; }; // An edge in a directed graph, corresponding to SARIF v2.1.0 section 3.41. diff --git a/gcc/logical-location.h b/gcc/diagnostics/logical-locations.h similarity index 62% rename from gcc/logical-location.h rename to gcc/diagnostics/logical-locations.h index 3522934a90b4..b52a9b4f3b98 100644 --- a/gcc/logical-location.h +++ b/gcc/diagnostics/logical-locations.h @@ -18,18 +18,21 @@ You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>. */ -#ifndef GCC_LOGICAL_LOCATION_H -#define GCC_LOGICAL_LOCATION_H +#ifndef GCC_DIAGNOSTICS_LOGICAL_LOCATIONS_H +#define GCC_DIAGNOSTICS_LOGICAL_LOCATIONS_H #include "label-text.h" +namespace diagnostics { +namespace logical_locations { + /* An enum for discriminating between different kinds of logical location for a diagnostic. Roughly corresponds to logicalLocation's "kind" property in SARIF v2.1.0 (section 3.33.7). */ -enum class logical_location_kind +enum class kind { unknown, @@ -68,78 +71,84 @@ enum class logical_location_kind libgdiagnostics internals), and without requiring heap allocation of an interface class when emitting a diagnostic. - To do this, we split the implementation into logical_location, which is - a wrapper around a (const void *), and logical_location_manager which + To do this, we split the implementation into logical_locations::key, which is + a wrapper around a (const void *), and logical_locations::manager which is provided by the client and has vfunc hooks for interpreting - logical_location instances. + key instances. - Every logical_location is associated with a logical_location_manager and - only has meaning in relation to that manager. + Every logical_locations::key is associated with a logical_locations::manager + and only has meaning in relation to that manager. - A "nullptr" within a logical_location means "no logical location". + A "nullptr" within a key means "no logical location". See tree-logical-location.h for concrete subclasses relating to trees, where the pointer is a const_tree. - See selftest-logical-location.h for a concrete subclass for selftests. */ + See diagnostics/selftest-logical-locations.h for a concrete subclass for + selftests. */ -/* Abstract base class for giving meaning to logical_location values. - Typically there will just be one client-provided instance, of a - client-specific subclass. */ +/* Extrinsic state for identifying a specific logical location. + This will be our logical location type. + This only makes sense with respect to a specific manager. + e.g. for a tree-based one it's a wrapper around "tree". + + "nullptr" means "no logical location". + + Note that there is no integration with GCC's garbage collector and thus + keys can't be long-lived. */ -class logical_location_manager +class key { public: - /* Extrinsic state for identifying a specific logical location. - This will be our logical_location type. - This only makes sense with respect to a specific manager. - e.g. for a tree-based one it's a wrapper around "tree". - "nullptr" means "no logical location". */ - class key + key () : m_ptr (nullptr) {} + + static key from_ptr (const void *ptr) { - public: - key () : m_ptr (nullptr) {} + return key (ptr); + } - static key from_ptr (const void *ptr) - { - return key (ptr); - } + operator bool () const + { + return m_ptr != nullptr; + } - operator bool () const - { - return m_ptr != nullptr; - } + template <typename T> + T cast_to () const { return static_cast<T> (m_ptr); } - template <typename T> - T cast_to () const { return static_cast<T> (m_ptr); } + bool + operator== (const key &other) const + { + return m_ptr == other.m_ptr; + } - bool - operator== (const key &other) const - { - return m_ptr == other.m_ptr; - } + bool + operator!= (const key &other) const + { + return m_ptr != other.m_ptr; + } - bool - operator!= (const key &other) const - { - return m_ptr != other.m_ptr; - } + bool + operator< (const key &other) const + { + return m_ptr < other.m_ptr; + } - bool - operator< (const key &other) const - { - return m_ptr < other.m_ptr; - } +private: + explicit key (const void *ptr) : m_ptr (ptr) {} - private: - explicit key (const void *ptr) : m_ptr (ptr) {} + const void *m_ptr; +}; - const void *m_ptr; - }; +/* Abstract base class for giving meaning to keys. + Typically there will just be one client-provided instance, of a + client-specific subclass. */ - virtual ~logical_location_manager () {} +class manager +{ +public: + virtual ~manager () {} - /* vfuncs for interpreting logical_location values. */ + /* vfuncs for interpreting keys. */ /* Get a string (or NULL) for K suitable for use by the SARIF logicalLocation "name" property (SARIF v2.1.0 section 3.33.4). */ @@ -154,7 +163,7 @@ public: virtual const char *get_internal_name (key k) const = 0; /* Get what kind of SARIF logicalLocation K is (if any). */ - virtual enum logical_location_kind get_kind (key k) const = 0; + virtual enum kind get_kind (key k) const = 0; /* Get a string for location K in a form suitable for path output. */ virtual label_text get_name_for_path_output (key k) const = 0; @@ -165,11 +174,7 @@ public: bool function_p (key k) const; }; -/* A logical location is a key for a given logical_location_manager. - - Note that there is no integration with GCC's garbage collector and thus - logical_location instances can't be long-lived. */ - -typedef logical_location_manager::key logical_location; +} // namespace diagnostics::logical_locations +} // namespace diagnostics -#endif /* GCC_LOGICAL_LOCATION_H. */ +#endif /* GCC_DIAGNOSTICS_LOGICAL_LOCATIONS_H. */ diff --git a/gcc/selftest-logical-location.cc b/gcc/diagnostics/selftest-logical-locations.cc similarity index 84% rename from gcc/selftest-logical-location.cc rename to gcc/diagnostics/selftest-logical-locations.cc index 63b9fb4404c5..b32e7c2f69ce 100644 --- a/gcc/selftest-logical-location.cc +++ b/gcc/diagnostics/selftest-logical-locations.cc @@ -1,4 +1,4 @@ -/* Concrete subclass of logical_location for use in selftests. +/* Concrete subclass of logical_locations::manager for use in selftests. Copyright (C) 2024-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalc...@redhat.com>. @@ -22,12 +22,14 @@ along with GCC; see the file COPYING3. If not see #include "system.h" #include "coretypes.h" #include "selftest.h" -#include "selftest-logical-location.h" +#include "diagnostics/selftest-logical-locations.h" #if CHECKING_P namespace selftest { +using namespace diagnostics::logical_locations; + /* class test_logical_location_manager : public logical_location_manager. */ test_logical_location_manager::~test_logical_location_manager () @@ -59,7 +61,7 @@ test_logical_location_manager::get_internal_name (key k) const return item->m_name; } -enum logical_location_kind +enum diagnostics::logical_locations::kind test_logical_location_manager::get_kind (key k) const { auto item = item_from_key (k); @@ -73,7 +75,7 @@ test_logical_location_manager::get_name_for_path_output (key k) const return label_text::borrow (item->m_name); } -logical_location +diagnostics::logical_locations::key test_logical_location_manager:: logical_location_from_funcname (const char *funcname) { @@ -90,7 +92,7 @@ test_logical_location_manager::item_from_funcname (const char *funcname) if (item **slot = m_name_to_item_map.get (funcname)) return *slot; - item *i = new item (logical_location_kind::function, funcname); + item *i = new item (kind::function, funcname); m_name_to_item_map.put (funcname, i); return i; } @@ -98,14 +100,14 @@ test_logical_location_manager::item_from_funcname (const char *funcname) /* Run all of the selftests within this file. */ void -selftest_logical_location_cc_tests () +diagnostics_selftest_logical_locations_cc_tests () { test_logical_location_manager mgr; ASSERT_FALSE (mgr.logical_location_from_funcname (nullptr)); - logical_location loc_foo = mgr.logical_location_from_funcname ("foo"); - logical_location loc_bar = mgr.logical_location_from_funcname ("bar"); + key loc_foo = mgr.logical_location_from_funcname ("foo"); + key loc_bar = mgr.logical_location_from_funcname ("bar"); ASSERT_NE (loc_foo, loc_bar); diff --git a/gcc/selftest-logical-location.h b/gcc/diagnostics/selftest-logical-locations.h similarity index 70% rename from gcc/selftest-logical-location.h rename to gcc/diagnostics/selftest-logical-locations.h index d9bf38fd8d66..407ffda4253f 100644 --- a/gcc/selftest-logical-location.h +++ b/gcc/diagnostics/selftest-logical-locations.h @@ -1,4 +1,4 @@ -/* Concrete subclass of logical_location for use in selftests. +/* Concrete subclass of logical_locations::manager for use in selftests. Copyright (C) 2024-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalc...@redhat.com>. @@ -18,10 +18,10 @@ You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>. */ -#ifndef GCC_SELFTEST_LOGICAL_LOCATION_H -#define GCC_SELFTEST_LOGICAL_LOCATION_H +#ifndef GCC_DIAGNOSTICS_SELFTEST_LOGICAL_LOCATIONS_H +#define GCC_DIAGNOSTICS_SELFTEST_LOGICAL_LOCATIONS_H -#include "logical-location.h" +#include "diagnostics/logical-locations.h" /* The selftest code should entirely disappear in a production configuration, hence we guard all of it with #if CHECKING_P. */ @@ -30,44 +30,48 @@ along with GCC; see the file COPYING3. If not see namespace selftest { -/* Concrete subclass of logical_location_manager for use in selftests. */ +/* Concrete subclass of logical_locations::manager for use in selftests. */ -class test_logical_location_manager : public logical_location_manager +class test_logical_location_manager + : public diagnostics::logical_locations::manager { public: + using key = diagnostics::logical_locations::key; + using kind = diagnostics::logical_locations::kind; + ~test_logical_location_manager (); const char *get_short_name (key) const final override; const char *get_name_with_scope (key) const final override; const char *get_internal_name (key) const final override; - enum logical_location_kind get_kind (key) const final override; + kind get_kind (key) const final override; label_text get_name_for_path_output (key) const final override; key get_parent (key) const final override { return key (); } - logical_location + key logical_location_from_funcname (const char *funcname); private: struct item { - item (enum logical_location_kind kind, + item (kind kind_, const char *name) - : m_kind (kind), + : m_kind (kind_), m_name (name) { } - enum logical_location_kind m_kind; + kind m_kind; const char *m_name; }; const item * item_from_funcname (const char *funcname); - static const item *item_from_key (logical_location k) + static const item *item_from_key (key k) { return k.cast_to<const item *> (); } @@ -80,4 +84,4 @@ private: #endif /* #if CHECKING_P */ -#endif /* GCC_SELFTEST_LOGICAL_LOCATION_H. */ +#endif /* GCC_DIAGNOSTICS_SELFTEST_LOGICAL_LOCATIONS_H. */ diff --git a/gcc/diagnostics/state-graphs-to-dot.cc b/gcc/diagnostics/state-graphs-to-dot.cc index 9b64fa0889f0..c07ff41a5107 100644 --- a/gcc/diagnostics/state-graphs-to-dot.cc +++ b/gcc/diagnostics/state-graphs-to-dot.cc @@ -33,10 +33,11 @@ along with GCC; see the file COPYING3. If not see #include "xml-printer.h" #include "intl.h" +using namespace diagnostics; using namespace diagnostics::state_graphs; static int -get_depth (const diagnostics::digraphs::node &n) +get_depth (const digraphs::node &n) { int deepest_child = 0; for (size_t i = 0; i < n.get_num_children (); ++i) @@ -77,7 +78,7 @@ class state_diagram : public dot::graph { public: state_diagram (const diagnostics::digraphs::digraph &input_state_graph, - const logical_location_manager &logical_loc_mgr) + const logical_locations::manager &logical_loc_mgr) : m_logical_loc_mgr (logical_loc_mgr) { // "node [shape=plaintext]\n" @@ -531,20 +532,20 @@ private: } private: - const logical_location_manager &m_logical_loc_mgr; + const logical_locations::manager &m_logical_loc_mgr; /* All nodes involved in edges (and thus will need a port). */ - std::set<diagnostics::digraphs::node *> m_src_nodes; - std::set<diagnostics::digraphs::node *> m_dst_nodes; + std::set<digraphs::node *> m_src_nodes; + std::set<digraphs::node *> m_dst_nodes; - std::map<diagnostics::digraphs::node *, dot::node_id> m_src_node_to_port_id; - std::map<diagnostics::digraphs::node *, dot::node_id> m_dst_node_to_port_id; + std::map<digraphs::node *, dot::node_id> m_src_node_to_port_id; + std::map<digraphs::node *, dot::node_id> m_dst_node_to_port_id; }; std::unique_ptr<dot::graph> -diagnostics::state_graphs:: -make_dot_graph (const diagnostics::digraphs::digraph &state_graph, - const logical_location_manager &logical_loc_mgr) +state_graphs:: +make_dot_graph (const digraphs::digraph &state_graph, + const logical_locations::manager &logical_loc_mgr) { return std::make_unique<state_diagram> (state_graph, logical_loc_mgr); } diff --git a/gcc/diagnostics/state-graphs.h b/gcc/diagnostics/state-graphs.h index ccf8bde821ab..ad18f82b5b73 100644 --- a/gcc/diagnostics/state-graphs.h +++ b/gcc/diagnostics/state-graphs.h @@ -22,7 +22,7 @@ along with GCC; see the file COPYING3. If not see #define GCC_DIAGNOSTICS_STATE_GRAPHS_H #include "diagnostics/digraphs.h" -#include "logical-location.h" +#include "diagnostics/logical-locations.h" /* diagnostics::digraphs provides support for directed graphs. @@ -96,7 +96,7 @@ struct state_node_ref set_node_kind (enum node_kind); // For node_kind::stack_frame, this will be the function - logical_location + logical_locations::key get_logical_loc () const { return m_node.get_logical_loc (); @@ -148,7 +148,7 @@ struct state_node_ref extern std::unique_ptr<dot::graph> make_dot_graph (const diagnostics::digraphs::digraph &state_graph, - const logical_location_manager &logical_loc_mgr); + const logical_locations::manager &logical_loc_mgr); } // namespace state_graphs } // namespace diagnostics diff --git a/gcc/libgdiagnostics.cc b/gcc/libgdiagnostics.cc index 7bf0cbd7f4b8..8ccb27899586 100644 --- a/gcc/libgdiagnostics.cc +++ b/gcc/libgdiagnostics.cc @@ -35,7 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic-output-spec.h" #include "diagnostics/digraphs.h" #include "diagnostics/state-graphs.h" -#include "logical-location.h" +#include "diagnostics/logical-locations.h" #include "edit-context.h" #include "libgdiagnostics.h" #include "libgdiagnostics-private.h" @@ -458,19 +458,23 @@ round_alloc_size (size_t s) return s; } -class impl_logical_location_manager : public logical_location_manager +class impl_logical_location_manager + : public diagnostics::logical_locations::manager { public: + using key = diagnostics::logical_locations::key; + using kind = diagnostics::logical_locations::kind; + static const diagnostic_logical_location * - ptr_from_key (logical_location k) + ptr_from_key (key k) { return k.cast_to<const diagnostic_logical_location *> (); } - static logical_location + static key key_from_ptr (const diagnostic_logical_location *ptr) { - return logical_location::from_ptr (ptr); + return key::from_ptr (ptr); } const char *get_short_name (key k) const final override @@ -497,7 +501,7 @@ public: return nullptr; } - enum logical_location_kind get_kind (key k) const final override + kind get_kind (key k) const final override { auto loc = ptr_from_key (k); gcc_assert (loc); @@ -507,45 +511,45 @@ public: gcc_unreachable (); case DIAGNOSTIC_LOGICAL_LOCATION_KIND_FUNCTION: - return logical_location_kind::function; + return kind::function; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_MEMBER: - return logical_location_kind::member; + return kind::member; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_MODULE: - return logical_location_kind::module_; + return kind::module_; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_NAMESPACE: - return logical_location_kind::namespace_; + return kind::namespace_; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_TYPE: - return logical_location_kind::type; + return kind::type; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_RETURN_TYPE: - return logical_location_kind::return_type; + return kind::return_type; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_PARAMETER: - return logical_location_kind::parameter; + return kind::parameter; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_VARIABLE: - return logical_location_kind::variable; + return kind::variable; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_ELEMENT: - return logical_location_kind::element; + return kind::element; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_ATTRIBUTE: - return logical_location_kind::attribute; + return kind::attribute; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_TEXT: - return logical_location_kind::text; + return kind::text; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_COMMENT: - return logical_location_kind::comment; + return kind::comment; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_PROCESSING_INSTRUCTION: - return logical_location_kind::processing_instruction; + return kind::processing_instruction; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_DTD: - return logical_location_kind::dtd; + return kind::dtd; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_DECLARATION: - return logical_location_kind::declaration; + return kind::declaration; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_OBJECT: - return logical_location_kind::object; + return kind::object; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_ARRAY: - return logical_location_kind::array; + return kind::array; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_PROPERTY: - return logical_location_kind::property; + return kind::property; case DIAGNOSTIC_LOGICAL_LOCATION_KIND_VALUE: - return logical_location_kind::value; + return kind::value; } } @@ -573,12 +577,13 @@ public: const client_version_info *get_any_version_info () const final override; - const logical_location_manager * + const diagnostics::logical_locations::manager * get_logical_location_manager () const final override { return &m_logical_location_manager; } - logical_location get_current_logical_location () const final override; + diagnostics::logical_locations::key + get_current_logical_location () const final override; const char * maybe_get_sarif_source_language (const char *filename) const final override; @@ -688,7 +693,7 @@ public: line_maps *get_line_table () { return &m_line_table; } diagnostic_context &get_dc () { return m_dc; } - const logical_location_manager & + const diagnostics::logical_locations::manager & get_logical_location_manager () const { auto mgr = m_dc.get_logical_location_manager (); @@ -1023,7 +1028,8 @@ public: } } - logical_location get_logical_location () const final override + diagnostics::logical_locations::key + get_logical_location () const final override { return impl_logical_location_manager::key_from_ptr (m_logical_loc); } @@ -1160,9 +1166,10 @@ struct diagnostic_execution_path : public diagnostic_path same_function_p (int event_idx_a, int event_idx_b) const final override { + using logical_location = diagnostics::logical_locations::key; logical_location logical_loc_a = m_events[event_idx_a]->get_logical_location (); - logical_location logical_loc_b + logical_location logical_loc_b = m_events[event_idx_b]->get_logical_location (); /* Pointer equality, as we uniqify logical location instances. */ @@ -1370,7 +1377,7 @@ impl_diagnostic_client_data_hooks::get_any_version_info () const return m_mgr.get_client_version_info (); } -logical_location +diagnostics::logical_locations::key impl_diagnostic_client_data_hooks::get_current_logical_location () const { gcc_assert (m_mgr.get_current_diag ()); diff --git a/gcc/selftest-diagnostic-path.cc b/gcc/selftest-diagnostic-path.cc index 04372e7b47b6..c7b96f128232 100644 --- a/gcc/selftest-diagnostic-path.cc +++ b/gcc/selftest-diagnostic-path.cc @@ -206,7 +206,7 @@ test_diagnostic_path::add_call (const char *caller_name, add_entry (callee_name, caller_stack_depth + 1, thread_id); } -logical_location +diagnostics::logical_locations::key test_diagnostic_path::logical_location_from_funcname (const char *funcname) { return m_test_logical_loc_mgr.logical_location_from_funcname (funcname); diff --git a/gcc/selftest-diagnostic-path.h b/gcc/selftest-diagnostic-path.h index 8829943556e0..00b6c64ffcfe 100644 --- a/gcc/selftest-diagnostic-path.h +++ b/gcc/selftest-diagnostic-path.h @@ -22,7 +22,7 @@ along with GCC; see the file COPYING3. If not see #define GCC_SELFTEST_DIAGNOSTIC_PATH_H #include "diagnostic-path.h" -#include "selftest-logical-location.h" +#include "diagnostics/selftest-logical-locations.h" /* The selftest code should entirely disappear in a production configuration, hence we guard all of it with #if CHECKING_P. */ @@ -41,6 +41,8 @@ namespace selftest { class test_diagnostic_event : public diagnostic_event { public: + using logical_location = diagnostics::logical_locations::key; + test_diagnostic_event (location_t loc, logical_location logical_loc, int depth, @@ -143,7 +145,7 @@ class test_diagnostic_path : public diagnostic_path diagnostic_thread_id_t thread_id = 0); private: - logical_location + diagnostics::logical_locations::key logical_location_from_funcname (const char *funcname); test_logical_location_manager m_test_logical_loc_mgr; diff --git a/gcc/selftest-run-tests.cc b/gcc/selftest-run-tests.cc index 8cd04149f1ae..734959a5ba62 100644 --- a/gcc/selftest-run-tests.cc +++ b/gcc/selftest-run-tests.cc @@ -94,7 +94,7 @@ selftest::run_tests () digraph_cc_tests (); tristate_cc_tests (); ipa_modref_tree_cc_tests (); - selftest_logical_location_cc_tests (); + diagnostics_selftest_logical_locations_cc_tests (); /* Higher-level tests, or for components that other selftests don't rely on. */ diff --git a/gcc/selftest.h b/gcc/selftest.h index 5b1d2b00ad89..f66f47214047 100644 --- a/gcc/selftest.h +++ b/gcc/selftest.h @@ -228,6 +228,7 @@ extern void diagnostic_output_spec_cc_tests (); extern void diagnostic_path_output_cc_tests (); extern void diagnostic_show_locus_cc_tests (); extern void diagnostics_digraphs_cc_tests (); +extern void diagnostics_selftest_logical_locations_cc_tests (); extern void diagnostics_state_graphs_cc_tests (); extern void digraph_cc_tests (); extern void dumpfile_cc_tests (); @@ -263,7 +264,6 @@ extern void relation_tests (); extern void rtl_tests_cc_tests (); extern void sbitmap_cc_tests (); extern void selftest_cc_tests (); -extern void selftest_logical_location_cc_tests (); extern void simple_diagnostic_path_cc_tests (); extern void simplify_rtx_cc_tests (); extern void spellcheck_cc_tests (); diff --git a/gcc/simple-diagnostic-path.h b/gcc/simple-diagnostic-path.h index d2b366e81485..1f9dfd8476db 100644 --- a/gcc/simple-diagnostic-path.h +++ b/gcc/simple-diagnostic-path.h @@ -40,7 +40,8 @@ class simple_diagnostic_event : public diagnostic_event location_t get_location () const final override { return m_loc; } int get_stack_depth () const final override { return m_depth; } void print_desc (pretty_printer &pp) const final override; - logical_location get_logical_location () const final override + diagnostics::logical_locations::key + get_logical_location () const final override { return tree_logical_location_manager::key_from_tree (m_fndecl); } @@ -67,7 +68,7 @@ class simple_diagnostic_event : public diagnostic_event private: location_t m_loc; tree m_fndecl; - logical_location m_logical_loc; + diagnostics::logical_locations::key m_logical_loc; int m_depth; char *m_desc; // has been i18n-ed and formatted bool m_connected_to_next_event; diff --git a/gcc/tree-diagnostic-client-data-hooks.cc b/gcc/tree-diagnostic-client-data-hooks.cc index 84bd4b53fe76..c800eb4288a1 100644 --- a/gcc/tree-diagnostic-client-data-hooks.cc +++ b/gcc/tree-diagnostic-client-data-hooks.cc @@ -123,12 +123,14 @@ public: return &m_version_info; } - const logical_location_manager *get_logical_location_manager () const final override + const diagnostics::logical_locations::manager * + get_logical_location_manager () const final override { return &m_logical_location_manager; } - logical_location_manager::key get_current_logical_location () const final override + diagnostics::logical_locations::key + get_current_logical_location () const final override { return m_logical_location_manager.key_from_tree (current_function_decl); } diff --git a/gcc/tree-logical-location.cc b/gcc/tree-logical-location.cc index 1d0cc5803dd7..19bccd1a7060 100644 --- a/gcc/tree-logical-location.cc +++ b/gcc/tree-logical-location.cc @@ -27,6 +27,8 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" #include "intl.h" +using namespace diagnostics::logical_locations; + static void assert_valid_tree (const_tree node) { @@ -35,7 +37,8 @@ assert_valid_tree (const_tree node) gcc_assert (TREE_CODE (node) != TRANSLATION_UNIT_DECL); } -/* class tree_logical_location_manager : public logical_location_manager. */ +/* class tree_logical_location_manager + : public diagnostics::logical_locations::manager. */ const char * tree_logical_location_manager::get_short_name (key k) const @@ -81,7 +84,7 @@ tree_logical_location_manager::get_internal_name (key k) const return NULL; } -enum logical_location_kind +enum kind tree_logical_location_manager::get_kind (key k) const { tree node = tree_from_key (k); @@ -90,18 +93,18 @@ tree_logical_location_manager::get_kind (key k) const switch (TREE_CODE (node)) { default: - return logical_location_kind::unknown; + return kind::unknown; case FUNCTION_DECL: - return logical_location_kind::function; + return kind::function; case PARM_DECL: - return logical_location_kind::parameter; + return kind::parameter; case VAR_DECL: - return logical_location_kind::variable; + return kind::variable; case NAMESPACE_DECL: - return logical_location_kind::namespace_; + return kind::namespace_; case RECORD_TYPE: - return logical_location_kind::type; + return kind::type; } } @@ -123,7 +126,7 @@ tree_logical_location_manager::get_name_for_path_output (key k) const return label_text (); } -logical_location +key tree_logical_location_manager::get_parent (key k) const { tree node = tree_from_key (k); @@ -132,16 +135,16 @@ tree_logical_location_manager::get_parent (key k) const if (DECL_P (node)) { if (!DECL_CONTEXT (node)) - return logical_location (); + return key (); if (TREE_CODE (DECL_CONTEXT (node)) == TRANSLATION_UNIT_DECL) - return logical_location (); + return key (); return key_from_tree (DECL_CONTEXT (node)); } else if (TYPE_P (node)) { if (!TYPE_CONTEXT (node)) - return logical_location (); + return key (); return key_from_tree (TYPE_CONTEXT (node)); } - return logical_location (); + return key (); } diff --git a/gcc/tree-logical-location.h b/gcc/tree-logical-location.h index 0d57888fef7f..2a7de37ade78 100644 --- a/gcc/tree-logical-location.h +++ b/gcc/tree-logical-location.h @@ -21,29 +21,33 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_TREE_LOGICAL_LOCATION_H #define GCC_TREE_LOGICAL_LOCATION_H -#include "logical-location.h" +#include "diagnostics/logical-locations.h" -/* A subclass of logical_location_manager in which the keys are - "tree". +/* A subclass of diagnostics::logical_locations::manager in which the + keys are "tree". Note that there is no integration with the garbage collector, - and so logical_location instances can only be short-lived. */ -class tree_logical_location_manager : public logical_location_manager + and so key instances can only be short-lived. */ +class tree_logical_location_manager + : public diagnostics::logical_locations::manager { public: + using key = diagnostics::logical_locations::key; + using kind = diagnostics::logical_locations::kind; + const char *get_short_name (key) const final override; const char *get_name_with_scope (key) const final override; const char *get_internal_name (key) const final override; - enum logical_location_kind get_kind (key) const final override; + kind get_kind (key) const final override; label_text get_name_for_path_output (key) const final override; key get_parent (key) const final override; - static tree tree_from_key (logical_location k) + static tree tree_from_key (key k) { return const_cast<tree> (k.cast_to<const_tree> ()); } - static logical_location key_from_tree (tree node) + static key key_from_tree (tree node) { - return logical_location::from_ptr (node); + return key::from_ptr (node); } };