Mercurial > projects > ldc
comparison lphobos/internal/objectimpl.d @ 89:ccca1c13e13a trunk
[svn r93] a few fixes, some phobos additions.
some very rough groundwork for moduleinfo and classinfo support
author | lindquist |
---|---|
date | Wed, 07 Nov 2007 02:45:47 +0100 |
parents | fd32135dca3e |
children | 5b5194b25f33 |
comparison
equal
deleted
inserted
replaced
88:058d3925950e | 89:ccca1c13e13a |
---|---|
30 * be misrepresented as being the original software. | 30 * be misrepresented as being the original software. |
31 * o This notice may not be removed or altered from any source | 31 * o This notice may not be removed or altered from any source |
32 * distribution. | 32 * distribution. |
33 */ | 33 */ |
34 | 34 |
35 /* | |
36 * This copy is modified to work with LLVMDC by Tomas Lindquist Olsen 2007 | |
37 */ | |
35 | 38 |
36 module object; | 39 module object; |
37 | 40 |
38 //import std.outofmemory; | 41 import std.outofmemory; |
39 | 42 |
40 /** | 43 /** |
41 * An unsigned integral type large enough to span the memory space. Use for | 44 * An unsigned integral type large enough to span the memory space. Use for |
42 * array indices and pointer offsets for maximal portability to | 45 * array indices and pointer offsets for maximal portability to |
43 * architectures that have different memory address ranges. This is | 46 * architectures that have different memory address ranges. This is |
258 | 261 |
259 free(dgs.ptr); | 262 free(dgs.ptr); |
260 } | 263 } |
261 } | 264 } |
262 | 265 |
266 +/ | |
267 | |
263 /** | 268 /** |
264 * Information about an interface. | 269 * Information about an interface. |
265 * A pointer to this appears as the first entry in the interface's vtbl[]. | 270 * A pointer to this appears as the first entry in the interface's vtbl[]. |
266 */ | 271 */ |
267 struct Interface | 272 struct Interface |
270 void *[] vtbl; | 275 void *[] vtbl; |
271 int offset; /// offset to Interface 'this' from Object 'this' | 276 int offset; /// offset to Interface 'this' from Object 'this' |
272 } | 277 } |
273 | 278 |
274 import std.moduleinit; | 279 import std.moduleinit; |
280 | |
275 /** | 281 /** |
276 * Runtime type information about a class. Can be retrieved for any class type | 282 * Runtime type information about a class. Can be retrieved for any class type |
277 * or instance by using the .classinfo property. | 283 * or instance by using the .classinfo property. |
278 * A pointer to this appears as the first entry in the class's vtbl[]. | 284 * A pointer to this appears as the first entry in the class's vtbl[]. |
279 */ | 285 */ |
285 char[] name; /// class name | 291 char[] name; /// class name |
286 void *[] vtbl; /// virtual function pointer table | 292 void *[] vtbl; /// virtual function pointer table |
287 Interface[] interfaces; /// interfaces this class implements | 293 Interface[] interfaces; /// interfaces this class implements |
288 ClassInfo base; /// base class | 294 ClassInfo base; /// base class |
289 void *destructor; | 295 void *destructor; |
290 void (*classInvariant)(Object); | 296 void function(Object) classInvariant; |
291 uint flags; | 297 uint flags; |
292 // 1: // IUnknown | 298 // 1: // IUnknown |
293 // 2: // has no possible pointers into GC memory | 299 // 2: // has no possible pointers into GC memory |
294 // 4: // has offTi[] member | 300 // 4: // has offTi[] member |
295 // 8: // has constructors | 301 // 8: // has constructors |
301 * Search all modules for ClassInfo corresponding to classname. | 307 * Search all modules for ClassInfo corresponding to classname. |
302 * Returns: null if not found | 308 * Returns: null if not found |
303 */ | 309 */ |
304 static ClassInfo find(char[] classname) | 310 static ClassInfo find(char[] classname) |
305 { | 311 { |
306 foreach (m; ModuleInfo.modules()) | 312 /+foreach (m; ModuleInfo.modules()) |
307 { | 313 { |
308 //writefln("module %s, %d", m.name, m.localClasses.length); | 314 //writefln("module %s, %d", m.name, m.localClasses.length); |
309 foreach (c; m.localClasses) | 315 foreach (c; m.localClasses) |
310 { | 316 { |
311 //writefln("\tclass %s", c.name); | 317 //writefln("\tclass %s", c.name); |
312 if (c.name == classname) | 318 if (c.name == classname) |
313 return c; | 319 return c; |
314 } | 320 } |
315 } | 321 }+/ |
316 return null; | 322 return null; |
317 } | 323 } |
318 | 324 |
319 /******************** | 325 /******************** |
320 * Create instance of Object represented by 'this'. | 326 * Create instance of Object represented by 'this'. |
321 */ | 327 */ |
322 Object create() | 328 Object create() |
323 { | 329 { |
324 if (flags & 8 && !defaultConstructor) | 330 /+if (flags & 8 && !defaultConstructor) |
325 return null; | 331 return null; |
326 Object o = _d_newclass(this); | 332 Object o = _d_newclass(this); |
327 if (flags & 8 && defaultConstructor) | 333 if (flags & 8 && defaultConstructor) |
328 { | 334 { |
329 defaultConstructor(o); | 335 defaultConstructor(o); |
330 } | 336 } |
331 return o; | 337 return o; |
332 } | 338 +/ |
333 } | 339 return null; |
334 | 340 } |
335 private import std.string; | 341 } |
336 | 342 |
337 +/ | 343 //private import std.string; |
344 | |
338 | 345 |
339 /** | 346 /** |
340 * Array of pairs giving the offset and type information for each | 347 * Array of pairs giving the offset and type information for each |
341 * member in an aggregate. | 348 * member in an aggregate. |
342 */ | 349 */ |