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_declaration_scope(GQuark type_name
, struct type_scope
*scope
)
29 return g_hash_table_lookup(scope
->type_declarations
,
30 (gconstpointer
) (unsigned long) type_name
);
33 struct declaration
*lookup_type_declaration(GQuark type_name
, struct type_scope
*scope
)
35 struct declaration
*declaration
;
38 declaration
= lookup_type_declaration_scope(type_name
, scope
);
41 scope
= scope
->parent_scope
;
46 int register_type_declaration(GQuark name
, struct declaration
*declaration
,
47 struct type_scope
*scope
)
52 /* Only lookup in local scope */
53 if (lookup_type_declaration_scope(name
, scope
))
56 g_hash_table_insert(scope
->type_declarations
,
57 (gpointer
) (unsigned long) name
,
59 declaration_ref(declaration
);
65 lookup_field_declaration_scope(GQuark field_name
, struct declaration_scope
*scope
)
67 return g_hash_table_lookup(scope
->declarations
,
68 (gconstpointer
) (unsigned long) field_name
);
72 lookup_field_declaration(GQuark field_name
, struct declaration_scope
*scope
)
74 struct declaration
*declaration
;
77 declaration
= lookup_field_declaration_scope(field_name
, scope
);
80 scope
= scope
->parent_scope
;
85 int register_field_declaration(GQuark field_name
, struct declaration
*declaration
,
86 struct declaration_scope
*scope
)
91 /* Only lookup in local scope */
92 if (lookup_field_declaration_scope(field_name
, scope
))
95 g_hash_table_insert(scope
->declarations
,
96 (gpointer
) (unsigned long) field_name
,
98 declaration_ref(declaration
);
102 void type_ref(struct type
*type
)
107 void type_unref(struct type
*type
)
110 type
->type_free(type
);
113 void declaration_ref(struct declaration
*declaration
)
118 void declaration_unref(struct declaration
*declaration
)
120 if (!--declaration
->ref
)
121 declaration
->type
->declaration_free(declaration
);
125 new_type_scope(struct type_scope
*parent_scope
)
127 struct type_scope
*scope
= g_new(struct type_scope
, 1);
129 scope
->type_declarations
= g_hash_table_new_full(g_direct_hash
,
130 g_direct_equal
, NULL
,
131 (GDestroyNotify
) declaration_unref
);
132 scope
->struct_types
= g_hash_table_new_full(g_direct_hash
,
133 g_direct_equal
, NULL
,
134 (GDestroyNotify
) type_unref
);
135 scope
->variant_types
= g_hash_table_new_full(g_direct_hash
,
136 g_direct_equal
, NULL
,
137 (GDestroyNotify
) type_unref
);
138 scope
->enum_types
= g_hash_table_new_full(g_direct_hash
,
139 g_direct_equal
, NULL
,
140 (GDestroyNotify
) type_unref
);
141 scope
->parent_scope
= parent_scope
;
145 void free_type_scope(struct type_scope
*scope
)
147 g_hash_table_destroy(scope
->enum_types
);
148 g_hash_table_destroy(scope
->variant_types
);
149 g_hash_table_destroy(scope
->struct_types
);
150 g_hash_table_destroy(scope
->type_declarations
);
155 struct type_struct
*lookup_struct_type_scope(GQuark struct_name
,
156 struct type_scope
*scope
)
158 return g_hash_table_lookup(scope
->struct_types
,
159 (gconstpointer
) (unsigned long) struct_name
);
162 struct type_struct
*lookup_struct_type(GQuark struct_name
,
163 struct type_scope
*scope
)
165 struct type_struct
*type
;
168 type
= lookup_struct_type_scope(struct_name
, scope
);
171 scope
= scope
->parent_scope
;
176 int register_struct_type(GQuark struct_name
, struct type_struct
*struct_type
,
177 struct type_scope
*scope
)
182 /* Only lookup in local scope */
183 if (lookup_struct_type_scope(struct_name
, scope
))
186 g_hash_table_insert(scope
->struct_types
,
187 (gpointer
) (unsigned long) struct_name
,
189 type_ref(&struct_type
->p
);
194 struct type_variant
*lookup_variant_type_scope(GQuark variant_name
,
195 struct type_scope
*scope
)
197 return g_hash_table_lookup(scope
->variant_types
,
198 (gconstpointer
) (unsigned long) variant_name
);
201 struct type_variant
*lookup_variant_type(GQuark variant_name
,
202 struct type_scope
*scope
)
204 struct type_variant
*type
;
207 type
= lookup_variant_type_scope(variant_name
, scope
);
210 scope
= scope
->parent_scope
;
215 int register_variant_type(GQuark variant_name
,
216 struct type_variant
*variant_type
,
217 struct type_scope
*scope
)
222 /* Only lookup in local scope */
223 if (lookup_variant_type_scope(variant_name
, scope
))
226 g_hash_table_insert(scope
->variant_types
,
227 (gpointer
) (unsigned long) variant_name
,
229 type_ref(&variant_type
->p
);
234 struct type_enum
*lookup_enum_type_scope(GQuark enum_name
,
235 struct type_scope
*scope
)
237 return g_hash_table_lookup(scope
->enum_types
,
238 (gconstpointer
) (unsigned long) enum_name
);
241 struct type_enum
*lookup_enum_type(GQuark enum_name
,
242 struct type_scope
*scope
)
244 struct type_enum
*type
;
247 type
= lookup_enum_type_scope(enum_name
, scope
);
250 scope
= scope
->parent_scope
;
255 int register_enum_type(GQuark enum_name
, struct type_enum
*enum_type
,
256 struct type_scope
*scope
)
261 /* Only lookup in local scope */
262 if (lookup_enum_type_scope(enum_name
, scope
))
265 g_hash_table_insert(scope
->enum_types
,
266 (gpointer
) (unsigned long) enum_name
,
268 type_ref(&enum_type
->p
);
272 struct declaration_scope
*
273 new_declaration_scope(struct declaration_scope
*parent_scope
)
275 struct declaration_scope
*scope
= g_new(struct declaration_scope
, 1);
277 scope
->declarations
= g_hash_table_new_full(g_direct_hash
,
278 g_direct_equal
, NULL
,
279 (GDestroyNotify
) declaration_unref
);
280 scope
->parent_scope
= parent_scope
;
284 void free_declaration_scope(struct declaration_scope
*scope
)
286 g_hash_table_destroy(scope
->declarations
);
This page took 0.036582 seconds and 4 git commands to generate.