Ignore:
Timestamp:
Apr 7, 2007, 3:03:38 PM (17 years ago)
Author:
dai
Message:

動的型情報(Object.GetType)に対応。
戻り値やクラスメンバがオブジェクトだったとき、その初期値をNothingにした(※戻り値として関数名を使っている部分、要注意!!)。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Include/Classes/System/TypeInfo.ab

    r198 r207  
    1010
    1111    Sub TypeInfo()
     12    End Sub
     13    Sub ~TypeInfo()
    1214    End Sub
    1315
     
    4547    name As String
    4648
     49Protected
     50
    4751    baseType As TypeInfo
    4852    'interfaces As f(^^;;;
    49 
    50 Protected
    5153
    5254    Sub TypeBaseImpl()
     
    7779    */
    7880
     81    Sub ~TypeBaseImpl()
     82    End Sub
     83
    7984Public
    8085
     
    8893    End Function
    8994
     95    Sub SetBaseType( baseType As TypeInfo )
     96        This.baseType = baseType
     97    End Sub
     98
    9099    Override Function FullName() As String
    91100        Return strNamespace + "." + name
     
    142151Public
    143152    Sub _System_TypeForValueType( name As String )
    144         TypeInfo( "", name )
     153        TypeBaseImpl( "", name )
    145154    End Sub
    146155
     
    154163    Inherits TypeBaseImpl
    155164Public
    156     Sub _System_TypeForClass( strNamespace As String, name As String, baseType As TypeInfo )
    157         TypeBaseImpl( strNamespace, name, baseType )
     165    Sub _System_TypeForClass( strNamespace As String, name As String )
     166        TypeBaseImpl( strNamespace, name )
    158167    End Sub
    159168    Sub ~_System_TypeForClass()
     
    162171        Return True
    163172    End Function
    164 
    165     Sub SetBaseType( baseType As TypeInfo )
    166         This.baseType = baseType
    167     End Sub
    168173End Class
    169174
     
    188193
    189194'--------------------------------------------------------------------
    190 ' プロセスに存在するすべての型を管理する(シングルトン クラス)
     195' プロセスに存在するすべての型を管理する
    191196'--------------------------------------------------------------------
    192197Class _System_TypeBase
    193     pTypes As *TypeInfo
    194     count As Long
    195 
    196     Sub _System_TypeBase()
    197         pTypes = GC_malloc( 1 )
    198         count = 0
    199     End Sub
    200     Sub ~_System_TypeBase()
    201     End Sub
    202 
    203     Sub Add( typeInfo As TypeInfo )
     198    Static pTypes As *TypeBaseImpl
     199    Static count As Long
     200    Static isReady = False
     201
     202    Static Sub Add( typeInfo As TypeBaseImpl )
    204203        pTypes = realloc( pTypes, ( count + 1 ) * SizeOf(*TypeInfo) )
    205204        pTypes[count] = typeInfo
     
    207206    End Sub
    208207
    209     Function Search( strNamespace As String, typeName As String ) As TypeInfo
     208    Static Sub InitializeValueType()
     209        ' 値型の追加
     210        Add( New _System_TypeForValueType( "Byte" ) )
     211        Add( New _System_TypeForValueType( "SByte" ) )
     212        Add( New _System_TypeForValueType( "Word" ) )
     213        Add( New _System_TypeForValueType( "Integer" ) )
     214        Add( New _System_TypeForValueType( "DWord" ) )
     215        Add( New _System_TypeForValueType( "Long" ) )
     216        Add( New _System_TypeForValueType( "QWord" ) )
     217        Add( New _System_TypeForValueType( "Int64" ) )
     218        Add( New _System_TypeForValueType( "Boolean" ) )
     219        Add( New _System_TypeForValueType( "Single" ) )
     220        Add( New _System_TypeForValueType( "Double" ) )
     221    End Sub
     222
     223    Static Sub InitializeUserTypes()
     224        ' このメソッドの実装はコンパイラが自動生成する
     225
     226        '例:
     227        'Add( New _System_TypeForClass( "System", "String" ) )
     228        'Search( "String" ).SetBaseType( Search( "Object" ) )
     229    End Sub
     230
     231Public
     232
     233    Static Sub Initialize()
     234        pTypes = GC_malloc( 1 )
     235        count = 0
     236
     237        ' 値型を初期化
     238        InitializeValueType()
     239
     240        isReady = True
     241        ' Class / Interface / Enum / Delegate を初期化
     242        InitializeUserTypes()
     243
     244
     245        OutputDebugString( Ex"ready dynamic meta datas!\r\n" )
     246    End Sub
     247
     248    Static Sub _NextPointerForGC()
     249        ' TODO: 実装
     250    End Sub
     251
     252    Static Function Search( strNamespace As LPSTR, typeName As LPSTR ) As TypeBaseImpl
     253
    210254        ' TODO: 名前空間に対応する
    211255        Dim i As Long
     
    215259            End If
    216260        Next
     261
    217262        Return Nothing
    218263    End Function
    219264
    220     ' シングルトン オブジェクト
    221     Static obj As _System_TypeBase
    222 
    223     Static Sub InitializeValueType()
    224         ' 値型の追加
    225         obj.Add( New _System_TypeForValueType( "Byte" ) )
    226         obj.Add( New _System_TypeForValueType( "SByte" ) )
    227         obj.Add( New _System_TypeForValueType( "Word" ) )
    228         obj.Add( New _System_TypeForValueType( "Integer" ) )
    229         obj.Add( New _System_TypeForValueType( "DWord" ) )
    230         obj.Add( New _System_TypeForValueType( "Long" ) )
    231         obj.Add( New _System_TypeForValueType( "QWord" ) )
    232         obj.Add( New _System_TypeForValueType( "Int64" ) )
    233         obj.Add( New _System_TypeForValueType( "Boolean" ) )
    234         obj.Add( New _System_TypeForValueType( "Single" ) )
    235         obj.Add( New _System_TypeForValueType( "Double" ) )
    236     End Sub
    237 
    238     Static Sub InitializeUserTypes()
    239         ' このメソッドの実装はコンパイラが自動生成する
    240 
    241 #generate InitializeUserTypes
    242 
    243         '例:
    244         'obj.Add( New _System_TypeForClass( "System", "String" ) )
    245         'obj.Search( "String" ).SetBaseType( Search( "Object" ) )
    246     End Sub
    247 
    248 Public
    249 
    250     Static Sub _NextPointerForGC()
    251         ' TODO: 実装
    252     End Sub
    253 
    254     Static Sub Initialize()
    255         ' 値型を初期化
    256         InitializeValueType()
    257 
    258         ' Class / Interface / Enum / Delegate を初期化
    259         InitializeUserTypes()
    260     End Sub
    261 End Class
     265    Static Function IsReady() As Boolean
     266        Return isReady
     267    End Function
     268
     269End Class
     270
    262271
    263272' End Namespace ' System
Note: See TracChangeset for help on using the changeset viewer.