1 /* valaattribute.c generated by valac, the Vala compiler
2 * generated from valaattribute.vala, do not modify */
3
4 /* valaattribute.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 "vala.h"
27 #include <stdlib.h>
28 #include <string.h>
29 #include <glib.h>
30 #include <valagee.h>
31 #include <glib-object.h>
32 #include <float.h>
33 #include <math.h>
34
35 #define _g_free0(var) (var = (g_free (var), NULL))
36 #define _vala_map_unref0(var) ((var == NULL) ? NULL : (var = (vala_map_unref (var), NULL)))
37 #define _vala_code_context_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_context_unref (var), NULL)))
38
39 struct _ValaAttributePrivate {
40 gchar* _name;
41 ValaMap* _args;
42 };
43
44 static gint ValaAttribute_private_offset;
45 static gpointer vala_attribute_parent_class = NULL;
46
47 static void vala_attribute_set_args (ValaAttribute* self,
48 ValaMap* value);
49 static void vala_attribute_finalize (ValaCodeNode * obj);
50 static GType vala_attribute_get_type_once (void);
51
52 static inline gpointer
vala_attribute_get_instance_private(ValaAttribute * self)53 vala_attribute_get_instance_private (ValaAttribute* self)
54 {
55 return G_STRUCT_MEMBER_P (self, ValaAttribute_private_offset);
56 }
57
58 const gchar*
vala_attribute_get_name(ValaAttribute * self)59 vala_attribute_get_name (ValaAttribute* 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_attribute_set_name(ValaAttribute * self,const gchar * value)70 vala_attribute_set_name (ValaAttribute* 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 ValaMap*
vala_attribute_get_args(ValaAttribute * self)81 vala_attribute_get_args (ValaAttribute* self)
82 {
83 ValaMap* result;
84 ValaMap* _tmp0_;
85 g_return_val_if_fail (self != NULL, NULL);
86 _tmp0_ = self->priv->_args;
87 result = _tmp0_;
88 return result;
89 }
90
91 static gpointer
_vala_map_ref0(gpointer self)92 _vala_map_ref0 (gpointer self)
93 {
94 return self ? vala_map_ref (self) : NULL;
95 }
96
97 static void
vala_attribute_set_args(ValaAttribute * self,ValaMap * value)98 vala_attribute_set_args (ValaAttribute* self,
99 ValaMap* value)
100 {
101 ValaMap* _tmp0_;
102 g_return_if_fail (self != NULL);
103 _tmp0_ = _vala_map_ref0 (value);
104 _vala_map_unref0 (self->priv->_args);
105 self->priv->_args = _tmp0_;
106 }
107
108 /**
109 * Creates a new attribute.
110 *
111 * @param name attribute type name
112 * @param source_reference reference to source code
113 * @return newly created attribute
114 */
115 ValaAttribute*
vala_attribute_construct(GType object_type,const gchar * name,ValaSourceReference * source_reference)116 vala_attribute_construct (GType object_type,
117 const gchar* name,
118 ValaSourceReference* source_reference)
119 {
120 ValaAttribute* self = NULL;
121 GHashFunc _tmp0_;
122 GEqualFunc _tmp1_;
123 GEqualFunc _tmp2_;
124 ValaHashMap* _tmp3_;
125 ValaHashMap* _tmp4_;
126 ValaCodeContext* _tmp5_;
127 ValaCodeContext* _tmp6_;
128 gboolean _tmp7_;
129 gboolean _tmp8_;
130 gboolean _tmp9_;
131 g_return_val_if_fail (name != NULL, NULL);
132 self = (ValaAttribute*) vala_code_node_construct (object_type);
133 vala_attribute_set_name (self, name);
134 vala_code_node_set_source_reference ((ValaCodeNode*) self, source_reference);
135 _tmp0_ = g_str_hash;
136 _tmp1_ = g_str_equal;
137 _tmp2_ = g_direct_equal;
138 _tmp3_ = vala_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp0_, _tmp1_, _tmp2_);
139 _tmp4_ = _tmp3_;
140 vala_attribute_set_args (self, (ValaMap*) _tmp4_);
141 _vala_map_unref0 (_tmp4_);
142 _tmp5_ = vala_code_context_get ();
143 _tmp6_ = _tmp5_;
144 _tmp7_ = vala_code_context_get_deprecated (_tmp6_);
145 _tmp8_ = _tmp7_;
146 _tmp9_ = !_tmp8_;
147 _vala_code_context_unref0 (_tmp6_);
148 if (_tmp9_) {
149 if (g_strcmp0 (name, "Deprecated") == 0) {
150 vala_report_deprecated (source_reference, "[Deprecated] is deprecated. Use [Version (deprecated = true, deprecate" \
151 "d_since = \"\", replacement = \"\")]");
152 } else {
153 if (g_strcmp0 (name, "Experimental") == 0) {
154 vala_report_deprecated (source_reference, "[Experimental] is deprecated. Use [Version (experimental = true, exper" \
155 "imental_until = \"\")]");
156 }
157 }
158 }
159 return self;
160 }
161
162 ValaAttribute*
vala_attribute_new(const gchar * name,ValaSourceReference * source_reference)163 vala_attribute_new (const gchar* name,
164 ValaSourceReference* source_reference)
165 {
166 return vala_attribute_construct (VALA_TYPE_ATTRIBUTE, name, source_reference);
167 }
168
169 /**
170 * Adds an attribute argument.
171 *
172 * @param key argument name
173 * @param value argument value
174 */
175 void
vala_attribute_add_argument(ValaAttribute * self,const gchar * key,const gchar * value)176 vala_attribute_add_argument (ValaAttribute* self,
177 const gchar* key,
178 const gchar* value)
179 {
180 ValaMap* _tmp0_;
181 g_return_if_fail (self != NULL);
182 g_return_if_fail (key != NULL);
183 g_return_if_fail (value != NULL);
184 _tmp0_ = self->priv->_args;
185 vala_map_set (_tmp0_, key, value);
186 }
187
188 /**
189 * Returns whether this attribute has the specified named argument.
190 *
191 * @param name argument name
192 * @return true if the argument has been found, false otherwise
193 */
194 gboolean
vala_attribute_has_argument(ValaAttribute * self,const gchar * name)195 vala_attribute_has_argument (ValaAttribute* self,
196 const gchar* name)
197 {
198 ValaMap* _tmp0_;
199 gboolean result = FALSE;
200 g_return_val_if_fail (self != NULL, FALSE);
201 g_return_val_if_fail (name != NULL, FALSE);
202 _tmp0_ = self->priv->_args;
203 result = vala_map_contains (_tmp0_, name);
204 return result;
205 }
206
207 /**
208 * Returns the string value of the specified named argument.
209 *
210 * @param name argument name
211 * @return string value
212 */
213 static glong
string_strnlen(gchar * str,glong maxlen)214 string_strnlen (gchar* str,
215 glong maxlen)
216 {
217 gchar* end = NULL;
218 gchar* _tmp0_;
219 gchar* _tmp1_;
220 glong result = 0L;
221 _tmp0_ = memchr (str, 0, (gsize) maxlen);
222 end = _tmp0_;
223 _tmp1_ = end;
224 if (_tmp1_ == NULL) {
225 result = maxlen;
226 return result;
227 } else {
228 gchar* _tmp2_;
229 _tmp2_ = end;
230 result = (glong) (_tmp2_ - str);
231 return result;
232 }
233 }
234
235 static gchar*
string_substring(const gchar * self,glong offset,glong len)236 string_substring (const gchar* self,
237 glong offset,
238 glong len)
239 {
240 glong string_length = 0L;
241 gboolean _tmp0_ = FALSE;
242 gchar* _tmp3_;
243 gchar* result = NULL;
244 g_return_val_if_fail (self != NULL, NULL);
245 if (offset >= ((glong) 0)) {
246 _tmp0_ = len >= ((glong) 0);
247 } else {
248 _tmp0_ = FALSE;
249 }
250 if (_tmp0_) {
251 string_length = string_strnlen ((gchar*) self, offset + len);
252 } else {
253 gint _tmp1_;
254 gint _tmp2_;
255 _tmp1_ = strlen (self);
256 _tmp2_ = _tmp1_;
257 string_length = (glong) _tmp2_;
258 }
259 if (offset < ((glong) 0)) {
260 offset = string_length + offset;
261 g_return_val_if_fail (offset >= ((glong) 0), NULL);
262 } else {
263 g_return_val_if_fail (offset <= string_length, NULL);
264 }
265 if (len < ((glong) 0)) {
266 len = string_length - offset;
267 }
268 g_return_val_if_fail ((offset + len) <= string_length, NULL);
269 _tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
270 result = _tmp3_;
271 return result;
272 }
273
274 gchar*
vala_attribute_get_string(ValaAttribute * self,const gchar * name,const gchar * default_value)275 vala_attribute_get_string (ValaAttribute* self,
276 const gchar* name,
277 const gchar* default_value)
278 {
279 gchar* value = NULL;
280 ValaMap* _tmp0_;
281 gpointer _tmp1_;
282 const gchar* _tmp2_;
283 gchar* noquotes = NULL;
284 const gchar* _tmp4_;
285 const gchar* _tmp5_;
286 gint _tmp6_;
287 gint _tmp7_;
288 gchar* _tmp8_;
289 const gchar* _tmp9_;
290 gchar* _tmp10_;
291 gchar* result = NULL;
292 g_return_val_if_fail (self != NULL, NULL);
293 g_return_val_if_fail (name != NULL, NULL);
294 _tmp0_ = self->priv->_args;
295 _tmp1_ = vala_map_get (_tmp0_, name);
296 value = (gchar*) _tmp1_;
297 _tmp2_ = value;
298 if (_tmp2_ == NULL) {
299 gchar* _tmp3_;
300 _tmp3_ = g_strdup (default_value);
301 result = _tmp3_;
302 _g_free0 (value);
303 return result;
304 }
305 _tmp4_ = value;
306 _tmp5_ = value;
307 _tmp6_ = strlen (_tmp5_);
308 _tmp7_ = _tmp6_;
309 _tmp8_ = string_substring (_tmp4_, (glong) 1, (glong) ((guint) (_tmp7_ - 2)));
310 noquotes = _tmp8_;
311 _tmp9_ = noquotes;
312 _tmp10_ = g_strcompress (_tmp9_);
313 result = _tmp10_;
314 _g_free0 (noquotes);
315 _g_free0 (value);
316 return result;
317 }
318
319 /**
320 * Returns the integer value of the specified named argument.
321 *
322 * @param name argument name
323 * @return integer value
324 */
325 gint
vala_attribute_get_integer(ValaAttribute * self,const gchar * name,gint default_value)326 vala_attribute_get_integer (ValaAttribute* self,
327 const gchar* name,
328 gint default_value)
329 {
330 gchar* value = NULL;
331 ValaMap* _tmp0_;
332 gpointer _tmp1_;
333 const gchar* _tmp2_;
334 const gchar* _tmp3_;
335 gint result = 0;
336 g_return_val_if_fail (self != NULL, 0);
337 g_return_val_if_fail (name != NULL, 0);
338 _tmp0_ = self->priv->_args;
339 _tmp1_ = vala_map_get (_tmp0_, name);
340 value = (gchar*) _tmp1_;
341 _tmp2_ = value;
342 if (_tmp2_ == NULL) {
343 result = default_value;
344 _g_free0 (value);
345 return result;
346 }
347 _tmp3_ = value;
348 result = atoi (_tmp3_);
349 _g_free0 (value);
350 return result;
351 }
352
353 /**
354 * Returns the double value of the specified named argument.
355 *
356 * @param name argument name
357 * @return double value
358 */
359 static gdouble
double_parse(const gchar * str)360 double_parse (const gchar* str)
361 {
362 gdouble result = 0.0;
363 g_return_val_if_fail (str != NULL, 0.0);
364 result = g_ascii_strtod (str, NULL);
365 return result;
366 }
367
368 gdouble
vala_attribute_get_double(ValaAttribute * self,const gchar * name,gdouble default_value)369 vala_attribute_get_double (ValaAttribute* self,
370 const gchar* name,
371 gdouble default_value)
372 {
373 gchar* value = NULL;
374 ValaMap* _tmp0_;
375 gpointer _tmp1_;
376 const gchar* _tmp2_;
377 const gchar* _tmp3_;
378 gdouble result = 0.0;
379 g_return_val_if_fail (self != NULL, 0.0);
380 g_return_val_if_fail (name != NULL, 0.0);
381 _tmp0_ = self->priv->_args;
382 _tmp1_ = vala_map_get (_tmp0_, name);
383 value = (gchar*) _tmp1_;
384 _tmp2_ = value;
385 if (_tmp2_ == NULL) {
386 result = default_value;
387 _g_free0 (value);
388 return result;
389 }
390 _tmp3_ = value;
391 result = double_parse (_tmp3_);
392 _g_free0 (value);
393 return result;
394 }
395
396 /**
397 * Returns the boolean value of the specified named argument.
398 *
399 * @param name argument name
400 * @return boolean value
401 */
402 static gboolean
bool_parse(const gchar * str)403 bool_parse (const gchar* str)
404 {
405 gboolean result = FALSE;
406 g_return_val_if_fail (str != NULL, FALSE);
407 if (g_strcmp0 (str, "true") == 0) {
408 result = TRUE;
409 return result;
410 } else {
411 result = FALSE;
412 return result;
413 }
414 }
415
416 gboolean
vala_attribute_get_bool(ValaAttribute * self,const gchar * name,gboolean default_value)417 vala_attribute_get_bool (ValaAttribute* self,
418 const gchar* name,
419 gboolean default_value)
420 {
421 gchar* value = NULL;
422 ValaMap* _tmp0_;
423 gpointer _tmp1_;
424 const gchar* _tmp2_;
425 const gchar* _tmp3_;
426 gboolean result = FALSE;
427 g_return_val_if_fail (self != NULL, FALSE);
428 g_return_val_if_fail (name != NULL, FALSE);
429 _tmp0_ = self->priv->_args;
430 _tmp1_ = vala_map_get (_tmp0_, name);
431 value = (gchar*) _tmp1_;
432 _tmp2_ = value;
433 if (_tmp2_ == NULL) {
434 result = default_value;
435 _g_free0 (value);
436 return result;
437 }
438 _tmp3_ = value;
439 result = bool_parse (_tmp3_);
440 _g_free0 (value);
441 return result;
442 }
443
444 static void
vala_attribute_class_init(ValaAttributeClass * klass,gpointer klass_data)445 vala_attribute_class_init (ValaAttributeClass * klass,
446 gpointer klass_data)
447 {
448 vala_attribute_parent_class = g_type_class_peek_parent (klass);
449 ((ValaCodeNodeClass *) klass)->finalize = vala_attribute_finalize;
450 g_type_class_adjust_private_offset (klass, &ValaAttribute_private_offset);
451 }
452
453 static void
vala_attribute_instance_init(ValaAttribute * self,gpointer klass)454 vala_attribute_instance_init (ValaAttribute * self,
455 gpointer klass)
456 {
457 self->priv = vala_attribute_get_instance_private (self);
458 }
459
460 static void
vala_attribute_finalize(ValaCodeNode * obj)461 vala_attribute_finalize (ValaCodeNode * obj)
462 {
463 ValaAttribute * self;
464 self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_ATTRIBUTE, ValaAttribute);
465 _g_free0 (self->priv->_name);
466 _vala_map_unref0 (self->priv->_args);
467 VALA_CODE_NODE_CLASS (vala_attribute_parent_class)->finalize (obj);
468 }
469
470 /**
471 * Represents an attribute specified in the source code.
472 */
473 static GType
vala_attribute_get_type_once(void)474 vala_attribute_get_type_once (void)
475 {
476 static const GTypeInfo g_define_type_info = { sizeof (ValaAttributeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_attribute_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaAttribute), 0, (GInstanceInitFunc) vala_attribute_instance_init, NULL };
477 GType vala_attribute_type_id;
478 vala_attribute_type_id = g_type_register_static (VALA_TYPE_CODE_NODE, "ValaAttribute", &g_define_type_info, 0);
479 ValaAttribute_private_offset = g_type_add_instance_private (vala_attribute_type_id, sizeof (ValaAttributePrivate));
480 return vala_attribute_type_id;
481 }
482
483 GType
vala_attribute_get_type(void)484 vala_attribute_get_type (void)
485 {
486 static volatile gsize vala_attribute_type_id__volatile = 0;
487 if (g_once_init_enter (&vala_attribute_type_id__volatile)) {
488 GType vala_attribute_type_id;
489 vala_attribute_type_id = vala_attribute_get_type_once ();
490 g_once_init_leave (&vala_attribute_type_id__volatile, vala_attribute_type_id);
491 }
492 return vala_attribute_type_id__volatile;
493 }
494
495