1 /* valaccodecasestatement.c generated by valac, the Vala compiler
2 * generated from valaccodecasestatement.vala, do not modify */
3
4 /* valaccodecasestatement.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 <glib.h>
28
29 #define _vala_ccode_node_unref0(var) ((var == NULL) ? NULL : (var = (vala_ccode_node_unref (var), NULL)))
30
31 struct _ValaCCodeCaseStatementPrivate {
32 ValaCCodeExpression* _expression;
33 };
34
35 static gint ValaCCodeCaseStatement_private_offset;
36 static gpointer vala_ccode_case_statement_parent_class = NULL;
37
38 static void vala_ccode_case_statement_real_write (ValaCCodeNode* base,
39 ValaCCodeWriter* writer);
40 static void vala_ccode_case_statement_finalize (ValaCCodeNode * obj);
41 static GType vala_ccode_case_statement_get_type_once (void);
42
43 static inline gpointer
vala_ccode_case_statement_get_instance_private(ValaCCodeCaseStatement * self)44 vala_ccode_case_statement_get_instance_private (ValaCCodeCaseStatement* self)
45 {
46 return G_STRUCT_MEMBER_P (self, ValaCCodeCaseStatement_private_offset);
47 }
48
49 ValaCCodeExpression*
vala_ccode_case_statement_get_expression(ValaCCodeCaseStatement * self)50 vala_ccode_case_statement_get_expression (ValaCCodeCaseStatement* self)
51 {
52 ValaCCodeExpression* result;
53 ValaCCodeExpression* _tmp0_;
54 g_return_val_if_fail (self != NULL, NULL);
55 _tmp0_ = self->priv->_expression;
56 result = _tmp0_;
57 return result;
58 }
59
60 static gpointer
_vala_ccode_node_ref0(gpointer self)61 _vala_ccode_node_ref0 (gpointer self)
62 {
63 return self ? vala_ccode_node_ref (self) : NULL;
64 }
65
66 void
vala_ccode_case_statement_set_expression(ValaCCodeCaseStatement * self,ValaCCodeExpression * value)67 vala_ccode_case_statement_set_expression (ValaCCodeCaseStatement* self,
68 ValaCCodeExpression* value)
69 {
70 ValaCCodeExpression* _tmp0_;
71 g_return_if_fail (self != NULL);
72 _tmp0_ = _vala_ccode_node_ref0 (value);
73 _vala_ccode_node_unref0 (self->priv->_expression);
74 self->priv->_expression = _tmp0_;
75 }
76
77 ValaCCodeCaseStatement*
vala_ccode_case_statement_construct(GType object_type,ValaCCodeExpression * expression)78 vala_ccode_case_statement_construct (GType object_type,
79 ValaCCodeExpression* expression)
80 {
81 ValaCCodeCaseStatement* self = NULL;
82 g_return_val_if_fail (expression != NULL, NULL);
83 self = (ValaCCodeCaseStatement*) vala_ccode_statement_construct (object_type);
84 vala_ccode_case_statement_set_expression (self, expression);
85 return self;
86 }
87
88 ValaCCodeCaseStatement*
vala_ccode_case_statement_new(ValaCCodeExpression * expression)89 vala_ccode_case_statement_new (ValaCCodeExpression* expression)
90 {
91 return vala_ccode_case_statement_construct (VALA_TYPE_CCODE_CASE_STATEMENT, expression);
92 }
93
94 static void
vala_ccode_case_statement_real_write(ValaCCodeNode * base,ValaCCodeWriter * writer)95 vala_ccode_case_statement_real_write (ValaCCodeNode* base,
96 ValaCCodeWriter* writer)
97 {
98 ValaCCodeCaseStatement * self;
99 ValaCCodeLineDirective* _tmp0_;
100 ValaCCodeLineDirective* _tmp1_;
101 ValaCCodeExpression* _tmp2_;
102 self = (ValaCCodeCaseStatement*) base;
103 g_return_if_fail (writer != NULL);
104 _tmp0_ = vala_ccode_node_get_line ((ValaCCodeNode*) self);
105 _tmp1_ = _tmp0_;
106 vala_ccode_writer_write_indent (writer, _tmp1_);
107 vala_ccode_writer_write_string (writer, "case ");
108 _tmp2_ = self->priv->_expression;
109 vala_ccode_node_write ((ValaCCodeNode*) _tmp2_, writer);
110 vala_ccode_writer_write_string (writer, ":");
111 vala_ccode_writer_write_newline (writer);
112 }
113
114 static void
vala_ccode_case_statement_class_init(ValaCCodeCaseStatementClass * klass,gpointer klass_data)115 vala_ccode_case_statement_class_init (ValaCCodeCaseStatementClass * klass,
116 gpointer klass_data)
117 {
118 vala_ccode_case_statement_parent_class = g_type_class_peek_parent (klass);
119 ((ValaCCodeNodeClass *) klass)->finalize = vala_ccode_case_statement_finalize;
120 g_type_class_adjust_private_offset (klass, &ValaCCodeCaseStatement_private_offset);
121 ((ValaCCodeNodeClass *) klass)->write = (void (*) (ValaCCodeNode*, ValaCCodeWriter*)) vala_ccode_case_statement_real_write;
122 }
123
124 static void
vala_ccode_case_statement_instance_init(ValaCCodeCaseStatement * self,gpointer klass)125 vala_ccode_case_statement_instance_init (ValaCCodeCaseStatement * self,
126 gpointer klass)
127 {
128 self->priv = vala_ccode_case_statement_get_instance_private (self);
129 }
130
131 static void
vala_ccode_case_statement_finalize(ValaCCodeNode * obj)132 vala_ccode_case_statement_finalize (ValaCCodeNode * obj)
133 {
134 ValaCCodeCaseStatement * self;
135 self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_CCODE_CASE_STATEMENT, ValaCCodeCaseStatement);
136 _vala_ccode_node_unref0 (self->priv->_expression);
137 VALA_CCODE_NODE_CLASS (vala_ccode_case_statement_parent_class)->finalize (obj);
138 }
139
140 /**
141 * Represents a case block in a switch statement in C code.
142 */
143 static GType
vala_ccode_case_statement_get_type_once(void)144 vala_ccode_case_statement_get_type_once (void)
145 {
146 static const GTypeInfo g_define_type_info = { sizeof (ValaCCodeCaseStatementClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_ccode_case_statement_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaCCodeCaseStatement), 0, (GInstanceInitFunc) vala_ccode_case_statement_instance_init, NULL };
147 GType vala_ccode_case_statement_type_id;
148 vala_ccode_case_statement_type_id = g_type_register_static (VALA_TYPE_CCODE_STATEMENT, "ValaCCodeCaseStatement", &g_define_type_info, 0);
149 ValaCCodeCaseStatement_private_offset = g_type_add_instance_private (vala_ccode_case_statement_type_id, sizeof (ValaCCodeCaseStatementPrivate));
150 return vala_ccode_case_statement_type_id;
151 }
152
153 GType
vala_ccode_case_statement_get_type(void)154 vala_ccode_case_statement_get_type (void)
155 {
156 static volatile gsize vala_ccode_case_statement_type_id__volatile = 0;
157 if (g_once_init_enter (&vala_ccode_case_statement_type_id__volatile)) {
158 GType vala_ccode_case_statement_type_id;
159 vala_ccode_case_statement_type_id = vala_ccode_case_statement_get_type_once ();
160 g_once_init_leave (&vala_ccode_case_statement_type_id__volatile, vala_ccode_case_statement_type_id);
161 }
162 return vala_ccode_case_statement_type_id__volatile;
163 }
164
165