Mercurial > projects > ldc
comparison tango/lib/compiler/llvmdc/cast.d @ 137:ce7b81fb957f trunk
[svn r141] fixed more problems with classinfo
moved more IR state out of the AST classes
author | lindquist |
---|---|
date | Fri, 18 Jan 2008 16:42:16 +0100 |
parents | 0e28624814e8 |
children | 0ab29b838084 |
comparison
equal
deleted
inserted
replaced
136:0e28624814e8 | 137:ce7b81fb957f |
---|---|
38 * Else, undefined crash | 38 * Else, undefined crash |
39 */ | 39 */ |
40 | 40 |
41 Object _d_toObject(void* p) | 41 Object _d_toObject(void* p) |
42 { Object o; | 42 { Object o; |
43 | 43 debug(PRINTF) printf("toObject(%p)\n", p); |
44 if (p) | 44 if (p) |
45 { | 45 { |
46 o = cast(Object)p; | 46 o = cast(Object)p; |
47 debug(PRINTF) printf("o = %p\n", o); | |
48 debug(PRINTF) printf("o.vtbl = %p\n", *cast(void**)p); | |
47 ClassInfo oc = o.classinfo; | 49 ClassInfo oc = o.classinfo; |
50 debug(PRINTF) printf("oc = %p\n", oc); | |
48 Interface *pi = **cast(Interface ***)p; | 51 Interface *pi = **cast(Interface ***)p; |
52 debug(PRINTF) printf("pi = %p\n", pi); | |
49 | 53 |
50 /* Interface.offset lines up with ClassInfo.name.ptr, | 54 /* Interface.offset lines up with ClassInfo.name.ptr, |
51 * so we rely on pointers never being less than 64K, | 55 * so we rely on pointers never being less than 64K, |
52 * and Objects never being greater. | 56 * and interface vtable offsets never being greater. |
53 */ | 57 */ |
54 if (pi.offset < 0x10000) | 58 if (pi.offset < 0x10000) |
55 { | 59 { |
56 //printf("\tpi.offset = %d\n", pi.offset); | 60 debug(PRINTF) printf("\tpi.offset = %d\n", pi.offset); |
57 o = cast(Object)(p - pi.offset); | 61 o = cast(Object)(p - pi.offset); |
58 } | 62 } |
59 } | 63 } |
60 debug(PRINTF) printf("toObject = %p\n", o); | 64 debug(PRINTF) printf("toObject = %p\n", o); |
61 return o; | 65 return o; |
68 */ | 72 */ |
69 | 73 |
70 Object _d_interface_cast(void* p, ClassInfo c) | 74 Object _d_interface_cast(void* p, ClassInfo c) |
71 { Object o; | 75 { Object o; |
72 | 76 |
73 //printf("_d_interface_cast(p = %p, c = '%.*s')\n", p, c.name); | 77 debug(PRINTF) printf("_d_interface_cast(p = %p, c = '%.*s')\n", p, c.name.length, c.name.ptr); |
74 if (p) | 78 if (p) |
75 { | 79 { |
76 Interface *pi = **cast(Interface ***)p; | 80 Interface *pi = **cast(Interface ***)p; |
77 | 81 |
78 //printf("\tpi.offset = %d\n", pi.offset); | 82 debug(PRINTF) printf("\tpi.offset = %d\n", pi.offset); |
79 o = cast(Object)(p - pi.offset); | 83 o = cast(Object)(p - pi.offset); |
80 return _d_dynamic_cast(o, c); | 84 return _d_dynamic_cast(o, c); |
81 } | 85 } |
82 debug(PRINTF) printf("_d_interface_cast = %p\n", o); | 86 debug(PRINTF) printf("_d_interface_cast = %p\n", o); |
83 return o; | 87 return o; |
92 if (o) | 96 if (o) |
93 { | 97 { |
94 oc = o.classinfo; | 98 oc = o.classinfo; |
95 if (_d_isbaseof2(oc, c, offset)) | 99 if (_d_isbaseof2(oc, c, offset)) |
96 { | 100 { |
97 //printf("\toffset = %d\n", offset); | 101 debug(PRINTF) printf("\toffset = %d\n", offset); |
98 o = cast(Object)(cast(void*)o + offset); | 102 o = cast(Object)(cast(void*)o + offset); |
99 } | 103 } |
100 else | 104 else |
101 o = null; | 105 o = null; |
102 } | 106 } |