Debian Codegraph @

gcc/testsuite/gdc.test/compilable/dtoh_StructDeclaration.d

raw
1 /*
2 REQUIRED_ARGS: -HC -c -o-
3 PERMUTE_ARGS:
4 TEST_OUTPUT:
5 ---
6 // Automatically generated by Digital Mars D Compiler
7
8 #pragma once
9
10 #include <assert.h>
11 #include <math.h>
12 #include <stddef.h>
13 #include <stdint.h>
14
15 #ifdef CUSTOM_D_ARRAY_TYPE
16 #define _d_dynamicArray CUSTOM_D_ARRAY_TYPE
17 #else
18 /// Represents a D [] array
19 template<typename T>
20 struct _d_dynamicArray final
21 {
22 size_t length;
23 T *ptr;
24
25 _d_dynamicArray() : length(0), ptr(NULL) { }
26
27 _d_dynamicArray(size_t length_in, T *ptr_in)
28 : length(length_in), ptr(ptr_in) { }
29
30 T& operator[](const size_t idx) {
31 assert(idx < length);
32 return ptr[idx];
33 }
34
35 const T& operator[](const size_t idx) const {
36 assert(idx < length);
37 return ptr[idx];
38 }
39 };
40 #endif
41
42 struct S final
43 {
44 int8_t a;
45 int32_t b;
46 int64_t c;
47 _d_dynamicArray< int32_t > arr;
48 private:
49 ~S();
50 public:
51 S() :
52 a(),
53 b(),
54 c(),
55 arr()
56 {
57 }
58 S(int8_t a, int32_t b = 0, int64_t c = 0LL, _d_dynamicArray< int32_t > arr = {}) :
59 a(a),
60 b(b),
61 c(c),
62 arr(arr)
63 {}
64 };
65
66 struct S2 final
67 {
68 int32_t a;
69 int32_t b;
70 int64_t c;
71 S d;
72 S2(int32_t a);
73 S2(char ) = delete;
74 S2() :
75 a(42),
76 b(),
77 c()
78 {
79 }
80 };
81
82 struct S3 final
83 {
84 int32_t a;
85 int32_t b;
86 int64_t c;
87 S3() :
88 a(42),
89 b(),
90 c()
91 {
92 }
93 };
94
95 struct S4 final
96 {
97 int32_t a;
98 int64_t b;
99 int32_t c;
100 int8_t d;
101 S4() :
102 a(),
103 b(),
104 c(),
105 d()
106 {
107 }
108 S4(int32_t a, int64_t b = 0LL, int32_t c = 0, int8_t d = 0) :
109 a(a),
110 b(b),
111 c(c),
112 d(d)
113 {}
114 };
115
116 #pragma pack(push, 1)
117 struct Aligned final
118 {
119 int8_t a;
120 int32_t b;
121 int64_t c;
122 Aligned(int32_t a);
123 Aligned() :
124 a(),
125 b(),
126 c()
127 {
128 }
129 };
130 #pragma pack(pop)
131
132 struct Null final
133 {
134 void* field;
135 Null() :
136 field(nullptr)
137 {
138 }
139 Null(void* field) :
140 field(field)
141 {}
142 };
143
144 struct A final
145 {
146 int32_t a;
147 S s;
148 void baz(int32_t x = 42);
149 struct
150 {
151 int32_t x;
152 int32_t y;
153 };
154 union
155 {
156 int32_t u1;
157 char u2[4$?:32=u|64=LLU$];
158 };
159 struct Inner final
160 {
161 int32_t x;
162 Inner() :
163 x()
164 {
165 }
166 Inner(int32_t x) :
167 x(x)
168 {}
169 };
170
171 typedef Inner I;
172 class C;
173
174 A() :
175 a(),
176 s(),
177 x(),
178 y()
179 {
180 }
181 A(int32_t a, S s = S(), int32_t x = 0, int32_t y = 0) :
182 a(a),
183 s(s),
184 x(x),
185 y(y)
186 {}
187 };
188
189 union U
190 {
191 int32_t i;
192 char c;
193 };
194
195 struct Array final
196 {
197 uint32_t length;
198 private:
199 _d_dynamicArray< char > data;
200 char smallarray[1$?:32=u|64=LLU$];
201 public:
202 Array() :
203 length(),
204 data()
205 {
206 }
207 Array(uint32_t length, _d_dynamicArray< char > data = {}) :
208 length(length),
209 data(data)
210 {}
211 };
212
213 struct Params final
214 {
215 bool obj;
216 Array ddocfiles;
217 Params() :
218 obj(true),
219 ddocfiles()
220 {
221 }
222 Params(bool obj, Array ddocfiles = Array()) :
223 obj(obj),
224 ddocfiles(ddocfiles)
225 {}
226 };
227
228 struct Loc final
229 {
230 static int32_t showColumns;
231 void toChars(int32_t showColumns = Loc::showColumns);
232 Loc()
233 {
234 }
235 };
236 ---
237 */
238
239 /*
240 StructDeclaration has the following issues:
241 * align different than 1 does nothing; we should support align(n), where `n` in [1, 2, 4, 8, 16]
242 * align(n): inside struct definition doesn’t add alignment, but breaks generation of default ctors
243 */
244
245 extern (C++) struct S
246 {
247 byte a;
248 int b;
249 long c;
250 int[] arr;
251 extern(D) ~this() {}
252 }
253
254 extern (C++) struct S2
255 {
256 int a = 42;
257 int b;
258 long c;
259 S d = void;
260
261 this(int a) {}
262 extern(D) this(int, int, long) {}
263 @disable this(char);
264 }
265
266 extern (C) struct S3
267 {
268 int a = 42;
269 int b;
270 long c;
271
272 this(int a) {}
273 }
274
275 extern (C) struct S4
276 {
277 int a;
278 long b;
279 int c;
280 byte d;
281 }
282
283 extern (C++) align(1) struct Aligned
284 {
285 //align(1):
286 byte a;
287 int b;
288 long c;
289
290 this(int a) {}
291 }
292
293 extern (C++) struct Null
294 {
295 void* field = null;
296 }
297
298 extern (C++) struct A
299 {
300 int a;
301 S s;
302
303 extern (D) void foo();
304 extern (C) void bar() {}
305 extern (C++) void baz(int x = 42) {}
306
307 struct
308 {
309 int x;
310 int y;
311 }
312
313 union
314 {
315 int u1;
316 char[4] u2;
317 }
318
319 struct Inner
320 {
321 int x;
322 }
323
324 alias I = Inner;
325
326 extern(C++) class C;
327
328 }
329
330 extern(C++) union U
331 {
332 int i;
333 char c;
334 }
335
336 extern (C++) struct Array
337 {
338 uint length;
339 private:
340 char[] data;
341 char[1] smallarray;
342 }
343
344 extern (C++) struct Params
345 {
346 bool obj = true;
347 Array ddocfiles;
348 }
349
350 extern (C++) struct Loc
351 {
352 __gshared int showColumns;
353 void toChars(int showColumns = Loc.showColumns) {}
354 }