1 /* valaccodeconstant.c generated by valac, the Vala compiler
2  * generated from valaccodeconstant.vala, do not modify */
3 
4 /* valaccodeconstant.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 "valaccode.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_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
33 #define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
34 #define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
35 #define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
36 #define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
37 
38 struct _ValaCCodeConstantPrivate {
39 	gchar* _name;
40 };
41 
42 static gint ValaCCodeConstant_private_offset;
43 static gpointer vala_ccode_constant_parent_class = NULL;
44 
45 #define VALA_CCODE_CONSTANT_LINE_LENGTH 70
46 static void vala_ccode_constant_real_write (ValaCCodeNode* base,
47                                      ValaCCodeWriter* writer);
48 static void vala_ccode_constant_finalize (ValaCCodeNode * obj);
49 static GType vala_ccode_constant_get_type_once (void);
50 
51 static inline gpointer
vala_ccode_constant_get_instance_private(ValaCCodeConstant * self)52 vala_ccode_constant_get_instance_private (ValaCCodeConstant* self)
53 {
54 	return G_STRUCT_MEMBER_P (self, ValaCCodeConstant_private_offset);
55 }
56 
57 const gchar*
vala_ccode_constant_get_name(ValaCCodeConstant * self)58 vala_ccode_constant_get_name (ValaCCodeConstant* self)
59 {
60 	const gchar* result;
61 	const gchar* _tmp0_;
62 	g_return_val_if_fail (self != NULL, NULL);
63 	_tmp0_ = self->priv->_name;
64 	result = _tmp0_;
65 	return result;
66 }
67 
68 void
vala_ccode_constant_set_name(ValaCCodeConstant * self,const gchar * value)69 vala_ccode_constant_set_name (ValaCCodeConstant* self,
70                               const gchar* value)
71 {
72 	gchar* _tmp0_;
73 	g_return_if_fail (self != NULL);
74 	_tmp0_ = g_strdup (value);
75 	_g_free0 (self->priv->_name);
76 	self->priv->_name = _tmp0_;
77 }
78 
79 ValaCCodeConstant*
vala_ccode_constant_construct(GType object_type,const gchar * _name)80 vala_ccode_constant_construct (GType object_type,
81                                const gchar* _name)
82 {
83 	ValaCCodeConstant* self = NULL;
84 	g_return_val_if_fail (_name != NULL, NULL);
85 	self = (ValaCCodeConstant*) vala_ccode_expression_construct (object_type);
86 	vala_ccode_constant_set_name (self, _name);
87 	return self;
88 }
89 
90 ValaCCodeConstant*
vala_ccode_constant_new(const gchar * _name)91 vala_ccode_constant_new (const gchar* _name)
92 {
93 	return vala_ccode_constant_construct (VALA_TYPE_CCODE_CONSTANT, _name);
94 }
95 
96 static gchar
string_get(const gchar * self,glong index)97 string_get (const gchar* self,
98             glong index)
99 {
100 	gchar _tmp0_;
101 	gchar result = '\0';
102 	g_return_val_if_fail (self != NULL, '\0');
103 	_tmp0_ = ((gchar*) self)[index];
104 	result = _tmp0_;
105 	return result;
106 }
107 
108 static gunichar
string_get_char(const gchar * self,glong index)109 string_get_char (const gchar* self,
110                  glong index)
111 {
112 	gunichar result = 0U;
113 	g_return_val_if_fail (self != NULL, 0U);
114 	result = g_utf8_get_char (((gchar*) self) + index);
115 	return result;
116 }
117 
118 ValaCCodeConstant*
vala_ccode_constant_construct_string(GType object_type,const gchar * _name)119 vala_ccode_constant_construct_string (GType object_type,
120                                       const gchar* _name)
121 {
122 	ValaCCodeConstant* self = NULL;
123 	gint _tmp0_;
124 	gint _tmp1_;
125 	GString* builder = NULL;
126 	GString* _tmp2_;
127 	gchar* p = NULL;
128 	gchar* end = NULL;
129 	gchar* _tmp3_;
130 	gint _tmp4_;
131 	gint _tmp5_;
132 	gchar* _tmp6_;
133 	gchar* _tmp7_;
134 	gint col = 0;
135 	GString* _tmp50_;
136 	GString* _tmp51_;
137 	const gchar* _tmp52_;
138 	g_return_val_if_fail (_name != NULL, NULL);
139 	self = (ValaCCodeConstant*) vala_ccode_expression_construct (object_type);
140 	_vala_assert (string_get (_name, (glong) 0) == '\"', "_name[0] == '\\\"'");
141 	_tmp0_ = strlen (_name);
142 	_tmp1_ = _tmp0_;
143 	if (_tmp1_ <= VALA_CCODE_CONSTANT_LINE_LENGTH) {
144 		vala_ccode_constant_set_name (self, _name);
145 		return self;
146 	}
147 	_tmp2_ = g_string_new ("\"");
148 	builder = _tmp2_;
149 	p = _name;
150 	_tmp3_ = p;
151 	_tmp4_ = strlen (_name);
152 	_tmp5_ = _tmp4_;
153 	end = _tmp3_ + _tmp5_;
154 	_tmp6_ = p;
155 	p = _tmp6_ + 1;
156 	_tmp7_ = end;
157 	end = _tmp7_ - 1;
158 	col = 0;
159 	while (TRUE) {
160 		gchar* _tmp8_;
161 		gchar* _tmp9_;
162 		gchar* _tmp11_;
163 		_tmp8_ = p;
164 		_tmp9_ = end;
165 		if (!(_tmp8_ < _tmp9_)) {
166 			break;
167 		}
168 		if (col >= VALA_CCODE_CONSTANT_LINE_LENGTH) {
169 			GString* _tmp10_;
170 			_tmp10_ = builder;
171 			g_string_append (_tmp10_, "\" \\\n\"");
172 			col = 0;
173 		}
174 		_tmp11_ = p;
175 		if ((*_tmp11_) == '\\') {
176 			gchar* begin_of_char = NULL;
177 			gchar* _tmp12_;
178 			GString* _tmp13_;
179 			gchar* _tmp14_;
180 			gchar _tmp15_;
181 			GString* _tmp16_;
182 			gchar* _tmp17_;
183 			gchar _tmp18_;
184 			gchar* _tmp19_;
185 			gchar* _tmp20_;
186 			gchar _tmp21_;
187 			gchar* _tmp41_;
188 			gchar* _tmp42_;
189 			_tmp12_ = p;
190 			begin_of_char = _tmp12_;
191 			_tmp13_ = builder;
192 			_tmp14_ = p;
193 			_tmp15_ = _tmp14_[0];
194 			g_string_append_c (_tmp13_, _tmp15_);
195 			_tmp16_ = builder;
196 			_tmp17_ = p;
197 			_tmp18_ = _tmp17_[1];
198 			g_string_append_c (_tmp16_, _tmp18_);
199 			_tmp19_ = p;
200 			p = _tmp19_ + 2;
201 			_tmp20_ = p;
202 			_tmp21_ = _tmp20_[-1];
203 			switch (_tmp21_) {
204 				case 'x':
205 				{
206 					while (TRUE) {
207 						gboolean _tmp22_ = FALSE;
208 						gchar* _tmp23_;
209 						gchar* _tmp24_;
210 						GString* _tmp26_;
211 						gchar* _tmp27_;
212 						gchar* _tmp28_;
213 						_tmp23_ = p;
214 						_tmp24_ = end;
215 						if (_tmp23_ < _tmp24_) {
216 							gchar* _tmp25_;
217 							_tmp25_ = p;
218 							_tmp22_ = g_ascii_isxdigit (*_tmp25_);
219 						} else {
220 							_tmp22_ = FALSE;
221 						}
222 						if (!_tmp22_) {
223 							break;
224 						}
225 						_tmp26_ = builder;
226 						_tmp27_ = p;
227 						g_string_append_c (_tmp26_, *_tmp27_);
228 						_tmp28_ = p;
229 						p = _tmp28_ + 1;
230 					}
231 					break;
232 				}
233 				case '0':
234 				case '1':
235 				case '2':
236 				case '3':
237 				case '4':
238 				case '5':
239 				case '6':
240 				case '7':
241 				{
242 					while (TRUE) {
243 						gboolean _tmp29_ = FALSE;
244 						gboolean _tmp30_ = FALSE;
245 						gboolean _tmp31_ = FALSE;
246 						gchar* _tmp32_;
247 						gchar* _tmp33_;
248 						GString* _tmp38_;
249 						gchar* _tmp39_;
250 						gchar* _tmp40_;
251 						_tmp32_ = p;
252 						_tmp33_ = end;
253 						if (_tmp32_ < _tmp33_) {
254 							gchar* _tmp34_;
255 							gchar* _tmp35_;
256 							_tmp34_ = p;
257 							_tmp35_ = begin_of_char;
258 							_tmp31_ = (_tmp34_ - _tmp35_) <= ((gsize) 3);
259 						} else {
260 							_tmp31_ = FALSE;
261 						}
262 						if (_tmp31_) {
263 							gchar* _tmp36_;
264 							_tmp36_ = p;
265 							_tmp30_ = (*_tmp36_) >= '0';
266 						} else {
267 							_tmp30_ = FALSE;
268 						}
269 						if (_tmp30_) {
270 							gchar* _tmp37_;
271 							_tmp37_ = p;
272 							_tmp29_ = (*_tmp37_) <= '7';
273 						} else {
274 							_tmp29_ = FALSE;
275 						}
276 						if (!_tmp29_) {
277 							break;
278 						}
279 						_tmp38_ = builder;
280 						_tmp39_ = p;
281 						g_string_append_c (_tmp38_, *_tmp39_);
282 						_tmp40_ = p;
283 						p = _tmp40_ + 1;
284 					}
285 					break;
286 				}
287 				case 'n':
288 				{
289 					col = VALA_CCODE_CONSTANT_LINE_LENGTH;
290 					break;
291 				}
292 				default:
293 				break;
294 			}
295 			_tmp41_ = p;
296 			_tmp42_ = begin_of_char;
297 			col += (gint) (_tmp41_ - _tmp42_);
298 		} else {
299 			GString* _tmp43_;
300 			gchar* _tmp44_;
301 			gchar* _tmp45_;
302 			gchar* _tmp46_;
303 			const gchar* _tmp47_;
304 			gchar* _tmp48_;
305 			gint _tmp49_;
306 			_tmp43_ = builder;
307 			_tmp44_ = p;
308 			g_string_append_unichar (_tmp43_, string_get_char ((const gchar*) _tmp44_, (glong) 0));
309 			_tmp45_ = p;
310 			_tmp46_ = p;
311 			_tmp47_ = g_utf8_next_char ((const gchar*) _tmp46_);
312 			_tmp48_ = p;
313 			p = _tmp45_ + (((gchar*) _tmp47_) - _tmp48_);
314 			_tmp49_ = col;
315 			col = _tmp49_ + 1;
316 		}
317 	}
318 	_tmp50_ = builder;
319 	g_string_append_c (_tmp50_, '"');
320 	_tmp51_ = builder;
321 	_tmp52_ = _tmp51_->str;
322 	vala_ccode_constant_set_name (self, _tmp52_);
323 	_g_string_free0 (builder);
324 	return self;
325 }
326 
327 ValaCCodeConstant*
vala_ccode_constant_new_string(const gchar * _name)328 vala_ccode_constant_new_string (const gchar* _name)
329 {
330 	return vala_ccode_constant_construct_string (VALA_TYPE_CCODE_CONSTANT, _name);
331 }
332 
333 static void
vala_ccode_constant_real_write(ValaCCodeNode * base,ValaCCodeWriter * writer)334 vala_ccode_constant_real_write (ValaCCodeNode* base,
335                                 ValaCCodeWriter* writer)
336 {
337 	ValaCCodeConstant * self;
338 	const gchar* _tmp0_;
339 	self = (ValaCCodeConstant*) base;
340 	g_return_if_fail (writer != NULL);
341 	_tmp0_ = self->priv->_name;
342 	vala_ccode_writer_write_string (writer, _tmp0_);
343 }
344 
345 static void
vala_ccode_constant_class_init(ValaCCodeConstantClass * klass,gpointer klass_data)346 vala_ccode_constant_class_init (ValaCCodeConstantClass * klass,
347                                 gpointer klass_data)
348 {
349 	vala_ccode_constant_parent_class = g_type_class_peek_parent (klass);
350 	((ValaCCodeNodeClass *) klass)->finalize = vala_ccode_constant_finalize;
351 	g_type_class_adjust_private_offset (klass, &ValaCCodeConstant_private_offset);
352 	((ValaCCodeNodeClass *) klass)->write = (void (*) (ValaCCodeNode*, ValaCCodeWriter*)) vala_ccode_constant_real_write;
353 }
354 
355 static void
vala_ccode_constant_instance_init(ValaCCodeConstant * self,gpointer klass)356 vala_ccode_constant_instance_init (ValaCCodeConstant * self,
357                                    gpointer klass)
358 {
359 	self->priv = vala_ccode_constant_get_instance_private (self);
360 }
361 
362 static void
vala_ccode_constant_finalize(ValaCCodeNode * obj)363 vala_ccode_constant_finalize (ValaCCodeNode * obj)
364 {
365 	ValaCCodeConstant * self;
366 	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_CCODE_CONSTANT, ValaCCodeConstant);
367 	_g_free0 (self->priv->_name);
368 	VALA_CCODE_NODE_CLASS (vala_ccode_constant_parent_class)->finalize (obj);
369 }
370 
371 /**
372  * A constant C expression.
373  */
374 static GType
vala_ccode_constant_get_type_once(void)375 vala_ccode_constant_get_type_once (void)
376 {
377 	static const GTypeInfo g_define_type_info = { sizeof (ValaCCodeConstantClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_ccode_constant_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaCCodeConstant), 0, (GInstanceInitFunc) vala_ccode_constant_instance_init, NULL };
378 	GType vala_ccode_constant_type_id;
379 	vala_ccode_constant_type_id = g_type_register_static (VALA_TYPE_CCODE_EXPRESSION, "ValaCCodeConstant", &g_define_type_info, 0);
380 	ValaCCodeConstant_private_offset = g_type_add_instance_private (vala_ccode_constant_type_id, sizeof (ValaCCodeConstantPrivate));
381 	return vala_ccode_constant_type_id;
382 }
383 
384 GType
vala_ccode_constant_get_type(void)385 vala_ccode_constant_get_type (void)
386 {
387 	static volatile gsize vala_ccode_constant_type_id__volatile = 0;
388 	if (g_once_init_enter (&vala_ccode_constant_type_id__volatile)) {
389 		GType vala_ccode_constant_type_id;
390 		vala_ccode_constant_type_id = vala_ccode_constant_get_type_once ();
391 		g_once_init_leave (&vala_ccode_constant_type_id__volatile, vala_ccode_constant_type_id);
392 	}
393 	return vala_ccode_constant_type_id__volatile;
394 }
395 
396