1 /* valaenumvalue.c generated by valac, the Vala compiler
2 * generated from valaenumvalue.vala, do not modify */
3
4 /* valaenumvalue.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 "vala.h"
27 #include <stdlib.h>
28 #include <string.h>
29 #include <glib.h>
30
31 #define _g_free0(var) (var = (g_free (var), NULL))
32 #define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
33
34 struct _ValaEnumValuePrivate {
35 gchar* _nick;
36 };
37
38 static gint ValaEnumValue_private_offset;
39 static gpointer vala_enum_value_parent_class = NULL;
40
41 static void vala_enum_value_real_accept (ValaCodeNode* base,
42 ValaCodeVisitor* visitor);
43 static void vala_enum_value_real_accept_children (ValaCodeNode* base,
44 ValaCodeVisitor* visitor);
45 static gboolean vala_enum_value_real_check (ValaCodeNode* base,
46 ValaCodeContext* context);
47 static void vala_enum_value_finalize (ValaCodeNode * obj);
48 static GType vala_enum_value_get_type_once (void);
49
50 static inline gpointer
vala_enum_value_get_instance_private(ValaEnumValue * self)51 vala_enum_value_get_instance_private (ValaEnumValue* self)
52 {
53 return G_STRUCT_MEMBER_P (self, ValaEnumValue_private_offset);
54 }
55
56 static gchar*
string_replace(const gchar * self,const gchar * old,const gchar * replacement)57 string_replace (const gchar* self,
58 const gchar* old,
59 const gchar* replacement)
60 {
61 gboolean _tmp0_ = FALSE;
62 gboolean _tmp1_ = FALSE;
63 GError* _inner_error0_ = NULL;
64 gchar* result = NULL;
65 g_return_val_if_fail (self != NULL, NULL);
66 g_return_val_if_fail (old != NULL, NULL);
67 g_return_val_if_fail (replacement != NULL, NULL);
68 if ((*((gchar*) self)) == '\0') {
69 _tmp1_ = TRUE;
70 } else {
71 _tmp1_ = (*((gchar*) old)) == '\0';
72 }
73 if (_tmp1_) {
74 _tmp0_ = TRUE;
75 } else {
76 _tmp0_ = g_strcmp0 (old, replacement) == 0;
77 }
78 if (_tmp0_) {
79 gchar* _tmp2_;
80 _tmp2_ = g_strdup (self);
81 result = _tmp2_;
82 return result;
83 }
84 {
85 GRegex* regex = NULL;
86 gchar* _tmp3_;
87 gchar* _tmp4_;
88 GRegex* _tmp5_;
89 GRegex* _tmp6_;
90 gchar* _tmp7_ = NULL;
91 GRegex* _tmp8_;
92 gchar* _tmp9_;
93 gchar* _tmp10_;
94 _tmp3_ = g_regex_escape_string (old, -1);
95 _tmp4_ = _tmp3_;
96 _tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error0_);
97 _tmp6_ = _tmp5_;
98 _g_free0 (_tmp4_);
99 regex = _tmp6_;
100 if (G_UNLIKELY (_inner_error0_ != NULL)) {
101 _g_free0 (_tmp7_);
102 _g_regex_unref0 (regex);
103 if (_inner_error0_->domain == G_REGEX_ERROR) {
104 goto __catch0_g_regex_error;
105 }
106 g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
107 g_clear_error (&_inner_error0_);
108 return NULL;
109 }
110 _tmp8_ = regex;
111 _tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
112 _tmp7_ = _tmp9_;
113 if (G_UNLIKELY (_inner_error0_ != NULL)) {
114 _g_free0 (_tmp7_);
115 _g_regex_unref0 (regex);
116 if (_inner_error0_->domain == G_REGEX_ERROR) {
117 goto __catch0_g_regex_error;
118 }
119 g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
120 g_clear_error (&_inner_error0_);
121 return NULL;
122 }
123 _tmp10_ = _tmp7_;
124 _tmp7_ = NULL;
125 result = _tmp10_;
126 _g_free0 (_tmp7_);
127 _g_regex_unref0 (regex);
128 return result;
129 }
130 goto __finally0;
131 __catch0_g_regex_error:
132 {
133 g_clear_error (&_inner_error0_);
134 g_assert_not_reached ();
135 }
136 __finally0:
137 g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
138 g_clear_error (&_inner_error0_);
139 return NULL;
140 }
141
142 const gchar*
vala_enum_value_get_nick(ValaEnumValue * self)143 vala_enum_value_get_nick (ValaEnumValue* self)
144 {
145 const gchar* result;
146 const gchar* _tmp0_;
147 const gchar* _tmp8_;
148 g_return_val_if_fail (self != NULL, NULL);
149 _tmp0_ = self->priv->_nick;
150 if (_tmp0_ == NULL) {
151 gchar* _tmp1_;
152 const gchar* _tmp2_;
153 _tmp1_ = vala_code_node_get_attribute_string ((ValaCodeNode*) self, "Description", "nick", NULL);
154 _g_free0 (self->priv->_nick);
155 self->priv->_nick = _tmp1_;
156 _tmp2_ = self->priv->_nick;
157 if (_tmp2_ == NULL) {
158 const gchar* _tmp3_;
159 const gchar* _tmp4_;
160 gchar* _tmp5_;
161 gchar* _tmp6_;
162 gchar* _tmp7_;
163 _tmp3_ = vala_symbol_get_name ((ValaSymbol*) self);
164 _tmp4_ = _tmp3_;
165 _tmp5_ = g_ascii_strdown (_tmp4_, (gssize) -1);
166 _tmp6_ = _tmp5_;
167 _tmp7_ = string_replace (_tmp6_, "_", "-");
168 _g_free0 (self->priv->_nick);
169 self->priv->_nick = _tmp7_;
170 _g_free0 (_tmp6_);
171 }
172 }
173 _tmp8_ = self->priv->_nick;
174 result = _tmp8_;
175 return result;
176 }
177
178 /**
179 * Creates a new enum value with the specified numerical representation.
180 *
181 * @param name enum value name
182 * @param value numerical representation
183 * @return newly created enum value
184 */
185 ValaEnumValue*
vala_enum_value_construct(GType object_type,const gchar * name,ValaExpression * value,ValaSourceReference * source_reference,ValaComment * comment)186 vala_enum_value_construct (GType object_type,
187 const gchar* name,
188 ValaExpression* value,
189 ValaSourceReference* source_reference,
190 ValaComment* comment)
191 {
192 ValaEnumValue* self = NULL;
193 g_return_val_if_fail (name != NULL, NULL);
194 self = (ValaEnumValue*) vala_constant_construct (object_type, name, NULL, value, source_reference, comment);
195 return self;
196 }
197
198 ValaEnumValue*
vala_enum_value_new(const gchar * name,ValaExpression * value,ValaSourceReference * source_reference,ValaComment * comment)199 vala_enum_value_new (const gchar* name,
200 ValaExpression* value,
201 ValaSourceReference* source_reference,
202 ValaComment* comment)
203 {
204 return vala_enum_value_construct (VALA_TYPE_ENUM_VALUE, name, value, source_reference, comment);
205 }
206
207 static void
vala_enum_value_real_accept(ValaCodeNode * base,ValaCodeVisitor * visitor)208 vala_enum_value_real_accept (ValaCodeNode* base,
209 ValaCodeVisitor* visitor)
210 {
211 ValaEnumValue * self;
212 self = (ValaEnumValue*) base;
213 g_return_if_fail (visitor != NULL);
214 vala_code_visitor_visit_enum_value (visitor, self);
215 }
216
217 static void
vala_enum_value_real_accept_children(ValaCodeNode * base,ValaCodeVisitor * visitor)218 vala_enum_value_real_accept_children (ValaCodeNode* base,
219 ValaCodeVisitor* visitor)
220 {
221 ValaEnumValue * self;
222 ValaExpression* _tmp0_;
223 ValaExpression* _tmp1_;
224 self = (ValaEnumValue*) base;
225 g_return_if_fail (visitor != NULL);
226 _tmp0_ = vala_constant_get_value ((ValaConstant*) self);
227 _tmp1_ = _tmp0_;
228 if (_tmp1_ != NULL) {
229 ValaExpression* _tmp2_;
230 ValaExpression* _tmp3_;
231 _tmp2_ = vala_constant_get_value ((ValaConstant*) self);
232 _tmp3_ = _tmp2_;
233 vala_code_node_accept ((ValaCodeNode*) _tmp3_, visitor);
234 }
235 }
236
237 static gboolean
vala_enum_value_real_check(ValaCodeNode * base,ValaCodeContext * context)238 vala_enum_value_real_check (ValaCodeNode* base,
239 ValaCodeContext* context)
240 {
241 ValaEnumValue * self;
242 gboolean _tmp0_;
243 gboolean _tmp1_;
244 ValaExpression* _tmp4_;
245 ValaExpression* _tmp5_;
246 gboolean _tmp8_;
247 gboolean _tmp9_;
248 gboolean result = FALSE;
249 self = (ValaEnumValue*) base;
250 g_return_val_if_fail (context != NULL, FALSE);
251 _tmp0_ = vala_code_node_get_checked ((ValaCodeNode*) self);
252 _tmp1_ = _tmp0_;
253 if (_tmp1_) {
254 gboolean _tmp2_;
255 gboolean _tmp3_;
256 _tmp2_ = vala_code_node_get_error ((ValaCodeNode*) self);
257 _tmp3_ = _tmp2_;
258 result = !_tmp3_;
259 return result;
260 }
261 vala_code_node_set_checked ((ValaCodeNode*) self, TRUE);
262 _tmp4_ = vala_constant_get_value ((ValaConstant*) self);
263 _tmp5_ = _tmp4_;
264 if (_tmp5_ != NULL) {
265 ValaExpression* _tmp6_;
266 ValaExpression* _tmp7_;
267 _tmp6_ = vala_constant_get_value ((ValaConstant*) self);
268 _tmp7_ = _tmp6_;
269 vala_code_node_check ((ValaCodeNode*) _tmp7_, context);
270 }
271 _tmp8_ = vala_code_node_get_error ((ValaCodeNode*) self);
272 _tmp9_ = _tmp8_;
273 result = !_tmp9_;
274 return result;
275 }
276
277 static void
vala_enum_value_class_init(ValaEnumValueClass * klass,gpointer klass_data)278 vala_enum_value_class_init (ValaEnumValueClass * klass,
279 gpointer klass_data)
280 {
281 vala_enum_value_parent_class = g_type_class_peek_parent (klass);
282 ((ValaCodeNodeClass *) klass)->finalize = vala_enum_value_finalize;
283 g_type_class_adjust_private_offset (klass, &ValaEnumValue_private_offset);
284 ((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_enum_value_real_accept;
285 ((ValaCodeNodeClass *) klass)->accept_children = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_enum_value_real_accept_children;
286 ((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode*, ValaCodeContext*)) vala_enum_value_real_check;
287 }
288
289 static void
vala_enum_value_instance_init(ValaEnumValue * self,gpointer klass)290 vala_enum_value_instance_init (ValaEnumValue * self,
291 gpointer klass)
292 {
293 self->priv = vala_enum_value_get_instance_private (self);
294 self->priv->_nick = NULL;
295 }
296
297 static void
vala_enum_value_finalize(ValaCodeNode * obj)298 vala_enum_value_finalize (ValaCodeNode * obj)
299 {
300 ValaEnumValue * self;
301 self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_ENUM_VALUE, ValaEnumValue);
302 _g_free0 (self->priv->_nick);
303 VALA_CODE_NODE_CLASS (vala_enum_value_parent_class)->finalize (obj);
304 }
305
306 /**
307 * Represents an enum value member in the source code.
308 */
309 static GType
vala_enum_value_get_type_once(void)310 vala_enum_value_get_type_once (void)
311 {
312 static const GTypeInfo g_define_type_info = { sizeof (ValaEnumValueClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_enum_value_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaEnumValue), 0, (GInstanceInitFunc) vala_enum_value_instance_init, NULL };
313 GType vala_enum_value_type_id;
314 vala_enum_value_type_id = g_type_register_static (VALA_TYPE_CONSTANT, "ValaEnumValue", &g_define_type_info, 0);
315 ValaEnumValue_private_offset = g_type_add_instance_private (vala_enum_value_type_id, sizeof (ValaEnumValuePrivate));
316 return vala_enum_value_type_id;
317 }
318
319 GType
vala_enum_value_get_type(void)320 vala_enum_value_get_type (void)
321 {
322 static volatile gsize vala_enum_value_type_id__volatile = 0;
323 if (g_once_init_enter (&vala_enum_value_type_id__volatile)) {
324 GType vala_enum_value_type_id;
325 vala_enum_value_type_id = vala_enum_value_get_type_once ();
326 g_once_init_leave (&vala_enum_value_type_id__volatile, vala_enum_value_type_id);
327 }
328 return vala_enum_value_type_id__volatile;
329 }
330
331