[275] | 1 | Namespace ActiveBasic
|
---|
| 2 | Namespace Core
|
---|
| 3 |
|
---|
| 4 |
|
---|
| 5 | ' 中間的な実装(継承専用)
|
---|
| 6 | Class TypeBaseImpl
|
---|
| 7 | Inherits System.TypeInfo
|
---|
| 8 |
|
---|
| 9 | strNamespace As String
|
---|
| 10 | name As String
|
---|
[367] | 11 | fullName As String
|
---|
[275] | 12 |
|
---|
[413] | 13 | ptrType As TypeBaseImpl
|
---|
| 14 | ptrLevel As Long
|
---|
| 15 |
|
---|
[401] | 16 | ' メンバ情報
|
---|
[402] | 17 | memberNames As *String ' 名前リスト
|
---|
| 18 | memberTypeFullNames As *String ' 型名リスト
|
---|
[401] | 19 | memberCounts As Long ' 個数
|
---|
[403] | 20 | memberInfosCache As System.Collections.Generic.List<System.Reflection.MemberInfo>
|
---|
[401] | 21 |
|
---|
[275] | 22 | Protected
|
---|
| 23 |
|
---|
| 24 | baseType As System.TypeInfo
|
---|
| 25 | 'interfaces As f(^^;;;
|
---|
| 26 |
|
---|
[367] | 27 | Sub TypeBaseImpl( strNamespace As String, name As String, fullName As String )
|
---|
[275] | 28 | This.strNamespace = strNamespace
|
---|
| 29 | This.name = name
|
---|
[367] | 30 | This.fullName = fullName
|
---|
[275] | 31 | This.baseType = Nothing
|
---|
[413] | 32 |
|
---|
| 33 | ptrType = Nothing
|
---|
| 34 | ptrLevel = 0
|
---|
[275] | 35 | End Sub
|
---|
| 36 |
|
---|
| 37 | Sub ~TypeBaseImpl()
|
---|
| 38 | End Sub
|
---|
| 39 |
|
---|
[413] | 40 | Sub PtrLevelUp()
|
---|
| 41 | ptrLevel ++
|
---|
| 42 | fullName = "*" + fullName
|
---|
| 43 | End Sub
|
---|
| 44 |
|
---|
| 45 | Function Clone() As TypeBaseImpl
|
---|
| 46 | Dim result = New TypeBaseImpl( strNamespace, name, fullName )
|
---|
| 47 | result.SetBaseType( baseType )
|
---|
| 48 | result.SetMembers( memberNames, memberTypeFullNames, memberCounts )
|
---|
| 49 | result.memberInfosCache = This.memberInfosCache
|
---|
| 50 | result.ptrLevel = This.ptrLevel
|
---|
| 51 | Return result
|
---|
| 52 | End Function
|
---|
| 53 |
|
---|
[275] | 54 | Public
|
---|
| 55 |
|
---|
[402] | 56 | Sub SetMembers( memberNames As *String, memberTypeFullNames As *String, num As Long )
|
---|
[401] | 57 | This.memberNames = memberNames
|
---|
| 58 | This.memberTypeFullNames = memberTypeFullNames
|
---|
| 59 | This.memberCounts = num
|
---|
[402] | 60 |
|
---|
| 61 | /*
|
---|
| 62 | OutputDebugString( Ex"\r\n" )
|
---|
| 63 | Dim i As Long
|
---|
| 64 | For i=0 To ELM(num)
|
---|
| 65 | OutputDebugString( memberNames[i] )
|
---|
| 66 | OutputDebugString( ", " )
|
---|
| 67 | OutputDebugString( memberTypeFullNames[i] )
|
---|
| 68 | OutputDebugString( Ex"\r\n" )
|
---|
| 69 | Next
|
---|
| 70 | */
|
---|
[401] | 71 | End Sub
|
---|
[275] | 72 |
|
---|
[413] | 73 | Function GetPtrType() As TypeBaseImpl
|
---|
| 74 | If Object.ReferenceEquals( ptrType, Nothing ) Then
|
---|
| 75 | Dim clone = This.Clone()
|
---|
[401] | 76 |
|
---|
[413] | 77 | ptrType = clone
|
---|
| 78 | ptrType.PtrLevelUp()
|
---|
| 79 | End If
|
---|
| 80 | Return ptrType
|
---|
| 81 | End Function
|
---|
| 82 |
|
---|
| 83 |
|
---|
[275] | 84 | '----------------------------------------------------------------
|
---|
| 85 | ' Public properties
|
---|
| 86 | '----------------------------------------------------------------
|
---|
| 87 |
|
---|
| 88 | Override Function BaseType() As System.TypeInfo
|
---|
| 89 | Return baseType
|
---|
| 90 | End Function
|
---|
| 91 |
|
---|
| 92 | Sub SetBaseType( baseType As System.TypeInfo )
|
---|
| 93 | This.baseType = baseType
|
---|
| 94 | End Sub
|
---|
| 95 |
|
---|
| 96 | Override Function FullName() As String
|
---|
[367] | 97 | Return fullName
|
---|
[275] | 98 | End Function
|
---|
| 99 |
|
---|
| 100 | Override Function IsArray() As Boolean
|
---|
| 101 | Return False
|
---|
| 102 | End Function
|
---|
| 103 |
|
---|
| 104 | Override Function IsByRef() As Boolean
|
---|
| 105 | Return False
|
---|
| 106 | End Function
|
---|
| 107 |
|
---|
| 108 | Override Function IsClass() As Boolean
|
---|
| 109 | Return False
|
---|
| 110 | End Function
|
---|
| 111 |
|
---|
| 112 | Override Function IsEnum() As Boolean
|
---|
| 113 | Return False
|
---|
| 114 | End Function
|
---|
| 115 |
|
---|
| 116 | Override Function IsInterface() As Boolean
|
---|
| 117 | Return False
|
---|
| 118 | End Function
|
---|
| 119 |
|
---|
| 120 | Override Function IsPointer() As Boolean
|
---|
[413] | 121 | Return ( ptrLevel > 0 )
|
---|
[275] | 122 | End Function
|
---|
| 123 |
|
---|
| 124 | Override Function IsValueType() As Boolean
|
---|
| 125 | Return False
|
---|
| 126 | End Function
|
---|
| 127 |
|
---|
| 128 | Override Function Name() As String
|
---|
| 129 | Return name
|
---|
| 130 | End Function
|
---|
| 131 |
|
---|
| 132 | Override Function Namespace() As String
|
---|
| 133 | Return strNamespace
|
---|
| 134 | End Function
|
---|
| 135 |
|
---|
| 136 |
|
---|
| 137 |
|
---|
| 138 | '----------------------------------------------------------------
|
---|
| 139 | ' Public methods
|
---|
| 140 | '----------------------------------------------------------------
|
---|
| 141 |
|
---|
[403] | 142 | Override Function GetMembers() As System.Collections.Generic.List<System.Reflection.MemberInfo>
|
---|
| 143 | If Object.ReferenceEquals( memberInfosCache, Nothing ) Then
|
---|
| 144 | ' キャッシュにないときは生成する
|
---|
| 145 | memberInfosCache = New System.Collections.Generic.List
|
---|
| 146 | Dim i As Long
|
---|
| 147 | For i=0 To ELM(memberCounts)
|
---|
| 148 | memberInfosCache.Add( New System.Reflection.MemberInfo( memberNames[i], _System_TypeBase_Search( memberTypeFullNames[i] ) ) )
|
---|
| 149 | Next
|
---|
| 150 | End If
|
---|
| 151 |
|
---|
| 152 | Return memberInfosCache
|
---|
| 153 | End Function
|
---|
| 154 |
|
---|
[275] | 155 | End Class
|
---|
| 156 |
|
---|
| 157 |
|
---|
| 158 | ' 値型を管理するためのクラス
|
---|
| 159 | Class _System_TypeForValueType
|
---|
| 160 | Inherits TypeBaseImpl
|
---|
| 161 | Public
|
---|
| 162 | Sub _System_TypeForValueType( name As String )
|
---|
[367] | 163 | TypeBaseImpl( "", name, name )
|
---|
[275] | 164 | End Sub
|
---|
| 165 |
|
---|
| 166 | Override Function IsValueType() As Boolean
|
---|
| 167 | Return True
|
---|
| 168 | End Function
|
---|
| 169 | End Class
|
---|
| 170 |
|
---|
| 171 | ' クラスを管理するためのクラス
|
---|
| 172 | Class _System_TypeForClass
|
---|
| 173 | Inherits TypeBaseImpl
|
---|
| 174 |
|
---|
| 175 | Public
|
---|
| 176 | referenceOffsets As *Long
|
---|
| 177 | numOfReference As Long
|
---|
| 178 |
|
---|
[367] | 179 | Sub _System_TypeForClass( strNamespace As String, name As String, fullName As String, referenceOffsets As *Long, numOfReference As Long )
|
---|
| 180 | TypeBaseImpl( strNamespace, name, fullName )
|
---|
[275] | 181 |
|
---|
| 182 | This.referenceOffsets = referenceOffsets
|
---|
| 183 | This.numOfReference = numOfReference
|
---|
| 184 | End Sub
|
---|
[367] | 185 | Sub _System_TypeForClass( strNamespace As String, name As String, fullName As String )
|
---|
| 186 | TypeBaseImpl( strNamespace, name, fullName )
|
---|
[275] | 187 | End Sub
|
---|
| 188 | Sub ~_System_TypeForClass()
|
---|
| 189 | End Sub
|
---|
| 190 |
|
---|
| 191 | Override Function IsClass() As Boolean
|
---|
| 192 | Return True
|
---|
| 193 | End Function
|
---|
| 194 | End Class
|
---|
| 195 |
|
---|
| 196 | ' インターフェイスを管理するためのクラス
|
---|
| 197 | Class _System_TypeForInterface
|
---|
| 198 | Inherits TypeBaseImpl
|
---|
| 199 | Public
|
---|
| 200 | End Class
|
---|
| 201 |
|
---|
| 202 | ' 列挙体を管理するためのクラス
|
---|
| 203 | Class _System_TypeForEnum
|
---|
| 204 | Inherits TypeBaseImpl
|
---|
| 205 | Public
|
---|
| 206 | End Class
|
---|
| 207 |
|
---|
| 208 | ' デリゲートを管理するためのクラス
|
---|
| 209 | Class _System_TypeForDelegate
|
---|
| 210 | Inherits TypeBaseImpl
|
---|
| 211 | Public
|
---|
| 212 | End Class
|
---|
| 213 |
|
---|
| 214 |
|
---|
| 215 | '--------------------------------------------------------------------
|
---|
| 216 | ' プロセスに存在するすべての型を管理する
|
---|
| 217 | '--------------------------------------------------------------------
|
---|
| 218 | Class _System_TypeBase
|
---|
[367] | 219 | Static types As System.Collections.Generic.Dictionary<String, TypeBaseImpl>
|
---|
[299] | 220 |
|
---|
[275] | 221 | Static isReady = False
|
---|
| 222 |
|
---|
| 223 | Static Sub Add( typeInfo As TypeBaseImpl )
|
---|
[367] | 224 | types.Add( typeInfo.FullName, typeInfo )
|
---|
[275] | 225 | End Sub
|
---|
| 226 |
|
---|
| 227 | Static Sub InitializeValueType()
|
---|
[400] | 228 | types = New System.Collections.Generic.Dictionary<String, TypeBaseImpl>(8191)
|
---|
[367] | 229 |
|
---|
[275] | 230 | ' 値型の追加
|
---|
[367] | 231 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Byte", fullName = "Byte" ] )
|
---|
| 232 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "SByte", fullName = "SByte" ] )
|
---|
| 233 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Word", fullName = "Word" ] )
|
---|
| 234 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Integer", fullName = "Integer" ] )
|
---|
| 235 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "DWord", fullName = "DWord" ] )
|
---|
| 236 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Long", fullName = "Long" ] )
|
---|
| 237 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "QWord", fullName = "QWord" ] )
|
---|
| 238 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Int64", fullName = "Int64" ] )
|
---|
| 239 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Boolean", fullName = "Boolean" ] )
|
---|
| 240 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Single", fullName = "Single" ] )
|
---|
| 241 | Add( _System_Static_New _System_TypeForValueType[ strNamespace = "", name = "Double", fullName = "Double" ] )
|
---|
[275] | 242 | End Sub
|
---|
| 243 |
|
---|
| 244 | Static Sub InitializeUserTypes()
|
---|
| 245 | ' このメソッドの実装はコンパイラが自動生成する
|
---|
| 246 |
|
---|
| 247 | '例:
|
---|
[367] | 248 | 'Add( New _System_TypeForClass( "System", "String", "System.String", [__offsets...], __numOfOffsets ) )
|
---|
| 249 | '...
|
---|
[275] | 250 | End Sub
|
---|
[367] | 251 | Static Sub InitializeUserTypesForBaseType()
|
---|
| 252 | ' このメソッドの実装はコンパイラが自動生成する
|
---|
[275] | 253 |
|
---|
[367] | 254 | '例:
|
---|
| 255 | 'Search( "System.String" ).SetBaseType( Search( "System.Object" ) )
|
---|
| 256 | '...
|
---|
| 257 | End Sub
|
---|
| 258 |
|
---|
[275] | 259 | Public
|
---|
| 260 | Static Sub Initialize()
|
---|
| 261 | ' 値型を初期化
|
---|
| 262 | InitializeValueType()
|
---|
| 263 |
|
---|
| 264 | ' Class / Interface / Enum / Delegate を初期化
|
---|
| 265 | InitializeUserTypes()
|
---|
| 266 |
|
---|
[367] | 267 | isReady = True
|
---|
[275] | 268 |
|
---|
[367] | 269 | ' 基底クラスを登録
|
---|
| 270 | InitializeUserTypesForBaseType()
|
---|
| 271 |
|
---|
| 272 | selfTypeInfo = _System_TypeBase.Search( "System.TypeInfo" ) As System.TypeInfo
|
---|
| 273 |
|
---|
[275] | 274 | _System_DebugOnly_OutputDebugString( Ex"ready dynamic meta datas!\r\n" )
|
---|
| 275 | End Sub
|
---|
| 276 |
|
---|
| 277 | Static Sub _NextPointerForGC()
|
---|
| 278 | ' TODO: 実装
|
---|
| 279 | End Sub
|
---|
| 280 |
|
---|
[367] | 281 | Static Function Search( fullName As String ) As TypeBaseImpl
|
---|
| 282 | If Object.ReferenceEquals(types, Nothing) Then
|
---|
| 283 | Return Nothing
|
---|
| 284 | End If
|
---|
[299] | 285 |
|
---|
[367] | 286 | If isReady = False Then
|
---|
| 287 | Return Nothing
|
---|
| 288 | End If
|
---|
[275] | 289 |
|
---|
[413] | 290 | If fullName[0] = &H2A Then ' fullName[0] = '*'
|
---|
| 291 | Dim result = Search( fullName.Substring( 1 ) )
|
---|
| 292 | Return result.GetPtrType()
|
---|
| 293 | End If
|
---|
| 294 |
|
---|
[400] | 295 | Search = types.Item(fullName)
|
---|
| 296 |
|
---|
| 297 | If Object.ReferenceEquals( Search, Nothing ) Then
|
---|
| 298 | OutputDebugString("TypeSearch Failed: ")
|
---|
| 299 | If Not ActiveBasic.IsNothing(fullName) Then
|
---|
| 300 | OutputDebugStringW(StrPtr(fullName) As PWSTR)
|
---|
| 301 | OutputDebugString(Ex"\r\n")
|
---|
| 302 | OutputDebugStringA(StrPtr(fullName) As PSTR)
|
---|
| 303 | End If
|
---|
| 304 | OutputDebugString(Ex"\r\n")
|
---|
[367] | 305 | End If
|
---|
[275] | 306 | End Function
|
---|
| 307 |
|
---|
| 308 | Static Function IsReady() As Boolean
|
---|
| 309 | Return isReady
|
---|
| 310 | End Function
|
---|
| 311 |
|
---|
[367] | 312 | Static selfTypeInfo As System.TypeInfo
|
---|
[275] | 313 |
|
---|
| 314 | End Class
|
---|
| 315 |
|
---|
| 316 |
|
---|
| 317 | End Namespace
|
---|
| 318 | End Namespace
|
---|
[299] | 319 |
|
---|
[367] | 320 | Function _System_TypeBase_Search( fullName As String ) As ActiveBasic.Core.TypeBaseImpl
|
---|
| 321 | Return ActiveBasic.Core._System_TypeBase.Search( fullName )
|
---|
[299] | 322 | End Function
|
---|