1 /* field.c generated by valac, the Vala compiler
2 * generated from field.vala, do not modify */
3
4 /* field.vala
5 *
6 * Copyright (C) 2008-2011 Florian Brosch
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 * Florian Brosch <flo.brosch@gmail.com>
24 */
25
26 #include "valadoc.h"
27 #include <stdlib.h>
28 #include <string.h>
29 #include <glib.h>
30 #include <vala.h>
31 #include <valacodegen.h>
32
33 enum {
34 VALADOC_API_FIELD_0_PROPERTY,
35 VALADOC_API_FIELD_FIELD_TYPE_PROPERTY,
36 VALADOC_API_FIELD_IS_STATIC_PROPERTY,
37 VALADOC_API_FIELD_IS_CLASS_PROPERTY,
38 VALADOC_API_FIELD_IS_VOLATILE_PROPERTY,
39 VALADOC_API_FIELD_NODE_TYPE_PROPERTY,
40 VALADOC_API_FIELD_NUM_PROPERTIES
41 };
42 static GParamSpec* valadoc_api_field_properties[VALADOC_API_FIELD_NUM_PROPERTIES];
43 #define _g_free0(var) (var = (g_free (var), NULL))
44 #define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
45 #define _valadoc_api_signature_builder_unref0(var) ((var == NULL) ? NULL : (var = (valadoc_api_signature_builder_unref (var), NULL)))
46
47 struct _ValadocApiFieldPrivate {
48 gchar* cname;
49 ValadocApiTypeReference* _field_type;
50 gboolean _is_static;
51 gboolean _is_class;
52 gboolean _is_volatile;
53 };
54
55 static gint ValadocApiField_private_offset;
56 static gpointer valadoc_api_field_parent_class = NULL;
57
58 static void valadoc_api_field_set_is_static (ValadocApiField* self,
59 gboolean value);
60 static void valadoc_api_field_set_is_class (ValadocApiField* self,
61 gboolean value);
62 static void valadoc_api_field_set_is_volatile (ValadocApiField* self,
63 gboolean value);
64 static ValadocContentInline* valadoc_api_field_real_build_signature (ValadocApiItem* base);
65 static void valadoc_api_field_real_accept (ValadocApiNode* base,
66 ValadocApiVisitor* visitor);
67 static void valadoc_api_field_finalize (GObject * obj);
68 static GType valadoc_api_field_get_type_once (void);
69 static void _vala_valadoc_api_field_get_property (GObject * object,
70 guint property_id,
71 GValue * value,
72 GParamSpec * pspec);
73 static void _vala_valadoc_api_field_set_property (GObject * object,
74 guint property_id,
75 const GValue * value,
76 GParamSpec * pspec);
77
78 static inline gpointer
valadoc_api_field_get_instance_private(ValadocApiField * self)79 valadoc_api_field_get_instance_private (ValadocApiField* self)
80 {
81 return G_STRUCT_MEMBER_P (self, ValadocApiField_private_offset);
82 }
83
84 ValadocApiField*
valadoc_api_field_construct(GType object_type,ValadocApiNode * parent,ValadocApiSourceFile * file,const gchar * name,ValaSymbolAccessibility accessibility,ValadocApiSourceComment * comment,ValaField * data)85 valadoc_api_field_construct (GType object_type,
86 ValadocApiNode* parent,
87 ValadocApiSourceFile* file,
88 const gchar* name,
89 ValaSymbolAccessibility accessibility,
90 ValadocApiSourceComment* comment,
91 ValaField* data)
92 {
93 ValadocApiField * self = NULL;
94 gboolean _tmp0_ = FALSE;
95 ValaMemberBinding _tmp3_;
96 ValaMemberBinding _tmp4_;
97 gboolean _tmp5_;
98 gboolean _tmp6_;
99 gchar* _tmp7_;
100 g_return_val_if_fail (parent != NULL, NULL);
101 g_return_val_if_fail (file != NULL, NULL);
102 g_return_val_if_fail (name != NULL, NULL);
103 g_return_val_if_fail (data != NULL, NULL);
104 self = (ValadocApiField*) valadoc_api_symbol_construct (object_type, parent, file, name, accessibility, comment, (ValaSymbol*) data);
105 if (!VALADOC_API_IS_NAMESPACE (parent)) {
106 ValaMemberBinding _tmp1_;
107 ValaMemberBinding _tmp2_;
108 _tmp1_ = vala_field_get_binding (data);
109 _tmp2_ = _tmp1_;
110 _tmp0_ = _tmp2_ == VALA_MEMBER_BINDING_STATIC;
111 } else {
112 _tmp0_ = FALSE;
113 }
114 valadoc_api_field_set_is_static (self, _tmp0_);
115 _tmp3_ = vala_field_get_binding (data);
116 _tmp4_ = _tmp3_;
117 valadoc_api_field_set_is_class (self, _tmp4_ == VALA_MEMBER_BINDING_CLASS);
118 _tmp5_ = vala_field_get_is_volatile (data);
119 _tmp6_ = _tmp5_;
120 valadoc_api_field_set_is_volatile (self, _tmp6_);
121 _tmp7_ = vala_get_ccode_name ((ValaCodeNode*) data);
122 _g_free0 (self->priv->cname);
123 self->priv->cname = _tmp7_;
124 return self;
125 }
126
127 ValadocApiField*
valadoc_api_field_new(ValadocApiNode * parent,ValadocApiSourceFile * file,const gchar * name,ValaSymbolAccessibility accessibility,ValadocApiSourceComment * comment,ValaField * data)128 valadoc_api_field_new (ValadocApiNode* parent,
129 ValadocApiSourceFile* file,
130 const gchar* name,
131 ValaSymbolAccessibility accessibility,
132 ValadocApiSourceComment* comment,
133 ValaField* data)
134 {
135 return valadoc_api_field_construct (VALADOC_API_TYPE_FIELD, parent, file, name, accessibility, comment, data);
136 }
137
138 /**
139 * Returns the name of this field as it is used in C.
140 */
141 gchar*
valadoc_api_field_get_cname(ValadocApiField * self)142 valadoc_api_field_get_cname (ValadocApiField* self)
143 {
144 const gchar* _tmp0_;
145 gchar* _tmp1_;
146 gchar* result = NULL;
147 g_return_val_if_fail (self != NULL, NULL);
148 _tmp0_ = self->priv->cname;
149 _tmp1_ = g_strdup (_tmp0_);
150 result = _tmp1_;
151 return result;
152 }
153
154 ValadocApiTypeReference*
valadoc_api_field_get_field_type(ValadocApiField * self)155 valadoc_api_field_get_field_type (ValadocApiField* self)
156 {
157 ValadocApiTypeReference* result;
158 ValadocApiTypeReference* _tmp0_;
159 g_return_val_if_fail (self != NULL, NULL);
160 _tmp0_ = self->priv->_field_type;
161 result = _tmp0_;
162 return result;
163 }
164
165 static gpointer
_g_object_ref0(gpointer self)166 _g_object_ref0 (gpointer self)
167 {
168 return self ? g_object_ref (self) : NULL;
169 }
170
171 void
valadoc_api_field_set_field_type(ValadocApiField * self,ValadocApiTypeReference * value)172 valadoc_api_field_set_field_type (ValadocApiField* self,
173 ValadocApiTypeReference* value)
174 {
175 ValadocApiTypeReference* old_value;
176 g_return_if_fail (self != NULL);
177 old_value = valadoc_api_field_get_field_type (self);
178 if (old_value != value) {
179 ValadocApiTypeReference* _tmp0_;
180 _tmp0_ = _g_object_ref0 (value);
181 _g_object_unref0 (self->priv->_field_type);
182 self->priv->_field_type = _tmp0_;
183 g_object_notify_by_pspec ((GObject *) self, valadoc_api_field_properties[VALADOC_API_FIELD_FIELD_TYPE_PROPERTY]);
184 }
185 }
186
187 gboolean
valadoc_api_field_get_is_static(ValadocApiField * self)188 valadoc_api_field_get_is_static (ValadocApiField* self)
189 {
190 gboolean result;
191 g_return_val_if_fail (self != NULL, FALSE);
192 result = self->priv->_is_static;
193 return result;
194 }
195
196 static void
valadoc_api_field_set_is_static(ValadocApiField * self,gboolean value)197 valadoc_api_field_set_is_static (ValadocApiField* self,
198 gboolean value)
199 {
200 gboolean old_value;
201 g_return_if_fail (self != NULL);
202 old_value = valadoc_api_field_get_is_static (self);
203 if (old_value != value) {
204 self->priv->_is_static = value;
205 g_object_notify_by_pspec ((GObject *) self, valadoc_api_field_properties[VALADOC_API_FIELD_IS_STATIC_PROPERTY]);
206 }
207 }
208
209 gboolean
valadoc_api_field_get_is_class(ValadocApiField * self)210 valadoc_api_field_get_is_class (ValadocApiField* self)
211 {
212 gboolean result;
213 g_return_val_if_fail (self != NULL, FALSE);
214 result = self->priv->_is_class;
215 return result;
216 }
217
218 static void
valadoc_api_field_set_is_class(ValadocApiField * self,gboolean value)219 valadoc_api_field_set_is_class (ValadocApiField* self,
220 gboolean value)
221 {
222 gboolean old_value;
223 g_return_if_fail (self != NULL);
224 old_value = valadoc_api_field_get_is_class (self);
225 if (old_value != value) {
226 self->priv->_is_class = value;
227 g_object_notify_by_pspec ((GObject *) self, valadoc_api_field_properties[VALADOC_API_FIELD_IS_CLASS_PROPERTY]);
228 }
229 }
230
231 gboolean
valadoc_api_field_get_is_volatile(ValadocApiField * self)232 valadoc_api_field_get_is_volatile (ValadocApiField* self)
233 {
234 gboolean result;
235 g_return_val_if_fail (self != NULL, FALSE);
236 result = self->priv->_is_volatile;
237 return result;
238 }
239
240 static void
valadoc_api_field_set_is_volatile(ValadocApiField * self,gboolean value)241 valadoc_api_field_set_is_volatile (ValadocApiField* self,
242 gboolean value)
243 {
244 gboolean old_value;
245 g_return_if_fail (self != NULL);
246 old_value = valadoc_api_field_get_is_volatile (self);
247 if (old_value != value) {
248 self->priv->_is_volatile = value;
249 g_object_notify_by_pspec ((GObject *) self, valadoc_api_field_properties[VALADOC_API_FIELD_IS_VOLATILE_PROPERTY]);
250 }
251 }
252
253 /**
254 * {@inheritDoc}
255 */
256 static ValadocContentInline*
valadoc_api_field_real_build_signature(ValadocApiItem * base)257 valadoc_api_field_real_build_signature (ValadocApiItem* base)
258 {
259 ValadocApiField * self;
260 ValadocApiSignatureBuilder* signature = NULL;
261 ValadocApiSignatureBuilder* _tmp0_;
262 ValadocApiSignatureBuilder* _tmp1_;
263 ValaSymbolAccessibility _tmp2_;
264 ValaSymbolAccessibility _tmp3_;
265 const gchar* _tmp4_;
266 gboolean _tmp5_;
267 gboolean _tmp9_;
268 ValadocApiSignatureBuilder* _tmp11_;
269 ValadocApiTypeReference* _tmp12_;
270 ValadocContentInline* _tmp13_;
271 ValadocContentInline* _tmp14_;
272 ValadocApiSignatureBuilder* _tmp15_;
273 ValadocApiSignatureBuilder* _tmp16_;
274 ValadocContentRun* _tmp17_;
275 ValadocContentInline* result = NULL;
276 self = (ValadocApiField*) base;
277 _tmp0_ = valadoc_api_signature_builder_new ();
278 signature = _tmp0_;
279 _tmp1_ = signature;
280 _tmp2_ = valadoc_api_symbol_get_accessibility ((ValadocApiSymbol*) self);
281 _tmp3_ = _tmp2_;
282 _tmp4_ = vala_symbol_accessibility_to_string (_tmp3_);
283 valadoc_api_signature_builder_append_keyword (_tmp1_, _tmp4_, TRUE);
284 _tmp5_ = self->priv->_is_static;
285 if (_tmp5_) {
286 ValadocApiSignatureBuilder* _tmp6_;
287 _tmp6_ = signature;
288 valadoc_api_signature_builder_append_keyword (_tmp6_, "static", TRUE);
289 } else {
290 gboolean _tmp7_;
291 _tmp7_ = self->priv->_is_class;
292 if (_tmp7_) {
293 ValadocApiSignatureBuilder* _tmp8_;
294 _tmp8_ = signature;
295 valadoc_api_signature_builder_append_keyword (_tmp8_, "class", TRUE);
296 }
297 }
298 _tmp9_ = self->priv->_is_volatile;
299 if (_tmp9_) {
300 ValadocApiSignatureBuilder* _tmp10_;
301 _tmp10_ = signature;
302 valadoc_api_signature_builder_append_keyword (_tmp10_, "volatile", TRUE);
303 }
304 _tmp11_ = signature;
305 _tmp12_ = self->priv->_field_type;
306 _tmp13_ = valadoc_api_item_get_signature ((ValadocApiItem*) _tmp12_);
307 _tmp14_ = _tmp13_;
308 valadoc_api_signature_builder_append_content (_tmp11_, _tmp14_, TRUE);
309 _tmp15_ = signature;
310 valadoc_api_signature_builder_append_symbol (_tmp15_, (ValadocApiNode*) self, TRUE);
311 _tmp16_ = signature;
312 _tmp17_ = valadoc_api_signature_builder_get (_tmp16_);
313 result = (ValadocContentInline*) _tmp17_;
314 _valadoc_api_signature_builder_unref0 (signature);
315 return result;
316 }
317
318 static ValadocApiNodeType
valadoc_api_field_real_get_node_type(ValadocApiNode * base)319 valadoc_api_field_real_get_node_type (ValadocApiNode* base)
320 {
321 ValadocApiNodeType result;
322 ValadocApiField* self;
323 self = (ValadocApiField*) base;
324 result = VALADOC_API_NODE_TYPE_FIELD;
325 return result;
326 }
327
328 /**
329 * {@inheritDoc}
330 */
331 static void
valadoc_api_field_real_accept(ValadocApiNode * base,ValadocApiVisitor * visitor)332 valadoc_api_field_real_accept (ValadocApiNode* base,
333 ValadocApiVisitor* visitor)
334 {
335 ValadocApiField * self;
336 self = (ValadocApiField*) base;
337 g_return_if_fail (visitor != NULL);
338 valadoc_api_visitor_visit_field (visitor, self);
339 }
340
341 static void
valadoc_api_field_class_init(ValadocApiFieldClass * klass,gpointer klass_data)342 valadoc_api_field_class_init (ValadocApiFieldClass * klass,
343 gpointer klass_data)
344 {
345 valadoc_api_field_parent_class = g_type_class_peek_parent (klass);
346 g_type_class_adjust_private_offset (klass, &ValadocApiField_private_offset);
347 ((ValadocApiItemClass *) klass)->build_signature = (ValadocContentInline* (*) (ValadocApiItem*)) valadoc_api_field_real_build_signature;
348 ((ValadocApiNodeClass *) klass)->accept = (void (*) (ValadocApiNode*, ValadocApiVisitor*)) valadoc_api_field_real_accept;
349 VALADOC_API_NODE_CLASS (klass)->get_node_type = valadoc_api_field_real_get_node_type;
350 G_OBJECT_CLASS (klass)->get_property = _vala_valadoc_api_field_get_property;
351 G_OBJECT_CLASS (klass)->set_property = _vala_valadoc_api_field_set_property;
352 G_OBJECT_CLASS (klass)->finalize = valadoc_api_field_finalize;
353 /**
354 * The field type.
355 */
356 g_object_class_install_property (G_OBJECT_CLASS (klass), VALADOC_API_FIELD_FIELD_TYPE_PROPERTY, valadoc_api_field_properties[VALADOC_API_FIELD_FIELD_TYPE_PROPERTY] = g_param_spec_object ("field-type", "field-type", "field-type", VALADOC_API_TYPE_TYPEREFERENCE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
357 /**
358 * Specifies whether the field is static.
359 */
360 g_object_class_install_property (G_OBJECT_CLASS (klass), VALADOC_API_FIELD_IS_STATIC_PROPERTY, valadoc_api_field_properties[VALADOC_API_FIELD_IS_STATIC_PROPERTY] = g_param_spec_boolean ("is-static", "is-static", "is-static", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
361 /**
362 * Specifies whether this field is a class field.
363 */
364 g_object_class_install_property (G_OBJECT_CLASS (klass), VALADOC_API_FIELD_IS_CLASS_PROPERTY, valadoc_api_field_properties[VALADOC_API_FIELD_IS_CLASS_PROPERTY] = g_param_spec_boolean ("is-class", "is-class", "is-class", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
365 /**
366 * Specifies whether the field is volatile.
367 */
368 g_object_class_install_property (G_OBJECT_CLASS (klass), VALADOC_API_FIELD_IS_VOLATILE_PROPERTY, valadoc_api_field_properties[VALADOC_API_FIELD_IS_VOLATILE_PROPERTY] = g_param_spec_boolean ("is-volatile", "is-volatile", "is-volatile", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
369 /**
370 * {@inheritDoc}
371 */
372 g_object_class_install_property (G_OBJECT_CLASS (klass), VALADOC_API_FIELD_NODE_TYPE_PROPERTY, valadoc_api_field_properties[VALADOC_API_FIELD_NODE_TYPE_PROPERTY] = g_param_spec_enum ("node-type", "node-type", "node-type", VALADOC_API_TYPE_NODE_TYPE, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
373 }
374
375 static void
valadoc_api_field_instance_init(ValadocApiField * self,gpointer klass)376 valadoc_api_field_instance_init (ValadocApiField * self,
377 gpointer klass)
378 {
379 self->priv = valadoc_api_field_get_instance_private (self);
380 }
381
382 static void
valadoc_api_field_finalize(GObject * obj)383 valadoc_api_field_finalize (GObject * obj)
384 {
385 ValadocApiField * self;
386 self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALADOC_API_TYPE_FIELD, ValadocApiField);
387 _g_free0 (self->priv->cname);
388 _g_object_unref0 (self->priv->_field_type);
389 G_OBJECT_CLASS (valadoc_api_field_parent_class)->finalize (obj);
390 }
391
392 /**
393 * Represents a field.
394 */
395 static GType
valadoc_api_field_get_type_once(void)396 valadoc_api_field_get_type_once (void)
397 {
398 static const GTypeInfo g_define_type_info = { sizeof (ValadocApiFieldClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) valadoc_api_field_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValadocApiField), 0, (GInstanceInitFunc) valadoc_api_field_instance_init, NULL };
399 GType valadoc_api_field_type_id;
400 valadoc_api_field_type_id = g_type_register_static (VALADOC_API_TYPE_SYMBOL, "ValadocApiField", &g_define_type_info, 0);
401 ValadocApiField_private_offset = g_type_add_instance_private (valadoc_api_field_type_id, sizeof (ValadocApiFieldPrivate));
402 return valadoc_api_field_type_id;
403 }
404
405 GType
valadoc_api_field_get_type(void)406 valadoc_api_field_get_type (void)
407 {
408 static volatile gsize valadoc_api_field_type_id__volatile = 0;
409 if (g_once_init_enter (&valadoc_api_field_type_id__volatile)) {
410 GType valadoc_api_field_type_id;
411 valadoc_api_field_type_id = valadoc_api_field_get_type_once ();
412 g_once_init_leave (&valadoc_api_field_type_id__volatile, valadoc_api_field_type_id);
413 }
414 return valadoc_api_field_type_id__volatile;
415 }
416
417 static void
_vala_valadoc_api_field_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)418 _vala_valadoc_api_field_get_property (GObject * object,
419 guint property_id,
420 GValue * value,
421 GParamSpec * pspec)
422 {
423 ValadocApiField * self;
424 self = G_TYPE_CHECK_INSTANCE_CAST (object, VALADOC_API_TYPE_FIELD, ValadocApiField);
425 switch (property_id) {
426 case VALADOC_API_FIELD_FIELD_TYPE_PROPERTY:
427 g_value_set_object (value, valadoc_api_field_get_field_type (self));
428 break;
429 case VALADOC_API_FIELD_IS_STATIC_PROPERTY:
430 g_value_set_boolean (value, valadoc_api_field_get_is_static (self));
431 break;
432 case VALADOC_API_FIELD_IS_CLASS_PROPERTY:
433 g_value_set_boolean (value, valadoc_api_field_get_is_class (self));
434 break;
435 case VALADOC_API_FIELD_IS_VOLATILE_PROPERTY:
436 g_value_set_boolean (value, valadoc_api_field_get_is_volatile (self));
437 break;
438 case VALADOC_API_FIELD_NODE_TYPE_PROPERTY:
439 g_value_set_enum (value, valadoc_api_node_get_node_type ((ValadocApiNode*) self));
440 break;
441 default:
442 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
443 break;
444 }
445 }
446
447 static void
_vala_valadoc_api_field_set_property(GObject * object,guint property_id,const GValue * value,GParamSpec * pspec)448 _vala_valadoc_api_field_set_property (GObject * object,
449 guint property_id,
450 const GValue * value,
451 GParamSpec * pspec)
452 {
453 ValadocApiField * self;
454 self = G_TYPE_CHECK_INSTANCE_CAST (object, VALADOC_API_TYPE_FIELD, ValadocApiField);
455 switch (property_id) {
456 case VALADOC_API_FIELD_FIELD_TYPE_PROPERTY:
457 valadoc_api_field_set_field_type (self, g_value_get_object (value));
458 break;
459 case VALADOC_API_FIELD_IS_STATIC_PROPERTY:
460 valadoc_api_field_set_is_static (self, g_value_get_boolean (value));
461 break;
462 case VALADOC_API_FIELD_IS_CLASS_PROPERTY:
463 valadoc_api_field_set_is_class (self, g_value_get_boolean (value));
464 break;
465 case VALADOC_API_FIELD_IS_VOLATILE_PROPERTY:
466 valadoc_api_field_set_is_volatile (self, g_value_get_boolean (value));
467 break;
468 default:
469 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
470 break;
471 }
472 }
473
474