summaryrefslogtreecommitdiffstats
path: root/test/cvtest.d
blob: 5bdc819aec42dbec51cb5c055268fd754a02cd3f (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

module cvtest;

import std.string;
import std.stdio;

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

// field type LF_ENUMERATE_V1

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

// field type LF_MEMBER_V1

class class_member
{
	int member1;
};

// field type LF_BCLASS_V1

class base_class
{
	int base_member;
};

class derived_class : public 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;

// 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;
}

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;
}

int arrays()
{
	int[] iarr;
	iarr ~= 4;
	
	void[] varr;
	varr = new char[102];
	
	const void[] cvarr;
	
	return iarr.length;
}

int main2(char[][]argv)
{
	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; // = new class_outer.class_inner(inst_outer);

	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();
	
	class_with_struct_member cwsm = new class_with_struct_member;

	return 0;
}


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

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

	main2(argv);

	writefln("Hello world");

	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();

	dmd_quirks();
	strings();

	int[] dynint_arr;
	dynint_arr ~= 12;

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

}

// alias invariant(char)[] string;


class Test
{
	int 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 cs = "char string";
	wstring ws = "wchar string"w;
	dstring ds = "dchar string"d;

	return 0;
}

void dmd_quirks()
{
	long quirk_long; // written as delegate<void*,int>

	ulong quirk_ulong; // written as int[]

}