source: Include/Classes/System/TypeInfo.ab@ 207

Last change on this file since 207 was 207, checked in by dai, 17 years ago

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

File size: 5.9 KB
RevLine 
[169]1' 実装中...
2'(※ まだ組み込んでいません)
3
[195]4
5'Namespace System
6
7
[169]8Class TypeInfo
9Public
10
11 Sub TypeInfo()
12 End Sub
[207]13 Sub ~TypeInfo()
14 End Sub
[169]15
16
17 '----------------------------------------------------------------
18 ' Public properties
19 '----------------------------------------------------------------
20
21 Abstract Function BaseType() As TypeInfo
22 Abstract Function FullName() As String
23 Abstract Function IsArray() As Boolean
24 Abstract Function IsByRef() As Boolean
25 Abstract Function IsClass() As Boolean
26 Abstract Function IsEnum() As Boolean
27 Abstract Function IsInterface() As Boolean
28 Abstract Function IsPointer() As Boolean
29 Abstract Function IsValueType() As Boolean
30 Abstract Function Name() As String
31 Abstract Function Namespace() As String
32
33
34
35 '----------------------------------------------------------------
36 ' Public methods
37 '----------------------------------------------------------------
38
39End Class
40
41
42' 中間的な実装(継承専用)
[195]43Class TypeBaseImpl
[169]44 Inherits TypeInfo
45
[198]46 strNamespace As String
[169]47 name As String
48
[207]49Protected
50
[186]51 baseType As TypeInfo
[169]52 'interfaces As f(^^;;;
53
[195]54 Sub TypeBaseImpl()
[198]55 strNamespace = ""
[169]56 name = ""
57 baseType = Nothing
58 End Sub
59
[198]60 Sub TypeBaseImpl( strNamespace As String, name As String )
61 This.strNamespace = strNamespace
[169]62 This.name = name
[195]63 This.baseType = Nothing
[169]64 End Sub
65
[198]66 Sub TypeBaseImpl( strNamespace As String, name As String, baseType As TypeInfo )
67 This.strNamespace = strNamespace
[195]68 This.name = name
[169]69 This.baseType = baseType
70 End Sub
71
72 /*
[198]73 Sub TypeBaseImpl( strNamespace As String, name As String, baseType As Type, interfaces As ... )
74 This.strNamespace = strNamespace
75 This.name = name
76 This.baseType = baseType
77 This.interfaces = interfaces
[169]78 End Sub
79 */
80
[207]81 Sub ~TypeBaseImpl()
82 End Sub
83
[169]84Public
85
86
87 '----------------------------------------------------------------
88 ' Public properties
89 '----------------------------------------------------------------
90
91 Override Function BaseType() As TypeInfo
92 Return baseType
93 End Function
94
[207]95 Sub SetBaseType( baseType As TypeInfo )
96 This.baseType = baseType
97 End Sub
98
[169]99 Override Function FullName() As String
100 Return strNamespace + "." + name
101 End Function
102
103 Override Function IsArray() As Boolean
104 Return False
105 End Function
106
107 Override Function IsByRef() As Boolean
108 Return False
109 End Function
110
111 Override Function IsClass() As Boolean
112 Return False
113 End Function
114
115 Override Function IsEnum() As Boolean
116 Return False
117 End Function
118
119 Override Function IsInterface() As Boolean
120 Return False
121 End Function
122
123 Override Function IsPointer() As Boolean
124 Return False
125 End Function
126
127 Override Function IsValueType() As Boolean
128 Return False
129 End Function
130
131 Override Function Name() As String
132 Return name
133 End Function
134
135 Override Function Namespace() As String
136 Return strNamespace
137 End Function
138
139
140
141 '----------------------------------------------------------------
142 ' Public methods
143 '----------------------------------------------------------------
144
145End Class
146
147
148' 値型を管理するためのクラス
149Class _System_TypeForValueType
[195]150 Inherits TypeBaseImpl
[169]151Public
[195]152 Sub _System_TypeForValueType( name As String )
[207]153 TypeBaseImpl( "", name )
[169]154 End Sub
155
156 Override Function IsValueType() As Boolean
157 Return True
158 End Function
159End Class
160
161' クラスを管理するためのクラス
162Class _System_TypeForClass
[195]163 Inherits TypeBaseImpl
[169]164Public
[207]165 Sub _System_TypeForClass( strNamespace As String, name As String )
166 TypeBaseImpl( strNamespace, name )
[195]167 End Sub
168 Sub ~_System_TypeForClass()
169 End Sub
170 Override Function IsClass() As Boolean
171 Return True
172 End Function
[169]173End Class
174
175' インターフェイスを管理するためのクラス
176Class _System_TypeForInterface
[195]177 Inherits TypeBaseImpl
[169]178Public
179End Class
180
181' 列挙体を管理するためのクラス
182Class _System_TypeForEnum
[195]183 Inherits TypeBaseImpl
[169]184Public
185End Class
186
187' デリゲートを管理するためのクラス
188Class _System_TypeForDelegate
[195]189 Inherits TypeBaseImpl
[169]190Public
191End Class
192
193
194'--------------------------------------------------------------------
[207]195' プロセスに存在するすべての型を管理する
[169]196'--------------------------------------------------------------------
197Class _System_TypeBase
[207]198 Static pTypes As *TypeBaseImpl
199 Static count As Long
200 Static isReady = False
[169]201
[207]202 Static Sub Add( typeInfo As TypeBaseImpl )
[195]203 pTypes = realloc( pTypes, ( count + 1 ) * SizeOf(*TypeInfo) )
204 pTypes[count] = typeInfo
205 count++
206 End Sub
207
[169]208 Static Sub InitializeValueType()
209 ' 値型の追加
[207]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" ) )
[169]221 End Sub
[195]222
223 Static Sub InitializeUserTypes()
224 ' このメソッドの実装はコンパイラが自動生成する
[196]225
226 '例:
[207]227 'Add( New _System_TypeForClass( "System", "String" ) )
228 'Search( "String" ).SetBaseType( Search( "Object" ) )
[195]229 End Sub
230
[196]231Public
232
[207]233 Static Sub Initialize()
234 pTypes = GC_malloc( 1 )
235 count = 0
[196]236
[195]237 ' 値型を初期化
238 InitializeValueType()
239
[207]240 isReady = True
[195]241 ' Class / Interface / Enum / Delegate を初期化
242 InitializeUserTypes()
[207]243
244
245 OutputDebugString( Ex"ready dynamic meta datas!\r\n" )
[195]246 End Sub
[207]247
248 Static Sub _NextPointerForGC()
249 ' TODO: 実装
250 End Sub
251
252 Static Function Search( strNamespace As LPSTR, typeName As LPSTR ) As TypeBaseImpl
253
254 ' TODO: 名前空間に対応する
255 Dim i As Long
256 For i = 0 To ELM( count )
257 If pTypes[i].Name = typeName Then
258 Return pTypes[i]
259 End If
260 Next
261
262 Return Nothing
263 End Function
264
265 Static Function IsReady() As Boolean
266 Return isReady
267 End Function
268
[169]269End Class
[195]270
[207]271
[195]272' End Namespace ' System
Note: See TracBrowser for help on using the repository browser.