4 * BabelTrace - Converter
8 * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
21 #include <babeltrace/format.h>
27 lookup_type_scope(GQuark type_name
, struct type_scope
*scope
)
29 return g_hash_table_lookup(scope
->types
,
30 (gconstpointer
) (unsigned long) type_name
);
33 struct type
*lookup_type(GQuark type_name
, struct type_scope
*scope
)
38 type
= lookup_type_scope(type_name
, scope
);
41 scope
= scope
->parent_scope
;
46 int register_type(GQuark name
, struct type
*type
, struct type_scope
*scope
)
48 g_assert(name
== type
->name
);
53 /* Only lookup in local scope */
54 if (lookup_type_scope(name
, scope
))
57 g_hash_table_insert(scope
->types
,
58 (gpointer
) (unsigned long) name
,
66 lookup_declaration_scope(GQuark field_name
, struct declaration_scope
*scope
)
68 return g_hash_table_lookup(scope
->declarations
,
69 (gconstpointer
) (unsigned long) field_name
);
73 lookup_declaration(GQuark field_name
, struct declaration_scope
*scope
)
75 struct declaration
*declaration
;
78 declaration
= lookup_declaration_scope(field_name
, scope
);
81 scope
= scope
->parent_scope
;
86 int register_declaration(GQuark field_name
, struct declaration
*declaration
,
87 struct declaration_scope
*scope
)
92 /* Only lookup in local scope */
93 if (lookup_declaration_scope(field_name
, scope
))
96 g_hash_table_insert(scope
->declarations
,
97 (gpointer
) (unsigned long) field_name
,
99 declaration_ref(declaration
);
103 void type_ref(struct type
*type
)
108 void type_unref(struct type
*type
)
111 type
->type_free(type
);
114 void declaration_ref(struct declaration
*declaration
)
119 void declaration_unref(struct declaration
*declaration
)
121 if (!--declaration
->ref
)
122 declaration
->type
->declaration_free(declaration
);
126 new_type_scope(struct type_scope
*parent_scope
)
128 struct type_scope
*scope
= g_new(struct type_scope
, 1);
130 scope
->types
= g_hash_table_new_full(g_direct_hash
,
131 g_direct_equal
, NULL
,
132 (GDestroyNotify
) type_unref
);
133 scope
->parent_scope
= parent_scope
;
137 void free_type_scope(struct type_scope
*scope
)
139 g_hash_table_destroy(scope
->types
);
143 struct declaration_scope
*
144 new_declaration_scope(struct declaration_scope
*parent_scope
)
146 struct declaration_scope
*scope
= g_new(struct declaration_scope
, 1);
148 scope
->declarations
= g_hash_table_new_full(g_direct_hash
,
149 g_direct_equal
, NULL
,
150 (GDestroyNotify
) declaration_unref
);
151 scope
->parent_scope
= parent_scope
;
155 void free_declaration_scope(struct declaration_scope
*scope
)
157 g_hash_table_destroy(scope
->declarations
);
This page took 0.031718 seconds and 4 git commands to generate.