1 /* valaifstatement.c generated by valac, the Vala compiler
2  * generated from valaifstatement.vala, do not modify */
3 
4 /* valaifstatement.vala
5  *
6  * Copyright (C) 2006-2010  Jürg Billeter
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12 
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17 
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
21  *
22  * Author:
23  * 	Jürg Billeter <j@bitron.ch>
24  */
25 
26 #include "vala.h"
27 #include <valagee.h>
28 #include <glib-object.h>
29 #include <glib.h>
30 
31 #define _vala_code_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_node_unref (var), NULL)))
32 
33 struct _ValaIfStatementPrivate {
34 	ValaExpression* _condition;
35 	ValaBlock* _true_statement;
36 	ValaBlock* _false_statement;
37 };
38 
39 static gint ValaIfStatement_private_offset;
40 static gpointer vala_if_statement_parent_class = NULL;
41 static ValaStatementIface * vala_if_statement_vala_statement_parent_iface = NULL;
42 
43 static void vala_if_statement_real_accept (ValaCodeNode* base,
44                                     ValaCodeVisitor* visitor);
45 static void vala_if_statement_real_accept_children (ValaCodeNode* base,
46                                              ValaCodeVisitor* visitor);
47 static void vala_if_statement_real_replace_expression (ValaCodeNode* base,
48                                                 ValaExpression* old_node,
49                                                 ValaExpression* new_node);
50 static void vala_if_statement_real_get_error_types (ValaCodeNode* base,
51                                              ValaCollection* collection,
52                                              ValaSourceReference* source_reference);
53 static gboolean vala_if_statement_real_check (ValaCodeNode* base,
54                                        ValaCodeContext* context);
55 static void vala_if_statement_real_emit (ValaCodeNode* base,
56                                   ValaCodeGenerator* codegen);
57 static void vala_if_statement_finalize (ValaCodeNode * obj);
58 static GType vala_if_statement_get_type_once (void);
59 
60 static inline gpointer
vala_if_statement_get_instance_private(ValaIfStatement * self)61 vala_if_statement_get_instance_private (ValaIfStatement* self)
62 {
63 	return G_STRUCT_MEMBER_P (self, ValaIfStatement_private_offset);
64 }
65 
66 ValaExpression*
vala_if_statement_get_condition(ValaIfStatement * self)67 vala_if_statement_get_condition (ValaIfStatement* self)
68 {
69 	ValaExpression* result;
70 	ValaExpression* _tmp0_;
71 	g_return_val_if_fail (self != NULL, NULL);
72 	_tmp0_ = self->priv->_condition;
73 	result = _tmp0_;
74 	return result;
75 }
76 
77 static gpointer
_vala_code_node_ref0(gpointer self)78 _vala_code_node_ref0 (gpointer self)
79 {
80 	return self ? vala_code_node_ref (self) : NULL;
81 }
82 
83 void
vala_if_statement_set_condition(ValaIfStatement * self,ValaExpression * value)84 vala_if_statement_set_condition (ValaIfStatement* self,
85                                  ValaExpression* value)
86 {
87 	ValaExpression* _tmp0_;
88 	ValaExpression* _tmp1_;
89 	g_return_if_fail (self != NULL);
90 	_tmp0_ = _vala_code_node_ref0 (value);
91 	_vala_code_node_unref0 (self->priv->_condition);
92 	self->priv->_condition = _tmp0_;
93 	_tmp1_ = self->priv->_condition;
94 	vala_code_node_set_parent_node ((ValaCodeNode*) _tmp1_, (ValaCodeNode*) self);
95 }
96 
97 ValaBlock*
vala_if_statement_get_true_statement(ValaIfStatement * self)98 vala_if_statement_get_true_statement (ValaIfStatement* self)
99 {
100 	ValaBlock* result;
101 	ValaBlock* _tmp0_;
102 	g_return_val_if_fail (self != NULL, NULL);
103 	_tmp0_ = self->priv->_true_statement;
104 	result = _tmp0_;
105 	return result;
106 }
107 
108 void
vala_if_statement_set_true_statement(ValaIfStatement * self,ValaBlock * value)109 vala_if_statement_set_true_statement (ValaIfStatement* self,
110                                       ValaBlock* value)
111 {
112 	ValaBlock* _tmp0_;
113 	ValaBlock* _tmp1_;
114 	g_return_if_fail (self != NULL);
115 	_tmp0_ = _vala_code_node_ref0 (value);
116 	_vala_code_node_unref0 (self->priv->_true_statement);
117 	self->priv->_true_statement = _tmp0_;
118 	_tmp1_ = self->priv->_true_statement;
119 	vala_code_node_set_parent_node ((ValaCodeNode*) _tmp1_, (ValaCodeNode*) self);
120 }
121 
122 ValaBlock*
vala_if_statement_get_false_statement(ValaIfStatement * self)123 vala_if_statement_get_false_statement (ValaIfStatement* self)
124 {
125 	ValaBlock* result;
126 	ValaBlock* _tmp0_;
127 	g_return_val_if_fail (self != NULL, NULL);
128 	_tmp0_ = self->priv->_false_statement;
129 	result = _tmp0_;
130 	return result;
131 }
132 
133 void
vala_if_statement_set_false_statement(ValaIfStatement * self,ValaBlock * value)134 vala_if_statement_set_false_statement (ValaIfStatement* self,
135                                        ValaBlock* value)
136 {
137 	ValaBlock* _tmp0_;
138 	ValaBlock* _tmp1_;
139 	g_return_if_fail (self != NULL);
140 	_tmp0_ = _vala_code_node_ref0 (value);
141 	_vala_code_node_unref0 (self->priv->_false_statement);
142 	self->priv->_false_statement = _tmp0_;
143 	_tmp1_ = self->priv->_false_statement;
144 	if (_tmp1_ != NULL) {
145 		ValaBlock* _tmp2_;
146 		_tmp2_ = self->priv->_false_statement;
147 		vala_code_node_set_parent_node ((ValaCodeNode*) _tmp2_, (ValaCodeNode*) self);
148 	}
149 }
150 
151 /**
152  * Creates a new if statement.
153  *
154  * @param cond       a boolean condition
155  * @param true_stmt  statement to be evaluated if condition is true
156  * @param false_stmt statement to be evaluated if condition is false
157  * @return           newly created if statement
158  */
159 ValaIfStatement*
vala_if_statement_construct(GType object_type,ValaExpression * cond,ValaBlock * true_stmt,ValaBlock * false_stmt,ValaSourceReference * source)160 vala_if_statement_construct (GType object_type,
161                              ValaExpression* cond,
162                              ValaBlock* true_stmt,
163                              ValaBlock* false_stmt,
164                              ValaSourceReference* source)
165 {
166 	ValaIfStatement* self = NULL;
167 	g_return_val_if_fail (cond != NULL, NULL);
168 	g_return_val_if_fail (true_stmt != NULL, NULL);
169 	self = (ValaIfStatement*) vala_code_node_construct (object_type);
170 	vala_if_statement_set_condition (self, cond);
171 	vala_if_statement_set_true_statement (self, true_stmt);
172 	vala_if_statement_set_false_statement (self, false_stmt);
173 	vala_code_node_set_source_reference ((ValaCodeNode*) self, source);
174 	return self;
175 }
176 
177 ValaIfStatement*
vala_if_statement_new(ValaExpression * cond,ValaBlock * true_stmt,ValaBlock * false_stmt,ValaSourceReference * source)178 vala_if_statement_new (ValaExpression* cond,
179                        ValaBlock* true_stmt,
180                        ValaBlock* false_stmt,
181                        ValaSourceReference* source)
182 {
183 	return vala_if_statement_construct (VALA_TYPE_IF_STATEMENT, cond, true_stmt, false_stmt, source);
184 }
185 
186 static void
vala_if_statement_real_accept(ValaCodeNode * base,ValaCodeVisitor * visitor)187 vala_if_statement_real_accept (ValaCodeNode* base,
188                                ValaCodeVisitor* visitor)
189 {
190 	ValaIfStatement * self;
191 	self = (ValaIfStatement*) base;
192 	g_return_if_fail (visitor != NULL);
193 	vala_code_visitor_visit_if_statement (visitor, self);
194 }
195 
196 static void
vala_if_statement_real_accept_children(ValaCodeNode * base,ValaCodeVisitor * visitor)197 vala_if_statement_real_accept_children (ValaCodeNode* base,
198                                         ValaCodeVisitor* visitor)
199 {
200 	ValaIfStatement * self;
201 	ValaExpression* _tmp0_;
202 	ValaExpression* _tmp1_;
203 	ValaExpression* _tmp2_;
204 	ValaExpression* _tmp3_;
205 	ValaBlock* _tmp4_;
206 	ValaBlock* _tmp5_;
207 	ValaBlock* _tmp6_;
208 	ValaBlock* _tmp7_;
209 	self = (ValaIfStatement*) base;
210 	g_return_if_fail (visitor != NULL);
211 	_tmp0_ = vala_if_statement_get_condition (self);
212 	_tmp1_ = _tmp0_;
213 	vala_code_node_accept ((ValaCodeNode*) _tmp1_, visitor);
214 	_tmp2_ = vala_if_statement_get_condition (self);
215 	_tmp3_ = _tmp2_;
216 	vala_code_visitor_visit_end_full_expression (visitor, _tmp3_);
217 	_tmp4_ = vala_if_statement_get_true_statement (self);
218 	_tmp5_ = _tmp4_;
219 	vala_code_node_accept ((ValaCodeNode*) _tmp5_, visitor);
220 	_tmp6_ = vala_if_statement_get_false_statement (self);
221 	_tmp7_ = _tmp6_;
222 	if (_tmp7_ != NULL) {
223 		ValaBlock* _tmp8_;
224 		ValaBlock* _tmp9_;
225 		_tmp8_ = vala_if_statement_get_false_statement (self);
226 		_tmp9_ = _tmp8_;
227 		vala_code_node_accept ((ValaCodeNode*) _tmp9_, visitor);
228 	}
229 }
230 
231 static void
vala_if_statement_real_replace_expression(ValaCodeNode * base,ValaExpression * old_node,ValaExpression * new_node)232 vala_if_statement_real_replace_expression (ValaCodeNode* base,
233                                            ValaExpression* old_node,
234                                            ValaExpression* new_node)
235 {
236 	ValaIfStatement * self;
237 	ValaExpression* _tmp0_;
238 	ValaExpression* _tmp1_;
239 	self = (ValaIfStatement*) base;
240 	g_return_if_fail (old_node != NULL);
241 	g_return_if_fail (new_node != NULL);
242 	_tmp0_ = vala_if_statement_get_condition (self);
243 	_tmp1_ = _tmp0_;
244 	if (_tmp1_ == old_node) {
245 		vala_if_statement_set_condition (self, new_node);
246 	}
247 }
248 
249 static void
vala_if_statement_real_get_error_types(ValaCodeNode * base,ValaCollection * collection,ValaSourceReference * source_reference)250 vala_if_statement_real_get_error_types (ValaCodeNode* base,
251                                         ValaCollection* collection,
252                                         ValaSourceReference* source_reference)
253 {
254 	ValaIfStatement * self;
255 	ValaExpression* _tmp0_;
256 	ValaExpression* _tmp1_;
257 	ValaBlock* _tmp2_;
258 	ValaBlock* _tmp3_;
259 	ValaBlock* _tmp4_;
260 	ValaBlock* _tmp5_;
261 	self = (ValaIfStatement*) base;
262 	g_return_if_fail (collection != NULL);
263 	_tmp0_ = vala_if_statement_get_condition (self);
264 	_tmp1_ = _tmp0_;
265 	vala_code_node_get_error_types ((ValaCodeNode*) _tmp1_, collection, source_reference);
266 	_tmp2_ = vala_if_statement_get_true_statement (self);
267 	_tmp3_ = _tmp2_;
268 	vala_code_node_get_error_types ((ValaCodeNode*) _tmp3_, collection, source_reference);
269 	_tmp4_ = vala_if_statement_get_false_statement (self);
270 	_tmp5_ = _tmp4_;
271 	if (_tmp5_ != NULL) {
272 		ValaBlock* _tmp6_;
273 		ValaBlock* _tmp7_;
274 		_tmp6_ = vala_if_statement_get_false_statement (self);
275 		_tmp7_ = _tmp6_;
276 		vala_code_node_get_error_types ((ValaCodeNode*) _tmp7_, collection, source_reference);
277 	}
278 }
279 
280 static gboolean
vala_if_statement_real_check(ValaCodeNode * base,ValaCodeContext * context)281 vala_if_statement_real_check (ValaCodeNode* base,
282                               ValaCodeContext* context)
283 {
284 	ValaIfStatement * self;
285 	gboolean _tmp0_;
286 	gboolean _tmp1_;
287 	ValaExpression* _tmp4_;
288 	ValaExpression* _tmp5_;
289 	ValaSemanticAnalyzer* _tmp6_;
290 	ValaSemanticAnalyzer* _tmp7_;
291 	ValaDataType* _tmp8_;
292 	ValaDataType* _tmp9_;
293 	ValaDataType* _tmp10_;
294 	ValaExpression* _tmp11_;
295 	ValaExpression* _tmp12_;
296 	ValaBlock* _tmp13_;
297 	ValaBlock* _tmp14_;
298 	ValaBlock* _tmp15_;
299 	ValaBlock* _tmp16_;
300 	ValaExpression* _tmp19_;
301 	ValaExpression* _tmp20_;
302 	gboolean _tmp21_;
303 	gboolean _tmp22_;
304 	gboolean _tmp23_ = FALSE;
305 	ValaExpression* _tmp24_;
306 	ValaExpression* _tmp25_;
307 	ValaDataType* _tmp26_;
308 	ValaDataType* _tmp27_;
309 	gboolean _tmp39_;
310 	gboolean _tmp40_;
311 	gboolean result = FALSE;
312 	self = (ValaIfStatement*) base;
313 	g_return_val_if_fail (context != NULL, FALSE);
314 	_tmp0_ = vala_code_node_get_checked ((ValaCodeNode*) self);
315 	_tmp1_ = _tmp0_;
316 	if (_tmp1_) {
317 		gboolean _tmp2_;
318 		gboolean _tmp3_;
319 		_tmp2_ = vala_code_node_get_error ((ValaCodeNode*) self);
320 		_tmp3_ = _tmp2_;
321 		result = !_tmp3_;
322 		return result;
323 	}
324 	vala_code_node_set_checked ((ValaCodeNode*) self, TRUE);
325 	_tmp4_ = vala_if_statement_get_condition (self);
326 	_tmp5_ = _tmp4_;
327 	_tmp6_ = vala_code_context_get_analyzer (context);
328 	_tmp7_ = _tmp6_;
329 	_tmp8_ = _tmp7_->bool_type;
330 	_tmp9_ = vala_data_type_copy (_tmp8_);
331 	_tmp10_ = _tmp9_;
332 	vala_expression_set_target_type (_tmp5_, _tmp10_);
333 	_vala_code_node_unref0 (_tmp10_);
334 	_tmp11_ = vala_if_statement_get_condition (self);
335 	_tmp12_ = _tmp11_;
336 	vala_code_node_check ((ValaCodeNode*) _tmp12_, context);
337 	_tmp13_ = vala_if_statement_get_true_statement (self);
338 	_tmp14_ = _tmp13_;
339 	vala_code_node_check ((ValaCodeNode*) _tmp14_, context);
340 	_tmp15_ = vala_if_statement_get_false_statement (self);
341 	_tmp16_ = _tmp15_;
342 	if (_tmp16_ != NULL) {
343 		ValaBlock* _tmp17_;
344 		ValaBlock* _tmp18_;
345 		_tmp17_ = vala_if_statement_get_false_statement (self);
346 		_tmp18_ = _tmp17_;
347 		vala_code_node_check ((ValaCodeNode*) _tmp18_, context);
348 	}
349 	_tmp19_ = vala_if_statement_get_condition (self);
350 	_tmp20_ = _tmp19_;
351 	_tmp21_ = vala_code_node_get_error ((ValaCodeNode*) _tmp20_);
352 	_tmp22_ = _tmp21_;
353 	if (_tmp22_) {
354 		vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
355 		result = FALSE;
356 		return result;
357 	}
358 	_tmp24_ = vala_if_statement_get_condition (self);
359 	_tmp25_ = _tmp24_;
360 	_tmp26_ = vala_expression_get_value_type (_tmp25_);
361 	_tmp27_ = _tmp26_;
362 	if (_tmp27_ == NULL) {
363 		_tmp23_ = TRUE;
364 	} else {
365 		ValaExpression* _tmp28_;
366 		ValaExpression* _tmp29_;
367 		ValaDataType* _tmp30_;
368 		ValaDataType* _tmp31_;
369 		ValaSemanticAnalyzer* _tmp32_;
370 		ValaSemanticAnalyzer* _tmp33_;
371 		ValaDataType* _tmp34_;
372 		_tmp28_ = vala_if_statement_get_condition (self);
373 		_tmp29_ = _tmp28_;
374 		_tmp30_ = vala_expression_get_value_type (_tmp29_);
375 		_tmp31_ = _tmp30_;
376 		_tmp32_ = vala_code_context_get_analyzer (context);
377 		_tmp33_ = _tmp32_;
378 		_tmp34_ = _tmp33_->bool_type;
379 		_tmp23_ = !vala_data_type_compatible (_tmp31_, _tmp34_);
380 	}
381 	if (_tmp23_) {
382 		ValaExpression* _tmp35_;
383 		ValaExpression* _tmp36_;
384 		ValaSourceReference* _tmp37_;
385 		ValaSourceReference* _tmp38_;
386 		vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
387 		_tmp35_ = vala_if_statement_get_condition (self);
388 		_tmp36_ = _tmp35_;
389 		_tmp37_ = vala_code_node_get_source_reference ((ValaCodeNode*) _tmp36_);
390 		_tmp38_ = _tmp37_;
391 		vala_report_error (_tmp38_, "Condition must be boolean");
392 		result = FALSE;
393 		return result;
394 	}
395 	_tmp39_ = vala_code_node_get_error ((ValaCodeNode*) self);
396 	_tmp40_ = _tmp39_;
397 	result = !_tmp40_;
398 	return result;
399 }
400 
401 static void
vala_if_statement_real_emit(ValaCodeNode * base,ValaCodeGenerator * codegen)402 vala_if_statement_real_emit (ValaCodeNode* base,
403                              ValaCodeGenerator* codegen)
404 {
405 	ValaIfStatement * self;
406 	ValaExpression* _tmp0_;
407 	ValaExpression* _tmp1_;
408 	ValaExpression* _tmp2_;
409 	ValaExpression* _tmp3_;
410 	self = (ValaIfStatement*) base;
411 	g_return_if_fail (codegen != NULL);
412 	_tmp0_ = vala_if_statement_get_condition (self);
413 	_tmp1_ = _tmp0_;
414 	vala_code_node_emit ((ValaCodeNode*) _tmp1_, codegen);
415 	_tmp2_ = vala_if_statement_get_condition (self);
416 	_tmp3_ = _tmp2_;
417 	vala_code_visitor_visit_end_full_expression ((ValaCodeVisitor*) codegen, _tmp3_);
418 	vala_code_visitor_visit_if_statement ((ValaCodeVisitor*) codegen, self);
419 }
420 
421 static void
vala_if_statement_class_init(ValaIfStatementClass * klass,gpointer klass_data)422 vala_if_statement_class_init (ValaIfStatementClass * klass,
423                               gpointer klass_data)
424 {
425 	vala_if_statement_parent_class = g_type_class_peek_parent (klass);
426 	((ValaCodeNodeClass *) klass)->finalize = vala_if_statement_finalize;
427 	g_type_class_adjust_private_offset (klass, &ValaIfStatement_private_offset);
428 	((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_if_statement_real_accept;
429 	((ValaCodeNodeClass *) klass)->accept_children = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_if_statement_real_accept_children;
430 	((ValaCodeNodeClass *) klass)->replace_expression = (void (*) (ValaCodeNode*, ValaExpression*, ValaExpression*)) vala_if_statement_real_replace_expression;
431 	((ValaCodeNodeClass *) klass)->get_error_types = (void (*) (ValaCodeNode*, ValaCollection*, ValaSourceReference*)) vala_if_statement_real_get_error_types;
432 	((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode*, ValaCodeContext*)) vala_if_statement_real_check;
433 	((ValaCodeNodeClass *) klass)->emit = (void (*) (ValaCodeNode*, ValaCodeGenerator*)) vala_if_statement_real_emit;
434 }
435 
436 static void
vala_if_statement_vala_statement_interface_init(ValaStatementIface * iface,gpointer iface_data)437 vala_if_statement_vala_statement_interface_init (ValaStatementIface * iface,
438                                                  gpointer iface_data)
439 {
440 	vala_if_statement_vala_statement_parent_iface = g_type_interface_peek_parent (iface);
441 }
442 
443 static void
vala_if_statement_instance_init(ValaIfStatement * self,gpointer klass)444 vala_if_statement_instance_init (ValaIfStatement * self,
445                                  gpointer klass)
446 {
447 	self->priv = vala_if_statement_get_instance_private (self);
448 }
449 
450 static void
vala_if_statement_finalize(ValaCodeNode * obj)451 vala_if_statement_finalize (ValaCodeNode * obj)
452 {
453 	ValaIfStatement * self;
454 	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_IF_STATEMENT, ValaIfStatement);
455 	_vala_code_node_unref0 (self->priv->_condition);
456 	_vala_code_node_unref0 (self->priv->_true_statement);
457 	_vala_code_node_unref0 (self->priv->_false_statement);
458 	VALA_CODE_NODE_CLASS (vala_if_statement_parent_class)->finalize (obj);
459 }
460 
461 /**
462  * Represents an if selection statement in the source code.
463  */
464 static GType
vala_if_statement_get_type_once(void)465 vala_if_statement_get_type_once (void)
466 {
467 	static const GTypeInfo g_define_type_info = { sizeof (ValaIfStatementClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_if_statement_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaIfStatement), 0, (GInstanceInitFunc) vala_if_statement_instance_init, NULL };
468 	static const GInterfaceInfo vala_statement_info = { (GInterfaceInitFunc) vala_if_statement_vala_statement_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
469 	GType vala_if_statement_type_id;
470 	vala_if_statement_type_id = g_type_register_static (VALA_TYPE_CODE_NODE, "ValaIfStatement", &g_define_type_info, 0);
471 	g_type_add_interface_static (vala_if_statement_type_id, VALA_TYPE_STATEMENT, &vala_statement_info);
472 	ValaIfStatement_private_offset = g_type_add_instance_private (vala_if_statement_type_id, sizeof (ValaIfStatementPrivate));
473 	return vala_if_statement_type_id;
474 }
475 
476 GType
vala_if_statement_get_type(void)477 vala_if_statement_get_type (void)
478 {
479 	static volatile gsize vala_if_statement_type_id__volatile = 0;
480 	if (g_once_init_enter (&vala_if_statement_type_id__volatile)) {
481 		GType vala_if_statement_type_id;
482 		vala_if_statement_type_id = vala_if_statement_get_type_once ();
483 		g_once_init_leave (&vala_if_statement_type_id__volatile, vala_if_statement_type_id);
484 	}
485 	return vala_if_statement_type_id__volatile;
486 }
487 
488