 |
Changeset 2148
- Timestamp:
- 05/04/07 14:28:14
(2 years ago)
- Author:
- sean
- Message:
Exposed ModuleInfo? in object.di. This closes ticket #433.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r2076 |
r2148 |
|
| 129 | 129 | struct Interface |
|---|
| 130 | 130 | { |
|---|
| 131 | | ClassInfo classinfo; /// .classinfo for this interface (not for containing class) |
|---|
| 132 | | void *[] vtbl; |
|---|
| 133 | | ptrdiff_t offset; /// offset to Interface 'this' from Object 'this' |
|---|
| | 131 | ClassInfo classinfo; /// .classinfo for this interface (not for containing class) |
|---|
| | 132 | void*[] vtbl; |
|---|
| | 133 | ptrdiff_t offset; /// offset to Interface 'this' from Object 'this' |
|---|
| 134 | 134 | } |
|---|
| 135 | 135 | |
|---|
| … | … | |
| 141 | 141 | class ClassInfo : Object |
|---|
| 142 | 142 | { |
|---|
| 143 | | byte[] init; /** class static initializer |
|---|
| | 143 | byte[] init; /** class static initializer |
|---|
| 144 | 144 | * (init.length gives size in bytes of class) |
|---|
| 145 | 145 | */ |
|---|
| 146 | | char[] name; /// class name |
|---|
| 147 | | void *[] vtbl; /// virtual function pointer table |
|---|
| | 146 | char[] name; /// class name |
|---|
| | 147 | void*[] vtbl; /// virtual function pointer table |
|---|
| 148 | 148 | Interface[] interfaces; /// interfaces this class implements |
|---|
| 149 | | ClassInfo base; /// base class |
|---|
| 150 | | void *destructor; |
|---|
| 151 | | void (*classInvariant)(Object); |
|---|
| 152 | | uint flags; |
|---|
| | 149 | ClassInfo base; /// base class |
|---|
| | 150 | void* destructor; |
|---|
| | 151 | void function(Object) classInvariant; |
|---|
| | 152 | uint flags; |
|---|
| 153 | 153 | // 1: // IUnknown |
|---|
| 154 | 154 | // 2: // has no possible pointers into GC memory |
|---|
| 155 | 155 | // 4: // has offTi[] member |
|---|
| 156 | 156 | // 8: // has constructors |
|---|
| 157 | | void *deallocator; |
|---|
| | 157 | void* deallocator; |
|---|
| 158 | 158 | OffsetTypeInfo[] offTi; |
|---|
| 159 | 159 | void function(Object) defaultConstructor; // default Constructor |
|---|
| … | … | |
| 165 | 165 | static ClassInfo find(char[] classname) |
|---|
| 166 | 166 | { |
|---|
| 167 | | foreach (m; ModuleInfo.modules()) |
|---|
| | 167 | foreach (m; ModuleInfo) |
|---|
| 168 | 168 | { |
|---|
| 169 | 169 | //writefln("module %s, %d", m.name, m.localClasses.length); |
|---|
| … | … | |
| 200 | 200 | struct OffsetTypeInfo |
|---|
| 201 | 201 | { |
|---|
| 202 | | size_t offset; /// Offset of member from start of object |
|---|
| | 202 | size_t offset; /// Offset of member from start of object |
|---|
| 203 | 203 | TypeInfo ti; /// TypeInfo for this member |
|---|
| 204 | 204 | } |
|---|
| … | … | |
| 930 | 930 | class ModuleInfo |
|---|
| 931 | 931 | { |
|---|
| 932 | | char name[]; |
|---|
| 933 | | ModuleInfo importedModules[]; |
|---|
| 934 | | ClassInfo localClasses[]; |
|---|
| 935 | | |
|---|
| 936 | | uint flags; // initialization state |
|---|
| 937 | | |
|---|
| 938 | | void (*ctor)(); |
|---|
| 939 | | void (*dtor)(); |
|---|
| 940 | | void (*unitTest)(); |
|---|
| 941 | | |
|---|
| 942 | | static ModuleInfo[] modules() |
|---|
| 943 | | { |
|---|
| 944 | | return _moduleinfo_array; |
|---|
| | 932 | char[] name; |
|---|
| | 933 | ModuleInfo[] importedModules; |
|---|
| | 934 | ClassInfo[] localClasses; |
|---|
| | 935 | uint flags; |
|---|
| | 936 | |
|---|
| | 937 | void function() ctor; |
|---|
| | 938 | void function() dtor; |
|---|
| | 939 | void function() unitTest; |
|---|
| | 940 | |
|---|
| | 941 | static int opApply( int delegate( inout ModuleInfo ) dg ) |
|---|
| | 942 | { |
|---|
| | 943 | int ret = 0; |
|---|
| | 944 | |
|---|
| | 945 | foreach( m; _moduleinfo_array ) |
|---|
| | 946 | { |
|---|
| | 947 | ret = dg( m ); |
|---|
| | 948 | if( ret ) |
|---|
| | 949 | break; |
|---|
| | 950 | } |
|---|
| | 951 | return ret; |
|---|
| 945 | 952 | } |
|---|
| 946 | 953 | } |
|---|
| … | … | |
| 959 | 966 | { |
|---|
| 960 | 967 | ModuleReference* next; |
|---|
| 961 | | ModuleInfo mod; |
|---|
| 962 | | } |
|---|
| 963 | | |
|---|
| 964 | | extern (C) ModuleReference *_Dmodule_ref; // start of linked list |
|---|
| | 968 | ModuleInfo mod; |
|---|
| | 969 | } |
|---|
| | 970 | |
|---|
| | 971 | extern (C) ModuleReference* _Dmodule_ref; // start of linked list |
|---|
| 965 | 972 | } |
|---|
| 966 | 973 | |
|---|
| 967 | 974 | ModuleInfo[] _moduleinfo_dtors; |
|---|
| 968 | | uint _moduleinfo_dtors_i; |
|---|
| | 975 | uint _moduleinfo_dtors_i; |
|---|
| 969 | 976 | |
|---|
| 970 | 977 | // Register termination function pointers |
|---|
| r2090 |
r2148 |
|
| 113 | 113 | int opEquals(Object o) |
|---|
| 114 | 114 | { |
|---|
| 115 | | return cast(int)(this is o); |
|---|
| | 115 | return cast(int)(this is o); |
|---|
| 116 | 116 | } |
|---|
| 117 | 117 | |
|---|
| 118 | 118 | interface Monitor |
|---|
| 119 | | { |
|---|
| | 119 | { |
|---|
| 120 | 120 | void lock(); |
|---|
| 121 | 121 | void unlock(); |
|---|
| 122 | | } |
|---|
| 123 | | } |
|---|
| | 122 | } |
|---|
| | 123 | } |
|---|
| 124 | 124 | |
|---|
| 125 | 125 | /** |
|---|
| … | … | |
| 129 | 129 | struct Interface |
|---|
| 130 | 130 | { |
|---|
| 131 | | ClassInfo classinfo; /// .classinfo for this interface (not for containing class) |
|---|
| 132 | | void *[] vtbl; |
|---|
| 133 | | ptrdiff_t offset; /// offset to Interface 'this' from Object 'this' |
|---|
| | 131 | ClassInfo classinfo; /// .classinfo for this interface (not for containing class) |
|---|
| | 132 | void*[] vtbl; |
|---|
| | 133 | ptrdiff_t offset; /// offset to Interface 'this' from Object 'this' |
|---|
| 134 | 134 | } |
|---|
| 135 | 135 | |
|---|
| … | … | |
| 141 | 141 | class ClassInfo : Object |
|---|
| 142 | 142 | { |
|---|
| 143 | | byte[] init; /** class static initializer |
|---|
| | 143 | byte[] init; /** class static initializer |
|---|
| 144 | 144 | * (init.length gives size in bytes of class) |
|---|
| 145 | 145 | */ |
|---|
| 146 | | char[] name; /// class name |
|---|
| 147 | | void *[] vtbl; /// virtual function pointer table |
|---|
| | 146 | char[] name; /// class name |
|---|
| | 147 | void*[] vtbl; /// virtual function pointer table |
|---|
| 148 | 148 | Interface[] interfaces; /// interfaces this class implements |
|---|
| 149 | | ClassInfo base; /// base class |
|---|
| 150 | | void *destructor; |
|---|
| 151 | | void (*classInvariant)(Object); |
|---|
| 152 | | uint flags; |
|---|
| | 149 | ClassInfo base; /// base class |
|---|
| | 150 | void* destructor; |
|---|
| | 151 | void function(Object) classInvariant; |
|---|
| | 152 | uint flags; |
|---|
| 153 | 153 | // 1: // IUnknown |
|---|
| 154 | 154 | // 2: // has no possible pointers into GC memory |
|---|
| 155 | 155 | // 4: // has offTi[] member |
|---|
| 156 | | void *deallocator; |
|---|
| | 156 | // 8: // has constructors |
|---|
| | 157 | void* deallocator; |
|---|
| 157 | 158 | OffsetTypeInfo[] offTi; |
|---|
| 158 | | } |
|---|
| 159 | | |
|---|
| | 159 | /+ |
|---|
| | 160 | void function(Object) defaultConstructor; // default Constructor |
|---|
| | 161 | |
|---|
| | 162 | /** |
|---|
| | 163 | * Search all modules for ClassInfo corresponding to classname. |
|---|
| | 164 | * Returns: null if not found |
|---|
| | 165 | */ |
|---|
| | 166 | static ClassInfo find(char[] classname) |
|---|
| | 167 | { |
|---|
| | 168 | foreach (m; ModuleInfo) |
|---|
| | 169 | { |
|---|
| | 170 | //writefln("module %s, %d", m.name, m.localClasses.length); |
|---|
| | 171 | foreach (c; m.localClasses) |
|---|
| | 172 | { |
|---|
| | 173 | //writefln("\tclass %s", c.name); |
|---|
| | 174 | if (c.name == classname) |
|---|
| | 175 | return c; |
|---|
| | 176 | } |
|---|
| | 177 | } |
|---|
| | 178 | return null; |
|---|
| | 179 | } |
|---|
| | 180 | |
|---|
| | 181 | /** |
|---|
| | 182 | * Create instance of Object represented by 'this'. |
|---|
| | 183 | */ |
|---|
| | 184 | Object create() |
|---|
| | 185 | { |
|---|
| | 186 | if (flags & 8 && !defaultConstructor) |
|---|
| | 187 | return null; |
|---|
| | 188 | Object o = _d_newclass(this); |
|---|
| | 189 | if (flags & 8 && defaultConstructor) |
|---|
| | 190 | { |
|---|
| | 191 | defaultConstructor(o); |
|---|
| | 192 | } |
|---|
| | 193 | return o; |
|---|
| | 194 | } |
|---|
| | 195 | +/ |
|---|
| | 196 | } |
|---|
| 160 | 197 | |
|---|
| 161 | 198 | /** |
|---|
| … | … | |
| 165 | 202 | struct OffsetTypeInfo |
|---|
| 166 | 203 | { |
|---|
| 167 | | size_t offset; /// Offset of member from start of object |
|---|
| | 204 | size_t offset; /// Offset of member from start of object |
|---|
| 168 | 205 | TypeInfo ti; /// TypeInfo for this member |
|---|
| 169 | 206 | } |
|---|
| 170 | | |
|---|
| 171 | 207 | |
|---|
| 172 | 208 | /** |
|---|
| … | … | |
| 336 | 372 | { TypeInfo_Array c; |
|---|
| 337 | 373 | |
|---|
| 338 | | return cast(int) |
|---|
| 339 | | (this is o || |
|---|
| | 374 | return cast(int) |
|---|
| | 375 | (this is o || |
|---|
| 340 | 376 | ((c = cast(TypeInfo_Array)o) !is null && |
|---|
| 341 | | this.value == c.value)); |
|---|
| | 377 | this.value == c.value)); |
|---|
| 342 | 378 | } |
|---|
| 343 | 379 | |
|---|
| … | … | |
| 417 | 453 | { TypeInfo_StaticArray c; |
|---|
| 418 | 454 | |
|---|
| 419 | | return cast(int) |
|---|
| 420 | | (this is o || |
|---|
| | 455 | return cast(int) |
|---|
| | 456 | (this is o || |
|---|
| 421 | 457 | ((c = cast(TypeInfo_StaticArray)o) !is null && |
|---|
| 422 | 458 | this.len == c.len && |
|---|
| 423 | | this.value == c.value)); |
|---|
| | 459 | this.value == c.value)); |
|---|
| 424 | 460 | } |
|---|
| 425 | 461 | |
|---|
| … | … | |
| 899 | 935 | enum |
|---|
| 900 | 936 | { |
|---|
| 901 | | MIctorstart = 1, // we've started constructing it |
|---|
| 902 | | MIctordone = 2, // finished construction |
|---|
| | 937 | MIctorstart = 1, // we've started constructing it |
|---|
| | 938 | MIctordone = 2, // finished construction |
|---|
| 903 | 939 | MIstandalone = 4, // module ctor does not depend on other module |
|---|
| 904 | 940 | // ctors being done first |
|---|
| 905 | 941 | } |
|---|
| 906 | 942 | |
|---|
| | 943 | |
|---|
| 907 | 944 | class ModuleInfo |
|---|
| 908 | 945 | { |
|---|
| 909 | | char name[]; |
|---|
| 910 | | ModuleInfo importedModules[]; |
|---|
| 911 | | ClassInfo localClasses[]; |
|---|
| 912 | | |
|---|
| 913 | | uint flags; // initialization state |
|---|
| 914 | | |
|---|
| 915 | | void (*ctor)(); |
|---|
| 916 | | void (*dtor)(); |
|---|
| 917 | | void (*unitTest)(); |
|---|
| 918 | | |
|---|
| 919 | | static ModuleInfo[] modules() |
|---|
| 920 | | { |
|---|
| 921 | | return _moduleinfo_array; |
|---|
| | 946 | char[] name; |
|---|
| | 947 | ModuleInfo[] importedModules; |
|---|
| | 948 | ClassInfo[] localClasses; |
|---|
| | 949 | uint flags; |
|---|
| | 950 | |
|---|
| | 951 | void function() ctor; |
|---|
| | 952 | void function() dtor; |
|---|
| | 953 | void function() unitTest; |
|---|
| | 954 | |
|---|
| | 955 | static int opApply( int delegate( inout ModuleInfo ) dg ) |
|---|
| | 956 | { |
|---|
| | 957 | int ret = 0; |
|---|
| | 958 | |
|---|
| | 959 | foreach( m; _moduleinfo_array ) |
|---|
| | 960 | { |
|---|
| | 961 | ret = dg( m ); |
|---|
| | 962 | if( ret ) |
|---|
| | 963 | break; |
|---|
| | 964 | } |
|---|
| | 965 | return ret; |
|---|
| 922 | 966 | } |
|---|
| 923 | 967 | } |
|---|
| … | … | |
| 943 | 987 | { |
|---|
| 944 | 988 | ModuleReference* next; |
|---|
| 945 | | ModuleInfo mod; |
|---|
| 946 | | } |
|---|
| 947 | | |
|---|
| 948 | | extern (C) ModuleReference *_Dmodule_ref; // start of linked list |
|---|
| | 989 | ModuleInfo mod; |
|---|
| | 990 | } |
|---|
| | 991 | |
|---|
| | 992 | extern (C) ModuleReference* _Dmodule_ref; // start of linked list |
|---|
| 949 | 993 | } |
|---|
| 950 | 994 | |
|---|
| 951 | 995 | ModuleInfo[] _moduleinfo_dtors; |
|---|
| 952 | | uint _moduleinfo_dtors_i; |
|---|
| | 996 | uint _moduleinfo_dtors_i; |
|---|
| 953 | 997 | |
|---|
| 954 | 998 | // Register termination function pointers |
|---|
| … | … | |
| 1076 | 1120 | } |
|---|
| 1077 | 1121 | |
|---|
| | 1122 | |
|---|
| 1078 | 1123 | //////////////////////////////////////////////////////////////////////////////// |
|---|
| 1079 | 1124 | // Monitor |
|---|
| r2076 |
r2148 |
|
| 148 | 148 | } |
|---|
| 149 | 149 | |
|---|
| | 150 | class ModuleInfo |
|---|
| | 151 | { |
|---|
| | 152 | char[] name; |
|---|
| | 153 | ModuleInfo[] importedModules; |
|---|
| | 154 | ClassInfo[] localClasses; |
|---|
| | 155 | uint flags; |
|---|
| | 156 | |
|---|
| | 157 | void function() ctor; |
|---|
| | 158 | void function() dtor; |
|---|
| | 159 | void function() unitTest; |
|---|
| | 160 | |
|---|
| | 161 | static int opApply( int delegate( inout ModuleInfo ) ); |
|---|
| | 162 | } |
|---|
| | 163 | |
|---|
| 150 | 164 | class Exception : Object |
|---|
| 151 | 165 | { |
|---|
Download in other formats:
|
 |
 |
|
 |
Copyright © 2006-2008 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic