1 /* valabooleanliteral.c generated by valac, the Vala compiler
2  * generated from valabooleanliteral.vala, do not modify */
3 
4 /* valabooleanliteral.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 "vala.h"
27 #include <glib.h>
28 #include <stdlib.h>
29 #include <string.h>
30 
31 struct _ValaBooleanLiteralPrivate {
32 	gboolean _value;
33 };
34 
35 static gint ValaBooleanLiteral_private_offset;
36 static gpointer vala_boolean_literal_parent_class = NULL;
37 
38 static void vala_boolean_literal_real_accept (ValaCodeNode* base,
39                                        ValaCodeVisitor* visitor);
40 static gchar* vala_boolean_literal_real_to_string (ValaCodeNode* base);
41 static gboolean vala_boolean_literal_real_is_pure (ValaExpression* base);
42 static gboolean vala_boolean_literal_real_check (ValaCodeNode* base,
43                                           ValaCodeContext* context);
44 static void vala_boolean_literal_real_emit (ValaCodeNode* base,
45                                      ValaCodeGenerator* codegen);
46 static void vala_boolean_literal_finalize (ValaCodeNode * obj);
47 static GType vala_boolean_literal_get_type_once (void);
48 
49 static inline gpointer
vala_boolean_literal_get_instance_private(ValaBooleanLiteral * self)50 vala_boolean_literal_get_instance_private (ValaBooleanLiteral* self)
51 {
52 	return G_STRUCT_MEMBER_P (self, ValaBooleanLiteral_private_offset);
53 }
54 
55 gboolean
vala_boolean_literal_get_value(ValaBooleanLiteral * self)56 vala_boolean_literal_get_value (ValaBooleanLiteral* self)
57 {
58 	gboolean result;
59 	g_return_val_if_fail (self != NULL, FALSE);
60 	result = self->priv->_value;
61 	return result;
62 }
63 
64 void
vala_boolean_literal_set_value(ValaBooleanLiteral * self,gboolean value)65 vala_boolean_literal_set_value (ValaBooleanLiteral* self,
66                                 gboolean value)
67 {
68 	g_return_if_fail (self != NULL);
69 	self->priv->_value = value;
70 }
71 
72 /**
73  * Creates a new boolean literal.
74  *
75  * @param b      boolean value
76  * @param source reference to source code
77  * @return       newly created boolean literal
78  */
79 ValaBooleanLiteral*
vala_boolean_literal_construct(GType object_type,gboolean b,ValaSourceReference * source)80 vala_boolean_literal_construct (GType object_type,
81                                 gboolean b,
82                                 ValaSourceReference* source)
83 {
84 	ValaBooleanLiteral* self = NULL;
85 	self = (ValaBooleanLiteral*) vala_literal_construct (object_type);
86 	vala_boolean_literal_set_value (self, b);
87 	vala_code_node_set_source_reference ((ValaCodeNode*) self, source);
88 	return self;
89 }
90 
91 ValaBooleanLiteral*
vala_boolean_literal_new(gboolean b,ValaSourceReference * source)92 vala_boolean_literal_new (gboolean b,
93                           ValaSourceReference* source)
94 {
95 	return vala_boolean_literal_construct (VALA_TYPE_BOOLEAN_LITERAL, b, source);
96 }
97 
98 static void
vala_boolean_literal_real_accept(ValaCodeNode * base,ValaCodeVisitor * visitor)99 vala_boolean_literal_real_accept (ValaCodeNode* base,
100                                   ValaCodeVisitor* visitor)
101 {
102 	ValaBooleanLiteral * self;
103 	self = (ValaBooleanLiteral*) base;
104 	g_return_if_fail (visitor != NULL);
105 	vala_code_visitor_visit_boolean_literal (visitor, self);
106 	vala_code_visitor_visit_expression (visitor, (ValaExpression*) self);
107 }
108 
109 static gchar*
vala_boolean_literal_real_to_string(ValaCodeNode * base)110 vala_boolean_literal_real_to_string (ValaCodeNode* base)
111 {
112 	ValaBooleanLiteral * self;
113 	gboolean _tmp0_;
114 	gchar* result = NULL;
115 	self = (ValaBooleanLiteral*) base;
116 	_tmp0_ = self->priv->_value;
117 	if (_tmp0_) {
118 		gchar* _tmp1_;
119 		_tmp1_ = g_strdup ("true");
120 		result = _tmp1_;
121 		return result;
122 	} else {
123 		gchar* _tmp2_;
124 		_tmp2_ = g_strdup ("false");
125 		result = _tmp2_;
126 		return result;
127 	}
128 }
129 
130 static gboolean
vala_boolean_literal_real_is_pure(ValaExpression * base)131 vala_boolean_literal_real_is_pure (ValaExpression* base)
132 {
133 	ValaBooleanLiteral * self;
134 	gboolean result = FALSE;
135 	self = (ValaBooleanLiteral*) base;
136 	result = TRUE;
137 	return result;
138 }
139 
140 static gboolean
vala_boolean_literal_real_check(ValaCodeNode * base,ValaCodeContext * context)141 vala_boolean_literal_real_check (ValaCodeNode* base,
142                                  ValaCodeContext* context)
143 {
144 	ValaBooleanLiteral * self;
145 	gboolean _tmp0_;
146 	gboolean _tmp1_;
147 	ValaSemanticAnalyzer* _tmp4_;
148 	ValaSemanticAnalyzer* _tmp5_;
149 	ValaDataType* _tmp6_;
150 	gboolean _tmp7_;
151 	gboolean _tmp8_;
152 	gboolean result = FALSE;
153 	self = (ValaBooleanLiteral*) base;
154 	g_return_val_if_fail (context != NULL, FALSE);
155 	_tmp0_ = vala_code_node_get_checked ((ValaCodeNode*) self);
156 	_tmp1_ = _tmp0_;
157 	if (_tmp1_) {
158 		gboolean _tmp2_;
159 		gboolean _tmp3_;
160 		_tmp2_ = vala_code_node_get_error ((ValaCodeNode*) self);
161 		_tmp3_ = _tmp2_;
162 		result = !_tmp3_;
163 		return result;
164 	}
165 	vala_code_node_set_checked ((ValaCodeNode*) self, TRUE);
166 	_tmp4_ = vala_code_context_get_analyzer (context);
167 	_tmp5_ = _tmp4_;
168 	_tmp6_ = _tmp5_->bool_type;
169 	vala_expression_set_value_type ((ValaExpression*) self, _tmp6_);
170 	_tmp7_ = vala_code_node_get_error ((ValaCodeNode*) self);
171 	_tmp8_ = _tmp7_;
172 	result = !_tmp8_;
173 	return result;
174 }
175 
176 static void
vala_boolean_literal_real_emit(ValaCodeNode * base,ValaCodeGenerator * codegen)177 vala_boolean_literal_real_emit (ValaCodeNode* base,
178                                 ValaCodeGenerator* codegen)
179 {
180 	ValaBooleanLiteral * self;
181 	self = (ValaBooleanLiteral*) base;
182 	g_return_if_fail (codegen != NULL);
183 	vala_code_visitor_visit_boolean_literal ((ValaCodeVisitor*) codegen, self);
184 	vala_code_visitor_visit_expression ((ValaCodeVisitor*) codegen, (ValaExpression*) self);
185 }
186 
187 static void
vala_boolean_literal_class_init(ValaBooleanLiteralClass * klass,gpointer klass_data)188 vala_boolean_literal_class_init (ValaBooleanLiteralClass * klass,
189                                  gpointer klass_data)
190 {
191 	vala_boolean_literal_parent_class = g_type_class_peek_parent (klass);
192 	((ValaCodeNodeClass *) klass)->finalize = vala_boolean_literal_finalize;
193 	g_type_class_adjust_private_offset (klass, &ValaBooleanLiteral_private_offset);
194 	((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_boolean_literal_real_accept;
195 	((ValaCodeNodeClass *) klass)->to_string = (gchar* (*) (ValaCodeNode*)) vala_boolean_literal_real_to_string;
196 	((ValaExpressionClass *) klass)->is_pure = (gboolean (*) (ValaExpression*)) vala_boolean_literal_real_is_pure;
197 	((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode*, ValaCodeContext*)) vala_boolean_literal_real_check;
198 	((ValaCodeNodeClass *) klass)->emit = (void (*) (ValaCodeNode*, ValaCodeGenerator*)) vala_boolean_literal_real_emit;
199 }
200 
201 static void
vala_boolean_literal_instance_init(ValaBooleanLiteral * self,gpointer klass)202 vala_boolean_literal_instance_init (ValaBooleanLiteral * self,
203                                     gpointer klass)
204 {
205 	self->priv = vala_boolean_literal_get_instance_private (self);
206 }
207 
208 static void
vala_boolean_literal_finalize(ValaCodeNode * obj)209 vala_boolean_literal_finalize (ValaCodeNode * obj)
210 {
211 	ValaBooleanLiteral * self;
212 	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_BOOLEAN_LITERAL, ValaBooleanLiteral);
213 	VALA_CODE_NODE_CLASS (vala_boolean_literal_parent_class)->finalize (obj);
214 }
215 
216 /**
217  * Represents a literal boolean, i.e. true or false.
218  */
219 static GType
vala_boolean_literal_get_type_once(void)220 vala_boolean_literal_get_type_once (void)
221 {
222 	static const GTypeInfo g_define_type_info = { sizeof (ValaBooleanLiteralClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_boolean_literal_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaBooleanLiteral), 0, (GInstanceInitFunc) vala_boolean_literal_instance_init, NULL };
223 	GType vala_boolean_literal_type_id;
224 	vala_boolean_literal_type_id = g_type_register_static (VALA_TYPE_LITERAL, "ValaBooleanLiteral", &g_define_type_info, 0);
225 	ValaBooleanLiteral_private_offset = g_type_add_instance_private (vala_boolean_literal_type_id, sizeof (ValaBooleanLiteralPrivate));
226 	return vala_boolean_literal_type_id;
227 }
228 
229 GType
vala_boolean_literal_get_type(void)230 vala_boolean_literal_get_type (void)
231 {
232 	static volatile gsize vala_boolean_literal_type_id__volatile = 0;
233 	if (g_once_init_enter (&vala_boolean_literal_type_id__volatile)) {
234 		GType vala_boolean_literal_type_id;
235 		vala_boolean_literal_type_id = vala_boolean_literal_get_type_once ();
236 		g_once_init_leave (&vala_boolean_literal_type_id__volatile, vala_boolean_literal_type_id);
237 	}
238 	return vala_boolean_literal_type_id__volatile;
239 }
240 
241