File: valaccodeifstatement.c

package info (click to toggle)
vala 0.42.5-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 41,584 kB
  • sloc: ansic: 557,663; sh: 4,808; xml: 3,135; makefile: 2,864; yacc: 1,218; lex: 374; perl: 106
file content (315 lines) | stat: -rw-r--r-- 10,124 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/* valaccodeifstatement.c generated by valac, the Vala compiler
 * generated from valaccodeifstatement.vala, do not modify */

/* valaccodeifstatement.vala
 *
 * Copyright (C) 2006-2008  Jürg Billeter
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Jürg Billeter <j@bitron.ch>
 */


#include <glib.h>
#include <glib-object.h>
#include "valaccode.h"

#define _vala_ccode_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_ccode_node_unref (var), NULL)))

struct _ValaCCodeIfStatementPrivate {
	ValaCCodeExpression* _condition;
	ValaCCodeStatement* _true_statement;
	ValaCCodeStatement* _false_statement;
	gboolean _else_if;
};


static gint ValaCCodeIfStatement_private_offset;
static gpointer vala_ccode_if_statement_parent_class = NULL;

static void vala_ccode_if_statement_real_write (ValaCCodeNode* base,
                                         ValaCCodeWriter* writer);
static void vala_ccode_if_statement_finalize (ValaCCodeNode * obj);


static inline gpointer
vala_ccode_if_statement_get_instance_private (ValaCCodeIfStatement* self)
{
	return G_STRUCT_MEMBER_P (self, ValaCCodeIfStatement_private_offset);
}


ValaCCodeIfStatement*
vala_ccode_if_statement_construct (GType object_type,
                                   ValaCCodeExpression* cond,
                                   ValaCCodeStatement* true_stmt,
                                   ValaCCodeStatement* false_stmt)
{
	ValaCCodeIfStatement* self = NULL;
	g_return_val_if_fail (cond != NULL, NULL);
	g_return_val_if_fail (true_stmt != NULL, NULL);
	self = (ValaCCodeIfStatement*) vala_ccode_statement_construct (object_type);
	vala_ccode_if_statement_set_condition (self, cond);
	vala_ccode_if_statement_set_true_statement (self, true_stmt);
	vala_ccode_if_statement_set_false_statement (self, false_stmt);
	return self;
}


ValaCCodeIfStatement*
vala_ccode_if_statement_new (ValaCCodeExpression* cond,
                             ValaCCodeStatement* true_stmt,
                             ValaCCodeStatement* false_stmt)
{
	return vala_ccode_if_statement_construct (VALA_TYPE_CCODE_IF_STATEMENT, cond, true_stmt, false_stmt);
}


static gpointer
_vala_ccode_node_ref0 (gpointer self)
{
	return self ? vala_ccode_node_ref (self) : NULL;
}


static void
vala_ccode_if_statement_real_write (ValaCCodeNode* base,
                                    ValaCCodeWriter* writer)
{
	ValaCCodeIfStatement * self;
	gboolean _tmp0_;
	ValaCCodeExpression* _tmp3_;
	gboolean _tmp5_ = FALSE;
	ValaCCodeStatement* _tmp6_;
	ValaCCodeStatement* _tmp11_;
	ValaCCodeStatement* _tmp12_;
	self = (ValaCCodeIfStatement*) base;
	g_return_if_fail (writer != NULL);
	_tmp0_ = self->priv->_else_if;
	if (!_tmp0_) {
		ValaCCodeLineDirective* _tmp1_;
		ValaCCodeLineDirective* _tmp2_;
		_tmp1_ = vala_ccode_node_get_line ((ValaCCodeNode*) self);
		_tmp2_ = _tmp1_;
		vala_ccode_writer_write_indent (writer, _tmp2_);
	} else {
		vala_ccode_writer_write_string (writer, " ");
	}
	vala_ccode_writer_write_string (writer, "if (");
	_tmp3_ = self->priv->_condition;
	if (_tmp3_ != NULL) {
		ValaCCodeExpression* _tmp4_;
		_tmp4_ = self->priv->_condition;
		vala_ccode_node_write ((ValaCCodeNode*) _tmp4_, writer);
	}
	vala_ccode_writer_write_string (writer, ")");
	_tmp6_ = self->priv->_false_statement;
	if (_tmp6_ != NULL) {
		ValaCCodeStatement* _tmp7_;
		_tmp7_ = self->priv->_true_statement;
		_tmp5_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp7_, VALA_TYPE_CCODE_BLOCK);
	} else {
		_tmp5_ = FALSE;
	}
	if (_tmp5_) {
		ValaCCodeBlock* cblock = NULL;
		ValaCCodeStatement* _tmp8_;
		ValaCCodeBlock* _tmp9_;
		ValaCCodeBlock* _tmp10_;
		_tmp8_ = self->priv->_true_statement;
		_tmp9_ = _vala_ccode_node_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, VALA_TYPE_CCODE_BLOCK, ValaCCodeBlock));
		cblock = _tmp9_;
		_tmp10_ = cblock;
		vala_ccode_block_set_suppress_newline (_tmp10_, TRUE);
		_vala_ccode_node_unref0 (cblock);
	}
	_tmp11_ = self->priv->_true_statement;
	vala_ccode_node_write ((ValaCCodeNode*) _tmp11_, writer);
	_tmp12_ = self->priv->_false_statement;
	if (_tmp12_ != NULL) {
		gboolean _tmp13_;
		gboolean _tmp14_;
		ValaCCodeStatement* _tmp15_;
		ValaCCodeStatement* _tmp19_;
		_tmp13_ = vala_ccode_writer_get_bol (writer);
		_tmp14_ = _tmp13_;
		if (_tmp14_) {
			vala_ccode_writer_write_indent (writer, NULL);
			vala_ccode_writer_write_string (writer, "else");
		} else {
			vala_ccode_writer_write_string (writer, " else");
		}
		_tmp15_ = self->priv->_false_statement;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp15_, VALA_TYPE_CCODE_IF_STATEMENT)) {
			ValaCCodeIfStatement* cif = NULL;
			ValaCCodeStatement* _tmp16_;
			ValaCCodeIfStatement* _tmp17_;
			ValaCCodeIfStatement* _tmp18_;
			_tmp16_ = self->priv->_false_statement;
			_tmp17_ = _vala_ccode_node_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp16_, VALA_TYPE_CCODE_IF_STATEMENT, ValaCCodeIfStatement));
			cif = _tmp17_;
			_tmp18_ = cif;
			vala_ccode_if_statement_set_else_if (_tmp18_, TRUE);
			_vala_ccode_node_unref0 (cif);
		}
		_tmp19_ = self->priv->_false_statement;
		vala_ccode_node_write ((ValaCCodeNode*) _tmp19_, writer);
	}
}


ValaCCodeExpression*
vala_ccode_if_statement_get_condition (ValaCCodeIfStatement* self)
{
	ValaCCodeExpression* result;
	ValaCCodeExpression* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_condition;
	result = _tmp0_;
	return result;
}


void
vala_ccode_if_statement_set_condition (ValaCCodeIfStatement* self,
                                       ValaCCodeExpression* value)
{
	ValaCCodeExpression* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _vala_ccode_node_ref0 (value);
	_vala_ccode_node_unref0 (self->priv->_condition);
	self->priv->_condition = _tmp0_;
}


ValaCCodeStatement*
vala_ccode_if_statement_get_true_statement (ValaCCodeIfStatement* self)
{
	ValaCCodeStatement* result;
	ValaCCodeStatement* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_true_statement;
	result = _tmp0_;
	return result;
}


void
vala_ccode_if_statement_set_true_statement (ValaCCodeIfStatement* self,
                                            ValaCCodeStatement* value)
{
	ValaCCodeStatement* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _vala_ccode_node_ref0 (value);
	_vala_ccode_node_unref0 (self->priv->_true_statement);
	self->priv->_true_statement = _tmp0_;
}


ValaCCodeStatement*
vala_ccode_if_statement_get_false_statement (ValaCCodeIfStatement* self)
{
	ValaCCodeStatement* result;
	ValaCCodeStatement* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_false_statement;
	result = _tmp0_;
	return result;
}


void
vala_ccode_if_statement_set_false_statement (ValaCCodeIfStatement* self,
                                             ValaCCodeStatement* value)
{
	ValaCCodeStatement* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _vala_ccode_node_ref0 (value);
	_vala_ccode_node_unref0 (self->priv->_false_statement);
	self->priv->_false_statement = _tmp0_;
}


gboolean
vala_ccode_if_statement_get_else_if (ValaCCodeIfStatement* self)
{
	gboolean result;
	gboolean _tmp0_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_else_if;
	result = _tmp0_;
	return result;
}


void
vala_ccode_if_statement_set_else_if (ValaCCodeIfStatement* self,
                                     gboolean value)
{
	g_return_if_fail (self != NULL);
	self->priv->_else_if = value;
}


static void
vala_ccode_if_statement_class_init (ValaCCodeIfStatementClass * klass)
{
	vala_ccode_if_statement_parent_class = g_type_class_peek_parent (klass);
	((ValaCCodeNodeClass *) klass)->finalize = vala_ccode_if_statement_finalize;
	g_type_class_adjust_private_offset (klass, &ValaCCodeIfStatement_private_offset);
	((ValaCCodeNodeClass *) klass)->write = (void (*) (ValaCCodeNode*, ValaCCodeWriter*)) vala_ccode_if_statement_real_write;
}


static void
vala_ccode_if_statement_instance_init (ValaCCodeIfStatement * self)
{
	self->priv = vala_ccode_if_statement_get_instance_private (self);
}


static void
vala_ccode_if_statement_finalize (ValaCCodeNode * obj)
{
	ValaCCodeIfStatement * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_CCODE_IF_STATEMENT, ValaCCodeIfStatement);
	_vala_ccode_node_unref0 (self->priv->_condition);
	_vala_ccode_node_unref0 (self->priv->_true_statement);
	_vala_ccode_node_unref0 (self->priv->_false_statement);
	VALA_CCODE_NODE_CLASS (vala_ccode_if_statement_parent_class)->finalize (obj);
}


/**
 * Represents an if selection statement in the C code.
 */
GType
vala_ccode_if_statement_get_type (void)
{
	static volatile gsize vala_ccode_if_statement_type_id__volatile = 0;
	if (g_once_init_enter (&vala_ccode_if_statement_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValaCCodeIfStatementClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_ccode_if_statement_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaCCodeIfStatement), 0, (GInstanceInitFunc) vala_ccode_if_statement_instance_init, NULL };
		GType vala_ccode_if_statement_type_id;
		vala_ccode_if_statement_type_id = g_type_register_static (VALA_TYPE_CCODE_STATEMENT, "ValaCCodeIfStatement", &g_define_type_info, 0);
		ValaCCodeIfStatement_private_offset = g_type_add_instance_private (vala_ccode_if_statement_type_id, sizeof (ValaCCodeIfStatementPrivate));
		g_once_init_leave (&vala_ccode_if_statement_type_id__volatile, vala_ccode_if_statement_type_id);
	}
	return vala_ccode_if_statement_type_id__volatile;
}