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_typedef_declaration_scope(GQuark declaration_name
,
28 struct declaration_scope
*scope
)
30 return g_hash_table_lookup(scope
->typedef_declarations
,
31 (gconstpointer
) (unsigned long) declaration_name
);
34 struct definition
*lookup_typedef_declaration(GQuark declaration_name
,
35 struct declaration_scope
*scope
)
37 struct definition
*definition
;
40 definition
= lookup_typedef_declaration_scope(declaration_name
,
44 scope
= scope
->parent_scope
;
49 int register_typedef_declaration(GQuark name
, struct declaration
*declaration
,
50 struct declaration_scope
*scope
)
55 /* Only lookup in local scope */
56 if (lookup_typedef_declaration_scope(name
, scope
))
59 g_hash_table_insert(scope
->typedef_declarations
,
60 (gpointer
) (unsigned long) name
,
62 declaration_ref(declaration
);
68 lookup_field_definition_scope(GQuark field_name
,
69 struct definition_scope
*scope
)
71 return g_hash_table_lookup(scope
->definitions
,
72 (gconstpointer
) (unsigned long) field_name
);
76 lookup_field_definition(GQuark field_name
,
77 struct definition_scope
*scope
)
79 struct definition
*definition
;
82 definition
= lookup_field_definition_scope(field_name
, scope
);
85 scope
= scope
->parent_scope
;
90 int register_field_definition(GQuark field_name
, struct definition
*definition
,
91 struct definition_scope
*scope
)
96 /* Only lookup in local scope */
97 if (lookup_field_definition_scope(field_name
, scope
))
100 g_hash_table_insert(scope
->definitions
,
101 (gpointer
) (unsigned long) field_name
,
103 definition_ref(definition
);
107 void declaration_ref(struct declaration
*declaration
)
112 void declaration_unref(struct declaration
*declaration
)
114 if (!--declaration
->ref
)
115 declaration
->declaration_free(declaration
);
118 void definition_ref(struct definition
*definition
)
123 void definition_unref(struct definition
*definition
)
125 if (!--definition
->ref
)
126 definition
->declaration
->definition_free(definition
);
129 struct declaration_scope
*
130 new_declaration_scope(struct declaration_scope
*parent_scope
)
132 struct declaration_scope
*scope
= g_new(struct declaration_scope
, 1);
134 scope
->typedef_declarations
= g_hash_table_new_full(g_direct_hash
,
135 g_direct_equal
, NULL
,
136 (GDestroyNotify
) definition_unref
);
137 scope
->struct_declarations
= g_hash_table_new_full(g_direct_hash
,
138 g_direct_equal
, NULL
,
139 (GDestroyNotify
) declaration_unref
);
140 scope
->variant_declarations
= g_hash_table_new_full(g_direct_hash
,
141 g_direct_equal
, NULL
,
142 (GDestroyNotify
) declaration_unref
);
143 scope
->enum_declarations
= g_hash_table_new_full(g_direct_hash
,
144 g_direct_equal
, NULL
,
145 (GDestroyNotify
) declaration_unref
);
146 scope
->parent_scope
= parent_scope
;
150 void free_declaration_scope(struct declaration_scope
*scope
)
152 g_hash_table_destroy(scope
->enum_declarations
);
153 g_hash_table_destroy(scope
->variant_declarations
);
154 g_hash_table_destroy(scope
->struct_declarations
);
155 g_hash_table_destroy(scope
->typedef_declarations
);
160 struct declaration_struct
*lookup_struct_declaration_scope(GQuark struct_name
,
161 struct declaration_scope
*scope
)
163 return g_hash_table_lookup(scope
->struct_declarations
,
164 (gconstpointer
) (unsigned long) struct_name
);
167 struct declaration_struct
*lookup_struct_declaration(GQuark struct_name
,
168 struct declaration_scope
*scope
)
170 struct declaration_struct
*declaration
;
173 declaration
= lookup_struct_declaration_scope(struct_name
, scope
);
176 scope
= scope
->parent_scope
;
181 int register_struct_declaration(GQuark struct_name
,
182 struct declaration_struct
*struct_declaration
,
183 struct declaration_scope
*scope
)
188 /* Only lookup in local scope */
189 if (lookup_struct_declaration_scope(struct_name
, scope
))
192 g_hash_table_insert(scope
->struct_declarations
,
193 (gpointer
) (unsigned long) struct_name
,
195 declaration_ref(&struct_declaration
->p
);
200 struct declaration_variant
*
201 lookup_variant_declaration_scope(GQuark variant_name
,
202 struct declaration_scope
*scope
)
204 return g_hash_table_lookup(scope
->variant_declarations
,
205 (gconstpointer
) (unsigned long) variant_name
);
208 struct declaration_variant
*
209 lookup_variant_declaration(GQuark variant_name
,
210 struct declaration_scope
*scope
)
212 struct declaration_variant
*declaration
;
215 declaration
= lookup_variant_declaration_scope(variant_name
, scope
);
218 scope
= scope
->parent_scope
;
223 int register_variant_declaration(GQuark variant_name
,
224 struct declaration_variant
*variant_declaration
,
225 struct declaration_scope
*scope
)
230 /* Only lookup in local scope */
231 if (lookup_variant_declaration_scope(variant_name
, scope
))
234 g_hash_table_insert(scope
->variant_declarations
,
235 (gpointer
) (unsigned long) variant_name
,
236 variant_declaration
);
237 declaration_ref(&variant_declaration
->p
);
242 struct declaration_enum
*
243 lookup_enum_declaration_scope(GQuark enum_name
,
244 struct declaration_scope
*scope
)
246 return g_hash_table_lookup(scope
->enum_declarations
,
247 (gconstpointer
) (unsigned long) enum_name
);
250 struct declaration_enum
*
251 lookup_enum_declaration(GQuark enum_name
,
252 struct declaration_scope
*scope
)
254 struct declaration_enum
*declaration
;
257 declaration
= lookup_enum_declaration_scope(enum_name
, scope
);
260 scope
= scope
->parent_scope
;
265 int register_enum_declaration(GQuark enum_name
,
266 struct declaration_enum
*enum_declaration
,
267 struct declaration_scope
*scope
)
272 /* Only lookup in local scope */
273 if (lookup_enum_declaration_scope(enum_name
, scope
))
276 g_hash_table_insert(scope
->enum_declarations
,
277 (gpointer
) (unsigned long) enum_name
,
279 declaration_ref(&enum_declaration
->p
);
283 struct definition_scope
*
284 new_definition_scope(struct definition_scope
*parent_scope
)
286 struct definition_scope
*scope
= g_new(struct definition_scope
, 1);
288 scope
->definitions
= g_hash_table_new_full(g_direct_hash
,
289 g_direct_equal
, NULL
,
290 (GDestroyNotify
) definition_unref
);
291 scope
->parent_scope
= parent_scope
;
295 void free_definition_scope(struct definition_scope
*scope
)
297 g_hash_table_destroy(scope
->definitions
);
This page took 0.050744 seconds and 5 git commands to generate.