lib: make trace IR API const-correct
[babeltrace.git] / include / babeltrace / trace-ir / field-classes-internal.h
CommitLineData
5cd6d0e5
PP
1#ifndef BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
2#define BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
3
4/*
5cd6d0e5
PP
5 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 *
7 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28#include <babeltrace/assert-pre-internal.h>
29#include <babeltrace/trace-ir/clock-class.h>
30#include <babeltrace/trace-ir/field-classes.h>
31#include <babeltrace/babeltrace-internal.h>
32#include <babeltrace/object-internal.h>
33#include <babeltrace/types.h>
34#include <stdint.h>
35#include <glib.h>
36
37#define BT_ASSERT_PRE_FC_IS_INT(_fc, _name) \
38 BT_ASSERT_PRE( \
40f4ba76
PP
39 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
40 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \
41 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \
42 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, \
5cd6d0e5
PP
43 _name " is not an integer field class: %![fc-]+F", (_fc))
44
45#define BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(_fc, _name) \
46 BT_ASSERT_PRE( \
40f4ba76
PP
47 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
48 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, \
5cd6d0e5
PP
49 _name " is not an unsigned integer field class: %![fc-]+F", (_fc))
50
51#define BT_ASSERT_PRE_FC_IS_ENUM(_fc, _name) \
52 BT_ASSERT_PRE( \
40f4ba76
PP
53 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \
54 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, \
5cd6d0e5
PP
55 _name " is not an enumeration field class: %![fc-]+F", (_fc))
56
57#define BT_ASSERT_PRE_FC_IS_ARRAY(_fc, _name) \
58 BT_ASSERT_PRE( \
40f4ba76
PP
59 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \
60 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY, \
5cd6d0e5
PP
61 _name " is not an array field class: %![fc-]+F", (_fc))
62
864cad70 63#define BT_ASSERT_PRE_FC_HAS_ID(_fc, _type, _name) \
40f4ba76 64 BT_ASSERT_PRE(((const struct bt_field_class *) (_fc))->type == (_type), \
864cad70
PP
65 _name " has the wrong type: expected-type=%s, " \
66 "%![fc-]+F", bt_common_field_class_type_string(_type), (_fc))
5cd6d0e5
PP
67
68#define BT_ASSERT_PRE_FC_HOT(_fc, _name) \
40f4ba76 69 BT_ASSERT_PRE_HOT((const struct bt_field_class *) (_fc), \
5cd6d0e5
PP
70 (_name), ": %!+F", (_fc))
71
72#define BT_FIELD_CLASS_NAMED_FC_AT_INDEX(_fc, _index) \
73 (&g_array_index(((struct bt_field_class_named_field_class_container *) (_fc))->named_fcs, \
74 struct bt_named_field_class, (_index)))
75
76#define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \
77 (&g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \
78 struct bt_field_class_enumeration_mapping, (_index)))
79
80#define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \
81 (&g_array_index((_mapping)->ranges, \
82 struct bt_field_class_enumeration_mapping_range, (_index)))
83
84struct bt_field;
85struct bt_field_class;
86
87struct bt_field_class {
88 struct bt_object base;
864cad70 89 enum bt_field_class_type type;
5cd6d0e5
PP
90 bool frozen;
91
92 /*
93 * Only used in developer mode, this flag indicates whether or
94 * not this field class is part of a trace.
95 */
96 bool part_of_trace;
97};
98
99struct bt_field_class_integer {
100 struct bt_field_class common;
101
102 /*
103 * Value range of fields built from this integer field class:
104 * this is an equivalent integer size in bits. More formally,
105 * `range` is `n` in:
106 *
107 * Unsigned range: [0, 2^n - 1]
108 * Signed range: [-2^(n - 1), 2^(n - 1) - 1]
109 */
110 uint64_t range;
111
112 enum bt_field_class_integer_preferred_display_base base;
113};
114
115struct bt_field_class_enumeration_mapping_range {
116 union {
117 uint64_t u;
118 int64_t i;
119 } lower;
120
121 union {
122 uint64_t u;
123 int64_t i;
124 } upper;
125};
126
127struct bt_field_class_enumeration_mapping {
128 GString *label;
129
130 /* Array of `struct bt_field_class_enumeration_mapping_range` */
131 GArray *ranges;
132};
133
134struct bt_field_class_enumeration {
135 struct bt_field_class_integer common;
136
137 /* Array of `struct bt_field_class_enumeration_mapping *` */
138 GArray *mappings;
139
140 /*
141 * This is an array of `const char *` which acts as a temporary
142 * (potentially growing) buffer for
143 * bt_field_class_unsigned_enumeration_get_mapping_labels_by_value()
144 * and
145 * bt_field_class_signed_enumeration_get_mapping_labels_by_value().
146 *
147 * The actual strings are owned by the mappings above.
148 */
149 GPtrArray *label_buf;
150};
151
152struct bt_field_class_real {
153 struct bt_field_class common;
154 bool is_single_precision;
155};
156
157struct bt_field_class_string {
158 struct bt_field_class common;
159};
160
161/* A named field class is a (name, field class) pair */
162struct bt_named_field_class {
163 GString *name;
164
165 /* Owned by this */
166 struct bt_field_class *fc;
167};
168
169/*
170 * This is the base field class for a container of named field classes.
171 * Structure and variant field classes inherit this.
172 */
173struct bt_field_class_named_field_class_container {
174 struct bt_field_class common;
175
176 /*
177 * Key: `const char *`, not owned by this (owned by named field
178 * type objects contained in `named_fcs` below).
179 */
180 GHashTable *name_to_index;
181
182 /* Array of `struct bt_named_field_class` */
183 GArray *named_fcs;
184};
185
186struct bt_field_class_structure {
187 struct bt_field_class_named_field_class_container common;
188};
189
190struct bt_field_class_array {
191 struct bt_field_class common;
192
193 /* Owned by this */
194 struct bt_field_class *element_fc;
195};
196
197struct bt_field_class_static_array {
198 struct bt_field_class_array common;
199 uint64_t length;
200};
201
202struct bt_field_class_dynamic_array {
203 struct bt_field_class_array common;
204
205 /* Weak: never dereferenced, only use to find it elsewhere */
206 struct bt_field_class *length_fc;
207
208 /* Owned by this */
209 struct bt_field_path *length_field_path;
210};
211
212struct bt_field_class_variant {
213 struct bt_field_class_named_field_class_container common;
214
215 /* Weak: never dereferenced, only use to find it elsewhere */
216 struct bt_field_class *selector_fc;
217
218 /* Owned by this */
219 struct bt_field_path *selector_field_path;
220};
221
222static inline
40f4ba76 223bool bt_field_class_has_known_type(const struct bt_field_class *fc)
5cd6d0e5 224{
864cad70
PP
225 return fc->type >= BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER &&
226 fc->type <= BT_FIELD_CLASS_TYPE_VARIANT;
5cd6d0e5
PP
227}
228
229BT_HIDDEN
40f4ba76 230void _bt_field_class_freeze(const struct bt_field_class *field_class);
5cd6d0e5
PP
231
232#ifdef BT_DEV_MODE
233# define bt_field_class_freeze _bt_field_class_freeze
234#else
235# define bt_field_class_freeze(_fc)
236#endif
237
238/*
239 * This function recursively marks `field_class` and its children as
240 * being part of a trace. This is used to validate that all field classes
241 * are used at a single location within trace objects even if they are
242 * shared objects for other purposes.
243 */
244BT_HIDDEN
40f4ba76 245void _bt_field_class_make_part_of_trace(const struct bt_field_class *field_class);
5cd6d0e5
PP
246
247#ifdef BT_DEV_MODE
248# define bt_field_class_make_part_of_trace _bt_field_class_make_part_of_trace
249#else
250# define bt_field_class_make_part_of_trace(_fc) ((void) _fc)
251#endif
252
253#endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */
This page took 0.032299 seconds and 4 git commands to generate.