2 * SPDX-License-Identifier: MIT
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 #ifndef BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
9 #define BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
11 #include "lib/assert-cond.h"
12 #include <babeltrace2/trace-ir/clock-class.h>
13 #include <babeltrace2/trace-ir/field-class.h>
14 #include "common/macros.h"
15 #include "common/common.h"
16 #include "lib/object.h"
17 #include <babeltrace2/types.h>
22 #define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \
23 (&bt_g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \
24 struct bt_field_class_enumeration_mapping, (_index)))
26 #define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \
27 (&bt_g_array_index((_mapping)->ranges, \
28 struct bt_field_class_enumeration_mapping_range, (_index)))
30 struct bt_field_class
{
31 struct bt_object base
;
32 enum bt_field_class_type type
;
36 struct bt_value
*user_attributes
;
39 * This flag indicates whether or not this field class is part
42 bool part_of_trace_class
;
45 struct bt_field_class_bool
{
46 struct bt_field_class common
;
49 struct bt_field_class_bit_array
{
50 struct bt_field_class common
;
54 struct bt_field_class_integer
{
55 struct bt_field_class common
;
58 * Value range of fields built from this integer field class:
59 * this is an equivalent integer size in bits. More formally,
62 * Unsigned range: [0, 2^n - 1]
63 * Signed range: [-2^(n - 1), 2^(n - 1) - 1]
67 enum bt_field_class_integer_preferred_display_base base
;
70 struct bt_field_class_enumeration_mapping
{
74 const struct bt_integer_range_set
*range_set
;
77 struct bt_field_class_enumeration_unsigned_mapping
;
78 struct bt_field_class_enumeration_signed_mapping
;
80 struct bt_field_class_enumeration
{
81 struct bt_field_class_integer common
;
83 /* Array of `struct bt_field_class_enumeration_mapping *` */
87 * This is an array of `const char *` which acts as a temporary
88 * (potentially growing) buffer for
89 * bt_field_class_enumeration_unsigned_get_mapping_labels_for_value()
91 * bt_field_class_enumeration_signed_get_mapping_labels_for_value().
93 * The actual strings are owned by the mappings above.
98 struct bt_field_class_real
{
99 struct bt_field_class common
;
102 struct bt_field_class_string
{
103 struct bt_field_class common
;
106 /* A named field class is a (name, field class) pair */
107 struct bt_named_field_class
{
111 struct bt_value
*user_attributes
;
114 struct bt_field_class
*fc
;
119 struct bt_field_class_structure_member
;
120 struct bt_field_class_variant_option
;
121 struct bt_field_class_variant_with_selector_field_integer_unsigned_option
;
122 struct bt_field_class_variant_with_selector_field_integer_signed_option
;
124 struct bt_field_class_named_field_class_container
{
125 struct bt_field_class common
;
128 * Key: `const char *`, not owned by this (owned by named field
129 * class objects contained in `named_fcs` below).
131 GHashTable
*name_to_index
;
133 /* Array of `struct bt_named_field_class *` */
134 GPtrArray
*named_fcs
;
137 struct bt_field_class_structure
{
138 struct bt_field_class_named_field_class_container common
;
141 struct bt_field_class_array
{
142 struct bt_field_class common
;
145 struct bt_field_class
*element_fc
;
148 struct bt_field_class_array_static
{
149 struct bt_field_class_array common
;
153 struct bt_field_class_array_dynamic
{
154 struct bt_field_class_array common
;
157 struct bt_field_class
*length_fc
;
160 struct bt_field_path
*length_field_path
;
163 struct bt_field_class_option
{
164 struct bt_field_class common
;
167 struct bt_field_class
*content_fc
;
170 struct bt_field_class_option_with_selector_field
{
171 struct bt_field_class_option common
;
174 struct bt_field_class
*selector_fc
;
177 struct bt_field_path
*selector_field_path
;
180 struct bt_field_class_option_with_selector_field_bool
{
181 struct bt_field_class_option_with_selector_field common
;
184 bool sel_is_reversed
;
187 struct bt_field_class_option_with_selector_field_integer
{
188 struct bt_field_class_option_with_selector_field common
;
191 const struct bt_integer_range_set
*range_set
;
194 /* Variant FC (with selector) option: named field class + range set */
195 struct bt_field_class_variant_with_selector_field_option
{
196 struct bt_named_field_class common
;
199 const struct bt_integer_range_set
*range_set
;
202 struct bt_field_class_variant
{
204 * Depending on the variant field class type, the contained
205 * named field classes are of type
206 * `struct bt_named_field_class *` if the variant field class
207 * doesn't have a selector, or
208 * `struct bt_field_class_variant_with_selector_field_option *`
211 struct bt_field_class_named_field_class_container common
;
214 struct bt_field_class_variant_with_selector_field
{
215 struct bt_field_class_variant common
;
218 * Owned by this, but never dereferenced: only use to find it
221 const struct bt_field_class
*selector_fc
;
224 struct bt_field_path
*selector_field_path
;
227 void _bt_field_class_freeze(const struct bt_field_class
*field_class
);
230 # define bt_field_class_freeze _bt_field_class_freeze
232 # define bt_field_class_freeze(_fc) ((void) _fc)
235 void _bt_named_field_class_freeze(const struct bt_named_field_class
*named_fc
);
238 # define bt_named_field_class_freeze _bt_named_field_class_freeze
240 # define bt_named_field_class_freeze(_named_fc) ((void) _named_fc)
244 * This function recursively marks `field_class` and its children as
245 * being part of a trace. This is used to validate that all field classes
246 * are used at a single location within trace objects even if they are
247 * shared objects for other purposes.
249 void bt_field_class_make_part_of_trace_class(
250 const struct bt_field_class
*field_class
);
252 #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */