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 (&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 (&g_array_index((_mapping)->ranges, \
28 struct bt_field_class_enumeration_mapping_range, (_index)))
31 struct bt_field_class
;
33 struct bt_field_class
{
34 struct bt_object base
;
35 enum bt_field_class_type type
;
39 struct bt_value
*user_attributes
;
42 * This flag indicates whether or not this field class is part
45 bool part_of_trace_class
;
48 struct bt_field_class_bool
{
49 struct bt_field_class common
;
52 struct bt_field_class_bit_array
{
53 struct bt_field_class common
;
57 struct bt_field_class_integer
{
58 struct bt_field_class common
;
61 * Value range of fields built from this integer field class:
62 * this is an equivalent integer size in bits. More formally,
65 * Unsigned range: [0, 2^n - 1]
66 * Signed range: [-2^(n - 1), 2^(n - 1) - 1]
70 enum bt_field_class_integer_preferred_display_base base
;
73 struct bt_field_class_enumeration_mapping
{
77 const struct bt_integer_range_set
*range_set
;
80 struct bt_field_class_enumeration_unsigned_mapping
;
81 struct bt_field_class_enumeration_signed_mapping
;
83 struct bt_field_class_enumeration
{
84 struct bt_field_class_integer common
;
86 /* Array of `struct bt_field_class_enumeration_mapping *` */
90 * This is an array of `const char *` which acts as a temporary
91 * (potentially growing) buffer for
92 * bt_field_class_enumeration_unsigned_get_mapping_labels_for_value()
94 * bt_field_class_enumeration_signed_get_mapping_labels_for_value().
96 * The actual strings are owned by the mappings above.
101 struct bt_field_class_real
{
102 struct bt_field_class common
;
105 struct bt_field_class_string
{
106 struct bt_field_class common
;
109 /* A named field class is a (name, field class) pair */
110 struct bt_named_field_class
{
114 struct bt_value
*user_attributes
;
117 struct bt_field_class
*fc
;
122 struct bt_field_class_structure_member
;
123 struct bt_field_class_variant_option
;
124 struct bt_field_class_variant_with_selector_field_integer_unsigned_option
;
125 struct bt_field_class_variant_with_selector_field_integer_signed_option
;
127 struct bt_field_class_named_field_class_container
{
128 struct bt_field_class common
;
131 * Key: `const char *`, not owned by this (owned by named field
132 * class objects contained in `named_fcs` below).
134 GHashTable
*name_to_index
;
136 /* Array of `struct bt_named_field_class *` */
137 GPtrArray
*named_fcs
;
140 struct bt_field_class_structure
{
141 struct bt_field_class_named_field_class_container common
;
144 struct bt_field_class_array
{
145 struct bt_field_class common
;
148 struct bt_field_class
*element_fc
;
151 struct bt_field_class_array_static
{
152 struct bt_field_class_array common
;
156 struct bt_field_class_array_dynamic
{
157 struct bt_field_class_array common
;
160 struct bt_field_class
*length_fc
;
163 struct bt_field_path
*length_field_path
;
166 struct bt_field_class_option
{
167 struct bt_field_class common
;
170 struct bt_field_class
*content_fc
;
173 struct bt_field_class_option_with_selector_field
{
174 struct bt_field_class_option common
;
177 struct bt_field_class
*selector_fc
;
180 struct bt_field_path
*selector_field_path
;
183 struct bt_field_class_option_with_selector_field_bool
{
184 struct bt_field_class_option_with_selector_field common
;
187 bool sel_is_reversed
;
190 struct bt_field_class_option_with_selector_field_integer
{
191 struct bt_field_class_option_with_selector_field common
;
194 const struct bt_integer_range_set
*range_set
;
197 /* Variant FC (with selector) option: named field class + range set */
198 struct bt_field_class_variant_with_selector_field_option
{
199 struct bt_named_field_class common
;
202 const struct bt_integer_range_set
*range_set
;
205 struct bt_field_class_variant
{
207 * Depending on the variant field class type, the contained
208 * named field classes are of type
209 * `struct bt_named_field_class *` if the variant field class
210 * doesn't have a selector, or
211 * `struct bt_field_class_variant_with_selector_field_option *`
214 struct bt_field_class_named_field_class_container common
;
217 struct bt_field_class_variant_with_selector_field
{
218 struct bt_field_class_variant common
;
221 * Owned by this, but never dereferenced: only use to find it
224 const struct bt_field_class
*selector_fc
;
227 struct bt_field_path
*selector_field_path
;
230 void _bt_field_class_freeze(const struct bt_field_class
*field_class
);
233 # define bt_field_class_freeze _bt_field_class_freeze
235 # define bt_field_class_freeze(_fc) ((void) _fc)
238 void _bt_named_field_class_freeze(const struct bt_named_field_class
*named_fc
);
241 # define bt_named_field_class_freeze _bt_named_field_class_freeze
243 # define bt_named_field_class_freeze(_named_fc) ((void) _named_fc)
247 * This function recursively marks `field_class` and its children as
248 * being part of a trace. This is used to validate that all field classes
249 * are used at a single location within trace objects even if they are
250 * shared objects for other purposes.
252 void bt_field_class_make_part_of_trace_class(
253 const struct bt_field_class
*field_class
);
255 #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */