1 /* valaccodetypedefinition.c generated by valac, the Vala compiler
2 * generated from valaccodetypedefinition.vala, do not modify */
3
4 /* valaccodetypedefinition.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 <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 _ValaCCodeTypeDefinitionPrivate {
35 gchar* _type_name;
36 ValaCCodeDeclarator* _declarator;
37 };
38
39 static gint ValaCCodeTypeDefinition_private_offset;
40 static gpointer vala_ccode_type_definition_parent_class = NULL;
41
42 static void vala_ccode_type_definition_real_write (ValaCCodeNode* base,
43 ValaCCodeWriter* writer);
44 static void vala_ccode_type_definition_real_write_declaration (ValaCCodeNode* base,
45 ValaCCodeWriter* writer);
46 static void vala_ccode_type_definition_finalize (ValaCCodeNode * obj);
47 static GType vala_ccode_type_definition_get_type_once (void);
48
49 static inline gpointer
vala_ccode_type_definition_get_instance_private(ValaCCodeTypeDefinition * self)50 vala_ccode_type_definition_get_instance_private (ValaCCodeTypeDefinition* self)
51 {
52 return G_STRUCT_MEMBER_P (self, ValaCCodeTypeDefinition_private_offset);
53 }
54
55 const gchar*
vala_ccode_type_definition_get_type_name(ValaCCodeTypeDefinition * self)56 vala_ccode_type_definition_get_type_name (ValaCCodeTypeDefinition* self)
57 {
58 const gchar* result;
59 const gchar* _tmp0_;
60 g_return_val_if_fail (self != NULL, NULL);
61 _tmp0_ = self->priv->_type_name;
62 result = _tmp0_;
63 return result;
64 }
65
66 void
vala_ccode_type_definition_set_type_name(ValaCCodeTypeDefinition * self,const gchar * value)67 vala_ccode_type_definition_set_type_name (ValaCCodeTypeDefinition* self,
68 const gchar* value)
69 {
70 gchar* _tmp0_;
71 g_return_if_fail (self != NULL);
72 _tmp0_ = g_strdup (value);
73 _g_free0 (self->priv->_type_name);
74 self->priv->_type_name = _tmp0_;
75 }
76
77 ValaCCodeDeclarator*
vala_ccode_type_definition_get_declarator(ValaCCodeTypeDefinition * self)78 vala_ccode_type_definition_get_declarator (ValaCCodeTypeDefinition* self)
79 {
80 ValaCCodeDeclarator* result;
81 ValaCCodeDeclarator* _tmp0_;
82 g_return_val_if_fail (self != NULL, NULL);
83 _tmp0_ = self->priv->_declarator;
84 result = _tmp0_;
85 return result;
86 }
87
88 static gpointer
_vala_ccode_node_ref0(gpointer self)89 _vala_ccode_node_ref0 (gpointer self)
90 {
91 return self ? vala_ccode_node_ref (self) : NULL;
92 }
93
94 void
vala_ccode_type_definition_set_declarator(ValaCCodeTypeDefinition * self,ValaCCodeDeclarator * value)95 vala_ccode_type_definition_set_declarator (ValaCCodeTypeDefinition* self,
96 ValaCCodeDeclarator* value)
97 {
98 ValaCCodeDeclarator* _tmp0_;
99 g_return_if_fail (self != NULL);
100 _tmp0_ = _vala_ccode_node_ref0 (value);
101 _vala_ccode_node_unref0 (self->priv->_declarator);
102 self->priv->_declarator = _tmp0_;
103 }
104
105 ValaCCodeTypeDefinition*
vala_ccode_type_definition_construct(GType object_type,const gchar * type,ValaCCodeDeclarator * decl)106 vala_ccode_type_definition_construct (GType object_type,
107 const gchar* type,
108 ValaCCodeDeclarator* decl)
109 {
110 ValaCCodeTypeDefinition* self = NULL;
111 g_return_val_if_fail (type != NULL, NULL);
112 g_return_val_if_fail (decl != NULL, NULL);
113 self = (ValaCCodeTypeDefinition*) vala_ccode_node_construct (object_type);
114 vala_ccode_type_definition_set_type_name (self, type);
115 vala_ccode_type_definition_set_declarator (self, decl);
116 return self;
117 }
118
119 ValaCCodeTypeDefinition*
vala_ccode_type_definition_new(const gchar * type,ValaCCodeDeclarator * decl)120 vala_ccode_type_definition_new (const gchar* type,
121 ValaCCodeDeclarator* decl)
122 {
123 return vala_ccode_type_definition_construct (VALA_TYPE_CCODE_TYPE_DEFINITION, type, decl);
124 }
125
126 static void
vala_ccode_type_definition_real_write(ValaCCodeNode * base,ValaCCodeWriter * writer)127 vala_ccode_type_definition_real_write (ValaCCodeNode* base,
128 ValaCCodeWriter* writer)
129 {
130 ValaCCodeTypeDefinition * self;
131 self = (ValaCCodeTypeDefinition*) base;
132 g_return_if_fail (writer != NULL);
133 }
134
135 static void
vala_ccode_type_definition_real_write_declaration(ValaCCodeNode * base,ValaCCodeWriter * writer)136 vala_ccode_type_definition_real_write_declaration (ValaCCodeNode* base,
137 ValaCCodeWriter* writer)
138 {
139 ValaCCodeTypeDefinition * self;
140 const gchar* _tmp0_;
141 ValaCCodeDeclarator* _tmp1_;
142 ValaCCodeModifiers _tmp2_;
143 ValaCCodeModifiers _tmp3_;
144 self = (ValaCCodeTypeDefinition*) base;
145 g_return_if_fail (writer != NULL);
146 vala_ccode_writer_write_indent (writer, NULL);
147 vala_ccode_writer_write_string (writer, "typedef ");
148 _tmp0_ = self->priv->_type_name;
149 vala_ccode_writer_write_string (writer, _tmp0_);
150 vala_ccode_writer_write_string (writer, " ");
151 _tmp1_ = self->priv->_declarator;
152 vala_ccode_node_write_declaration ((ValaCCodeNode*) _tmp1_, writer);
153 _tmp2_ = vala_ccode_node_get_modifiers ((ValaCCodeNode*) self);
154 _tmp3_ = _tmp2_;
155 if ((_tmp3_ & VALA_CCODE_MODIFIERS_DEPRECATED) == VALA_CCODE_MODIFIERS_DEPRECATED) {
156 vala_ccode_writer_write_string (writer, " G_GNUC_DEPRECATED");
157 }
158 vala_ccode_writer_write_string (writer, ";");
159 vala_ccode_writer_write_newline (writer);
160 }
161
162 static void
vala_ccode_type_definition_class_init(ValaCCodeTypeDefinitionClass * klass,gpointer klass_data)163 vala_ccode_type_definition_class_init (ValaCCodeTypeDefinitionClass * klass,
164 gpointer klass_data)
165 {
166 vala_ccode_type_definition_parent_class = g_type_class_peek_parent (klass);
167 ((ValaCCodeNodeClass *) klass)->finalize = vala_ccode_type_definition_finalize;
168 g_type_class_adjust_private_offset (klass, &ValaCCodeTypeDefinition_private_offset);
169 ((ValaCCodeNodeClass *) klass)->write = (void (*) (ValaCCodeNode*, ValaCCodeWriter*)) vala_ccode_type_definition_real_write;
170 ((ValaCCodeNodeClass *) klass)->write_declaration = (void (*) (ValaCCodeNode*, ValaCCodeWriter*)) vala_ccode_type_definition_real_write_declaration;
171 }
172
173 static void
vala_ccode_type_definition_instance_init(ValaCCodeTypeDefinition * self,gpointer klass)174 vala_ccode_type_definition_instance_init (ValaCCodeTypeDefinition * self,
175 gpointer klass)
176 {
177 self->priv = vala_ccode_type_definition_get_instance_private (self);
178 }
179
180 static void
vala_ccode_type_definition_finalize(ValaCCodeNode * obj)181 vala_ccode_type_definition_finalize (ValaCCodeNode * obj)
182 {
183 ValaCCodeTypeDefinition * self;
184 self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_CCODE_TYPE_DEFINITION, ValaCCodeTypeDefinition);
185 _g_free0 (self->priv->_type_name);
186 _vala_ccode_node_unref0 (self->priv->_declarator);
187 VALA_CCODE_NODE_CLASS (vala_ccode_type_definition_parent_class)->finalize (obj);
188 }
189
190 /**
191 * Represents a typedef in the C code.
192 */
193 static GType
vala_ccode_type_definition_get_type_once(void)194 vala_ccode_type_definition_get_type_once (void)
195 {
196 static const GTypeInfo g_define_type_info = { sizeof (ValaCCodeTypeDefinitionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_ccode_type_definition_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaCCodeTypeDefinition), 0, (GInstanceInitFunc) vala_ccode_type_definition_instance_init, NULL };
197 GType vala_ccode_type_definition_type_id;
198 vala_ccode_type_definition_type_id = g_type_register_static (VALA_TYPE_CCODE_NODE, "ValaCCodeTypeDefinition", &g_define_type_info, 0);
199 ValaCCodeTypeDefinition_private_offset = g_type_add_instance_private (vala_ccode_type_definition_type_id, sizeof (ValaCCodeTypeDefinitionPrivate));
200 return vala_ccode_type_definition_type_id;
201 }
202
203 GType
vala_ccode_type_definition_get_type(void)204 vala_ccode_type_definition_get_type (void)
205 {
206 static volatile gsize vala_ccode_type_definition_type_id__volatile = 0;
207 if (g_once_init_enter (&vala_ccode_type_definition_type_id__volatile)) {
208 GType vala_ccode_type_definition_type_id;
209 vala_ccode_type_definition_type_id = vala_ccode_type_definition_get_type_once ();
210 g_once_init_leave (&vala_ccode_type_definition_type_id__volatile, vala_ccode_type_definition_type_id);
211 }
212 return vala_ccode_type_definition_type_id__volatile;
213 }
214
215