From bff1af9ebf6949da6274e94f7bf5bcc17d937a3d Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 25 Jul 2025 15:13:36 -0400 Subject: diagnostics: move client data hooks into namespace/dir "diagnostics" No functional change intended. Note that the tree-*.cc implementations are *not* moved into namespace diagnostics. gcc/ChangeLog: * diagnostic-format-html.cc: Update #include for move of diagnostic-client-data-hooks.h to diagnostics/client-data-hooks.h. * diagnostic-format-sarif.cc: Likewise. Update for move of diagnostic_client_plugin_info to diagnostics::client_plugin_info. * diagnostic-format-text.cc: Likewise. * diagnostic.cc: Likewise. * diagnostic.h: Likewise. * diagnostic-client-data-hooks.h: Move to... * diagnostics/client-data-hooks.h: ...here, updating header guard. (class diagnostic_client_data_hooks): Move to... (class diagnostics::client_data_hooks): ...here. Remove redundant "diagnostics::" prefixes. (class diagnostic_client_plugin_info): Move to... (class diagnostics::client_plugin_info): ...here. * libgdiagnostics.cc: : Update #include for move of diagnostic-client-data-hooks.h to diagnostics/client-data-hooks.h. Update for move of diagnostic_client_data_hooks to diagnostics::client_data_hooks, and for move of diagnostic_client_version_info to diagnostics::client_version_info. * tree-diagnostic-client-data-hooks.cc: Likewise. * tree-diagnostic.cc: Likewise. Signed-off-by: David Malcolm --- gcc/diagnostic-client-data-hooks.h | 120 ----------------------------- gcc/diagnostic-format-html.cc | 2 +- gcc/diagnostic-format-sarif.cc | 5 +- gcc/diagnostic-format-text.cc | 2 +- gcc/diagnostic.cc | 4 +- gcc/diagnostic.h | 10 +-- gcc/diagnostics/client-data-hooks.h | 126 +++++++++++++++++++++++++++++++ gcc/libgdiagnostics.cc | 14 ++-- gcc/tree-diagnostic-client-data-hooks.cc | 17 +++-- gcc/tree-diagnostic.cc | 2 +- 10 files changed, 156 insertions(+), 146 deletions(-) delete mode 100644 gcc/diagnostic-client-data-hooks.h create mode 100644 gcc/diagnostics/client-data-hooks.h (limited to 'gcc') diff --git a/gcc/diagnostic-client-data-hooks.h b/gcc/diagnostic-client-data-hooks.h deleted file mode 100644 index 32cda19..0000000 --- a/gcc/diagnostic-client-data-hooks.h +++ /dev/null @@ -1,120 +0,0 @@ -/* Additional metadata about a client for a diagnostic context. - Copyright (C) 2022-2025 Free Software Foundation, Inc. - Contributed by David Malcolm - -This file is part of GCC. - -GCC is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 3, or (at your option) any later -version. - -GCC is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -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_CLIENT_DATA_HOOKS_H -#define GCC_DIAGNOSTIC_CLIENT_DATA_HOOKS_H - -#include "diagnostics/logical-locations.h" - -class sarif_object; -class client_version_info; - -/* A bundle of additional metadata, owned by the diagnostic_context, - for querying things about the client, like version data. */ - -class diagnostic_client_data_hooks -{ - public: - virtual ~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_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 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. */ - virtual const char * - maybe_get_sarif_source_language (const char *filename) const = 0; - - /* Hook to allow client to populate a SARIF "invocation" object with - a custom property bag (see SARIF v2.1.0 section 3.8). */ - virtual void - add_sarif_invocation_properties (sarif_object &invocation_obj) const = 0; -}; - -/* Factory function for making an instance of diagnostic_client_data_hooks - for use in the compiler (i.e. with knowledge of "tree", access to - langhooks, etc). */ - -extern std::unique_ptr make_compiler_data_hooks (); - -class diagnostic_client_plugin_info; - -/* Abstract base class for a diagnostic_context to get at - version information about the client. */ - -class client_version_info -{ -public: - class plugin_visitor - { - public: - virtual void on_plugin (const diagnostic_client_plugin_info &) = 0; - }; - - virtual ~client_version_info () {} - - /* Get a string suitable for use as the value of the "name" property - (SARIF v2.1.0 section 3.19.8). */ - virtual const char *get_tool_name () const = 0; - - /* Create a string suitable for use as the value of the "fullName" property - (SARIF v2.1.0 section 3.19.9). */ - virtual char *maybe_make_full_name () const = 0; - - /* Get a string suitable for use as the value of the "version" property - (SARIF v2.1.0 section 3.19.13). */ - virtual const char *get_version_string () const = 0; - - /* Create a string suitable for use as the value of the "informationUri" - property (SARIF v2.1.0 section 3.19.17). */ - virtual char *maybe_make_version_url () const = 0; - - virtual void for_each_plugin (plugin_visitor &v) const = 0; -}; - -/* Abstract base class for a diagnostic_context to get at - information about a specific plugin within a client. */ - -class diagnostic_client_plugin_info -{ -public: - /* For use e.g. by SARIF "name" property (SARIF v2.1.0 section 3.19.8). */ - virtual const char *get_short_name () const = 0; - - /* For use e.g. by SARIF "fullName" property - (SARIF v2.1.0 section 3.19.9). */ - virtual const char *get_full_name () const = 0; - - /* For use e.g. by SARIF "version" property - (SARIF v2.1.0 section 3.19.13). */ - virtual const char *get_version () const = 0; -}; - -#endif /* ! GCC_DIAGNOSTIC_CLIENT_DATA_HOOKS_H */ diff --git a/gcc/diagnostic-format-html.cc b/gcc/diagnostic-format-html.cc index a8e36d6..90a2ee2 100644 --- a/gcc/diagnostic-format-html.cc +++ b/gcc/diagnostic-format-html.cc @@ -33,7 +33,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic-output-file.h" #include "diagnostic-buffer.h" #include "diagnostic-path.h" -#include "diagnostic-client-data-hooks.h" +#include "diagnostics/client-data-hooks.h" #include "selftest.h" #include "selftest-diagnostic.h" #include "pretty-print-format-impl.h" diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc index 5663e77..75451cb 100644 --- a/gcc/diagnostic-format-sarif.cc +++ b/gcc/diagnostic-format-sarif.cc @@ -36,7 +36,7 @@ along with GCC; see the file COPYING3. If not see #include "json.h" #include "cpplib.h" #include "diagnostics/logical-locations.h" -#include "diagnostic-client-data-hooks.h" +#include "diagnostics/client-data-hooks.h" #include "diagnostics/diagram.h" #include "text-art/canvas.h" #include "diagnostic-format-sarif.h" @@ -3442,7 +3442,8 @@ sarif_builder::make_tool_object () class my_plugin_visitor : public client_version_info :: plugin_visitor { public: - void on_plugin (const diagnostic_client_plugin_info &p) final override + void + on_plugin (const client_plugin_info &p) final override { /* Create a "toolComponent" object (SARIF v2.1.0 section 3.19) for the plugin. */ diff --git a/gcc/diagnostic-format-text.cc b/gcc/diagnostic-format-text.cc index 5df117d..fd4e421 100644 --- a/gcc/diagnostic-format-text.cc +++ b/gcc/diagnostic-format-text.cc @@ -29,7 +29,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic-url.h" #include "diagnostics/metadata.h" #include "diagnostic-path.h" -#include "diagnostic-client-data-hooks.h" +#include "diagnostics/client-data-hooks.h" #include "diagnostics/diagram.h" #include "diagnostic-format-text.h" #include "diagnostic-buffer.h" diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index b2b8f0a..1fc3720 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -35,7 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic-url.h" #include "diagnostics/metadata.h" #include "diagnostic-path.h" -#include "diagnostic-client-data-hooks.h" +#include "diagnostics/client-data-hooks.h" #include "diagnostics/diagram.h" #include "diagnostic-format.h" #include "diagnostic-format-sarif.h" @@ -533,7 +533,7 @@ diagnostic_context::set_main_input_filename (const char *filename) void diagnostic_context:: -set_client_data_hooks (std::unique_ptr hooks) +set_client_data_hooks (std::unique_ptr hooks) { delete m_client_data_hooks; /* Ideally the field would be a std::unique_ptr here. */ diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index e51de43..4d8a76b 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -38,6 +38,7 @@ namespace diagnostics { class manager; } // namespace diagnostics::logical_locations + class client_data_hooks; class diagram; class edit_context; @@ -236,7 +237,6 @@ public: virtual char *make_option_url (diagnostic_option_id option_id) const = 0; }; -class diagnostic_client_data_hooks; class diagnostic_source_effect_info; class diagnostic_output_format; class diagnostic_text_output_format; @@ -550,7 +550,7 @@ struct diagnostic_counters - a cache for use when quoting the user's source code (class file_cache) - a text_art::theme - a diagnostics::edit_context for generating patches from fix-it hints - - diagnostic_client_data_hooks for metadata. + - diagnostics::client_data_hooks for metadata. Try to avoid adding new responsibilities to this class itself, to avoid the "blob" anti-pattern. */ @@ -672,7 +672,7 @@ public: /* Various setters for use by option-handling logic. */ void set_output_format (std::unique_ptr output_format); void set_text_art_charset (enum diagnostic_text_art_charset charset); - void set_client_data_hooks (std::unique_ptr hooks); + void set_client_data_hooks (std::unique_ptr hooks); void push_owned_urlifier (std::unique_ptr); void push_borrowed_urlifier (const urlifier &); @@ -730,7 +730,7 @@ public: { return m_edit_context_ptr; } - const diagnostic_client_data_hooks *get_client_data_hooks () const + const diagnostics::client_data_hooks *get_client_data_hooks () const { return m_client_data_hooks; } @@ -1100,7 +1100,7 @@ private: producing diagnostics. Owned by the context; this would be a std::unique_ptr if diagnostic_context had a proper ctor. */ - diagnostic_client_data_hooks *m_client_data_hooks; + diagnostics::client_data_hooks *m_client_data_hooks; /* Support for diagrams. */ struct diff --git a/gcc/diagnostics/client-data-hooks.h b/gcc/diagnostics/client-data-hooks.h new file mode 100644 index 0000000..d7c549f --- /dev/null +++ b/gcc/diagnostics/client-data-hooks.h @@ -0,0 +1,126 @@ +/* Additional metadata about a client for a diagnostic context. + Copyright (C) 2022-2025 Free Software Foundation, Inc. + Contributed by David Malcolm + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef GCC_DIAGNOSTICS_CLIENT_DATA_HOOKS_H +#define GCC_DIAGNOSTICS_CLIENT_DATA_HOOKS_H + +#include "diagnostics/logical-locations.h" + +class sarif_object; + +namespace diagnostics { + +class client_version_info; + +/* A bundle of additional metadata, owned by the diagnostic_context, + for querying things about the client, like version data. */ + +class client_data_hooks +{ + public: + virtual ~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_locations::manager for this client, or null. */ + virtual const 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_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. */ + virtual const char * + maybe_get_sarif_source_language (const char *filename) const = 0; + + /* Hook to allow client to populate a SARIF "invocation" object with + a custom property bag (see SARIF v2.1.0 section 3.8). */ + virtual void + add_sarif_invocation_properties (sarif_object &invocation_obj) const = 0; +}; + +class client_plugin_info; + +/* Abstract base class for a diagnostic_context to get at + version information about the client. */ + +class client_version_info +{ +public: + class plugin_visitor + { + public: + virtual void on_plugin (const client_plugin_info &) = 0; + }; + + virtual ~client_version_info () {} + + /* Get a string suitable for use as the value of the "name" property + (SARIF v2.1.0 section 3.19.8). */ + virtual const char *get_tool_name () const = 0; + + /* Create a string suitable for use as the value of the "fullName" property + (SARIF v2.1.0 section 3.19.9). */ + virtual char *maybe_make_full_name () const = 0; + + /* Get a string suitable for use as the value of the "version" property + (SARIF v2.1.0 section 3.19.13). */ + virtual const char *get_version_string () const = 0; + + /* Create a string suitable for use as the value of the "informationUri" + property (SARIF v2.1.0 section 3.19.17). */ + virtual char *maybe_make_version_url () const = 0; + + virtual void for_each_plugin (plugin_visitor &v) const = 0; +}; + +/* Abstract base class for a diagnostic_context to get at + information about a specific plugin within a client. */ + +class client_plugin_info +{ +public: + /* For use e.g. by SARIF "name" property (SARIF v2.1.0 section 3.19.8). */ + virtual const char *get_short_name () const = 0; + + /* For use e.g. by SARIF "fullName" property + (SARIF v2.1.0 section 3.19.9). */ + virtual const char *get_full_name () const = 0; + + /* For use e.g. by SARIF "version" property + (SARIF v2.1.0 section 3.19.13). */ + virtual const char *get_version () const = 0; +}; + +} // namespace diagnostics + +/* Factory function for making an instance of client_data_hooks + for use in the compiler (i.e. with knowledge of "tree", access to + langhooks, etc). */ + +extern std::unique_ptr +make_compiler_data_hooks (); + +#endif /* ! GCC_DIAGNOSTICS_CLIENT_DATA_HOOKS_H */ diff --git a/gcc/libgdiagnostics.cc b/gcc/libgdiagnostics.cc index a1a5b59..65bad53 100644 --- a/gcc/libgdiagnostics.cc +++ b/gcc/libgdiagnostics.cc @@ -29,7 +29,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic-url.h" #include "diagnostics/metadata.h" #include "diagnostic-path.h" -#include "diagnostic-client-data-hooks.h" +#include "diagnostics/client-data-hooks.h" #include "diagnostic-format-sarif.h" #include "diagnostic-format-text.h" #include "diagnostic-output-spec.h" @@ -568,14 +568,15 @@ public: } }; -class impl_diagnostic_client_data_hooks : public diagnostic_client_data_hooks +class impl_diagnostic_client_data_hooks : public diagnostics::client_data_hooks { public: impl_diagnostic_client_data_hooks (diagnostic_manager &mgr) : m_mgr (mgr) {} - const client_version_info *get_any_version_info () const final override; + const diagnostics::client_version_info * + get_any_version_info () const final override; const diagnostics::logical_locations::manager * get_logical_location_manager () const final override @@ -595,7 +596,7 @@ private: impl_logical_location_manager m_logical_location_manager; }; -class impl_client_version_info : public client_version_info +class impl_client_version_info : public diagnostics::client_version_info { public: const char *get_tool_name () const final override @@ -824,7 +825,8 @@ public: const diagnostic *get_current_diag () { return m_current_diag; } - const client_version_info *get_client_version_info () const + const diagnostics::client_version_info * + get_client_version_info () const { return &m_client_version_info; } @@ -1372,7 +1374,7 @@ diagnostic_physical_location::get_file () const /* class impl_diagnostic_client_data_hooks. */ -const client_version_info * +const diagnostics::client_version_info * impl_diagnostic_client_data_hooks::get_any_version_info () const { return m_mgr.get_client_version_info (); diff --git a/gcc/tree-diagnostic-client-data-hooks.cc b/gcc/tree-diagnostic-client-data-hooks.cc index c800eb4..2010600 100644 --- a/gcc/tree-diagnostic-client-data-hooks.cc +++ b/gcc/tree-diagnostic-client-data-hooks.cc @@ -1,4 +1,4 @@ -/* Implementation of diagnostic_client_data_hooks for the compilers +/* Implementation of diagnostics::client_data_hooks for the compilers (e.g. with knowledge of "tree", lang_hooks, and timevars). Copyright (C) 2022-2025 Free Software Foundation, Inc. Contributed by David Malcolm . @@ -26,7 +26,7 @@ along with GCC; see the file COPYING3. If not see #include "tree.h" #include "diagnostic.h" #include "tree-logical-location.h" -#include "diagnostic-client-data-hooks.h" +#include "diagnostics/client-data-hooks.h" #include "diagnostic-format-sarif.h" #include "langhooks.h" #include "plugin.h" @@ -37,7 +37,7 @@ along with GCC; see the file COPYING3. If not see compiler (i.e. a GCC plugin). */ class compiler_diagnostic_client_plugin_info - : public diagnostic_client_plugin_info + : public diagnostics::client_plugin_info { public: compiler_diagnostic_client_plugin_info (const plugin_name_args *args) @@ -67,7 +67,7 @@ private: /* Concrete subclass of client_version_info for use by compilers proper, (i.e. using lang_hooks, and with knowledge of GCC plugins). */ -class compiler_version_info : public client_version_info +class compiler_version_info : public diagnostics::client_version_info { public: const char *get_tool_name () const final override @@ -112,13 +112,14 @@ private: } }; -/* Subclass of diagnostic_client_data_hooks for use by compilers proper +/* Subclass of diagnostics::client_data_hooks for use by compilers proper i.e. with knowledge of "tree", access to langhooks, timevars etc. */ -class compiler_data_hooks : public diagnostic_client_data_hooks +class compiler_data_hooks : public diagnostics::client_data_hooks { public: - const client_version_info *get_any_version_info () const final override + const diagnostics::client_version_info * + get_any_version_info () const final override { return &m_version_info; } @@ -169,7 +170,7 @@ private: /* Create a compiler_data_hooks (so that the class can be local to this file). */ -std::unique_ptr +std::unique_ptr make_compiler_data_hooks () { return std::make_unique (); diff --git a/gcc/tree-diagnostic.cc b/gcc/tree-diagnostic.cc index 57c6715..34c3de8 100644 --- a/gcc/tree-diagnostic.cc +++ b/gcc/tree-diagnostic.cc @@ -27,7 +27,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-pretty-print.h" #include "gimple-pretty-print.h" #include "tree-diagnostic.h" -#include "diagnostic-client-data-hooks.h" +#include "diagnostics/client-data-hooks.h" #include "langhooks.h" #include "intl.h" #include "diagnostic-format-text.h" -- cgit v1.1