Scan dynamic libraries for GC roots
[delight/core.git] / phobos2 / object.d
blobb95eac072f9b1293e33861141bdb329ad11d2ddf
2 // Implementation is in internal\object.d
4 module object;
6 alias bool bit;
8 alias typeof(int.sizeof) size_t;
9 alias typeof(cast(void*)0 - cast(void*)0) ptrdiff_t;
10 alias size_t hash_t;
12 alias invariant(char)[] string;
13 alias invariant(wchar)[] wstring;
14 alias invariant(dchar)[] dstring;
16 extern (C)
17 { int printf(in char *, ...);
20 class Object
22 void print();
23 string toString();
24 hash_t toHash();
25 int opCmp(Object o);
26 int opEquals(Object o);
28 final void notifyRegister(void delegate(Object) dg);
29 final void notifyUnRegister(void delegate(Object) dg);
31 static Object factory(string classname);
34 struct Interface
36 ClassInfo classinfo;
37 void *[] vtbl;
38 ptrdiff_t offset; // offset to Interface 'this' from Object 'this'
41 class ClassInfo : Object
43 byte[] init; // class static initializer
44 string name; // class name
45 void *[] vtbl; // virtual function pointer table
46 Interface[] interfaces;
47 ClassInfo base;
48 void *destructor;
49 void (*classInvariant)(Object);
50 uint flags;
51 // 1: // is IUnknown or is derived from IUnknown
52 // 2: // has no possible pointers into GC memory
53 // 4: // has offTi[] member
54 // 8: // has constructors
55 // 16: // has xgetMembers member
56 void *deallocator;
57 OffsetTypeInfo[] offTi;
58 void* defaultConstructor; // default Constructor
59 const(MemberInfo[]) function(string) xgetMembers;
61 static ClassInfo find(string classname);
62 Object create();
63 const(MemberInfo[]) getMembers(string);
66 struct OffsetTypeInfo
68 size_t offset;
69 TypeInfo ti;
72 class TypeInfo
74 hash_t getHash(in void *p);
75 int equals(in void *p1, in void *p2);
76 int compare(in void *p1, in void *p2);
77 size_t tsize();
78 void swap(void *p1, void *p2);
79 TypeInfo next();
80 void[] init();
81 uint flags();
82 // 1: // has possible pointers into GC memory
83 OffsetTypeInfo[] offTi();
84 void destroy(void *p);
85 void postblit(void *p);
88 class TypeInfo_Typedef : TypeInfo
90 TypeInfo base;
91 string name;
92 void[] m_init;
95 class TypeInfo_Enum : TypeInfo_Typedef
99 class TypeInfo_Pointer : TypeInfo
101 TypeInfo m_next;
104 class TypeInfo_Array : TypeInfo
106 TypeInfo value;
109 class TypeInfo_StaticArray : TypeInfo
111 TypeInfo value;
112 size_t len;
115 class TypeInfo_AssociativeArray : TypeInfo
117 TypeInfo value;
118 TypeInfo key;
121 class TypeInfo_Function : TypeInfo
123 TypeInfo next;
126 class TypeInfo_Delegate : TypeInfo
128 TypeInfo next;
131 class TypeInfo_Class : TypeInfo
133 ClassInfo info;
136 class TypeInfo_Interface : TypeInfo
138 ClassInfo info;
141 class TypeInfo_Struct : TypeInfo
143 string name;
144 void[] m_init;
146 uint function(in void*) xtoHash;
147 int function(in void*, in void*) xopEquals;
148 int function(in void*, in void*) xopCmp;
149 string function(const(void)*) xtoString;
151 uint m_flags;
153 const(MemberInfo[]) function(string) xgetMembers;
154 void function(void*) xdtor;
155 void function(void*) xpostblit;
158 class TypeInfo_Tuple : TypeInfo
160 TypeInfo[] elements;
163 class TypeInfo_Const : TypeInfo
165 TypeInfo next;
168 class TypeInfo_Invariant : TypeInfo_Const
172 abstract class MemberInfo
174 string name();
177 class MemberInfo_field : MemberInfo
179 this(string name, TypeInfo ti, size_t offset);
181 override string name();
182 TypeInfo typeInfo();
183 size_t offset();
186 class MemberInfo_function : MemberInfo
188 enum
189 { Virtual = 1,
190 Member = 2,
191 Static = 4,
194 this(string name, TypeInfo ti, void* fp, uint flags);
196 override string name();
197 TypeInfo typeInfo();
198 void* fp();
199 uint flags();
202 // Recoverable errors
204 class Exception : Object
206 string msg;
207 Exception next;
209 this(string msg);
210 this(string msg, Error next);
212 void print();
213 string toString();
216 // Non-recoverable errors
218 class Error : Exception
220 this(string msg);
221 this(string msg, Error next);
224 /** If the top-level main throws this, the message will be printed to stderr
225 * and the program terminates with the given exit code.
227 class SystemExit : Exception {
228 int exitCode;
230 this(string msg, int exitCode = 1);