summaryrefslogtreecommitdiffstats
path: root/test/cvtest.d
blob: f1bd9f55892720b58cf526d619883dc4e645d230 (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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565

module cvtest;

version(none)
{
	int[int] global_oem_int_assoc_array;

	int args(int a, int b, int c, int abc)
	{
		int d = a + b;
		int e = b + c;
		foreach(x; global_oem_int_assoc_array)
			e += x;
		return d + e + abc;
	}
	void main()
	{
		args(3, 4, 5, 345);
	}
}
version(all):
import std.string;
import std.stdio;
import std.range;

///////////////// field types ////////////////////////

// field type LF_ENUMERATE_V1

enum enum_name
{
	kEnum1 = 1,
	kEnum2 = cast(uint) 2,
	kEnum3,
	kEnum500 = 500,
	E_NOTIMPL     = cast(int)0x80004001,
};

enum derived_enum : ushort
{
	kDerived1,
	kDerived2
}

// field type LF_MEMBER_V1

class class_member
{
	int member1;
};

// field type LF_BCLASS_V1

class base_class
{
	int base_member;
};

class derived_class : base_class
{
	int derived_member;
	int a1_1234;

private:
	int a2;
	int a3;
	int a4;
	int a5;
	int a6;
	int a7;
	int a8;
	int a9;
	int a10;
	int a11;
	int a12;
	int a13;
	int a14;
	int a15;
	int a16;
	int a17;
};

// field type LF_METHOD_V1

class class_method
{
	int member = 3;
	static int stmember = 2;
	int method()
	{
		return member + stmember + this.member;
	}
};

// function with same arguments as class_method.method. does it have different type?

int sim_method(class_method mthd)
{
	return 2;
}

// field type LF_STMEMBER_V1

class class_staticmember
{
	static int static_member = 2;
};

// field type LF_NESTTYPE_V1

class class_outer
{
	class class_inner
	{
		int a, b;
	};
	class_inner inner;
	int c, d;
};

// LF_ARRAY_V1

long[4] global_fixed_array;
__gshared long[4] gshared_fixed_array = [ 1, 2, 3, 4 ];
__gshared string gshared_bss_string;

// OEM types;

long[] global_oem_long_dynarray;
int[int] global_oem_int_assoc_array;

alias int[] alias_int_array;

void procedure(int arg1)
{
}

struct struct_name
{
	int member;
	static int static_member;

	int method()
	{
		return member + static_member + this.member;
	}
}

union union_name
{
	int int_member;
	long long_member;
	float float_member;
	struct_name struct_member;
}

class this_is_a_rather_long_classname_to_test_what_happens_if_the_classname_gets_longer_than_the_limit_imposed_by_the_old_codeview_format_which_limits_the_length_of_names_to_tw0_hundred_and_fifty_five_characters_because_it_uses_pascal_strings_with_a_length_byte_and_chars_appended
{
	int member;
};

int longfoo(this_is_a_rather_long_classname_to_test_what_happens_if_the_classname_gets_longer_than_the_limit_imposed_by_the_old_codeview_format_which_limits_the_length_of_names_to_tw0_hundred_and_fifty_five_characters_because_it_uses_pascal_strings_with_a_length_byte_and_chars_appended x)
{
	return 1;
}

class Templ(T)
{
  T foo(T x)
  {
    return x+x;
  }
}

struct struc
{
	int a;
	struc * next;
}

class class_with_struct_member
{
	int c1;
	int c2;
	struc *s1;

	this() { s1 = new struc; }
};

interface iface
{
	void foo();
}

interface iface2 : iface
{
	void foo2();
}

class iface_impl : iface2
{
	void foo() {}
	void foo2() {}
}

interface IUnknown
{
	void addref();
	void release();
}

class CUnknown : IUnknown
{
	void addref() {}
	void release() {}
}

version(D2)
{
    string stringMixin = "int a = 0;

    return x + a;

    ";

    int mixinTest(int x)
    {
        mixin(stringMixin);
    }
}

class A
{
	static int outer_func(int x)
	{
		int inner_func(int y)
		{
			return x * y;
		}
		return inner_func(2);
	}
}

A outer_func(int x)
{
	int inner_func(int y)
	{
		return x * y;
	}
	inner_func(3);
	return new A;
}

void voidpointers(ubyte* p)
{
	void* vp = cast(void*) p;
	const(void)* const_vp = cast(const(void)*) p;
	const(void*) const_vp2 = cast(const(void*)) p;

	int* ip = cast(int*) p;
	const(int)* const_ip = cast(const(int)*) p;
	const(int*) const_ip2 = cast(const(int*)) p;
}

int args(int a, int b, int c, int abc)
{
	int d = a + b;
	int e = b + c;
	foreach(x; global_oem_int_assoc_array)
		e += x;
	return d + e + abc;
}

extern(C) int cargs(int a, int b, int c, int abc)
{
	int d = a + b;
	int e = b + c;
	foreach(x; global_oem_int_assoc_array)
		e += x;
	return d + e + abc;
}

size_t arrays()
{
	int[] iarr;
	iarr ~= 4;

	void[] varr;
	varr = new char[102];

	const void[] cvarr;

	int[7] xarr = [ 1, 2, 3, 4, 5, 6, 7 ];
	string[7] sarr = [ "a", "b", "c", "d", "e", "f", "g" ];
	wstring[7] wsarr = [ "a", "b", "c", "d", "e", "f", "g" ];
	dstring[7] dsarr = [ "a", "b", "c", "d", "e", "f", "g" ];

	return iarr.length;
}

size_t lexical_scope()
/*in

{

	int i = 13;

	int j = 5;

}*/
out
{
	int i = 42;
	i++;
}
body
{
	int[10] arr1;
	for(int i = 0; i < 5; i++)
		arr1[i] = i;

	foreach(int i; 0..4)
		arr1[i] += i;

	foreach(int i; iota(0,3))
		arr1[i] += i;

	foreach(i; "hello")
		if(i == 'e')
			break;

	{
		long i = 7;
		i = i + 1;
	}

	while(arr1[5] != 9)
	{
		int i = 9;
		arr1[5] = i;
	}
	do
	{
		int i = 6;
		arr1[5] = i;
	}
	while(arr1[5] != 6);

	Object obj;
	with(obj)
	{
		int i = 3;
		i = i + 4;
	}

	return arr1.length;
}

enum { Forward, Accept, Reject }
alias int Action;

Action convertEnum()
{
	derived_enum direvedEnum = derived_enum.kDerived2;
	return Accept;
}

int main2(string[]argv)
{
	convertEnum();

	enum_name inst_enum = enum_name.kEnum2;
	class_member inst_member = new class_member;
	base_class inst_base = new base_class;
	derived_class inst_derived = new derived_class;
	class_method inst_method = new class_method;
	class_staticmember inst_staticmember = new class_staticmember;
	class_outer inst_outer = new class_outer;
	class_outer.class_inner inst_inner = /*inst_outer.inner; // =*/ inst_outer.new class_inner;
	struct_name inst_struct;
	struct_name* pinst_struct;
	pinst_struct = &inst_struct;
	inst_struct.member = 1;
	struct_name.static_member = 3;
	this_is_a_rather_long_classname_to_test_what_happens_if_the_classname_gets_longer_than_the_limit_imposed_by_the_old_codeview_format_which_limits_the_length_of_names_to_tw0_hundred_and_fifty_five_characters_because_it_uses_pascal_strings_with_a_length_byte_and_chars_appended long_class_name;
	int this_is_a_rather_long_varname_to_test_what_happens_if_the_classname_gets_longer_than_the_limit_imposed_by_the_old_codeview_format_which_limits_the_length_of_names_to_tw0_hundred_and_fifty_five_characters_because_it_uses_pascal_strings_with_a_length_byte_and_chars_appended = 1;
	int *plongname = &this_is_a_rather_long_varname_to_test_what_happens_if_the_classname_gets_longer_than_the_limit_imposed_by_the_old_codeview_format_which_limits_the_length_of_names_to_tw0_hundred_and_fifty_five_characters_because_it_uses_pascal_strings_with_a_length_byte_and_chars_appended;

	iface_impl impl = new iface_impl;
	iface face = impl;
	iface_impl nimpl = cast(iface_impl) face;

	CUnknown unkn = new CUnknown;
	IUnknown iunkn = unkn;
//	CUnknown nunkn = cast(CUnknown) iunkn;


	FILE stdfile;
	inst_member.member1 = 2;

	union_name inst_union;
	inst_union.float_member = 1;

	int* pointer_int = null;
	struct_name* pointer_struct_name = &inst_struct;
	class_member* pointer_class_member = &inst_member;

	alias_int_array int_array;

	int[] int_oem_long_dynarray; int_oem_long_dynarray ~= 12;
	int[int] local_oem_int_assoc_array;

	for (int i = 0; i < 1024; i++)
	    local_oem_int_assoc_array[i] = 2*i;

	local_oem_int_assoc_array[5000] = 1;

	int *intptr = int_oem_long_dynarray.ptr;
	Object null_obj;
	derived_class null_derived;

	// delegate

	int delegate() dg = &inst_method.method;
	int res = dg();

	int delegate() dg2 = &inst_struct.method;
	int res2 = dg2();

	class_with_struct_member cwsm = new class_with_struct_member;

	return 0;
}


int main(string[]argv)
{
	long lng = 3;
	ulong ulng = 4;

	args(3, 4, 5, 345);
	cargs(3, 4, 5, 345);
	voidpointers(null);
	arrays();
	lexical_scope();

	outer_func(3);
	A.outer_func(3);

	global_fixed_array[1] = 3;
	gshared_fixed_array[0] = 3;
	gshared_bss_string = "bss";

	main2(argv);

	writefln("Hello world");
	getchar();

	int[int] int_arr;
	int_arr[1] = 100;
	int_arr[98] = 101;
	int_arr[8] = 7;
	int_arr[12] = 11;
	int_arr[17] = 28;
	int_arr[45] = 91;

	float f = 2.4;
	double d = 2.4;
	if(d == f)
		d = 0;
	assert(2.4 == 2.4f);

	struct ab {
		int a;
		int b;
	}
	ab ab1 = { 1, 2 };
	ab ab2 = { 3, 4 };
	ab ab3 = { 1, 3 };
	int[ab] struc_arr;
	struc_arr[ab1] = 5;
	struc_arr[ab2] = 6;
	struc_arr[ab3] = 7;

	struc s = { 2, null };

	Templ!(int) templ = new Templ!(int);
	int y = templ.foo(3);
	version(D2)
		int z = mixinTest(7);

	(new Test).test();

	basictypes();
	strings();

	int[] dynint_arr;
	dynint_arr ~= 12;

	return enum_name.E_NOTIMPL;
	//return dynint_arr.length;

}

// alias invariant(char)[] string;


class Test
{
	size_t test()
	{
		class_outer clss = new class_outer;

		string[] dyn_arr;
		dyn_arr ~= "foo";
		dyn_arr ~= "bar";

		int[string] assoc_arr;
		assoc_arr["foo"] = 3;
		assoc_arr["bar"] = 1;
		assoc_arr["abc"] = 7;

		return dyn_arr.length + assoc_arr.length + clss.c;
	}
}

int strings()
{
	string empty;
	string  cs = "char string";
	wstring ws = "wchar string"w;
	dstring ds = "dchar string"d;

	immutable(char)[]  ics = cs;
	immutable(wchar)[] iws = ws;
	immutable(dchar)[] ids = ds;

	char[]  mcs = cs.dup;
	wchar[] mws = ws.dup;
	dchar[] mds = ds.dup;

	const(char)[]  ccs = cs;
	const(wchar)[] cws = ws;
	const(dchar)[] cds = ds;

	immutable char[]  i2cs = cs[0..$-1];
	immutable wchar[] i2ws = ws[0..$-1];
	immutable dchar[] i2ds = ds[0..$-1];

	const char[]  c2cs = cs;
	const wchar[] c2ws = ws;
	const dchar[] c2ds = ds;

	return 0;
}

double basictypes()
{
	// basic types

	char c;
	wchar wc;
	dchar dc;
	byte b;
	ubyte ub;
	short s;
	ushort us;
	int i;
	uint ui;
	long quirk_long; // written as delegate<void*,int>

	ulong quirk_ulong; // written as int[]


	float f;
	double d;
	real r;

	ifloat iflt;
	idouble id;
	ireal ir;
	cfloat cf;
	cdouble cd;
	creal cr;

	return f + d + r + cf.im;
}