71
68
* @param type_name field type
72
69
* @param name member name
74
void vala_ccode_struct_add_field (ValaCCodeStruct* self, const char* type_name, const char* name)
71
void vala_ccode_struct_add_field (ValaCCodeStruct* self, const char* type_name, const char* name) {
76
72
ValaCCodeDeclaration* decl;
77
ValaCCodeVariableDeclarator* __temp0;
73
ValaCCodeVariableDeclarator* _tmp0;
78
74
g_return_if_fail (VALA_IS_CCODE_STRUCT (self));
79
75
g_return_if_fail (type_name != NULL);
80
76
g_return_if_fail (name != NULL);
81
77
decl = vala_ccode_declaration_new (type_name);
83
vala_ccode_declaration_add_declarator (decl, VALA_CCODE_DECLARATOR ((__temp0 = vala_ccode_variable_declarator_new (name))));
84
(__temp0 == NULL ? NULL : (__temp0 = (g_object_unref (__temp0), NULL)));
79
vala_ccode_declaration_add_declarator (decl, VALA_CCODE_DECLARATOR ((_tmp0 = vala_ccode_variable_declarator_new (name))));
80
(_tmp0 == NULL ? NULL : (_tmp0 = (g_object_unref (_tmp0), NULL)));
85
81
vala_ccode_struct_add_declaration (self, decl);
86
82
(decl == NULL ? NULL : (decl = (g_object_unref (decl), NULL)));
90
static void vala_ccode_struct_real_write (ValaCCodeNode* base, ValaCCodeWriter* writer)
86
static void vala_ccode_struct_real_write (ValaCCodeNode* base, ValaCCodeWriter* writer) {
92
87
ValaCCodeStruct * self;
93
self = ((ValaCCodeStruct*) base);
88
self = VALA_CCODE_STRUCT (base);
94
89
g_return_if_fail (VALA_IS_CCODE_WRITER (writer));
95
90
vala_ccode_writer_write_string (writer, "struct ");
96
91
vala_ccode_writer_write_string (writer, vala_ccode_struct_get_name (self));
119
char* vala_ccode_struct_get_name (ValaCCodeStruct* self)
114
char* vala_ccode_struct_get_name (ValaCCodeStruct* self) {
121
115
g_return_val_if_fail (VALA_IS_CCODE_STRUCT (self), NULL);
122
116
return self->priv->_name;
126
void vala_ccode_struct_set_name (ValaCCodeStruct* self, const char* value)
120
void vala_ccode_struct_set_name (ValaCCodeStruct* self, const char* value) {
129
122
g_return_if_fail (VALA_IS_CCODE_STRUCT (self));
131
self->priv->_name = (__temp2 = g_strdup (value), (self->priv->_name = (g_free (self->priv->_name), NULL)), __temp2);
124
self->priv->_name = (_tmp1 = g_strdup (value), (self->priv->_name = (g_free (self->priv->_name), NULL)), _tmp1);
135
static void vala_ccode_struct_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec)
128
static void vala_ccode_struct_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
137
129
ValaCCodeStruct * self;
138
130
self = VALA_CCODE_STRUCT (object);
139
131
switch (property_id) {
140
132
case VALA_CCODE_STRUCT_NAME:
141
133
g_value_set_string (value, vala_ccode_struct_get_name (self));
136
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
147
static void vala_ccode_struct_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec)
142
static void vala_ccode_struct_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
149
143
ValaCCodeStruct * self;
150
144
self = VALA_CCODE_STRUCT (object);
151
145
switch (property_id) {
152
146
case VALA_CCODE_STRUCT_NAME:
153
147
vala_ccode_struct_set_name (self, g_value_get_string (value));
150
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
159
static void vala_ccode_struct_class_init (ValaCCodeStructClass * klass)
156
static void vala_ccode_struct_class_init (ValaCCodeStructClass * klass) {
161
157
vala_ccode_struct_parent_class = g_type_class_peek_parent (klass);
162
158
g_type_class_add_private (klass, sizeof (ValaCCodeStructPrivate));
163
159
G_OBJECT_CLASS (klass)->get_property = vala_ccode_struct_get_property;
164
160
G_OBJECT_CLASS (klass)->set_property = vala_ccode_struct_set_property;
165
161
G_OBJECT_CLASS (klass)->dispose = vala_ccode_struct_dispose;
166
162
VALA_CCODE_NODE_CLASS (klass)->write = vala_ccode_struct_real_write;
167
g_object_class_install_property (G_OBJECT_CLASS (klass), VALA_CCODE_STRUCT_NAME, g_param_spec_string ("name", "foo", "bar", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
163
g_object_class_install_property (G_OBJECT_CLASS (klass), VALA_CCODE_STRUCT_NAME, g_param_spec_string ("name", "name", "name", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
171
static void vala_ccode_struct_init (ValaCCodeStruct * self)
167
static void vala_ccode_struct_init (ValaCCodeStruct * self) {
173
168
self->priv = VALA_CCODE_STRUCT_GET_PRIVATE (self);
174
169
self->priv->declarations = GEE_LIST (gee_array_list_new (g_object_ref, g_object_unref, g_direct_equal));
178
static void vala_ccode_struct_dispose (GObject * obj)
173
static void vala_ccode_struct_dispose (GObject * obj) {
180
174
ValaCCodeStruct * self;
181
ValaCCodeStructClass * klass;
182
GObjectClass * parent_class;
183
175
self = VALA_CCODE_STRUCT (obj);
184
176
(self->priv->_name = (g_free (self->priv->_name), NULL));
185
177
(self->priv->declarations == NULL ? NULL : (self->priv->declarations = (g_object_unref (self->priv->declarations), NULL)));
186
klass = VALA_CCODE_STRUCT_CLASS (g_type_class_peek (VALA_TYPE_CCODE_STRUCT));
187
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
188
parent_class->dispose (obj);
178
G_OBJECT_CLASS (vala_ccode_struct_parent_class)->dispose (obj);
192
GType vala_ccode_struct_get_type (void)
182
GType vala_ccode_struct_get_type (void) {
194
183
static GType vala_ccode_struct_type_id = 0;
195
184
if (G_UNLIKELY (vala_ccode_struct_type_id == 0)) {
196
185
static const GTypeInfo g_define_type_info = { sizeof (ValaCCodeStructClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_ccode_struct_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaCCodeStruct), 0, (GInstanceInitFunc) vala_ccode_struct_init };