X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=include%2Fbabeltrace%2Fctf-ir%2Ffield-types-internal.h;h=fcefa0637c9ce019f9a88efe6c31756c410c13a2;hp=a4f4c833f2265617937930d228bd9e90e508d74d;hb=44c440bc5fe8219cc17d1b786d91fd83c4c9860a;hpb=2f4b93cd29ab927436c42544ef6fccfb33429c0f diff --git a/include/babeltrace/ctf-ir/field-types-internal.h b/include/babeltrace/ctf-ir/field-types-internal.h index a4f4c833..fcefa063 100644 --- a/include/babeltrace/ctf-ir/field-types-internal.h +++ b/include/babeltrace/ctf-ir/field-types-internal.h @@ -27,308 +27,229 @@ * SOFTWARE. */ -#include -#include -#include -#include -#include +#include #include #include #include #include #include +#include #include -typedef void (*type_freeze_func)(struct bt_ctf_field_type *); -typedef int (*type_serialize_func)(struct bt_ctf_field_type *, - struct metadata_context *); - -struct bt_ctf_field_type { +#define BT_ASSERT_PRE_FT_IS_INT(_ft, _name) \ + BT_ASSERT_PRE( \ + ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_UNSIGNED_INTEGER || \ + ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_SIGNED_INTEGER || \ + ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_UNSIGNED_ENUMERATION || \ + ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_SIGNED_ENUMERATION, \ + _name " is not an integer field type: %![ft-]+F", (_ft)) + +#define BT_ASSERT_PRE_FT_IS_UNSIGNED_INT(_ft, _name) \ + BT_ASSERT_PRE( \ + ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_UNSIGNED_INTEGER || \ + ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_UNSIGNED_ENUMERATION, \ + _name " is not an unsigned integer field type: %![ft-]+F", (_ft)) + +#define BT_ASSERT_PRE_FT_IS_ENUM(_ft, _name) \ + BT_ASSERT_PRE( \ + ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_UNSIGNED_ENUMERATION || \ + ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_SIGNED_ENUMERATION, \ + _name " is not an enumeration field type: %![ft-]+F", (_ft)) + +#define BT_ASSERT_PRE_FT_IS_ARRAY(_ft, _name) \ + BT_ASSERT_PRE( \ + ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_STATIC_ARRAY || \ + ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_DYNAMIC_ARRAY, \ + _name " is not an array field type: %![ft-]+F", (_ft)) + +#define BT_ASSERT_PRE_FT_HAS_ID(_ft, _id, _name) \ + BT_ASSERT_PRE(((struct bt_field_type *) (_ft))->id == (_id), \ + _name " has the wrong ID: expected-id=%s, " \ + "%![ft-]+F", bt_common_field_type_id_string(_id), (_ft)) + +#define BT_ASSERT_PRE_FT_HOT(_ft, _name) \ + BT_ASSERT_PRE_HOT((struct bt_field_type *) (_ft), \ + (_name), ": %!+F", (_ft)) + +#define BT_FIELD_TYPE_NAMED_FT_AT_INDEX(_ft, _index) \ + (&g_array_index(((struct bt_field_type_named_field_types_container *) (_ft))->named_fts, \ + struct bt_named_field_type, (_index))) + +#define BT_FIELD_TYPE_ENUM_MAPPING_AT_INDEX(_ft, _index) \ + (&g_array_index(((struct bt_field_type_enumeration *) (_ft))->mappings, \ + struct bt_field_type_enumeration_mapping, (_index))) + +#define BT_FIELD_TYPE_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \ + (&g_array_index((_mapping)->ranges, \ + struct bt_field_type_enumeration_mapping_range, (_index))) + +struct bt_field; +struct bt_field_type; + +struct bt_field_type { struct bt_object base; - enum bt_ctf_field_type_id id; - unsigned int alignment; - type_freeze_func freeze; - type_serialize_func serialize; + enum bt_field_type_id id; + bool frozen; + /* - * A type can't be modified once it is added to an event or after a - * a field has been instanciated from it. + * Only used in developer mode, this flag indicates whether or + * not this field type is part of a trace. */ - int frozen; + bool part_of_trace; +}; + +struct bt_field_type_integer { + struct bt_field_type common; /* - * This flag indicates if the field type is valid. A valid - * field type is _always_ frozen. All the nested field types of - * a valid field type are also valid (and thus frozen). + * Value range of fields built from this integer field type: + * this is an equivalent integer size in bits. More formally, + * `range` is `n` in: + * + * Unsigned range: [0, 2^n - 1] + * Signed range: [-2^(n - 1), 2^(n - 1) - 1] */ - int valid; -}; + uint64_t range; -struct bt_ctf_field_type_integer { - struct bt_ctf_field_type parent; - struct bt_ctf_clock_class *mapped_clock; - enum bt_ctf_byte_order user_byte_order; - bt_bool is_signed; - unsigned int size; - enum bt_ctf_integer_base base; - enum bt_ctf_string_encoding encoding; + enum bt_field_type_integer_preferred_display_base base; }; -struct enumeration_mapping { +struct bt_field_type_enumeration_mapping_range { union { - uint64_t _unsigned; - int64_t _signed; - } range_start; + uint64_t u; + int64_t i; + } lower; union { - uint64_t _unsigned; - int64_t _signed; - } range_end; - GQuark string; -}; - -struct bt_ctf_field_type_enumeration { - struct bt_ctf_field_type parent; - struct bt_ctf_field_type *container; - GPtrArray *entries; /* Array of ptrs to struct enumeration_mapping */ - /* Only set during validation. */ - bt_bool has_overlapping_ranges; + uint64_t u; + int64_t i; + } upper; }; -enum bt_ctf_field_type_enumeration_mapping_iterator_type { - ITERATOR_BY_NAME, - ITERATOR_BY_SIGNED_VALUE, - ITERATOR_BY_UNSIGNED_VALUE, -}; +struct bt_field_type_enumeration_mapping { + GString *label; -struct bt_ctf_field_type_enumeration_mapping_iterator { - struct bt_object base; - struct bt_ctf_field_type_enumeration *enumeration_type; - enum bt_ctf_field_type_enumeration_mapping_iterator_type type; - int index; - union { - GQuark name_quark; - int64_t signed_value; - uint64_t unsigned_value; - } u; + /* Array of `struct bt_field_type_enumeration_mapping_range` */ + GArray *ranges; }; -struct bt_ctf_field_type_floating_point { - struct bt_ctf_field_type parent; - enum bt_ctf_byte_order user_byte_order; - unsigned int exp_dig; - unsigned int mant_dig; -}; +struct bt_field_type_enumeration { + struct bt_field_type_integer common; -struct structure_field { - GQuark name; - struct bt_ctf_field_type *type; -}; + /* Array of `struct bt_field_type_enumeration_mapping *` */ + GArray *mappings; -struct bt_ctf_field_type_structure { - struct bt_ctf_field_type parent; - GHashTable *field_name_to_index; - GPtrArray *fields; /* Array of pointers to struct structure_field */ + /* + * This is an array of `const char *` which acts as a temporary + * (potentially growing) buffer for + * bt_field_type_unsigned_enumeration_get_mapping_labels_by_value() + * and + * bt_field_type_signed_enumeration_get_mapping_labels_by_value(). + * + * The actual strings are owned by the mappings above. + */ + GPtrArray *label_buf; }; -struct bt_ctf_field_type_variant { - struct bt_ctf_field_type parent; - GString *tag_name; - struct bt_ctf_field_type_enumeration *tag; - struct bt_ctf_field_path *tag_field_path; - GHashTable *field_name_to_index; - GPtrArray *fields; /* Array of pointers to struct structure_field */ +struct bt_field_type_real { + struct bt_field_type common; + bool is_single_precision; }; -struct bt_ctf_field_type_array { - struct bt_ctf_field_type parent; - struct bt_ctf_field_type *element_type; - unsigned int length; /* Number of elements */ +struct bt_field_type_string { + struct bt_field_type common; }; -struct bt_ctf_field_type_sequence { - struct bt_ctf_field_type parent; - struct bt_ctf_field_type *element_type; - GString *length_field_name; - struct bt_ctf_field_path *length_field_path; -}; +/* A named field type is a (name, field type) pair */ +struct bt_named_field_type { + GString *name; -struct bt_ctf_field_type_string { - struct bt_ctf_field_type parent; - enum bt_ctf_string_encoding encoding; + /* Owned by this */ + struct bt_field_type *ft; }; -BT_HIDDEN -void bt_ctf_field_type_freeze(struct bt_ctf_field_type *type); - -BT_HIDDEN -struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_signed( - struct bt_ctf_field_type_variant *variant, int64_t tag_value); - -BT_HIDDEN -struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_unsigned( - struct bt_ctf_field_type_variant *variant, uint64_t tag_value); - -BT_HIDDEN -int bt_ctf_field_type_serialize(struct bt_ctf_field_type *type, - struct metadata_context *context); - -BT_HIDDEN -int bt_ctf_field_type_validate(struct bt_ctf_field_type *type); +/* + * This is the base field type for a container of named field types. + * Structure and variant field types inherit this. + */ +struct bt_field_type_named_field_types_container { + struct bt_field_type common; -BT_HIDDEN -int bt_ctf_field_type_structure_get_field_name_index( - struct bt_ctf_field_type *structure, const char *name); + /* + * Key: `const char *`, not owned by this (owned by named field + * type objects contained in `named_fts` below). + */ + GHashTable *name_to_index; -BT_HIDDEN -int bt_ctf_field_type_variant_get_field_name_index( - struct bt_ctf_field_type *variant, const char *name); + /* Array of `struct bt_named_field_type` */ + GArray *named_fts; +}; -BT_HIDDEN -int bt_ctf_field_type_sequence_set_length_field_path( - struct bt_ctf_field_type *type, - struct bt_ctf_field_path *path); +struct bt_field_type_structure { + struct bt_field_type_named_field_types_container common; +}; -BT_HIDDEN -int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type *type, - struct bt_ctf_field_path *path); +struct bt_field_type_array { + struct bt_field_type common; -BT_HIDDEN -int bt_ctf_field_type_variant_set_tag_field_type(struct bt_ctf_field_type *type, - struct bt_ctf_field_type *tag_type); + /* Owned by this */ + struct bt_field_type *element_ft; +}; -BT_HIDDEN -int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type *array, - struct bt_ctf_field_type *element_type); +struct bt_field_type_static_array { + struct bt_field_type_array common; + uint64_t length; +}; -BT_HIDDEN -int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type *array, - struct bt_ctf_field_type *element_type); +struct bt_field_type_dynamic_array { + struct bt_field_type_array common; -BT_HIDDEN -int64_t bt_ctf_field_type_get_field_count(struct bt_ctf_field_type *type); + /* Weak: never dereferenced, only use to find it elsewhere */ + struct bt_field_type *length_ft; -BT_HIDDEN -struct bt_ctf_field_type *bt_ctf_field_type_get_field_at_index( - struct bt_ctf_field_type *type, int index); + /* Owned by this */ + struct bt_field_path *length_field_path; +}; -BT_HIDDEN -int bt_ctf_field_type_get_field_index(struct bt_ctf_field_type *type, - const char *name); +struct bt_field_type_variant { + struct bt_field_type_named_field_types_container common; -BT_HIDDEN -int bt_ctf_field_type_integer_set_mapped_clock_class_no_check( - struct bt_ctf_field_type *int_field_type, - struct bt_ctf_clock_class *clock_class); + /* Weak: never dereferenced, only use to find it elsewhere */ + struct bt_field_type *selector_ft; -static inline -const char *bt_ctf_field_type_id_string(enum bt_ctf_field_type_id type_id) -{ - switch (type_id) { - case BT_CTF_FIELD_TYPE_ID_UNKNOWN: - return "BT_CTF_FIELD_TYPE_ID_UNKNOWN"; - case BT_CTF_FIELD_TYPE_ID_INTEGER: - return "BT_CTF_FIELD_TYPE_ID_INTEGER"; - case BT_CTF_FIELD_TYPE_ID_FLOAT: - return "BT_CTF_FIELD_TYPE_ID_FLOAT"; - case BT_CTF_FIELD_TYPE_ID_ENUM: - return "BT_CTF_FIELD_TYPE_ID_ENUM"; - case BT_CTF_FIELD_TYPE_ID_STRING: - return "BT_CTF_FIELD_TYPE_ID_STRING"; - case BT_CTF_FIELD_TYPE_ID_STRUCT: - return "BT_CTF_FIELD_TYPE_ID_STRUCT"; - case BT_CTF_FIELD_TYPE_ID_ARRAY: - return "BT_CTF_FIELD_TYPE_ID_ARRAY"; - case BT_CTF_FIELD_TYPE_ID_SEQUENCE: - return "BT_CTF_FIELD_TYPE_ID_SEQUENCE"; - case BT_CTF_FIELD_TYPE_ID_VARIANT: - return "BT_CTF_FIELD_TYPE_ID_VARIANT"; - default: - return "(unknown)"; - } + /* Owned by this */ + struct bt_field_path *selector_field_path; }; static inline -const char *bt_ctf_byte_order_string(enum bt_ctf_byte_order bo) +bool bt_field_type_has_known_id(struct bt_field_type *ft) { - switch (bo) { - case BT_CTF_BYTE_ORDER_UNKNOWN: - return "BT_CTF_BYTE_ORDER_UNKNOWN"; - case BT_CTF_BYTE_ORDER_UNSPECIFIED: - return "BT_CTF_BYTE_ORDER_UNSPECIFIED"; - case BT_CTF_BYTE_ORDER_NATIVE: - return "BT_CTF_BYTE_ORDER_NATIVE"; - case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN: - return "BT_CTF_BYTE_ORDER_LITTLE_ENDIAN"; - case BT_CTF_BYTE_ORDER_BIG_ENDIAN: - return "BT_CTF_BYTE_ORDER_BIG_ENDIAN"; - case BT_CTF_BYTE_ORDER_NETWORK: - return "BT_CTF_BYTE_ORDER_NETWORK"; - default: - return "(unknown)"; - } -}; + return ft->id >= BT_FIELD_TYPE_ID_UNSIGNED_INTEGER && + ft->id <= BT_FIELD_TYPE_ID_VARIANT; +} -static inline -const char *bt_ctf_string_encoding_string(enum bt_ctf_string_encoding encoding) -{ - switch (encoding) { - case BT_CTF_STRING_ENCODING_UNKNOWN: - return "BT_CTF_STRING_ENCODING_UNKNOWN"; - case BT_CTF_STRING_ENCODING_NONE: - return "BT_CTF_STRING_ENCODING_NONE"; - case BT_CTF_STRING_ENCODING_UTF8: - return "BT_CTF_STRING_ENCODING_UTF8"; - case BT_CTF_STRING_ENCODING_ASCII: - return "BT_CTF_STRING_ENCODING_ASCII"; - default: - return "(unknown)"; - } -}; +BT_HIDDEN +void _bt_field_type_freeze(struct bt_field_type *field_type); -static inline -const char *bt_ctf_integer_base_string(enum bt_ctf_integer_base base) -{ - switch (base) { - case BT_CTF_INTEGER_BASE_UNKNOWN: - return "BT_CTF_INTEGER_BASE_UNKNOWN"; - case BT_CTF_INTEGER_BASE_UNSPECIFIED: - return "BT_CTF_INTEGER_BASE_UNSPECIFIED"; - case BT_CTF_INTEGER_BASE_BINARY: - return "BT_CTF_INTEGER_BASE_BINARY"; - case BT_CTF_INTEGER_BASE_OCTAL: - return "BT_CTF_INTEGER_BASE_OCTAL"; - case BT_CTF_INTEGER_BASE_DECIMAL: - return "BT_CTF_INTEGER_BASE_DECIMAL"; - case BT_CTF_INTEGER_BASE_HEXADECIMAL: - return "BT_CTF_INTEGER_BASE_HEXADECIMAL"; - default: - return "(unknown)"; - } -} +#ifdef BT_DEV_MODE +# define bt_field_type_freeze _bt_field_type_freeze +#else +# define bt_field_type_freeze(_ft) +#endif -static inline -const char *bt_ctf_scope_string(enum bt_ctf_scope scope) -{ - switch (scope) { - case BT_CTF_SCOPE_UNKNOWN: - return "BT_CTF_SCOPE_UNKNOWN"; - case BT_CTF_SCOPE_TRACE_PACKET_HEADER: - return "BT_CTF_SCOPE_TRACE_PACKET_HEADER"; - case BT_CTF_SCOPE_STREAM_PACKET_CONTEXT: - return "BT_CTF_SCOPE_STREAM_PACKET_CONTEXT"; - case BT_CTF_SCOPE_STREAM_EVENT_HEADER: - return "BT_CTF_SCOPE_STREAM_EVENT_HEADER"; - case BT_CTF_SCOPE_STREAM_EVENT_CONTEXT: - return "BT_CTF_SCOPE_STREAM_EVENT_CONTEXT"; - case BT_CTF_SCOPE_EVENT_CONTEXT: - return "BT_CTF_SCOPE_EVENT_CONTEXT"; - case BT_CTF_SCOPE_EVENT_PAYLOAD: - return "BT_CTF_SCOPE_EVENT_PAYLOAD"; - case BT_CTF_SCOPE_ENV: - return "BT_CTF_SCOPE_ENV"; - default: - return "(unknown)"; - } -} +/* + * This function recursively marks `field_type` and its children as + * being part of a trace. This is used to validate that all field types + * are used at a single location within trace objects even if they are + * shared objects for other purposes. + */ +BT_HIDDEN +void _bt_field_type_make_part_of_trace(struct bt_field_type *field_type); + +#ifdef BT_DEV_MODE +# define bt_field_type_make_part_of_trace _bt_field_type_make_part_of_trace +#else +# define bt_field_type_make_part_of_trace(_ft) ((void) _ft) +#endif #endif /* BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H */