1 /* valaccodefunctiondeclarator.c generated by valac, the Vala compiler
2 * generated from valaccodefunctiondeclarator.vala, do not modify */
3
4 /* valaccodefunctiondeclarator.vala
5 *
6 * Copyright (C) 2006-2007 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 _ValaCCodeFunctionDeclaratorPrivate {
38 gchar* _name;
39 ValaList* parameters;
40 };
41
42 static gint ValaCCodeFunctionDeclarator_private_offset;
43 static gpointer vala_ccode_function_declarator_parent_class = NULL;
44
45 static void vala_ccode_function_declarator_real_write (ValaCCodeNode* base,
46 ValaCCodeWriter* writer);
47 static void vala_ccode_function_declarator_real_write_declaration (ValaCCodeNode* base,
48 ValaCCodeWriter* writer);
49 static void vala_ccode_function_declarator_finalize (ValaCCodeNode * obj);
50 static GType vala_ccode_function_declarator_get_type_once (void);
51
52 static inline gpointer
vala_ccode_function_declarator_get_instance_private(ValaCCodeFunctionDeclarator * self)53 vala_ccode_function_declarator_get_instance_private (ValaCCodeFunctionDeclarator* self)
54 {
55 return G_STRUCT_MEMBER_P (self, ValaCCodeFunctionDeclarator_private_offset);
56 }
57
58 const gchar*
vala_ccode_function_declarator_get_name(ValaCCodeFunctionDeclarator * self)59 vala_ccode_function_declarator_get_name (ValaCCodeFunctionDeclarator* self)
60 {
61 const gchar* result;
62 const gchar* _tmp0_;
63 g_return_val_if_fail (self != NULL, NULL);
64 _tmp0_ = self->priv->_name;
65 result = _tmp0_;
66 return result;
67 }
68
69 void
vala_ccode_function_declarator_set_name(ValaCCodeFunctionDeclarator * self,const gchar * value)70 vala_ccode_function_declarator_set_name (ValaCCodeFunctionDeclarator* self,
71 const gchar* value)
72 {
73 gchar* _tmp0_;
74 g_return_if_fail (self != NULL);
75 _tmp0_ = g_strdup (value);
76 _g_free0 (self->priv->_name);
77 self->priv->_name = _tmp0_;
78 }
79
80 ValaCCodeFunctionDeclarator*
vala_ccode_function_declarator_construct(GType object_type,const gchar * name)81 vala_ccode_function_declarator_construct (GType object_type,
82 const gchar* name)
83 {
84 ValaCCodeFunctionDeclarator* self = NULL;
85 g_return_val_if_fail (name != NULL, NULL);
86 self = (ValaCCodeFunctionDeclarator*) vala_ccode_declarator_construct (object_type);
87 vala_ccode_function_declarator_set_name (self, name);
88 return self;
89 }
90
91 ValaCCodeFunctionDeclarator*
vala_ccode_function_declarator_new(const gchar * name)92 vala_ccode_function_declarator_new (const gchar* name)
93 {
94 return vala_ccode_function_declarator_construct (VALA_TYPE_CCODE_FUNCTION_DECLARATOR, name);
95 }
96
97 /**
98 * Appends the specified parameter to the list of function parameters.
99 *
100 * @param param a formal parameter
101 */
102 void
vala_ccode_function_declarator_add_parameter(ValaCCodeFunctionDeclarator * self,ValaCCodeParameter * param)103 vala_ccode_function_declarator_add_parameter (ValaCCodeFunctionDeclarator* self,
104 ValaCCodeParameter* param)
105 {
106 ValaList* _tmp0_;
107 g_return_if_fail (self != NULL);
108 g_return_if_fail (param != NULL);
109 _tmp0_ = self->priv->parameters;
110 vala_collection_add ((ValaCollection*) _tmp0_, param);
111 }
112
113 static void
vala_ccode_function_declarator_real_write(ValaCCodeNode * base,ValaCCodeWriter * writer)114 vala_ccode_function_declarator_real_write (ValaCCodeNode* base,
115 ValaCCodeWriter* writer)
116 {
117 ValaCCodeFunctionDeclarator * self;
118 self = (ValaCCodeFunctionDeclarator*) base;
119 g_return_if_fail (writer != NULL);
120 vala_ccode_node_write_declaration ((ValaCCodeNode*) self, writer);
121 }
122
123 static gpointer
_vala_iterable_ref0(gpointer self)124 _vala_iterable_ref0 (gpointer self)
125 {
126 return self ? vala_iterable_ref (self) : NULL;
127 }
128
129 static void
vala_ccode_function_declarator_real_write_declaration(ValaCCodeNode * base,ValaCCodeWriter * writer)130 vala_ccode_function_declarator_real_write_declaration (ValaCCodeNode* base,
131 ValaCCodeWriter* writer)
132 {
133 ValaCCodeFunctionDeclarator * self;
134 const gchar* _tmp0_;
135 gboolean _tmp1_ = FALSE;
136 ValaCCodeModifiers _tmp2_;
137 ValaCCodeModifiers _tmp3_;
138 gboolean has_args = FALSE;
139 gint i = 0;
140 gint format_arg_index = 0;
141 gint args_index = 0;
142 ValaCCodeModifiers _tmp29_;
143 ValaCCodeModifiers _tmp30_;
144 ValaCCodeModifiers _tmp31_;
145 ValaCCodeModifiers _tmp32_;
146 self = (ValaCCodeFunctionDeclarator*) base;
147 g_return_if_fail (writer != NULL);
148 vala_ccode_writer_write_string (writer, "(*");
149 _tmp0_ = self->priv->_name;
150 vala_ccode_writer_write_string (writer, _tmp0_);
151 vala_ccode_writer_write_string (writer, ") (");
152 _tmp2_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
153 _tmp3_ = _tmp2_;
154 if ((_tmp3_ & VALA_CCODE_MODIFIERS_PRINTF) == VALA_CCODE_MODIFIERS_PRINTF) {
155 _tmp1_ = TRUE;
156 } else {
157 ValaCCodeModifiers _tmp4_;
158 ValaCCodeModifiers _tmp5_;
159 _tmp4_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
160 _tmp5_ = _tmp4_;
161 _tmp1_ = (_tmp5_ & VALA_CCODE_MODIFIERS_SCANF) == VALA_CCODE_MODIFIERS_SCANF;
162 }
163 has_args = _tmp1_;
164 i = 0;
165 format_arg_index = -1;
166 args_index = -1;
167 {
168 ValaList* _param_list = NULL;
169 ValaList* _tmp6_;
170 ValaList* _tmp7_;
171 gint _param_size = 0;
172 ValaList* _tmp8_;
173 gint _tmp9_;
174 gint _tmp10_;
175 gint _param_index = 0;
176 _tmp6_ = self->priv->parameters;
177 _tmp7_ = _vala_iterable_ref0 (_tmp6_);
178 _param_list = _tmp7_;
179 _tmp8_ = _param_list;
180 _tmp9_ = vala_collection_get_size ((ValaCollection*) _tmp8_);
181 _tmp10_ = _tmp9_;
182 _param_size = _tmp10_;
183 _param_index = -1;
184 while (TRUE) {
185 gint _tmp11_;
186 gint _tmp12_;
187 ValaCCodeParameter* param = NULL;
188 ValaList* _tmp13_;
189 gpointer _tmp14_;
190 ValaCCodeParameter* _tmp15_;
191 ValaCCodeParameter* _tmp16_;
192 ValaCCodeModifiers _tmp17_;
193 ValaCCodeModifiers _tmp18_;
194 gboolean _tmp19_ = FALSE;
195 gint _tmp28_;
196 _param_index = _param_index + 1;
197 _tmp11_ = _param_index;
198 _tmp12_ = _param_size;
199 if (!(_tmp11_ < _tmp12_)) {
200 break;
201 }
202 _tmp13_ = _param_list;
203 _tmp14_ = vala_list_get (_tmp13_, _param_index);
204 param = (ValaCCodeParameter*) _tmp14_;
205 if (i > 0) {
206 vala_ccode_writer_write_string (writer, ", ");
207 }
208 _tmp15_ = param;
209 vala_ccode_node_write ((ValaCCodeNode*) _tmp15_, writer);
210 _tmp16_ = param;
211 _tmp17_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) _tmp16_);
212 _tmp18_ = _tmp17_;
213 if ((_tmp18_ & VALA_CCODE_MODIFIERS_FORMAT_ARG) == VALA_CCODE_MODIFIERS_FORMAT_ARG) {
214 format_arg_index = i;
215 }
216 if (has_args) {
217 ValaCCodeParameter* _tmp20_;
218 gboolean _tmp21_;
219 gboolean _tmp22_;
220 _tmp20_ = param;
221 _tmp21_ = vala_ccode_parameter_get_ellipsis (_tmp20_);
222 _tmp22_ = _tmp21_;
223 _tmp19_ = _tmp22_;
224 } else {
225 _tmp19_ = FALSE;
226 }
227 if (_tmp19_) {
228 args_index = i;
229 } else {
230 gboolean _tmp23_ = FALSE;
231 gboolean _tmp24_ = FALSE;
232 if (has_args) {
233 ValaCCodeParameter* _tmp25_;
234 const gchar* _tmp26_;
235 const gchar* _tmp27_;
236 _tmp25_ = param;
237 _tmp26_ = vala_ccode_parameter_get_type_name (_tmp25_);
238 _tmp27_ = _tmp26_;
239 _tmp24_ = g_strcmp0 (_tmp27_, "va_list") == 0;
240 } else {
241 _tmp24_ = FALSE;
242 }
243 if (_tmp24_) {
244 _tmp23_ = format_arg_index < 0;
245 } else {
246 _tmp23_ = FALSE;
247 }
248 if (_tmp23_) {
249 format_arg_index = i - 1;
250 }
251 }
252 _tmp28_ = i;
253 i = _tmp28_ + 1;
254 _vala_ccode_node_unref0 (param);
255 }
256 _vala_iterable_unref0 (_param_list);
257 }
258 if (i == 0) {
259 vala_ccode_writer_write_string (writer, "void");
260 }
261 vala_ccode_writer_write_string (writer, ")");
262 _tmp29_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
263 _tmp30_ = _tmp29_;
264 if ((_tmp30_ & VALA_CCODE_MODIFIERS_DEPRECATED) == VALA_CCODE_MODIFIERS_DEPRECATED) {
265 vala_ccode_writer_write_string (writer, " G_GNUC_DEPRECATED");
266 }
267 _tmp31_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
268 _tmp32_ = _tmp31_;
269 if ((_tmp32_ & VALA_CCODE_MODIFIERS_PRINTF) == VALA_CCODE_MODIFIERS_PRINTF) {
270 gint _tmp33_ = 0;
271 gchar* _tmp34_;
272 gchar* _tmp35_;
273 if (format_arg_index >= 0) {
274 _tmp33_ = format_arg_index + 1;
275 } else {
276 _tmp33_ = args_index;
277 }
278 format_arg_index = _tmp33_;
279 _tmp34_ = g_strdup_printf (" G_GNUC_PRINTF(%d,%d)", format_arg_index, args_index + 1);
280 _tmp35_ = _tmp34_;
281 vala_ccode_writer_write_string (writer, _tmp35_);
282 _g_free0 (_tmp35_);
283 } else {
284 ValaCCodeModifiers _tmp36_;
285 ValaCCodeModifiers _tmp37_;
286 _tmp36_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
287 _tmp37_ = _tmp36_;
288 if ((_tmp37_ & VALA_CCODE_MODIFIERS_SCANF) == VALA_CCODE_MODIFIERS_SCANF) {
289 gint _tmp38_ = 0;
290 gchar* _tmp39_;
291 gchar* _tmp40_;
292 if (format_arg_index >= 0) {
293 _tmp38_ = format_arg_index + 1;
294 } else {
295 _tmp38_ = args_index;
296 }
297 format_arg_index = _tmp38_;
298 _tmp39_ = g_strdup_printf (" G_GNUC_SCANF(%d,%d)", format_arg_index, args_index + 1);
299 _tmp40_ = _tmp39_;
300 vala_ccode_writer_write_string (writer, _tmp40_);
301 _g_free0 (_tmp40_);
302 } else {
303 if (format_arg_index >= 0) {
304 gchar* _tmp41_;
305 gchar* _tmp42_;
306 _tmp41_ = g_strdup_printf (" G_GNUC_FORMAT(%d)", format_arg_index + 1);
307 _tmp42_ = _tmp41_;
308 vala_ccode_writer_write_string (writer, _tmp42_);
309 _g_free0 (_tmp42_);
310 }
311 }
312 }
313 }
314
315 static void
vala_ccode_function_declarator_class_init(ValaCCodeFunctionDeclaratorClass * klass,gpointer klass_data)316 vala_ccode_function_declarator_class_init (ValaCCodeFunctionDeclaratorClass * klass,
317 gpointer klass_data)
318 {
319 vala_ccode_function_declarator_parent_class = g_type_class_peek_parent (klass);
320 ((ValaCCodeNodeClass *) klass)->finalize = vala_ccode_function_declarator_finalize;
321 g_type_class_adjust_private_offset (klass, &ValaCCodeFunctionDeclarator_private_offset);
322 ((ValaCCodeNodeClass *) klass)->write = (void (*) (ValaCCodeNode*, ValaCCodeWriter*)) vala_ccode_function_declarator_real_write;
323 ((ValaCCodeNodeClass *) klass)->write_declaration = (void (*) (ValaCCodeNode*, ValaCCodeWriter*)) vala_ccode_function_declarator_real_write_declaration;
324 }
325
326 static void
vala_ccode_function_declarator_instance_init(ValaCCodeFunctionDeclarator * self,gpointer klass)327 vala_ccode_function_declarator_instance_init (ValaCCodeFunctionDeclarator * self,
328 gpointer klass)
329 {
330 GEqualFunc _tmp0_;
331 ValaArrayList* _tmp1_;
332 self->priv = vala_ccode_function_declarator_get_instance_private (self);
333 _tmp0_ = g_direct_equal;
334 _tmp1_ = vala_array_list_new (VALA_TYPE_CCODE_PARAMETER, (GBoxedCopyFunc) vala_ccode_node_ref, (GDestroyNotify) vala_ccode_node_unref, _tmp0_);
335 self->priv->parameters = (ValaList*) _tmp1_;
336 }
337
338 static void
vala_ccode_function_declarator_finalize(ValaCCodeNode * obj)339 vala_ccode_function_declarator_finalize (ValaCCodeNode * obj)
340 {
341 ValaCCodeFunctionDeclarator * self;
342 self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_CCODE_FUNCTION_DECLARATOR, ValaCCodeFunctionDeclarator);
343 _g_free0 (self->priv->_name);
344 _vala_iterable_unref0 (self->priv->parameters);
345 VALA_CCODE_NODE_CLASS (vala_ccode_function_declarator_parent_class)->finalize (obj);
346 }
347
348 /**
349 * Represents a function pointer declarator in the C code.
350 */
351 static GType
vala_ccode_function_declarator_get_type_once(void)352 vala_ccode_function_declarator_get_type_once (void)
353 {
354 static const GTypeInfo g_define_type_info = { sizeof (ValaCCodeFunctionDeclaratorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_ccode_function_declarator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaCCodeFunctionDeclarator), 0, (GInstanceInitFunc) vala_ccode_function_declarator_instance_init, NULL };
355 GType vala_ccode_function_declarator_type_id;
356 vala_ccode_function_declarator_type_id = g_type_register_static (VALA_TYPE_CCODE_DECLARATOR, "ValaCCodeFunctionDeclarator", &g_define_type_info, 0);
357 ValaCCodeFunctionDeclarator_private_offset = g_type_add_instance_private (vala_ccode_function_declarator_type_id, sizeof (ValaCCodeFunctionDeclaratorPrivate));
358 return vala_ccode_function_declarator_type_id;
359 }
360
361 GType
vala_ccode_function_declarator_get_type(void)362 vala_ccode_function_declarator_get_type (void)
363 {
364 static volatile gsize vala_ccode_function_declarator_type_id__volatile = 0;
365 if (g_once_init_enter (&vala_ccode_function_declarator_type_id__volatile)) {
366 GType vala_ccode_function_declarator_type_id;
367 vala_ccode_function_declarator_type_id = vala_ccode_function_declarator_get_type_once ();
368 g_once_init_leave (&vala_ccode_function_declarator_type_id__volatile, vala_ccode_function_declarator_type_id);
369 }
370 return vala_ccode_function_declarator_type_id__volatile;
371 }
372
373