summaryrefslogtreecommitdiff
path: root/tests/enums/bug666035.c-expected
blob: cbc78c93b3634896fe1fee815a0b0148f3619184 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/* enums_bug666035.c generated by valac, the Vala compiler
 * generated from enums_bug666035.vala, do not modify */

#include <glib-object.h>
#include <glib.h>
#include <string.h>

#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

typedef enum  {
	FOO_ENUM_FOO,
	FOO_ENUM_BAR,
	FOO_ENUM_MAM
} FooEnum;

#define TYPE_FOO_ENUM (foo_enum_get_type ())
typedef enum  {
	FOO_FLAG_FOO = 1 << 0,
	FOO_FLAG_BAR = 1 << 1,
	FOO_FLAG_MAM = 1 << 2
} FooFlag;

#define TYPE_FOO_FLAG (foo_flag_get_type ())

#define TYPE_FOO_STRUCT (foo_struct_get_type ())
typedef struct _FooStruct FooStruct;
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _FooStruct {
	FooEnum f;
};

VALA_EXTERN GType foo_enum_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType foo_flag_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType foo_struct_get_type (void) G_GNUC_CONST ;
VALA_EXTERN FooStruct* foo_struct_dup (const FooStruct* self);
VALA_EXTERN void foo_struct_free (FooStruct* self);
VALA_EXTERN FooEnum takes_enum (FooEnum foo);
VALA_EXTERN FooEnum gives_enum (void);
VALA_EXTERN FooFlag takes_flag (FooFlag foo);
VALA_EXTERN FooFlag gives_flag (void);
static void _vala_main (void);

static GType
foo_enum_get_type_once (void)
{
	static const GEnumValue values[] = {{FOO_ENUM_FOO, "FOO_ENUM_FOO", "foo"}, {FOO_ENUM_BAR, "FOO_ENUM_BAR", "bar"}, {FOO_ENUM_MAM, "FOO_ENUM_MAM", "mam"}, {0, NULL, NULL}};
	GType foo_enum_type_id;
	foo_enum_type_id = g_enum_register_static ("FooEnum", values);
	return foo_enum_type_id;
}

GType
foo_enum_get_type (void)
{
	static volatile gsize foo_enum_type_id__once = 0;
	if (g_once_init_enter (&foo_enum_type_id__once)) {
		GType foo_enum_type_id;
		foo_enum_type_id = foo_enum_get_type_once ();
		g_once_init_leave (&foo_enum_type_id__once, foo_enum_type_id);
	}
	return foo_enum_type_id__once;
}

static GType
foo_flag_get_type_once (void)
{
	static const GFlagsValue values[] = {{FOO_FLAG_FOO, "FOO_FLAG_FOO", "foo"}, {FOO_FLAG_BAR, "FOO_FLAG_BAR", "bar"}, {FOO_FLAG_MAM, "FOO_FLAG_MAM", "mam"}, {0, NULL, NULL}};
	GType foo_flag_type_id;
	foo_flag_type_id = g_flags_register_static ("FooFlag", values);
	return foo_flag_type_id;
}

GType
foo_flag_get_type (void)
{
	static volatile gsize foo_flag_type_id__once = 0;
	if (g_once_init_enter (&foo_flag_type_id__once)) {
		GType foo_flag_type_id;
		foo_flag_type_id = foo_flag_get_type_once ();
		g_once_init_leave (&foo_flag_type_id__once, foo_flag_type_id);
	}
	return foo_flag_type_id__once;
}

FooStruct*
foo_struct_dup (const FooStruct* self)
{
	FooStruct* dup;
	dup = g_new0 (FooStruct, 1);
	memcpy (dup, self, sizeof (FooStruct));
	return dup;
}

void
foo_struct_free (FooStruct* self)
{
	g_free (self);
}

static GType
foo_struct_get_type_once (void)
{
	GType foo_struct_type_id;
	foo_struct_type_id = g_boxed_type_register_static ("FooStruct", (GBoxedCopyFunc) foo_struct_dup, (GBoxedFreeFunc) foo_struct_free);
	return foo_struct_type_id;
}

GType
foo_struct_get_type (void)
{
	static volatile gsize foo_struct_type_id__once = 0;
	if (g_once_init_enter (&foo_struct_type_id__once)) {
		GType foo_struct_type_id;
		foo_struct_type_id = foo_struct_get_type_once ();
		g_once_init_leave (&foo_struct_type_id__once, foo_struct_type_id);
	}
	return foo_struct_type_id__once;
}

FooEnum
takes_enum (FooEnum foo)
{
	FooEnum result;
	result = foo;
	return result;
}

FooEnum
gives_enum (void)
{
	FooEnum result;
	result = FOO_ENUM_MAM;
	return result;
}

FooFlag
takes_flag (FooFlag foo)
{
	FooFlag result;
	result = foo;
	return result;
}

FooFlag
gives_flag (void)
{
	FooFlag result;
	result = FOO_FLAG_MAM | FOO_FLAG_BAR;
	return result;
}

static void
_vala_main (void)
{
	FooEnum* foo_array = NULL;
	FooEnum* _tmp0_;
	gint foo_array_length1;
	gint _foo_array_size_;
	FooEnum* _tmp1_;
	gint _tmp1__length1;
	FooEnum* _tmp2_;
	gint _tmp2__length1;
	FooEnum _tmp3_;
	FooStruct foo_struct = {0};
	FooStruct _tmp4_ = {0};
	FooStruct _tmp5_;
	FooEnum foo_enum = 0;
	if (takes_enum (FOO_ENUM_BAR) == FOO_ENUM_BAR) {
		return;
	}
	_vala_assert (takes_enum (FOO_ENUM_BAR) == FOO_ENUM_BAR, "takes_enum (BAR) == BAR");
	_vala_assert (takes_flag (FOO_FLAG_BAR | FOO_FLAG_MAM) == (FOO_FLAG_BAR | FOO_FLAG_MAM), "takes_flag (BAR | MAM) == (BAR | MAM)");
	_vala_assert (gives_flag () == (FOO_FLAG_BAR | FOO_FLAG_MAM), "gives_flag () == (BAR | MAM)");
	_tmp0_ = g_new0 (FooEnum, 3);
	_tmp0_[0] = FOO_ENUM_FOO;
	_tmp0_[1] = FOO_ENUM_BAR;
	_tmp0_[2] = FOO_ENUM_FOO;
	foo_array = _tmp0_;
	foo_array_length1 = 3;
	_foo_array_size_ = foo_array_length1;
	_tmp1_ = foo_array;
	_tmp1__length1 = foo_array_length1;
	_tmp1_[1] = FOO_ENUM_MAM;
	_tmp2_ = foo_array;
	_tmp2__length1 = foo_array_length1;
	_tmp3_ = _tmp2_[1];
	_vala_assert (_tmp3_ == FOO_ENUM_MAM, "foo_array[1] == MAM");
	_tmp4_.f = FOO_ENUM_BAR;
	foo_struct = _tmp4_;
	_tmp5_ = foo_struct;
	_vala_assert (_tmp5_.f == FOO_ENUM_BAR, "foo_struct.f == BAR");
	foo_enum = FOO_ENUM_BAR;
	switch (foo_enum) {
		default:
		case FOO_ENUM_FOO:
		{
			_vala_assert (FALSE, "false");
			break;
		}
		case FOO_ENUM_BAR:
		{
			break;
		}
	}
	foo_array = (g_free (foo_array), NULL);
}

int
main (int argc,
      char ** argv)
{
	_vala_main ();
	return 0;
}