GCC Middle and Back End API Reference
diagnostic-event-id.h
Go to the documentation of this file.
1/* A class for referring to events within a diagnostic_path.
2 Copyright (C) 2019-2024 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_DIAGNOSTIC_EVENT_ID_H
22#define GCC_DIAGNOSTIC_EVENT_ID_H
23
24/* A class for referring to events within a diagnostic_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 diagnostic_path
34 (which e.g. refers to "tree"). */
35
37{
38 public:
40 diagnostic_event_id_t (int zero_based_idx) : m_index (zero_based_idx) {}
41
42 bool known_p () const { return m_index != UNKNOWN_EVENT_IDX; }
43
44 int zero_based () const
45 {
47 return m_index;
48 }
49
50 int one_based () const
51 {
53 return m_index + 1;
54 }
55
56 private:
57 static const int UNKNOWN_EVENT_IDX = -1;
58 int m_index; // zero-based
59};
60
61/* A pointer to a diagnostic_event_id_t, for use with the "%@" format
62 code, which will print a 1-based representation for it, with suitable
63 colorization, e.g. "(1)".
64 The %@ format code requires that known_p be true for the event ID. */
66
67/* A type for compactly referring to a particular thread within a
68 diagnostic_path. Typically there is just one thread per path,
69 with id 0. */
71
72#endif /* ! GCC_DIAGNOSTIC_EVENT_ID_H */
Definition diagnostic-event-id.h:37
static const int UNKNOWN_EVENT_IDX
Definition diagnostic-event-id.h:57
int zero_based() const
Definition diagnostic-event-id.h:44
bool known_p() const
Definition diagnostic-event-id.h:42
int one_based() const
Definition diagnostic-event-id.h:50
int m_index
Definition diagnostic-event-id.h:58
diagnostic_event_id_t(int zero_based_idx)
Definition diagnostic-event-id.h:40
diagnostic_event_id_t()
Definition diagnostic-event-id.h:39
int diagnostic_thread_id_t
Definition diagnostic-event-id.h:70
diagnostic_event_id_t * diagnostic_event_id_ptr
Definition diagnostic-event-id.h:65
#define gcc_assert(EXPR)
Definition system.h:814