1 /* valaunlockstatement.c generated by valac, the Vala compiler
2 * generated from valaunlockstatement.vala, do not modify */
3
4 /* valaunlockstatement.vala
5 *
6 * Copyright (C) 2009-2010 Jürg Billeter
7 * Copyright (C) 2009 Jiří Zárevúcky
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 *
23 * Author:
24 * Jiří Zárevúcky <zarevucky.jiri@gmail.com>
25 */
26
27 #include "vala.h"
28 #include <glib.h>
29
30 #define _vala_code_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_node_unref (var), NULL)))
31
32 struct _ValaUnlockStatementPrivate {
33 ValaExpression* _resource;
34 };
35
36 static gint ValaUnlockStatement_private_offset;
37 static gpointer vala_unlock_statement_parent_class = NULL;
38 static ValaStatementIface * vala_unlock_statement_vala_statement_parent_iface = NULL;
39
40 static void vala_unlock_statement_real_accept (ValaCodeNode* base,
41 ValaCodeVisitor* visitor);
42 static void vala_unlock_statement_real_replace_expression (ValaCodeNode* base,
43 ValaExpression* old_node,
44 ValaExpression* new_node);
45 static gboolean vala_unlock_statement_real_check (ValaCodeNode* base,
46 ValaCodeContext* context);
47 static void vala_unlock_statement_real_emit (ValaCodeNode* base,
48 ValaCodeGenerator* codegen);
49 static void vala_unlock_statement_finalize (ValaCodeNode * obj);
50 static GType vala_unlock_statement_get_type_once (void);
51
52 static inline gpointer
vala_unlock_statement_get_instance_private(ValaUnlockStatement * self)53 vala_unlock_statement_get_instance_private (ValaUnlockStatement* self)
54 {
55 return G_STRUCT_MEMBER_P (self, ValaUnlockStatement_private_offset);
56 }
57
58 ValaExpression*
vala_unlock_statement_get_resource(ValaUnlockStatement * self)59 vala_unlock_statement_get_resource (ValaUnlockStatement* self)
60 {
61 ValaExpression* result;
62 ValaExpression* _tmp0_;
63 g_return_val_if_fail (self != NULL, NULL);
64 _tmp0_ = self->priv->_resource;
65 result = _tmp0_;
66 return result;
67 }
68
69 static gpointer
_vala_code_node_ref0(gpointer self)70 _vala_code_node_ref0 (gpointer self)
71 {
72 return self ? vala_code_node_ref (self) : NULL;
73 }
74
75 void
vala_unlock_statement_set_resource(ValaUnlockStatement * self,ValaExpression * value)76 vala_unlock_statement_set_resource (ValaUnlockStatement* self,
77 ValaExpression* value)
78 {
79 ValaExpression* _tmp0_;
80 ValaExpression* _tmp1_;
81 g_return_if_fail (self != NULL);
82 _tmp0_ = _vala_code_node_ref0 (value);
83 _vala_code_node_unref0 (self->priv->_resource);
84 self->priv->_resource = _tmp0_;
85 _tmp1_ = self->priv->_resource;
86 vala_code_node_set_parent_node ((ValaCodeNode*) _tmp1_, (ValaCodeNode*) self);
87 }
88
89 ValaUnlockStatement*
vala_unlock_statement_construct(GType object_type,ValaExpression * resource,ValaSourceReference * source_reference)90 vala_unlock_statement_construct (GType object_type,
91 ValaExpression* resource,
92 ValaSourceReference* source_reference)
93 {
94 ValaUnlockStatement* self = NULL;
95 g_return_val_if_fail (resource != NULL, NULL);
96 self = (ValaUnlockStatement*) vala_code_node_construct (object_type);
97 vala_code_node_set_source_reference ((ValaCodeNode*) self, source_reference);
98 vala_unlock_statement_set_resource (self, resource);
99 return self;
100 }
101
102 ValaUnlockStatement*
vala_unlock_statement_new(ValaExpression * resource,ValaSourceReference * source_reference)103 vala_unlock_statement_new (ValaExpression* resource,
104 ValaSourceReference* source_reference)
105 {
106 return vala_unlock_statement_construct (VALA_TYPE_UNLOCK_STATEMENT, resource, source_reference);
107 }
108
109 static void
vala_unlock_statement_real_accept(ValaCodeNode * base,ValaCodeVisitor * visitor)110 vala_unlock_statement_real_accept (ValaCodeNode* base,
111 ValaCodeVisitor* visitor)
112 {
113 ValaUnlockStatement * self;
114 ValaExpression* _tmp0_;
115 ValaExpression* _tmp1_;
116 self = (ValaUnlockStatement*) base;
117 g_return_if_fail (visitor != NULL);
118 _tmp0_ = vala_unlock_statement_get_resource (self);
119 _tmp1_ = _tmp0_;
120 vala_code_node_accept ((ValaCodeNode*) _tmp1_, visitor);
121 vala_code_visitor_visit_unlock_statement (visitor, self);
122 }
123
124 static void
vala_unlock_statement_real_replace_expression(ValaCodeNode * base,ValaExpression * old_node,ValaExpression * new_node)125 vala_unlock_statement_real_replace_expression (ValaCodeNode* base,
126 ValaExpression* old_node,
127 ValaExpression* new_node)
128 {
129 ValaUnlockStatement * self;
130 ValaExpression* _tmp0_;
131 ValaExpression* _tmp1_;
132 self = (ValaUnlockStatement*) base;
133 g_return_if_fail (old_node != NULL);
134 g_return_if_fail (new_node != NULL);
135 _tmp0_ = vala_unlock_statement_get_resource (self);
136 _tmp1_ = _tmp0_;
137 if (_tmp1_ == old_node) {
138 vala_unlock_statement_set_resource (self, new_node);
139 }
140 }
141
142 static gboolean
vala_unlock_statement_real_check(ValaCodeNode * base,ValaCodeContext * context)143 vala_unlock_statement_real_check (ValaCodeNode* base,
144 ValaCodeContext* context)
145 {
146 ValaUnlockStatement * self;
147 gboolean _tmp0_;
148 gboolean _tmp1_;
149 ValaExpression* _tmp4_;
150 ValaExpression* _tmp5_;
151 gboolean _tmp6_ = FALSE;
152 ValaExpression* _tmp7_;
153 ValaExpression* _tmp8_;
154 ValaExpression* _tmp19_;
155 ValaExpression* _tmp20_;
156 ValaSymbol* _tmp21_;
157 ValaSymbol* _tmp22_;
158 ValaSymbol* _tmp23_;
159 ValaSymbol* _tmp24_;
160 ValaSemanticAnalyzer* _tmp25_;
161 ValaSemanticAnalyzer* _tmp26_;
162 ValaClass* _tmp27_;
163 ValaClass* _tmp28_;
164 ValaSemanticAnalyzer* _tmp35_;
165 ValaSemanticAnalyzer* _tmp36_;
166 ValaClass* _tmp37_;
167 ValaClass* _tmp38_;
168 gboolean _tmp39_;
169 gboolean _tmp40_;
170 ValaExpression* _tmp47_;
171 ValaExpression* _tmp48_;
172 ValaSymbol* _tmp49_;
173 ValaSymbol* _tmp50_;
174 gboolean _tmp51_;
175 gboolean _tmp52_;
176 gboolean result = FALSE;
177 self = (ValaUnlockStatement*) base;
178 g_return_val_if_fail (context != NULL, FALSE);
179 _tmp0_ = vala_code_node_get_checked ((ValaCodeNode*) self);
180 _tmp1_ = _tmp0_;
181 if (_tmp1_) {
182 gboolean _tmp2_;
183 gboolean _tmp3_;
184 _tmp2_ = vala_code_node_get_error ((ValaCodeNode*) self);
185 _tmp3_ = _tmp2_;
186 result = !_tmp3_;
187 return result;
188 }
189 vala_code_node_set_checked ((ValaCodeNode*) self, TRUE);
190 _tmp4_ = vala_unlock_statement_get_resource (self);
191 _tmp5_ = _tmp4_;
192 vala_code_node_check ((ValaCodeNode*) _tmp5_, context);
193 _tmp7_ = vala_unlock_statement_get_resource (self);
194 _tmp8_ = _tmp7_;
195 if (VALA_IS_MEMBER_ACCESS (_tmp8_)) {
196 ValaExpression* _tmp9_;
197 ValaExpression* _tmp10_;
198 ValaSymbol* _tmp11_;
199 ValaSymbol* _tmp12_;
200 _tmp9_ = vala_unlock_statement_get_resource (self);
201 _tmp10_ = _tmp9_;
202 _tmp11_ = vala_expression_get_symbol_reference (_tmp10_);
203 _tmp12_ = _tmp11_;
204 _tmp6_ = VALA_IS_LOCKABLE (_tmp12_);
205 } else {
206 _tmp6_ = FALSE;
207 }
208 if (!_tmp6_) {
209 ValaExpression* _tmp13_;
210 ValaExpression* _tmp14_;
211 ValaExpression* _tmp15_;
212 ValaExpression* _tmp16_;
213 ValaSourceReference* _tmp17_;
214 ValaSourceReference* _tmp18_;
215 vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
216 _tmp13_ = vala_unlock_statement_get_resource (self);
217 _tmp14_ = _tmp13_;
218 vala_code_node_set_error ((ValaCodeNode*) _tmp14_, TRUE);
219 _tmp15_ = vala_unlock_statement_get_resource (self);
220 _tmp16_ = _tmp15_;
221 _tmp17_ = vala_code_node_get_source_reference ((ValaCodeNode*) _tmp16_);
222 _tmp18_ = _tmp17_;
223 vala_report_error (_tmp18_, "Expression is either not a member access or does not denote a lockable" \
224 " member");
225 result = FALSE;
226 return result;
227 }
228 _tmp19_ = vala_unlock_statement_get_resource (self);
229 _tmp20_ = _tmp19_;
230 _tmp21_ = vala_expression_get_symbol_reference (_tmp20_);
231 _tmp22_ = _tmp21_;
232 _tmp23_ = vala_symbol_get_parent_symbol (_tmp22_);
233 _tmp24_ = _tmp23_;
234 _tmp25_ = vala_code_context_get_analyzer (context);
235 _tmp26_ = _tmp25_;
236 _tmp27_ = vala_semantic_analyzer_get_current_class (_tmp26_);
237 _tmp28_ = _tmp27_;
238 if (_tmp24_ != G_TYPE_CHECK_INSTANCE_CAST (_tmp28_, VALA_TYPE_SYMBOL, ValaSymbol)) {
239 ValaExpression* _tmp29_;
240 ValaExpression* _tmp30_;
241 ValaExpression* _tmp31_;
242 ValaExpression* _tmp32_;
243 ValaSourceReference* _tmp33_;
244 ValaSourceReference* _tmp34_;
245 vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
246 _tmp29_ = vala_unlock_statement_get_resource (self);
247 _tmp30_ = _tmp29_;
248 vala_code_node_set_error ((ValaCodeNode*) _tmp30_, TRUE);
249 _tmp31_ = vala_unlock_statement_get_resource (self);
250 _tmp32_ = _tmp31_;
251 _tmp33_ = vala_code_node_get_source_reference ((ValaCodeNode*) _tmp32_);
252 _tmp34_ = _tmp33_;
253 vala_report_error (_tmp34_, "Only members of the current class are lockable");
254 result = FALSE;
255 return result;
256 }
257 _tmp35_ = vala_code_context_get_analyzer (context);
258 _tmp36_ = _tmp35_;
259 _tmp37_ = vala_semantic_analyzer_get_current_class (_tmp36_);
260 _tmp38_ = _tmp37_;
261 _tmp39_ = vala_class_get_is_compact (_tmp38_);
262 _tmp40_ = _tmp39_;
263 if (_tmp40_) {
264 ValaExpression* _tmp41_;
265 ValaExpression* _tmp42_;
266 ValaExpression* _tmp43_;
267 ValaExpression* _tmp44_;
268 ValaSourceReference* _tmp45_;
269 ValaSourceReference* _tmp46_;
270 vala_code_node_set_error ((ValaCodeNode*) self, TRUE);
271 _tmp41_ = vala_unlock_statement_get_resource (self);
272 _tmp42_ = _tmp41_;
273 vala_code_node_set_error ((ValaCodeNode*) _tmp42_, TRUE);
274 _tmp43_ = vala_unlock_statement_get_resource (self);
275 _tmp44_ = _tmp43_;
276 _tmp45_ = vala_code_node_get_source_reference ((ValaCodeNode*) _tmp44_);
277 _tmp46_ = _tmp45_;
278 vala_report_error (_tmp46_, "Only members of the non-compact classes are lockable");
279 result = FALSE;
280 return result;
281 }
282 _tmp47_ = vala_unlock_statement_get_resource (self);
283 _tmp48_ = _tmp47_;
284 _tmp49_ = vala_expression_get_symbol_reference (_tmp48_);
285 _tmp50_ = _tmp49_;
286 vala_lockable_set_lock_used (G_TYPE_CHECK_INSTANCE_CAST (_tmp50_, VALA_TYPE_LOCKABLE, ValaLockable), TRUE);
287 _tmp51_ = vala_code_node_get_error ((ValaCodeNode*) self);
288 _tmp52_ = _tmp51_;
289 result = !_tmp52_;
290 return result;
291 }
292
293 static void
vala_unlock_statement_real_emit(ValaCodeNode * base,ValaCodeGenerator * codegen)294 vala_unlock_statement_real_emit (ValaCodeNode* base,
295 ValaCodeGenerator* codegen)
296 {
297 ValaUnlockStatement * self;
298 ValaExpression* _tmp0_;
299 ValaExpression* _tmp1_;
300 self = (ValaUnlockStatement*) base;
301 g_return_if_fail (codegen != NULL);
302 _tmp0_ = vala_unlock_statement_get_resource (self);
303 _tmp1_ = _tmp0_;
304 vala_code_node_emit ((ValaCodeNode*) _tmp1_, codegen);
305 vala_code_visitor_visit_unlock_statement ((ValaCodeVisitor*) codegen, self);
306 }
307
308 static void
vala_unlock_statement_class_init(ValaUnlockStatementClass * klass,gpointer klass_data)309 vala_unlock_statement_class_init (ValaUnlockStatementClass * klass,
310 gpointer klass_data)
311 {
312 vala_unlock_statement_parent_class = g_type_class_peek_parent (klass);
313 ((ValaCodeNodeClass *) klass)->finalize = vala_unlock_statement_finalize;
314 g_type_class_adjust_private_offset (klass, &ValaUnlockStatement_private_offset);
315 ((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_unlock_statement_real_accept;
316 ((ValaCodeNodeClass *) klass)->replace_expression = (void (*) (ValaCodeNode*, ValaExpression*, ValaExpression*)) vala_unlock_statement_real_replace_expression;
317 ((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode*, ValaCodeContext*)) vala_unlock_statement_real_check;
318 ((ValaCodeNodeClass *) klass)->emit = (void (*) (ValaCodeNode*, ValaCodeGenerator*)) vala_unlock_statement_real_emit;
319 }
320
321 static void
vala_unlock_statement_vala_statement_interface_init(ValaStatementIface * iface,gpointer iface_data)322 vala_unlock_statement_vala_statement_interface_init (ValaStatementIface * iface,
323 gpointer iface_data)
324 {
325 vala_unlock_statement_vala_statement_parent_iface = g_type_interface_peek_parent (iface);
326 }
327
328 static void
vala_unlock_statement_instance_init(ValaUnlockStatement * self,gpointer klass)329 vala_unlock_statement_instance_init (ValaUnlockStatement * self,
330 gpointer klass)
331 {
332 self->priv = vala_unlock_statement_get_instance_private (self);
333 }
334
335 static void
vala_unlock_statement_finalize(ValaCodeNode * obj)336 vala_unlock_statement_finalize (ValaCodeNode * obj)
337 {
338 ValaUnlockStatement * self;
339 self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_UNLOCK_STATEMENT, ValaUnlockStatement);
340 _vala_code_node_unref0 (self->priv->_resource);
341 VALA_CODE_NODE_CLASS (vala_unlock_statement_parent_class)->finalize (obj);
342 }
343
344 /**
345 * Represents an unlock statement.
346 *
347 * {{{ unlock (foo); }}}
348 */
349 static GType
vala_unlock_statement_get_type_once(void)350 vala_unlock_statement_get_type_once (void)
351 {
352 static const GTypeInfo g_define_type_info = { sizeof (ValaUnlockStatementClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_unlock_statement_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaUnlockStatement), 0, (GInstanceInitFunc) vala_unlock_statement_instance_init, NULL };
353 static const GInterfaceInfo vala_statement_info = { (GInterfaceInitFunc) vala_unlock_statement_vala_statement_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
354 GType vala_unlock_statement_type_id;
355 vala_unlock_statement_type_id = g_type_register_static (VALA_TYPE_CODE_NODE, "ValaUnlockStatement", &g_define_type_info, 0);
356 g_type_add_interface_static (vala_unlock_statement_type_id, VALA_TYPE_STATEMENT, &vala_statement_info);
357 ValaUnlockStatement_private_offset = g_type_add_instance_private (vala_unlock_statement_type_id, sizeof (ValaUnlockStatementPrivate));
358 return vala_unlock_statement_type_id;
359 }
360
361 GType
vala_unlock_statement_get_type(void)362 vala_unlock_statement_get_type (void)
363 {
364 static volatile gsize vala_unlock_statement_type_id__volatile = 0;
365 if (g_once_init_enter (&vala_unlock_statement_type_id__volatile)) {
366 GType vala_unlock_statement_type_id;
367 vala_unlock_statement_type_id = vala_unlock_statement_get_type_once ();
368 g_once_init_leave (&vala_unlock_statement_type_id__volatile, vala_unlock_statement_type_id);
369 }
370 return vala_unlock_statement_type_id__volatile;
371 }
372
373