1 /* valaccodeforstatement.c generated by valac, the Vala compiler
2  * generated from valaccodeforstatement.vala, do not modify */
3 
4 /* valaccodeforstatement.vala
5  *
6  * Copyright (C) 2006-2008  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 "valaccode.h"
27 #include <valagee.h>
28 #include <glib-object.h>
29 #include <glib.h>
30 
31 #define _vala_ccode_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_ccode_node_unref (var), NULL)))
32 #define _vala_iterable_unref0(var) ((var == NULL) ? NULL : (var = (vala_iterable_unref (var), NULL)))
33 
34 struct _ValaCCodeForStatementPrivate {
35 	ValaCCodeExpression* _condition;
36 	ValaCCodeStatement* _body;
37 	ValaList* initializer;
38 	ValaList* iterator;
39 };
40 
41 static gint ValaCCodeForStatement_private_offset;
42 static gpointer vala_ccode_for_statement_parent_class = NULL;
43 
44 static void vala_ccode_for_statement_real_write (ValaCCodeNode* base,
45                                           ValaCCodeWriter* writer);
46 static void vala_ccode_for_statement_finalize (ValaCCodeNode * obj);
47 static GType vala_ccode_for_statement_get_type_once (void);
48 
49 static inline gpointer
vala_ccode_for_statement_get_instance_private(ValaCCodeForStatement * self)50 vala_ccode_for_statement_get_instance_private (ValaCCodeForStatement* self)
51 {
52 	return G_STRUCT_MEMBER_P (self, ValaCCodeForStatement_private_offset);
53 }
54 
55 ValaCCodeExpression*
vala_ccode_for_statement_get_condition(ValaCCodeForStatement * self)56 vala_ccode_for_statement_get_condition (ValaCCodeForStatement* self)
57 {
58 	ValaCCodeExpression* result;
59 	ValaCCodeExpression* _tmp0_;
60 	g_return_val_if_fail (self != NULL, NULL);
61 	_tmp0_ = self->priv->_condition;
62 	result = _tmp0_;
63 	return result;
64 }
65 
66 static gpointer
_vala_ccode_node_ref0(gpointer self)67 _vala_ccode_node_ref0 (gpointer self)
68 {
69 	return self ? vala_ccode_node_ref (self) : NULL;
70 }
71 
72 void
vala_ccode_for_statement_set_condition(ValaCCodeForStatement * self,ValaCCodeExpression * value)73 vala_ccode_for_statement_set_condition (ValaCCodeForStatement* self,
74                                         ValaCCodeExpression* value)
75 {
76 	ValaCCodeExpression* _tmp0_;
77 	g_return_if_fail (self != NULL);
78 	_tmp0_ = _vala_ccode_node_ref0 (value);
79 	_vala_ccode_node_unref0 (self->priv->_condition);
80 	self->priv->_condition = _tmp0_;
81 }
82 
83 ValaCCodeStatement*
vala_ccode_for_statement_get_body(ValaCCodeForStatement * self)84 vala_ccode_for_statement_get_body (ValaCCodeForStatement* self)
85 {
86 	ValaCCodeStatement* result;
87 	ValaCCodeStatement* _tmp0_;
88 	g_return_val_if_fail (self != NULL, NULL);
89 	_tmp0_ = self->priv->_body;
90 	result = _tmp0_;
91 	return result;
92 }
93 
94 void
vala_ccode_for_statement_set_body(ValaCCodeForStatement * self,ValaCCodeStatement * value)95 vala_ccode_for_statement_set_body (ValaCCodeForStatement* self,
96                                    ValaCCodeStatement* value)
97 {
98 	ValaCCodeStatement* _tmp0_;
99 	g_return_if_fail (self != NULL);
100 	_tmp0_ = _vala_ccode_node_ref0 (value);
101 	_vala_ccode_node_unref0 (self->priv->_body);
102 	self->priv->_body = _tmp0_;
103 }
104 
105 ValaCCodeForStatement*
vala_ccode_for_statement_construct(GType object_type,ValaCCodeExpression * condition,ValaCCodeStatement * body)106 vala_ccode_for_statement_construct (GType object_type,
107                                     ValaCCodeExpression* condition,
108                                     ValaCCodeStatement* body)
109 {
110 	ValaCCodeForStatement* self = NULL;
111 	self = (ValaCCodeForStatement*) vala_ccode_statement_construct (object_type);
112 	vala_ccode_for_statement_set_condition (self, condition);
113 	vala_ccode_for_statement_set_body (self, body);
114 	return self;
115 }
116 
117 ValaCCodeForStatement*
vala_ccode_for_statement_new(ValaCCodeExpression * condition,ValaCCodeStatement * body)118 vala_ccode_for_statement_new (ValaCCodeExpression* condition,
119                               ValaCCodeStatement* body)
120 {
121 	return vala_ccode_for_statement_construct (VALA_TYPE_CCODE_FOR_STATEMENT, condition, body);
122 }
123 
124 /**
125  * Appends the specified expression to the list of initializers.
126  *
127  * @param expr an initializer expression
128  */
129 void
vala_ccode_for_statement_add_initializer(ValaCCodeForStatement * self,ValaCCodeExpression * expr)130 vala_ccode_for_statement_add_initializer (ValaCCodeForStatement* self,
131                                           ValaCCodeExpression* expr)
132 {
133 	ValaList* _tmp0_;
134 	g_return_if_fail (self != NULL);
135 	g_return_if_fail (expr != NULL);
136 	_tmp0_ = self->priv->initializer;
137 	vala_collection_add ((ValaCollection*) _tmp0_, expr);
138 }
139 
140 /**
141  * Appends the specified expression to the iterator.
142  *
143  * @param expr an iterator expression
144  */
145 void
vala_ccode_for_statement_add_iterator(ValaCCodeForStatement * self,ValaCCodeExpression * expr)146 vala_ccode_for_statement_add_iterator (ValaCCodeForStatement* self,
147                                        ValaCCodeExpression* expr)
148 {
149 	ValaList* _tmp0_;
150 	g_return_if_fail (self != NULL);
151 	g_return_if_fail (expr != NULL);
152 	_tmp0_ = self->priv->iterator;
153 	vala_collection_add ((ValaCollection*) _tmp0_, expr);
154 }
155 
156 static gpointer
_vala_iterable_ref0(gpointer self)157 _vala_iterable_ref0 (gpointer self)
158 {
159 	return self ? vala_iterable_ref (self) : NULL;
160 }
161 
162 static void
vala_ccode_for_statement_real_write(ValaCCodeNode * base,ValaCCodeWriter * writer)163 vala_ccode_for_statement_real_write (ValaCCodeNode* base,
164                                      ValaCCodeWriter* writer)
165 {
166 	ValaCCodeForStatement * self;
167 	gboolean first = FALSE;
168 	ValaCCodeLineDirective* _tmp0_;
169 	ValaCCodeLineDirective* _tmp1_;
170 	ValaCCodeExpression* _tmp13_;
171 	ValaCCodeStatement* _tmp26_;
172 	self = (ValaCCodeForStatement*) base;
173 	g_return_if_fail (writer != NULL);
174 	_tmp0_ = vala_ccode_node_get_line ((ValaCCodeNode*) self);
175 	_tmp1_ = _tmp0_;
176 	vala_ccode_writer_write_indent (writer, _tmp1_);
177 	vala_ccode_writer_write_string (writer, "for (");
178 	first = TRUE;
179 	{
180 		ValaList* _init_expr_list = NULL;
181 		ValaList* _tmp2_;
182 		ValaList* _tmp3_;
183 		gint _init_expr_size = 0;
184 		ValaList* _tmp4_;
185 		gint _tmp5_;
186 		gint _tmp6_;
187 		gint _init_expr_index = 0;
188 		_tmp2_ = self->priv->initializer;
189 		_tmp3_ = _vala_iterable_ref0 (_tmp2_);
190 		_init_expr_list = _tmp3_;
191 		_tmp4_ = _init_expr_list;
192 		_tmp5_ = vala_collection_get_size ((ValaCollection*) _tmp4_);
193 		_tmp6_ = _tmp5_;
194 		_init_expr_size = _tmp6_;
195 		_init_expr_index = -1;
196 		while (TRUE) {
197 			gint _tmp7_;
198 			gint _tmp8_;
199 			ValaCCodeExpression* init_expr = NULL;
200 			ValaList* _tmp9_;
201 			gpointer _tmp10_;
202 			ValaCCodeExpression* _tmp11_;
203 			_init_expr_index = _init_expr_index + 1;
204 			_tmp7_ = _init_expr_index;
205 			_tmp8_ = _init_expr_size;
206 			if (!(_tmp7_ < _tmp8_)) {
207 				break;
208 			}
209 			_tmp9_ = _init_expr_list;
210 			_tmp10_ = vala_list_get (_tmp9_, _init_expr_index);
211 			init_expr = (ValaCCodeExpression*) _tmp10_;
212 			if (!first) {
213 				vala_ccode_writer_write_string (writer, ", ");
214 			} else {
215 				first = FALSE;
216 			}
217 			_tmp11_ = init_expr;
218 			if (_tmp11_ != NULL) {
219 				ValaCCodeExpression* _tmp12_;
220 				_tmp12_ = init_expr;
221 				vala_ccode_node_write ((ValaCCodeNode*) _tmp12_, writer);
222 			}
223 			_vala_ccode_node_unref0 (init_expr);
224 		}
225 		_vala_iterable_unref0 (_init_expr_list);
226 	}
227 	vala_ccode_writer_write_string (writer, "; ");
228 	_tmp13_ = self->priv->_condition;
229 	if (_tmp13_ != NULL) {
230 		ValaCCodeExpression* _tmp14_;
231 		_tmp14_ = self->priv->_condition;
232 		vala_ccode_node_write ((ValaCCodeNode*) _tmp14_, writer);
233 	}
234 	vala_ccode_writer_write_string (writer, "; ");
235 	first = TRUE;
236 	{
237 		ValaList* _it_expr_list = NULL;
238 		ValaList* _tmp15_;
239 		ValaList* _tmp16_;
240 		gint _it_expr_size = 0;
241 		ValaList* _tmp17_;
242 		gint _tmp18_;
243 		gint _tmp19_;
244 		gint _it_expr_index = 0;
245 		_tmp15_ = self->priv->iterator;
246 		_tmp16_ = _vala_iterable_ref0 (_tmp15_);
247 		_it_expr_list = _tmp16_;
248 		_tmp17_ = _it_expr_list;
249 		_tmp18_ = vala_collection_get_size ((ValaCollection*) _tmp17_);
250 		_tmp19_ = _tmp18_;
251 		_it_expr_size = _tmp19_;
252 		_it_expr_index = -1;
253 		while (TRUE) {
254 			gint _tmp20_;
255 			gint _tmp21_;
256 			ValaCCodeExpression* it_expr = NULL;
257 			ValaList* _tmp22_;
258 			gpointer _tmp23_;
259 			ValaCCodeExpression* _tmp24_;
260 			_it_expr_index = _it_expr_index + 1;
261 			_tmp20_ = _it_expr_index;
262 			_tmp21_ = _it_expr_size;
263 			if (!(_tmp20_ < _tmp21_)) {
264 				break;
265 			}
266 			_tmp22_ = _it_expr_list;
267 			_tmp23_ = vala_list_get (_tmp22_, _it_expr_index);
268 			it_expr = (ValaCCodeExpression*) _tmp23_;
269 			if (!first) {
270 				vala_ccode_writer_write_string (writer, ", ");
271 			} else {
272 				first = FALSE;
273 			}
274 			_tmp24_ = it_expr;
275 			if (_tmp24_ != NULL) {
276 				ValaCCodeExpression* _tmp25_;
277 				_tmp25_ = it_expr;
278 				vala_ccode_node_write ((ValaCCodeNode*) _tmp25_, writer);
279 			}
280 			_vala_ccode_node_unref0 (it_expr);
281 		}
282 		_vala_iterable_unref0 (_it_expr_list);
283 	}
284 	vala_ccode_writer_write_string (writer, ")");
285 	_tmp26_ = self->priv->_body;
286 	vala_ccode_node_write ((ValaCCodeNode*) _tmp26_, writer);
287 }
288 
289 static void
vala_ccode_for_statement_class_init(ValaCCodeForStatementClass * klass,gpointer klass_data)290 vala_ccode_for_statement_class_init (ValaCCodeForStatementClass * klass,
291                                      gpointer klass_data)
292 {
293 	vala_ccode_for_statement_parent_class = g_type_class_peek_parent (klass);
294 	((ValaCCodeNodeClass *) klass)->finalize = vala_ccode_for_statement_finalize;
295 	g_type_class_adjust_private_offset (klass, &ValaCCodeForStatement_private_offset);
296 	((ValaCCodeNodeClass *) klass)->write = (void (*) (ValaCCodeNode*, ValaCCodeWriter*)) vala_ccode_for_statement_real_write;
297 }
298 
299 static void
vala_ccode_for_statement_instance_init(ValaCCodeForStatement * self,gpointer klass)300 vala_ccode_for_statement_instance_init (ValaCCodeForStatement * self,
301                                         gpointer klass)
302 {
303 	GEqualFunc _tmp0_;
304 	ValaArrayList* _tmp1_;
305 	GEqualFunc _tmp2_;
306 	ValaArrayList* _tmp3_;
307 	self->priv = vala_ccode_for_statement_get_instance_private (self);
308 	_tmp0_ = g_direct_equal;
309 	_tmp1_ = vala_array_list_new (VALA_TYPE_CCODE_EXPRESSION, (GBoxedCopyFunc) vala_ccode_node_ref, (GDestroyNotify) vala_ccode_node_unref, _tmp0_);
310 	self->priv->initializer = (ValaList*) _tmp1_;
311 	_tmp2_ = g_direct_equal;
312 	_tmp3_ = vala_array_list_new (VALA_TYPE_CCODE_EXPRESSION, (GBoxedCopyFunc) vala_ccode_node_ref, (GDestroyNotify) vala_ccode_node_unref, _tmp2_);
313 	self->priv->iterator = (ValaList*) _tmp3_;
314 }
315 
316 static void
vala_ccode_for_statement_finalize(ValaCCodeNode * obj)317 vala_ccode_for_statement_finalize (ValaCCodeNode * obj)
318 {
319 	ValaCCodeForStatement * self;
320 	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_CCODE_FOR_STATEMENT, ValaCCodeForStatement);
321 	_vala_ccode_node_unref0 (self->priv->_condition);
322 	_vala_ccode_node_unref0 (self->priv->_body);
323 	_vala_iterable_unref0 (self->priv->initializer);
324 	_vala_iterable_unref0 (self->priv->iterator);
325 	VALA_CCODE_NODE_CLASS (vala_ccode_for_statement_parent_class)->finalize (obj);
326 }
327 
328 /**
329  * Represents a for iteration statement in the C code.
330  */
331 static GType
vala_ccode_for_statement_get_type_once(void)332 vala_ccode_for_statement_get_type_once (void)
333 {
334 	static const GTypeInfo g_define_type_info = { sizeof (ValaCCodeForStatementClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_ccode_for_statement_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaCCodeForStatement), 0, (GInstanceInitFunc) vala_ccode_for_statement_instance_init, NULL };
335 	GType vala_ccode_for_statement_type_id;
336 	vala_ccode_for_statement_type_id = g_type_register_static (VALA_TYPE_CCODE_STATEMENT, "ValaCCodeForStatement", &g_define_type_info, 0);
337 	ValaCCodeForStatement_private_offset = g_type_add_instance_private (vala_ccode_for_statement_type_id, sizeof (ValaCCodeForStatementPrivate));
338 	return vala_ccode_for_statement_type_id;
339 }
340 
341 GType
vala_ccode_for_statement_get_type(void)342 vala_ccode_for_statement_get_type (void)
343 {
344 	static volatile gsize vala_ccode_for_statement_type_id__volatile = 0;
345 	if (g_once_init_enter (&vala_ccode_for_statement_type_id__volatile)) {
346 		GType vala_ccode_for_statement_type_id;
347 		vala_ccode_for_statement_type_id = vala_ccode_for_statement_get_type_once ();
348 		g_once_init_leave (&vala_ccode_for_statement_type_id__volatile, vala_ccode_for_statement_type_id);
349 	}
350 	return vala_ccode_for_statement_type_id__volatile;
351 }
352 
353