+
+static
+struct type_enum *lookup_enum_type_scope(GQuark enum_name,
+ struct type_scope *scope)
+{
+ return g_hash_table_lookup(scope->enum_types,
+ (gconstpointer) (unsigned long) enum_name);
+}
+
+struct type_enum *lookup_enum_type(GQuark enum_name,
+ struct type_scope *scope)
+{
+ struct type_enum *type;
+
+ while (scope) {
+ type = lookup_enum_type_scope(enum_name, scope);
+ if (type)
+ return type;
+ scope = scope->parent_scope;
+ }
+ return NULL;
+}
+
+int register_enum_type(GQuark enum_name, struct type_enum *enum_type,
+ struct type_scope *scope)
+{
+ if (!enum_name)
+ return -EPERM;
+
+ /* Only lookup in local scope */
+ if (lookup_enum_type_scope(enum_name, scope))
+ return -EEXIST;
+
+ g_hash_table_insert(scope->enum_types,
+ (gpointer) (unsigned long) enum_name,
+ enum_type);
+ type_ref(&enum_type->p);
+ return 0;
+}
+
+struct definition_scope *
+ new_definition_scope(struct definition_scope *parent_scope)
+{
+ struct definition_scope *scope = g_new(struct definition_scope, 1);
+
+ scope->definitions = g_hash_table_new_full(g_direct_hash,
+ g_direct_equal, NULL,
+ (GDestroyNotify) definition_unref);
+ scope->parent_scope = parent_scope;
+ return scope;
+}
+
+void free_definition_scope(struct definition_scope *scope)
+{
+ g_hash_table_destroy(scope->definitions);
+ g_free(scope);
+}