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 <babeltrace2/trace-ir/clock-class.h>
12 #include <babeltrace2/trace-ir/field-class.h>
13 #include "common/macros.h"
14 #include "lib/object.h"
15 #include <babeltrace2/types.h>
20 #define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \
21 (&bt_g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \
22 struct bt_field_class_enumeration_mapping, (_index)))
24 #define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \
25 (&bt_g_array_index((_mapping)->ranges, \
26 struct bt_field_class_enumeration_mapping_range, (_index)))
28 struct bt_field_class
{
29 struct bt_object base
;
30 enum bt_field_class_type type
;
34 struct bt_value
*user_attributes
;
37 * This flag indicates whether or not this field class is part
40 bool part_of_trace_class
;
43 struct bt_field_class_bool
{
44 struct bt_field_class common
;
47 struct bt_field_class_bit_array
{
48 struct bt_field_class common
;
52 struct bt_field_class_integer
{
53 struct bt_field_class common
;
56 * Value range of fields built from this integer field class:
57 * this is an equivalent integer size in bits. More formally,
60 * Unsigned range: [0, 2^n - 1]
61 * Signed range: [-2^(n - 1), 2^(n - 1) - 1]
65 enum bt_field_class_integer_preferred_display_base base
;
68 struct bt_field_class_enumeration_mapping
{
72 const struct bt_integer_range_set
*range_set
;
75 struct bt_field_class_enumeration_unsigned_mapping
;
76 struct bt_field_class_enumeration_signed_mapping
;
78 struct bt_field_class_enumeration
{
79 struct bt_field_class_integer common
;
81 /* Array of `struct bt_field_class_enumeration_mapping *` */
85 * This is an array of `const char *` which acts as a temporary
86 * (potentially growing) buffer for
87 * bt_field_class_enumeration_unsigned_get_mapping_labels_for_value()
89 * bt_field_class_enumeration_signed_get_mapping_labels_for_value().
91 * The actual strings are owned by the mappings above.
96 struct bt_field_class_real
{
97 struct bt_field_class common
;
100 struct bt_field_class_string
{
101 struct bt_field_class common
;
104 /* A named field class is a (name, field class) pair */
105 struct bt_named_field_class
{
109 struct bt_value
*user_attributes
;
112 struct bt_field_class
*fc
;
117 struct bt_field_class_structure_member
;
118 struct bt_field_class_variant_option
;
119 struct bt_field_class_variant_with_selector_field_integer_unsigned_option
;
120 struct bt_field_class_variant_with_selector_field_integer_signed_option
;
122 struct bt_field_class_named_field_class_container
{
123 struct bt_field_class common
;
126 * Key: `const char *`, not owned by this (owned by named field
127 * class objects contained in `named_fcs` below).
129 GHashTable
*name_to_index
;
131 /* Array of `struct bt_named_field_class *` */
132 GPtrArray
*named_fcs
;
135 struct bt_field_class_structure
{
136 struct bt_field_class_named_field_class_container common
;
139 struct bt_field_class_array
{
140 struct bt_field_class common
;
143 struct bt_field_class
*element_fc
;
146 struct bt_field_class_array_static
{
147 struct bt_field_class_array common
;
151 struct bt_field_class_array_dynamic
{
152 struct bt_field_class_array common
;
155 struct bt_field_class
*length_fc
;
158 struct bt_field_path
*length_field_path
;
161 struct bt_field_class_option
{
162 struct bt_field_class common
;
165 struct bt_field_class
*content_fc
;
168 struct bt_field_class_option_with_selector_field
{
169 struct bt_field_class_option common
;
172 struct bt_field_class
*selector_fc
;
175 struct bt_field_path
*selector_field_path
;
178 struct bt_field_class_option_with_selector_field_bool
{
179 struct bt_field_class_option_with_selector_field common
;
182 bool sel_is_reversed
;
185 struct bt_field_class_option_with_selector_field_integer
{
186 struct bt_field_class_option_with_selector_field common
;
189 const struct bt_integer_range_set
*range_set
;
192 /* Variant FC (with selector) option: named field class + range set */
193 struct bt_field_class_variant_with_selector_field_option
{
194 struct bt_named_field_class common
;
197 const struct bt_integer_range_set
*range_set
;
200 struct bt_field_class_variant
{
202 * Depending on the variant field class type, the contained
203 * named field classes are of type
204 * `struct bt_named_field_class *` if the variant field class
205 * doesn't have a selector, or
206 * `struct bt_field_class_variant_with_selector_field_option *`
209 struct bt_field_class_named_field_class_container common
;
212 struct bt_field_class_variant_with_selector_field
{
213 struct bt_field_class_variant common
;
216 * Owned by this, but never dereferenced: only use to find it
219 const struct bt_field_class
*selector_fc
;
222 struct bt_field_path
*selector_field_path
;
225 void _bt_field_class_freeze(const struct bt_field_class
*field_class
);
228 # define bt_field_class_freeze _bt_field_class_freeze
230 # define bt_field_class_freeze(_fc) ((void) _fc)
233 void _bt_named_field_class_freeze(const struct bt_named_field_class
*named_fc
);
236 # define bt_named_field_class_freeze _bt_named_field_class_freeze
238 # define bt_named_field_class_freeze(_named_fc) ((void) _named_fc)
242 * This function recursively marks `field_class` and its children as
243 * being part of a trace. This is used to validate that all field classes
244 * are used at a single location within trace objects even if they are
245 * shared objects for other purposes.
247 void bt_field_class_make_part_of_trace_class(
248 const struct bt_field_class
*field_class
);
250 #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */