AVR: Provide built-ins for strlen where the string lives in some AS.
[gcc.git] / gcc / tree-diagnostic-client-data-hooks.cc
blob80717c197572ca78811119b032a1ba5db708db7c
1 /* Implementation of diagnostic_client_data_hooks for the compilers
2 (e.g. with knowledge of "tree", lang_hooks, and timevars).
3 Copyright (C) 2022-2025 Free Software Foundation, Inc.
4 Contributed by David Malcolm <dmalcolm@redhat.com>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "version.h"
26 #include "tree.h"
27 #include "diagnostic.h"
28 #include "tree-logical-location.h"
29 #include "diagnostic-client-data-hooks.h"
30 #include "diagnostic-format-sarif.h"
31 #include "langhooks.h"
32 #include "plugin.h"
33 #include "timevar.h"
34 #include "make-unique.h"
36 /* Concrete class for supplying a diagnostic_context with information
37 about a specific plugin within the client, when the client is the
38 compiler (i.e. a GCC plugin). */
40 class compiler_diagnostic_client_plugin_info
41 : public diagnostic_client_plugin_info
43 public:
44 compiler_diagnostic_client_plugin_info (const plugin_name_args *args)
45 : m_args (args)
49 const char *get_short_name () const final override
51 return m_args->base_name;
54 const char *get_full_name () const final override
56 return m_args->full_name;
59 const char *get_version () const final override
61 return m_args->version;
64 private:
65 const plugin_name_args *m_args;
68 /* Concrete subclass of client_version_info for use by compilers proper,
69 (i.e. using lang_hooks, and with knowledge of GCC plugins). */
71 class compiler_version_info : public client_version_info
73 public:
74 const char *get_tool_name () const final override
76 return lang_hooks.name;
79 /* Compare with toplev.cc: print_version.
80 TARGET_NAME is passed in by the Makefile. */
81 char *
82 maybe_make_full_name () const final override
84 return xasprintf ("%s %sversion %s (%s)",
85 get_tool_name (), pkgversion_string, version_string,
86 TARGET_NAME);
89 const char *get_version_string () const final override
91 return version_string;
94 char *maybe_make_version_url () const final override
96 return xasprintf ("https://gcc.gnu.org/gcc-%i/", GCC_major_version);
99 void for_each_plugin (plugin_visitor &visitor) const final override
101 ::for_each_plugin (on_plugin_cb, &visitor);
104 private:
105 static void
106 on_plugin_cb (const plugin_name_args *args,
107 void *user_data)
109 compiler_diagnostic_client_plugin_info cpi (args);
110 client_version_info::plugin_visitor *visitor
111 = (client_version_info::plugin_visitor *)user_data;
112 visitor->on_plugin (cpi);
116 /* Subclass of diagnostic_client_data_hooks for use by compilers proper
117 i.e. with knowledge of "tree", access to langhooks, timevars etc. */
119 class compiler_data_hooks : public diagnostic_client_data_hooks
121 public:
122 const client_version_info *get_any_version_info () const final override
124 return &m_version_info;
127 const logical_location *get_current_logical_location () const final override
129 if (current_function_decl)
130 return &m_current_fndecl_logical_loc;
131 else
132 return NULL;
135 const char *
136 maybe_get_sarif_source_language (const char *filename) const final override
138 return lang_hooks.get_sarif_source_language (filename);
141 void
142 add_sarif_invocation_properties (sarif_object &invocation_obj)
143 const final override
145 if (g_timer)
146 if (auto timereport_val = g_timer->make_json ())
148 sarif_property_bag &bag_obj
149 = invocation_obj.get_or_create_properties ();
150 bag_obj.set ("gcc/timeReport", std::move (timereport_val));
152 /* If the user requested SARIF output, then assume they want the
153 time report data in the SARIF output, and *not* later emitted on
154 stderr.
155 Implement this by cleaning up the global timer instance now. */
156 delete g_timer;
157 g_timer = NULL;
161 private:
162 compiler_version_info m_version_info;
163 current_fndecl_logical_location m_current_fndecl_logical_loc;
166 /* Create a compiler_data_hooks (so that the class can be local
167 to this file). */
169 std::unique_ptr<diagnostic_client_data_hooks>
170 make_compiler_data_hooks ()
172 return ::make_unique<compiler_data_hooks> ();