1 /* Concrete classes for implementing diagnostic paths.
2 Copyright (C) 2019-2025 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>
5 This file is part of GCC.
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
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
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/>. */
21 #ifndef GCC_SIMPLE_DIAGNOSTIC_PATH_H
22 #define GCC_SIMPLE_DIAGNOSTIC_PATH_H
24 #include "diagnostic-path.h"
25 #include "tree-logical-location.h"
27 /* Concrete subclasses of the abstract base classes
28 declared in diagnostic-path.h. */
30 /* A simple implementation of diagnostic_event. */
32 class simple_diagnostic_event
: public diagnostic_event
35 simple_diagnostic_event (location_t loc
, tree fndecl
, int depth
,
37 diagnostic_thread_id_t thread_id
= 0);
38 ~simple_diagnostic_event ();
40 location_t
get_location () const final override
{ return m_loc
; }
41 int get_stack_depth () const final override
{ return m_depth
; }
42 void print_desc (pretty_printer
&pp
) const final override
;
43 const logical_location
*get_logical_location () const final override
46 return &m_logical_loc
;
50 meaning
get_meaning () const final override
54 bool connect_to_next_event_p () const final override
56 return m_connected_to_next_event
;
58 diagnostic_thread_id_t
get_thread_id () const final override
63 void connect_to_next_event ()
65 m_connected_to_next_event
= true;
68 tree
get_fndecl () const { return m_fndecl
; }
73 tree_logical_location m_logical_loc
;
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
;
80 /* A simple implementation of diagnostic_thread. */
82 class simple_diagnostic_thread
: public diagnostic_thread
85 simple_diagnostic_thread (const char *name
) : m_name (name
) {}
86 label_text
get_name (bool) const final override
88 return label_text::borrow (m_name
);
92 const char *m_name
; // has been i18n-ed and formatted
95 /* A simple implementation of diagnostic_path, as a vector of
96 simple_diagnostic_event instances. */
98 class simple_diagnostic_path
: public diagnostic_path
101 simple_diagnostic_path (pretty_printer
*event_pp
);
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
;
109 same_function_p (int event_idx_a
,
110 int event_idx_b
) const final override
;
112 diagnostic_thread_id_t
add_thread (const char *name
);
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);
123 void connect_to_next_event ();
125 void disable_event_localization () { m_localize_events
= false; }
128 auto_delete_vec
<simple_diagnostic_thread
> m_threads
;
129 auto_delete_vec
<simple_diagnostic_event
> m_events
;
131 /* (for use by add_event). */
132 pretty_printer
*m_event_pp
;
133 bool m_localize_events
;
136 #endif /* ! GCC_SIMPLE_DIAGNOSTIC_PATH_H */