5
5
* This library is free software; you can redistribute it and/or
6
6
* modify it under the terms of the GNU Lesser General Public
7
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
8
* version 2.1 of the License, or (at your option) any later version.
10
10
* This library is distributed in the hope that it will be useful,
11
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
20
* Jürg Billeter <j@bitron.ch>
23
#include "valaswitchstatement.h"
23
#include <vala/valaswitchstatement.h>
24
24
#include <gee/arraylist.h>
25
25
#include <gee/list.h>
26
26
#include <gee/readonlycollection.h>
27
27
#include <vala/valaexpression.h>
28
28
#include <vala/valasourcereference.h>
29
#include <vala/valaswitchstatement.h>
30
29
#include <vala/valaswitchsection.h>
31
30
#include <vala/valacodevisitor.h>
53
52
* @param source_reference reference to source code
54
53
* @return newly created switch statement
56
ValaSwitchStatement* vala_switch_statement_new (ValaExpression* expression, ValaSourceReference* source_reference)
55
ValaSwitchStatement* vala_switch_statement_new (ValaExpression* expression, ValaSourceReference* source_reference) {
58
56
GParameter * __params;
59
57
GParameter * __params_it;
60
58
ValaSwitchStatement * self;
80
78
* @param section a switch section
82
void vala_switch_statement_add_section (ValaSwitchStatement* self, ValaSwitchSection* section)
80
void vala_switch_statement_add_section (ValaSwitchStatement* self, ValaSwitchSection* section) {
84
81
g_return_if_fail (VALA_IS_SWITCH_STATEMENT (self));
85
82
g_return_if_fail (VALA_IS_SWITCH_SECTION (section));
83
vala_code_node_set_parent_node (VALA_CODE_NODE (section), VALA_CODE_NODE (self));
86
84
gee_collection_add (GEE_COLLECTION (self->priv->sections), section);
93
91
* @return section list
95
GeeCollection* vala_switch_statement_get_sections (ValaSwitchStatement* self)
93
GeeCollection* vala_switch_statement_get_sections (ValaSwitchStatement* self) {
97
94
g_return_val_if_fail (VALA_IS_SWITCH_STATEMENT (self), NULL);
98
95
return GEE_COLLECTION (gee_read_only_collection_new (g_object_ref, g_object_unref, GEE_COLLECTION (self->priv->sections)));
102
static void vala_switch_statement_real_accept (ValaCodeNode* base, ValaCodeVisitor* visitor)
99
static void vala_switch_statement_real_accept (ValaCodeNode* base, ValaCodeVisitor* visitor) {
104
100
ValaSwitchStatement * self;
105
self = ((ValaSwitchStatement*) base);
101
self = VALA_SWITCH_STATEMENT (base);
106
102
g_return_if_fail (VALA_IS_CODE_VISITOR (visitor));
107
103
vala_code_node_accept (VALA_CODE_NODE (vala_switch_statement_get_expression (self)), visitor);
108
104
vala_code_visitor_visit_end_full_expression (visitor, vala_switch_statement_get_expression (self));
128
static void vala_switch_statement_real_replace (ValaCodeNode* base, ValaCodeNode* old_node, ValaCodeNode* new_node)
124
static void vala_switch_statement_real_replace (ValaCodeNode* base, ValaCodeNode* old_node, ValaCodeNode* new_node) {
130
125
ValaSwitchStatement * self;
131
self = ((ValaSwitchStatement*) base);
126
self = VALA_SWITCH_STATEMENT (base);
132
127
g_return_if_fail (VALA_IS_CODE_NODE (old_node));
133
128
g_return_if_fail (VALA_IS_CODE_NODE (new_node));
134
129
if (VALA_CODE_NODE (vala_switch_statement_get_expression (self)) == old_node) {
140
ValaExpression* vala_switch_statement_get_expression (ValaSwitchStatement* self)
135
ValaExpression* vala_switch_statement_get_expression (ValaSwitchStatement* self) {
142
136
g_return_val_if_fail (VALA_IS_SWITCH_STATEMENT (self), NULL);
143
137
return self->priv->_expression;
147
void vala_switch_statement_set_expression (ValaSwitchStatement* self, ValaExpression* value)
149
ValaExpression* __temp2;
141
void vala_switch_statement_set_expression (ValaSwitchStatement* self, ValaExpression* value) {
142
ValaExpression* _tmp1;
150
143
g_return_if_fail (VALA_IS_SWITCH_STATEMENT (self));
152
self->priv->_expression = (__temp2 = g_object_ref (value), (self->priv->_expression == NULL ? NULL : (self->priv->_expression = (g_object_unref (self->priv->_expression), NULL))), __temp2);
145
self->priv->_expression = (_tmp1 = g_object_ref (value), (self->priv->_expression == NULL ? NULL : (self->priv->_expression = (g_object_unref (self->priv->_expression), NULL))), _tmp1);
153
146
vala_code_node_set_parent_node (VALA_CODE_NODE (self->priv->_expression), VALA_CODE_NODE (self));
157
static void vala_switch_statement_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec)
150
static void vala_switch_statement_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
159
151
ValaSwitchStatement * self;
160
152
self = VALA_SWITCH_STATEMENT (object);
161
153
switch (property_id) {
162
154
case VALA_SWITCH_STATEMENT_EXPRESSION:
163
155
g_value_set_object (value, vala_switch_statement_get_expression (self));
158
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
169
static void vala_switch_statement_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec)
164
static void vala_switch_statement_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
171
165
ValaSwitchStatement * self;
172
166
self = VALA_SWITCH_STATEMENT (object);
173
167
switch (property_id) {
174
168
case VALA_SWITCH_STATEMENT_EXPRESSION:
175
169
vala_switch_statement_set_expression (self, g_value_get_object (value));
172
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
181
static void vala_switch_statement_class_init (ValaSwitchStatementClass * klass)
178
static void vala_switch_statement_class_init (ValaSwitchStatementClass * klass) {
183
179
vala_switch_statement_parent_class = g_type_class_peek_parent (klass);
184
180
g_type_class_add_private (klass, sizeof (ValaSwitchStatementPrivate));
185
181
G_OBJECT_CLASS (klass)->get_property = vala_switch_statement_get_property;
187
183
G_OBJECT_CLASS (klass)->dispose = vala_switch_statement_dispose;
188
184
VALA_CODE_NODE_CLASS (klass)->accept = vala_switch_statement_real_accept;
189
185
VALA_CODE_NODE_CLASS (klass)->replace = vala_switch_statement_real_replace;
190
g_object_class_install_property (G_OBJECT_CLASS (klass), VALA_SWITCH_STATEMENT_EXPRESSION, g_param_spec_object ("expression", "foo", "bar", VALA_TYPE_EXPRESSION, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
186
g_object_class_install_property (G_OBJECT_CLASS (klass), VALA_SWITCH_STATEMENT_EXPRESSION, g_param_spec_object ("expression", "expression", "expression", VALA_TYPE_EXPRESSION, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
194
static void vala_switch_statement_vala_statement_interface_init (ValaStatementIface * iface)
190
static void vala_switch_statement_vala_statement_interface_init (ValaStatementIface * iface) {
196
191
vala_switch_statement_vala_statement_parent_iface = g_type_interface_peek_parent (iface);
200
static void vala_switch_statement_init (ValaSwitchStatement * self)
195
static void vala_switch_statement_init (ValaSwitchStatement * self) {
202
196
self->priv = VALA_SWITCH_STATEMENT_GET_PRIVATE (self);
203
197
self->priv->sections = GEE_LIST (gee_array_list_new (g_object_ref, g_object_unref, g_direct_equal));
207
static void vala_switch_statement_dispose (GObject * obj)
201
static void vala_switch_statement_dispose (GObject * obj) {
209
202
ValaSwitchStatement * self;
210
ValaSwitchStatementClass * klass;
211
GObjectClass * parent_class;
212
203
self = VALA_SWITCH_STATEMENT (obj);
213
204
(self->priv->_expression == NULL ? NULL : (self->priv->_expression = (g_object_unref (self->priv->_expression), NULL)));
214
205
(self->priv->sections == NULL ? NULL : (self->priv->sections = (g_object_unref (self->priv->sections), NULL)));
215
klass = VALA_SWITCH_STATEMENT_CLASS (g_type_class_peek (VALA_TYPE_SWITCH_STATEMENT));
216
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
217
parent_class->dispose (obj);
206
G_OBJECT_CLASS (vala_switch_statement_parent_class)->dispose (obj);
221
GType vala_switch_statement_get_type (void)
210
GType vala_switch_statement_get_type (void) {
223
211
static GType vala_switch_statement_type_id = 0;
224
212
if (G_UNLIKELY (vala_switch_statement_type_id == 0)) {
225
213
static const GTypeInfo g_define_type_info = { sizeof (ValaSwitchStatementClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_switch_statement_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaSwitchStatement), 0, (GInstanceInitFunc) vala_switch_statement_init };