1 /* valaccodeenumvalue.c generated by valac, the Vala compiler
2  * generated from valaccodeenumvalue.vala, do not modify */
3 
4 /* valaccodeenumvalue.vala
5  *
6  * Copyright (C) 2007-2008  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 <stdlib.h>
28 #include <string.h>
29 #include <glib.h>
30 
31 #define _g_free0(var) (var = (g_free (var), NULL))
32 #define _vala_ccode_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_ccode_node_unref (var), NULL)))
33 
34 struct _ValaCCodeEnumValuePrivate {
35 	gchar* _name;
36 	ValaCCodeExpression* _value;
37 };
38 
39 static gint ValaCCodeEnumValue_private_offset;
40 static gpointer vala_ccode_enum_value_parent_class = NULL;
41 
42 static void vala_ccode_enum_value_real_write (ValaCCodeNode* base,
43                                        ValaCCodeWriter* writer);
44 static void vala_ccode_enum_value_finalize (ValaCCodeNode * obj);
45 static GType vala_ccode_enum_value_get_type_once (void);
46 
47 static inline gpointer
vala_ccode_enum_value_get_instance_private(ValaCCodeEnumValue * self)48 vala_ccode_enum_value_get_instance_private (ValaCCodeEnumValue* self)
49 {
50 	return G_STRUCT_MEMBER_P (self, ValaCCodeEnumValue_private_offset);
51 }
52 
53 const gchar*
vala_ccode_enum_value_get_name(ValaCCodeEnumValue * self)54 vala_ccode_enum_value_get_name (ValaCCodeEnumValue* self)
55 {
56 	const gchar* result;
57 	const gchar* _tmp0_;
58 	g_return_val_if_fail (self != NULL, NULL);
59 	_tmp0_ = self->priv->_name;
60 	result = _tmp0_;
61 	return result;
62 }
63 
64 void
vala_ccode_enum_value_set_name(ValaCCodeEnumValue * self,const gchar * value)65 vala_ccode_enum_value_set_name (ValaCCodeEnumValue* self,
66                                 const gchar* value)
67 {
68 	gchar* _tmp0_;
69 	g_return_if_fail (self != NULL);
70 	_tmp0_ = g_strdup (value);
71 	_g_free0 (self->priv->_name);
72 	self->priv->_name = _tmp0_;
73 }
74 
75 ValaCCodeExpression*
vala_ccode_enum_value_get_value(ValaCCodeEnumValue * self)76 vala_ccode_enum_value_get_value (ValaCCodeEnumValue* self)
77 {
78 	ValaCCodeExpression* result;
79 	ValaCCodeExpression* _tmp0_;
80 	g_return_val_if_fail (self != NULL, NULL);
81 	_tmp0_ = self->priv->_value;
82 	result = _tmp0_;
83 	return result;
84 }
85 
86 static gpointer
_vala_ccode_node_ref0(gpointer self)87 _vala_ccode_node_ref0 (gpointer self)
88 {
89 	return self ? vala_ccode_node_ref (self) : NULL;
90 }
91 
92 void
vala_ccode_enum_value_set_value(ValaCCodeEnumValue * self,ValaCCodeExpression * value)93 vala_ccode_enum_value_set_value (ValaCCodeEnumValue* self,
94                                  ValaCCodeExpression* value)
95 {
96 	ValaCCodeExpression* _tmp0_;
97 	g_return_if_fail (self != NULL);
98 	_tmp0_ = _vala_ccode_node_ref0 (value);
99 	_vala_ccode_node_unref0 (self->priv->_value);
100 	self->priv->_value = _tmp0_;
101 }
102 
103 ValaCCodeEnumValue*
vala_ccode_enum_value_construct(GType object_type,const gchar * name,ValaCCodeExpression * value)104 vala_ccode_enum_value_construct (GType object_type,
105                                  const gchar* name,
106                                  ValaCCodeExpression* value)
107 {
108 	ValaCCodeEnumValue* self = NULL;
109 	g_return_val_if_fail (name != NULL, NULL);
110 	self = (ValaCCodeEnumValue*) vala_ccode_node_construct (object_type);
111 	vala_ccode_enum_value_set_name (self, name);
112 	vala_ccode_enum_value_set_value (self, value);
113 	return self;
114 }
115 
116 ValaCCodeEnumValue*
vala_ccode_enum_value_new(const gchar * name,ValaCCodeExpression * value)117 vala_ccode_enum_value_new (const gchar* name,
118                            ValaCCodeExpression* value)
119 {
120 	return vala_ccode_enum_value_construct (VALA_TYPE_CCODE_ENUM_VALUE, name, value);
121 }
122 
123 static void
vala_ccode_enum_value_real_write(ValaCCodeNode * base,ValaCCodeWriter * writer)124 vala_ccode_enum_value_real_write (ValaCCodeNode* base,
125                                   ValaCCodeWriter* writer)
126 {
127 	ValaCCodeEnumValue * self;
128 	const gchar* _tmp0_;
129 	ValaCCodeModifiers _tmp1_;
130 	ValaCCodeModifiers _tmp2_;
131 	ValaCCodeExpression* _tmp3_;
132 	self = (ValaCCodeEnumValue*) base;
133 	g_return_if_fail (writer != NULL);
134 	_tmp0_ = self->priv->_name;
135 	vala_ccode_writer_write_string (writer, _tmp0_);
136 	_tmp1_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
137 	_tmp2_ = _tmp1_;
138 	if ((_tmp2_ & VALA_CCODE_MODIFIERS_DEPRECATED) == VALA_CCODE_MODIFIERS_DEPRECATED) {
139 	}
140 	_tmp3_ = self->priv->_value;
141 	if (_tmp3_ != NULL) {
142 		ValaCCodeExpression* _tmp4_;
143 		vala_ccode_writer_write_string (writer, " = ");
144 		_tmp4_ = self->priv->_value;
145 		vala_ccode_node_write ((ValaCCodeNode*) _tmp4_, writer);
146 	}
147 }
148 
149 static void
vala_ccode_enum_value_class_init(ValaCCodeEnumValueClass * klass,gpointer klass_data)150 vala_ccode_enum_value_class_init (ValaCCodeEnumValueClass * klass,
151                                   gpointer klass_data)
152 {
153 	vala_ccode_enum_value_parent_class = g_type_class_peek_parent (klass);
154 	((ValaCCodeNodeClass *) klass)->finalize = vala_ccode_enum_value_finalize;
155 	g_type_class_adjust_private_offset (klass, &ValaCCodeEnumValue_private_offset);
156 	((ValaCCodeNodeClass *) klass)->write = (void (*) (ValaCCodeNode*, ValaCCodeWriter*)) vala_ccode_enum_value_real_write;
157 }
158 
159 static void
vala_ccode_enum_value_instance_init(ValaCCodeEnumValue * self,gpointer klass)160 vala_ccode_enum_value_instance_init (ValaCCodeEnumValue * self,
161                                      gpointer klass)
162 {
163 	self->priv = vala_ccode_enum_value_get_instance_private (self);
164 }
165 
166 static void
vala_ccode_enum_value_finalize(ValaCCodeNode * obj)167 vala_ccode_enum_value_finalize (ValaCCodeNode * obj)
168 {
169 	ValaCCodeEnumValue * self;
170 	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_CCODE_ENUM_VALUE, ValaCCodeEnumValue);
171 	_g_free0 (self->priv->_name);
172 	_vala_ccode_node_unref0 (self->priv->_value);
173 	VALA_CCODE_NODE_CLASS (vala_ccode_enum_value_parent_class)->finalize (obj);
174 }
175 
176 /**
177  * Represents an enum value in the C code.
178  */
179 static GType
vala_ccode_enum_value_get_type_once(void)180 vala_ccode_enum_value_get_type_once (void)
181 {
182 	static const GTypeInfo g_define_type_info = { sizeof (ValaCCodeEnumValueClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_ccode_enum_value_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaCCodeEnumValue), 0, (GInstanceInitFunc) vala_ccode_enum_value_instance_init, NULL };
183 	GType vala_ccode_enum_value_type_id;
184 	vala_ccode_enum_value_type_id = g_type_register_static (VALA_TYPE_CCODE_NODE, "ValaCCodeEnumValue", &g_define_type_info, 0);
185 	ValaCCodeEnumValue_private_offset = g_type_add_instance_private (vala_ccode_enum_value_type_id, sizeof (ValaCCodeEnumValuePrivate));
186 	return vala_ccode_enum_value_type_id;
187 }
188 
189 GType
vala_ccode_enum_value_get_type(void)190 vala_ccode_enum_value_get_type (void)
191 {
192 	static volatile gsize vala_ccode_enum_value_type_id__volatile = 0;
193 	if (g_once_init_enter (&vala_ccode_enum_value_type_id__volatile)) {
194 		GType vala_ccode_enum_value_type_id;
195 		vala_ccode_enum_value_type_id = vala_ccode_enum_value_get_type_once ();
196 		g_once_init_leave (&vala_ccode_enum_value_type_id__volatile, vala_ccode_enum_value_type_id);
197 	}
198 	return vala_ccode_enum_value_type_id__volatile;
199 }
200 
201