Line data Source code
1 : /* Concrete classes for implementing diagnostic paths, using tree.
2 : Copyright (C) 2019-2026 Free Software Foundation, Inc.
3 : Contributed by David Malcolm <dmalcolm@redhat.com>
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify it under
8 : the terms of the GNU General Public License as published by the Free
9 : Software Foundation; either version 3, or (at your option) any later
10 : version.
11 :
12 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with GCC; see the file COPYING3. If not see
19 : <http://www.gnu.org/licenses/>. */
20 :
21 : #ifndef GCC_SIMPLE_DIAGNOSTIC_PATH_H
22 : #define GCC_SIMPLE_DIAGNOSTIC_PATH_H
23 :
24 : #include "diagnostics/paths.h"
25 : #include "tree-logical-location.h"
26 :
27 : /* Concrete subclasses of the abstract base classes
28 : declared in diagnostic-path.h. */
29 :
30 : /* A simple implementation of diagnostic event.
31 : This uses "tree" and so is not in "namespace diagnostics". */
32 :
33 : class simple_diagnostic_event : public diagnostics::paths::event
34 : {
35 : public:
36 : using thread_id_t = diagnostics::paths::thread_id_t;
37 :
38 : simple_diagnostic_event (location_t loc, tree fndecl, int depth,
39 : const char *desc,
40 : thread_id_t thread_id = 0);
41 : ~simple_diagnostic_event ();
42 :
43 444 : location_t get_location () const final override { return m_loc; }
44 299 : int get_stack_depth () const final override { return m_depth; }
45 : void print_desc (pretty_printer &pp) const final override;
46 : diagnostics::logical_locations::key
47 75 : get_logical_location () const final override
48 : {
49 75 : return tree_logical_location_manager::key_from_tree (m_fndecl);
50 : }
51 117 : meaning get_meaning () const final override
52 : {
53 117 : return meaning ();
54 : }
55 293 : bool connect_to_next_event_p () const final override
56 : {
57 293 : return m_connected_to_next_event;
58 : }
59 361 : thread_id_t get_thread_id () const final override
60 : {
61 361 : return m_thread_id;
62 : }
63 :
64 0 : void connect_to_next_event ()
65 : {
66 0 : m_connected_to_next_event = true;
67 : }
68 :
69 372 : tree get_fndecl () const { return m_fndecl; }
70 :
71 : private:
72 : location_t m_loc;
73 : tree m_fndecl;
74 : diagnostics::logical_locations::key m_logical_loc;
75 : int m_depth;
76 : char *m_desc; // has been i18n-ed and formatted
77 : bool m_connected_to_next_event;
78 : thread_id_t m_thread_id;
79 : };
80 :
81 : /* A simple implementation of diagnostics::paths::thread. */
82 :
83 : class simple_diagnostic_thread : public diagnostics::paths::thread
84 : {
85 : public:
86 9764 : simple_diagnostic_thread (const char *name) : m_name (name) {}
87 259 : label_text get_name (bool) const final override
88 : {
89 259 : return label_text::borrow (m_name);
90 : }
91 :
92 : private:
93 : const char *m_name; // has been i18n-ed and formatted
94 : };
95 :
96 : /* A simple implementation of diagnostic_path, as a vector of
97 : simple_diagnostic_event instances. */
98 :
99 : class simple_diagnostic_path : public diagnostics::paths::path
100 : {
101 : public:
102 : using thread = diagnostics::paths::thread;
103 : using thread_id_t = diagnostics::paths::thread_id_t;
104 : using event = diagnostics::paths::event;
105 : using event_id_t = diagnostics::paths::event_id_t;
106 :
107 : simple_diagnostic_path (const tree_logical_location_manager &logical_loc_mgr,
108 : pretty_printer *event_pp);
109 :
110 5855 : unsigned num_events () const final override { return m_events.length (); }
111 : const event & get_event (int idx) const final override;
112 4 : unsigned num_threads () const final override { return m_threads.length (); }
113 : const thread &
114 : get_thread (thread_id_t) const final override;
115 : bool
116 : same_function_p (int event_idx_a,
117 : int event_idx_b) const final override;
118 :
119 : thread_id_t add_thread (const char *name);
120 :
121 : event_id_t add_event (location_t loc, tree fndecl, int depth,
122 : const char *fmt, ...)
123 : ATTRIBUTE_GCC_DIAG(5,6);
124 : event_id_t
125 : add_thread_event (thread_id_t thread_id,
126 : location_t loc, tree fndecl, int depth,
127 : const char *fmt, ...)
128 : ATTRIBUTE_GCC_DIAG(6,7);
129 :
130 : void connect_to_next_event ();
131 :
132 : void disable_event_localization () { m_localize_events = false; }
133 :
134 : private:
135 : auto_delete_vec<simple_diagnostic_thread> m_threads;
136 : auto_delete_vec<simple_diagnostic_event> m_events;
137 :
138 : /* (for use by add_event). */
139 : pretty_printer *m_event_pp;
140 : bool m_localize_events;
141 : };
142 :
143 : #endif /* ! GCC_SIMPLE_DIAGNOSTIC_PATH_H */
|