1 /* valacodenode.c generated by valac, the Vala compiler
2 * generated from valacodenode.vala, do not modify */
3
4 /* valacodenode.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 <glib.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <valagee.h>
31 #include <glib-object.h>
32 #include <float.h>
33 #include <math.h>
34 #include <gobject/gvaluecollector.h>
35
36 #define _vala_source_reference_unref0(var) ((var == NULL) ? NULL : (var = (vala_source_reference_unref (var), NULL)))
37 #define _vala_iterable_unref0(var) ((var == NULL) ? NULL : (var = (vala_iterable_unref (var), NULL)))
38 #define _vala_code_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_node_unref (var), NULL)))
39 #define _g_free0(var) (var = (g_free (var), NULL))
40 #define _vala_attribute_cache_unref0(var) ((var == NULL) ? NULL : (var = (vala_attribute_cache_unref (var), NULL)))
41 #define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
42 typedef struct _ValaParamSpecCodeNode ValaParamSpecCodeNode;
43 typedef struct _ValaParamSpecAttributeCache ValaParamSpecAttributeCache;
44
45 struct _ValaCodeNodePrivate {
46 ValaCodeNode* _parent_node;
47 ValaSourceReference* _source_reference;
48 gboolean _unreachable;
49 gboolean _checked;
50 gboolean _error;
51 ValaAttributeCache** attributes_cache;
52 gint attributes_cache_length1;
53 gint _attributes_cache_size_;
54 };
55
56 struct _ValaParamSpecCodeNode {
57 GParamSpec parent_instance;
58 };
59
60 struct _ValaParamSpecAttributeCache {
61 GParamSpec parent_instance;
62 };
63
64 static gint ValaCodeNode_private_offset;
65 static gpointer vala_code_node_parent_class = NULL;
66 static gint vala_code_node_last_temp_nr;
67 static gint vala_code_node_last_temp_nr = 0;
68 static gint vala_code_node_next_attribute_cache_index;
69 static gint vala_code_node_next_attribute_cache_index = 0;
70 static gpointer vala_attribute_cache_parent_class = NULL;
71
72 static void _vala_code_node_unref0_ (gpointer var);
73 static inline void _g_list_free__vala_code_node_unref0_ (GList* self);
74 static void vala_code_node_real_accept (ValaCodeNode* self,
75 ValaCodeVisitor* visitor);
76 static void vala_code_node_real_accept_children (ValaCodeNode* self,
77 ValaCodeVisitor* visitor);
78 static gboolean vala_code_node_real_check (ValaCodeNode* self,
79 ValaCodeContext* context);
80 static void vala_code_node_real_emit (ValaCodeNode* self,
81 ValaCodeGenerator* codegen);
82 static void vala_code_node_real_replace_type (ValaCodeNode* self,
83 ValaDataType* old_type,
84 ValaDataType* new_type);
85 static void vala_code_node_real_replace_expression (ValaCodeNode* self,
86 ValaExpression* old_node,
87 ValaExpression* new_node);
88 static ValaAttribute* vala_code_node_get_or_create_attribute (ValaCodeNode* self,
89 const gchar* name);
90 static gchar* vala_code_node_real_to_string (ValaCodeNode* self);
91 static void vala_code_node_real_get_defined_variables (ValaCodeNode* self,
92 ValaCollection* collection);
93 static void vala_code_node_real_get_used_variables (ValaCodeNode* self,
94 ValaCollection* collection);
95 static void vala_code_node_real_get_error_types (ValaCodeNode* self,
96 ValaCollection* collection,
97 ValaSourceReference* source_reference);
98 static void vala_code_node_finalize (ValaCodeNode * obj);
99 static GType vala_code_node_get_type_once (void);
100 static void vala_attribute_cache_finalize (ValaAttributeCache * obj);
101 static GType vala_attribute_cache_get_type_once (void);
102 static void _vala_array_destroy (gpointer array,
103 gint array_length,
104 GDestroyNotify destroy_func);
105 static void _vala_array_free (gpointer array,
106 gint array_length,
107 GDestroyNotify destroy_func);
108
109 static inline gpointer
vala_code_node_get_instance_private(ValaCodeNode * self)110 vala_code_node_get_instance_private (ValaCodeNode* self)
111 {
112 return G_STRUCT_MEMBER_P (self, ValaCodeNode_private_offset);
113 }
114
115 ValaCodeNode*
vala_code_node_get_parent_node(ValaCodeNode * self)116 vala_code_node_get_parent_node (ValaCodeNode* self)
117 {
118 ValaCodeNode* result;
119 ValaCodeNode* _tmp0_;
120 g_return_val_if_fail (self != NULL, NULL);
121 _tmp0_ = self->priv->_parent_node;
122 result = _tmp0_;
123 return result;
124 }
125
126 void
vala_code_node_set_parent_node(ValaCodeNode * self,ValaCodeNode * value)127 vala_code_node_set_parent_node (ValaCodeNode* self,
128 ValaCodeNode* value)
129 {
130 g_return_if_fail (self != NULL);
131 self->priv->_parent_node = value;
132 }
133
134 ValaSourceReference*
vala_code_node_get_source_reference(ValaCodeNode * self)135 vala_code_node_get_source_reference (ValaCodeNode* self)
136 {
137 ValaSourceReference* result;
138 ValaSourceReference* _tmp0_;
139 g_return_val_if_fail (self != NULL, NULL);
140 _tmp0_ = self->priv->_source_reference;
141 result = _tmp0_;
142 return result;
143 }
144
145 static gpointer
_vala_source_reference_ref0(gpointer self)146 _vala_source_reference_ref0 (gpointer self)
147 {
148 return self ? vala_source_reference_ref (self) : NULL;
149 }
150
151 void
vala_code_node_set_source_reference(ValaCodeNode * self,ValaSourceReference * value)152 vala_code_node_set_source_reference (ValaCodeNode* self,
153 ValaSourceReference* value)
154 {
155 ValaSourceReference* _tmp0_;
156 g_return_if_fail (self != NULL);
157 _tmp0_ = _vala_source_reference_ref0 (value);
158 _vala_source_reference_unref0 (self->priv->_source_reference);
159 self->priv->_source_reference = _tmp0_;
160 }
161
162 gboolean
vala_code_node_get_unreachable(ValaCodeNode * self)163 vala_code_node_get_unreachable (ValaCodeNode* self)
164 {
165 gboolean result;
166 g_return_val_if_fail (self != NULL, FALSE);
167 result = self->priv->_unreachable;
168 return result;
169 }
170
171 void
vala_code_node_set_unreachable(ValaCodeNode * self,gboolean value)172 vala_code_node_set_unreachable (ValaCodeNode* self,
173 gboolean value)
174 {
175 g_return_if_fail (self != NULL);
176 self->priv->_unreachable = value;
177 }
178
179 static void
_vala_code_node_unref0_(gpointer var)180 _vala_code_node_unref0_ (gpointer var)
181 {
182 (var == NULL) ? NULL : (var = (vala_code_node_unref (var), NULL));
183 }
184
185 static inline void
_g_list_free__vala_code_node_unref0_(GList * self)186 _g_list_free__vala_code_node_unref0_ (GList* self)
187 {
188 g_list_free_full (self, (GDestroyNotify) _vala_code_node_unref0_);
189 }
190
191 const gchar*
vala_code_node_get_type_name(ValaCodeNode * self)192 vala_code_node_get_type_name (ValaCodeNode* self)
193 {
194 const gchar* result;
195 const gchar* _tmp0_;
196 g_return_val_if_fail (self != NULL, NULL);
197 _tmp0_ = g_type_name (G_TYPE_FROM_INSTANCE (self));
198 result = _tmp0_;
199 return result;
200 }
201
202 gboolean
vala_code_node_get_checked(ValaCodeNode * self)203 vala_code_node_get_checked (ValaCodeNode* self)
204 {
205 gboolean result;
206 g_return_val_if_fail (self != NULL, FALSE);
207 result = self->priv->_checked;
208 return result;
209 }
210
211 void
vala_code_node_set_checked(ValaCodeNode * self,gboolean value)212 vala_code_node_set_checked (ValaCodeNode* self,
213 gboolean value)
214 {
215 g_return_if_fail (self != NULL);
216 self->priv->_checked = value;
217 }
218
219 gboolean
vala_code_node_get_error(ValaCodeNode * self)220 vala_code_node_get_error (ValaCodeNode* self)
221 {
222 gboolean result;
223 g_return_val_if_fail (self != NULL, FALSE);
224 result = self->priv->_error;
225 return result;
226 }
227
228 void
vala_code_node_set_error(ValaCodeNode * self,gboolean value)229 vala_code_node_set_error (ValaCodeNode* self,
230 gboolean value)
231 {
232 g_return_if_fail (self != NULL);
233 self->priv->_error = value;
234 }
235
236 gboolean
vala_code_node_get_tree_can_fail(ValaCodeNode * self)237 vala_code_node_get_tree_can_fail (ValaCodeNode* self)
238 {
239 gboolean result;
240 ValaArrayList* error_types = NULL;
241 GEqualFunc _tmp0_;
242 ValaArrayList* _tmp1_;
243 gint _tmp2_;
244 gint _tmp3_;
245 g_return_val_if_fail (self != NULL, FALSE);
246 _tmp0_ = g_direct_equal;
247 _tmp1_ = vala_array_list_new (VALA_TYPE_DATA_TYPE, (GBoxedCopyFunc) vala_code_node_ref, (GDestroyNotify) vala_code_node_unref, _tmp0_);
248 error_types = _tmp1_;
249 vala_code_node_get_error_types (self, (ValaCollection*) error_types, NULL);
250 _tmp2_ = vala_collection_get_size ((ValaCollection*) error_types);
251 _tmp3_ = _tmp2_;
252 result = _tmp3_ > 0;
253 _vala_iterable_unref0 (error_types);
254 return result;
255 }
256
257 /**
258 * Visits this code node with the specified CodeVisitor.
259 *
260 * @param visitor the visitor to be called while traversing
261 */
262 static void
vala_code_node_real_accept(ValaCodeNode * self,ValaCodeVisitor * visitor)263 vala_code_node_real_accept (ValaCodeNode* self,
264 ValaCodeVisitor* visitor)
265 {
266 g_return_if_fail (visitor != NULL);
267 }
268
269 void
vala_code_node_accept(ValaCodeNode * self,ValaCodeVisitor * visitor)270 vala_code_node_accept (ValaCodeNode* self,
271 ValaCodeVisitor* visitor)
272 {
273 g_return_if_fail (self != NULL);
274 VALA_CODE_NODE_GET_CLASS (self)->accept (self, visitor);
275 }
276
277 /**
278 * Visits all children of this code node with the specified CodeVisitor.
279 *
280 * @param visitor the visitor to be called while traversing
281 */
282 static void
vala_code_node_real_accept_children(ValaCodeNode * self,ValaCodeVisitor * visitor)283 vala_code_node_real_accept_children (ValaCodeNode* self,
284 ValaCodeVisitor* visitor)
285 {
286 g_return_if_fail (visitor != NULL);
287 }
288
289 void
vala_code_node_accept_children(ValaCodeNode * self,ValaCodeVisitor * visitor)290 vala_code_node_accept_children (ValaCodeNode* self,
291 ValaCodeVisitor* visitor)
292 {
293 g_return_if_fail (self != NULL);
294 VALA_CODE_NODE_GET_CLASS (self)->accept_children (self, visitor);
295 }
296
297 static gboolean
vala_code_node_real_check(ValaCodeNode * self,ValaCodeContext * context)298 vala_code_node_real_check (ValaCodeNode* self,
299 ValaCodeContext* context)
300 {
301 gboolean result = FALSE;
302 g_return_val_if_fail (context != NULL, FALSE);
303 result = TRUE;
304 return result;
305 }
306
307 gboolean
vala_code_node_check(ValaCodeNode * self,ValaCodeContext * context)308 vala_code_node_check (ValaCodeNode* self,
309 ValaCodeContext* context)
310 {
311 g_return_val_if_fail (self != NULL, FALSE);
312 return VALA_CODE_NODE_GET_CLASS (self)->check (self, context);
313 }
314
315 static void
vala_code_node_real_emit(ValaCodeNode * self,ValaCodeGenerator * codegen)316 vala_code_node_real_emit (ValaCodeNode* self,
317 ValaCodeGenerator* codegen)
318 {
319 g_return_if_fail (codegen != NULL);
320 }
321
322 void
vala_code_node_emit(ValaCodeNode * self,ValaCodeGenerator * codegen)323 vala_code_node_emit (ValaCodeNode* self,
324 ValaCodeGenerator* codegen)
325 {
326 g_return_if_fail (self != NULL);
327 VALA_CODE_NODE_GET_CLASS (self)->emit (self, codegen);
328 }
329
330 static void
vala_code_node_real_replace_type(ValaCodeNode * self,ValaDataType * old_type,ValaDataType * new_type)331 vala_code_node_real_replace_type (ValaCodeNode* self,
332 ValaDataType* old_type,
333 ValaDataType* new_type)
334 {
335 g_return_if_fail (old_type != NULL);
336 g_return_if_fail (new_type != NULL);
337 }
338
339 void
vala_code_node_replace_type(ValaCodeNode * self,ValaDataType * old_type,ValaDataType * new_type)340 vala_code_node_replace_type (ValaCodeNode* self,
341 ValaDataType* old_type,
342 ValaDataType* new_type)
343 {
344 g_return_if_fail (self != NULL);
345 VALA_CODE_NODE_GET_CLASS (self)->replace_type (self, old_type, new_type);
346 }
347
348 static void
vala_code_node_real_replace_expression(ValaCodeNode * self,ValaExpression * old_node,ValaExpression * new_node)349 vala_code_node_real_replace_expression (ValaCodeNode* self,
350 ValaExpression* old_node,
351 ValaExpression* new_node)
352 {
353 g_return_if_fail (old_node != NULL);
354 g_return_if_fail (new_node != NULL);
355 }
356
357 void
vala_code_node_replace_expression(ValaCodeNode * self,ValaExpression * old_node,ValaExpression * new_node)358 vala_code_node_replace_expression (ValaCodeNode* self,
359 ValaExpression* old_node,
360 ValaExpression* new_node)
361 {
362 g_return_if_fail (self != NULL);
363 VALA_CODE_NODE_GET_CLASS (self)->replace_expression (self, old_node, new_node);
364 }
365
366 /**
367 * Returns the specified attribute.
368 *
369 * @param name attribute name
370 * @return attribute
371 */
372 ValaAttribute*
vala_code_node_get_attribute(ValaCodeNode * self,const gchar * name)373 vala_code_node_get_attribute (ValaCodeNode* self,
374 const gchar* name)
375 {
376 GList* _tmp0_;
377 ValaAttribute* result = NULL;
378 g_return_val_if_fail (self != NULL, NULL);
379 g_return_val_if_fail (name != NULL, NULL);
380 _tmp0_ = self->attributes;
381 {
382 GList* a_collection = NULL;
383 GList* a_it = NULL;
384 a_collection = _tmp0_;
385 for (a_it = a_collection; a_it != NULL; a_it = a_it->next) {
386 ValaAttribute* a = NULL;
387 a = (ValaAttribute*) a_it->data;
388 {
389 ValaAttribute* _tmp1_;
390 const gchar* _tmp2_;
391 const gchar* _tmp3_;
392 _tmp1_ = a;
393 _tmp2_ = vala_attribute_get_name (_tmp1_);
394 _tmp3_ = _tmp2_;
395 if (g_strcmp0 (_tmp3_, name) == 0) {
396 ValaAttribute* _tmp4_;
397 _tmp4_ = a;
398 result = _tmp4_;
399 return result;
400 }
401 }
402 }
403 }
404 result = NULL;
405 return result;
406 }
407
408 static gpointer
_vala_code_node_ref0(gpointer self)409 _vala_code_node_ref0 (gpointer self)
410 {
411 return self ? vala_code_node_ref (self) : NULL;
412 }
413
414 static ValaAttribute*
vala_code_node_get_or_create_attribute(ValaCodeNode * self,const gchar * name)415 vala_code_node_get_or_create_attribute (ValaCodeNode* self,
416 const gchar* name)
417 {
418 ValaAttribute* a = NULL;
419 ValaAttribute* _tmp0_;
420 ValaAttribute* _tmp1_;
421 ValaAttribute* _tmp7_;
422 ValaAttribute* result = NULL;
423 g_return_val_if_fail (self != NULL, NULL);
424 g_return_val_if_fail (name != NULL, NULL);
425 _tmp0_ = vala_code_node_get_attribute (self, name);
426 a = _tmp0_;
427 _tmp1_ = a;
428 if (_tmp1_ == NULL) {
429 ValaAttribute* new_a = NULL;
430 ValaSourceReference* _tmp2_;
431 ValaAttribute* _tmp3_;
432 ValaAttribute* _tmp4_;
433 ValaAttribute* _tmp5_;
434 ValaAttribute* _tmp6_;
435 _tmp2_ = self->priv->_source_reference;
436 _tmp3_ = vala_attribute_new (name, _tmp2_);
437 new_a = _tmp3_;
438 _tmp4_ = new_a;
439 _tmp5_ = _vala_code_node_ref0 (_tmp4_);
440 self->attributes = g_list_append (self->attributes, _tmp5_);
441 _tmp6_ = new_a;
442 a = _tmp6_;
443 _vala_code_node_unref0 (new_a);
444 }
445 _tmp7_ = a;
446 result = G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, VALA_TYPE_ATTRIBUTE, ValaAttribute);
447 return result;
448 }
449
450 /**
451 * Returns true if the specified attribute argument is set.
452 *
453 * @param attribute attribute name
454 * @param argument argument name
455 * @return true if the attribute has the given argument
456 */
457 gboolean
vala_code_node_has_attribute_argument(ValaCodeNode * self,const gchar * attribute,const gchar * argument)458 vala_code_node_has_attribute_argument (ValaCodeNode* self,
459 const gchar* attribute,
460 const gchar* argument)
461 {
462 ValaAttribute* a = NULL;
463 ValaAttribute* _tmp0_;
464 ValaAttribute* _tmp1_;
465 ValaAttribute* _tmp2_;
466 gboolean result = FALSE;
467 g_return_val_if_fail (self != NULL, FALSE);
468 g_return_val_if_fail (attribute != NULL, FALSE);
469 g_return_val_if_fail (argument != NULL, FALSE);
470 _tmp0_ = vala_code_node_get_attribute (self, attribute);
471 a = _tmp0_;
472 _tmp1_ = a;
473 if (_tmp1_ == NULL) {
474 result = FALSE;
475 return result;
476 }
477 _tmp2_ = a;
478 result = vala_attribute_has_argument (_tmp2_, argument);
479 return result;
480 }
481
482 /**
483 * Sets the specified named attribute to this code node.
484 *
485 * @param name attribute name
486 * @param value true to add the attribute, false to remove it
487 */
488 void
vala_code_node_set_attribute(ValaCodeNode * self,const gchar * name,gboolean value,ValaSourceReference * source_reference)489 vala_code_node_set_attribute (ValaCodeNode* self,
490 const gchar* name,
491 gboolean value,
492 ValaSourceReference* source_reference)
493 {
494 ValaAttribute* a = NULL;
495 ValaAttribute* _tmp0_;
496 gboolean _tmp1_ = FALSE;
497 g_return_if_fail (self != NULL);
498 g_return_if_fail (name != NULL);
499 _tmp0_ = vala_code_node_get_attribute (self, name);
500 a = _tmp0_;
501 if (value) {
502 ValaAttribute* _tmp2_;
503 _tmp2_ = a;
504 _tmp1_ = _tmp2_ == NULL;
505 } else {
506 _tmp1_ = FALSE;
507 }
508 if (_tmp1_) {
509 ValaAttribute* _tmp3_;
510 _tmp3_ = vala_attribute_new (name, source_reference);
511 self->attributes = g_list_append (self->attributes, _tmp3_);
512 } else {
513 gboolean _tmp4_ = FALSE;
514 if (!value) {
515 ValaAttribute* _tmp5_;
516 _tmp5_ = a;
517 _tmp4_ = _tmp5_ != NULL;
518 } else {
519 _tmp4_ = FALSE;
520 }
521 if (_tmp4_) {
522 ValaAttribute* _tmp6_;
523 _tmp6_ = a;
524 self->attributes = g_list_remove (self->attributes, _tmp6_);
525 }
526 }
527 }
528
529 /**
530 * Remove the specified named attribute argument
531 *
532 * @param attribute attribute name
533 * @param argument argument name
534 */
535 void
vala_code_node_remove_attribute_argument(ValaCodeNode * self,const gchar * attribute,const gchar * argument)536 vala_code_node_remove_attribute_argument (ValaCodeNode* self,
537 const gchar* attribute,
538 const gchar* argument)
539 {
540 ValaAttribute* a = NULL;
541 ValaAttribute* _tmp0_;
542 ValaAttribute* _tmp1_;
543 g_return_if_fail (self != NULL);
544 g_return_if_fail (attribute != NULL);
545 g_return_if_fail (argument != NULL);
546 _tmp0_ = vala_code_node_get_attribute (self, attribute);
547 a = _tmp0_;
548 _tmp1_ = a;
549 if (_tmp1_ != NULL) {
550 ValaAttribute* _tmp2_;
551 ValaMap* _tmp3_;
552 ValaMap* _tmp4_;
553 ValaAttribute* _tmp5_;
554 ValaMap* _tmp6_;
555 ValaMap* _tmp7_;
556 gint _tmp8_;
557 gint _tmp9_;
558 _tmp2_ = a;
559 _tmp3_ = vala_attribute_get_args (_tmp2_);
560 _tmp4_ = _tmp3_;
561 vala_map_remove (_tmp4_, argument);
562 _tmp5_ = a;
563 _tmp6_ = vala_attribute_get_args (_tmp5_);
564 _tmp7_ = _tmp6_;
565 _tmp8_ = vala_map_get_size (_tmp7_);
566 _tmp9_ = _tmp8_;
567 if (_tmp9_ == 0) {
568 ValaAttribute* _tmp10_;
569 _tmp10_ = a;
570 self->attributes = g_list_remove (self->attributes, _tmp10_);
571 }
572 }
573 }
574
575 /**
576 * Returns the string value of the specified attribute argument.
577 *
578 * @param attribute attribute name
579 * @param argument argument name
580 * @return string value
581 */
582 gchar*
vala_code_node_get_attribute_string(ValaCodeNode * self,const gchar * attribute,const gchar * argument,const gchar * default_value)583 vala_code_node_get_attribute_string (ValaCodeNode* self,
584 const gchar* attribute,
585 const gchar* argument,
586 const gchar* default_value)
587 {
588 ValaAttribute* a = NULL;
589 ValaAttribute* _tmp0_;
590 ValaAttribute* _tmp1_;
591 ValaAttribute* _tmp3_;
592 gchar* _tmp4_;
593 gchar* result = NULL;
594 g_return_val_if_fail (self != NULL, NULL);
595 g_return_val_if_fail (attribute != NULL, NULL);
596 g_return_val_if_fail (argument != NULL, NULL);
597 _tmp0_ = vala_code_node_get_attribute (self, attribute);
598 a = _tmp0_;
599 _tmp1_ = a;
600 if (_tmp1_ == NULL) {
601 gchar* _tmp2_;
602 _tmp2_ = g_strdup (default_value);
603 result = _tmp2_;
604 return result;
605 }
606 _tmp3_ = a;
607 _tmp4_ = vala_attribute_get_string (_tmp3_, argument, default_value);
608 result = _tmp4_;
609 return result;
610 }
611
612 /**
613 * Returns the integer value of the specified attribute argument.
614 *
615 * @param attribute attribute name
616 * @param argument argument name
617 * @return integer value
618 */
619 gint
vala_code_node_get_attribute_integer(ValaCodeNode * self,const gchar * attribute,const gchar * argument,gint default_value)620 vala_code_node_get_attribute_integer (ValaCodeNode* self,
621 const gchar* attribute,
622 const gchar* argument,
623 gint default_value)
624 {
625 ValaAttribute* a = NULL;
626 ValaAttribute* _tmp0_;
627 ValaAttribute* _tmp1_;
628 ValaAttribute* _tmp2_;
629 gint result = 0;
630 g_return_val_if_fail (self != NULL, 0);
631 g_return_val_if_fail (attribute != NULL, 0);
632 g_return_val_if_fail (argument != NULL, 0);
633 _tmp0_ = vala_code_node_get_attribute (self, attribute);
634 a = _tmp0_;
635 _tmp1_ = a;
636 if (_tmp1_ == NULL) {
637 result = default_value;
638 return result;
639 }
640 _tmp2_ = a;
641 result = vala_attribute_get_integer (_tmp2_, argument, default_value);
642 return result;
643 }
644
645 /**
646 * Returns the double value of the specified attribute argument.
647 *
648 * @param attribute attribute name
649 * @param argument argument name
650 * @return double value
651 */
652 gdouble
vala_code_node_get_attribute_double(ValaCodeNode * self,const gchar * attribute,const gchar * argument,gdouble default_value)653 vala_code_node_get_attribute_double (ValaCodeNode* self,
654 const gchar* attribute,
655 const gchar* argument,
656 gdouble default_value)
657 {
658 GList* _tmp0_;
659 ValaAttribute* a = NULL;
660 ValaAttribute* _tmp1_;
661 ValaAttribute* _tmp2_;
662 ValaAttribute* _tmp3_;
663 gdouble result = 0.0;
664 g_return_val_if_fail (self != NULL, 0.0);
665 g_return_val_if_fail (attribute != NULL, 0.0);
666 g_return_val_if_fail (argument != NULL, 0.0);
667 _tmp0_ = self->attributes;
668 if (_tmp0_ == NULL) {
669 result = default_value;
670 return result;
671 }
672 _tmp1_ = vala_code_node_get_attribute (self, attribute);
673 a = _tmp1_;
674 _tmp2_ = a;
675 if (_tmp2_ == NULL) {
676 result = default_value;
677 return result;
678 }
679 _tmp3_ = a;
680 result = vala_attribute_get_double (_tmp3_, argument, default_value);
681 return result;
682 }
683
684 /**
685 * Returns the bool value of the specified attribute argument.
686 *
687 * @param attribute attribute name
688 * @param argument argument name
689 * @return bool value
690 */
691 gboolean
vala_code_node_get_attribute_bool(ValaCodeNode * self,const gchar * attribute,const gchar * argument,gboolean default_value)692 vala_code_node_get_attribute_bool (ValaCodeNode* self,
693 const gchar* attribute,
694 const gchar* argument,
695 gboolean default_value)
696 {
697 GList* _tmp0_;
698 ValaAttribute* a = NULL;
699 ValaAttribute* _tmp1_;
700 ValaAttribute* _tmp2_;
701 ValaAttribute* _tmp3_;
702 gboolean result = FALSE;
703 g_return_val_if_fail (self != NULL, FALSE);
704 g_return_val_if_fail (attribute != NULL, FALSE);
705 g_return_val_if_fail (argument != NULL, FALSE);
706 _tmp0_ = self->attributes;
707 if (_tmp0_ == NULL) {
708 result = default_value;
709 return result;
710 }
711 _tmp1_ = vala_code_node_get_attribute (self, attribute);
712 a = _tmp1_;
713 _tmp2_ = a;
714 if (_tmp2_ == NULL) {
715 result = default_value;
716 return result;
717 }
718 _tmp3_ = a;
719 result = vala_attribute_get_bool (_tmp3_, argument, default_value);
720 return result;
721 }
722
723 /**
724 * Sets the string value of the specified attribute argument.
725 *
726 * @param attribute attribute name
727 * @param argument argument name
728 * @param value string value
729 */
730 void
vala_code_node_set_attribute_string(ValaCodeNode * self,const gchar * attribute,const gchar * argument,const gchar * value,ValaSourceReference * source_reference)731 vala_code_node_set_attribute_string (ValaCodeNode* self,
732 const gchar* attribute,
733 const gchar* argument,
734 const gchar* value,
735 ValaSourceReference* source_reference)
736 {
737 ValaAttribute* a = NULL;
738 ValaAttribute* _tmp0_;
739 ValaAttribute* _tmp1_;
740 gchar* _tmp2_;
741 gchar* _tmp3_;
742 g_return_if_fail (self != NULL);
743 g_return_if_fail (attribute != NULL);
744 g_return_if_fail (argument != NULL);
745 if (value == NULL) {
746 vala_code_node_remove_attribute_argument (self, attribute, argument);
747 return;
748 }
749 _tmp0_ = vala_code_node_get_or_create_attribute (self, attribute);
750 a = _tmp0_;
751 _tmp1_ = a;
752 _tmp2_ = g_strdup_printf ("\"%s\"", value);
753 _tmp3_ = _tmp2_;
754 vala_attribute_add_argument (_tmp1_, argument, _tmp3_);
755 _g_free0 (_tmp3_);
756 }
757
758 /**
759 * Sets the integer value of the specified attribute argument.
760 *
761 * @param attribute attribute name
762 * @param argument argument name
763 * @param value integer value
764 */
765 void
vala_code_node_set_attribute_integer(ValaCodeNode * self,const gchar * attribute,const gchar * argument,gint value,ValaSourceReference * source_reference)766 vala_code_node_set_attribute_integer (ValaCodeNode* self,
767 const gchar* attribute,
768 const gchar* argument,
769 gint value,
770 ValaSourceReference* source_reference)
771 {
772 ValaAttribute* a = NULL;
773 ValaAttribute* _tmp0_;
774 gchar* _tmp1_;
775 gchar* _tmp2_;
776 g_return_if_fail (self != NULL);
777 g_return_if_fail (attribute != NULL);
778 g_return_if_fail (argument != NULL);
779 _tmp0_ = vala_code_node_get_or_create_attribute (self, attribute);
780 a = _tmp0_;
781 _tmp1_ = g_strdup_printf ("%i", value);
782 _tmp2_ = _tmp1_;
783 vala_attribute_add_argument (a, argument, _tmp2_);
784 _g_free0 (_tmp2_);
785 }
786
787 /**
788 * Sets the integer value of the specified attribute argument.
789 *
790 * @param attribute attribute name
791 * @param argument argument name
792 * @param value double value
793 */
794 void
vala_code_node_set_attribute_double(ValaCodeNode * self,const gchar * attribute,const gchar * argument,gdouble value,ValaSourceReference * source_reference)795 vala_code_node_set_attribute_double (ValaCodeNode* self,
796 const gchar* attribute,
797 const gchar* argument,
798 gdouble value,
799 ValaSourceReference* source_reference)
800 {
801 ValaAttribute* a = NULL;
802 ValaAttribute* _tmp0_;
803 gchar* _tmp1_;
804 gchar* _tmp2_;
805 gint _tmp2__length1;
806 const gchar* _tmp3_;
807 g_return_if_fail (self != NULL);
808 g_return_if_fail (attribute != NULL);
809 g_return_if_fail (argument != NULL);
810 _tmp0_ = vala_code_node_get_or_create_attribute (self, attribute);
811 a = _tmp0_;
812 _tmp1_ = g_new0 (gchar, G_ASCII_DTOSTR_BUF_SIZE);
813 _tmp2_ = _tmp1_;
814 _tmp2__length1 = G_ASCII_DTOSTR_BUF_SIZE;
815 _tmp3_ = g_ascii_formatd (_tmp2_, (gint) G_ASCII_DTOSTR_BUF_SIZE, "%g", value);
816 vala_attribute_add_argument (a, argument, _tmp3_);
817 _tmp2_ = (g_free (_tmp2_), NULL);
818 }
819
820 /**
821 * Sets the boolean value of the specified attribute argument.
822 *
823 * @param attribute attribute name
824 * @param argument argument name
825 * @param value bool value
826 */
827 static gchar*
bool_to_string(gboolean self)828 bool_to_string (gboolean self)
829 {
830 gchar* result = NULL;
831 if (self) {
832 gchar* _tmp0_;
833 _tmp0_ = g_strdup ("true");
834 result = _tmp0_;
835 return result;
836 } else {
837 gchar* _tmp1_;
838 _tmp1_ = g_strdup ("false");
839 result = _tmp1_;
840 return result;
841 }
842 }
843
844 void
vala_code_node_set_attribute_bool(ValaCodeNode * self,const gchar * attribute,const gchar * argument,gboolean value,ValaSourceReference * source_reference)845 vala_code_node_set_attribute_bool (ValaCodeNode* self,
846 const gchar* attribute,
847 const gchar* argument,
848 gboolean value,
849 ValaSourceReference* source_reference)
850 {
851 ValaAttribute* a = NULL;
852 ValaAttribute* _tmp0_;
853 gchar* _tmp1_;
854 gchar* _tmp2_;
855 g_return_if_fail (self != NULL);
856 g_return_if_fail (attribute != NULL);
857 g_return_if_fail (argument != NULL);
858 _tmp0_ = vala_code_node_get_or_create_attribute (self, attribute);
859 a = _tmp0_;
860 _tmp1_ = bool_to_string (value);
861 _tmp2_ = _tmp1_;
862 vala_attribute_add_argument (a, argument, _tmp2_);
863 _g_free0 (_tmp2_);
864 }
865
866 /**
867 * Copy the string value of the specified attribute argument if available.
868 *
869 * @param source codenode to copy from
870 * @param attribute attribute name
871 * @param argument argument name
872 * @return true if successful
873 */
874 gboolean
vala_code_node_copy_attribute_string(ValaCodeNode * self,ValaCodeNode * source,const gchar * attribute,const gchar * argument)875 vala_code_node_copy_attribute_string (ValaCodeNode* self,
876 ValaCodeNode* source,
877 const gchar* attribute,
878 const gchar* argument)
879 {
880 gboolean result = FALSE;
881 g_return_val_if_fail (self != NULL, FALSE);
882 g_return_val_if_fail (source != NULL, FALSE);
883 g_return_val_if_fail (attribute != NULL, FALSE);
884 g_return_val_if_fail (argument != NULL, FALSE);
885 if (vala_code_node_has_attribute_argument (source, attribute, argument)) {
886 gchar* _tmp0_;
887 gchar* _tmp1_;
888 _tmp0_ = vala_code_node_get_attribute_string (source, attribute, argument, NULL);
889 _tmp1_ = _tmp0_;
890 vala_code_node_set_attribute_string (self, attribute, argument, _tmp1_, NULL);
891 _g_free0 (_tmp1_);
892 result = TRUE;
893 return result;
894 }
895 result = FALSE;
896 return result;
897 }
898
899 /**
900 * Copy the integer value of the specified attribute argument if available.
901 *
902 * @param source codenode to copy from
903 * @param attribute attribute name
904 * @param argument argument name
905 * @return true if successful
906 */
907 gboolean
vala_code_node_copy_attribute_integer(ValaCodeNode * self,ValaCodeNode * source,const gchar * attribute,const gchar * argument)908 vala_code_node_copy_attribute_integer (ValaCodeNode* self,
909 ValaCodeNode* source,
910 const gchar* attribute,
911 const gchar* argument)
912 {
913 gboolean result = FALSE;
914 g_return_val_if_fail (self != NULL, FALSE);
915 g_return_val_if_fail (source != NULL, FALSE);
916 g_return_val_if_fail (attribute != NULL, FALSE);
917 g_return_val_if_fail (argument != NULL, FALSE);
918 if (vala_code_node_has_attribute_argument (source, attribute, argument)) {
919 vala_code_node_set_attribute_integer (self, attribute, argument, vala_code_node_get_attribute_integer (source, attribute, argument, 0), NULL);
920 result = TRUE;
921 return result;
922 }
923 result = FALSE;
924 return result;
925 }
926
927 /**
928 * Copy the double value of the specified attribute argument if available.
929 *
930 * @param source codenode to copy from
931 * @param attribute attribute name
932 * @param argument argument name
933 * @return true if successful
934 */
935 gboolean
vala_code_node_copy_attribute_double(ValaCodeNode * self,ValaCodeNode * source,const gchar * attribute,const gchar * argument)936 vala_code_node_copy_attribute_double (ValaCodeNode* self,
937 ValaCodeNode* source,
938 const gchar* attribute,
939 const gchar* argument)
940 {
941 gboolean result = FALSE;
942 g_return_val_if_fail (self != NULL, FALSE);
943 g_return_val_if_fail (source != NULL, FALSE);
944 g_return_val_if_fail (attribute != NULL, FALSE);
945 g_return_val_if_fail (argument != NULL, FALSE);
946 if (vala_code_node_has_attribute_argument (source, attribute, argument)) {
947 vala_code_node_set_attribute_double (self, attribute, argument, vala_code_node_get_attribute_double (source, attribute, argument, (gdouble) 0), NULL);
948 result = TRUE;
949 return result;
950 }
951 result = FALSE;
952 return result;
953 }
954
955 /**
956 * Copy the boolean value of the specified attribute argument if available.
957 *
958 * @param source codenode to copy from
959 * @param attribute attribute name
960 * @param argument argument name
961 * @return true if successful
962 */
963 gboolean
vala_code_node_copy_attribute_bool(ValaCodeNode * self,ValaCodeNode * source,const gchar * attribute,const gchar * argument)964 vala_code_node_copy_attribute_bool (ValaCodeNode* self,
965 ValaCodeNode* source,
966 const gchar* attribute,
967 const gchar* argument)
968 {
969 gboolean result = FALSE;
970 g_return_val_if_fail (self != NULL, FALSE);
971 g_return_val_if_fail (source != NULL, FALSE);
972 g_return_val_if_fail (attribute != NULL, FALSE);
973 g_return_val_if_fail (argument != NULL, FALSE);
974 if (vala_code_node_has_attribute_argument (source, attribute, argument)) {
975 vala_code_node_set_attribute_bool (self, attribute, argument, vala_code_node_get_attribute_bool (source, attribute, argument, FALSE), NULL);
976 result = TRUE;
977 return result;
978 }
979 result = FALSE;
980 return result;
981 }
982
983 /**
984 * Returns the attribute cache at the specified index.
985 *
986 * @param index attribute cache index
987 * @return attribute cache
988 */
989 ValaAttributeCache*
vala_code_node_get_attribute_cache(ValaCodeNode * self,gint index)990 vala_code_node_get_attribute_cache (ValaCodeNode* self,
991 gint index)
992 {
993 ValaAttributeCache** _tmp0_;
994 gint _tmp0__length1;
995 ValaAttributeCache** _tmp1_;
996 gint _tmp1__length1;
997 ValaAttributeCache* _tmp2_;
998 ValaAttributeCache* result = NULL;
999 g_return_val_if_fail (self != NULL, NULL);
1000 _tmp0_ = self->priv->attributes_cache;
1001 _tmp0__length1 = self->priv->attributes_cache_length1;
1002 if (index >= _tmp0__length1) {
1003 result = NULL;
1004 return result;
1005 }
1006 _tmp1_ = self->priv->attributes_cache;
1007 _tmp1__length1 = self->priv->attributes_cache_length1;
1008 _tmp2_ = _tmp1_[index];
1009 result = _tmp2_;
1010 return result;
1011 }
1012
1013 /**
1014 * Sets the specified attribute cache to this code node.
1015 *
1016 * @param index attribute cache index
1017 * @param cache attribute cache
1018 */
1019 static gpointer
_vala_attribute_cache_ref0(gpointer self)1020 _vala_attribute_cache_ref0 (gpointer self)
1021 {
1022 return self ? vala_attribute_cache_ref (self) : NULL;
1023 }
1024
1025 void
vala_code_node_set_attribute_cache(ValaCodeNode * self,gint index,ValaAttributeCache * cache)1026 vala_code_node_set_attribute_cache (ValaCodeNode* self,
1027 gint index,
1028 ValaAttributeCache* cache)
1029 {
1030 ValaAttributeCache** _tmp0_;
1031 gint _tmp0__length1;
1032 ValaAttributeCache** _tmp2_;
1033 gint _tmp2__length1;
1034 ValaAttributeCache* _tmp3_;
1035 g_return_if_fail (self != NULL);
1036 g_return_if_fail (cache != NULL);
1037 _tmp0_ = self->priv->attributes_cache;
1038 _tmp0__length1 = self->priv->attributes_cache_length1;
1039 if (index >= _tmp0__length1) {
1040 gint _tmp1_;
1041 _tmp1_ = (index * 2) + 1;
1042 self->priv->attributes_cache = g_renew (ValaAttributeCache*, self->priv->attributes_cache, (index * 2) + 1);
1043 (_tmp1_ > self->priv->attributes_cache_length1) ? memset (self->priv->attributes_cache + self->priv->attributes_cache_length1, 0, sizeof (ValaAttributeCache*) * (_tmp1_ - self->priv->attributes_cache_length1)) : NULL;
1044 self->priv->attributes_cache_length1 = _tmp1_;
1045 self->priv->_attributes_cache_size_ = _tmp1_;
1046 }
1047 _tmp2_ = self->priv->attributes_cache;
1048 _tmp2__length1 = self->priv->attributes_cache_length1;
1049 _tmp3_ = _vala_attribute_cache_ref0 (cache);
1050 _vala_attribute_cache_unref0 (_tmp2_[index]);
1051 _tmp2_[index] = _tmp3_;
1052 }
1053
1054 /**
1055 * Returns a string that represents this code node.
1056 *
1057 * @return a string representation
1058 */
1059 static gchar*
vala_code_node_real_to_string(ValaCodeNode * self)1060 vala_code_node_real_to_string (ValaCodeNode* self)
1061 {
1062 GString* str = NULL;
1063 GString* _tmp0_;
1064 GString* _tmp1_;
1065 GString* _tmp2_;
1066 const gchar* _tmp3_;
1067 const gchar* _tmp4_;
1068 ValaSourceReference* _tmp5_;
1069 GString* _tmp11_;
1070 GString* _tmp12_;
1071 const gchar* _tmp13_;
1072 gchar* _tmp14_;
1073 gchar* result = NULL;
1074 _tmp0_ = g_string_new ("");
1075 str = _tmp0_;
1076 _tmp1_ = str;
1077 g_string_append (_tmp1_, "/* ");
1078 _tmp2_ = str;
1079 _tmp3_ = vala_code_node_get_type_name (self);
1080 _tmp4_ = _tmp3_;
1081 g_string_append (_tmp2_, _tmp4_);
1082 _tmp5_ = self->priv->_source_reference;
1083 if (_tmp5_ != NULL) {
1084 GString* _tmp6_;
1085 GString* _tmp7_;
1086 ValaSourceReference* _tmp8_;
1087 gchar* _tmp9_;
1088 gchar* _tmp10_;
1089 _tmp6_ = str;
1090 _tmp7_ = g_string_append (_tmp6_, "@");
1091 _tmp8_ = self->priv->_source_reference;
1092 _tmp9_ = vala_source_reference_to_string (_tmp8_);
1093 _tmp10_ = _tmp9_;
1094 g_string_append (_tmp7_, _tmp10_);
1095 _g_free0 (_tmp10_);
1096 }
1097 _tmp11_ = str;
1098 _tmp12_ = g_string_append (_tmp11_, " */");
1099 _tmp13_ = _tmp12_->str;
1100 _tmp14_ = g_strdup (_tmp13_);
1101 result = _tmp14_;
1102 _g_string_free0 (str);
1103 return result;
1104 }
1105
1106 gchar*
vala_code_node_to_string(ValaCodeNode * self)1107 vala_code_node_to_string (ValaCodeNode* self)
1108 {
1109 g_return_val_if_fail (self != NULL, NULL);
1110 return VALA_CODE_NODE_GET_CLASS (self)->to_string (self);
1111 }
1112
1113 static void
vala_code_node_real_get_defined_variables(ValaCodeNode * self,ValaCollection * collection)1114 vala_code_node_real_get_defined_variables (ValaCodeNode* self,
1115 ValaCollection* collection)
1116 {
1117 g_return_if_fail (collection != NULL);
1118 }
1119
1120 void
vala_code_node_get_defined_variables(ValaCodeNode * self,ValaCollection * collection)1121 vala_code_node_get_defined_variables (ValaCodeNode* self,
1122 ValaCollection* collection)
1123 {
1124 g_return_if_fail (self != NULL);
1125 VALA_CODE_NODE_GET_CLASS (self)->get_defined_variables (self, collection);
1126 }
1127
1128 static void
vala_code_node_real_get_used_variables(ValaCodeNode * self,ValaCollection * collection)1129 vala_code_node_real_get_used_variables (ValaCodeNode* self,
1130 ValaCollection* collection)
1131 {
1132 g_return_if_fail (collection != NULL);
1133 }
1134
1135 void
vala_code_node_get_used_variables(ValaCodeNode * self,ValaCollection * collection)1136 vala_code_node_get_used_variables (ValaCodeNode* self,
1137 ValaCollection* collection)
1138 {
1139 g_return_if_fail (self != NULL);
1140 VALA_CODE_NODE_GET_CLASS (self)->get_used_variables (self, collection);
1141 }
1142
1143 static void
vala_code_node_real_get_error_types(ValaCodeNode * self,ValaCollection * collection,ValaSourceReference * source_reference)1144 vala_code_node_real_get_error_types (ValaCodeNode* self,
1145 ValaCollection* collection,
1146 ValaSourceReference* source_reference)
1147 {
1148 g_return_if_fail (collection != NULL);
1149 }
1150
1151 void
vala_code_node_get_error_types(ValaCodeNode * self,ValaCollection * collection,ValaSourceReference * source_reference)1152 vala_code_node_get_error_types (ValaCodeNode* self,
1153 ValaCollection* collection,
1154 ValaSourceReference* source_reference)
1155 {
1156 g_return_if_fail (self != NULL);
1157 VALA_CODE_NODE_GET_CLASS (self)->get_error_types (self, collection, source_reference);
1158 }
1159
1160 gchar*
vala_code_node_get_temp_name(void)1161 vala_code_node_get_temp_name (void)
1162 {
1163 gint _tmp0_;
1164 gchar* _tmp1_;
1165 gchar* _tmp2_;
1166 gchar* _tmp3_;
1167 gchar* _tmp4_;
1168 gchar* result = NULL;
1169 vala_code_node_last_temp_nr = vala_code_node_last_temp_nr + 1;
1170 _tmp0_ = vala_code_node_last_temp_nr;
1171 _tmp1_ = g_strdup_printf ("%i", _tmp0_);
1172 _tmp2_ = _tmp1_;
1173 _tmp3_ = g_strconcat (".", _tmp2_, NULL);
1174 _tmp4_ = _tmp3_;
1175 _g_free0 (_tmp2_);
1176 result = _tmp4_;
1177 return result;
1178 }
1179
1180 /**
1181 * Returns a new cache index for accessing the attributes cache of code nodes
1182 *
1183 * @return a new cache index
1184 */
1185 gint
vala_code_node_get_attribute_cache_index(void)1186 vala_code_node_get_attribute_cache_index (void)
1187 {
1188 gint _tmp0_;
1189 gint result = 0;
1190 _tmp0_ = vala_code_node_next_attribute_cache_index;
1191 vala_code_node_next_attribute_cache_index = _tmp0_ + 1;
1192 result = _tmp0_;
1193 return result;
1194 }
1195
1196 ValaCodeNode*
vala_code_node_construct(GType object_type)1197 vala_code_node_construct (GType object_type)
1198 {
1199 ValaCodeNode* self = NULL;
1200 self = (ValaCodeNode*) g_type_create_instance (object_type);
1201 return self;
1202 }
1203
1204 static void
vala_value_code_node_init(GValue * value)1205 vala_value_code_node_init (GValue* value)
1206 {
1207 value->data[0].v_pointer = NULL;
1208 }
1209
1210 static void
vala_value_code_node_free_value(GValue * value)1211 vala_value_code_node_free_value (GValue* value)
1212 {
1213 if (value->data[0].v_pointer) {
1214 vala_code_node_unref (value->data[0].v_pointer);
1215 }
1216 }
1217
1218 static void
vala_value_code_node_copy_value(const GValue * src_value,GValue * dest_value)1219 vala_value_code_node_copy_value (const GValue* src_value,
1220 GValue* dest_value)
1221 {
1222 if (src_value->data[0].v_pointer) {
1223 dest_value->data[0].v_pointer = vala_code_node_ref (src_value->data[0].v_pointer);
1224 } else {
1225 dest_value->data[0].v_pointer = NULL;
1226 }
1227 }
1228
1229 static gpointer
vala_value_code_node_peek_pointer(const GValue * value)1230 vala_value_code_node_peek_pointer (const GValue* value)
1231 {
1232 return value->data[0].v_pointer;
1233 }
1234
1235 static gchar*
vala_value_code_node_collect_value(GValue * value,guint n_collect_values,GTypeCValue * collect_values,guint collect_flags)1236 vala_value_code_node_collect_value (GValue* value,
1237 guint n_collect_values,
1238 GTypeCValue* collect_values,
1239 guint collect_flags)
1240 {
1241 if (collect_values[0].v_pointer) {
1242 ValaCodeNode * object;
1243 object = collect_values[0].v_pointer;
1244 if (object->parent_instance.g_class == NULL) {
1245 return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
1246 } else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
1247 return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
1248 }
1249 value->data[0].v_pointer = vala_code_node_ref (object);
1250 } else {
1251 value->data[0].v_pointer = NULL;
1252 }
1253 return NULL;
1254 }
1255
1256 static gchar*
vala_value_code_node_lcopy_value(const GValue * value,guint n_collect_values,GTypeCValue * collect_values,guint collect_flags)1257 vala_value_code_node_lcopy_value (const GValue* value,
1258 guint n_collect_values,
1259 GTypeCValue* collect_values,
1260 guint collect_flags)
1261 {
1262 ValaCodeNode ** object_p;
1263 object_p = collect_values[0].v_pointer;
1264 if (!object_p) {
1265 return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
1266 }
1267 if (!value->data[0].v_pointer) {
1268 *object_p = NULL;
1269 } else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
1270 *object_p = value->data[0].v_pointer;
1271 } else {
1272 *object_p = vala_code_node_ref (value->data[0].v_pointer);
1273 }
1274 return NULL;
1275 }
1276
1277 GParamSpec*
vala_param_spec_code_node(const gchar * name,const gchar * nick,const gchar * blurb,GType object_type,GParamFlags flags)1278 vala_param_spec_code_node (const gchar* name,
1279 const gchar* nick,
1280 const gchar* blurb,
1281 GType object_type,
1282 GParamFlags flags)
1283 {
1284 ValaParamSpecCodeNode* spec;
1285 g_return_val_if_fail (g_type_is_a (object_type, VALA_TYPE_CODE_NODE), NULL);
1286 spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
1287 G_PARAM_SPEC (spec)->value_type = object_type;
1288 return G_PARAM_SPEC (spec);
1289 }
1290
1291 gpointer
vala_value_get_code_node(const GValue * value)1292 vala_value_get_code_node (const GValue* value)
1293 {
1294 g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_CODE_NODE), NULL);
1295 return value->data[0].v_pointer;
1296 }
1297
1298 void
vala_value_set_code_node(GValue * value,gpointer v_object)1299 vala_value_set_code_node (GValue* value,
1300 gpointer v_object)
1301 {
1302 ValaCodeNode * old;
1303 g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_CODE_NODE));
1304 old = value->data[0].v_pointer;
1305 if (v_object) {
1306 g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, VALA_TYPE_CODE_NODE));
1307 g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
1308 value->data[0].v_pointer = v_object;
1309 vala_code_node_ref (value->data[0].v_pointer);
1310 } else {
1311 value->data[0].v_pointer = NULL;
1312 }
1313 if (old) {
1314 vala_code_node_unref (old);
1315 }
1316 }
1317
1318 void
vala_value_take_code_node(GValue * value,gpointer v_object)1319 vala_value_take_code_node (GValue* value,
1320 gpointer v_object)
1321 {
1322 ValaCodeNode * old;
1323 g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_CODE_NODE));
1324 old = value->data[0].v_pointer;
1325 if (v_object) {
1326 g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, VALA_TYPE_CODE_NODE));
1327 g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
1328 value->data[0].v_pointer = v_object;
1329 } else {
1330 value->data[0].v_pointer = NULL;
1331 }
1332 if (old) {
1333 vala_code_node_unref (old);
1334 }
1335 }
1336
1337 static void
vala_code_node_class_init(ValaCodeNodeClass * klass,gpointer klass_data)1338 vala_code_node_class_init (ValaCodeNodeClass * klass,
1339 gpointer klass_data)
1340 {
1341 vala_code_node_parent_class = g_type_class_peek_parent (klass);
1342 ((ValaCodeNodeClass *) klass)->finalize = vala_code_node_finalize;
1343 g_type_class_adjust_private_offset (klass, &ValaCodeNode_private_offset);
1344 ((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_code_node_real_accept;
1345 ((ValaCodeNodeClass *) klass)->accept_children = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_code_node_real_accept_children;
1346 ((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode*, ValaCodeContext*)) vala_code_node_real_check;
1347 ((ValaCodeNodeClass *) klass)->emit = (void (*) (ValaCodeNode*, ValaCodeGenerator*)) vala_code_node_real_emit;
1348 ((ValaCodeNodeClass *) klass)->replace_type = (void (*) (ValaCodeNode*, ValaDataType*, ValaDataType*)) vala_code_node_real_replace_type;
1349 ((ValaCodeNodeClass *) klass)->replace_expression = (void (*) (ValaCodeNode*, ValaExpression*, ValaExpression*)) vala_code_node_real_replace_expression;
1350 ((ValaCodeNodeClass *) klass)->to_string = (gchar* (*) (ValaCodeNode*)) vala_code_node_real_to_string;
1351 ((ValaCodeNodeClass *) klass)->get_defined_variables = (void (*) (ValaCodeNode*, ValaCollection*)) vala_code_node_real_get_defined_variables;
1352 ((ValaCodeNodeClass *) klass)->get_used_variables = (void (*) (ValaCodeNode*, ValaCollection*)) vala_code_node_real_get_used_variables;
1353 ((ValaCodeNodeClass *) klass)->get_error_types = (void (*) (ValaCodeNode*, ValaCollection*, ValaSourceReference*)) vala_code_node_real_get_error_types;
1354 }
1355
1356 static void
vala_code_node_instance_init(ValaCodeNode * self,gpointer klass)1357 vala_code_node_instance_init (ValaCodeNode * self,
1358 gpointer klass)
1359 {
1360 self->priv = vala_code_node_get_instance_private (self);
1361 self->ref_count = 1;
1362 }
1363
1364 static void
vala_code_node_finalize(ValaCodeNode * obj)1365 vala_code_node_finalize (ValaCodeNode * obj)
1366 {
1367 ValaCodeNode * self;
1368 self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_CODE_NODE, ValaCodeNode);
1369 g_signal_handlers_destroy (self);
1370 _vala_source_reference_unref0 (self->priv->_source_reference);
1371 (self->attributes == NULL) ? NULL : (self->attributes = (_g_list_free__vala_code_node_unref0_ (self->attributes), NULL));
1372 self->priv->attributes_cache = (_vala_array_free (self->priv->attributes_cache, self->priv->attributes_cache_length1, (GDestroyNotify) vala_attribute_cache_unref), NULL);
1373 }
1374
1375 /**
1376 * Represents a part of the parsed source code.
1377 *
1378 * Code nodes get created by the parser and are used throughout the whole
1379 * compilation process.
1380 */
1381 static GType
vala_code_node_get_type_once(void)1382 vala_code_node_get_type_once (void)
1383 {
1384 static const GTypeValueTable g_define_type_value_table = { vala_value_code_node_init, vala_value_code_node_free_value, vala_value_code_node_copy_value, vala_value_code_node_peek_pointer, "p", vala_value_code_node_collect_value, "p", vala_value_code_node_lcopy_value };
1385 static const GTypeInfo g_define_type_info = { sizeof (ValaCodeNodeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_code_node_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaCodeNode), 0, (GInstanceInitFunc) vala_code_node_instance_init, &g_define_type_value_table };
1386 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) };
1387 GType vala_code_node_type_id;
1388 vala_code_node_type_id = g_type_register_fundamental (g_type_fundamental_next (), "ValaCodeNode", &g_define_type_info, &g_define_type_fundamental_info, G_TYPE_FLAG_ABSTRACT);
1389 ValaCodeNode_private_offset = g_type_add_instance_private (vala_code_node_type_id, sizeof (ValaCodeNodePrivate));
1390 return vala_code_node_type_id;
1391 }
1392
1393 GType
vala_code_node_get_type(void)1394 vala_code_node_get_type (void)
1395 {
1396 static volatile gsize vala_code_node_type_id__volatile = 0;
1397 if (g_once_init_enter (&vala_code_node_type_id__volatile)) {
1398 GType vala_code_node_type_id;
1399 vala_code_node_type_id = vala_code_node_get_type_once ();
1400 g_once_init_leave (&vala_code_node_type_id__volatile, vala_code_node_type_id);
1401 }
1402 return vala_code_node_type_id__volatile;
1403 }
1404
1405 gpointer
vala_code_node_ref(gpointer instance)1406 vala_code_node_ref (gpointer instance)
1407 {
1408 ValaCodeNode * self;
1409 self = instance;
1410 g_atomic_int_inc (&self->ref_count);
1411 return instance;
1412 }
1413
1414 void
vala_code_node_unref(gpointer instance)1415 vala_code_node_unref (gpointer instance)
1416 {
1417 ValaCodeNode * self;
1418 self = instance;
1419 if (g_atomic_int_dec_and_test (&self->ref_count)) {
1420 VALA_CODE_NODE_GET_CLASS (self)->finalize (self);
1421 g_type_free_instance ((GTypeInstance *) self);
1422 }
1423 }
1424
1425 ValaAttributeCache*
vala_attribute_cache_construct(GType object_type)1426 vala_attribute_cache_construct (GType object_type)
1427 {
1428 ValaAttributeCache* self = NULL;
1429 self = (ValaAttributeCache*) g_type_create_instance (object_type);
1430 return self;
1431 }
1432
1433 ValaAttributeCache*
vala_attribute_cache_new(void)1434 vala_attribute_cache_new (void)
1435 {
1436 return vala_attribute_cache_construct (VALA_TYPE_ATTRIBUTE_CACHE);
1437 }
1438
1439 static void
vala_value_attribute_cache_init(GValue * value)1440 vala_value_attribute_cache_init (GValue* value)
1441 {
1442 value->data[0].v_pointer = NULL;
1443 }
1444
1445 static void
vala_value_attribute_cache_free_value(GValue * value)1446 vala_value_attribute_cache_free_value (GValue* value)
1447 {
1448 if (value->data[0].v_pointer) {
1449 vala_attribute_cache_unref (value->data[0].v_pointer);
1450 }
1451 }
1452
1453 static void
vala_value_attribute_cache_copy_value(const GValue * src_value,GValue * dest_value)1454 vala_value_attribute_cache_copy_value (const GValue* src_value,
1455 GValue* dest_value)
1456 {
1457 if (src_value->data[0].v_pointer) {
1458 dest_value->data[0].v_pointer = vala_attribute_cache_ref (src_value->data[0].v_pointer);
1459 } else {
1460 dest_value->data[0].v_pointer = NULL;
1461 }
1462 }
1463
1464 static gpointer
vala_value_attribute_cache_peek_pointer(const GValue * value)1465 vala_value_attribute_cache_peek_pointer (const GValue* value)
1466 {
1467 return value->data[0].v_pointer;
1468 }
1469
1470 static gchar*
vala_value_attribute_cache_collect_value(GValue * value,guint n_collect_values,GTypeCValue * collect_values,guint collect_flags)1471 vala_value_attribute_cache_collect_value (GValue* value,
1472 guint n_collect_values,
1473 GTypeCValue* collect_values,
1474 guint collect_flags)
1475 {
1476 if (collect_values[0].v_pointer) {
1477 ValaAttributeCache * object;
1478 object = collect_values[0].v_pointer;
1479 if (object->parent_instance.g_class == NULL) {
1480 return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
1481 } else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
1482 return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
1483 }
1484 value->data[0].v_pointer = vala_attribute_cache_ref (object);
1485 } else {
1486 value->data[0].v_pointer = NULL;
1487 }
1488 return NULL;
1489 }
1490
1491 static gchar*
vala_value_attribute_cache_lcopy_value(const GValue * value,guint n_collect_values,GTypeCValue * collect_values,guint collect_flags)1492 vala_value_attribute_cache_lcopy_value (const GValue* value,
1493 guint n_collect_values,
1494 GTypeCValue* collect_values,
1495 guint collect_flags)
1496 {
1497 ValaAttributeCache ** object_p;
1498 object_p = collect_values[0].v_pointer;
1499 if (!object_p) {
1500 return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
1501 }
1502 if (!value->data[0].v_pointer) {
1503 *object_p = NULL;
1504 } else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
1505 *object_p = value->data[0].v_pointer;
1506 } else {
1507 *object_p = vala_attribute_cache_ref (value->data[0].v_pointer);
1508 }
1509 return NULL;
1510 }
1511
1512 GParamSpec*
vala_param_spec_attribute_cache(const gchar * name,const gchar * nick,const gchar * blurb,GType object_type,GParamFlags flags)1513 vala_param_spec_attribute_cache (const gchar* name,
1514 const gchar* nick,
1515 const gchar* blurb,
1516 GType object_type,
1517 GParamFlags flags)
1518 {
1519 ValaParamSpecAttributeCache* spec;
1520 g_return_val_if_fail (g_type_is_a (object_type, VALA_TYPE_ATTRIBUTE_CACHE), NULL);
1521 spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
1522 G_PARAM_SPEC (spec)->value_type = object_type;
1523 return G_PARAM_SPEC (spec);
1524 }
1525
1526 gpointer
vala_value_get_attribute_cache(const GValue * value)1527 vala_value_get_attribute_cache (const GValue* value)
1528 {
1529 g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_ATTRIBUTE_CACHE), NULL);
1530 return value->data[0].v_pointer;
1531 }
1532
1533 void
vala_value_set_attribute_cache(GValue * value,gpointer v_object)1534 vala_value_set_attribute_cache (GValue* value,
1535 gpointer v_object)
1536 {
1537 ValaAttributeCache * old;
1538 g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_ATTRIBUTE_CACHE));
1539 old = value->data[0].v_pointer;
1540 if (v_object) {
1541 g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, VALA_TYPE_ATTRIBUTE_CACHE));
1542 g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
1543 value->data[0].v_pointer = v_object;
1544 vala_attribute_cache_ref (value->data[0].v_pointer);
1545 } else {
1546 value->data[0].v_pointer = NULL;
1547 }
1548 if (old) {
1549 vala_attribute_cache_unref (old);
1550 }
1551 }
1552
1553 void
vala_value_take_attribute_cache(GValue * value,gpointer v_object)1554 vala_value_take_attribute_cache (GValue* value,
1555 gpointer v_object)
1556 {
1557 ValaAttributeCache * old;
1558 g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_ATTRIBUTE_CACHE));
1559 old = value->data[0].v_pointer;
1560 if (v_object) {
1561 g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, VALA_TYPE_ATTRIBUTE_CACHE));
1562 g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
1563 value->data[0].v_pointer = v_object;
1564 } else {
1565 value->data[0].v_pointer = NULL;
1566 }
1567 if (old) {
1568 vala_attribute_cache_unref (old);
1569 }
1570 }
1571
1572 static void
vala_attribute_cache_class_init(ValaAttributeCacheClass * klass,gpointer klass_data)1573 vala_attribute_cache_class_init (ValaAttributeCacheClass * klass,
1574 gpointer klass_data)
1575 {
1576 vala_attribute_cache_parent_class = g_type_class_peek_parent (klass);
1577 ((ValaAttributeCacheClass *) klass)->finalize = vala_attribute_cache_finalize;
1578 }
1579
1580 static void
vala_attribute_cache_instance_init(ValaAttributeCache * self,gpointer klass)1581 vala_attribute_cache_instance_init (ValaAttributeCache * self,
1582 gpointer klass)
1583 {
1584 self->ref_count = 1;
1585 }
1586
1587 static void
vala_attribute_cache_finalize(ValaAttributeCache * obj)1588 vala_attribute_cache_finalize (ValaAttributeCache * obj)
1589 {
1590 ValaAttributeCache * self;
1591 self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_ATTRIBUTE_CACHE, ValaAttributeCache);
1592 g_signal_handlers_destroy (self);
1593 }
1594
1595 static GType
vala_attribute_cache_get_type_once(void)1596 vala_attribute_cache_get_type_once (void)
1597 {
1598 static const GTypeValueTable g_define_type_value_table = { vala_value_attribute_cache_init, vala_value_attribute_cache_free_value, vala_value_attribute_cache_copy_value, vala_value_attribute_cache_peek_pointer, "p", vala_value_attribute_cache_collect_value, "p", vala_value_attribute_cache_lcopy_value };
1599 static const GTypeInfo g_define_type_info = { sizeof (ValaAttributeCacheClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_attribute_cache_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaAttributeCache), 0, (GInstanceInitFunc) vala_attribute_cache_instance_init, &g_define_type_value_table };
1600 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) };
1601 GType vala_attribute_cache_type_id;
1602 vala_attribute_cache_type_id = g_type_register_fundamental (g_type_fundamental_next (), "ValaAttributeCache", &g_define_type_info, &g_define_type_fundamental_info, 0);
1603 return vala_attribute_cache_type_id;
1604 }
1605
1606 GType
vala_attribute_cache_get_type(void)1607 vala_attribute_cache_get_type (void)
1608 {
1609 static volatile gsize vala_attribute_cache_type_id__volatile = 0;
1610 if (g_once_init_enter (&vala_attribute_cache_type_id__volatile)) {
1611 GType vala_attribute_cache_type_id;
1612 vala_attribute_cache_type_id = vala_attribute_cache_get_type_once ();
1613 g_once_init_leave (&vala_attribute_cache_type_id__volatile, vala_attribute_cache_type_id);
1614 }
1615 return vala_attribute_cache_type_id__volatile;
1616 }
1617
1618 gpointer
vala_attribute_cache_ref(gpointer instance)1619 vala_attribute_cache_ref (gpointer instance)
1620 {
1621 ValaAttributeCache * self;
1622 self = instance;
1623 g_atomic_int_inc (&self->ref_count);
1624 return instance;
1625 }
1626
1627 void
vala_attribute_cache_unref(gpointer instance)1628 vala_attribute_cache_unref (gpointer instance)
1629 {
1630 ValaAttributeCache * self;
1631 self = instance;
1632 if (g_atomic_int_dec_and_test (&self->ref_count)) {
1633 VALA_ATTRIBUTE_CACHE_GET_CLASS (self)->finalize (self);
1634 g_type_free_instance ((GTypeInstance *) self);
1635 }
1636 }
1637
1638 static void
_vala_array_destroy(gpointer array,gint array_length,GDestroyNotify destroy_func)1639 _vala_array_destroy (gpointer array,
1640 gint array_length,
1641 GDestroyNotify destroy_func)
1642 {
1643 if ((array != NULL) && (destroy_func != NULL)) {
1644 gint i;
1645 for (i = 0; i < array_length; i = i + 1) {
1646 if (((gpointer*) array)[i] != NULL) {
1647 destroy_func (((gpointer*) array)[i]);
1648 }
1649 }
1650 }
1651 }
1652
1653 static void
_vala_array_free(gpointer array,gint array_length,GDestroyNotify destroy_func)1654 _vala_array_free (gpointer array,
1655 gint array_length,
1656 GDestroyNotify destroy_func)
1657 {
1658 _vala_array_destroy (array, array_length, destroy_func);
1659 g_free (array);
1660 }
1661
1662