Branch data Line data Source code
1 : : /* A class for referring to events within a diagnostics::paths::path.
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_DIAGNOSTICS_EVENT_ID_H
22 : : #define GCC_DIAGNOSTICS_EVENT_ID_H
23 : :
24 : : /* A class for referring to events within a diagnostics::paths::path.
25 : :
26 : : They are stored as 0-based offsets into the events, but
27 : : printed (e.g. via %@) as 1-based numbers.
28 : :
29 : : For example, a 3-event path has event offsets 0, 1, and 2,
30 : : which would be shown to the user as "(1)", "(2)" and "(3)".
31 : :
32 : : This has its own header so that pretty-print.cc can use this
33 : : to implement "%@" without bringing in all of diagnostics::paths.
34 : :
35 : : This has to be in the global namespace for compatibility with
36 : : c-format.cc in GCC 10 onwards. */
37 : :
38 : : class diagnostic_event_id_t
39 : : {
40 : : public:
41 : 61776 : diagnostic_event_id_t () : m_index (UNKNOWN_EVENT_IDX) {}
42 : 42454 : diagnostic_event_id_t (int zero_based_idx) : m_index (zero_based_idx) {}
43 : :
44 : 74724 : bool known_p () const { return m_index != UNKNOWN_EVENT_IDX; }
45 : :
46 : 140 : int zero_based () const
47 : : {
48 : 140 : gcc_assert (known_p ());
49 : 140 : return m_index;
50 : : }
51 : :
52 : 23705 : int one_based () const
53 : : {
54 : 23705 : gcc_assert (known_p ());
55 : 23705 : return m_index + 1;
56 : : }
57 : :
58 : : private:
59 : : static const int UNKNOWN_EVENT_IDX = -1;
60 : : int m_index; // zero-based
61 : : };
62 : :
63 : : namespace diagnostics {
64 : : namespace paths {
65 : :
66 : : typedef diagnostic_event_id_t event_id_t;
67 : :
68 : : /* A type for compactly referring to a particular thread within a
69 : : diagnostics::paths::path. Typically there is just one thread per path,
70 : : with id 0. */
71 : : typedef int thread_id_t;
72 : :
73 : : } // namespace paths
74 : : } // namespace diagnostics
75 : :
76 : :
77 : : /* A pointer to a diagnostic_event_id_t, for use with the "%@" format
78 : : code, which will print a 1-based representation for it, with suitable
79 : : colorization, e.g. "(1)".
80 : : The %@ format code requires that known_p be true for the event ID. */
81 : : typedef diagnostic_event_id_t *diagnostic_event_id_ptr;
82 : :
83 : : #endif /* ! GCC_DIAGNOSTICS_EVENT_ID_H */
|