1 /* valanullliteral.c generated by valac, the Vala compiler
2  * generated from valanullliteral.vala, do not modify */
3 
4 /* valanullliteral.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 <stdlib.h>
28 #include <string.h>
29 #include <glib.h>
30 
31 #define _vala_code_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_node_unref (var), NULL)))
32 
33 static gpointer vala_null_literal_parent_class = NULL;
34 
35 static void vala_null_literal_real_accept (ValaCodeNode* base,
36                                     ValaCodeVisitor* visitor);
37 static gchar* vala_null_literal_real_to_string (ValaCodeNode* base);
38 static gboolean vala_null_literal_real_is_pure (ValaExpression* base);
39 static gboolean vala_null_literal_real_check (ValaCodeNode* base,
40                                        ValaCodeContext* context);
41 static void vala_null_literal_real_emit (ValaCodeNode* base,
42                                   ValaCodeGenerator* codegen);
43 static GType vala_null_literal_get_type_once (void);
44 
45 /**
46  * Creates a new null literal.
47  *
48  * @param source reference to source code
49  * @return       newly created null literal
50  */
51 ValaNullLiteral*
vala_null_literal_construct(GType object_type,ValaSourceReference * source)52 vala_null_literal_construct (GType object_type,
53                              ValaSourceReference* source)
54 {
55 	ValaNullLiteral* self = NULL;
56 	self = (ValaNullLiteral*) vala_literal_construct (object_type);
57 	vala_code_node_set_source_reference ((ValaCodeNode*) self, source);
58 	return self;
59 }
60 
61 ValaNullLiteral*
vala_null_literal_new(ValaSourceReference * source)62 vala_null_literal_new (ValaSourceReference* source)
63 {
64 	return vala_null_literal_construct (VALA_TYPE_NULL_LITERAL, source);
65 }
66 
67 static void
vala_null_literal_real_accept(ValaCodeNode * base,ValaCodeVisitor * visitor)68 vala_null_literal_real_accept (ValaCodeNode* base,
69                                ValaCodeVisitor* visitor)
70 {
71 	ValaNullLiteral * self;
72 	self = (ValaNullLiteral*) base;
73 	g_return_if_fail (visitor != NULL);
74 	vala_code_visitor_visit_null_literal (visitor, self);
75 	vala_code_visitor_visit_expression (visitor, (ValaExpression*) self);
76 }
77 
78 static gchar*
vala_null_literal_real_to_string(ValaCodeNode * base)79 vala_null_literal_real_to_string (ValaCodeNode* base)
80 {
81 	ValaNullLiteral * self;
82 	gchar* _tmp0_;
83 	gchar* result = NULL;
84 	self = (ValaNullLiteral*) base;
85 	_tmp0_ = g_strdup ("null");
86 	result = _tmp0_;
87 	return result;
88 }
89 
90 static gboolean
vala_null_literal_real_is_pure(ValaExpression * base)91 vala_null_literal_real_is_pure (ValaExpression* base)
92 {
93 	ValaNullLiteral * self;
94 	gboolean result = FALSE;
95 	self = (ValaNullLiteral*) base;
96 	result = TRUE;
97 	return result;
98 }
99 
100 static gboolean
vala_null_literal_real_check(ValaCodeNode * base,ValaCodeContext * context)101 vala_null_literal_real_check (ValaCodeNode* base,
102                               ValaCodeContext* context)
103 {
104 	ValaNullLiteral * self;
105 	gboolean _tmp0_;
106 	gboolean _tmp1_;
107 	ValaSourceReference* _tmp4_;
108 	ValaSourceReference* _tmp5_;
109 	ValaNullType* _tmp6_;
110 	ValaNullType* _tmp7_;
111 	gboolean _tmp8_;
112 	gboolean _tmp9_;
113 	gboolean result = FALSE;
114 	self = (ValaNullLiteral*) base;
115 	g_return_val_if_fail (context != NULL, FALSE);
116 	_tmp0_ = vala_code_node_get_checked ((ValaCodeNode*) self);
117 	_tmp1_ = _tmp0_;
118 	if (_tmp1_) {
119 		gboolean _tmp2_;
120 		gboolean _tmp3_;
121 		_tmp2_ = vala_code_node_get_error ((ValaCodeNode*) self);
122 		_tmp3_ = _tmp2_;
123 		result = !_tmp3_;
124 		return result;
125 	}
126 	vala_code_node_set_checked ((ValaCodeNode*) self, TRUE);
127 	_tmp4_ = vala_code_node_get_source_reference ((ValaCodeNode*) self);
128 	_tmp5_ = _tmp4_;
129 	_tmp6_ = vala_null_type_new (_tmp5_);
130 	_tmp7_ = _tmp6_;
131 	vala_expression_set_value_type ((ValaExpression*) self, (ValaDataType*) _tmp7_);
132 	_vala_code_node_unref0 (_tmp7_);
133 	_tmp8_ = vala_code_node_get_error ((ValaCodeNode*) self);
134 	_tmp9_ = _tmp8_;
135 	result = !_tmp9_;
136 	return result;
137 }
138 
139 static void
vala_null_literal_real_emit(ValaCodeNode * base,ValaCodeGenerator * codegen)140 vala_null_literal_real_emit (ValaCodeNode* base,
141                              ValaCodeGenerator* codegen)
142 {
143 	ValaNullLiteral * self;
144 	self = (ValaNullLiteral*) base;
145 	g_return_if_fail (codegen != NULL);
146 	vala_code_visitor_visit_null_literal ((ValaCodeVisitor*) codegen, self);
147 	vala_code_visitor_visit_expression ((ValaCodeVisitor*) codegen, (ValaExpression*) self);
148 }
149 
150 static void
vala_null_literal_class_init(ValaNullLiteralClass * klass,gpointer klass_data)151 vala_null_literal_class_init (ValaNullLiteralClass * klass,
152                               gpointer klass_data)
153 {
154 	vala_null_literal_parent_class = g_type_class_peek_parent (klass);
155 	((ValaCodeNodeClass *) klass)->accept = (void (*) (ValaCodeNode*, ValaCodeVisitor*)) vala_null_literal_real_accept;
156 	((ValaCodeNodeClass *) klass)->to_string = (gchar* (*) (ValaCodeNode*)) vala_null_literal_real_to_string;
157 	((ValaExpressionClass *) klass)->is_pure = (gboolean (*) (ValaExpression*)) vala_null_literal_real_is_pure;
158 	((ValaCodeNodeClass *) klass)->check = (gboolean (*) (ValaCodeNode*, ValaCodeContext*)) vala_null_literal_real_check;
159 	((ValaCodeNodeClass *) klass)->emit = (void (*) (ValaCodeNode*, ValaCodeGenerator*)) vala_null_literal_real_emit;
160 }
161 
162 static void
vala_null_literal_instance_init(ValaNullLiteral * self,gpointer klass)163 vala_null_literal_instance_init (ValaNullLiteral * self,
164                                  gpointer klass)
165 {
166 }
167 
168 /**
169  * Represents a literal `null` in the source code.
170  */
171 static GType
vala_null_literal_get_type_once(void)172 vala_null_literal_get_type_once (void)
173 {
174 	static const GTypeInfo g_define_type_info = { sizeof (ValaNullLiteralClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_null_literal_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaNullLiteral), 0, (GInstanceInitFunc) vala_null_literal_instance_init, NULL };
175 	GType vala_null_literal_type_id;
176 	vala_null_literal_type_id = g_type_register_static (VALA_TYPE_LITERAL, "ValaNullLiteral", &g_define_type_info, 0);
177 	return vala_null_literal_type_id;
178 }
179 
180 GType
vala_null_literal_get_type(void)181 vala_null_literal_get_type (void)
182 {
183 	static volatile gsize vala_null_literal_type_id__volatile = 0;
184 	if (g_once_init_enter (&vala_null_literal_type_id__volatile)) {
185 		GType vala_null_literal_type_id;
186 		vala_null_literal_type_id = vala_null_literal_get_type_once ();
187 		g_once_init_leave (&vala_null_literal_type_id__volatile, vala_null_literal_type_id);
188 	}
189 	return vala_null_literal_type_id__volatile;
190 }
191 
192