X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Ftrace-ir%2Ffield-class.c;h=c1f1805883dca4628985b5062b2c3fc8e42ac960;hb=3fadfbc0c91f82c46bd36e6e0657ea93570c9db1;hp=02a59d94301105f079917f0930f77f036b4a946e;hpb=1998d1abe7d22a9109f505526078c1073c2da342;p=babeltrace.git diff --git a/lib/trace-ir/field-class.c b/lib/trace-ir/field-class.c index 02a59d94..c1f18058 100644 --- a/lib/trace-ir/field-class.c +++ b/lib/trace-ir/field-class.c @@ -22,24 +22,24 @@ */ #define BT_LOG_TAG "FIELD-CLASSES" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -291,64 +291,44 @@ uint64_t bt_field_class_enumeration_get_mapping_count( return (uint64_t) enum_fc->mappings->len; } -void bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const( - const struct bt_field_class *fc, uint64_t index, - const char **name, - const struct bt_field_class_unsigned_enumeration_mapping_ranges **ranges) +const struct bt_field_class_unsigned_enumeration_mapping * +bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const( + const struct bt_field_class *fc, uint64_t index) { const struct bt_field_class_enumeration *enum_fc = (const void *) fc; - const struct bt_field_class_enumeration_mapping *mapping; BT_ASSERT_PRE_NON_NULL(fc, "Field class"); - BT_ASSERT_PRE_NON_NULL(name, "Name (output)"); - BT_ASSERT_PRE_NON_NULL(ranges, "Ranges (output)"); BT_ASSERT_PRE_VALID_INDEX(index, enum_fc->mappings->len); BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, "Field class"); - mapping = BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index); - *name = mapping->label->str; - *ranges = (void *) mapping; + return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index); } -void bt_field_class_signed_enumeration_borrow_mapping_by_index_const( - const struct bt_field_class *fc, uint64_t index, - const char **name, - const struct bt_field_class_signed_enumeration_mapping_ranges **ranges) +const struct bt_field_class_signed_enumeration_mapping * +bt_field_class_signed_enumeration_borrow_mapping_by_index_const( + const struct bt_field_class *fc, uint64_t index) { const struct bt_field_class_enumeration *enum_fc = (const void *) fc; - const struct bt_field_class_enumeration_mapping *mapping; BT_ASSERT_PRE_NON_NULL(fc, "Field class"); - BT_ASSERT_PRE_NON_NULL(name, "Name (output)"); - BT_ASSERT_PRE_NON_NULL(ranges, "Ranges (output)"); BT_ASSERT_PRE_VALID_INDEX(index, enum_fc->mappings->len); BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, "Field class"); - mapping = BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index); - *name = mapping->label->str; - *ranges = (void *) mapping; + return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index); } -static inline -uint64_t get_enumeration_field_class_mapping_range_count( +const char *bt_field_class_enumeration_mapping_get_label( const struct bt_field_class_enumeration_mapping *mapping) { - BT_ASSERT_PRE_NON_NULL(mapping, "Ranges"); - return (uint64_t) mapping->ranges->len; + BT_ASSERT_PRE_NON_NULL(mapping, "Enumeration field class mapping"); + return mapping->label->str; } -uint64_t bt_field_class_unsigned_enumeration_mapping_ranges_get_range_count( - const struct bt_field_class_unsigned_enumeration_mapping_ranges *ranges) -{ - return get_enumeration_field_class_mapping_range_count( - (const void *) ranges); -} - -uint64_t bt_field_class_signed_enumeration_mapping_ranges_get_range_count( - const struct bt_field_class_signed_enumeration_mapping_ranges *ranges) +uint64_t bt_field_class_enumeration_mapping_get_range_count( + const struct bt_field_class_enumeration_mapping *mapping) { - return get_enumeration_field_class_mapping_range_count( - (const void *) ranges); + BT_ASSERT_PRE_NON_NULL(mapping, "Enumeration field class mapping"); + return (uint64_t) mapping->ranges->len; } static inline @@ -367,16 +347,16 @@ void get_enumeration_field_class_mapping_range_at_index( *upper = range->upper.u; } -void bt_field_class_unsigned_enumeration_mapping_ranges_get_range_by_index( - const struct bt_field_class_unsigned_enumeration_mapping_ranges *ranges, +void bt_field_class_unsigned_enumeration_mapping_get_range_by_index( + const struct bt_field_class_unsigned_enumeration_mapping *ranges, uint64_t index, uint64_t *lower, uint64_t *upper) { get_enumeration_field_class_mapping_range_at_index( (const void *) ranges, index, lower, upper); } -void bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index( - const struct bt_field_class_signed_enumeration_mapping_ranges *ranges, +void bt_field_class_signed_enumeration_mapping_get_range_by_index( + const struct bt_field_class_signed_enumeration_mapping *ranges, uint64_t index, int64_t *lower, int64_t *upper) { get_enumeration_field_class_mapping_range_at_index( @@ -384,8 +364,6 @@ void bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index( (uint64_t *) lower, (uint64_t *) upper); } - - enum bt_field_class_status bt_field_class_unsigned_enumeration_get_mapping_labels_by_value( const struct bt_field_class *fc, uint64_t value, @@ -775,6 +753,12 @@ enum bt_field_class_status append_named_field_class_to_container_field_class( bt_object_get_no_null_check(fc); g_hash_table_insert(container_fc->name_to_index, named_fc->name->str, GUINT_TO_POINTER(container_fc->named_fcs->len - 1)); + + /* + * Freeze the field class, but not the named field class (the + * user can still modify it, if possible, until the container + * itself is frozen). + */ bt_field_class_freeze(fc); end: @@ -787,7 +771,8 @@ enum bt_field_class_status bt_field_class_structure_append_member( { BT_ASSERT_PRE_NON_NULL(fc, "Field class"); - BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, "Field class"); + BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, + "Field class"); return append_named_field_class_to_container_field_class((void *) fc, name, member_fc); } @@ -798,45 +783,53 @@ uint64_t bt_field_class_structure_get_member_count( struct bt_field_class_structure *struct_fc = (void *) fc; BT_ASSERT_PRE_NON_NULL(fc, "Field class"); - BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, "Field class"); + BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, + "Field class"); return (uint64_t) struct_fc->common.named_fcs->len; } static -void borrow_named_field_class_from_container_field_class_at_index_const( - const struct bt_field_class_named_field_class_container *fc, - uint64_t index, const char **name, - const struct bt_field_class **out_fc) +struct bt_named_field_class * +borrow_named_field_class_from_container_field_class_at_index( + struct bt_field_class_named_field_class_container *fc, + uint64_t index) { - const struct bt_named_field_class *named_fc; - BT_ASSERT(fc); - BT_ASSERT_PRE_NON_NULL(name, "Name"); - BT_ASSERT_PRE_NON_NULL(out_fc, "Field class (output)"); BT_ASSERT_PRE_VALID_INDEX(index, fc->named_fcs->len); - named_fc = BT_FIELD_CLASS_NAMED_FC_AT_INDEX(fc, index); - *name = named_fc->name->str; - *out_fc = named_fc->fc; + return BT_FIELD_CLASS_NAMED_FC_AT_INDEX(fc, index); +} + +const struct bt_field_class_structure_member * +bt_field_class_structure_borrow_member_by_index_const( + const struct bt_field_class *fc, uint64_t index) +{ + BT_ASSERT_PRE_NON_NULL(fc, "Field class"); + BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, + "Field class"); + return (const void *) + borrow_named_field_class_from_container_field_class_at_index( + (void *) fc, index); } -void bt_field_class_structure_borrow_member_by_index_const( - const struct bt_field_class *fc, uint64_t index, - const char **name, const struct bt_field_class **out_fc) +struct bt_field_class_structure_member * +bt_field_class_structure_borrow_member_by_index( + struct bt_field_class *fc, uint64_t index) { BT_ASSERT_PRE_NON_NULL(fc, "Field class"); - BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, "Field class"); - borrow_named_field_class_from_container_field_class_at_index_const( - (void *) fc, index, name, out_fc); + BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, + "Field class"); + return (void *) + borrow_named_field_class_from_container_field_class_at_index( + (void *) fc, index); } static -const struct bt_field_class * -borrow_field_class_from_container_field_class_by_name_const( - const struct bt_field_class_named_field_class_container *fc, +struct bt_named_field_class * +borrow_named_field_class_from_container_field_class_by_name( + struct bt_field_class_named_field_class_container *fc, const char *name) { - const struct bt_field_class *ret_fc = NULL; - const struct bt_named_field_class *named_fc; + struct bt_named_field_class *named_fc = NULL; gpointer orig_key; gpointer value; @@ -849,22 +842,64 @@ borrow_field_class_from_container_field_class_by_name_const( named_fc = BT_FIELD_CLASS_NAMED_FC_AT_INDEX(fc, GPOINTER_TO_UINT(value)); - ret_fc = named_fc->fc; end: - return ret_fc; + return named_fc; } -const struct bt_field_class * -bt_field_class_structure_borrow_member_field_class_by_name_const( +const struct bt_field_class_structure_member * +bt_field_class_structure_borrow_member_by_name_const( const struct bt_field_class *fc, const char *name) { BT_ASSERT_PRE_NON_NULL(fc, "Field class"); - BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, "Field class"); - return borrow_field_class_from_container_field_class_by_name_const( + BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, + "Field class"); + return (const void *) + borrow_named_field_class_from_container_field_class_by_name( + (void *) fc, name); +} + +struct bt_field_class_structure_member * +bt_field_class_structure_borrow_member_by_name( + struct bt_field_class *fc, const char *name) +{ + BT_ASSERT_PRE_NON_NULL(fc, "Field class"); + BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, + "Field class"); + return (void *) + borrow_named_field_class_from_container_field_class_by_name( (void *) fc, name); } +const char *bt_field_class_structure_member_get_name( + const struct bt_field_class_structure_member *member) +{ + const struct bt_named_field_class *named_fc = (const void *) member; + + BT_ASSERT_PRE_NON_NULL(member, "Structure field class member"); + return named_fc->name->str; +} + +const struct bt_field_class * +bt_field_class_structure_member_borrow_field_class_const( + const struct bt_field_class_structure_member *member) +{ + const struct bt_named_field_class *named_fc = (const void *) member; + + BT_ASSERT_PRE_NON_NULL(member, "Structure field class member"); + return named_fc->fc; +} + +struct bt_field_class * +bt_field_class_structure_member_borrow_field_class( + struct bt_field_class_structure_member *member) +{ + struct bt_named_field_class *named_fc = (void *) member; + + BT_ASSERT_PRE_NON_NULL(member, "Structure field class member"); + return named_fc->fc; +} + static void destroy_variant_field_class(struct bt_object *obj) { @@ -938,14 +973,26 @@ enum bt_field_class_status bt_field_class_variant_append_option( name, option_fc); } -const struct bt_field_class * -bt_field_class_variant_borrow_option_field_class_by_name_const( +const struct bt_field_class_variant_option * +bt_field_class_variant_borrow_option_by_name_const( const struct bt_field_class *fc, const char *name) { BT_ASSERT_PRE_NON_NULL(fc, "Field class"); BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class"); - return borrow_field_class_from_container_field_class_by_name_const( - (void *) fc, name); + return (const void *) + borrow_named_field_class_from_container_field_class_by_name( + (void *) fc, name); +} + +struct bt_field_class_variant_option * +bt_field_class_variant_borrow_option_by_name( + struct bt_field_class *fc, const char *name) +{ + BT_ASSERT_PRE_NON_NULL(fc, "Field class"); + BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class"); + return (void *) + borrow_named_field_class_from_container_field_class_by_name( + (void *) fc, name); } uint64_t bt_field_class_variant_get_option_count(const struct bt_field_class *fc) @@ -957,14 +1004,55 @@ uint64_t bt_field_class_variant_get_option_count(const struct bt_field_class *fc return (uint64_t) var_fc->common.named_fcs->len; } -void bt_field_class_variant_borrow_option_by_index_const( - const struct bt_field_class *fc, uint64_t index, - const char **name, const struct bt_field_class **out_fc) +const struct bt_field_class_variant_option * +bt_field_class_variant_borrow_option_by_index_const( + const struct bt_field_class *fc, uint64_t index) { BT_ASSERT_PRE_NON_NULL(fc, "Field class"); BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class"); - borrow_named_field_class_from_container_field_class_at_index_const( - (void *) fc, index, name, out_fc); + return (const void *) + borrow_named_field_class_from_container_field_class_at_index( + (void *) fc, index); +} + +struct bt_field_class_variant_option * +bt_field_class_variant_borrow_option_by_index( + struct bt_field_class *fc, uint64_t index) +{ + BT_ASSERT_PRE_NON_NULL(fc, "Field class"); + BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class"); + return (void *) + borrow_named_field_class_from_container_field_class_at_index( + (void *) fc, index); +} + +const char *bt_field_class_variant_option_get_name( + const struct bt_field_class_variant_option *option) +{ + const struct bt_named_field_class *named_fc = (const void *) option; + + BT_ASSERT_PRE_NON_NULL(option, "Variant field class option"); + return named_fc->name->str; +} + +const struct bt_field_class * +bt_field_class_variant_option_borrow_field_class_const( + const struct bt_field_class_variant_option *option) +{ + const struct bt_named_field_class *named_fc = (const void *) option; + + BT_ASSERT_PRE_NON_NULL(option, "Variant field class option"); + return named_fc->fc; +} + +struct bt_field_class * +bt_field_class_variant_option_borrow_field_class( + struct bt_field_class_variant_option *option) +{ + struct bt_named_field_class *named_fc = (void *) option; + + BT_ASSERT_PRE_NON_NULL(option, "Variant field class option"); + return named_fc->fc; } const struct bt_field_path * @@ -1047,6 +1135,16 @@ bt_field_class_array_borrow_element_field_class_const( return array_fc->element_fc; } +struct bt_field_class * +bt_field_class_array_borrow_element_field_class(struct bt_field_class *fc) +{ + struct bt_field_class_array *array_fc = (void *) fc; + + BT_ASSERT_PRE_NON_NULL(fc, "Field class"); + BT_ASSERT_PRE_FC_IS_ARRAY(fc, "Field class"); + return array_fc->element_fc; +} + uint64_t bt_field_class_static_array_get_length(const struct bt_field_class *fc) { const struct bt_field_class_static_array *array_fc = (const void *) fc; @@ -1163,14 +1261,46 @@ end: } BT_HIDDEN -void _bt_field_class_freeze(const struct bt_field_class *fc) +void _bt_field_class_freeze(const struct bt_field_class *c_fc) { + struct bt_field_class *fc = (void *) c_fc; + /* * Element/member/option field classes are frozen when added to * their owner. */ BT_ASSERT(fc); - ((struct bt_field_class *) fc)->frozen = true; + fc->frozen = true; + + switch (fc->type) { + case BT_FIELD_CLASS_TYPE_STRUCTURE: + case BT_FIELD_CLASS_TYPE_VARIANT: + { + struct bt_field_class_named_field_class_container *container_fc = + (void *) fc; + uint64_t i; + + for (i = 0; i < container_fc->named_fcs->len; i++) { + struct bt_named_field_class *named_fc = + BT_FIELD_CLASS_NAMED_FC_AT_INDEX( + container_fc, i); + + bt_named_field_class_freeze(named_fc); + } + + break; + } + default: + break; + } +} + +BT_HIDDEN +void _bt_named_field_class_freeze(const struct bt_named_field_class *named_fc) +{ + BT_ASSERT(named_fc); + ((struct bt_named_field_class *) named_fc)->frozen = true; + bt_field_class_freeze(named_fc->fc); } BT_HIDDEN