1 /* valascope.c generated by valac, the Vala compiler
2 * generated from valascope.vala, do not modify */
3
4 /* valascope.vala
5 *
6 * Copyright (C) 2006-2010 Jürg Billeter
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 * Author:
23 * Jürg Billeter <j@bitron.ch>
24 */
25
26 #include "vala.h"
27 #include <valagee.h>
28 #include <glib-object.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <glib.h>
32 #include <gobject/gvaluecollector.h>
33
34 #define _vala_map_unref0(var) ((var == NULL) ? NULL : (var = (vala_map_unref (var), NULL)))
35 #define _vala_iterable_unref0(var) ((var == NULL) ? NULL : (var = (vala_iterable_unref (var), NULL)))
36 #define _vala_code_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_node_unref (var), NULL)))
37 #define _g_free0(var) (var = (g_free (var), NULL))
38 typedef struct _ValaParamSpecScope ValaParamSpecScope;
39
40 struct _ValaScopePrivate {
41 ValaSymbol* _owner;
42 ValaScope* _parent_scope;
43 ValaMap* symbol_table;
44 ValaList* anonymous_members;
45 };
46
47 struct _ValaParamSpecScope {
48 GParamSpec parent_instance;
49 };
50
51 static gint ValaScope_private_offset;
52 static gpointer vala_scope_parent_class = NULL;
53
54 static void vala_scope_finalize (ValaScope * obj);
55 static GType vala_scope_get_type_once (void);
56
57 static inline gpointer
vala_scope_get_instance_private(ValaScope * self)58 vala_scope_get_instance_private (ValaScope* self)
59 {
60 return G_STRUCT_MEMBER_P (self, ValaScope_private_offset);
61 }
62
63 ValaSymbol*
vala_scope_get_owner(ValaScope * self)64 vala_scope_get_owner (ValaScope* self)
65 {
66 ValaSymbol* result;
67 ValaSymbol* _tmp0_;
68 g_return_val_if_fail (self != NULL, NULL);
69 _tmp0_ = self->priv->_owner;
70 result = _tmp0_;
71 return result;
72 }
73
74 void
vala_scope_set_owner(ValaScope * self,ValaSymbol * value)75 vala_scope_set_owner (ValaScope* self,
76 ValaSymbol* value)
77 {
78 g_return_if_fail (self != NULL);
79 self->priv->_owner = value;
80 }
81
82 ValaScope*
vala_scope_get_parent_scope(ValaScope * self)83 vala_scope_get_parent_scope (ValaScope* self)
84 {
85 ValaScope* result;
86 ValaScope* _tmp0_;
87 g_return_val_if_fail (self != NULL, NULL);
88 _tmp0_ = self->priv->_parent_scope;
89 result = _tmp0_;
90 return result;
91 }
92
93 void
vala_scope_set_parent_scope(ValaScope * self,ValaScope * value)94 vala_scope_set_parent_scope (ValaScope* self,
95 ValaScope* value)
96 {
97 g_return_if_fail (self != NULL);
98 self->priv->_parent_scope = value;
99 }
100
101 /**
102 * Creates a new scope.
103 *
104 * @return newly created scope
105 */
106 ValaScope*
vala_scope_construct(GType object_type,ValaSymbol * owner)107 vala_scope_construct (GType object_type,
108 ValaSymbol* owner)
109 {
110 ValaScope* self = NULL;
111 self = (ValaScope*) g_type_create_instance (object_type);
112 vala_scope_set_owner (self, owner);
113 return self;
114 }
115
116 ValaScope*
vala_scope_new(ValaSymbol * owner)117 vala_scope_new (ValaSymbol* owner)
118 {
119 return vala_scope_construct (VALA_TYPE_SCOPE, owner);
120 }
121
122 /**
123 * Adds the specified symbol with the specified name to the symbol table
124 * of this scope.
125 *
126 * @param name name for the specified symbol
127 * @param sym a symbol
128 */
129 void
vala_scope_add(ValaScope * self,const gchar * name,ValaSymbol * sym)130 vala_scope_add (ValaScope* self,
131 const gchar* name,
132 ValaSymbol* sym)
133 {
134 gboolean _tmp0_ = FALSE;
135 g_return_if_fail (self != NULL);
136 g_return_if_fail (sym != NULL);
137 if (VALA_IS_PARAMETER (sym)) {
138 gboolean _tmp1_;
139 gboolean _tmp2_;
140 _tmp1_ = vala_parameter_get_params_array (G_TYPE_CHECK_INSTANCE_CAST (sym, VALA_TYPE_PARAMETER, ValaParameter));
141 _tmp2_ = _tmp1_;
142 _tmp0_ = _tmp2_;
143 } else {
144 _tmp0_ = FALSE;
145 }
146 if (_tmp0_) {
147 name = NULL;
148 }
149 if (name != NULL) {
150 ValaMap* _tmp3_;
151 ValaMap* _tmp36_;
152 _tmp3_ = self->priv->symbol_table;
153 if (_tmp3_ == NULL) {
154 GHashFunc _tmp4_;
155 GEqualFunc _tmp5_;
156 GEqualFunc _tmp6_;
157 ValaHashMap* _tmp7_;
158 _tmp4_ = g_str_hash;
159 _tmp5_ = g_str_equal;
160 _tmp6_ = g_direct_equal;
161 _tmp7_ = vala_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, VALA_TYPE_SYMBOL, (GBoxedCopyFunc) vala_code_node_ref, (GDestroyNotify) vala_code_node_unref, _tmp4_, _tmp5_, _tmp6_);
162 _vala_map_unref0 (self->priv->symbol_table);
163 self->priv->symbol_table = (ValaMap*) _tmp7_;
164 } else {
165 ValaSymbol* _tmp8_;
166 ValaSymbol* _tmp9_;
167 gboolean _tmp10_;
168 _tmp8_ = vala_scope_lookup (self, name);
169 _tmp9_ = _tmp8_;
170 _tmp10_ = _tmp9_ != NULL;
171 _vala_code_node_unref0 (_tmp9_);
172 if (_tmp10_) {
173 ValaSymbol* _tmp11_;
174 gboolean _tmp12_ = FALSE;
175 ValaSymbol* _tmp13_;
176 const gchar* _tmp14_;
177 const gchar* _tmp15_;
178 ValaSymbol* _tmp30_;
179 ValaSymbol* _tmp31_;
180 ValaSourceReference* _tmp32_;
181 ValaSourceReference* _tmp33_;
182 gchar* _tmp34_;
183 gchar* _tmp35_;
184 _tmp11_ = self->priv->_owner;
185 vala_code_node_set_error ((ValaCodeNode*) _tmp11_, TRUE);
186 _tmp13_ = self->priv->_owner;
187 _tmp14_ = vala_symbol_get_name (_tmp13_);
188 _tmp15_ = _tmp14_;
189 if (_tmp15_ == NULL) {
190 ValaSymbol* _tmp16_;
191 ValaSymbol* _tmp17_;
192 ValaSymbol* _tmp18_;
193 _tmp16_ = self->priv->_owner;
194 _tmp17_ = vala_symbol_get_parent_symbol (_tmp16_);
195 _tmp18_ = _tmp17_;
196 _tmp12_ = _tmp18_ == NULL;
197 } else {
198 _tmp12_ = FALSE;
199 }
200 if (_tmp12_) {
201 ValaSourceReference* _tmp19_;
202 ValaSourceReference* _tmp20_;
203 gchar* _tmp21_;
204 gchar* _tmp22_;
205 _tmp19_ = vala_code_node_get_source_reference ((ValaCodeNode*) sym);
206 _tmp20_ = _tmp19_;
207 _tmp21_ = g_strdup_printf ("The root namespace already contains a definition for `%s'", name);
208 _tmp22_ = _tmp21_;
209 vala_report_error (_tmp20_, _tmp22_);
210 _g_free0 (_tmp22_);
211 } else {
212 ValaSourceReference* _tmp23_;
213 ValaSourceReference* _tmp24_;
214 ValaSymbol* _tmp25_;
215 gchar* _tmp26_;
216 gchar* _tmp27_;
217 gchar* _tmp28_;
218 gchar* _tmp29_;
219 _tmp23_ = vala_code_node_get_source_reference ((ValaCodeNode*) sym);
220 _tmp24_ = _tmp23_;
221 _tmp25_ = self->priv->_owner;
222 _tmp26_ = vala_symbol_get_full_name (_tmp25_);
223 _tmp27_ = _tmp26_;
224 _tmp28_ = g_strdup_printf ("`%s' already contains a definition for `%s'", _tmp27_, name);
225 _tmp29_ = _tmp28_;
226 vala_report_error (_tmp24_, _tmp29_);
227 _g_free0 (_tmp29_);
228 _g_free0 (_tmp27_);
229 }
230 _tmp30_ = vala_scope_lookup (self, name);
231 _tmp31_ = _tmp30_;
232 _tmp32_ = vala_code_node_get_source_reference ((ValaCodeNode*) _tmp31_);
233 _tmp33_ = _tmp32_;
234 _tmp34_ = g_strdup_printf ("previous definition of `%s' was here", name);
235 _tmp35_ = _tmp34_;
236 vala_report_notice (_tmp33_, _tmp35_);
237 _g_free0 (_tmp35_);
238 _vala_code_node_unref0 (_tmp31_);
239 return;
240 }
241 }
242 _tmp36_ = self->priv->symbol_table;
243 vala_map_set (_tmp36_, (const gchar*) name, sym);
244 } else {
245 ValaList* _tmp37_;
246 ValaList* _tmp40_;
247 _tmp37_ = self->priv->anonymous_members;
248 if (_tmp37_ == NULL) {
249 GEqualFunc _tmp38_;
250 ValaArrayList* _tmp39_;
251 _tmp38_ = g_direct_equal;
252 _tmp39_ = vala_array_list_new (VALA_TYPE_SYMBOL, (GBoxedCopyFunc) vala_code_node_ref, (GDestroyNotify) vala_code_node_unref, _tmp38_);
253 _vala_iterable_unref0 (self->priv->anonymous_members);
254 self->priv->anonymous_members = (ValaList*) _tmp39_;
255 }
256 _tmp40_ = self->priv->anonymous_members;
257 vala_collection_add ((ValaCollection*) _tmp40_, sym);
258 }
259 vala_symbol_set_owner (sym, self);
260 }
261
262 void
vala_scope_remove(ValaScope * self,const gchar * name)263 vala_scope_remove (ValaScope* self,
264 const gchar* name)
265 {
266 ValaMap* _tmp0_;
267 g_return_if_fail (self != NULL);
268 g_return_if_fail (name != NULL);
269 _tmp0_ = self->priv->symbol_table;
270 vala_map_remove (_tmp0_, name);
271 }
272
273 /**
274 * Returns the symbol stored in the symbol table with the specified
275 * name.
276 *
277 * @param name name of the symbol to be returned
278 * @return found symbol or null
279 */
280 ValaSymbol*
vala_scope_lookup(ValaScope * self,const gchar * name)281 vala_scope_lookup (ValaScope* self,
282 const gchar* name)
283 {
284 ValaMap* _tmp0_;
285 ValaSymbol* sym = NULL;
286 ValaMap* _tmp1_;
287 gpointer _tmp2_;
288 gboolean _tmp3_ = FALSE;
289 ValaSymbol* _tmp4_;
290 ValaSymbol* result = NULL;
291 g_return_val_if_fail (self != NULL, NULL);
292 g_return_val_if_fail (name != NULL, NULL);
293 _tmp0_ = self->priv->symbol_table;
294 if (_tmp0_ == NULL) {
295 result = NULL;
296 return result;
297 }
298 _tmp1_ = self->priv->symbol_table;
299 _tmp2_ = vala_map_get (_tmp1_, name);
300 sym = (ValaSymbol*) _tmp2_;
301 _tmp4_ = sym;
302 if (_tmp4_ != NULL) {
303 ValaSymbol* _tmp5_;
304 gboolean _tmp6_;
305 gboolean _tmp7_;
306 _tmp5_ = sym;
307 _tmp6_ = vala_symbol_get_active (_tmp5_);
308 _tmp7_ = _tmp6_;
309 _tmp3_ = !_tmp7_;
310 } else {
311 _tmp3_ = FALSE;
312 }
313 if (_tmp3_) {
314 _vala_code_node_unref0 (sym);
315 sym = NULL;
316 }
317 result = sym;
318 return result;
319 }
320
321 /**
322 * Returns whether the specified scope is an ancestor of this scope.
323 *
324 * @param scope a scope or null for the root scope
325 * @return true if this scope is a subscope of the specified
326 * scope, false otherwise
327 */
328 gboolean
vala_scope_is_subscope_of(ValaScope * self,ValaScope * scope)329 vala_scope_is_subscope_of (ValaScope* self,
330 ValaScope* scope)
331 {
332 ValaScope* _tmp0_;
333 gboolean result = FALSE;
334 g_return_val_if_fail (self != NULL, FALSE);
335 if (scope == self) {
336 result = TRUE;
337 return result;
338 }
339 if (scope == NULL) {
340 result = TRUE;
341 return result;
342 }
343 _tmp0_ = self->priv->_parent_scope;
344 if (_tmp0_ != NULL) {
345 ValaScope* _tmp1_;
346 _tmp1_ = self->priv->_parent_scope;
347 result = vala_scope_is_subscope_of (_tmp1_, scope);
348 return result;
349 }
350 result = FALSE;
351 return result;
352 }
353
354 ValaMap*
vala_scope_get_symbol_table(ValaScope * self)355 vala_scope_get_symbol_table (ValaScope* self)
356 {
357 ValaMap* _tmp0_;
358 ValaMap* result = NULL;
359 g_return_val_if_fail (self != NULL, NULL);
360 _tmp0_ = self->priv->symbol_table;
361 result = _tmp0_;
362 return result;
363 }
364
365 static void
vala_value_scope_init(GValue * value)366 vala_value_scope_init (GValue* value)
367 {
368 value->data[0].v_pointer = NULL;
369 }
370
371 static void
vala_value_scope_free_value(GValue * value)372 vala_value_scope_free_value (GValue* value)
373 {
374 if (value->data[0].v_pointer) {
375 vala_scope_unref (value->data[0].v_pointer);
376 }
377 }
378
379 static void
vala_value_scope_copy_value(const GValue * src_value,GValue * dest_value)380 vala_value_scope_copy_value (const GValue* src_value,
381 GValue* dest_value)
382 {
383 if (src_value->data[0].v_pointer) {
384 dest_value->data[0].v_pointer = vala_scope_ref (src_value->data[0].v_pointer);
385 } else {
386 dest_value->data[0].v_pointer = NULL;
387 }
388 }
389
390 static gpointer
vala_value_scope_peek_pointer(const GValue * value)391 vala_value_scope_peek_pointer (const GValue* value)
392 {
393 return value->data[0].v_pointer;
394 }
395
396 static gchar*
vala_value_scope_collect_value(GValue * value,guint n_collect_values,GTypeCValue * collect_values,guint collect_flags)397 vala_value_scope_collect_value (GValue* value,
398 guint n_collect_values,
399 GTypeCValue* collect_values,
400 guint collect_flags)
401 {
402 if (collect_values[0].v_pointer) {
403 ValaScope * object;
404 object = collect_values[0].v_pointer;
405 if (object->parent_instance.g_class == NULL) {
406 return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
407 } else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
408 return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
409 }
410 value->data[0].v_pointer = vala_scope_ref (object);
411 } else {
412 value->data[0].v_pointer = NULL;
413 }
414 return NULL;
415 }
416
417 static gchar*
vala_value_scope_lcopy_value(const GValue * value,guint n_collect_values,GTypeCValue * collect_values,guint collect_flags)418 vala_value_scope_lcopy_value (const GValue* value,
419 guint n_collect_values,
420 GTypeCValue* collect_values,
421 guint collect_flags)
422 {
423 ValaScope ** object_p;
424 object_p = collect_values[0].v_pointer;
425 if (!object_p) {
426 return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
427 }
428 if (!value->data[0].v_pointer) {
429 *object_p = NULL;
430 } else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
431 *object_p = value->data[0].v_pointer;
432 } else {
433 *object_p = vala_scope_ref (value->data[0].v_pointer);
434 }
435 return NULL;
436 }
437
438 GParamSpec*
vala_param_spec_scope(const gchar * name,const gchar * nick,const gchar * blurb,GType object_type,GParamFlags flags)439 vala_param_spec_scope (const gchar* name,
440 const gchar* nick,
441 const gchar* blurb,
442 GType object_type,
443 GParamFlags flags)
444 {
445 ValaParamSpecScope* spec;
446 g_return_val_if_fail (g_type_is_a (object_type, VALA_TYPE_SCOPE), NULL);
447 spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
448 G_PARAM_SPEC (spec)->value_type = object_type;
449 return G_PARAM_SPEC (spec);
450 }
451
452 gpointer
vala_value_get_scope(const GValue * value)453 vala_value_get_scope (const GValue* value)
454 {
455 g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_SCOPE), NULL);
456 return value->data[0].v_pointer;
457 }
458
459 void
vala_value_set_scope(GValue * value,gpointer v_object)460 vala_value_set_scope (GValue* value,
461 gpointer v_object)
462 {
463 ValaScope * old;
464 g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_SCOPE));
465 old = value->data[0].v_pointer;
466 if (v_object) {
467 g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, VALA_TYPE_SCOPE));
468 g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
469 value->data[0].v_pointer = v_object;
470 vala_scope_ref (value->data[0].v_pointer);
471 } else {
472 value->data[0].v_pointer = NULL;
473 }
474 if (old) {
475 vala_scope_unref (old);
476 }
477 }
478
479 void
vala_value_take_scope(GValue * value,gpointer v_object)480 vala_value_take_scope (GValue* value,
481 gpointer v_object)
482 {
483 ValaScope * old;
484 g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_SCOPE));
485 old = value->data[0].v_pointer;
486 if (v_object) {
487 g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, VALA_TYPE_SCOPE));
488 g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
489 value->data[0].v_pointer = v_object;
490 } else {
491 value->data[0].v_pointer = NULL;
492 }
493 if (old) {
494 vala_scope_unref (old);
495 }
496 }
497
498 static void
vala_scope_class_init(ValaScopeClass * klass,gpointer klass_data)499 vala_scope_class_init (ValaScopeClass * klass,
500 gpointer klass_data)
501 {
502 vala_scope_parent_class = g_type_class_peek_parent (klass);
503 ((ValaScopeClass *) klass)->finalize = vala_scope_finalize;
504 g_type_class_adjust_private_offset (klass, &ValaScope_private_offset);
505 }
506
507 static void
vala_scope_instance_init(ValaScope * self,gpointer klass)508 vala_scope_instance_init (ValaScope * self,
509 gpointer klass)
510 {
511 self->priv = vala_scope_get_instance_private (self);
512 self->ref_count = 1;
513 }
514
515 static void
vala_scope_finalize(ValaScope * obj)516 vala_scope_finalize (ValaScope * obj)
517 {
518 ValaScope * self;
519 self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_SCOPE, ValaScope);
520 g_signal_handlers_destroy (self);
521 _vala_map_unref0 (self->priv->symbol_table);
522 _vala_iterable_unref0 (self->priv->anonymous_members);
523 }
524
525 /**
526 * Represents a part of the symbol tree.
527 */
528 static GType
vala_scope_get_type_once(void)529 vala_scope_get_type_once (void)
530 {
531 static const GTypeValueTable g_define_type_value_table = { vala_value_scope_init, vala_value_scope_free_value, vala_value_scope_copy_value, vala_value_scope_peek_pointer, "p", vala_value_scope_collect_value, "p", vala_value_scope_lcopy_value };
532 static const GTypeInfo g_define_type_info = { sizeof (ValaScopeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_scope_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaScope), 0, (GInstanceInitFunc) vala_scope_instance_init, &g_define_type_value_table };
533 static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
534 GType vala_scope_type_id;
535 vala_scope_type_id = g_type_register_fundamental (g_type_fundamental_next (), "ValaScope", &g_define_type_info, &g_define_type_fundamental_info, 0);
536 ValaScope_private_offset = g_type_add_instance_private (vala_scope_type_id, sizeof (ValaScopePrivate));
537 return vala_scope_type_id;
538 }
539
540 GType
vala_scope_get_type(void)541 vala_scope_get_type (void)
542 {
543 static volatile gsize vala_scope_type_id__volatile = 0;
544 if (g_once_init_enter (&vala_scope_type_id__volatile)) {
545 GType vala_scope_type_id;
546 vala_scope_type_id = vala_scope_get_type_once ();
547 g_once_init_leave (&vala_scope_type_id__volatile, vala_scope_type_id);
548 }
549 return vala_scope_type_id__volatile;
550 }
551
552 gpointer
vala_scope_ref(gpointer instance)553 vala_scope_ref (gpointer instance)
554 {
555 ValaScope * self;
556 self = instance;
557 g_atomic_int_inc (&self->ref_count);
558 return instance;
559 }
560
561 void
vala_scope_unref(gpointer instance)562 vala_scope_unref (gpointer instance)
563 {
564 ValaScope * self;
565 self = instance;
566 if (g_atomic_int_dec_and_test (&self->ref_count)) {
567 VALA_SCOPE_GET_CLASS (self)->finalize (self);
568 g_type_free_instance ((GTypeInstance *) self);
569 }
570 }
571
572