Branch data Line data Source code
1 : : /* Concrete classes for implementing diagnostic paths.
2 : : Copyright (C) 2019-2025 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 "diagnostic-path.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 : :
32 : : class simple_diagnostic_event : public diagnostic_event
33 : : {
34 : : public:
35 : : simple_diagnostic_event (location_t loc, tree fndecl, int depth,
36 : : const char *desc,
37 : : diagnostic_thread_id_t thread_id = 0);
38 : : ~simple_diagnostic_event ();
39 : :
40 : 274 : location_t get_location () const final override { return m_loc; }
41 : 223 : int get_stack_depth () const final override { return m_depth; }
42 : : void print_desc (pretty_printer &pp) const final override;
43 : 69 : logical_location get_logical_location () const final override
44 : : {
45 : 69 : return tree_logical_location_manager::key_from_tree (m_fndecl);
46 : : }
47 : 74 : meaning get_meaning () const final override
48 : : {
49 : 74 : return meaning ();
50 : : }
51 : 178 : bool connect_to_next_event_p () const final override
52 : : {
53 : 178 : return m_connected_to_next_event;
54 : : }
55 : 266 : diagnostic_thread_id_t get_thread_id () const final override
56 : : {
57 : 266 : return m_thread_id;
58 : : }
59 : :
60 : 0 : void connect_to_next_event ()
61 : : {
62 : 0 : m_connected_to_next_event = true;
63 : : }
64 : :
65 : 168 : tree get_fndecl () const { return m_fndecl; }
66 : :
67 : : private:
68 : : location_t m_loc;
69 : : tree m_fndecl;
70 : : logical_location m_logical_loc;
71 : : int m_depth;
72 : : char *m_desc; // has been i18n-ed and formatted
73 : : bool m_connected_to_next_event;
74 : : diagnostic_thread_id_t m_thread_id;
75 : : };
76 : :
77 : : /* A simple implementation of diagnostic_thread. */
78 : :
79 : : class simple_diagnostic_thread : public diagnostic_thread
80 : : {
81 : : public:
82 : 3977 : simple_diagnostic_thread (const char *name) : m_name (name) {}
83 : 230 : label_text get_name (bool) const final override
84 : : {
85 : 230 : return label_text::borrow (m_name);
86 : : }
87 : :
88 : : private:
89 : : const char *m_name; // has been i18n-ed and formatted
90 : : };
91 : :
92 : : /* A simple implementation of diagnostic_path, as a vector of
93 : : simple_diagnostic_event instances. */
94 : :
95 : : class simple_diagnostic_path : public diagnostic_path
96 : : {
97 : : public:
98 : : simple_diagnostic_path (const tree_logical_location_manager &logical_loc_mgr,
99 : : pretty_printer *event_pp);
100 : :
101 : 79 : unsigned num_events () const final override { return m_events.length (); }
102 : : const diagnostic_event & get_event (int idx) const final override;
103 : 8 : unsigned num_threads () const final override { return m_threads.length (); }
104 : : const diagnostic_thread &
105 : : get_thread (diagnostic_thread_id_t) const final override;
106 : : bool
107 : : same_function_p (int event_idx_a,
108 : : int event_idx_b) const final override;
109 : :
110 : : diagnostic_thread_id_t add_thread (const char *name);
111 : :
112 : : diagnostic_event_id_t add_event (location_t loc, tree fndecl, int depth,
113 : : const char *fmt, ...)
114 : : ATTRIBUTE_GCC_DIAG(5,6);
115 : : diagnostic_event_id_t
116 : : add_thread_event (diagnostic_thread_id_t thread_id,
117 : : location_t loc, tree fndecl, int depth,
118 : : const char *fmt, ...)
119 : : ATTRIBUTE_GCC_DIAG(6,7);
120 : :
121 : : void connect_to_next_event ();
122 : :
123 : : void disable_event_localization () { m_localize_events = false; }
124 : :
125 : : private:
126 : : auto_delete_vec<simple_diagnostic_thread> m_threads;
127 : : auto_delete_vec<simple_diagnostic_event> m_events;
128 : :
129 : : /* (for use by add_event). */
130 : : pretty_printer *m_event_pp;
131 : : bool m_localize_events;
132 : : };
133 : :
134 : : #endif /* ! GCC_SIMPLE_DIAGNOSTIC_PATH_H */
|