GCC Middle and Back End API Reference
units.h
Go to the documentation of this file.
1/* Traits for expressing units and dimensions in the type system.
2 Copyright (C) 2026 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
8under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15General Public License for 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_ANALYZER_UNITS_H
22#define GCC_ANALYZER_UNITS_H
23
24/* Traits types for distinguishing different kinds of scalars
25 and ranges, so that we get a type error if we mess up our units. */
26
27namespace ana {
28namespace units {
29
30/* Traits type representing the size of something in memory,
31 measured in *bits*. */
32
33struct bit
34{
35 // Forbid creating instances: this is just a trait
36 bit () = delete;
37
38 static constexpr const char *dump_type_name = "bits";
39 static constexpr const char *singular_dump_name = "bit";
40 static constexpr const char *plural_dump_name = "bit";
41};
42
43/* Traits type representing the size of something in memory,
44 measured in *bytes*. */
45
46struct byte
47{
48 // Forbid creating instances: this is just a trait
49 byte () = delete;
50
51 static constexpr const char *dump_type_name = "bytes";
52 static constexpr const char *singular_dump_name = "byte";
53 static constexpr const char *plural_dump_name = "bytes";
54};
55
56/* Enum for distinguishing different roles of a scalar
57 so e.g. "10" vs "byte 10" for an offset vs "10 bytes" for a size. */
58
59enum class role
60{
61 generic,
64};
65
66} // namespace ana::units
67} // namespace ana
68
69#endif /* GCC_ANALYZER_UNITS_H */
Definition common.h:68
role
Definition units.h:60
@ offset
Definition units.h:62
@ size
Definition units.h:63
Definition access-diagram.h:30
static constexpr const char * dump_type_name
Definition units.h:38
static constexpr const char * singular_dump_name
Definition units.h:39
static constexpr const char * plural_dump_name
Definition units.h:40
static constexpr const char * plural_dump_name
Definition units.h:53
static constexpr const char * singular_dump_name
Definition units.h:52
static constexpr const char * dump_type_name
Definition units.h:51