GCC Middle and Back End API Reference
client-data-hooks.h
Go to the documentation of this file.
1/* Additional metadata about a client for a diagnostic context.
2 Copyright (C) 2022-2025 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_DIAGNOSTICS_CLIENT_DATA_HOOKS_H
22#define GCC_DIAGNOSTICS_CLIENT_DATA_HOOKS_H
23
25
26namespace diagnostics {
27
28class sarif_object;
30
31/* A bundle of additional metadata, owned by the diagnostics::context,
32 for querying things about the client, like version data. */
33
35{
36 public:
37 virtual ~client_data_hooks () {}
38
39 void dump (FILE *out, int indent) const;
40 void DEBUG_FUNCTION dump () const { dump (stderr, 0); }
41
42 /* Get version info for this client, or NULL. */
43 virtual const client_version_info *get_any_version_info () const = 0;
44
45 /* Get the current logical_locations::manager for this client, or null. */
46 virtual const logical_locations::manager *
48
49 /* Get the current logical location, or null.
50 If this returns a non-null logical location, then
51 get_logical_location_manager must return non-null. */
54
55 /* Get a sourceLanguage value for FILENAME, or return NULL.
56 See SARIF v2.1.0 Appendix J for suggested values. */
57 virtual const char *
58 maybe_get_sarif_source_language (const char *filename) const = 0;
59
60 /* Hook to allow client to populate a SARIF "invocation" object with
61 a custom property bag (see SARIF v2.1.0 section 3.8). */
62 virtual void
63 add_sarif_invocation_properties (sarif_object &invocation_obj) const = 0;
64};
65
67
68/* Abstract base class for a diagnostics::context to get at
69 version information about the client. */
70
72{
73public:
75 {
76 public:
77 virtual void on_plugin (const client_plugin_info &) = 0;
78 };
79
81
82 /* Get a string suitable for use as the value of the "name" property
83 (SARIF v2.1.0 section 3.19.8). */
84 virtual const char *get_tool_name () const = 0;
85
86 /* Create a string suitable for use as the value of the "fullName" property
87 (SARIF v2.1.0 section 3.19.9). */
88 virtual char *maybe_make_full_name () const = 0;
89
90 /* Get a string suitable for use as the value of the "version" property
91 (SARIF v2.1.0 section 3.19.13). */
92 virtual const char *get_version_string () const = 0;
93
94 /* Create a string suitable for use as the value of the "informationUri"
95 property (SARIF v2.1.0 section 3.19.17). */
96 virtual char *maybe_make_version_url () const = 0;
97
98 virtual void for_each_plugin (plugin_visitor &v) const = 0;
99};
100
101/* Abstract base class for a diagnostics::context to get at
102 information about a specific plugin within a client. */
103
105{
106public:
107 /* For use e.g. by SARIF "name" property (SARIF v2.1.0 section 3.19.8). */
108 virtual const char *get_short_name () const = 0;
109
110 /* For use e.g. by SARIF "fullName" property
111 (SARIF v2.1.0 section 3.19.9). */
112 virtual const char *get_full_name () const = 0;
113
114 /* For use e.g. by SARIF "version" property
115 (SARIF v2.1.0 section 3.19.13). */
116 virtual const char *get_version () const = 0;
117};
118
119} // namespace diagnostics
120
121/* Factory function for making an instance of client_data_hooks
122 for use in the compiler (i.e. with knowledge of "tree", access to
123 langhooks, etc). */
124
125extern std::unique_ptr<diagnostics::client_data_hooks>
127
128#endif /* ! GCC_DIAGNOSTICS_CLIENT_DATA_HOOKS_H */
Definition client-data-hooks.h:35
void DEBUG_FUNCTION dump() const
Definition client-data-hooks.h:40
virtual const char * maybe_get_sarif_source_language(const char *filename) const =0
virtual const client_version_info * get_any_version_info() const =0
virtual const logical_locations::manager * get_logical_location_manager() const =0
virtual logical_locations::key get_current_logical_location() const =0
virtual void add_sarif_invocation_properties(sarif_object &invocation_obj) const =0
virtual ~client_data_hooks()
Definition client-data-hooks.h:37
Definition client-data-hooks.h:105
virtual const char * get_full_name() const =0
virtual const char * get_short_name() const =0
virtual const char * get_version() const =0
Definition client-data-hooks.h:75
virtual void on_plugin(const client_plugin_info &)=0
Definition client-data-hooks.h:72
virtual char * maybe_make_full_name() const =0
virtual void for_each_plugin(plugin_visitor &v) const =0
virtual char * maybe_make_version_url() const =0
virtual ~client_version_info()
Definition client-data-hooks.h:80
virtual const char * get_tool_name() const =0
virtual const char * get_version_string() const =0
Definition logical-locations.h:101
Definition logical-locations.h:147
Definition sarif-sink.h:151
std::unique_ptr< diagnostics::client_data_hooks > make_compiler_data_hooks()
Definition tree-diagnostic-client-data-hooks.cc:174
Definition coretypes.h:167
#define DEBUG_FUNCTION
Definition system.h:1236