Mercurial > projects > ldc
annotate lphobos/internal/objectimpl.d @ 116:fd7ad91fd713 trunk
[svn r120] ModuleInfo implementation is now almost complete.
Fixed some nasty static array-initializer bugs.
Fixed bug in DtoArrayLen and DtoArrayPtr for full slices of static arrays.
author | lindquist |
---|---|
date | Sun, 25 Nov 2007 18:55:52 +0100 |
parents | 27b9f749d9fe |
children | a2c2c3c1a73d |
rev | line source |
---|---|
1 | 1 |
2 /** | |
3 * Part of the D programming language runtime library. | |
4 * Forms the symbols available to all D programs. Includes | |
5 * Object, which is the root of the class object hierarchy. | |
6 * | |
7 * This module is implicitly imported. | |
8 * Macros: | |
9 * WIKI = Phobos/Object | |
10 */ | |
11 | |
12 /* | |
13 * Copyright (C) 2004-2007 by Digital Mars, www.digitalmars.com | |
14 * Written by Walter Bright | |
15 * | |
16 * This software is provided 'as-is', without any express or implied | |
17 * warranty. In no event will the authors be held liable for any damages | |
18 * arising from the use of this software. | |
19 * | |
20 * Permission is granted to anyone to use this software for any purpose, | |
21 * including commercial applications, and to alter it and redistribute it | |
22 * freely, in both source and binary form, subject to the following | |
23 * restrictions: | |
24 * | |
25 * o The origin of this software must not be misrepresented; you must not | |
26 * claim that you wrote the original software. If you use this software | |
27 * in a product, an acknowledgment in the product documentation would be | |
28 * appreciated but is not required. | |
29 * o Altered source versions must be plainly marked as such, and must not | |
30 * be misrepresented as being the original software. | |
31 * o This notice may not be removed or altered from any source | |
32 * distribution. | |
33 */ | |
34 | |
89 | 35 /* |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
36 * This copy is modified to work with LLVMDC |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
37 * by Tomas Lindquist Olsen, September 2007 |
89 | 38 */ |
1 | 39 |
40 module object; | |
41 | |
89 | 42 import std.outofmemory; |
1 | 43 |
52 | 44 /** |
45 * An unsigned integral type large enough to span the memory space. Use for | |
46 * array indices and pointer offsets for maximal portability to | |
47 * architectures that have different memory address ranges. This is | |
48 * analogous to C's size_t. | |
49 */ | |
50 alias typeof(int.sizeof) size_t; | |
51 | |
52 /** | |
53 * A signed integral type large enough to span the memory space. Use for | |
54 * pointer differences and for size_t differences for maximal portability to | |
55 * architectures that have different memory address ranges. This is | |
56 * analogous to C's ptrdiff_t. | |
57 */ | |
58 alias typeof(cast(void*)0 - cast(void*)0) ptrdiff_t; | |
59 | |
60 alias size_t hash_t; | |
61 | |
1 | 62 extern (C) |
63 { /// C's printf function. | |
64 int printf(char *, ...); | |
52 | 65 void trace_term(); |
1 | 66 |
67 int memcmp(void *, void *, size_t); | |
68 void* memcpy(void *, void *, size_t); | |
69 void* calloc(size_t, size_t); | |
70 void* realloc(void*, size_t); | |
71 void free(void*); | |
72 | |
73 //Object _d_newclass(ClassInfo ci); | |
74 } | |
75 | |
76 /// Standard boolean type. | |
77 alias bool bit; | |
78 | |
52 | 79 alias char[] string; |
80 alias wchar[] wstring; | |
81 alias dchar[] dstring; | |
1 | 82 |
83 /+ | |
52 | 84 |
1 | 85 /* ************************* |
86 * Internal struct pointed to by the hidden .monitor member. | |
87 */ | |
88 struct Monitor | |
89 { | |
90 void delegate(Object)[] delegates; | |
91 | |
92 /* More stuff goes here defined by internal/monitor.c */ | |
93 } | |
52 | 94 |
1 | 95 +/ |
96 | |
97 /****************** | |
98 * All D class objects inherit from Object. | |
99 */ | |
100 class Object | |
101 { | |
102 void print() | |
103 { | |
104 char[] s = toString(); | |
105 printf("%.*s\n", s.length, s.ptr); | |
106 } | |
107 | |
108 /** | |
109 * Convert Object to a human readable string. | |
110 */ | |
111 char[] toString() | |
112 { | |
113 //return this.classinfo.name; | |
52 | 114 return "object.Object (no classinfo yet)"; |
1 | 115 } |
116 | |
117 /** | |
118 * Compute hash function for Object. | |
119 */ | |
120 hash_t toHash() | |
121 { | |
122 // BUG: this prevents a compacting GC from working, needs to be fixed | |
52 | 123 return cast(hash_t)cast(void *)this; |
1 | 124 } |
125 | |
126 /** | |
127 * Compare with another Object obj. | |
128 * Returns: | |
129 * $(TABLE | |
130 * $(TR $(TD this < obj) $(TD < 0)) | |
131 * $(TR $(TD this == obj) $(TD 0)) | |
132 * $(TR $(TD this > obj) $(TD > 0)) | |
133 * ) | |
134 */ | |
135 int opCmp(Object o) | |
136 { | |
137 // BUG: this prevents a compacting GC from working, needs to be fixed | |
138 //return cast(int)cast(void *)this - cast(int)cast(void *)o; | |
139 | |
140 //throw new Error("need opCmp for class " ~ this.classinfo.name); | |
52 | 141 throw new Error("need opCmp for class unknown object.Object (no classinfo yet)"); |
1 | 142 } |
143 | |
144 /** | |
145 * Returns !=0 if this object does have the same contents as obj. | |
146 */ | |
147 int opEquals(Object o) | |
148 { | |
149 return cast(int)(this is o); | |
150 } | |
151 | |
152 /* ** | |
153 * Call delegate dg, passing this to it, when this object gets destroyed. | |
154 * Use extreme caution, as the list of delegates is stored in a place | |
155 * not known to the gc. Thus, if any objects pointed to by one of these | |
156 * delegates gets freed by the gc, calling the delegate will cause a | |
157 * crash. | |
158 * This is only for use by library developers, as it will need to be | |
159 * redone if weak pointers are added or a moving gc is developed. | |
160 */ | |
161 final void notifyRegister(void delegate(Object) dg) | |
162 { | |
52 | 163 /+ |
1 | 164 //printf("notifyRegister(dg = %llx, o = %p)\n", dg, this); |
52 | 165 synchronized (this) |
1 | 166 { |
167 Monitor* m = cast(Monitor*)(cast(void**)this)[1]; | |
168 foreach (inout x; m.delegates) | |
169 { | |
170 if (!x || x == dg) | |
171 { x = dg; | |
172 return; | |
173 } | |
174 } | |
175 | |
176 // Increase size of delegates[] | |
177 auto len = m.delegates.length; | |
178 auto startlen = len; | |
179 if (len == 0) | |
180 { | |
181 len = 4; | |
182 auto p = calloc((void delegate(Object)).sizeof, len); | |
183 if (!p) | |
184 _d_OutOfMemory(); | |
185 m.delegates = (cast(void delegate(Object)*)p)[0 .. len]; | |
186 } | |
187 else | |
188 { | |
189 len += len + 4; | |
190 auto p = realloc(m.delegates.ptr, (void delegate(Object)).sizeof * len); | |
191 if (!p) | |
192 _d_OutOfMemory(); | |
193 m.delegates = (cast(void delegate(Object)*)p)[0 .. len]; | |
194 m.delegates[startlen .. len] = null; | |
195 } | |
196 m.delegates[startlen] = dg; | |
52 | 197 } |
198 +/ | |
1 | 199 } |
200 | |
201 /* ** | |
202 * Remove delegate dg from the notify list. | |
203 * This is only for use by library developers, as it will need to be | |
204 * redone if weak pointers are added or a moving gc is developed. | |
205 */ | |
206 final void notifyUnRegister(void delegate(Object) dg) | |
207 { | |
52 | 208 /+ |
209 synchronized (this) | |
1 | 210 { |
211 Monitor* m = cast(Monitor*)(cast(void**)this)[1]; | |
212 foreach (inout x; m.delegates) | |
213 { | |
214 if (x == dg) | |
215 x = null; | |
216 } | |
52 | 217 } |
218 +/ | |
1 | 219 } |
220 | |
221 /****** | |
222 * Create instance of class specified by classname. | |
223 * The class must either have no constructors or have | |
224 * a default constructor. | |
225 * Returns: | |
226 * null if failed | |
227 */ | |
52 | 228 static Object factory(char[] classname) |
1 | 229 { |
52 | 230 /+ |
42 | 231 auto ci = ClassInfo.find(classname); |
1 | 232 if (ci) |
233 { | |
234 return ci.create(); | |
42 | 235 } |
52 | 236 +/ |
1 | 237 return null; |
52 | 238 } |
1 | 239 } |
240 | |
241 /+ | |
242 extern (C) void _d_notify_release(Object o) | |
243 { | |
244 //printf("_d_notify_release(o = %p)\n", o); | |
245 Monitor* m = cast(Monitor*)(cast(void**)o)[1]; | |
246 if (m.delegates.length) | |
247 { | |
248 auto dgs = m.delegates; | |
249 synchronized (o) | |
250 { | |
251 dgs = m.delegates; | |
252 m.delegates = null; | |
253 } | |
254 | |
255 foreach (dg; dgs) | |
256 { | |
257 if (dg) | |
258 { //printf("calling dg = %llx (%p)\n", dg, o); | |
259 dg(o); | |
260 } | |
261 } | |
262 | |
263 free(dgs.ptr); | |
264 } | |
265 } | |
266 | |
89 | 267 +/ |
268 | |
1 | 269 /** |
270 * Information about an interface. | |
271 * A pointer to this appears as the first entry in the interface's vtbl[]. | |
272 */ | |
273 struct Interface | |
274 { | |
275 ClassInfo classinfo; /// .classinfo for this interface (not for containing class) | |
276 void *[] vtbl; | |
277 int offset; /// offset to Interface 'this' from Object 'this' | |
278 } | |
279 | |
280 import std.moduleinit; | |
89 | 281 |
1 | 282 /** |
283 * Runtime type information about a class. Can be retrieved for any class type | |
284 * or instance by using the .classinfo property. | |
285 * A pointer to this appears as the first entry in the class's vtbl[]. | |
286 */ | |
287 class ClassInfo : Object | |
288 { | |
289 byte[] init; /** class static initializer | |
290 * (init.length gives size in bytes of class) | |
291 */ | |
292 char[] name; /// class name | |
293 void *[] vtbl; /// virtual function pointer table | |
294 Interface[] interfaces; /// interfaces this class implements | |
295 ClassInfo base; /// base class | |
296 void *destructor; | |
89 | 297 void function(Object) classInvariant; |
1 | 298 uint flags; |
299 // 1: // IUnknown | |
300 // 2: // has no possible pointers into GC memory | |
301 // 4: // has offTi[] member | |
302 // 8: // has constructors | |
303 void *deallocator; | |
304 OffsetTypeInfo[] offTi; | |
305 void function(Object) defaultConstructor; // default Constructor | |
306 | |
307 /************* | |
308 * Search all modules for ClassInfo corresponding to classname. | |
309 * Returns: null if not found | |
310 */ | |
311 static ClassInfo find(char[] classname) | |
312 { | |
89 | 313 /+foreach (m; ModuleInfo.modules()) |
1 | 314 { |
315 //writefln("module %s, %d", m.name, m.localClasses.length); | |
316 foreach (c; m.localClasses) | |
317 { | |
318 //writefln("\tclass %s", c.name); | |
319 if (c.name == classname) | |
320 return c; | |
321 } | |
89 | 322 }+/ |
1 | 323 return null; |
324 } | |
325 | |
326 /******************** | |
327 * Create instance of Object represented by 'this'. | |
328 */ | |
329 Object create() | |
330 { | |
89 | 331 /+if (flags & 8 && !defaultConstructor) |
1 | 332 return null; |
333 Object o = _d_newclass(this); | |
334 if (flags & 8 && defaultConstructor) | |
335 { | |
336 defaultConstructor(o); | |
337 } | |
338 return o; | |
89 | 339 +/ |
340 return null; | |
1 | 341 } |
342 } | |
343 | |
89 | 344 //private import std.string; |
1 | 345 |
52 | 346 |
1 | 347 /** |
348 * Array of pairs giving the offset and type information for each | |
349 * member in an aggregate. | |
350 */ | |
351 struct OffsetTypeInfo | |
352 { | |
353 size_t offset; /// Offset of member from start of object | |
354 TypeInfo ti; /// TypeInfo for this member | |
355 } | |
356 | |
52 | 357 private int string_cmp(char[] s1, char[] s2) |
358 { | |
359 auto len = s1.length; | |
360 if (s2.length < len) | |
361 len = s2.length; | |
362 int result = memcmp(s1.ptr, s2.ptr, len); | |
363 if (result == 0) | |
364 result = cast(int)(cast(ptrdiff_t)s1.length - cast(ptrdiff_t)s2.length); | |
365 return result; | |
366 } | |
367 | |
1 | 368 /** |
369 * Runtime type information about a type. | |
370 * Can be retrieved for any type using a | |
371 * <a href="../expression.html#typeidexpression">TypeidExpression</a>. | |
372 */ | |
373 class TypeInfo | |
374 { | |
375 hash_t toHash() | |
376 { hash_t hash; | |
377 | |
378 foreach (char c; this.toString()) | |
379 hash = hash * 9 + c; | |
380 return hash; | |
381 } | |
382 | |
383 int opCmp(Object o) | |
384 { | |
385 if (this is o) | |
386 return 0; | |
387 TypeInfo ti = cast(TypeInfo)o; | |
388 if (ti is null) | |
389 return 1; | |
52 | 390 return string_cmp(this.toString(), ti.toString()); |
1 | 391 } |
392 | |
393 int opEquals(Object o) | |
394 { | |
395 /* TypeInfo instances are singletons, but duplicates can exist | |
396 * across DLL's. Therefore, comparing for a name match is | |
397 * sufficient. | |
398 */ | |
399 if (this is o) | |
400 return 1; | |
401 TypeInfo ti = cast(TypeInfo)o; | |
402 return cast(int)(ti && this.toString() == ti.toString()); | |
403 } | |
404 | |
405 /// Returns a hash of the instance of a type. | |
406 hash_t getHash(void *p) { return cast(uint)p; } | |
407 | |
408 /// Compares two instances for equality. | |
409 int equals(void *p1, void *p2) { return cast(int)(p1 == p2); } | |
410 | |
411 /// Compares two instances for <, ==, or >. | |
412 int compare(void *p1, void *p2) { return 0; } | |
413 | |
414 /// Returns size of the type. | |
415 size_t tsize() { return 0; } | |
416 | |
417 /// Swaps two instances of the type. | |
418 void swap(void *p1, void *p2) | |
419 { | |
420 size_t n = tsize(); | |
421 for (size_t i = 0; i < n; i++) | |
422 { byte t; | |
423 | |
424 t = (cast(byte *)p1)[i]; | |
425 (cast(byte *)p1)[i] = (cast(byte *)p2)[i]; | |
426 (cast(byte *)p2)[i] = t; | |
427 } | |
428 } | |
429 | |
430 /// Get TypeInfo for 'next' type, as defined by what kind of type this is, | |
431 /// null if none. | |
432 TypeInfo next() { return null; } | |
433 | |
434 /// Return default initializer, null if default initialize to 0 | |
435 void[] init() { return null; } | |
436 | |
437 /// Get flags for type: 1 means GC should scan for pointers | |
438 uint flags() { return 0; } | |
439 | |
440 /// Get type information on the contents of the type; null if not available | |
441 OffsetTypeInfo[] offTi() { return null; } | |
442 } | |
443 | |
444 class TypeInfo_Typedef : TypeInfo | |
445 { | |
446 char[] toString() { return name; } | |
447 | |
448 int opEquals(Object o) | |
449 { TypeInfo_Typedef c; | |
450 | |
451 return cast(int) | |
452 (this is o || | |
453 ((c = cast(TypeInfo_Typedef)o) !is null && | |
454 this.name == c.name && | |
455 this.base == c.base)); | |
456 } | |
457 | |
458 hash_t getHash(void *p) { return base.getHash(p); } | |
459 int equals(void *p1, void *p2) { return base.equals(p1, p2); } | |
460 int compare(void *p1, void *p2) { return base.compare(p1, p2); } | |
461 size_t tsize() { return base.tsize(); } | |
462 void swap(void *p1, void *p2) { return base.swap(p1, p2); } | |
463 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
464 TypeInfo next() { return base; } |
1 | 465 uint flags() { return base.flags(); } |
466 void[] init() { return m_init.length ? m_init : base.init(); } | |
467 | |
468 TypeInfo base; | |
469 char[] name; | |
470 void[] m_init; | |
471 } | |
472 | |
473 class TypeInfo_Enum : TypeInfo_Typedef | |
474 { | |
475 } | |
476 | |
477 class TypeInfo_Pointer : TypeInfo | |
478 { | |
479 char[] toString() { return m_next.toString() ~ "*"; } | |
480 | |
481 int opEquals(Object o) | |
482 { TypeInfo_Pointer c; | |
483 | |
484 return this is o || | |
485 ((c = cast(TypeInfo_Pointer)o) !is null && | |
486 this.m_next == c.m_next); | |
487 } | |
488 | |
489 hash_t getHash(void *p) | |
490 { | |
491 return cast(uint)*cast(void* *)p; | |
492 } | |
493 | |
494 int equals(void *p1, void *p2) | |
495 { | |
496 return cast(int)(*cast(void* *)p1 == *cast(void* *)p2); | |
497 } | |
498 | |
499 int compare(void *p1, void *p2) | |
500 { | |
501 if (*cast(void* *)p1 < *cast(void* *)p2) | |
502 return -1; | |
503 else if (*cast(void* *)p1 > *cast(void* *)p2) | |
504 return 1; | |
505 else | |
506 return 0; | |
507 } | |
508 | |
509 size_t tsize() | |
510 { | |
511 return (void*).sizeof; | |
512 } | |
513 | |
514 void swap(void *p1, void *p2) | |
515 { void* tmp; | |
516 tmp = *cast(void**)p1; | |
517 *cast(void**)p1 = *cast(void**)p2; | |
518 *cast(void**)p2 = tmp; | |
519 } | |
520 | |
521 TypeInfo next() { return m_next; } | |
522 uint flags() { return 1; } | |
523 | |
524 TypeInfo m_next; | |
525 } | |
526 | |
527 class TypeInfo_Array : TypeInfo | |
528 { | |
529 char[] toString() { return value.toString() ~ "[]"; } | |
530 | |
531 int opEquals(Object o) | |
532 { TypeInfo_Array c; | |
533 | |
534 return cast(int) | |
535 (this is o || | |
536 ((c = cast(TypeInfo_Array)o) !is null && | |
537 this.value == c.value)); | |
538 } | |
539 | |
540 hash_t getHash(void *p) | |
541 { size_t sz = value.tsize(); | |
542 hash_t hash = 0; | |
543 void[] a = *cast(void[]*)p; | |
544 for (size_t i = 0; i < a.length; i++) | |
545 hash += value.getHash(a.ptr + i * sz); | |
546 return hash; | |
547 } | |
548 | |
549 int equals(void *p1, void *p2) | |
550 { | |
551 void[] a1 = *cast(void[]*)p1; | |
552 void[] a2 = *cast(void[]*)p2; | |
553 if (a1.length != a2.length) | |
554 return 0; | |
555 size_t sz = value.tsize(); | |
556 for (size_t i = 0; i < a1.length; i++) | |
557 { | |
558 if (!value.equals(a1.ptr + i * sz, a2.ptr + i * sz)) | |
559 return 0; | |
560 } | |
561 return 1; | |
562 } | |
563 | |
564 int compare(void *p1, void *p2) | |
565 { | |
566 void[] a1 = *cast(void[]*)p1; | |
567 void[] a2 = *cast(void[]*)p2; | |
568 size_t sz = value.tsize(); | |
569 size_t len = a1.length; | |
570 | |
571 if (a2.length < len) | |
572 len = a2.length; | |
573 for (size_t u = 0; u < len; u++) | |
574 { | |
575 int result = value.compare(a1.ptr + u * sz, a2.ptr + u * sz); | |
576 if (result) | |
577 return result; | |
578 } | |
579 return cast(int)a1.length - cast(int)a2.length; | |
580 } | |
581 | |
582 size_t tsize() | |
583 { | |
584 return (void[]).sizeof; | |
585 } | |
586 | |
587 void swap(void *p1, void *p2) | |
588 { void[] tmp; | |
589 tmp = *cast(void[]*)p1; | |
590 *cast(void[]*)p1 = *cast(void[]*)p2; | |
591 *cast(void[]*)p2 = tmp; | |
592 } | |
593 | |
594 TypeInfo value; | |
595 | |
596 TypeInfo next() | |
597 { | |
598 return value; | |
599 } | |
600 | |
601 uint flags() { return 1; } | |
602 } | |
603 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
604 private const char[10] digits = "0123456789"; /// 0..9 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
605 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
606 private char[] lengthToString(uint u) |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
607 { char[uint.sizeof * 3] buffer = void; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
608 int ndigits; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
609 char[] result; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
610 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
611 ndigits = 0; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
612 if (u < 10) |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
613 // Avoid storage allocation for simple stuff |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
614 result = digits[u .. u + 1]; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
615 else |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
616 { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
617 while (u) |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
618 { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
619 uint c = (u % 10) + '0'; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
620 u /= 10; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
621 ndigits++; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
622 buffer[buffer.length - ndigits] = cast(char)c; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
623 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
624 result = new char[ndigits]; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
625 result[] = buffer[buffer.length - ndigits .. buffer.length]; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
626 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
627 return result; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
628 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
629 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
630 private char[] lengthToString(ulong u) |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
631 { char[ulong.sizeof * 3] buffer; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
632 int ndigits; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
633 char[] result; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
634 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
635 if (u < 0x1_0000_0000) |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
636 return lengthToString(cast(uint)u); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
637 ndigits = 0; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
638 while (u) |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
639 { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
640 char c = cast(char)((u % 10) + '0'); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
641 u /= 10; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
642 ndigits++; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
643 buffer[buffer.length - ndigits] = c; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
644 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
645 result = new char[ndigits]; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
646 result[] = buffer[buffer.length - ndigits .. buffer.length]; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
647 return result; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
648 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
649 |
1 | 650 class TypeInfo_StaticArray : TypeInfo |
651 { | |
652 char[] toString() | |
653 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
654 return value.toString() ~ "[" ~ lengthToString(len) ~ "]"; |
1 | 655 } |
656 | |
657 int opEquals(Object o) | |
658 { TypeInfo_StaticArray c; | |
659 | |
660 return cast(int) | |
661 (this is o || | |
662 ((c = cast(TypeInfo_StaticArray)o) !is null && | |
663 this.len == c.len && | |
664 this.value == c.value)); | |
665 } | |
666 | |
667 hash_t getHash(void *p) | |
668 { size_t sz = value.tsize(); | |
669 hash_t hash = 0; | |
670 for (size_t i = 0; i < len; i++) | |
671 hash += value.getHash(p + i * sz); | |
672 return hash; | |
673 } | |
674 | |
675 int equals(void *p1, void *p2) | |
676 { | |
677 size_t sz = value.tsize(); | |
678 | |
679 for (size_t u = 0; u < len; u++) | |
680 { | |
681 if (!value.equals(p1 + u * sz, p2 + u * sz)) | |
682 return 0; | |
683 } | |
684 return 1; | |
685 } | |
686 | |
687 int compare(void *p1, void *p2) | |
688 { | |
689 size_t sz = value.tsize(); | |
690 | |
691 for (size_t u = 0; u < len; u++) | |
692 { | |
693 int result = value.compare(p1 + u * sz, p2 + u * sz); | |
694 if (result) | |
695 return result; | |
696 } | |
697 return 0; | |
698 } | |
699 | |
700 size_t tsize() | |
701 { | |
702 return len * value.tsize(); | |
703 } | |
704 | |
705 void swap(void *p1, void *p2) | |
706 { void* tmp; | |
707 size_t sz = value.tsize(); | |
708 ubyte[16] buffer; | |
709 void* pbuffer; | |
710 | |
711 if (sz < buffer.sizeof) | |
712 tmp = buffer.ptr; | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
713 else { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
714 if (value.flags() & 1) |
1 | 715 tmp = pbuffer = (new void[sz]).ptr; |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
716 else |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
717 tmp = pbuffer = (new byte[sz]).ptr; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
718 } |
1 | 719 |
720 for (size_t u = 0; u < len; u += sz) | |
721 { size_t o = u * sz; | |
722 memcpy(tmp, p1 + o, sz); | |
723 memcpy(p1 + o, p2 + o, sz); | |
724 memcpy(p2 + o, tmp, sz); | |
725 } | |
726 if (pbuffer) | |
727 delete pbuffer; | |
728 } | |
729 | |
730 void[] init() { return value.init(); } | |
731 TypeInfo next() { return value; } | |
732 uint flags() { return value.flags(); } | |
733 | |
734 TypeInfo value; | |
735 size_t len; | |
736 } | |
737 | |
738 class TypeInfo_AssociativeArray : TypeInfo | |
739 { | |
740 char[] toString() | |
741 { | |
742 return value.toString() ~ "[" ~ key.toString() ~ "]"; | |
743 } | |
744 | |
745 int opEquals(Object o) | |
746 { TypeInfo_AssociativeArray c; | |
747 | |
748 return this is o || | |
749 ((c = cast(TypeInfo_AssociativeArray)o) !is null && | |
750 this.key == c.key && | |
751 this.value == c.value); | |
752 } | |
753 | |
754 // BUG: need to add the rest of the functions | |
755 | |
756 size_t tsize() | |
757 { | |
758 return (char[int]).sizeof; | |
759 } | |
760 | |
761 TypeInfo next() { return value; } | |
762 uint flags() { return 1; } | |
763 | |
764 TypeInfo value; | |
765 TypeInfo key; | |
766 } | |
767 | |
768 class TypeInfo_Function : TypeInfo | |
769 { | |
770 char[] toString() | |
771 { | |
772 return next.toString() ~ "()"; | |
773 } | |
774 | |
775 int opEquals(Object o) | |
776 { TypeInfo_Function c; | |
777 | |
778 return this is o || | |
779 ((c = cast(TypeInfo_Function)o) !is null && | |
780 this.next == c.next); | |
781 } | |
782 | |
783 // BUG: need to add the rest of the functions | |
784 | |
785 size_t tsize() | |
786 { | |
787 return 0; // no size for functions | |
788 } | |
789 | |
790 TypeInfo next; | |
791 } | |
792 | |
793 class TypeInfo_Delegate : TypeInfo | |
794 { | |
795 char[] toString() | |
796 { | |
797 return next.toString() ~ " delegate()"; | |
798 } | |
799 | |
800 int opEquals(Object o) | |
801 { TypeInfo_Delegate c; | |
802 | |
803 return this is o || | |
804 ((c = cast(TypeInfo_Delegate)o) !is null && | |
805 this.next == c.next); | |
806 } | |
807 | |
808 // BUG: need to add the rest of the functions | |
809 | |
810 size_t tsize() | |
811 { alias int delegate() dg; | |
812 return dg.sizeof; | |
813 } | |
814 | |
815 uint flags() { return 1; } | |
816 | |
817 TypeInfo next; | |
818 } | |
819 | |
820 class TypeInfo_Class : TypeInfo | |
821 { | |
822 char[] toString() { return info.name; } | |
823 | |
824 int opEquals(Object o) | |
825 { TypeInfo_Class c; | |
826 | |
827 return this is o || | |
828 ((c = cast(TypeInfo_Class)o) !is null && | |
829 this.info.name == c.classinfo.name); | |
830 } | |
831 | |
832 hash_t getHash(void *p) | |
833 { | |
834 Object o = *cast(Object*)p; | |
835 assert(o); | |
836 return o.toHash(); | |
837 } | |
838 | |
839 int equals(void *p1, void *p2) | |
840 { | |
841 Object o1 = *cast(Object*)p1; | |
842 Object o2 = *cast(Object*)p2; | |
843 | |
844 return (o1 is o2) || (o1 && o1.opEquals(o2)); | |
845 } | |
846 | |
847 int compare(void *p1, void *p2) | |
848 { | |
849 Object o1 = *cast(Object*)p1; | |
850 Object o2 = *cast(Object*)p2; | |
851 int c = 0; | |
852 | |
853 // Regard null references as always being "less than" | |
854 if (o1 !is o2) | |
855 { | |
856 if (o1) | |
857 { if (!o2) | |
858 c = 1; | |
859 else | |
860 c = o1.opCmp(o2); | |
861 } | |
862 else | |
863 c = -1; | |
864 } | |
865 return c; | |
866 } | |
867 | |
868 size_t tsize() | |
869 { | |
870 return Object.sizeof; | |
871 } | |
872 | |
873 uint flags() { return 1; } | |
874 | |
875 OffsetTypeInfo[] offTi() | |
876 { | |
877 return (info.flags & 4) ? info.offTi : null; | |
878 } | |
879 | |
880 ClassInfo info; | |
881 } | |
882 | |
883 class TypeInfo_Interface : TypeInfo | |
884 { | |
885 char[] toString() { return info.name; } | |
886 | |
887 int opEquals(Object o) | |
888 { TypeInfo_Interface c; | |
889 | |
890 return this is o || | |
891 ((c = cast(TypeInfo_Interface)o) !is null && | |
892 this.info.name == c.classinfo.name); | |
893 } | |
894 | |
895 hash_t getHash(void *p) | |
896 { | |
897 Interface* pi = **cast(Interface ***)*cast(void**)p; | |
898 Object o = cast(Object)(*cast(void**)p - pi.offset); | |
899 assert(o); | |
900 return o.toHash(); | |
901 } | |
902 | |
903 int equals(void *p1, void *p2) | |
904 { | |
905 Interface* pi = **cast(Interface ***)*cast(void**)p1; | |
906 Object o1 = cast(Object)(*cast(void**)p1 - pi.offset); | |
907 pi = **cast(Interface ***)*cast(void**)p2; | |
908 Object o2 = cast(Object)(*cast(void**)p2 - pi.offset); | |
909 | |
910 return o1 == o2 || (o1 && o1.opCmp(o2) == 0); | |
911 } | |
912 | |
913 int compare(void *p1, void *p2) | |
914 { | |
915 Interface* pi = **cast(Interface ***)*cast(void**)p1; | |
916 Object o1 = cast(Object)(*cast(void**)p1 - pi.offset); | |
917 pi = **cast(Interface ***)*cast(void**)p2; | |
918 Object o2 = cast(Object)(*cast(void**)p2 - pi.offset); | |
919 int c = 0; | |
920 | |
921 // Regard null references as always being "less than" | |
922 if (o1 != o2) | |
923 { | |
924 if (o1) | |
925 { if (!o2) | |
926 c = 1; | |
927 else | |
928 c = o1.opCmp(o2); | |
929 } | |
930 else | |
931 c = -1; | |
932 } | |
933 return c; | |
934 } | |
935 | |
936 size_t tsize() | |
937 { | |
938 return Object.sizeof; | |
939 } | |
940 | |
941 uint flags() { return 1; } | |
942 | |
943 ClassInfo info; | |
944 } | |
945 | |
946 class TypeInfo_Struct : TypeInfo | |
947 { | |
948 char[] toString() { return name; } | |
949 | |
950 int opEquals(Object o) | |
951 { TypeInfo_Struct s; | |
952 | |
953 return this is o || | |
954 ((s = cast(TypeInfo_Struct)o) !is null && | |
955 this.name == s.name && | |
956 this.init.length == s.init.length); | |
957 } | |
958 | |
959 hash_t getHash(void *p) | |
960 { hash_t h; | |
961 | |
962 assert(p); | |
963 if (xtoHash) | |
964 { //printf("getHash() using xtoHash\n"); | |
965 h = (*xtoHash)(p); | |
966 } | |
967 else | |
968 { | |
969 //printf("getHash() using default hash\n"); | |
970 // A sorry hash algorithm. | |
971 // Should use the one for strings. | |
972 // BUG: relies on the GC not moving objects | |
973 for (size_t i = 0; i < init.length; i++) | |
974 { h = h * 9 + *cast(ubyte*)p; | |
975 p++; | |
976 } | |
977 } | |
978 return h; | |
979 } | |
980 | |
73 | 981 int equals(void *p1, void *p2) |
1 | 982 { int c; |
983 | |
984 if (p1 == p2) | |
985 c = 1; | |
986 else if (!p1 || !p2) | |
987 c = 0; | |
988 else if (xopEquals) | |
989 c = (*xopEquals)(p1, p2); | |
990 else | |
991 // BUG: relies on the GC not moving objects | |
992 c = (memcmp(p1, p2, init.length) == 0); | |
993 return c; | |
994 } | |
995 | |
72 | 996 int compare(void *p1, void *p2) |
1 | 997 { |
998 int c = 0; | |
999 | |
1000 // Regard null references as always being "less than" | |
1001 if (p1 != p2) | |
1002 { | |
1003 if (p1) | |
1004 { if (!p2) | |
1005 c = 1; | |
1006 else if (xopCmp) | |
1007 c = (*xopCmp)(p1, p2); | |
1008 else | |
1009 // BUG: relies on the GC not moving objects | |
1010 c = memcmp(p1, p2, init.length); | |
1011 } | |
1012 else | |
1013 c = -1; | |
1014 } | |
1015 return c; | |
1016 } | |
1017 | |
1018 size_t tsize() | |
1019 { | |
1020 return init.length; | |
1021 } | |
1022 | |
1023 void[] init() { return m_init; } | |
1024 | |
1025 uint flags() { return m_flags; } | |
1026 | |
1027 char[] name; | |
1028 void[] m_init; // initializer; init.ptr == null if 0 initialize | |
1029 | |
1030 hash_t function(void*) xtoHash; | |
1031 int function(void*,void*) xopEquals; | |
1032 int function(void*,void*) xopCmp; | |
1033 char[] function(void*) xtoString; | |
1034 | |
1035 uint m_flags; | |
1036 } | |
1037 | |
1038 class TypeInfo_Tuple : TypeInfo | |
1039 { | |
1040 TypeInfo[] elements; | |
1041 | |
1042 char[] toString() | |
1043 { | |
1044 char[] s; | |
1045 s = "("; | |
1046 foreach (i, element; elements) | |
1047 { | |
1048 if (i) | |
1049 s ~= ','; | |
1050 s ~= element.toString(); | |
1051 } | |
1052 s ~= ")"; | |
1053 return s; | |
1054 } | |
1055 | |
1056 int opEquals(Object o) | |
1057 { | |
1058 if (this is o) | |
1059 return 1; | |
1060 | |
1061 auto t = cast(TypeInfo_Tuple)o; | |
1062 if (t && elements.length == t.elements.length) | |
1063 { | |
1064 for (size_t i = 0; i < elements.length; i++) | |
1065 { | |
1066 if (elements[i] != t.elements[i]) | |
1067 return 0; | |
1068 } | |
1069 return 1; | |
1070 } | |
1071 return 0; | |
1072 } | |
1073 | |
1074 hash_t getHash(void *p) | |
1075 { | |
1076 assert(0); | |
1077 } | |
1078 | |
1079 int equals(void *p1, void *p2) | |
1080 { | |
1081 assert(0); | |
1082 } | |
1083 | |
1084 int compare(void *p1, void *p2) | |
1085 { | |
1086 assert(0); | |
1087 } | |
1088 | |
1089 size_t tsize() | |
1090 { | |
1091 assert(0); | |
1092 } | |
1093 | |
1094 void swap(void *p1, void *p2) | |
1095 { | |
1096 assert(0); | |
1097 } | |
1098 } | |
52 | 1099 |
1100 class TypeInfo_Const : TypeInfo | |
1101 { | |
1102 char[] toString() { return "const " ~ base.toString(); } | |
1103 | |
1104 int opEquals(Object o) { return base.opEquals(o); } | |
1105 hash_t getHash(void *p) { return base.getHash(p); } | |
1106 int equals(void *p1, void *p2) { return base.equals(p1, p2); } | |
1107 int compare(void *p1, void *p2) { return base.compare(p1, p2); } | |
1108 size_t tsize() { return base.tsize(); } | |
1109 void swap(void *p1, void *p2) { return base.swap(p1, p2); } | |
1110 | |
1111 TypeInfo next() { return base.next(); } | |
1112 uint flags() { return base.flags(); } | |
1113 void[] init() { return base.init(); } | |
1114 | |
1115 TypeInfo base; | |
1116 } | |
1117 | |
1118 class TypeInfo_Invariant : TypeInfo_Const | |
1119 { | |
1120 char[] toString() { return "invariant " ~ base.toString(); } | |
1121 } | |
1122 | |
1 | 1123 /** |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1124 * Information about each module. |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1125 */ |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1126 class ModuleInfo |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1127 { |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1128 char[] name; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1129 ModuleInfo[] importedModules; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1130 ClassInfo[] localClasses; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1131 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1132 uint flags; // initialization state |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1133 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1134 void function() ctor; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1135 void function() dtor; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1136 void function() unitTest; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1137 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1138 /****************** |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1139 * Return collection of all modules in the program. |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1140 */ |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1141 static ModuleInfo[] modules() |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1142 { |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1143 return std.moduleinit._moduleinfo_array; |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1144 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1145 } |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1146 |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
113
diff
changeset
|
1147 /** |
1 | 1148 * All recoverable exceptions should be derived from class Exception. |
1149 */ | |
1150 class Exception : Object | |
1151 { | |
1152 char[] msg; | |
1153 | |
1154 /** | |
1155 * Constructor; msg is a descriptive message for the exception. | |
1156 */ | |
1157 this(char[] msg) | |
1158 { | |
1159 this.msg = msg; | |
1160 } | |
1161 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
73
diff
changeset
|
1162 void print() |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
73
diff
changeset
|
1163 { |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
73
diff
changeset
|
1164 char[] s = toString(); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
73
diff
changeset
|
1165 printf("%.*s\n", s.length, s.ptr); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
73
diff
changeset
|
1166 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
73
diff
changeset
|
1167 |
1 | 1168 char[] toString() { return msg; } |
1169 } | |
1170 | |
1171 /** | |
1172 * All irrecoverable exceptions should be derived from class Error. | |
1173 */ | |
1174 class Error : Exception | |
1175 { | |
1176 Error next; | |
1177 | |
1178 /** | |
1179 * Constructor; msg is a descriptive message for the exception. | |
1180 */ | |
1181 this(char[] msg) | |
1182 { | |
1183 super(msg); | |
1184 } | |
1185 | |
1186 this(char[] msg, Error next) | |
1187 { | |
1188 super(msg); | |
1189 this.next = next; | |
1190 } | |
1191 } | |
1192 | |
1193 //extern (C) int nullext = 0; | |
52 | 1194 |