1 /* valaccodeblock.c generated by valac, the Vala compiler
2 * generated from valaccodeblock.vala, do not modify */
3
4 /* valaccodeblock.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 <glib.h>
28 #include <valagee.h>
29 #include <glib-object.h>
30
31 #define _vala_iterable_unref0(var) ((var == NULL) ? NULL : (var = (vala_iterable_unref (var), NULL)))
32 #define _vala_ccode_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_ccode_node_unref (var), NULL)))
33
34 struct _ValaCCodeBlockPrivate {
35 gboolean _suppress_newline;
36 ValaList* statements;
37 };
38
39 static gint ValaCCodeBlock_private_offset;
40 static gpointer vala_ccode_block_parent_class = NULL;
41
42 static void vala_ccode_block_real_write (ValaCCodeNode* base,
43 ValaCCodeWriter* writer);
44 static void vala_ccode_block_finalize (ValaCCodeNode * obj);
45 static GType vala_ccode_block_get_type_once (void);
46
47 static inline gpointer
vala_ccode_block_get_instance_private(ValaCCodeBlock * self)48 vala_ccode_block_get_instance_private (ValaCCodeBlock* self)
49 {
50 return G_STRUCT_MEMBER_P (self, ValaCCodeBlock_private_offset);
51 }
52
53 gboolean
vala_ccode_block_get_suppress_newline(ValaCCodeBlock * self)54 vala_ccode_block_get_suppress_newline (ValaCCodeBlock* self)
55 {
56 gboolean result;
57 g_return_val_if_fail (self != NULL, FALSE);
58 result = self->priv->_suppress_newline;
59 return result;
60 }
61
62 void
vala_ccode_block_set_suppress_newline(ValaCCodeBlock * self,gboolean value)63 vala_ccode_block_set_suppress_newline (ValaCCodeBlock* self,
64 gboolean value)
65 {
66 g_return_if_fail (self != NULL);
67 self->priv->_suppress_newline = value;
68 }
69
70 /**
71 * Prepend the specified statement to the list of statements.
72 */
73 void
vala_ccode_block_prepend_statement(ValaCCodeBlock * self,ValaCCodeNode * statement)74 vala_ccode_block_prepend_statement (ValaCCodeBlock* self,
75 ValaCCodeNode* statement)
76 {
77 ValaList* _tmp0_;
78 g_return_if_fail (self != NULL);
79 g_return_if_fail (statement != NULL);
80 _tmp0_ = self->priv->statements;
81 vala_list_insert (_tmp0_, 0, statement);
82 }
83
84 /**
85 * Append the specified statement to the list of statements.
86 */
87 void
vala_ccode_block_add_statement(ValaCCodeBlock * self,ValaCCodeNode * statement)88 vala_ccode_block_add_statement (ValaCCodeBlock* self,
89 ValaCCodeNode* statement)
90 {
91 ValaList* _tmp0_;
92 g_return_if_fail (self != NULL);
93 g_return_if_fail (statement != NULL);
94 _tmp0_ = self->priv->statements;
95 vala_collection_add ((ValaCollection*) _tmp0_, statement);
96 }
97
98 static gpointer
_vala_iterable_ref0(gpointer self)99 _vala_iterable_ref0 (gpointer self)
100 {
101 return self ? vala_iterable_ref (self) : NULL;
102 }
103
104 static gpointer
_vala_ccode_node_ref0(gpointer self)105 _vala_ccode_node_ref0 (gpointer self)
106 {
107 return self ? vala_ccode_node_ref (self) : NULL;
108 }
109
110 static void
vala_ccode_block_real_write(ValaCCodeNode * base,ValaCCodeWriter * writer)111 vala_ccode_block_real_write (ValaCCodeNode* base,
112 ValaCCodeWriter* writer)
113 {
114 ValaCCodeBlock * self;
115 ValaCCodeNode* last_statement = NULL;
116 gboolean _tmp34_;
117 self = (ValaCCodeBlock*) base;
118 g_return_if_fail (writer != NULL);
119 last_statement = NULL;
120 vala_ccode_writer_write_begin_block (writer);
121 {
122 ValaList* _statement_list = NULL;
123 ValaList* _tmp0_;
124 ValaList* _tmp1_;
125 gint _statement_size = 0;
126 ValaList* _tmp2_;
127 gint _tmp3_;
128 gint _tmp4_;
129 gint _statement_index = 0;
130 _tmp0_ = self->priv->statements;
131 _tmp1_ = _vala_iterable_ref0 (_tmp0_);
132 _statement_list = _tmp1_;
133 _tmp2_ = _statement_list;
134 _tmp3_ = vala_collection_get_size ((ValaCollection*) _tmp2_);
135 _tmp4_ = _tmp3_;
136 _statement_size = _tmp4_;
137 _statement_index = -1;
138 while (TRUE) {
139 gint _tmp5_;
140 gint _tmp6_;
141 ValaCCodeNode* statement = NULL;
142 ValaList* _tmp7_;
143 gpointer _tmp8_;
144 ValaCCodeNode* _tmp9_;
145 gboolean _tmp10_ = FALSE;
146 ValaCCodeNode* _tmp11_;
147 _statement_index = _statement_index + 1;
148 _tmp5_ = _statement_index;
149 _tmp6_ = _statement_size;
150 if (!(_tmp5_ < _tmp6_)) {
151 break;
152 }
153 _tmp7_ = _statement_list;
154 _tmp8_ = vala_list_get (_tmp7_, _statement_index);
155 statement = (ValaCCodeNode*) _tmp8_;
156 _tmp9_ = statement;
157 vala_ccode_node_write_declaration (_tmp9_, writer);
158 _tmp11_ = statement;
159 if (VALA_IS_CCODE_LABEL (_tmp11_)) {
160 _tmp10_ = TRUE;
161 } else {
162 ValaCCodeNode* _tmp12_;
163 _tmp12_ = statement;
164 _tmp10_ = VALA_IS_CCODE_CASE_STATEMENT (_tmp12_);
165 }
166 if (_tmp10_) {
167 _vala_ccode_node_unref0 (last_statement);
168 last_statement = NULL;
169 } else {
170 gboolean _tmp13_ = FALSE;
171 gboolean _tmp14_ = FALSE;
172 gboolean _tmp15_ = FALSE;
173 ValaCCodeNode* _tmp16_;
174 _tmp16_ = statement;
175 if (VALA_IS_CCODE_RETURN_STATEMENT (_tmp16_)) {
176 _tmp15_ = TRUE;
177 } else {
178 ValaCCodeNode* _tmp17_;
179 _tmp17_ = statement;
180 _tmp15_ = VALA_IS_CCODE_GOTO_STATEMENT (_tmp17_);
181 }
182 if (_tmp15_) {
183 _tmp14_ = TRUE;
184 } else {
185 ValaCCodeNode* _tmp18_;
186 _tmp18_ = statement;
187 _tmp14_ = VALA_IS_CCODE_CONTINUE_STATEMENT (_tmp18_);
188 }
189 if (_tmp14_) {
190 _tmp13_ = TRUE;
191 } else {
192 ValaCCodeNode* _tmp19_;
193 _tmp19_ = statement;
194 _tmp13_ = VALA_IS_CCODE_BREAK_STATEMENT (_tmp19_);
195 }
196 if (_tmp13_) {
197 ValaCCodeNode* _tmp20_;
198 ValaCCodeNode* _tmp21_;
199 _tmp20_ = statement;
200 _tmp21_ = _vala_ccode_node_ref0 (_tmp20_);
201 _vala_ccode_node_unref0 (last_statement);
202 last_statement = _tmp21_;
203 }
204 }
205 _vala_ccode_node_unref0 (statement);
206 }
207 _vala_iterable_unref0 (_statement_list);
208 }
209 {
210 ValaList* _statement_list = NULL;
211 ValaList* _tmp22_;
212 ValaList* _tmp23_;
213 gint _statement_size = 0;
214 ValaList* _tmp24_;
215 gint _tmp25_;
216 gint _tmp26_;
217 gint _statement_index = 0;
218 _tmp22_ = self->priv->statements;
219 _tmp23_ = _vala_iterable_ref0 (_tmp22_);
220 _statement_list = _tmp23_;
221 _tmp24_ = _statement_list;
222 _tmp25_ = vala_collection_get_size ((ValaCollection*) _tmp24_);
223 _tmp26_ = _tmp25_;
224 _statement_size = _tmp26_;
225 _statement_index = -1;
226 while (TRUE) {
227 gint _tmp27_;
228 gint _tmp28_;
229 ValaCCodeNode* statement = NULL;
230 ValaList* _tmp29_;
231 gpointer _tmp30_;
232 ValaCCodeNode* _tmp31_;
233 ValaCCodeNode* _tmp32_;
234 ValaCCodeNode* _tmp33_;
235 _statement_index = _statement_index + 1;
236 _tmp27_ = _statement_index;
237 _tmp28_ = _statement_size;
238 if (!(_tmp27_ < _tmp28_)) {
239 break;
240 }
241 _tmp29_ = _statement_list;
242 _tmp30_ = vala_list_get (_tmp29_, _statement_index);
243 statement = (ValaCCodeNode*) _tmp30_;
244 _tmp31_ = statement;
245 vala_ccode_node_write (_tmp31_, writer);
246 _tmp32_ = statement;
247 _tmp33_ = last_statement;
248 if (_tmp32_ == _tmp33_) {
249 _vala_ccode_node_unref0 (statement);
250 break;
251 }
252 _vala_ccode_node_unref0 (statement);
253 }
254 _vala_iterable_unref0 (_statement_list);
255 }
256 vala_ccode_writer_write_end_block (writer);
257 _tmp34_ = self->priv->_suppress_newline;
258 if (!_tmp34_) {
259 vala_ccode_writer_write_newline (writer);
260 }
261 _vala_ccode_node_unref0 (last_statement);
262 }
263
264 ValaCCodeBlock*
vala_ccode_block_construct(GType object_type)265 vala_ccode_block_construct (GType object_type)
266 {
267 ValaCCodeBlock* self = NULL;
268 self = (ValaCCodeBlock*) vala_ccode_statement_construct (object_type);
269 return self;
270 }
271
272 ValaCCodeBlock*
vala_ccode_block_new(void)273 vala_ccode_block_new (void)
274 {
275 return vala_ccode_block_construct (VALA_TYPE_CCODE_BLOCK);
276 }
277
278 static void
vala_ccode_block_class_init(ValaCCodeBlockClass * klass,gpointer klass_data)279 vala_ccode_block_class_init (ValaCCodeBlockClass * klass,
280 gpointer klass_data)
281 {
282 vala_ccode_block_parent_class = g_type_class_peek_parent (klass);
283 ((ValaCCodeNodeClass *) klass)->finalize = vala_ccode_block_finalize;
284 g_type_class_adjust_private_offset (klass, &ValaCCodeBlock_private_offset);
285 ((ValaCCodeNodeClass *) klass)->write = (void (*) (ValaCCodeNode*, ValaCCodeWriter*)) vala_ccode_block_real_write;
286 }
287
288 static void
vala_ccode_block_instance_init(ValaCCodeBlock * self,gpointer klass)289 vala_ccode_block_instance_init (ValaCCodeBlock * self,
290 gpointer klass)
291 {
292 GEqualFunc _tmp0_;
293 ValaArrayList* _tmp1_;
294 self->priv = vala_ccode_block_get_instance_private (self);
295 _tmp0_ = g_direct_equal;
296 _tmp1_ = vala_array_list_new (VALA_TYPE_CCODE_NODE, (GBoxedCopyFunc) vala_ccode_node_ref, (GDestroyNotify) vala_ccode_node_unref, _tmp0_);
297 self->priv->statements = (ValaList*) _tmp1_;
298 }
299
300 static void
vala_ccode_block_finalize(ValaCCodeNode * obj)301 vala_ccode_block_finalize (ValaCCodeNode * obj)
302 {
303 ValaCCodeBlock * self;
304 self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_CCODE_BLOCK, ValaCCodeBlock);
305 _vala_iterable_unref0 (self->priv->statements);
306 VALA_CCODE_NODE_CLASS (vala_ccode_block_parent_class)->finalize (obj);
307 }
308
309 /**
310 * Represents a C code block.
311 */
312 static GType
vala_ccode_block_get_type_once(void)313 vala_ccode_block_get_type_once (void)
314 {
315 static const GTypeInfo g_define_type_info = { sizeof (ValaCCodeBlockClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_ccode_block_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaCCodeBlock), 0, (GInstanceInitFunc) vala_ccode_block_instance_init, NULL };
316 GType vala_ccode_block_type_id;
317 vala_ccode_block_type_id = g_type_register_static (VALA_TYPE_CCODE_STATEMENT, "ValaCCodeBlock", &g_define_type_info, 0);
318 ValaCCodeBlock_private_offset = g_type_add_instance_private (vala_ccode_block_type_id, sizeof (ValaCCodeBlockPrivate));
319 return vala_ccode_block_type_id;
320 }
321
322 GType
vala_ccode_block_get_type(void)323 vala_ccode_block_get_type (void)
324 {
325 static volatile gsize vala_ccode_block_type_id__volatile = 0;
326 if (g_once_init_enter (&vala_ccode_block_type_id__volatile)) {
327 GType vala_ccode_block_type_id;
328 vala_ccode_block_type_id = vala_ccode_block_get_type_once ();
329 g_once_init_leave (&vala_ccode_block_type_id__volatile, vala_ccode_block_type_id);
330 }
331 return vala_ccode_block_type_id__volatile;
332 }
333
334