comparison tango/lib/compiler/llvmdc/cast.d @ 136:0e28624814e8 trunk

[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
author lindquist
date Thu, 17 Jan 2008 03:15:12 +0100
parents 44a95ac7368a
children ce7b81fb957f
comparison
equal deleted inserted replaced
135:176bd52b3cf5 136:0e28624814e8
25 * Modified by Sean Kelly <sean@f4.ca> for use with Tango. 25 * Modified by Sean Kelly <sean@f4.ca> for use with Tango.
26 */ 26 */
27 27
28 extern (C): 28 extern (C):
29 29
30 debug = PRINTF;
31 debug(PRINTF) int printf(char*, ...);
32
30 /****************************************** 33 /******************************************
31 * Given a pointer: 34 * Given a pointer:
32 * If it is an Object, return that Object. 35 * If it is an Object, return that Object.
33 * If it is an interface, return the Object implementing the interface. 36 * If it is an interface, return the Object implementing the interface.
34 * If it is null, return null. 37 * If it is null, return null.
52 { 55 {
53 //printf("\tpi.offset = %d\n", pi.offset); 56 //printf("\tpi.offset = %d\n", pi.offset);
54 o = cast(Object)(p - pi.offset); 57 o = cast(Object)(p - pi.offset);
55 } 58 }
56 } 59 }
60 debug(PRINTF) printf("toObject = %p\n", o);
57 return o; 61 return o;
58 } 62 }
59 63
60 64
61 /************************************* 65 /*************************************
73 77
74 //printf("\tpi.offset = %d\n", pi.offset); 78 //printf("\tpi.offset = %d\n", pi.offset);
75 o = cast(Object)(p - pi.offset); 79 o = cast(Object)(p - pi.offset);
76 return _d_dynamic_cast(o, c); 80 return _d_dynamic_cast(o, c);
77 } 81 }
82 debug(PRINTF) printf("_d_interface_cast = %p\n", o);
78 return o; 83 return o;
79 } 84 }
80 85
81 Object _d_dynamic_cast(Object o, ClassInfo c) 86 Object _d_dynamic_cast(Object o, ClassInfo c)
82 { ClassInfo oc; 87 { ClassInfo oc;
83 size_t offset = 0; 88 size_t offset = 0;
84 89
85 //printf("_d_dynamic_cast(o = %p, c = '%.*s')\n", o, c.name); 90 debug(PRINTF) printf("_d_dynamic_cast(o = %p, c = '%.*s')\n", o, c.name.length, c.name.ptr);
86 91
87 if (o) 92 if (o)
88 { 93 {
89 oc = o.classinfo; 94 oc = o.classinfo;
90 if (_d_isbaseof2(oc, c, offset)) 95 if (_d_isbaseof2(oc, c, offset))
94 } 99 }
95 else 100 else
96 o = null; 101 o = null;
97 } 102 }
98 //printf("\tresult = %p\n", o); 103 //printf("\tresult = %p\n", o);
104 debug(PRINTF) printf("_d_dynamic_cast = %p\n", o);
99 return o; 105 return o;
100 } 106 }
101 107
102 int _d_isbaseof2(ClassInfo oc, ClassInfo c, ref size_t offset) 108 int _d_isbaseof2(ClassInfo oc, ClassInfo c, ref size_t offset)
103 { int i; 109 { int i;
104 110
111 debug(PRINTF) printf("_d_isbaseof2(%.*s, %.*s, %ul)\n", oc.name.length, oc.name.ptr, c.name.length, c.name.ptr, offset);
112
105 if (oc is c) 113 if (oc is c)
106 return 1; 114 return 1;
107 do 115 do
108 { 116 {
117 debug(PRINTF) printf("oc.interfaces.length = %ul\n", oc.interfaces.length);
109 if (oc.base is c) 118 if (oc.base is c)
110 return 1; 119 return 1;
111 for (i = 0; i < oc.interfaces.length; i++) 120 for (i = 0; i < oc.interfaces.length; i++)
112 { 121 {
113 ClassInfo ic; 122 ClassInfo ic;
114 123
115 ic = oc.interfaces[i].classinfo; 124 ic = oc.interfaces[i].classinfo;
125 debug(PRINTF) printf("checking %.*s\n", ic.name.length, ic.name.ptr);
116 if (ic is c) 126 if (ic is c)
117 { offset = cast(size_t)oc.interfaces[i].offset; 127 { offset = cast(size_t)oc.interfaces[i].offset;
118 return 1; 128 return 1;
119 } 129 }
120 } 130 }