1 /* valaccodedeclaration.c generated by valac, the Vala compiler
2 * generated from valaccodedeclaration.vala, do not modify */
3
4 /* valaccodedeclaration.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 "valaccode.h"
27 #include <stdlib.h>
28 #include <string.h>
29 #include <glib.h>
30 #include <valagee.h>
31 #include <glib-object.h>
32
33 #define _g_free0(var) (var = (g_free (var), NULL))
34 #define _vala_iterable_unref0(var) ((var == NULL) ? NULL : (var = (vala_iterable_unref (var), NULL)))
35 #define _vala_ccode_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_ccode_node_unref (var), NULL)))
36
37 struct _ValaCCodeDeclarationPrivate {
38 gchar* _type_name;
39 ValaList* declarators;
40 };
41
42 static gint ValaCCodeDeclaration_private_offset;
43 static gpointer vala_ccode_declaration_parent_class = NULL;
44
45 static void vala_ccode_declaration_real_write (ValaCCodeNode* base,
46 ValaCCodeWriter* writer);
47 static gboolean vala_ccode_declaration_has_initializer (ValaCCodeDeclaration* self);
48 static void vala_ccode_declaration_real_write_declaration (ValaCCodeNode* base,
49 ValaCCodeWriter* writer);
50 static void vala_ccode_declaration_finalize (ValaCCodeNode * obj);
51 static GType vala_ccode_declaration_get_type_once (void);
52
53 static inline gpointer
vala_ccode_declaration_get_instance_private(ValaCCodeDeclaration * self)54 vala_ccode_declaration_get_instance_private (ValaCCodeDeclaration* self)
55 {
56 return G_STRUCT_MEMBER_P (self, ValaCCodeDeclaration_private_offset);
57 }
58
59 const gchar*
vala_ccode_declaration_get_type_name(ValaCCodeDeclaration * self)60 vala_ccode_declaration_get_type_name (ValaCCodeDeclaration* self)
61 {
62 const gchar* result;
63 const gchar* _tmp0_;
64 g_return_val_if_fail (self != NULL, NULL);
65 _tmp0_ = self->priv->_type_name;
66 result = _tmp0_;
67 return result;
68 }
69
70 void
vala_ccode_declaration_set_type_name(ValaCCodeDeclaration * self,const gchar * value)71 vala_ccode_declaration_set_type_name (ValaCCodeDeclaration* self,
72 const gchar* value)
73 {
74 gchar* _tmp0_;
75 g_return_if_fail (self != NULL);
76 _tmp0_ = g_strdup (value);
77 _g_free0 (self->priv->_type_name);
78 self->priv->_type_name = _tmp0_;
79 }
80
81 ValaCCodeDeclaration*
vala_ccode_declaration_construct(GType object_type,const gchar * type_name)82 vala_ccode_declaration_construct (GType object_type,
83 const gchar* type_name)
84 {
85 ValaCCodeDeclaration* self = NULL;
86 g_return_val_if_fail (type_name != NULL, NULL);
87 self = (ValaCCodeDeclaration*) vala_ccode_statement_construct (object_type);
88 vala_ccode_declaration_set_type_name (self, type_name);
89 return self;
90 }
91
92 ValaCCodeDeclaration*
vala_ccode_declaration_new(const gchar * type_name)93 vala_ccode_declaration_new (const gchar* type_name)
94 {
95 return vala_ccode_declaration_construct (VALA_TYPE_CCODE_DECLARATION, type_name);
96 }
97
98 /**
99 * Adds the specified declarator to this declaration.
100 *
101 * @param decl a declarator
102 */
103 void
vala_ccode_declaration_add_declarator(ValaCCodeDeclaration * self,ValaCCodeDeclarator * decl)104 vala_ccode_declaration_add_declarator (ValaCCodeDeclaration* self,
105 ValaCCodeDeclarator* decl)
106 {
107 ValaList* _tmp0_;
108 g_return_if_fail (self != NULL);
109 g_return_if_fail (decl != NULL);
110 _tmp0_ = self->priv->declarators;
111 vala_collection_add ((ValaCollection*) _tmp0_, decl);
112 }
113
114 static gpointer
_vala_iterable_ref0(gpointer self)115 _vala_iterable_ref0 (gpointer self)
116 {
117 return self ? vala_iterable_ref (self) : NULL;
118 }
119
120 static void
vala_ccode_declaration_real_write(ValaCCodeNode * base,ValaCCodeWriter * writer)121 vala_ccode_declaration_real_write (ValaCCodeNode* base,
122 ValaCCodeWriter* writer)
123 {
124 ValaCCodeDeclaration * self;
125 ValaCCodeModifiers _tmp0_;
126 ValaCCodeModifiers _tmp1_;
127 self = (ValaCCodeDeclaration*) base;
128 g_return_if_fail (writer != NULL);
129 _tmp0_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
130 _tmp1_ = _tmp0_;
131 if ((_tmp1_ & ((VALA_CCODE_MODIFIERS_STATIC | VALA_CCODE_MODIFIERS_INTERNAL) | VALA_CCODE_MODIFIERS_EXTERN)) == 0) {
132 {
133 ValaList* _decl_list = NULL;
134 ValaList* _tmp2_;
135 ValaList* _tmp3_;
136 gint _decl_size = 0;
137 ValaList* _tmp4_;
138 gint _tmp5_;
139 gint _tmp6_;
140 gint _decl_index = 0;
141 _tmp2_ = self->priv->declarators;
142 _tmp3_ = _vala_iterable_ref0 (_tmp2_);
143 _decl_list = _tmp3_;
144 _tmp4_ = _decl_list;
145 _tmp5_ = vala_collection_get_size ((ValaCollection*) _tmp4_);
146 _tmp6_ = _tmp5_;
147 _decl_size = _tmp6_;
148 _decl_index = -1;
149 while (TRUE) {
150 gint _tmp7_;
151 gint _tmp8_;
152 ValaCCodeDeclarator* decl = NULL;
153 ValaList* _tmp9_;
154 gpointer _tmp10_;
155 ValaCCodeDeclarator* _tmp11_;
156 _decl_index = _decl_index + 1;
157 _tmp7_ = _decl_index;
158 _tmp8_ = _decl_size;
159 if (!(_tmp7_ < _tmp8_)) {
160 break;
161 }
162 _tmp9_ = _decl_list;
163 _tmp10_ = vala_list_get (_tmp9_, _decl_index);
164 decl = (ValaCCodeDeclarator*) _tmp10_;
165 _tmp11_ = decl;
166 vala_ccode_declarator_write_initialization (_tmp11_, writer);
167 _vala_ccode_node_unref0 (decl);
168 }
169 _vala_iterable_unref0 (_decl_list);
170 }
171 }
172 }
173
174 static gpointer
_vala_ccode_node_ref0(gpointer self)175 _vala_ccode_node_ref0 (gpointer self)
176 {
177 return self ? vala_ccode_node_ref (self) : NULL;
178 }
179
180 static gboolean
vala_ccode_declaration_has_initializer(ValaCCodeDeclaration * self)181 vala_ccode_declaration_has_initializer (ValaCCodeDeclaration* self)
182 {
183 gboolean result = FALSE;
184 g_return_val_if_fail (self != NULL, FALSE);
185 {
186 ValaList* _decl_list = NULL;
187 ValaList* _tmp0_;
188 ValaList* _tmp1_;
189 gint _decl_size = 0;
190 ValaList* _tmp2_;
191 gint _tmp3_;
192 gint _tmp4_;
193 gint _decl_index = 0;
194 _tmp0_ = self->priv->declarators;
195 _tmp1_ = _vala_iterable_ref0 (_tmp0_);
196 _decl_list = _tmp1_;
197 _tmp2_ = _decl_list;
198 _tmp3_ = vala_collection_get_size ((ValaCollection*) _tmp2_);
199 _tmp4_ = _tmp3_;
200 _decl_size = _tmp4_;
201 _decl_index = -1;
202 while (TRUE) {
203 gint _tmp5_;
204 gint _tmp6_;
205 ValaCCodeDeclarator* decl = NULL;
206 ValaList* _tmp7_;
207 gpointer _tmp8_;
208 ValaCCodeVariableDeclarator* var_decl = NULL;
209 ValaCCodeDeclarator* _tmp9_;
210 ValaCCodeVariableDeclarator* _tmp10_;
211 gboolean _tmp11_ = FALSE;
212 ValaCCodeVariableDeclarator* _tmp12_;
213 _decl_index = _decl_index + 1;
214 _tmp5_ = _decl_index;
215 _tmp6_ = _decl_size;
216 if (!(_tmp5_ < _tmp6_)) {
217 break;
218 }
219 _tmp7_ = _decl_list;
220 _tmp8_ = vala_list_get (_tmp7_, _decl_index);
221 decl = (ValaCCodeDeclarator*) _tmp8_;
222 _tmp9_ = decl;
223 _tmp10_ = _vala_ccode_node_ref0 (VALA_IS_CCODE_VARIABLE_DECLARATOR (_tmp9_) ? ((ValaCCodeVariableDeclarator*) _tmp9_) : NULL);
224 var_decl = _tmp10_;
225 _tmp12_ = var_decl;
226 if (_tmp12_ != NULL) {
227 ValaCCodeVariableDeclarator* _tmp13_;
228 ValaCCodeExpression* _tmp14_;
229 ValaCCodeExpression* _tmp15_;
230 _tmp13_ = var_decl;
231 _tmp14_ = vala_ccode_variable_declarator_get_initializer (_tmp13_);
232 _tmp15_ = _tmp14_;
233 _tmp11_ = _tmp15_ == NULL;
234 } else {
235 _tmp11_ = FALSE;
236 }
237 if (_tmp11_) {
238 result = FALSE;
239 _vala_ccode_node_unref0 (var_decl);
240 _vala_ccode_node_unref0 (decl);
241 _vala_iterable_unref0 (_decl_list);
242 return result;
243 }
244 _vala_ccode_node_unref0 (var_decl);
245 _vala_ccode_node_unref0 (decl);
246 }
247 _vala_iterable_unref0 (_decl_list);
248 }
249 result = TRUE;
250 return result;
251 }
252
253 static void
vala_ccode_declaration_real_write_declaration(ValaCCodeNode * base,ValaCCodeWriter * writer)254 vala_ccode_declaration_real_write_declaration (ValaCCodeNode* base,
255 ValaCCodeWriter* writer)
256 {
257 ValaCCodeDeclaration * self;
258 ValaCCodeModifiers _tmp0_;
259 ValaCCodeModifiers _tmp1_;
260 ValaCCodeModifiers _tmp26_;
261 ValaCCodeModifiers _tmp27_;
262 ValaCCodeModifiers _tmp28_;
263 ValaCCodeModifiers _tmp29_;
264 const gchar* _tmp30_;
265 gboolean first = FALSE;
266 ValaCCodeModifiers _tmp41_;
267 ValaCCodeModifiers _tmp42_;
268 self = (ValaCCodeDeclaration*) base;
269 g_return_if_fail (writer != NULL);
270 _tmp0_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
271 _tmp1_ = _tmp0_;
272 if ((_tmp1_ & ((VALA_CCODE_MODIFIERS_STATIC | VALA_CCODE_MODIFIERS_INTERNAL) | VALA_CCODE_MODIFIERS_EXTERN)) != 0) {
273 ValaCCodeLineDirective* _tmp2_;
274 ValaCCodeLineDirective* _tmp3_;
275 ValaCCodeModifiers _tmp4_;
276 ValaCCodeModifiers _tmp5_;
277 ValaCCodeModifiers _tmp6_;
278 ValaCCodeModifiers _tmp7_;
279 ValaCCodeModifiers _tmp8_;
280 ValaCCodeModifiers _tmp9_;
281 gboolean _tmp10_ = FALSE;
282 ValaCCodeModifiers _tmp11_;
283 ValaCCodeModifiers _tmp12_;
284 ValaCCodeModifiers _tmp13_;
285 ValaCCodeModifiers _tmp14_;
286 const gchar* _tmp15_;
287 gboolean first = FALSE;
288 _tmp2_ = vala_ccode_node_get_line ((ValaCCodeNode*) self);
289 _tmp3_ = _tmp2_;
290 vala_ccode_writer_write_indent (writer, _tmp3_);
291 _tmp4_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
292 _tmp5_ = _tmp4_;
293 if ((_tmp5_ & VALA_CCODE_MODIFIERS_INTERNAL) != 0) {
294 vala_ccode_writer_write_string (writer, "G_GNUC_INTERNAL ");
295 }
296 _tmp6_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
297 _tmp7_ = _tmp6_;
298 if ((_tmp7_ & VALA_CCODE_MODIFIERS_STATIC) != 0) {
299 vala_ccode_writer_write_string (writer, "static ");
300 }
301 _tmp8_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
302 _tmp9_ = _tmp8_;
303 if ((_tmp9_ & VALA_CCODE_MODIFIERS_VOLATILE) != 0) {
304 vala_ccode_writer_write_string (writer, "volatile ");
305 }
306 _tmp11_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
307 _tmp12_ = _tmp11_;
308 if ((_tmp12_ & VALA_CCODE_MODIFIERS_EXTERN) != 0) {
309 _tmp10_ = !vala_ccode_declaration_has_initializer (self);
310 } else {
311 _tmp10_ = FALSE;
312 }
313 if (_tmp10_) {
314 vala_ccode_writer_write_string (writer, "extern ");
315 }
316 _tmp13_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
317 _tmp14_ = _tmp13_;
318 if ((_tmp14_ & VALA_CCODE_MODIFIERS_THREAD_LOCAL) != 0) {
319 vala_ccode_writer_write_string (writer, "thread_local ");
320 }
321 _tmp15_ = self->priv->_type_name;
322 vala_ccode_writer_write_string (writer, _tmp15_);
323 vala_ccode_writer_write_string (writer, " ");
324 first = TRUE;
325 {
326 ValaList* _decl_list = NULL;
327 ValaList* _tmp16_;
328 ValaList* _tmp17_;
329 gint _decl_size = 0;
330 ValaList* _tmp18_;
331 gint _tmp19_;
332 gint _tmp20_;
333 gint _decl_index = 0;
334 _tmp16_ = self->priv->declarators;
335 _tmp17_ = _vala_iterable_ref0 (_tmp16_);
336 _decl_list = _tmp17_;
337 _tmp18_ = _decl_list;
338 _tmp19_ = vala_collection_get_size ((ValaCollection*) _tmp18_);
339 _tmp20_ = _tmp19_;
340 _decl_size = _tmp20_;
341 _decl_index = -1;
342 while (TRUE) {
343 gint _tmp21_;
344 gint _tmp22_;
345 ValaCCodeDeclarator* decl = NULL;
346 ValaList* _tmp23_;
347 gpointer _tmp24_;
348 ValaCCodeDeclarator* _tmp25_;
349 _decl_index = _decl_index + 1;
350 _tmp21_ = _decl_index;
351 _tmp22_ = _decl_size;
352 if (!(_tmp21_ < _tmp22_)) {
353 break;
354 }
355 _tmp23_ = _decl_list;
356 _tmp24_ = vala_list_get (_tmp23_, _decl_index);
357 decl = (ValaCCodeDeclarator*) _tmp24_;
358 if (!first) {
359 vala_ccode_writer_write_string (writer, ", ");
360 } else {
361 first = FALSE;
362 }
363 _tmp25_ = decl;
364 vala_ccode_node_write ((ValaCCodeNode*) _tmp25_, writer);
365 _vala_ccode_node_unref0 (decl);
366 }
367 _vala_iterable_unref0 (_decl_list);
368 }
369 vala_ccode_writer_write_string (writer, ";");
370 vala_ccode_writer_write_newline (writer);
371 return;
372 }
373 vala_ccode_writer_write_indent (writer, NULL);
374 _tmp26_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
375 _tmp27_ = _tmp26_;
376 if ((_tmp27_ & VALA_CCODE_MODIFIERS_REGISTER) == VALA_CCODE_MODIFIERS_REGISTER) {
377 vala_ccode_writer_write_string (writer, "register ");
378 }
379 _tmp28_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
380 _tmp29_ = _tmp28_;
381 if ((_tmp29_ & VALA_CCODE_MODIFIERS_VOLATILE) != 0) {
382 vala_ccode_writer_write_string (writer, "volatile ");
383 }
384 _tmp30_ = self->priv->_type_name;
385 vala_ccode_writer_write_string (writer, _tmp30_);
386 vala_ccode_writer_write_string (writer, " ");
387 first = TRUE;
388 {
389 ValaList* _decl_list = NULL;
390 ValaList* _tmp31_;
391 ValaList* _tmp32_;
392 gint _decl_size = 0;
393 ValaList* _tmp33_;
394 gint _tmp34_;
395 gint _tmp35_;
396 gint _decl_index = 0;
397 _tmp31_ = self->priv->declarators;
398 _tmp32_ = _vala_iterable_ref0 (_tmp31_);
399 _decl_list = _tmp32_;
400 _tmp33_ = _decl_list;
401 _tmp34_ = vala_collection_get_size ((ValaCollection*) _tmp33_);
402 _tmp35_ = _tmp34_;
403 _decl_size = _tmp35_;
404 _decl_index = -1;
405 while (TRUE) {
406 gint _tmp36_;
407 gint _tmp37_;
408 ValaCCodeDeclarator* decl = NULL;
409 ValaList* _tmp38_;
410 gpointer _tmp39_;
411 ValaCCodeDeclarator* _tmp40_;
412 _decl_index = _decl_index + 1;
413 _tmp36_ = _decl_index;
414 _tmp37_ = _decl_size;
415 if (!(_tmp36_ < _tmp37_)) {
416 break;
417 }
418 _tmp38_ = _decl_list;
419 _tmp39_ = vala_list_get (_tmp38_, _decl_index);
420 decl = (ValaCCodeDeclarator*) _tmp39_;
421 if (!first) {
422 vala_ccode_writer_write_string (writer, ", ");
423 } else {
424 first = FALSE;
425 }
426 _tmp40_ = decl;
427 vala_ccode_node_write_declaration ((ValaCCodeNode*) _tmp40_, writer);
428 _vala_ccode_node_unref0 (decl);
429 }
430 _vala_iterable_unref0 (_decl_list);
431 }
432 _tmp41_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
433 _tmp42_ = _tmp41_;
434 if ((_tmp42_ & VALA_CCODE_MODIFIERS_DEPRECATED) == VALA_CCODE_MODIFIERS_DEPRECATED) {
435 vala_ccode_writer_write_string (writer, " G_GNUC_DEPRECATED");
436 }
437 vala_ccode_writer_write_string (writer, ";");
438 vala_ccode_writer_write_newline (writer);
439 }
440
441 static void
vala_ccode_declaration_class_init(ValaCCodeDeclarationClass * klass,gpointer klass_data)442 vala_ccode_declaration_class_init (ValaCCodeDeclarationClass * klass,
443 gpointer klass_data)
444 {
445 vala_ccode_declaration_parent_class = g_type_class_peek_parent (klass);
446 ((ValaCCodeNodeClass *) klass)->finalize = vala_ccode_declaration_finalize;
447 g_type_class_adjust_private_offset (klass, &ValaCCodeDeclaration_private_offset);
448 ((ValaCCodeNodeClass *) klass)->write = (void (*) (ValaCCodeNode*, ValaCCodeWriter*)) vala_ccode_declaration_real_write;
449 ((ValaCCodeNodeClass *) klass)->write_declaration = (void (*) (ValaCCodeNode*, ValaCCodeWriter*)) vala_ccode_declaration_real_write_declaration;
450 }
451
452 static void
vala_ccode_declaration_instance_init(ValaCCodeDeclaration * self,gpointer klass)453 vala_ccode_declaration_instance_init (ValaCCodeDeclaration * self,
454 gpointer klass)
455 {
456 GEqualFunc _tmp0_;
457 ValaArrayList* _tmp1_;
458 self->priv = vala_ccode_declaration_get_instance_private (self);
459 _tmp0_ = g_direct_equal;
460 _tmp1_ = vala_array_list_new (VALA_TYPE_CCODE_DECLARATOR, (GBoxedCopyFunc) vala_ccode_node_ref, (GDestroyNotify) vala_ccode_node_unref, _tmp0_);
461 self->priv->declarators = (ValaList*) _tmp1_;
462 }
463
464 static void
vala_ccode_declaration_finalize(ValaCCodeNode * obj)465 vala_ccode_declaration_finalize (ValaCCodeNode * obj)
466 {
467 ValaCCodeDeclaration * self;
468 self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_CCODE_DECLARATION, ValaCCodeDeclaration);
469 _g_free0 (self->priv->_type_name);
470 _vala_iterable_unref0 (self->priv->declarators);
471 VALA_CCODE_NODE_CLASS (vala_ccode_declaration_parent_class)->finalize (obj);
472 }
473
474 /**
475 * Represents a local variable declaration in the C code.
476 */
477 static GType
vala_ccode_declaration_get_type_once(void)478 vala_ccode_declaration_get_type_once (void)
479 {
480 static const GTypeInfo g_define_type_info = { sizeof (ValaCCodeDeclarationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_ccode_declaration_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaCCodeDeclaration), 0, (GInstanceInitFunc) vala_ccode_declaration_instance_init, NULL };
481 GType vala_ccode_declaration_type_id;
482 vala_ccode_declaration_type_id = g_type_register_static (VALA_TYPE_CCODE_STATEMENT, "ValaCCodeDeclaration", &g_define_type_info, 0);
483 ValaCCodeDeclaration_private_offset = g_type_add_instance_private (vala_ccode_declaration_type_id, sizeof (ValaCCodeDeclarationPrivate));
484 return vala_ccode_declaration_type_id;
485 }
486
487 GType
vala_ccode_declaration_get_type(void)488 vala_ccode_declaration_get_type (void)
489 {
490 static volatile gsize vala_ccode_declaration_type_id__volatile = 0;
491 if (g_once_init_enter (&vala_ccode_declaration_type_id__volatile)) {
492 GType vala_ccode_declaration_type_id;
493 vala_ccode_declaration_type_id = vala_ccode_declaration_get_type_once ();
494 g_once_init_leave (&vala_ccode_declaration_type_id__volatile, vala_ccode_declaration_type_id);
495 }
496 return vala_ccode_declaration_type_id__volatile;
497 }
498
499