1 /* valawhilestatement.c generated by valac, the Vala compiler
2  * generated from valawhilestatement.vala, do not modify */
3 
4 /* valawhilestatement.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 
29 #define _vala_code_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_node_unref (var), NULL)))
30 
31 struct _ValaWhileStatementPrivate {
32 	ValaExpression* _condition;
33 	ValaBlock* _body;
34 };
35 
36 static gint ValaWhileStatement_private_offset;
37 static gpointer vala_while_statement_parent_class = NULL;
38 static ValaStatementIface * vala_while_statement_vala_statement_parent_iface = NULL;
39 
40 static void vala_while_statement_real_accept (ValaCodeNode* base,
41                                        ValaCodeVisitor* visitor);
42 static void vala_while_statement_real_accept_children (ValaCodeNode* base,
43                                                 ValaCodeVisitor* visitor);
44 static gboolean vala_while_statement_always_true (ValaWhileStatement* self,
45                                            ValaExpression* condition);
46 static gboolean vala_while_statement_always_false (ValaWhileStatement* self,
47                                             ValaExpression* condition);
48 static void vala_while_statement_real_replace_expression (ValaCodeNode* base,
49                                                    ValaExpression* old_node,
50                                                    ValaExpression* new_node);
51 static gboolean vala_while_statement_real_check (ValaCodeNode* base,
52                                           ValaCodeContext* context);
53 static void vala_while_statement_finalize (ValaCodeNode * obj);
54 static GType vala_while_statement_get_type_once (void);
55 
56 static inline gpointer
vala_while_statement_get_instance_private(ValaWhileStatement * self)57 vala_while_statement_get_instance_private (ValaWhileStatement* self)
58 {
59 	return G_STRUCT_MEMBER_P (self, ValaWhileStatement_private_offset);
60 }
61 
62 ValaExpression*
vala_while_statement_get_condition(ValaWhileStatement * self)63 vala_while_statement_get_condition (ValaWhileStatement* self)
64 {
65 	ValaExpression* result;
66 	ValaExpression* _tmp0_;
67 	g_return_val_if_fail (self != NULL, NULL);
68 	_tmp0_ = self->priv->_condition;
69 	result = _tmp0_;
70 	return result;
71 }
72 
73 static gpointer
_vala_code_node_ref0(gpointer self)74 _vala_code_node_ref0 (gpointer self)
75 {
76 	return self ? vala_code_node_ref (self) : NULL;
77 }
78 
79 void
vala_while_statement_set_condition(ValaWhileStatement * self,ValaExpression * value)80 vala_while_statement_set_condition (ValaWhileStatement* self,
81                                     ValaExpression* value)
82 {
83 	ValaExpression* _tmp0_;
84 	ValaExpression* _tmp1_;
85 	g_return_if_fail (self != NULL);
86 	_tmp0_ = _vala_code_node_ref0 (value);
87 	_vala_code_node_unref0 (self->priv->_condition);
88 	self->priv->_condition = _tmp0_;
89 	_tmp1_ = self->priv->_condition;
90 	vala_code_node_set_parent_node ((ValaCodeNode*) _tmp1_, (ValaCodeNode*) self);
91 }
92 
93 ValaBlock*
vala_while_statement_get_body(ValaWhileStatement * self)94 vala_while_statement_get_body (ValaWhileStatement* self)
95 {
96 	ValaBlock* result;
97 	ValaBlock* _tmp0_;
98 	g_return_val_if_fail (self != NULL, NULL);
99 	_tmp0_ = self->priv->_body;
100 	result = _tmp0_;
101 	return result;
102 }
103 
104 void
vala_while_statement_set_body(ValaWhileStatement * self,ValaBlock * value)105 vala_while_statement_set_body (ValaWhileStatement* self,
106                                ValaBlock* value)
107 {
108 	ValaBlock* _tmp0_;
109 	ValaBlock* _tmp1_;
110 	g_return_if_fail (self != NULL);
111 	_tmp0_ = _vala_code_node_ref0 (value);
112 	_vala_code_node_unref0 (self->priv->_body);
113 	self->priv->_body = _tmp0_;
114 	_tmp1_ = self->priv->_body;
115 	vala_code_node_set_parent_node ((ValaCodeNode*) _tmp1_, (ValaCodeNode*) self);
116 }
117 
118 /**
119  * Creates a new while statement.
120  *
121  * @param condition         loop condition
122  * @param body              loop body
123  * @param source_reference  reference to source code
124  * @return                  newly created while statement
125  */
126 ValaWhileStatement*
vala_while_statement_construct(GType object_type,ValaExpression * condition,ValaBlock * body,ValaSourceReference * source_reference)127 vala_while_statement_construct (GType object_type,
128                                 ValaExpression* condition,
129                                 ValaBlock* body,
130                                 ValaSourceReference* source_reference)
131 {
132 	ValaWhileStatement* self = NULL;
133 	g_return_val_if_fail (condition != NULL, NULL);
134 	g_return_val_if_fail (body != NULL, NULL);
135 	self = (ValaWhileStatement*) vala_code_node_construct (object_type);
136 	vala_while_statement_set_body (self, body);
137 	vala_code_node_set_source_reference ((ValaCodeNode*) self, source_reference);
138 	vala_while_statement_set_condition (self, condition);
139 	return self;
140 }
141 
142 ValaWhileStatement*
vala_while_statement_new(ValaExpression * condition,ValaBlock * body,ValaSourceReference * source_reference)143 vala_while_statement_new (ValaExpression* condition,
144                           ValaBlock* body,
145                           ValaSourceReference* source_reference)
146 {
147 	return vala_while_statement_construct (VALA_TYPE_WHILE_STATEMENT, condition, body, source_reference);
148 }
149 
150 static void
vala_while_statement_real_accept(ValaCodeNode * base,ValaCodeVisitor * visitor)151 vala_while_statement_real_accept (ValaCodeNode* base,
152                                   ValaCodeVisitor* visitor)
153 {
154 	ValaWhileStatement * self;
155 	self = (ValaWhileStatement*) base;
156 	g_return_if_fail (visitor != NULL);
157 	vala_code_visitor_visit_while_statement (visitor, self);
158 }
159 
160 static void
vala_while_statement_real_accept_children(ValaCodeNode * base,ValaCodeVisitor * visitor)161 vala_while_statement_real_accept_children (ValaCodeNode* base,
162                                            ValaCodeVisitor* visitor)
163 {
164 	ValaWhileStatement * self;
165 	ValaExpression* _tmp0_;
166 	ValaExpression* _tmp1_;
167 	ValaExpression* _tmp2_;
168 	ValaExpression* _tmp3_;
169 	ValaBlock* _tmp4_;
170 	ValaBlock* _tmp5_;
171 	self = (ValaWhileStatement*) base;
172 	g_return_if_fail (visitor != NULL);
173 	_tmp0_ = vala_while_statement_get_condition (self);
174 	_tmp1_ = _tmp0_;
175 	vala_code_node_accept ((ValaCodeNode*) _tmp1_, visitor);
176 	_tmp2_ = vala_while_statement_get_condition (self);
177 	_tmp3_ = _tmp2_;
178 	vala_code_visitor_visit_end_full_expression (visitor, _tmp3_);
179 	_tmp4_ = vala_while_statement_get_body (self);
180 	_tmp5_ = _tmp4_;
181 	vala_code_node_accept ((ValaCodeNode*) _tmp5_, visitor);
182 }
183 
184 static gboolean
vala_while_statement_always_true(ValaWhileStatement * self,ValaExpression * condition)185 vala_while_statement_always_true (ValaWhileStatement* self,
186                                   ValaExpression* condition)
187 {
188 	ValaBooleanLiteral* literal = NULL;
189 	gboolean _tmp0_ = FALSE;
190 	ValaBooleanLiteral* _tmp1_;
191 	gboolean result = FALSE;
192 	g_return_val_if_fail (self != NULL, FALSE);
193 	g_return_val_if_fail (condition != NULL, FALSE);
194 	literal = VALA_IS_BOOLEAN_LITERAL (condition) ? ((ValaBooleanLiteral*) condition) : NULL;
195 	_tmp1_ = literal;
196 	if (_tmp1_ != NULL) {
197 		ValaBooleanLiteral* _tmp2_;
198 		gboolean _tmp3_;
199 		gboolean _tmp4_;
200 		_tmp2_ = literal;
201 		_tmp3_ = vala_boolean_literal_get_value (_tmp2_);
202 		_tmp4_ = _tmp3_;
203 		_tmp0_ = _tmp4_;
204 	} else {
205 		_tmp0_ = FALSE;
206 	}
207 	result = _tmp0_;
208 	return result;
209 }
210 
211 static gboolean
vala_while_statement_always_false(ValaWhileStatement * self,ValaExpression * condition)212 vala_while_statement_always_false (ValaWhileStatement* self,
213                                    ValaExpression* condition)
214 {
215 	ValaBooleanLiteral* literal = NULL;
216 	gboolean _tmp0_ = FALSE;
217 	ValaBooleanLiteral* _tmp1_;
218 	gboolean result = FALSE;
219 	g_return_val_if_fail (self != NULL, FALSE);
220 	g_return_val_if_fail (condition != NULL, FALSE);
221 	literal = VALA_IS_BOOLEAN_LITERAL (condition) ? ((ValaBooleanLiteral*) condition) : NULL;
222 	_tmp1_ = literal;
223 	if (_tmp1_ != NULL) {
224 		ValaBooleanLiteral* _tmp2_;
225 		gboolean _tmp3_;
226 		gboolean _tmp4_;
227 		_tmp2_ = literal;
228 		_tmp3_ = vala_boolean_literal_get_value (_tmp2_);
229 		_tmp4_ = _tmp3_;
230 		_tmp0_ = !_tmp4_;
231 	} else {
232 		_tmp0_ = FALSE;
233 	}
234 	result = _tmp0_;
235 	return result;
236 }
237 
238 static void
vala_while_statement_real_replace_expression(ValaCodeNode * base,ValaExpression * old_node,ValaExpression * new_node)239 vala_while_statement_real_replace_expression (ValaCodeNode* base,
240                                               ValaExpression* old_node,
241                                               ValaExpression* new_node)
242 {
243 	ValaWhileStatement * self;
244 	ValaExpression* _tmp0_;
245 	ValaExpression* _tmp1_;
246 	self = (ValaWhileStatement*) base;
247 	g_return_if_fail (old_node != NULL);
248 	g_return_if_fail (new_node != NULL);
249 	_tmp0_ = vala_while_statement_get_condition (self);
250 	_tmp1_ = _tmp0_;
251 	if (_tmp1_ == old_node) {
252 		vala_while_statement_set_condition (self, new_node);
253 	}
254 }
255 
256 static gboolean
vala_while_statement_real_check(ValaCodeNode * base,ValaCodeContext * context)257 vala_while_statement_real_check (ValaCodeNode* base,
258                                  ValaCodeContext* context)
259 {
260 	ValaWhileStatement * self;
261 	gboolean _tmp0_;
262 	gboolean _tmp1_;
263 	ValaExpression* _tmp4_;
264 	ValaExpression* _tmp5_;
265 	ValaLoop* loop = NULL;
266 	ValaBlock* _tmp45_;
267 	ValaBlock* _tmp46_;
268 	ValaSourceReference* _tmp47_;
269 	ValaSourceReference* _tmp48_;
270 	ValaLoop* _tmp49_;
271 	ValaBlock* parent_block = NULL;
272 	ValaCodeNode* _tmp50_;
273 	ValaCodeNode* _tmp51_;
274 	ValaBlock* _tmp52_;
275 	ValaLoop* _tmp53_;
276 	ValaLoop* _tmp54_;
277 	gboolean _tmp55_;
278 	gboolean _tmp56_;
279 	gboolean result = FALSE;
280 	self = (ValaWhileStatement*) base;
281 	g_return_val_if_fail (context != NULL, FALSE);
282 	_tmp0_ = vala_code_node_get_checked ((ValaCodeNode*) self);
283 	_tmp1_ = _tmp0_;
284 	if (_tmp1_) {
285 		gboolean _tmp2_;
286 		gboolean _tmp3_;
287 		_tmp2_ = vala_code_node_get_error ((ValaCodeNode*) self);
288 		_tmp3_ = _tmp2_;
289 		result = !_tmp3_;
290 		return result;
291 	}
292 	vala_code_node_set_checked ((ValaCodeNode*) self, TRUE);
293 	_tmp4_ = vala_while_statement_get_condition (self);
294 	_tmp5_ = _tmp4_;
295 	if (vala_while_statement_always_true (self, _tmp5_)) {
296 	} else {
297 		ValaExpression* _tmp6_;
298 		ValaExpression* _tmp7_;
299 		_tmp6_ = vala_while_statement_get_condition (self);
300 		_tmp7_ = _tmp6_;
301 		if (vala_while_statement_always_false (self, _tmp7_)) {
302 			ValaBlock* _tmp8_;
303 			ValaBlock* _tmp9_;
304 			ValaExpression* _tmp10_;
305 			ValaExpression* _tmp11_;
306 			ValaSourceReference* _tmp12_;
307 			ValaSourceReference* _tmp13_;
308 			ValaBreakStatement* _tmp14_;
309 			ValaBreakStatement* _tmp15_;
310 			_tmp8_ = vala_while_statement_get_body (self);
311 			_tmp9_ = _tmp8_;
312 			_tmp10_ = vala_while_statement_get_condition (self);
313 			_tmp11_ = _tmp10_;
314 			_tmp12_ = vala_code_node_get_source_reference ((ValaCodeNode*) _tmp11_);
315 			_tmp13_ = _tmp12_;
316 			_tmp14_ = vala_break_statement_new (_tmp13_);
317 			_tmp15_ = _tmp14_;
318 			vala_block_insert_statement (_tmp9_, 0, (ValaStatement*) _tmp15_);
319 			_vala_code_node_unref0 (_tmp15_);
320 		} else {
321 			ValaUnaryExpression* if_condition = NULL;
322 			ValaExpression* _tmp16_;
323 			ValaExpression* _tmp17_;
324 			ValaExpression* _tmp18_;
325 			ValaExpression* _tmp19_;
326 			ValaSourceReference* _tmp20_;
327 			ValaSourceReference* _tmp21_;
328 			ValaUnaryExpression* _tmp22_;
329 			ValaBlock* true_block = NULL;
330 			ValaExpression* _tmp23_;
331 			ValaExpression* _tmp24_;
332 			ValaSourceReference* _tmp25_;
333 			ValaSourceReference* _tmp26_;
334 			ValaBlock* _tmp27_;
335 			ValaBlock* _tmp28_;
336 			ValaExpression* _tmp29_;
337 			ValaExpression* _tmp30_;
338 			ValaSourceReference* _tmp31_;
339 			ValaSourceReference* _tmp32_;
340 			ValaBreakStatement* _tmp33_;
341 			ValaBreakStatement* _tmp34_;
342 			ValaIfStatement* if_stmt = NULL;
343 			ValaUnaryExpression* _tmp35_;
344 			ValaBlock* _tmp36_;
345 			ValaExpression* _tmp37_;
346 			ValaExpression* _tmp38_;
347 			ValaSourceReference* _tmp39_;
348 			ValaSourceReference* _tmp40_;
349 			ValaIfStatement* _tmp41_;
350 			ValaBlock* _tmp42_;
351 			ValaBlock* _tmp43_;
352 			ValaIfStatement* _tmp44_;
353 			_tmp16_ = vala_while_statement_get_condition (self);
354 			_tmp17_ = _tmp16_;
355 			_tmp18_ = vala_while_statement_get_condition (self);
356 			_tmp19_ = _tmp18_;
357 			_tmp20_ = vala_code_node_get_source_reference ((ValaCodeNode*) _tmp19_);
358 			_tmp21_ = _tmp20_;
359 			_tmp22_ = vala_unary_expression_new (VALA_UNARY_OPERATOR_LOGICAL_NEGATION, _tmp17_, _tmp21_);
360 			if_condition = _tmp22_;
361 			_tmp23_ = vala_while_statement_get_condition (self);
362 			_tmp24_ = _tmp23_;
363 			_tmp25_ = vala_code_node_get_source_reference ((ValaCodeNode*) _tmp24_);
364 			_tmp26_ = _tmp25_;
365 			_tmp27_ = vala_block_new (_tmp26_);
366 			true_block = _tmp27_;
367 			_tmp28_ = true_block;
368 			_tmp29_ = vala_while_statement_get_condition (self);
369 			_tmp30_ = _tmp29_;
370 			_tmp31_ = vala_code_node_get_source_reference ((ValaCodeNode*) _tmp30_);
371 			_tmp32_ = _tmp31_;
372 			_tmp33_ = vala_break_statement_new (_tmp32_);
373 			_tmp34_ = _tmp33_;
374 			vala_block_add_statement (_tmp28_, (ValaStatement*) _tmp34_);
375 			_vala_code_node_unref0 (_tmp34_);
376 			_tmp35_ = if_condition;
377 			_tmp36_ = true_block;
378 			_tmp37_ = vala_while_statement_get_condition (self);
379 			_tmp38_ = _tmp37_;
380 			_tmp39_ = vala_code_node_get_source_reference ((ValaCodeNode*) _tmp38_);
381 			_tmp40_ = _tmp39_;
382 			_tmp41_ = vala_if_statement_new ((ValaExpression*) _tmp35_, _tmp36_, NULL, _tmp40_);
383 			if_stmt = _tmp41_;
384 			_tmp42_ = vala_while_statement_get_body (self);
385 			_tmp43_ = _tmp42_;
386 			_tmp44_ = if_stmt;
387 			vala_block_insert_statement (_tmp43_, 0, (ValaStatement*) _tmp44_);
388 			_vala_code_node_unref0 (if_stmt);
389 			_vala_code_node_unref0 (true_block);
390 			_vala_code_node_unref0 (if_condition);
391 		}
392 	}
393 	_tmp45_ = vala_while_statement_get_body (self);
394 	_tmp46_ = _tmp45_;
395 	_tmp47_ = vala_code_node_get_source_reference ((ValaCodeNode*) self);
396 	_tmp48_ = _tmp47_;
397 	_tmp49_ = vala_loop_new (_tmp46_, _tmp48_);
398 	loop = _tmp49_;
399 	_tmp50_ = vala_code_node_get_parent_node ((ValaCodeNode*) self);
400 	_tmp51_ = _tmp50_;
401 	parent_block = G_TYPE_CHECK_INSTANCE_CAST (_tmp51_, VALA_TYPE_BLOCK, ValaBlock);
402 	_tmp52_ = parent_block;
403 	_tmp53_ = loop;
404 	vala_block_replace_statement (_tmp52_, (ValaStatement*) self, (ValaStatement*) _tmp53_);
405 	_tmp54_ = loop;
406 	if (!vala_code_node_check ((ValaCodeNode*) _tmp54_, context)) {
407 		vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
408 	}
409 	_tmp55_ = vala_code_node_get_error ((ValaCodeNode*) self);
410 	_tmp56_ = _tmp55_;
411 	result = !_tmp56_;
412 	_vala_code_node_unref0 (loop);
413 	return result;
414 }
415 
416 static void
vala_while_statement_class_init(ValaWhileStatementClass * klass,gpointer klass_data)417 vala_while_statement_class_init (ValaWhileStatementClass * klass,
418                                  gpointer klass_data)
419 {
420 	vala_while_statement_parent_class = g_type_class_peek_parent (klass);
421 	((ValaCodeNodeClass *) klass)->finalize = vala_while_statement_finalize;
422 	g_type_class_adjust_private_offset (klass, &ValaWhileStatement_private_offset);
423 	((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_while_statement_real_accept;
424 	((ValaCodeNodeClass *) klass)->accept_children = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_while_statement_real_accept_children;
425 	((ValaCodeNodeClass *) klass)->replace_expression = (void (*) (ValaCodeNode*, ValaExpression*, ValaExpression*)) vala_while_statement_real_replace_expression;
426 	((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode*, ValaCodeContext*)) vala_while_statement_real_check;
427 }
428 
429 static void
vala_while_statement_vala_statement_interface_init(ValaStatementIface * iface,gpointer iface_data)430 vala_while_statement_vala_statement_interface_init (ValaStatementIface * iface,
431                                                     gpointer iface_data)
432 {
433 	vala_while_statement_vala_statement_parent_iface = g_type_interface_peek_parent (iface);
434 }
435 
436 static void
vala_while_statement_instance_init(ValaWhileStatement * self,gpointer klass)437 vala_while_statement_instance_init (ValaWhileStatement * self,
438                                     gpointer klass)
439 {
440 	self->priv = vala_while_statement_get_instance_private (self);
441 }
442 
443 static void
vala_while_statement_finalize(ValaCodeNode * obj)444 vala_while_statement_finalize (ValaCodeNode * obj)
445 {
446 	ValaWhileStatement * self;
447 	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_WHILE_STATEMENT, ValaWhileStatement);
448 	_vala_code_node_unref0 (self->priv->_condition);
449 	_vala_code_node_unref0 (self->priv->_body);
450 	VALA_CODE_NODE_CLASS (vala_while_statement_parent_class)->finalize (obj);
451 }
452 
453 /**
454  * Represents a while iteration statement in the source code.
455  */
456 static GType
vala_while_statement_get_type_once(void)457 vala_while_statement_get_type_once (void)
458 {
459 	static const GTypeInfo g_define_type_info = { sizeof (ValaWhileStatementClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_while_statement_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaWhileStatement), 0, (GInstanceInitFunc) vala_while_statement_instance_init, NULL };
460 	static const GInterfaceInfo vala_statement_info = { (GInterfaceInitFunc) vala_while_statement_vala_statement_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
461 	GType vala_while_statement_type_id;
462 	vala_while_statement_type_id = g_type_register_static (VALA_TYPE_CODE_NODE, "ValaWhileStatement", &g_define_type_info, 0);
463 	g_type_add_interface_static (vala_while_statement_type_id, VALA_TYPE_STATEMENT, &vala_statement_info);
464 	ValaWhileStatement_private_offset = g_type_add_instance_private (vala_while_statement_type_id, sizeof (ValaWhileStatementPrivate));
465 	return vala_while_statement_type_id;
466 }
467 
468 GType
vala_while_statement_get_type(void)469 vala_while_statement_get_type (void)
470 {
471 	static volatile gsize vala_while_statement_type_id__volatile = 0;
472 	if (g_once_init_enter (&vala_while_statement_type_id__volatile)) {
473 		GType vala_while_statement_type_id;
474 		vala_while_statement_type_id = vala_while_statement_get_type_once ();
475 		g_once_init_leave (&vala_while_statement_type_id__volatile, vala_while_statement_type_id);
476 	}
477 	return vala_while_statement_type_id__volatile;
478 }
479 
480