]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/analyzer/record-layout.h
Update copyright years.
[thirdparty/gcc.git] / gcc / analyzer / record-layout.h
1 /* Declaration of class record_layout.
2 Copyright (C) 2022-2024 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
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License 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_ANALYZER_RECORD_LAYOUT_H
22 #define GCC_ANALYZER_RECORD_LAYOUT_H
23
24 #include "analyzer/store.h"
25
26 namespace ana {
27
28 /* Information of the layout of a RECORD_TYPE, capturing it as a vector
29 of items, where each item is either a field or padding. */
30
31 class record_layout
32 {
33 public:
34 /* An item within a record; either a field, or padding after a field. */
35 struct item
36 {
37 public:
38 item (const bit_range &br,
39 tree field,
40 bool is_padding)
41 : m_bit_range (br),
42 m_field (field),
43 m_is_padding (is_padding)
44 {
45 }
46
47 bit_offset_t get_start_bit_offset () const
48 {
49 return m_bit_range.get_start_bit_offset ();
50 }
51 bit_offset_t get_next_bit_offset () const
52 {
53 return m_bit_range.get_next_bit_offset ();
54 }
55
56 bool contains_p (bit_offset_t offset) const
57 {
58 return m_bit_range.contains_p (offset);
59 }
60
61 void dump_to_pp (pretty_printer *pp) const
62 {
63 if (m_is_padding)
64 pp_printf (pp, "padding after %qD", m_field);
65 else
66 pp_printf (pp, "%qD", m_field);
67 pp_string (pp, ", ");
68 m_bit_range.dump_to_pp (pp);
69 }
70
71 bit_range m_bit_range;
72 tree m_field;
73 bool m_is_padding;
74 };
75
76 record_layout (tree record_type);
77
78 void dump_to_pp (pretty_printer *pp) const;
79 DEBUG_FUNCTION void dump () const;
80
81 const record_layout::item *get_item_at (bit_offset_t offset) const;
82
83 private:
84 void maybe_pad_to (bit_offset_t next_offset);
85
86 auto_vec<item> m_items;
87 };
88
89 } // namespace ana
90
91 #endif /* GCC_ANALYZER_RECORD_LAYOUT_H */