1 /* valaccodeenum.c generated by valac, the Vala compiler
2 * generated from valaccodeenum.vala, do not modify */
3
4 /* valaccodeenum.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 "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 _ValaCCodeEnumPrivate {
38 gchar* _name;
39 ValaList* values;
40 };
41
42 static gint ValaCCodeEnum_private_offset;
43 static gpointer vala_ccode_enum_parent_class = NULL;
44
45 static void vala_ccode_enum_real_write (ValaCCodeNode* base,
46 ValaCCodeWriter* writer);
47 static void vala_ccode_enum_finalize (ValaCCodeNode * obj);
48 static GType vala_ccode_enum_get_type_once (void);
49
50 static inline gpointer
vala_ccode_enum_get_instance_private(ValaCCodeEnum * self)51 vala_ccode_enum_get_instance_private (ValaCCodeEnum* self)
52 {
53 return G_STRUCT_MEMBER_P (self, ValaCCodeEnum_private_offset);
54 }
55
56 const gchar*
vala_ccode_enum_get_name(ValaCCodeEnum * self)57 vala_ccode_enum_get_name (ValaCCodeEnum* self)
58 {
59 const gchar* result;
60 const gchar* _tmp0_;
61 g_return_val_if_fail (self != NULL, NULL);
62 _tmp0_ = self->priv->_name;
63 result = _tmp0_;
64 return result;
65 }
66
67 void
vala_ccode_enum_set_name(ValaCCodeEnum * self,const gchar * value)68 vala_ccode_enum_set_name (ValaCCodeEnum* self,
69 const gchar* value)
70 {
71 gchar* _tmp0_;
72 g_return_if_fail (self != NULL);
73 _tmp0_ = g_strdup (value);
74 _g_free0 (self->priv->_name);
75 self->priv->_name = _tmp0_;
76 }
77
78 ValaCCodeEnum*
vala_ccode_enum_construct(GType object_type,const gchar * name)79 vala_ccode_enum_construct (GType object_type,
80 const gchar* name)
81 {
82 ValaCCodeEnum* self = NULL;
83 self = (ValaCCodeEnum*) vala_ccode_node_construct (object_type);
84 vala_ccode_enum_set_name (self, name);
85 return self;
86 }
87
88 ValaCCodeEnum*
vala_ccode_enum_new(const gchar * name)89 vala_ccode_enum_new (const gchar* name)
90 {
91 return vala_ccode_enum_construct (VALA_TYPE_CCODE_ENUM, name);
92 }
93
94 /**
95 * Adds the specified value to this enum.
96 *
97 * @param value optional numerical value
98 */
99 void
vala_ccode_enum_add_value(ValaCCodeEnum * self,ValaCCodeEnumValue * value)100 vala_ccode_enum_add_value (ValaCCodeEnum* self,
101 ValaCCodeEnumValue* value)
102 {
103 ValaList* _tmp0_;
104 g_return_if_fail (self != NULL);
105 g_return_if_fail (value != NULL);
106 _tmp0_ = self->priv->values;
107 vala_collection_add ((ValaCollection*) _tmp0_, value);
108 }
109
110 static gpointer
_vala_iterable_ref0(gpointer self)111 _vala_iterable_ref0 (gpointer self)
112 {
113 return self ? vala_iterable_ref (self) : NULL;
114 }
115
116 static void
vala_ccode_enum_real_write(ValaCCodeNode * base,ValaCCodeWriter * writer)117 vala_ccode_enum_real_write (ValaCCodeNode* base,
118 ValaCCodeWriter* writer)
119 {
120 ValaCCodeEnum * self;
121 const gchar* _tmp0_;
122 gboolean first = FALSE;
123 const gchar* _tmp11_;
124 ValaCCodeModifiers _tmp13_;
125 ValaCCodeModifiers _tmp14_;
126 self = (ValaCCodeEnum*) base;
127 g_return_if_fail (writer != NULL);
128 _tmp0_ = self->priv->_name;
129 if (_tmp0_ != NULL) {
130 vala_ccode_writer_write_string (writer, "typedef ");
131 }
132 vala_ccode_writer_write_string (writer, "enum ");
133 vala_ccode_writer_write_begin_block (writer);
134 first = TRUE;
135 {
136 ValaList* _value_list = NULL;
137 ValaList* _tmp1_;
138 ValaList* _tmp2_;
139 gint _value_size = 0;
140 ValaList* _tmp3_;
141 gint _tmp4_;
142 gint _tmp5_;
143 gint _value_index = 0;
144 _tmp1_ = self->priv->values;
145 _tmp2_ = _vala_iterable_ref0 (_tmp1_);
146 _value_list = _tmp2_;
147 _tmp3_ = _value_list;
148 _tmp4_ = vala_collection_get_size ((ValaCollection*) _tmp3_);
149 _tmp5_ = _tmp4_;
150 _value_size = _tmp5_;
151 _value_index = -1;
152 while (TRUE) {
153 gint _tmp6_;
154 gint _tmp7_;
155 ValaCCodeEnumValue* value = NULL;
156 ValaList* _tmp8_;
157 gpointer _tmp9_;
158 ValaCCodeEnumValue* _tmp10_;
159 _value_index = _value_index + 1;
160 _tmp6_ = _value_index;
161 _tmp7_ = _value_size;
162 if (!(_tmp6_ < _tmp7_)) {
163 break;
164 }
165 _tmp8_ = _value_list;
166 _tmp9_ = vala_list_get (_tmp8_, _value_index);
167 value = (ValaCCodeEnumValue*) _tmp9_;
168 if (!first) {
169 vala_ccode_writer_write_string (writer, ",");
170 vala_ccode_writer_write_newline (writer);
171 }
172 vala_ccode_writer_write_indent (writer, NULL);
173 _tmp10_ = value;
174 vala_ccode_node_write ((ValaCCodeNode*) _tmp10_, writer);
175 first = FALSE;
176 _vala_ccode_node_unref0 (value);
177 }
178 _vala_iterable_unref0 (_value_list);
179 }
180 if (!first) {
181 vala_ccode_writer_write_newline (writer);
182 }
183 vala_ccode_writer_write_end_block (writer);
184 _tmp11_ = self->priv->_name;
185 if (_tmp11_ != NULL) {
186 const gchar* _tmp12_;
187 vala_ccode_writer_write_string (writer, " ");
188 _tmp12_ = self->priv->_name;
189 vala_ccode_writer_write_string (writer, _tmp12_);
190 }
191 _tmp13_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
192 _tmp14_ = _tmp13_;
193 if ((_tmp14_ & VALA_CCODE_MODIFIERS_DEPRECATED) == VALA_CCODE_MODIFIERS_DEPRECATED) {
194 vala_ccode_writer_write_string (writer, " G_GNUC_DEPRECATED");
195 }
196 vala_ccode_writer_write_string (writer, ";");
197 vala_ccode_writer_write_newline (writer);
198 }
199
200 static void
vala_ccode_enum_class_init(ValaCCodeEnumClass * klass,gpointer klass_data)201 vala_ccode_enum_class_init (ValaCCodeEnumClass * klass,
202 gpointer klass_data)
203 {
204 vala_ccode_enum_parent_class = g_type_class_peek_parent (klass);
205 ((ValaCCodeNodeClass *) klass)->finalize = vala_ccode_enum_finalize;
206 g_type_class_adjust_private_offset (klass, &ValaCCodeEnum_private_offset);
207 ((ValaCCodeNodeClass *) klass)->write = (void (*) (ValaCCodeNode*, ValaCCodeWriter*)) vala_ccode_enum_real_write;
208 }
209
210 static void
vala_ccode_enum_instance_init(ValaCCodeEnum * self,gpointer klass)211 vala_ccode_enum_instance_init (ValaCCodeEnum * self,
212 gpointer klass)
213 {
214 GEqualFunc _tmp0_;
215 ValaArrayList* _tmp1_;
216 self->priv = vala_ccode_enum_get_instance_private (self);
217 _tmp0_ = g_direct_equal;
218 _tmp1_ = vala_array_list_new (VALA_TYPE_CCODE_ENUM_VALUE, (GBoxedCopyFunc) vala_ccode_node_ref, (GDestroyNotify) vala_ccode_node_unref, _tmp0_);
219 self->priv->values = (ValaList*) _tmp1_;
220 }
221
222 static void
vala_ccode_enum_finalize(ValaCCodeNode * obj)223 vala_ccode_enum_finalize (ValaCCodeNode * obj)
224 {
225 ValaCCodeEnum * self;
226 self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_CCODE_ENUM, ValaCCodeEnum);
227 _g_free0 (self->priv->_name);
228 _vala_iterable_unref0 (self->priv->values);
229 VALA_CCODE_NODE_CLASS (vala_ccode_enum_parent_class)->finalize (obj);
230 }
231
232 /**
233 * Represents an enum in the C code.
234 */
235 static GType
vala_ccode_enum_get_type_once(void)236 vala_ccode_enum_get_type_once (void)
237 {
238 static const GTypeInfo g_define_type_info = { sizeof (ValaCCodeEnumClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_ccode_enum_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaCCodeEnum), 0, (GInstanceInitFunc) vala_ccode_enum_instance_init, NULL };
239 GType vala_ccode_enum_type_id;
240 vala_ccode_enum_type_id = g_type_register_static (VALA_TYPE_CCODE_NODE, "ValaCCodeEnum", &g_define_type_info, 0);
241 ValaCCodeEnum_private_offset = g_type_add_instance_private (vala_ccode_enum_type_id, sizeof (ValaCCodeEnumPrivate));
242 return vala_ccode_enum_type_id;
243 }
244
245 GType
vala_ccode_enum_get_type(void)246 vala_ccode_enum_get_type (void)
247 {
248 static volatile gsize vala_ccode_enum_type_id__volatile = 0;
249 if (g_once_init_enter (&vala_ccode_enum_type_id__volatile)) {
250 GType vala_ccode_enum_type_id;
251 vala_ccode_enum_type_id = vala_ccode_enum_get_type_once ();
252 g_once_init_leave (&vala_ccode_enum_type_id__volatile, vala_ccode_enum_type_id);
253 }
254 return vala_ccode_enum_type_id__volatile;
255 }
256
257