summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
3c5cc37)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
struct format;
struct declaration;
struct format;
struct declaration;
-/* Type declaration scope */
-struct declaration_scope {
+/* type scope */
+struct type_scope {
/* Hash table mapping type name GQuark to struct type */
GHashTable *types;
/* Hash table mapping type name GQuark to struct type */
GHashTable *types;
+ struct type_scope *parent_scope;
+};
+
+/* declaration scope */
+struct declaration_scope {
/* Hash table mapping field name GQuark to struct declaration */
GHashTable *declarations;
struct declaration_scope *parent_scope;
/* Hash table mapping field name GQuark to struct declaration */
GHashTable *declarations;
struct declaration_scope *parent_scope;
struct type_struct {
struct type p;
GHashTable *fields_by_name; /* Tuples (field name, field index) */
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 */
};
GArray *fields; /* Array of type_field */
};
struct type_variant {
struct type p;
GHashTable *fields_by_tag; /* Tuples (field tag, field index) */
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 */
};
GArray *fields; /* Array of type_field */
};
struct type p;
size_t len;
struct type *elem;
struct type p;
size_t len;
struct type *elem;
+ struct type_scope *scope;
};
struct declaration_array {
};
struct declaration_array {
struct type p;
struct type_integer *len_type;
struct type *elem;
struct type p;
struct type_integer *len_type;
struct type *elem;
+ struct type_scope *scope;
};
struct declaration_sequence {
};
struct declaration_sequence {
struct field current_element; /* struct field */
};
struct field current_element; /* struct field */
};
-struct type *lookup_type(GQuark type_name, struct declaration_scope *scope);
-int register_type(struct type *type, struct declaration_scope *scope);
+int register_type(GQuark type_name, struct type *type,
+ struct type_scope *scope);
+struct type *lookup_type(GQuark type_name, struct type_scope *scope);
+struct type_scope *new_type_scope(struct type_scope *parent_scope);
+void free_type_scope(struct type_scope *scope);
struct declaration *
lookup_declaration(GQuark field_name, struct declaration_scope *scope);
int register_declaration(GQuark field_name, struct declaration *declaration,
struct declaration_scope *scope);
struct declaration *
lookup_declaration(GQuark field_name, struct declaration_scope *scope);
int register_declaration(GQuark field_name, struct declaration *declaration,
struct declaration_scope *scope);
-
-void type_ref(struct type *type);
-void type_unref(struct type *type);
-
struct declaration_scope *
new_declaration_scope(struct declaration_scope *parent_scope);
void free_declaration_scope(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);
void declaration_ref(struct declaration *declaration);
void declaration_unref(struct declaration *declaration);
struct type_enum *enum_type_new(const char *name,
struct type_integer *integer_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);
/*
void struct_type_add_field(struct type_struct *struct_type,
const char *field_name, struct type *field_type);
/*
* from numeric values to a single tag. Overlapping tag value ranges are
* therefore forbidden.
*/
* 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 *
void variant_type_add_field(struct type_variant *variant_type,
const char *tag_name, struct type *tag_type);
struct type_field *
* explicitly. "len" is the number of elements in the array.
*/
struct type_array *array_type_new(const char *name,
* 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
/*
* int_type and elem_type passed as parameter now belong to the sequence. No
*/
struct type_sequence *sequence_type_new(const char *name,
struct type_integer *len_type,
*/
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 */
#endif /* _BABELTRACE_TYPES_H */
struct type_array *array_type =
container_of(type, struct type_array, p);
struct type_array *array_type =
container_of(type, struct type_array, p);
+ free_type_scope(array_type->scope);
type_unref(array_type->elem);
g_free(array_type);
}
struct type_array *
type_unref(array_type->elem);
g_free(array_type);
}
struct type_array *
- array_type_new(const char *name, size_t len, struct type *elem_type)
+ array_type_new(const char *name, size_t len, struct type *elem_type,
+ struct type_scope *parent_scope)
{
struct type_array *array_type;
struct type *type;
{
struct type_array *array_type;
struct type *type;
array_type->len = len;
type_ref(elem_type);
array_type->elem = elem_type;
array_type->len = len;
type_ref(elem_type);
array_type->elem = elem_type;
+ array_type->scope = new_type_scope(parent_scope);
type->name = g_quark_from_string(name);
/* No need to align the array, the first element will align itself */
type->alignment = 1;
type->name = g_quark_from_string(name);
/* No need to align the array, the first element will align itself */
type->alignment = 1;
struct type_sequence *sequence_type =
container_of(type, struct type_sequence, p);
struct type_sequence *sequence_type =
container_of(type, struct type_sequence, p);
+ free_type_scope(sequence_type->scope);
type_unref(&sequence_type->len_type->p);
type_unref(sequence_type->elem);
g_free(sequence_type);
type_unref(&sequence_type->len_type->p);
type_unref(sequence_type->elem);
g_free(sequence_type);
struct type_sequence *
sequence_type_new(const char *name, struct type_integer *len_type,
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)
{
struct type_sequence *sequence_type;
struct type *type;
{
struct type_sequence *sequence_type;
struct type *type;
sequence_type->len_type = len_type;
type_ref(elem_type);
sequence_type->elem = elem_type;
sequence_type->len_type = len_type;
type_ref(elem_type);
sequence_type->elem = elem_type;
+ sequence_type->scope = new_type_scope(parent_scope);
type->name = g_quark_from_string(name);
type->alignment = max(len_type->p.alignment, elem_type->alignment);
type->copy = sequence_copy;
type->name = g_quark_from_string(name);
type->alignment = max(len_type->p.alignment, elem_type->alignment);
type->copy = sequence_copy;
container_of(type, struct type_struct, p);
unsigned long i;
container_of(type, struct type_struct, p);
unsigned long i;
+ free_type_scope(struct_type->scope);
g_hash_table_destroy(struct_type->fields_by_name);
for (i = 0; i < struct_type->fields->len; i++) {
g_hash_table_destroy(struct_type->fields_by_name);
for (i = 0; i < struct_type->fields->len; i++) {
-struct type_struct *struct_type_new(const char *name)
+struct type_struct *struct_type_new(const char *name,
+ struct type_scope *parent_scope)
{
struct type_struct *struct_type;
struct type *type;
{
struct type_struct *struct_type;
struct type *type;
struct_type->fields = g_array_sized_new(FALSE, TRUE,
sizeof(struct type_field),
DEFAULT_NR_STRUCT_FIELDS);
struct_type->fields = g_array_sized_new(FALSE, TRUE,
sizeof(struct type_field),
DEFAULT_NR_STRUCT_FIELDS);
+ struct_type->scope = new_type_scope(parent_scope);
type->name = g_quark_from_string(name);
type->alignment = 1;
type->copy = struct_copy;
type->name = g_quark_from_string(name);
type->alignment = 1;
type->copy = struct_copy;
- lookup_type_scope(GQuark type_name, struct declaration_scope *scope)
+ lookup_type_scope(GQuark type_name, struct type_scope *scope)
{
return g_hash_table_lookup(scope->types,
(gconstpointer) (unsigned long) type_name);
}
{
return g_hash_table_lookup(scope->types,
(gconstpointer) (unsigned long) type_name);
}
-struct type *lookup_type(GQuark type_name, struct declaration_scope *scope)
+struct type *lookup_type(GQuark type_name, struct type_scope *scope)
-int register_type(struct type *type, struct declaration_scope *scope)
+int register_type(GQuark name, struct type *type, struct type_scope *scope)
+ g_assert(name == type->name);
+
+ if (!name)
return -EPERM;
/* Only lookup in local scope */
return -EPERM;
/* Only lookup in local scope */
- if (lookup_type_scope(type->name, scope))
+ if (lookup_type_scope(name, scope))
return -EEXIST;
g_hash_table_insert(scope->types,
return -EEXIST;
g_hash_table_insert(scope->types,
- (gpointer) (unsigned long) type->name,
+ (gpointer) (unsigned long) name,
type);
type_ref(type);
return 0;
type);
type_ref(type);
return 0;
declaration->type->declaration_free(declaration);
}
declaration->type->declaration_free(declaration);
}
-struct declaration_scope *
- new_declaration_scope(struct declaration_scope *parent_scope)
+struct type_scope *
+ new_type_scope(struct type_scope *parent_scope)
- struct declaration_scope *scope = g_new(struct declaration_scope, 1);
+ struct type_scope *scope = g_new(struct type_scope, 1);
scope->types = g_hash_table_new_full(g_direct_hash,
g_direct_equal, NULL,
(GDestroyNotify) type_unref);
scope->types = g_hash_table_new_full(g_direct_hash,
g_direct_equal, NULL,
(GDestroyNotify) type_unref);
+ scope->parent_scope = parent_scope;
+ return scope;
+}
+
+void free_type_scope(struct type_scope *scope)
+{
+ g_hash_table_destroy(scope->types);
+ g_free(scope);
+}
+
+struct declaration_scope *
+ new_declaration_scope(struct declaration_scope *parent_scope)
+{
+ struct declaration_scope *scope = g_new(struct declaration_scope, 1);
+
scope->declarations = g_hash_table_new_full(g_direct_hash,
g_direct_equal, NULL,
(GDestroyNotify) declaration_unref);
scope->declarations = g_hash_table_new_full(g_direct_hash,
g_direct_equal, NULL,
(GDestroyNotify) declaration_unref);
void free_declaration_scope(struct declaration_scope *scope)
{
g_hash_table_destroy(scope->declarations);
void free_declaration_scope(struct declaration_scope *scope)
{
g_hash_table_destroy(scope->declarations);
- g_hash_table_destroy(scope->types);
container_of(type, struct type_variant, p);
unsigned long i;
container_of(type, struct type_variant, p);
unsigned long i;
+ free_type_scope(variant_type->scope);
g_hash_table_destroy(variant_type->fields_by_tag);
for (i = 0; i < variant_type->fields->len; i++) {
g_hash_table_destroy(variant_type->fields_by_tag);
for (i = 0; i < variant_type->fields->len; i++) {
-struct type_variant *variant_type_new(const char *name)
+struct type_variant *variant_type_new(const char *name,
+ struct type_scope *parent_scope)
{
struct type_variant *variant_type;
struct type *type;
{
struct type_variant *variant_type;
struct type *type;
variant_type->fields = g_array_sized_new(FALSE, TRUE,
sizeof(struct type_field),
DEFAULT_NR_STRUCT_FIELDS);
variant_type->fields = g_array_sized_new(FALSE, TRUE,
sizeof(struct type_field),
DEFAULT_NR_STRUCT_FIELDS);
+ variant_type->scope = new_type_scope(parent_scope);
type->name = g_quark_from_string(name);
type->alignment = 1;
type->copy = variant_copy;
type->name = g_quark_from_string(name);
type->alignment = 1;
type->copy = variant_copy;