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