1 /* valablock.c generated by valac, the Vala compiler
2 * generated from valablock.vala, do not modify */
3
4 /* valablock.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 <valagee.h>
29 #include <glib-object.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #define _vala_iterable_unref0(var) ((var == NULL) ? NULL : (var = (vala_iterable_unref (var), NULL)))
34 #define _vala_code_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_node_unref (var), NULL)))
35 #define _g_free0(var) (var = (g_free (var), NULL))
36
37 struct _ValaBlockPrivate {
38 gboolean _contains_jump_statement;
39 gboolean _captured;
40 ValaList* statement_list;
41 ValaList* local_variables;
42 ValaList* local_constants;
43 };
44
45 static gint ValaBlock_private_offset;
46 static gpointer vala_block_parent_class = NULL;
47 static ValaStatementIface * vala_block_vala_statement_parent_iface = NULL;
48
49 static void vala_block_real_accept (ValaCodeNode* base,
50 ValaCodeVisitor* visitor);
51 static void vala_block_real_accept_children (ValaCodeNode* base,
52 ValaCodeVisitor* visitor);
53 static gboolean vala_block_real_check (ValaCodeNode* base,
54 ValaCodeContext* context);
55 static void vala_block_real_get_error_types (ValaCodeNode* base,
56 ValaCollection* collection,
57 ValaSourceReference* source_reference);
58 static void vala_block_real_emit (ValaCodeNode* base,
59 ValaCodeGenerator* codegen);
60 static void vala_block_finalize (ValaCodeNode * obj);
61 static GType vala_block_get_type_once (void);
62
63 static inline gpointer
vala_block_get_instance_private(ValaBlock * self)64 vala_block_get_instance_private (ValaBlock* self)
65 {
66 return G_STRUCT_MEMBER_P (self, ValaBlock_private_offset);
67 }
68
69 gboolean
vala_block_get_contains_jump_statement(ValaBlock * self)70 vala_block_get_contains_jump_statement (ValaBlock* self)
71 {
72 gboolean result;
73 g_return_val_if_fail (self != NULL, FALSE);
74 result = self->priv->_contains_jump_statement;
75 return result;
76 }
77
78 void
vala_block_set_contains_jump_statement(ValaBlock * self,gboolean value)79 vala_block_set_contains_jump_statement (ValaBlock* self,
80 gboolean value)
81 {
82 g_return_if_fail (self != NULL);
83 self->priv->_contains_jump_statement = value;
84 }
85
86 gboolean
vala_block_get_captured(ValaBlock * self)87 vala_block_get_captured (ValaBlock* self)
88 {
89 gboolean result;
90 g_return_val_if_fail (self != NULL, FALSE);
91 result = self->priv->_captured;
92 return result;
93 }
94
95 void
vala_block_set_captured(ValaBlock * self,gboolean value)96 vala_block_set_captured (ValaBlock* self,
97 gboolean value)
98 {
99 g_return_if_fail (self != NULL);
100 self->priv->_captured = value;
101 }
102
103 /**
104 * Creates a new block.
105 *
106 * @param source_reference reference to source code
107 */
108 ValaBlock*
vala_block_construct(GType object_type,ValaSourceReference * source_reference)109 vala_block_construct (GType object_type,
110 ValaSourceReference* source_reference)
111 {
112 ValaBlock* self = NULL;
113 self = (ValaBlock*) vala_symbol_construct (object_type, NULL, source_reference, NULL);
114 return self;
115 }
116
117 ValaBlock*
vala_block_new(ValaSourceReference * source_reference)118 vala_block_new (ValaSourceReference* source_reference)
119 {
120 return vala_block_construct (VALA_TYPE_BLOCK, source_reference);
121 }
122
123 /**
124 * Append a statement to this block.
125 *
126 * @param stmt a statement
127 */
128 void
vala_block_add_statement(ValaBlock * self,ValaStatement * stmt)129 vala_block_add_statement (ValaBlock* self,
130 ValaStatement* stmt)
131 {
132 ValaList* _tmp0_;
133 g_return_if_fail (self != NULL);
134 g_return_if_fail (stmt != NULL);
135 vala_code_node_set_parent_node ((ValaCodeNode*) stmt, (ValaCodeNode*) self);
136 _tmp0_ = self->priv->statement_list;
137 vala_collection_add ((ValaCollection*) _tmp0_, stmt);
138 }
139
140 void
vala_block_insert_statement(ValaBlock * self,gint index,ValaStatement * stmt)141 vala_block_insert_statement (ValaBlock* self,
142 gint index,
143 ValaStatement* stmt)
144 {
145 ValaList* _tmp0_;
146 g_return_if_fail (self != NULL);
147 g_return_if_fail (stmt != NULL);
148 vala_code_node_set_parent_node ((ValaCodeNode*) stmt, (ValaCodeNode*) self);
149 _tmp0_ = self->priv->statement_list;
150 vala_list_insert (_tmp0_, index, stmt);
151 }
152
153 /**
154 * Returns a copy of the list of statements.
155 *
156 * @return statement list
157 */
158 static gpointer
_vala_iterable_ref0(gpointer self)159 _vala_iterable_ref0 (gpointer self)
160 {
161 return self ? vala_iterable_ref (self) : NULL;
162 }
163
164 ValaList*
vala_block_get_statements(ValaBlock * self)165 vala_block_get_statements (ValaBlock* self)
166 {
167 ValaArrayList* list = NULL;
168 GEqualFunc _tmp0_;
169 ValaArrayList* _tmp1_;
170 ValaList* result = NULL;
171 g_return_val_if_fail (self != NULL, NULL);
172 _tmp0_ = g_direct_equal;
173 _tmp1_ = vala_array_list_new (VALA_TYPE_STATEMENT, (GBoxedCopyFunc) vala_code_node_ref, (GDestroyNotify) vala_code_node_unref, _tmp0_);
174 list = _tmp1_;
175 {
176 ValaList* _stmt_list = NULL;
177 ValaList* _tmp2_;
178 ValaList* _tmp3_;
179 gint _stmt_size = 0;
180 ValaList* _tmp4_;
181 gint _tmp5_;
182 gint _tmp6_;
183 gint _stmt_index = 0;
184 _tmp2_ = self->priv->statement_list;
185 _tmp3_ = _vala_iterable_ref0 (_tmp2_);
186 _stmt_list = _tmp3_;
187 _tmp4_ = _stmt_list;
188 _tmp5_ = vala_collection_get_size ((ValaCollection*) _tmp4_);
189 _tmp6_ = _tmp5_;
190 _stmt_size = _tmp6_;
191 _stmt_index = -1;
192 while (TRUE) {
193 gint _tmp7_;
194 gint _tmp8_;
195 ValaStatement* stmt = NULL;
196 ValaList* _tmp9_;
197 gpointer _tmp10_;
198 ValaStatementList* stmt_list = NULL;
199 ValaStatement* _tmp11_;
200 ValaStatementList* _tmp12_;
201 _stmt_index = _stmt_index + 1;
202 _tmp7_ = _stmt_index;
203 _tmp8_ = _stmt_size;
204 if (!(_tmp7_ < _tmp8_)) {
205 break;
206 }
207 _tmp9_ = _stmt_list;
208 _tmp10_ = vala_list_get (_tmp9_, _stmt_index);
209 stmt = (ValaStatement*) _tmp10_;
210 _tmp11_ = stmt;
211 stmt_list = VALA_IS_STATEMENT_LIST (_tmp11_) ? ((ValaStatementList*) _tmp11_) : NULL;
212 _tmp12_ = stmt_list;
213 if (_tmp12_ != NULL) {
214 {
215 gint i = 0;
216 i = 0;
217 {
218 gboolean _tmp13_ = FALSE;
219 _tmp13_ = TRUE;
220 while (TRUE) {
221 ValaStatementList* _tmp15_;
222 gint _tmp16_;
223 gint _tmp17_;
224 ValaArrayList* _tmp18_;
225 ValaStatementList* _tmp19_;
226 ValaStatement* _tmp20_;
227 ValaStatement* _tmp21_;
228 if (!_tmp13_) {
229 gint _tmp14_;
230 _tmp14_ = i;
231 i = _tmp14_ + 1;
232 }
233 _tmp13_ = FALSE;
234 _tmp15_ = stmt_list;
235 _tmp16_ = vala_statement_list_get_length (_tmp15_);
236 _tmp17_ = _tmp16_;
237 if (!(i < _tmp17_)) {
238 break;
239 }
240 _tmp18_ = list;
241 _tmp19_ = stmt_list;
242 _tmp20_ = vala_statement_list_get (_tmp19_, i);
243 _tmp21_ = _tmp20_;
244 vala_collection_add ((ValaCollection*) _tmp18_, _tmp21_);
245 _vala_code_node_unref0 (_tmp21_);
246 }
247 }
248 }
249 } else {
250 ValaArrayList* _tmp22_;
251 ValaStatement* _tmp23_;
252 _tmp22_ = list;
253 _tmp23_ = stmt;
254 vala_collection_add ((ValaCollection*) _tmp22_, _tmp23_);
255 }
256 _vala_code_node_unref0 (stmt);
257 }
258 _vala_iterable_unref0 (_stmt_list);
259 }
260 result = (ValaList*) list;
261 return result;
262 }
263
264 /**
265 * Add a local variable to this block.
266 *
267 * @param local a variable declarator
268 */
269 void
vala_block_add_local_variable(ValaBlock * self,ValaLocalVariable * local)270 vala_block_add_local_variable (ValaBlock* self,
271 ValaLocalVariable* local)
272 {
273 ValaSymbol* parent_block = NULL;
274 ValaSymbol* _tmp0_;
275 ValaSymbol* _tmp1_;
276 ValaList* _tmp24_;
277 g_return_if_fail (self != NULL);
278 g_return_if_fail (local != NULL);
279 _tmp0_ = vala_symbol_get_parent_symbol ((ValaSymbol*) self);
280 _tmp1_ = _tmp0_;
281 parent_block = _tmp1_;
282 while (TRUE) {
283 gboolean _tmp2_ = FALSE;
284 gboolean _tmp3_ = FALSE;
285 ValaSymbol* _tmp4_;
286 ValaSymbol* _tmp7_;
287 ValaScope* _tmp8_;
288 ValaScope* _tmp9_;
289 const gchar* _tmp10_;
290 const gchar* _tmp11_;
291 ValaSymbol* _tmp12_;
292 ValaSymbol* _tmp13_;
293 gboolean _tmp14_;
294 ValaSymbol* _tmp21_;
295 ValaSymbol* _tmp22_;
296 ValaSymbol* _tmp23_;
297 _tmp4_ = parent_block;
298 if (VALA_IS_BLOCK (_tmp4_)) {
299 _tmp3_ = TRUE;
300 } else {
301 ValaSymbol* _tmp5_;
302 _tmp5_ = parent_block;
303 _tmp3_ = VALA_IS_METHOD (_tmp5_);
304 }
305 if (_tmp3_) {
306 _tmp2_ = TRUE;
307 } else {
308 ValaSymbol* _tmp6_;
309 _tmp6_ = parent_block;
310 _tmp2_ = VALA_IS_PROPERTY_ACCESSOR (_tmp6_);
311 }
312 if (!_tmp2_) {
313 break;
314 }
315 _tmp7_ = parent_block;
316 _tmp8_ = vala_symbol_get_scope (_tmp7_);
317 _tmp9_ = _tmp8_;
318 _tmp10_ = vala_symbol_get_name ((ValaSymbol*) local);
319 _tmp11_ = _tmp10_;
320 _tmp12_ = vala_scope_lookup (_tmp9_, _tmp11_);
321 _tmp13_ = _tmp12_;
322 _tmp14_ = _tmp13_ != NULL;
323 _vala_code_node_unref0 (_tmp13_);
324 if (_tmp14_) {
325 ValaSourceReference* _tmp15_;
326 ValaSourceReference* _tmp16_;
327 const gchar* _tmp17_;
328 const gchar* _tmp18_;
329 gchar* _tmp19_;
330 gchar* _tmp20_;
331 _tmp15_ = vala_code_node_get_source_reference ((ValaCodeNode*) local);
332 _tmp16_ = _tmp15_;
333 _tmp17_ = vala_symbol_get_name ((ValaSymbol*) local);
334 _tmp18_ = _tmp17_;
335 _tmp19_ = g_strdup_printf ("Local variable `%s' conflicts with a local variable or constant declar" \
336 "ed in a parent scope", _tmp18_);
337 _tmp20_ = _tmp19_;
338 vala_report_error (_tmp16_, _tmp20_);
339 _g_free0 (_tmp20_);
340 break;
341 }
342 _tmp21_ = parent_block;
343 _tmp22_ = vala_symbol_get_parent_symbol (_tmp21_);
344 _tmp23_ = _tmp22_;
345 parent_block = _tmp23_;
346 }
347 _tmp24_ = self->priv->local_variables;
348 vala_collection_add ((ValaCollection*) _tmp24_, local);
349 }
350
351 void
vala_block_remove_local_variable(ValaBlock * self,ValaLocalVariable * local)352 vala_block_remove_local_variable (ValaBlock* self,
353 ValaLocalVariable* local)
354 {
355 ValaList* _tmp0_;
356 g_return_if_fail (self != NULL);
357 g_return_if_fail (local != NULL);
358 _tmp0_ = self->priv->local_variables;
359 vala_collection_remove ((ValaCollection*) _tmp0_, local);
360 }
361
362 /**
363 * Returns the list of local variables.
364 *
365 * @return variable declarator list
366 */
367 ValaList*
vala_block_get_local_variables(ValaBlock * self)368 vala_block_get_local_variables (ValaBlock* self)
369 {
370 ValaList* _tmp0_;
371 ValaList* result = NULL;
372 g_return_val_if_fail (self != NULL, NULL);
373 _tmp0_ = self->priv->local_variables;
374 result = _tmp0_;
375 return result;
376 }
377
378 void
vala_block_add_local_constant(ValaBlock * self,ValaConstant * constant)379 vala_block_add_local_constant (ValaBlock* self,
380 ValaConstant* constant)
381 {
382 ValaSymbol* parent_block = NULL;
383 ValaSymbol* _tmp0_;
384 ValaSymbol* _tmp1_;
385 ValaList* _tmp24_;
386 ValaScope* _tmp25_;
387 ValaScope* _tmp26_;
388 const gchar* _tmp27_;
389 const gchar* _tmp28_;
390 g_return_if_fail (self != NULL);
391 g_return_if_fail (constant != NULL);
392 _tmp0_ = vala_symbol_get_parent_symbol ((ValaSymbol*) self);
393 _tmp1_ = _tmp0_;
394 parent_block = _tmp1_;
395 while (TRUE) {
396 gboolean _tmp2_ = FALSE;
397 gboolean _tmp3_ = FALSE;
398 ValaSymbol* _tmp4_;
399 ValaSymbol* _tmp7_;
400 ValaScope* _tmp8_;
401 ValaScope* _tmp9_;
402 const gchar* _tmp10_;
403 const gchar* _tmp11_;
404 ValaSymbol* _tmp12_;
405 ValaSymbol* _tmp13_;
406 gboolean _tmp14_;
407 ValaSymbol* _tmp21_;
408 ValaSymbol* _tmp22_;
409 ValaSymbol* _tmp23_;
410 _tmp4_ = parent_block;
411 if (VALA_IS_BLOCK (_tmp4_)) {
412 _tmp3_ = TRUE;
413 } else {
414 ValaSymbol* _tmp5_;
415 _tmp5_ = parent_block;
416 _tmp3_ = VALA_IS_METHOD (_tmp5_);
417 }
418 if (_tmp3_) {
419 _tmp2_ = TRUE;
420 } else {
421 ValaSymbol* _tmp6_;
422 _tmp6_ = parent_block;
423 _tmp2_ = VALA_IS_PROPERTY_ACCESSOR (_tmp6_);
424 }
425 if (!_tmp2_) {
426 break;
427 }
428 _tmp7_ = parent_block;
429 _tmp8_ = vala_symbol_get_scope (_tmp7_);
430 _tmp9_ = _tmp8_;
431 _tmp10_ = vala_symbol_get_name ((ValaSymbol*) constant);
432 _tmp11_ = _tmp10_;
433 _tmp12_ = vala_scope_lookup (_tmp9_, _tmp11_);
434 _tmp13_ = _tmp12_;
435 _tmp14_ = _tmp13_ != NULL;
436 _vala_code_node_unref0 (_tmp13_);
437 if (_tmp14_) {
438 ValaSourceReference* _tmp15_;
439 ValaSourceReference* _tmp16_;
440 const gchar* _tmp17_;
441 const gchar* _tmp18_;
442 gchar* _tmp19_;
443 gchar* _tmp20_;
444 _tmp15_ = vala_code_node_get_source_reference ((ValaCodeNode*) constant);
445 _tmp16_ = _tmp15_;
446 _tmp17_ = vala_symbol_get_name ((ValaSymbol*) constant);
447 _tmp18_ = _tmp17_;
448 _tmp19_ = g_strdup_printf ("Local constant `%s' conflicts with a local variable or constant declar" \
449 "ed in a parent scope", _tmp18_);
450 _tmp20_ = _tmp19_;
451 vala_report_error (_tmp16_, _tmp20_);
452 _g_free0 (_tmp20_);
453 break;
454 }
455 _tmp21_ = parent_block;
456 _tmp22_ = vala_symbol_get_parent_symbol (_tmp21_);
457 _tmp23_ = _tmp22_;
458 parent_block = _tmp23_;
459 }
460 _tmp24_ = self->priv->local_constants;
461 vala_collection_add ((ValaCollection*) _tmp24_, constant);
462 _tmp25_ = vala_symbol_get_scope ((ValaSymbol*) self);
463 _tmp26_ = _tmp25_;
464 _tmp27_ = vala_symbol_get_name ((ValaSymbol*) constant);
465 _tmp28_ = _tmp27_;
466 vala_scope_add (_tmp26_, _tmp28_, (ValaSymbol*) constant);
467 }
468
469 /**
470 * Returns the list of local constants.
471 *
472 * @return constants list
473 */
474 ValaList*
vala_block_get_local_constants(ValaBlock * self)475 vala_block_get_local_constants (ValaBlock* self)
476 {
477 ValaList* _tmp0_;
478 ValaList* result = NULL;
479 g_return_val_if_fail (self != NULL, NULL);
480 _tmp0_ = self->priv->local_constants;
481 result = _tmp0_;
482 return result;
483 }
484
485 static void
vala_block_real_accept(ValaCodeNode * base,ValaCodeVisitor * visitor)486 vala_block_real_accept (ValaCodeNode* base,
487 ValaCodeVisitor* visitor)
488 {
489 ValaBlock * self;
490 self = (ValaBlock*) base;
491 g_return_if_fail (visitor != NULL);
492 vala_code_visitor_visit_block (visitor, self);
493 }
494
495 static void
vala_block_real_accept_children(ValaCodeNode * base,ValaCodeVisitor * visitor)496 vala_block_real_accept_children (ValaCodeNode* base,
497 ValaCodeVisitor* visitor)
498 {
499 ValaBlock * self;
500 self = (ValaBlock*) base;
501 g_return_if_fail (visitor != NULL);
502 {
503 ValaList* _stmt_list = NULL;
504 ValaList* _tmp0_;
505 ValaList* _tmp1_;
506 gint _stmt_size = 0;
507 ValaList* _tmp2_;
508 gint _tmp3_;
509 gint _tmp4_;
510 gint _stmt_index = 0;
511 _tmp0_ = self->priv->statement_list;
512 _tmp1_ = _vala_iterable_ref0 (_tmp0_);
513 _stmt_list = _tmp1_;
514 _tmp2_ = _stmt_list;
515 _tmp3_ = vala_collection_get_size ((ValaCollection*) _tmp2_);
516 _tmp4_ = _tmp3_;
517 _stmt_size = _tmp4_;
518 _stmt_index = -1;
519 while (TRUE) {
520 gint _tmp5_;
521 gint _tmp6_;
522 ValaStatement* stmt = NULL;
523 ValaList* _tmp7_;
524 gpointer _tmp8_;
525 ValaStatement* _tmp9_;
526 _stmt_index = _stmt_index + 1;
527 _tmp5_ = _stmt_index;
528 _tmp6_ = _stmt_size;
529 if (!(_tmp5_ < _tmp6_)) {
530 break;
531 }
532 _tmp7_ = _stmt_list;
533 _tmp8_ = vala_list_get (_tmp7_, _stmt_index);
534 stmt = (ValaStatement*) _tmp8_;
535 _tmp9_ = stmt;
536 vala_code_node_accept ((ValaCodeNode*) _tmp9_, visitor);
537 _vala_code_node_unref0 (stmt);
538 }
539 _vala_iterable_unref0 (_stmt_list);
540 }
541 }
542
543 static gpointer
_vala_code_node_ref0(gpointer self)544 _vala_code_node_ref0 (gpointer self)
545 {
546 return self ? vala_code_node_ref (self) : NULL;
547 }
548
549 static gboolean
vala_block_real_check(ValaCodeNode * base,ValaCodeContext * context)550 vala_block_real_check (ValaCodeNode* base,
551 ValaCodeContext* context)
552 {
553 ValaBlock * self;
554 gboolean _tmp0_;
555 gboolean _tmp1_;
556 ValaSemanticAnalyzer* _tmp4_;
557 ValaSemanticAnalyzer* _tmp5_;
558 ValaSymbol* _tmp6_;
559 ValaSymbol* _tmp7_;
560 ValaScope* _tmp8_;
561 ValaScope* _tmp9_;
562 ValaSymbol* old_symbol = NULL;
563 ValaSemanticAnalyzer* _tmp10_;
564 ValaSemanticAnalyzer* _tmp11_;
565 ValaSymbol* _tmp12_;
566 ValaSymbol* _tmp13_;
567 ValaSymbol* _tmp14_;
568 ValaBlock* old_insert_block = NULL;
569 ValaSemanticAnalyzer* _tmp15_;
570 ValaSemanticAnalyzer* _tmp16_;
571 ValaBlock* _tmp17_;
572 ValaBlock* _tmp18_;
573 ValaSemanticAnalyzer* _tmp19_;
574 ValaSemanticAnalyzer* _tmp20_;
575 ValaSemanticAnalyzer* _tmp21_;
576 ValaSemanticAnalyzer* _tmp22_;
577 ValaBlock* _tmp23_;
578 ValaSemanticAnalyzer* _tmp53_;
579 ValaSemanticAnalyzer* _tmp54_;
580 ValaSymbol* _tmp55_;
581 ValaSemanticAnalyzer* _tmp56_;
582 ValaSemanticAnalyzer* _tmp57_;
583 ValaBlock* _tmp58_;
584 ValaBlock* _tmp59_;
585 gboolean _tmp60_;
586 gboolean _tmp61_;
587 gboolean result = FALSE;
588 self = (ValaBlock*) base;
589 g_return_val_if_fail (context != NULL, FALSE);
590 _tmp0_ = vala_code_node_get_checked ((ValaCodeNode*) self);
591 _tmp1_ = _tmp0_;
592 if (_tmp1_) {
593 gboolean _tmp2_;
594 gboolean _tmp3_;
595 _tmp2_ = vala_code_node_get_error ((ValaCodeNode*) self);
596 _tmp3_ = _tmp2_;
597 result = !_tmp3_;
598 return result;
599 }
600 vala_code_node_set_checked ((ValaCodeNode*) self, TRUE);
601 _tmp4_ = vala_code_context_get_analyzer (context);
602 _tmp5_ = _tmp4_;
603 _tmp6_ = vala_semantic_analyzer_get_current_symbol (_tmp5_);
604 _tmp7_ = _tmp6_;
605 _tmp8_ = vala_symbol_get_scope (_tmp7_);
606 _tmp9_ = _tmp8_;
607 vala_symbol_set_owner ((ValaSymbol*) self, _tmp9_);
608 _tmp10_ = vala_code_context_get_analyzer (context);
609 _tmp11_ = _tmp10_;
610 _tmp12_ = vala_semantic_analyzer_get_current_symbol (_tmp11_);
611 _tmp13_ = _tmp12_;
612 _tmp14_ = _vala_code_node_ref0 (_tmp13_);
613 old_symbol = _tmp14_;
614 _tmp15_ = vala_code_context_get_analyzer (context);
615 _tmp16_ = _tmp15_;
616 _tmp17_ = _tmp16_->insert_block;
617 _tmp18_ = _vala_code_node_ref0 (_tmp17_);
618 old_insert_block = _tmp18_;
619 _tmp19_ = vala_code_context_get_analyzer (context);
620 _tmp20_ = _tmp19_;
621 vala_semantic_analyzer_set_current_symbol (_tmp20_, (ValaSymbol*) self);
622 _tmp21_ = vala_code_context_get_analyzer (context);
623 _tmp22_ = _tmp21_;
624 _tmp23_ = _vala_code_node_ref0 (self);
625 _vala_code_node_unref0 (_tmp22_->insert_block);
626 _tmp22_->insert_block = _tmp23_;
627 {
628 gint i = 0;
629 i = 0;
630 {
631 gboolean _tmp24_ = FALSE;
632 _tmp24_ = TRUE;
633 while (TRUE) {
634 ValaList* _tmp26_;
635 gint _tmp27_;
636 gint _tmp28_;
637 ValaList* _tmp29_;
638 gpointer _tmp30_;
639 ValaStatement* _tmp31_;
640 gboolean _tmp32_;
641 if (!_tmp24_) {
642 gint _tmp25_;
643 _tmp25_ = i;
644 i = _tmp25_ + 1;
645 }
646 _tmp24_ = FALSE;
647 _tmp26_ = self->priv->statement_list;
648 _tmp27_ = vala_collection_get_size ((ValaCollection*) _tmp26_);
649 _tmp28_ = _tmp27_;
650 if (!(i < _tmp28_)) {
651 break;
652 }
653 _tmp29_ = self->priv->statement_list;
654 _tmp30_ = vala_list_get (_tmp29_, i);
655 _tmp31_ = (ValaStatement*) _tmp30_;
656 _tmp32_ = !vala_code_node_check ((ValaCodeNode*) _tmp31_, context);
657 _vala_code_node_unref0 (_tmp31_);
658 if (_tmp32_) {
659 vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
660 }
661 }
662 }
663 }
664 {
665 ValaList* _local_list = NULL;
666 ValaList* _tmp33_;
667 ValaList* _tmp34_;
668 gint _local_size = 0;
669 ValaList* _tmp35_;
670 gint _tmp36_;
671 gint _tmp37_;
672 gint _local_index = 0;
673 _tmp33_ = vala_block_get_local_variables (self);
674 _tmp34_ = _vala_iterable_ref0 (_tmp33_);
675 _local_list = _tmp34_;
676 _tmp35_ = _local_list;
677 _tmp36_ = vala_collection_get_size ((ValaCollection*) _tmp35_);
678 _tmp37_ = _tmp36_;
679 _local_size = _tmp37_;
680 _local_index = -1;
681 while (TRUE) {
682 gint _tmp38_;
683 gint _tmp39_;
684 ValaLocalVariable* local = NULL;
685 ValaList* _tmp40_;
686 gpointer _tmp41_;
687 ValaLocalVariable* _tmp42_;
688 _local_index = _local_index + 1;
689 _tmp38_ = _local_index;
690 _tmp39_ = _local_size;
691 if (!(_tmp38_ < _tmp39_)) {
692 break;
693 }
694 _tmp40_ = _local_list;
695 _tmp41_ = vala_list_get (_tmp40_, _local_index);
696 local = (ValaLocalVariable*) _tmp41_;
697 _tmp42_ = local;
698 vala_symbol_set_active ((ValaSymbol*) _tmp42_, FALSE);
699 _vala_code_node_unref0 (local);
700 }
701 _vala_iterable_unref0 (_local_list);
702 }
703 {
704 ValaList* _constant_list = NULL;
705 ValaList* _tmp43_;
706 ValaList* _tmp44_;
707 gint _constant_size = 0;
708 ValaList* _tmp45_;
709 gint _tmp46_;
710 gint _tmp47_;
711 gint _constant_index = 0;
712 _tmp43_ = self->priv->local_constants;
713 _tmp44_ = _vala_iterable_ref0 (_tmp43_);
714 _constant_list = _tmp44_;
715 _tmp45_ = _constant_list;
716 _tmp46_ = vala_collection_get_size ((ValaCollection*) _tmp45_);
717 _tmp47_ = _tmp46_;
718 _constant_size = _tmp47_;
719 _constant_index = -1;
720 while (TRUE) {
721 gint _tmp48_;
722 gint _tmp49_;
723 ValaConstant* constant = NULL;
724 ValaList* _tmp50_;
725 gpointer _tmp51_;
726 ValaConstant* _tmp52_;
727 _constant_index = _constant_index + 1;
728 _tmp48_ = _constant_index;
729 _tmp49_ = _constant_size;
730 if (!(_tmp48_ < _tmp49_)) {
731 break;
732 }
733 _tmp50_ = _constant_list;
734 _tmp51_ = vala_list_get (_tmp50_, _constant_index);
735 constant = (ValaConstant*) _tmp51_;
736 _tmp52_ = constant;
737 vala_symbol_set_active ((ValaSymbol*) _tmp52_, FALSE);
738 _vala_code_node_unref0 (constant);
739 }
740 _vala_iterable_unref0 (_constant_list);
741 }
742 _tmp53_ = vala_code_context_get_analyzer (context);
743 _tmp54_ = _tmp53_;
744 _tmp55_ = old_symbol;
745 vala_semantic_analyzer_set_current_symbol (_tmp54_, _tmp55_);
746 _tmp56_ = vala_code_context_get_analyzer (context);
747 _tmp57_ = _tmp56_;
748 _tmp58_ = old_insert_block;
749 _tmp59_ = _vala_code_node_ref0 (_tmp58_);
750 _vala_code_node_unref0 (_tmp57_->insert_block);
751 _tmp57_->insert_block = _tmp59_;
752 _tmp60_ = vala_code_node_get_error ((ValaCodeNode*) self);
753 _tmp61_ = _tmp60_;
754 result = !_tmp61_;
755 _vala_code_node_unref0 (old_insert_block);
756 _vala_code_node_unref0 (old_symbol);
757 return result;
758 }
759
760 static void
vala_block_real_get_error_types(ValaCodeNode * base,ValaCollection * collection,ValaSourceReference * source_reference)761 vala_block_real_get_error_types (ValaCodeNode* base,
762 ValaCollection* collection,
763 ValaSourceReference* source_reference)
764 {
765 ValaBlock * self;
766 self = (ValaBlock*) base;
767 g_return_if_fail (collection != NULL);
768 {
769 ValaList* _stmt_list = NULL;
770 ValaList* _tmp0_;
771 gint _stmt_size = 0;
772 ValaList* _tmp1_;
773 gint _tmp2_;
774 gint _tmp3_;
775 gint _stmt_index = 0;
776 _tmp0_ = vala_block_get_statements (self);
777 _stmt_list = _tmp0_;
778 _tmp1_ = _stmt_list;
779 _tmp2_ = vala_collection_get_size ((ValaCollection*) _tmp1_);
780 _tmp3_ = _tmp2_;
781 _stmt_size = _tmp3_;
782 _stmt_index = -1;
783 while (TRUE) {
784 gint _tmp4_;
785 gint _tmp5_;
786 ValaStatement* stmt = NULL;
787 ValaList* _tmp6_;
788 gpointer _tmp7_;
789 ValaStatement* _tmp8_;
790 _stmt_index = _stmt_index + 1;
791 _tmp4_ = _stmt_index;
792 _tmp5_ = _stmt_size;
793 if (!(_tmp4_ < _tmp5_)) {
794 break;
795 }
796 _tmp6_ = _stmt_list;
797 _tmp7_ = vala_list_get (_tmp6_, _stmt_index);
798 stmt = (ValaStatement*) _tmp7_;
799 _tmp8_ = stmt;
800 vala_code_node_get_error_types ((ValaCodeNode*) _tmp8_, collection, source_reference);
801 _vala_code_node_unref0 (stmt);
802 }
803 _vala_iterable_unref0 (_stmt_list);
804 }
805 }
806
807 static void
vala_block_real_emit(ValaCodeNode * base,ValaCodeGenerator * codegen)808 vala_block_real_emit (ValaCodeNode* base,
809 ValaCodeGenerator* codegen)
810 {
811 ValaBlock * self;
812 self = (ValaBlock*) base;
813 g_return_if_fail (codegen != NULL);
814 vala_code_visitor_visit_block ((ValaCodeVisitor*) codegen, self);
815 }
816
817 void
vala_block_insert_before(ValaBlock * self,ValaStatement * stmt,ValaStatement * new_stmt)818 vala_block_insert_before (ValaBlock* self,
819 ValaStatement* stmt,
820 ValaStatement* new_stmt)
821 {
822 g_return_if_fail (self != NULL);
823 g_return_if_fail (stmt != NULL);
824 g_return_if_fail (new_stmt != NULL);
825 {
826 gint i = 0;
827 i = 0;
828 {
829 gboolean _tmp0_ = FALSE;
830 _tmp0_ = TRUE;
831 while (TRUE) {
832 ValaList* _tmp2_;
833 gint _tmp3_;
834 gint _tmp4_;
835 ValaStatementList* stmt_list = NULL;
836 ValaList* _tmp5_;
837 gpointer _tmp6_;
838 ValaStatement* _tmp7_;
839 ValaStatementList* _tmp8_;
840 ValaStatementList* _tmp9_;
841 if (!_tmp0_) {
842 gint _tmp1_;
843 _tmp1_ = i;
844 i = _tmp1_ + 1;
845 }
846 _tmp0_ = FALSE;
847 _tmp2_ = self->priv->statement_list;
848 _tmp3_ = vala_collection_get_size ((ValaCollection*) _tmp2_);
849 _tmp4_ = _tmp3_;
850 if (!(i < _tmp4_)) {
851 break;
852 }
853 _tmp5_ = self->priv->statement_list;
854 _tmp6_ = vala_list_get (_tmp5_, i);
855 _tmp7_ = (ValaStatement*) _tmp6_;
856 _tmp8_ = VALA_IS_STATEMENT_LIST (_tmp7_) ? ((ValaStatementList*) _tmp7_) : NULL;
857 if (_tmp8_ == NULL) {
858 _vala_code_node_unref0 (_tmp7_);
859 }
860 stmt_list = _tmp8_;
861 _tmp9_ = stmt_list;
862 if (_tmp9_ != NULL) {
863 {
864 gint j = 0;
865 j = 0;
866 {
867 gboolean _tmp10_ = FALSE;
868 _tmp10_ = TRUE;
869 while (TRUE) {
870 ValaStatementList* _tmp12_;
871 gint _tmp13_;
872 gint _tmp14_;
873 ValaStatementList* _tmp15_;
874 ValaStatement* _tmp16_;
875 ValaStatement* _tmp17_;
876 gboolean _tmp18_;
877 if (!_tmp10_) {
878 gint _tmp11_;
879 _tmp11_ = j;
880 j = _tmp11_ + 1;
881 }
882 _tmp10_ = FALSE;
883 _tmp12_ = stmt_list;
884 _tmp13_ = vala_statement_list_get_length (_tmp12_);
885 _tmp14_ = _tmp13_;
886 if (!(j < _tmp14_)) {
887 break;
888 }
889 _tmp15_ = stmt_list;
890 _tmp16_ = vala_statement_list_get (_tmp15_, j);
891 _tmp17_ = _tmp16_;
892 _tmp18_ = _tmp17_ == stmt;
893 _vala_code_node_unref0 (_tmp17_);
894 if (_tmp18_) {
895 ValaStatementList* _tmp19_;
896 _tmp19_ = stmt_list;
897 vala_statement_list_insert (_tmp19_, j, new_stmt);
898 vala_code_node_set_parent_node ((ValaCodeNode*) new_stmt, (ValaCodeNode*) self);
899 break;
900 }
901 }
902 }
903 }
904 } else {
905 ValaList* _tmp20_;
906 gpointer _tmp21_;
907 ValaStatement* _tmp22_;
908 gboolean _tmp23_;
909 _tmp20_ = self->priv->statement_list;
910 _tmp21_ = vala_list_get (_tmp20_, i);
911 _tmp22_ = (ValaStatement*) _tmp21_;
912 _tmp23_ = _tmp22_ == stmt;
913 _vala_code_node_unref0 (_tmp22_);
914 if (_tmp23_) {
915 ValaSourceReference* _tmp24_;
916 ValaSourceReference* _tmp25_;
917 ValaStatementList* _tmp26_;
918 ValaStatementList* _tmp27_;
919 ValaStatementList* _tmp28_;
920 ValaList* _tmp29_;
921 ValaStatementList* _tmp30_;
922 _tmp24_ = vala_code_node_get_source_reference ((ValaCodeNode*) self);
923 _tmp25_ = _tmp24_;
924 _tmp26_ = vala_statement_list_new (_tmp25_);
925 _vala_code_node_unref0 (stmt_list);
926 stmt_list = _tmp26_;
927 _tmp27_ = stmt_list;
928 vala_statement_list_add (_tmp27_, new_stmt);
929 _tmp28_ = stmt_list;
930 vala_statement_list_add (_tmp28_, stmt);
931 _tmp29_ = self->priv->statement_list;
932 _tmp30_ = stmt_list;
933 vala_list_set (_tmp29_, i, (ValaStatement*) _tmp30_);
934 vala_code_node_set_parent_node ((ValaCodeNode*) new_stmt, (ValaCodeNode*) self);
935 }
936 }
937 _vala_code_node_unref0 (stmt_list);
938 }
939 }
940 }
941 }
942
943 void
vala_block_replace_statement(ValaBlock * self,ValaStatement * old_stmt,ValaStatement * new_stmt)944 vala_block_replace_statement (ValaBlock* self,
945 ValaStatement* old_stmt,
946 ValaStatement* new_stmt)
947 {
948 g_return_if_fail (self != NULL);
949 g_return_if_fail (old_stmt != NULL);
950 g_return_if_fail (new_stmt != NULL);
951 {
952 gint i = 0;
953 i = 0;
954 {
955 gboolean _tmp0_ = FALSE;
956 _tmp0_ = TRUE;
957 while (TRUE) {
958 ValaList* _tmp2_;
959 gint _tmp3_;
960 gint _tmp4_;
961 ValaStatementList* stmt_list = NULL;
962 ValaList* _tmp5_;
963 gpointer _tmp6_;
964 ValaStatement* _tmp7_;
965 ValaStatementList* _tmp8_;
966 ValaStatementList* _tmp9_;
967 if (!_tmp0_) {
968 gint _tmp1_;
969 _tmp1_ = i;
970 i = _tmp1_ + 1;
971 }
972 _tmp0_ = FALSE;
973 _tmp2_ = self->priv->statement_list;
974 _tmp3_ = vala_collection_get_size ((ValaCollection*) _tmp2_);
975 _tmp4_ = _tmp3_;
976 if (!(i < _tmp4_)) {
977 break;
978 }
979 _tmp5_ = self->priv->statement_list;
980 _tmp6_ = vala_list_get (_tmp5_, i);
981 _tmp7_ = (ValaStatement*) _tmp6_;
982 _tmp8_ = VALA_IS_STATEMENT_LIST (_tmp7_) ? ((ValaStatementList*) _tmp7_) : NULL;
983 if (_tmp8_ == NULL) {
984 _vala_code_node_unref0 (_tmp7_);
985 }
986 stmt_list = _tmp8_;
987 _tmp9_ = stmt_list;
988 if (_tmp9_ != NULL) {
989 {
990 gint j = 0;
991 j = 0;
992 {
993 gboolean _tmp10_ = FALSE;
994 _tmp10_ = TRUE;
995 while (TRUE) {
996 ValaStatementList* _tmp12_;
997 gint _tmp13_;
998 gint _tmp14_;
999 ValaStatementList* _tmp15_;
1000 ValaStatement* _tmp16_;
1001 ValaStatement* _tmp17_;
1002 gboolean _tmp18_;
1003 if (!_tmp10_) {
1004 gint _tmp11_;
1005 _tmp11_ = j;
1006 j = _tmp11_ + 1;
1007 }
1008 _tmp10_ = FALSE;
1009 _tmp12_ = stmt_list;
1010 _tmp13_ = vala_statement_list_get_length (_tmp12_);
1011 _tmp14_ = _tmp13_;
1012 if (!(j < _tmp14_)) {
1013 break;
1014 }
1015 _tmp15_ = stmt_list;
1016 _tmp16_ = vala_statement_list_get (_tmp15_, j);
1017 _tmp17_ = _tmp16_;
1018 _tmp18_ = _tmp17_ == old_stmt;
1019 _vala_code_node_unref0 (_tmp17_);
1020 if (_tmp18_) {
1021 ValaStatementList* _tmp19_;
1022 _tmp19_ = stmt_list;
1023 vala_statement_list_set (_tmp19_, j, new_stmt);
1024 vala_code_node_set_parent_node ((ValaCodeNode*) new_stmt, (ValaCodeNode*) self);
1025 break;
1026 }
1027 }
1028 }
1029 }
1030 } else {
1031 ValaList* _tmp20_;
1032 gpointer _tmp21_;
1033 ValaStatement* _tmp22_;
1034 gboolean _tmp23_;
1035 _tmp20_ = self->priv->statement_list;
1036 _tmp21_ = vala_list_get (_tmp20_, i);
1037 _tmp22_ = (ValaStatement*) _tmp21_;
1038 _tmp23_ = _tmp22_ == old_stmt;
1039 _vala_code_node_unref0 (_tmp22_);
1040 if (_tmp23_) {
1041 ValaList* _tmp24_;
1042 _tmp24_ = self->priv->statement_list;
1043 vala_list_set (_tmp24_, i, new_stmt);
1044 vala_code_node_set_parent_node ((ValaCodeNode*) new_stmt, (ValaCodeNode*) self);
1045 _vala_code_node_unref0 (stmt_list);
1046 break;
1047 }
1048 }
1049 _vala_code_node_unref0 (stmt_list);
1050 }
1051 }
1052 }
1053 }
1054
1055 static void
vala_block_class_init(ValaBlockClass * klass,gpointer klass_data)1056 vala_block_class_init (ValaBlockClass * klass,
1057 gpointer klass_data)
1058 {
1059 vala_block_parent_class = g_type_class_peek_parent (klass);
1060 ((ValaCodeNodeClass *) klass)->finalize = vala_block_finalize;
1061 g_type_class_adjust_private_offset (klass, &ValaBlock_private_offset);
1062 ((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_block_real_accept;
1063 ((ValaCodeNodeClass *) klass)->accept_children = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_block_real_accept_children;
1064 ((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode*, ValaCodeContext*)) vala_block_real_check;
1065 ((ValaCodeNodeClass *) klass)->get_error_types = (void (*) (ValaCodeNode*, ValaCollection*, ValaSourceReference*)) vala_block_real_get_error_types;
1066 ((ValaCodeNodeClass *) klass)->emit = (void (*) (ValaCodeNode*, ValaCodeGenerator*)) vala_block_real_emit;
1067 }
1068
1069 static void
vala_block_vala_statement_interface_init(ValaStatementIface * iface,gpointer iface_data)1070 vala_block_vala_statement_interface_init (ValaStatementIface * iface,
1071 gpointer iface_data)
1072 {
1073 vala_block_vala_statement_parent_iface = g_type_interface_peek_parent (iface);
1074 }
1075
1076 static void
vala_block_instance_init(ValaBlock * self,gpointer klass)1077 vala_block_instance_init (ValaBlock * self,
1078 gpointer klass)
1079 {
1080 GEqualFunc _tmp0_;
1081 ValaArrayList* _tmp1_;
1082 GEqualFunc _tmp2_;
1083 ValaArrayList* _tmp3_;
1084 GEqualFunc _tmp4_;
1085 ValaArrayList* _tmp5_;
1086 self->priv = vala_block_get_instance_private (self);
1087 _tmp0_ = g_direct_equal;
1088 _tmp1_ = vala_array_list_new (VALA_TYPE_STATEMENT, (GBoxedCopyFunc) vala_code_node_ref, (GDestroyNotify) vala_code_node_unref, _tmp0_);
1089 self->priv->statement_list = (ValaList*) _tmp1_;
1090 _tmp2_ = g_direct_equal;
1091 _tmp3_ = vala_array_list_new (VALA_TYPE_LOCAL_VARIABLE, (GBoxedCopyFunc) vala_code_node_ref, (GDestroyNotify) vala_code_node_unref, _tmp2_);
1092 self->priv->local_variables = (ValaList*) _tmp3_;
1093 _tmp4_ = g_direct_equal;
1094 _tmp5_ = vala_array_list_new (VALA_TYPE_CONSTANT, (GBoxedCopyFunc) vala_code_node_ref, (GDestroyNotify) vala_code_node_unref, _tmp4_);
1095 self->priv->local_constants = (ValaList*) _tmp5_;
1096 }
1097
1098 static void
vala_block_finalize(ValaCodeNode * obj)1099 vala_block_finalize (ValaCodeNode * obj)
1100 {
1101 ValaBlock * self;
1102 self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_BLOCK, ValaBlock);
1103 _vala_iterable_unref0 (self->priv->statement_list);
1104 _vala_iterable_unref0 (self->priv->local_variables);
1105 _vala_iterable_unref0 (self->priv->local_constants);
1106 VALA_CODE_NODE_CLASS (vala_block_parent_class)->finalize (obj);
1107 }
1108
1109 /**
1110 * Represents a source code block.
1111 */
1112 static GType
vala_block_get_type_once(void)1113 vala_block_get_type_once (void)
1114 {
1115 static const GTypeInfo g_define_type_info = { sizeof (ValaBlockClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_block_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaBlock), 0, (GInstanceInitFunc) vala_block_instance_init, NULL };
1116 static const GInterfaceInfo vala_statement_info = { (GInterfaceInitFunc) vala_block_vala_statement_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
1117 GType vala_block_type_id;
1118 vala_block_type_id = g_type_register_static (VALA_TYPE_SYMBOL, "ValaBlock", &g_define_type_info, 0);
1119 g_type_add_interface_static (vala_block_type_id, VALA_TYPE_STATEMENT, &vala_statement_info);
1120 ValaBlock_private_offset = g_type_add_instance_private (vala_block_type_id, sizeof (ValaBlockPrivate));
1121 return vala_block_type_id;
1122 }
1123
1124 GType
vala_block_get_type(void)1125 vala_block_get_type (void)
1126 {
1127 static volatile gsize vala_block_type_id__volatile = 0;
1128 if (g_once_init_enter (&vala_block_type_id__volatile)) {
1129 GType vala_block_type_id;
1130 vala_block_type_id = vala_block_get_type_once ();
1131 g_once_init_leave (&vala_block_type_id__volatile, vala_block_type_id);
1132 }
1133 return vala_block_type_id__volatile;
1134 }
1135
1136