X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=include%2Fbabeltrace%2Ftypes.h;h=c8595f1231571bb573cbd0bb6358456f77cd49cd;hp=fe7ab62950f10604a1f4971b03f901bb6ab71f3c;hb=de47353a173cf134d0bd50673520e243ebc29054;hpb=e19c3d69b39d2fa422ab54b5ec7192799f536680 diff --git a/include/babeltrace/types.h b/include/babeltrace/types.h index fe7ab629..c8595f12 100644 --- a/include/babeltrace/types.h +++ b/include/babeltrace/types.h @@ -87,14 +87,41 @@ char *get_pos_addr(struct stream_pos *pos) struct format; struct declaration; -/* Type declaration scope */ +/* type scope */ +struct type_scope { + /* Hash table mapping type name GQuark to "struct declaration" */ + GHashTable *type_declarations; + /* Hash table mapping struct name GQuark to "struct type_struct" */ + GHashTable *struct_types; + /* Hash table mapping variant name GQuark to "struct type_variant" */ + GHashTable *variant_types; + /* Hash table mapping enum name GQuark to "struct type_enum" */ + GHashTable *enum_types; + struct type_scope *parent_scope; +}; + +/* declaration scope */ struct declaration_scope { - /* Hash table mapping type name GQuark to struct type */ - GHashTable *types; + /* Hash table mapping field name GQuark to "struct declaration" */ + GHashTable *declarations; struct declaration_scope *parent_scope; }; +enum ctf_type_id { + CTF_TYPE_UNKNOWN = 0, + CTF_TYPE_INTEGER, + CTF_TYPE_FLOAT, + CTF_TYPE_ENUM, + CTF_TYPE_STRING, + CTF_TYPE_STRUCT, + CTF_TYPE_VARIANT, + CTF_TYPE_ARRAY, + CTF_TYPE_SEQUENCE, + NR_CTF_TYPES, +}; + struct type { + enum ctf_type_id id; GQuark name; /* type name */ size_t alignment; /* type alignment, in bits */ int ref; /* number of references to the type */ @@ -229,12 +256,14 @@ struct type_field { }; struct field { - struct declaration *type; + GQuark name; + struct declaration *declaration; }; struct type_struct { struct type p; GHashTable *fields_by_name; /* Tuples (field name, field index) */ + struct type_scope *scope; GArray *fields; /* Array of type_field */ }; @@ -248,14 +277,17 @@ struct declaration_struct { struct type_variant { struct type p; GHashTable *fields_by_tag; /* Tuples (field tag, field index) */ + struct type_scope *scope; GArray *fields; /* Array of type_field */ + GQuark tag_name; /* TODO */ + /* Tag name must be nonzero and must exist when defining the variant */ }; struct declaration_variant { struct declaration p; struct type_variant *type; struct declaration_scope *scope; - struct declaration *tag; + struct declaration *enum_tag; GArray *fields; /* Array of struct field */ struct field *current_field; /* Last field read */ }; @@ -264,6 +296,7 @@ struct type_array { struct type p; size_t len; struct type *elem; + struct type_scope *scope; }; struct declaration_array { @@ -277,6 +310,7 @@ struct type_sequence { struct type p; struct type_integer *len_type; struct type *elem; + struct type_scope *scope; }; struct declaration_sequence { @@ -287,16 +321,55 @@ struct declaration_sequence { struct field current_element; /* struct field */ }; -struct type *lookup_type(GQuark qname, struct declaration_scope *scope); -int register_type(struct type *type, struct declaration_scope *scope); +/* + * type_declaration is for typedef and typealias. They are registered + * into type scopes. + */ +int register_type_declaration(GQuark type_name, struct declaration *declaration, + struct type_scope *scope); +struct declaration *lookup_type_declaration(GQuark type_name, + struct type_scope *scope); -void type_ref(struct type *type); -void type_unref(struct type *type); +/* + * Type scopes also contain a separate registry for struct, variant and + * enum types. Those register types rather than type declarations, so + * that a named variant can be declared without specifying its target + * "choice" tag field immediately. + */ +int register_struct_type(GQuark struct_name, struct type_struct *struct_type, + struct type_scope *scope); +struct type_struct *lookup_struct_type(GQuark struct_name, + struct type_scope *scope); +int register_variant_type(GQuark variant_name, + struct type_variant *variant_type, + struct type_scope *scope); +struct type_variant *lookup_variant_type(GQuark variant_name, + struct type_scope *scope); +int register_enum_type(GQuark enum_name, struct type_enum *enum_type, + struct type_scope *scope); +struct type_enum *lookup_enum_type(GQuark enum_name, + struct type_scope *scope); + +struct type_scope *new_type_scope(struct type_scope *parent_scope); +void free_type_scope(struct type_scope *scope); +/* + * field_declaration is for field declarations. They are registered into + * declaration scopes. + */ +struct declaration * + lookup_field_declaration(GQuark field_name, + struct declaration_scope *scope); +int register_field_declaration(GQuark field_name, + struct declaration *declaration, + struct declaration_scope *scope); struct declaration_scope * new_declaration_scope(struct declaration_scope *parent_scope); void free_declaration_scope(struct declaration_scope *scope); +void type_ref(struct type *type); +void type_unref(struct type *type); + void declaration_ref(struct declaration *declaration); void declaration_unref(struct declaration *declaration); @@ -347,7 +420,8 @@ size_t enum_get_nr_enumerators(struct type_enum *enum_type); struct type_enum *enum_type_new(const char *name, struct type_integer *integer_type); -struct type_struct *struct_type_new(const char *name); +struct type_struct *struct_type_new(const char *name, + struct type_scope *parent_scope); void struct_type_add_field(struct type_struct *struct_type, const char *field_name, struct type *field_type); /* @@ -370,7 +444,8 @@ struct_get_field_from_index(struct declaration_struct *struct_declaration, * from numeric values to a single tag. Overlapping tag value ranges are * therefore forbidden. */ -struct type_variant *variant_type_new(const char *name); +struct type_variant *variant_type_new(const char *name, + struct type_scope *parent_scope); void variant_type_add_field(struct type_variant *variant_type, const char *tag_name, struct type *tag_type); struct type_field * @@ -393,7 +468,8 @@ variant_get_current_field(struct declaration_variant *variant); * explicitly. "len" is the number of elements in the array. */ struct type_array *array_type_new(const char *name, - size_t len, struct type *elem_type); + size_t len, struct type *elem_type, + struct type_scope *parent_scope); /* * int_type and elem_type passed as parameter now belong to the sequence. No @@ -401,6 +477,7 @@ struct type_array *array_type_new(const char *name, */ struct type_sequence *sequence_type_new(const char *name, struct type_integer *len_type, - struct type *elem_type); + struct type *elem_type, + struct type_scope *parent_scope); #endif /* _BABELTRACE_TYPES_H */