- int_class = &enum_class->p;
- int_class->p.name = g_quark_from_string(name);
- int_class->p.alignment = alignment;
- int_class->p.copy = enum_copy;
- int_class->p.free = _enum_type_free;
- int_class->p.ref = 1;
- int_class->len = len;
- int_class->byte_order = byte_order;
- int_class->signedness = signedness;
- if (int_class->p.name) {
- ret = register_type(&int_class->p);
- if (ret) {
- struct enum_range_to_quark *iter, *tmp;
-
- g_hash_table_destroy(enum_class->table.value_to_quark_set);
- cds_list_for_each_entry_safe(iter, tmp, &enum_class->table.range_to_quark, node) {
- cds_list_del(&iter->node);
- g_free(iter);
- }
- g_hash_table_destroy(enum_class->table.quark_to_range_set);
- g_free(enum_class);
- return NULL;
- }
- }
- return enum_class;
+ type_ref(&integer_type->p);
+ enum_type->integer_type = integer_type;
+ enum_type->p.name = g_quark_from_string(name);
+ enum_type->p.alignment = 1;
+ enum_type->p.copy = enum_copy;
+ enum_type->p.type_free = _enum_type_free;
+ enum_type->p.declaration_new = _enum_declaration_new;
+ enum_type->p.declaration_free = _enum_declaration_free;
+ enum_type->p.ref = 1;
+ return enum_type;
+}
+
+static
+struct declaration *
+ _enum_declaration_new(struct type *type,
+ struct declaration_scope *parent_scope)
+{
+ struct type_enum *enum_type =
+ container_of(type, struct type_enum, p);
+ struct declaration_enum *_enum;
+ struct declaration *declaration_integer_parent;
+
+ _enum = g_new(struct declaration_enum, 1);
+ type_ref(&enum_type->p);
+ _enum->p.type = type;
+ _enum->type = enum_type;
+ _enum->p.ref = 1;
+ _enum->value = NULL;
+ declaration_integer_parent =
+ enum_type->integer_type->p.declaration_new(&enum_type->integer_type->p,
+ parent_scope);
+ _enum->integer = container_of(declaration_integer_parent,
+ struct declaration_integer, p);
+ return &_enum->p;
+}
+
+static
+void _enum_declaration_free(struct declaration *declaration)
+{
+ struct declaration_enum *_enum =
+ container_of(declaration, struct declaration_enum, p);
+
+ declaration_unref(&_enum->integer->p);
+ type_unref(_enum->p.type);
+ if (_enum->value)
+ g_array_unref(_enum->value);
+ g_free(_enum);