https://gcc.gnu.org/g:bff1af9ebf6949da6274e94f7bf5bcc17d937a3d
commit r16-2525-gbff1af9ebf6949da6274e94f7bf5bcc17d937a3d Author: David Malcolm <dmalc...@redhat.com> Date: Fri Jul 25 15:13:36 2025 -0400 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 <dmalc...@redhat.com> Diff: --- 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 +++--- .../client-data-hooks.h} | 38 +++++++++++++--------- gcc/libgdiagnostics.cc | 14 ++++---- gcc/tree-diagnostic-client-data-hooks.cc | 17 +++++----- gcc/tree-diagnostic.cc | 2 +- 9 files changed, 52 insertions(+), 42 deletions(-) diff --git a/gcc/diagnostic-format-html.cc b/gcc/diagnostic-format-html.cc index a8e36d6f4f14..90a2ee239de2 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 5663e778f155..75451cbf779a 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 5df117d40ce5..fd4e421b56d6 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 b2b8f0a80511..1fc3720a1258 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<diagnostic_client_data_hooks> hooks) +set_client_data_hooks (std::unique_ptr<diagnostics::client_data_hooks> 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 e51de435b20b..4d8a76b21b4f 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<diagnostic_output_format> output_format); void set_text_art_charset (enum diagnostic_text_art_charset charset); - void set_client_data_hooks (std::unique_ptr<diagnostic_client_data_hooks> hooks); + void set_client_data_hooks (std::unique_ptr<diagnostics::client_data_hooks> hooks); void push_owned_urlifier (std::unique_ptr<urlifier>); 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/diagnostic-client-data-hooks.h b/gcc/diagnostics/client-data-hooks.h similarity index 85% rename from gcc/diagnostic-client-data-hooks.h rename to gcc/diagnostics/client-data-hooks.h index 32cda19d1b62..d7c549f3d258 100644 --- a/gcc/diagnostic-client-data-hooks.h +++ b/gcc/diagnostics/client-data-hooks.h @@ -18,33 +18,36 @@ 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_DIAGNOSTIC_CLIENT_DATA_HOOKS_H -#define GCC_DIAGNOSTIC_CLIENT_DATA_HOOKS_H +#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 diagnostic_client_data_hooks +class client_data_hooks { public: - virtual ~diagnostic_client_data_hooks () {} + 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 diagnostics::logical_locations::manager * + 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 diagnostics::logical_locations::key + virtual logical_locations::key get_current_logical_location () const = 0; /* Get a sourceLanguage value for FILENAME, or return NULL. @@ -58,13 +61,7 @@ class diagnostic_client_data_hooks 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<diagnostic_client_data_hooks> make_compiler_data_hooks (); - -class diagnostic_client_plugin_info; +class client_plugin_info; /* Abstract base class for a diagnostic_context to get at version information about the client. */ @@ -75,7 +72,7 @@ public: class plugin_visitor { public: - virtual void on_plugin (const diagnostic_client_plugin_info &) = 0; + virtual void on_plugin (const client_plugin_info &) = 0; }; virtual ~client_version_info () {} @@ -102,7 +99,7 @@ public: /* Abstract base class for a diagnostic_context to get at information about a specific plugin within a client. */ -class diagnostic_client_plugin_info +class client_plugin_info { public: /* For use e.g. by SARIF "name" property (SARIF v2.1.0 section 3.19.8). */ @@ -117,4 +114,13 @@ public: virtual const char *get_version () const = 0; }; -#endif /* ! GCC_DIAGNOSTIC_CLIENT_DATA_HOOKS_H */ +} // 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<diagnostics::client_data_hooks> +make_compiler_data_hooks (); + +#endif /* ! GCC_DIAGNOSTICS_CLIENT_DATA_HOOKS_H */ diff --git a/gcc/libgdiagnostics.cc b/gcc/libgdiagnostics.cc index a1a5b590faf7..65bad53f254a 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 c800eb4288a1..2010600bf787 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 <dmalc...@redhat.com>. @@ -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<diagnostic_client_data_hooks> +std::unique_ptr<diagnostics::client_data_hooks> make_compiler_data_hooks () { return std::make_unique<compiler_data_hooks> (); diff --git a/gcc/tree-diagnostic.cc b/gcc/tree-diagnostic.cc index 57c671576ce7..34c3de85d2e3 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"