1 /* valaswitchsection.c generated by valac, the Vala compiler
2 * generated from valaswitchsection.vala, do not modify */
3
4 /* valaswitchsection.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_iterable_unref0(var) ((var == NULL) ? NULL : (var = (vala_iterable_unref (var), NULL)))
32 #define _vala_code_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_node_unref (var), NULL)))
33
34 struct _ValaSwitchSectionPrivate {
35 ValaList* labels;
36 };
37
38 static gint ValaSwitchSection_private_offset;
39 static gpointer vala_switch_section_parent_class = NULL;
40
41 static void vala_switch_section_real_accept (ValaCodeNode* base,
42 ValaCodeVisitor* visitor);
43 static void vala_switch_section_real_accept_children (ValaCodeNode* base,
44 ValaCodeVisitor* visitor);
45 static gboolean vala_switch_section_real_check (ValaCodeNode* base,
46 ValaCodeContext* context);
47 static void vala_switch_section_real_emit (ValaCodeNode* base,
48 ValaCodeGenerator* codegen);
49 static void vala_switch_section_finalize (ValaCodeNode * obj);
50 static GType vala_switch_section_get_type_once (void);
51
52 static inline gpointer
vala_switch_section_get_instance_private(ValaSwitchSection * self)53 vala_switch_section_get_instance_private (ValaSwitchSection* self)
54 {
55 return G_STRUCT_MEMBER_P (self, ValaSwitchSection_private_offset);
56 }
57
58 /**
59 * Creates a new switch section.
60 *
61 * @param source_reference reference to source code
62 * @return newly created switch section
63 */
64 ValaSwitchSection*
vala_switch_section_construct(GType object_type,ValaSourceReference * source_reference)65 vala_switch_section_construct (GType object_type,
66 ValaSourceReference* source_reference)
67 {
68 ValaSwitchSection* self = NULL;
69 self = (ValaSwitchSection*) vala_block_construct (object_type, source_reference);
70 return self;
71 }
72
73 ValaSwitchSection*
vala_switch_section_new(ValaSourceReference * source_reference)74 vala_switch_section_new (ValaSourceReference* source_reference)
75 {
76 return vala_switch_section_construct (VALA_TYPE_SWITCH_SECTION, source_reference);
77 }
78
79 /**
80 * Appends the specified label to the list of switch labels.
81 *
82 * @param label a switch label
83 */
84 void
vala_switch_section_add_label(ValaSwitchSection * self,ValaSwitchLabel * label)85 vala_switch_section_add_label (ValaSwitchSection* self,
86 ValaSwitchLabel* label)
87 {
88 ValaList* _tmp0_;
89 gint _tmp1_;
90 gint _tmp2_;
91 ValaList* _tmp5_;
92 g_return_if_fail (self != NULL);
93 g_return_if_fail (label != NULL);
94 _tmp0_ = self->priv->labels;
95 _tmp1_ = vala_collection_get_size ((ValaCollection*) _tmp0_);
96 _tmp2_ = _tmp1_;
97 if (_tmp2_ == 0) {
98 ValaSourceReference* _tmp3_;
99 ValaSourceReference* _tmp4_;
100 _tmp3_ = vala_code_node_get_source_reference ((ValaCodeNode*) label);
101 _tmp4_ = _tmp3_;
102 vala_code_node_set_source_reference ((ValaCodeNode*) self, _tmp4_);
103 }
104 _tmp5_ = self->priv->labels;
105 vala_collection_add ((ValaCollection*) _tmp5_, label);
106 vala_code_node_set_parent_node ((ValaCodeNode*) label, (ValaCodeNode*) self);
107 }
108
109 /**
110 * Returns the list of switch labels.
111 *
112 * @return switch label list
113 */
114 ValaList*
vala_switch_section_get_labels(ValaSwitchSection * self)115 vala_switch_section_get_labels (ValaSwitchSection* self)
116 {
117 ValaList* _tmp0_;
118 ValaList* result = NULL;
119 g_return_val_if_fail (self != NULL, NULL);
120 _tmp0_ = self->priv->labels;
121 result = _tmp0_;
122 return result;
123 }
124
125 static gpointer
_vala_iterable_ref0(gpointer self)126 _vala_iterable_ref0 (gpointer self)
127 {
128 return self ? vala_iterable_ref (self) : NULL;
129 }
130
131 gboolean
vala_switch_section_has_default_label(ValaSwitchSection * self)132 vala_switch_section_has_default_label (ValaSwitchSection* self)
133 {
134 gboolean result = FALSE;
135 g_return_val_if_fail (self != NULL, FALSE);
136 {
137 ValaList* _label_list = NULL;
138 ValaList* _tmp0_;
139 ValaList* _tmp1_;
140 gint _label_size = 0;
141 ValaList* _tmp2_;
142 gint _tmp3_;
143 gint _tmp4_;
144 gint _label_index = 0;
145 _tmp0_ = self->priv->labels;
146 _tmp1_ = _vala_iterable_ref0 (_tmp0_);
147 _label_list = _tmp1_;
148 _tmp2_ = _label_list;
149 _tmp3_ = vala_collection_get_size ((ValaCollection*) _tmp2_);
150 _tmp4_ = _tmp3_;
151 _label_size = _tmp4_;
152 _label_index = -1;
153 while (TRUE) {
154 gint _tmp5_;
155 gint _tmp6_;
156 ValaSwitchLabel* label = NULL;
157 ValaList* _tmp7_;
158 gpointer _tmp8_;
159 ValaSwitchLabel* _tmp9_;
160 ValaExpression* _tmp10_;
161 ValaExpression* _tmp11_;
162 _label_index = _label_index + 1;
163 _tmp5_ = _label_index;
164 _tmp6_ = _label_size;
165 if (!(_tmp5_ < _tmp6_)) {
166 break;
167 }
168 _tmp7_ = _label_list;
169 _tmp8_ = vala_list_get (_tmp7_, _label_index);
170 label = (ValaSwitchLabel*) _tmp8_;
171 _tmp9_ = label;
172 _tmp10_ = vala_switch_label_get_expression (_tmp9_);
173 _tmp11_ = _tmp10_;
174 if (_tmp11_ == NULL) {
175 result = TRUE;
176 _vala_code_node_unref0 (label);
177 _vala_iterable_unref0 (_label_list);
178 return result;
179 }
180 _vala_code_node_unref0 (label);
181 }
182 _vala_iterable_unref0 (_label_list);
183 }
184 result = FALSE;
185 return result;
186 }
187
188 static void
vala_switch_section_real_accept(ValaCodeNode * base,ValaCodeVisitor * visitor)189 vala_switch_section_real_accept (ValaCodeNode* base,
190 ValaCodeVisitor* visitor)
191 {
192 ValaSwitchSection * self;
193 self = (ValaSwitchSection*) base;
194 g_return_if_fail (visitor != NULL);
195 vala_code_visitor_visit_switch_section (visitor, self);
196 }
197
198 static void
vala_switch_section_real_accept_children(ValaCodeNode * base,ValaCodeVisitor * visitor)199 vala_switch_section_real_accept_children (ValaCodeNode* base,
200 ValaCodeVisitor* visitor)
201 {
202 ValaSwitchSection * self;
203 self = (ValaSwitchSection*) base;
204 g_return_if_fail (visitor != NULL);
205 {
206 ValaList* _label_list = NULL;
207 ValaList* _tmp0_;
208 ValaList* _tmp1_;
209 gint _label_size = 0;
210 ValaList* _tmp2_;
211 gint _tmp3_;
212 gint _tmp4_;
213 gint _label_index = 0;
214 _tmp0_ = self->priv->labels;
215 _tmp1_ = _vala_iterable_ref0 (_tmp0_);
216 _label_list = _tmp1_;
217 _tmp2_ = _label_list;
218 _tmp3_ = vala_collection_get_size ((ValaCollection*) _tmp2_);
219 _tmp4_ = _tmp3_;
220 _label_size = _tmp4_;
221 _label_index = -1;
222 while (TRUE) {
223 gint _tmp5_;
224 gint _tmp6_;
225 ValaSwitchLabel* label = NULL;
226 ValaList* _tmp7_;
227 gpointer _tmp8_;
228 ValaSwitchLabel* _tmp9_;
229 _label_index = _label_index + 1;
230 _tmp5_ = _label_index;
231 _tmp6_ = _label_size;
232 if (!(_tmp5_ < _tmp6_)) {
233 break;
234 }
235 _tmp7_ = _label_list;
236 _tmp8_ = vala_list_get (_tmp7_, _label_index);
237 label = (ValaSwitchLabel*) _tmp8_;
238 _tmp9_ = label;
239 vala_code_node_accept ((ValaCodeNode*) _tmp9_, visitor);
240 _vala_code_node_unref0 (label);
241 }
242 _vala_iterable_unref0 (_label_list);
243 }
244 VALA_CODE_NODE_CLASS (vala_switch_section_parent_class)->accept_children ((ValaCodeNode*) G_TYPE_CHECK_INSTANCE_CAST (self, VALA_TYPE_BLOCK, ValaBlock), visitor);
245 }
246
247 static gboolean
vala_switch_section_real_check(ValaCodeNode * base,ValaCodeContext * context)248 vala_switch_section_real_check (ValaCodeNode* base,
249 ValaCodeContext* context)
250 {
251 ValaSwitchSection * self;
252 gboolean _tmp0_;
253 gboolean _tmp1_;
254 gboolean _tmp14_;
255 gboolean _tmp15_;
256 gboolean result = FALSE;
257 self = (ValaSwitchSection*) base;
258 g_return_val_if_fail (context != NULL, FALSE);
259 _tmp0_ = vala_code_node_get_checked ((ValaCodeNode*) self);
260 _tmp1_ = _tmp0_;
261 if (_tmp1_) {
262 gboolean _tmp2_;
263 gboolean _tmp3_;
264 _tmp2_ = vala_code_node_get_error ((ValaCodeNode*) self);
265 _tmp3_ = _tmp2_;
266 result = !_tmp3_;
267 return result;
268 }
269 {
270 ValaList* _label_list = NULL;
271 ValaList* _tmp4_;
272 ValaList* _tmp5_;
273 gint _label_size = 0;
274 ValaList* _tmp6_;
275 gint _tmp7_;
276 gint _tmp8_;
277 gint _label_index = 0;
278 _tmp4_ = vala_switch_section_get_labels (self);
279 _tmp5_ = _vala_iterable_ref0 (_tmp4_);
280 _label_list = _tmp5_;
281 _tmp6_ = _label_list;
282 _tmp7_ = vala_collection_get_size ((ValaCollection*) _tmp6_);
283 _tmp8_ = _tmp7_;
284 _label_size = _tmp8_;
285 _label_index = -1;
286 while (TRUE) {
287 gint _tmp9_;
288 gint _tmp10_;
289 ValaSwitchLabel* label = NULL;
290 ValaList* _tmp11_;
291 gpointer _tmp12_;
292 ValaSwitchLabel* _tmp13_;
293 _label_index = _label_index + 1;
294 _tmp9_ = _label_index;
295 _tmp10_ = _label_size;
296 if (!(_tmp9_ < _tmp10_)) {
297 break;
298 }
299 _tmp11_ = _label_list;
300 _tmp12_ = vala_list_get (_tmp11_, _label_index);
301 label = (ValaSwitchLabel*) _tmp12_;
302 _tmp13_ = label;
303 vala_code_node_check ((ValaCodeNode*) _tmp13_, context);
304 _vala_code_node_unref0 (label);
305 }
306 _vala_iterable_unref0 (_label_list);
307 }
308 if (!VALA_CODE_NODE_CLASS (vala_switch_section_parent_class)->check ((ValaCodeNode*) G_TYPE_CHECK_INSTANCE_CAST (self, VALA_TYPE_BLOCK, ValaBlock), context)) {
309 vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
310 }
311 vala_code_node_set_checked ((ValaCodeNode*) self, TRUE);
312 _tmp14_ = vala_code_node_get_error ((ValaCodeNode*) self);
313 _tmp15_ = _tmp14_;
314 result = !_tmp15_;
315 return result;
316 }
317
318 static void
vala_switch_section_real_emit(ValaCodeNode * base,ValaCodeGenerator * codegen)319 vala_switch_section_real_emit (ValaCodeNode* base,
320 ValaCodeGenerator* codegen)
321 {
322 ValaSwitchSection * self;
323 self = (ValaSwitchSection*) base;
324 g_return_if_fail (codegen != NULL);
325 {
326 ValaList* _label_list = NULL;
327 ValaList* _tmp0_;
328 ValaList* _tmp1_;
329 gint _label_size = 0;
330 ValaList* _tmp2_;
331 gint _tmp3_;
332 gint _tmp4_;
333 gint _label_index = 0;
334 _tmp0_ = self->priv->labels;
335 _tmp1_ = _vala_iterable_ref0 (_tmp0_);
336 _label_list = _tmp1_;
337 _tmp2_ = _label_list;
338 _tmp3_ = vala_collection_get_size ((ValaCollection*) _tmp2_);
339 _tmp4_ = _tmp3_;
340 _label_size = _tmp4_;
341 _label_index = -1;
342 while (TRUE) {
343 gint _tmp5_;
344 gint _tmp6_;
345 ValaSwitchLabel* label = NULL;
346 ValaList* _tmp7_;
347 gpointer _tmp8_;
348 ValaSwitchLabel* _tmp9_;
349 _label_index = _label_index + 1;
350 _tmp5_ = _label_index;
351 _tmp6_ = _label_size;
352 if (!(_tmp5_ < _tmp6_)) {
353 break;
354 }
355 _tmp7_ = _label_list;
356 _tmp8_ = vala_list_get (_tmp7_, _label_index);
357 label = (ValaSwitchLabel*) _tmp8_;
358 _tmp9_ = label;
359 vala_code_node_emit ((ValaCodeNode*) _tmp9_, codegen);
360 _vala_code_node_unref0 (label);
361 }
362 _vala_iterable_unref0 (_label_list);
363 }
364 VALA_CODE_NODE_CLASS (vala_switch_section_parent_class)->emit ((ValaCodeNode*) G_TYPE_CHECK_INSTANCE_CAST (self, VALA_TYPE_BLOCK, ValaBlock), codegen);
365 }
366
367 static void
vala_switch_section_class_init(ValaSwitchSectionClass * klass,gpointer klass_data)368 vala_switch_section_class_init (ValaSwitchSectionClass * klass,
369 gpointer klass_data)
370 {
371 vala_switch_section_parent_class = g_type_class_peek_parent (klass);
372 ((ValaCodeNodeClass *) klass)->finalize = vala_switch_section_finalize;
373 g_type_class_adjust_private_offset (klass, &ValaSwitchSection_private_offset);
374 ((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_switch_section_real_accept;
375 ((ValaCodeNodeClass *) klass)->accept_children = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_switch_section_real_accept_children;
376 ((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode*, ValaCodeContext*)) vala_switch_section_real_check;
377 ((ValaCodeNodeClass *) klass)->emit = (void (*) (ValaCodeNode*, ValaCodeGenerator*)) vala_switch_section_real_emit;
378 }
379
380 static void
vala_switch_section_instance_init(ValaSwitchSection * self,gpointer klass)381 vala_switch_section_instance_init (ValaSwitchSection * self,
382 gpointer klass)
383 {
384 GEqualFunc _tmp0_;
385 ValaArrayList* _tmp1_;
386 self->priv = vala_switch_section_get_instance_private (self);
387 _tmp0_ = g_direct_equal;
388 _tmp1_ = vala_array_list_new (VALA_TYPE_SWITCH_LABEL, (GBoxedCopyFunc) vala_code_node_ref, (GDestroyNotify) vala_code_node_unref, _tmp0_);
389 self->priv->labels = (ValaList*) _tmp1_;
390 }
391
392 static void
vala_switch_section_finalize(ValaCodeNode * obj)393 vala_switch_section_finalize (ValaCodeNode * obj)
394 {
395 ValaSwitchSection * self;
396 self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_SWITCH_SECTION, ValaSwitchSection);
397 _vala_iterable_unref0 (self->priv->labels);
398 VALA_CODE_NODE_CLASS (vala_switch_section_parent_class)->finalize (obj);
399 }
400
401 /**
402 * Represents a switch section in the source code.
403 */
404 static GType
vala_switch_section_get_type_once(void)405 vala_switch_section_get_type_once (void)
406 {
407 static const GTypeInfo g_define_type_info = { sizeof (ValaSwitchSectionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_switch_section_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaSwitchSection), 0, (GInstanceInitFunc) vala_switch_section_instance_init, NULL };
408 GType vala_switch_section_type_id;
409 vala_switch_section_type_id = g_type_register_static (VALA_TYPE_BLOCK, "ValaSwitchSection", &g_define_type_info, 0);
410 ValaSwitchSection_private_offset = g_type_add_instance_private (vala_switch_section_type_id, sizeof (ValaSwitchSectionPrivate));
411 return vala_switch_section_type_id;
412 }
413
414 GType
vala_switch_section_get_type(void)415 vala_switch_section_get_type (void)
416 {
417 static volatile gsize vala_switch_section_type_id__volatile = 0;
418 if (g_once_init_enter (&vala_switch_section_type_id__volatile)) {
419 GType vala_switch_section_type_id;
420 vala_switch_section_type_id = vala_switch_section_get_type_once ();
421 g_once_init_leave (&vala_switch_section_type_id__volatile, vala_switch_section_type_id);
422 }
423 return vala_switch_section_type_id__volatile;
424 }
425
426