X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Flib%2Ftrace-ir%2Ffield-class.h;h=e95a4eb2023c6efe6f355555cb2577b75fa55a2e;hb=c4f23e30bf67d2523163614bc9461d84cbe1ae80;hp=6947c937513eadb37a217896eac22b6d54fb1999;hpb=91d8147391efdc4d42cc4e1c171a65c0372a008f;p=babeltrace.git diff --git a/src/lib/trace-ir/field-class.h b/src/lib/trace-ir/field-class.h index 6947c937..e95a4eb2 100644 --- a/src/lib/trace-ir/field-class.h +++ b/src/lib/trace-ir/field-class.h @@ -28,49 +28,190 @@ #include #include #include "common/macros.h" +#include "common/common.h" #include "lib/object.h" #include +#include #include #include +#define _BT_ASSERT_PRE_FC_IS_INT_COND(_fc) \ + (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \ + ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \ + ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \ + ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION) + +#define _BT_ASSERT_PRE_FC_IS_INT_FMT(_name) \ + _name " is not an integer field class: %![fc-]+F" + +#define _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc) \ + (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \ + ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION) + +#define _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name) \ + _name " is not an unsigned integer field class: %![fc-]+F" + + +#define _BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc) \ + (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \ + ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION) + +#define _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name) \ + _name " is not a signed integer field class: %![fc-]+F" + +#define _BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc) \ + (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \ + ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION) + +#define _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name) \ + _name " is not an enumeration field class: %![fc-]+F" + +#define _BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc) \ + (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \ + ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD || \ + ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD) + +#define _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name) \ + _name " is not an array field class: %![fc-]+F" + +#define _BT_ASSERT_PRE_FC_IS_OPTION_COND(_fc) \ + (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD || \ + ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD || \ + ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \ + ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD) + +#define _BT_ASSERT_PRE_FC_IS_OPTION_FMT(_name) \ + _name " is not an option field class: %![fc-]+F" + +#define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_COND(_fc) \ + (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD || \ + ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \ + ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD) + +#define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_FMT(_name) \ + _name " is not an option field class with a selector: %![fc-]+F" + +#define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_COND(_fc) \ + (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \ + ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD) + +#define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_FMT(_name) \ + _name " is not an option field class with an integer selector: %![fc-]+F" + +#define _BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc) \ + (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD || \ + ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \ + ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD) + +#define _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name) \ + _name " is not a variant field class: %![fc-]+F" + +#define _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc) \ + (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \ + ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD) + +#define _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name) \ + _name " is not a variant field class with a selector: %![fc-]+F" + +#define _BT_ASSERT_PRE_FC_HAS_ID_COND(_fc, _type) \ + (((const struct bt_field_class *) (_fc))->type == (_type)) + +#define _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name) \ + _name " has the wrong type: expected-type=%s, %![fc-]+F" + #define BT_ASSERT_PRE_FC_IS_INT(_fc, _name) \ - BT_ASSERT_PRE( \ - ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \ - ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \ - ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \ - ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, \ - _name " is not an integer field class: %![fc-]+F", (_fc)) + BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_INT_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_INT_FMT(_name), (_fc)) #define BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(_fc, _name) \ - BT_ASSERT_PRE( \ - ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \ - ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, \ - _name " is not an unsigned integer field class: %![fc-]+F", (_fc)) + BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name), (_fc)) + +#define BT_ASSERT_PRE_FC_IS_SIGNED_INT(_fc, _name) \ + BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name), (_fc)) #define BT_ASSERT_PRE_FC_IS_ENUM(_fc, _name) \ - BT_ASSERT_PRE( \ - ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \ - ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, \ - _name " is not an enumeration field class: %![fc-]+F", (_fc)) + BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name), (_fc)) #define BT_ASSERT_PRE_FC_IS_ARRAY(_fc, _name) \ - BT_ASSERT_PRE( \ - ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \ - ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY, \ - _name " is not an array field class: %![fc-]+F", (_fc)) + BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name), (_fc)) + +#define BT_ASSERT_PRE_FC_IS_OPTION(_fc, _name) \ + BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_OPTION_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_OPTION_FMT(_name), (_fc)) + +#define BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL(_fc, _name) \ + BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_FMT(_name), (_fc)) + +#define BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL(_fc, _name) \ + BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_FMT(_name), (_fc)) + +#define BT_ASSERT_PRE_FC_IS_VARIANT(_fc, _name) \ + BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name), (_fc)) + +#define BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL(_fc, _name) \ + BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name), (_fc)) #define BT_ASSERT_PRE_FC_HAS_ID(_fc, _type, _name) \ - BT_ASSERT_PRE(((const struct bt_field_class *) (_fc))->type == (_type), \ - _name " has the wrong type: expected-type=%s, " \ - "%![fc-]+F", bt_common_field_class_type_string(_type), (_fc)) + BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_HAS_ID_COND((_fc), (_type)), \ + _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name), \ + bt_common_field_class_type_string(_type), (_fc)) -#define BT_ASSERT_PRE_FC_HOT(_fc, _name) \ - BT_ASSERT_PRE_HOT((const struct bt_field_class *) (_fc), \ - (_name), ": %!+F", (_fc)) +#define BT_ASSERT_PRE_DEV_FC_IS_INT(_fc, _name) \ + BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_INT_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_INT_FMT(_name), (_fc)) + +#define BT_ASSERT_PRE_DEV_FC_IS_UNSIGNED_INT(_fc, _name) \ + BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name), (_fc)) + +#define BT_ASSERT_PRE_DEV_FC_IS_SIGNED_INT(_fc, _name) \ + BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name), (_fc)) + +#define BT_ASSERT_PRE_DEV_FC_IS_ENUM(_fc, _name) \ + BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name), (_fc)) + +#define BT_ASSERT_PRE_DEV_FC_IS_ARRAY(_fc, _name) \ + BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name), (_fc)) + +#define BT_ASSERT_PRE_DEV_FC_IS_OPTION(_fc, _name) \ + BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_OPTION_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_OPTION_FMT(_name), (_fc)) + +#define BT_ASSERT_PRE_DEV_FC_IS_OPTION_WITH_SEL(_fc, _name) \ + BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_FMT(_name), (_fc)) -#define BT_FIELD_CLASS_NAMED_FC_AT_INDEX(_fc, _index) \ - (&g_array_index(((struct bt_field_class_named_field_class_container *) (_fc))->named_fcs, \ - struct bt_named_field_class, (_index))) +#define BT_ASSERT_PRE_DEV_FC_IS_OPTION_WITH_INT_SEL(_fc, _name) \ + BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_FMT(_name), (_fc)) + +#define BT_ASSERT_PRE_DEV_FC_IS_VARIANT(_fc, _name) \ + BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name), (_fc)) + +#define BT_ASSERT_PRE_DEV_FC_IS_VARIANT_WITH_SEL(_fc, _name) \ + BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name), (_fc)) + +#define BT_ASSERT_PRE_DEV_FC_HAS_ID(_fc, _type, _name) \ + BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_HAS_ID_COND((_fc), (_type)), \ + _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name), \ + bt_common_field_class_type_string(_type), (_fc)) + +#define BT_ASSERT_PRE_DEV_FC_HOT(_fc, _name) \ + BT_ASSERT_PRE_DEV_HOT((const struct bt_field_class *) (_fc), \ + (_name), ": %!+F", (_fc)) #define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \ (&g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \ @@ -88,13 +229,25 @@ struct bt_field_class { enum bt_field_class_type type; bool frozen; + /* Owned by this */ + struct bt_value *user_attributes; + /* - * Only used in developer mode, this flag indicates whether or - * not this field class is part of a trace class. + * This flag indicates whether or not this field class is part + * of a trace class. */ bool part_of_trace_class; }; +struct bt_field_class_bool { + struct bt_field_class common; +}; + +struct bt_field_class_bit_array { + struct bt_field_class common; + uint64_t length; +}; + struct bt_field_class_integer { struct bt_field_class common; @@ -111,27 +264,15 @@ struct bt_field_class_integer { enum bt_field_class_integer_preferred_display_base base; }; -struct bt_field_class_enumeration_mapping_range { - union { - uint64_t u; - int64_t i; - } lower; - - union { - uint64_t u; - int64_t i; - } upper; -}; - struct bt_field_class_enumeration_mapping { GString *label; - /* Array of `struct bt_field_class_enumeration_mapping_range` */ - GArray *ranges; + /* Owner by this */ + const struct bt_integer_range_set *range_set; }; -struct bt_field_class_unsigned_enumeration_mapping; -struct bt_field_class_signed_enumeration_mapping; +struct bt_field_class_enumeration_unsigned_mapping; +struct bt_field_class_enumeration_signed_mapping; struct bt_field_class_enumeration { struct bt_field_class_integer common; @@ -142,9 +283,9 @@ struct bt_field_class_enumeration { /* * This is an array of `const char *` which acts as a temporary * (potentially growing) buffer for - * bt_field_class_unsigned_enumeration_get_mapping_labels_by_value() + * bt_field_class_enumeration_unsigned_get_mapping_labels_for_value() * and - * bt_field_class_signed_enumeration_get_mapping_labels_by_value(). + * bt_field_class_enumeration_signed_get_mapping_labels_for_value(). * * The actual strings are owned by the mappings above. */ @@ -153,7 +294,6 @@ struct bt_field_class_enumeration { struct bt_field_class_real { struct bt_field_class common; - bool is_single_precision; }; struct bt_field_class_string { @@ -164,6 +304,9 @@ struct bt_field_class_string { struct bt_named_field_class { GString *name; + /* Owned by this */ + struct bt_value *user_attributes; + /* Owned by this */ struct bt_field_class *fc; @@ -172,22 +315,20 @@ struct bt_named_field_class { struct bt_field_class_structure_member; struct bt_field_class_variant_option; +struct bt_field_class_variant_with_selector_field_integer_unsigned_option; +struct bt_field_class_variant_with_selector_field_integer_signed_option; -/* - * This is the base field class for a container of named field classes. - * Structure and variant field classes inherit this. - */ struct bt_field_class_named_field_class_container { struct bt_field_class common; /* * Key: `const char *`, not owned by this (owned by named field - * type objects contained in `named_fcs` below). + * class objects contained in `named_fcs` below). */ GHashTable *name_to_index; - /* Array of `struct bt_named_field_class` */ - GArray *named_fcs; + /* Array of `struct bt_named_field_class *` */ + GPtrArray *named_fcs; }; struct bt_field_class_structure { @@ -201,37 +342,84 @@ struct bt_field_class_array { struct bt_field_class *element_fc; }; -struct bt_field_class_static_array { +struct bt_field_class_array_static { struct bt_field_class_array common; uint64_t length; }; -struct bt_field_class_dynamic_array { +struct bt_field_class_array_dynamic { struct bt_field_class_array common; - /* Weak: never dereferenced, only use to find it elsewhere */ + /* Owned by this */ struct bt_field_class *length_fc; /* Owned by this */ struct bt_field_path *length_field_path; }; -struct bt_field_class_variant { - struct bt_field_class_named_field_class_container common; +struct bt_field_class_option { + struct bt_field_class common; + + /* Owned by this */ + struct bt_field_class *content_fc; +}; + +struct bt_field_class_option_with_selector_field { + struct bt_field_class_option common; - /* Weak: never dereferenced, only use to find it elsewhere */ + /* Owned by this */ struct bt_field_class *selector_fc; /* Owned by this */ struct bt_field_path *selector_field_path; }; -static inline -bool bt_field_class_has_known_type(const struct bt_field_class *fc) -{ - return fc->type >= BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER && - fc->type <= BT_FIELD_CLASS_TYPE_VARIANT; -} +struct bt_field_class_option_with_selector_field_bool { + struct bt_field_class_option_with_selector_field common; + + /* Owned by this */ + bool sel_is_reversed; +}; + +struct bt_field_class_option_with_selector_field_integer { + struct bt_field_class_option_with_selector_field common; + + /* Owned by this */ + const struct bt_integer_range_set *range_set; +}; + +/* Variant FC (with selector) option: named field class + range set */ +struct bt_field_class_variant_with_selector_field_option { + struct bt_named_field_class common; + + /* Owned by this */ + const struct bt_integer_range_set *range_set; +}; + +struct bt_field_class_variant { + /* + * Depending on the variant field class type, the contained + * named field classes are of type + * `struct bt_named_field_class *` if the variant field class + * doesn't have a selector, or + * `struct bt_field_class_variant_with_selector_field_option *` + * if it has. + */ + struct bt_field_class_named_field_class_container common; +}; + +struct bt_field_class_variant_with_selector_field { + struct bt_field_class_variant common; + + /* + * Owned by this, but never dereferenced: only use to find it + * elsewhere. + */ + const struct bt_field_class *selector_fc; + + /* Owned by this */ + struct bt_field_path *selector_field_path; +}; BT_HIDDEN void _bt_field_class_freeze(const struct bt_field_class *field_class); @@ -258,13 +446,7 @@ void _bt_named_field_class_freeze(const struct bt_named_field_class *named_fc); * shared objects for other purposes. */ BT_HIDDEN -void _bt_field_class_make_part_of_trace_class( +void bt_field_class_make_part_of_trace_class( const struct bt_field_class *field_class); -#ifdef BT_DEV_MODE -# define bt_field_class_make_part_of_trace_class _bt_field_class_make_part_of_trace_class -#else -# define bt_field_class_make_part_of_trace_class(_fc) ((void) _fc) -#endif - #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */