1 /* valaccodedostatement.c generated by valac, the Vala compiler
2  * generated from valaccodedostatement.vala, do not modify */
3 
4 /* valaccodedostatement.vala
5  *
6  * Copyright (C) 2006-2007  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 
29 #define _vala_ccode_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_ccode_node_unref (var), NULL)))
30 
31 struct _ValaCCodeDoStatementPrivate {
32 	ValaCCodeStatement* _body;
33 	ValaCCodeExpression* _condition;
34 };
35 
36 static gint ValaCCodeDoStatement_private_offset;
37 static gpointer vala_ccode_do_statement_parent_class = NULL;
38 
39 static void vala_ccode_do_statement_real_write (ValaCCodeNode* base,
40                                          ValaCCodeWriter* writer);
41 static void vala_ccode_do_statement_finalize (ValaCCodeNode * obj);
42 static GType vala_ccode_do_statement_get_type_once (void);
43 
44 static inline gpointer
vala_ccode_do_statement_get_instance_private(ValaCCodeDoStatement * self)45 vala_ccode_do_statement_get_instance_private (ValaCCodeDoStatement* self)
46 {
47 	return G_STRUCT_MEMBER_P (self, ValaCCodeDoStatement_private_offset);
48 }
49 
50 ValaCCodeStatement*
vala_ccode_do_statement_get_body(ValaCCodeDoStatement * self)51 vala_ccode_do_statement_get_body (ValaCCodeDoStatement* self)
52 {
53 	ValaCCodeStatement* result;
54 	ValaCCodeStatement* _tmp0_;
55 	g_return_val_if_fail (self != NULL, NULL);
56 	_tmp0_ = self->priv->_body;
57 	result = _tmp0_;
58 	return result;
59 }
60 
61 static gpointer
_vala_ccode_node_ref0(gpointer self)62 _vala_ccode_node_ref0 (gpointer self)
63 {
64 	return self ? vala_ccode_node_ref (self) : NULL;
65 }
66 
67 void
vala_ccode_do_statement_set_body(ValaCCodeDoStatement * self,ValaCCodeStatement * value)68 vala_ccode_do_statement_set_body (ValaCCodeDoStatement* self,
69                                   ValaCCodeStatement* value)
70 {
71 	ValaCCodeStatement* _tmp0_;
72 	g_return_if_fail (self != NULL);
73 	_tmp0_ = _vala_ccode_node_ref0 (value);
74 	_vala_ccode_node_unref0 (self->priv->_body);
75 	self->priv->_body = _tmp0_;
76 }
77 
78 ValaCCodeExpression*
vala_ccode_do_statement_get_condition(ValaCCodeDoStatement * self)79 vala_ccode_do_statement_get_condition (ValaCCodeDoStatement* self)
80 {
81 	ValaCCodeExpression* result;
82 	ValaCCodeExpression* _tmp0_;
83 	g_return_val_if_fail (self != NULL, NULL);
84 	_tmp0_ = self->priv->_condition;
85 	result = _tmp0_;
86 	return result;
87 }
88 
89 void
vala_ccode_do_statement_set_condition(ValaCCodeDoStatement * self,ValaCCodeExpression * value)90 vala_ccode_do_statement_set_condition (ValaCCodeDoStatement* self,
91                                        ValaCCodeExpression* value)
92 {
93 	ValaCCodeExpression* _tmp0_;
94 	g_return_if_fail (self != NULL);
95 	_tmp0_ = _vala_ccode_node_ref0 (value);
96 	_vala_ccode_node_unref0 (self->priv->_condition);
97 	self->priv->_condition = _tmp0_;
98 }
99 
100 ValaCCodeDoStatement*
vala_ccode_do_statement_construct(GType object_type,ValaCCodeStatement * stmt,ValaCCodeExpression * cond)101 vala_ccode_do_statement_construct (GType object_type,
102                                    ValaCCodeStatement* stmt,
103                                    ValaCCodeExpression* cond)
104 {
105 	ValaCCodeDoStatement* self = NULL;
106 	g_return_val_if_fail (stmt != NULL, NULL);
107 	g_return_val_if_fail (cond != NULL, NULL);
108 	self = (ValaCCodeDoStatement*) vala_ccode_statement_construct (object_type);
109 	vala_ccode_do_statement_set_body (self, stmt);
110 	vala_ccode_do_statement_set_condition (self, cond);
111 	return self;
112 }
113 
114 ValaCCodeDoStatement*
vala_ccode_do_statement_new(ValaCCodeStatement * stmt,ValaCCodeExpression * cond)115 vala_ccode_do_statement_new (ValaCCodeStatement* stmt,
116                              ValaCCodeExpression* cond)
117 {
118 	return vala_ccode_do_statement_construct (VALA_TYPE_CCODE_DO_STATEMENT, stmt, cond);
119 }
120 
121 static void
vala_ccode_do_statement_real_write(ValaCCodeNode * base,ValaCCodeWriter * writer)122 vala_ccode_do_statement_real_write (ValaCCodeNode* base,
123                                     ValaCCodeWriter* writer)
124 {
125 	ValaCCodeDoStatement * self;
126 	ValaCCodeLineDirective* _tmp0_;
127 	ValaCCodeLineDirective* _tmp1_;
128 	ValaCCodeStatement* _tmp2_;
129 	ValaCCodeStatement* _tmp6_;
130 	ValaCCodeExpression* _tmp7_;
131 	self = (ValaCCodeDoStatement*) base;
132 	g_return_if_fail (writer != NULL);
133 	_tmp0_ = vala_ccode_node_get_line ((ValaCCodeNode*) self);
134 	_tmp1_ = _tmp0_;
135 	vala_ccode_writer_write_indent (writer, _tmp1_);
136 	vala_ccode_writer_write_string (writer, "do");
137 	_tmp2_ = self->priv->_body;
138 	if (VALA_IS_CCODE_BLOCK (_tmp2_)) {
139 		ValaCCodeBlock* cblock = NULL;
140 		ValaCCodeStatement* _tmp3_;
141 		ValaCCodeBlock* _tmp4_;
142 		ValaCCodeBlock* _tmp5_;
143 		_tmp3_ = self->priv->_body;
144 		_tmp4_ = _vala_ccode_node_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, VALA_TYPE_CCODE_BLOCK, ValaCCodeBlock));
145 		cblock = _tmp4_;
146 		_tmp5_ = cblock;
147 		vala_ccode_block_set_suppress_newline (_tmp5_, TRUE);
148 		_vala_ccode_node_unref0 (cblock);
149 	}
150 	_tmp6_ = self->priv->_body;
151 	vala_ccode_node_write ((ValaCCodeNode*) _tmp6_, writer);
152 	vala_ccode_writer_write_string (writer, " while (");
153 	_tmp7_ = self->priv->_condition;
154 	vala_ccode_node_write ((ValaCCodeNode*) _tmp7_, writer);
155 	vala_ccode_writer_write_string (writer, ");");
156 }
157 
158 static void
vala_ccode_do_statement_class_init(ValaCCodeDoStatementClass * klass,gpointer klass_data)159 vala_ccode_do_statement_class_init (ValaCCodeDoStatementClass * klass,
160                                     gpointer klass_data)
161 {
162 	vala_ccode_do_statement_parent_class = g_type_class_peek_parent (klass);
163 	((ValaCCodeNodeClass *) klass)->finalize = vala_ccode_do_statement_finalize;
164 	g_type_class_adjust_private_offset (klass, &ValaCCodeDoStatement_private_offset);
165 	((ValaCCodeNodeClass *) klass)->write = (void (*) (ValaCCodeNode*, ValaCCodeWriter*)) vala_ccode_do_statement_real_write;
166 }
167 
168 static void
vala_ccode_do_statement_instance_init(ValaCCodeDoStatement * self,gpointer klass)169 vala_ccode_do_statement_instance_init (ValaCCodeDoStatement * self,
170                                        gpointer klass)
171 {
172 	self->priv = vala_ccode_do_statement_get_instance_private (self);
173 }
174 
175 static void
vala_ccode_do_statement_finalize(ValaCCodeNode * obj)176 vala_ccode_do_statement_finalize (ValaCCodeNode * obj)
177 {
178 	ValaCCodeDoStatement * self;
179 	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_CCODE_DO_STATEMENT, ValaCCodeDoStatement);
180 	_vala_ccode_node_unref0 (self->priv->_body);
181 	_vala_ccode_node_unref0 (self->priv->_condition);
182 	VALA_CCODE_NODE_CLASS (vala_ccode_do_statement_parent_class)->finalize (obj);
183 }
184 
185 /**
186  * Represents a do iteration statement in the C code.
187  */
188 static GType
vala_ccode_do_statement_get_type_once(void)189 vala_ccode_do_statement_get_type_once (void)
190 {
191 	static const GTypeInfo g_define_type_info = { sizeof (ValaCCodeDoStatementClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_ccode_do_statement_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaCCodeDoStatement), 0, (GInstanceInitFunc) vala_ccode_do_statement_instance_init, NULL };
192 	GType vala_ccode_do_statement_type_id;
193 	vala_ccode_do_statement_type_id = g_type_register_static (VALA_TYPE_CCODE_STATEMENT, "ValaCCodeDoStatement", &g_define_type_info, 0);
194 	ValaCCodeDoStatement_private_offset = g_type_add_instance_private (vala_ccode_do_statement_type_id, sizeof (ValaCCodeDoStatementPrivate));
195 	return vala_ccode_do_statement_type_id;
196 }
197 
198 GType
vala_ccode_do_statement_get_type(void)199 vala_ccode_do_statement_get_type (void)
200 {
201 	static volatile gsize vala_ccode_do_statement_type_id__volatile = 0;
202 	if (g_once_init_enter (&vala_ccode_do_statement_type_id__volatile)) {
203 		GType vala_ccode_do_statement_type_id;
204 		vala_ccode_do_statement_type_id = vala_ccode_do_statement_get_type_once ();
205 		g_once_init_leave (&vala_ccode_do_statement_type_id__volatile, vala_ccode_do_statement_type_id);
206 	}
207 	return vala_ccode_do_statement_type_id__volatile;
208 }
209 
210