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
Line 
1' 実装中...
2'(※ まだ組み込んでいません)
3
4
5'Namespace System
6
7
8Class TypeInfo
9Public
10
11 Sub TypeInfo()
12 End Sub
13 Sub ~TypeInfo()
14 End Sub
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' 中間的な実装(継承専用)
43Class TypeBaseImpl
44 Inherits TypeInfo
45
46 strNamespace As String
47 name As String
48
49Protected
50
51 baseType As TypeInfo
52 'interfaces As f(^^;;;
53
54 Sub TypeBaseImpl()
55 strNamespace = ""
56 name = ""
57 baseType = Nothing
58 End Sub
59
60 Sub TypeBaseImpl( strNamespace As String, name As String )
61 This.strNamespace = strNamespace
62 This.name = name
63 This.baseType = Nothing
64 End Sub
65
66 Sub TypeBaseImpl( strNamespace As String, name As String, baseType As TypeInfo )
67 This.strNamespace = strNamespace
68 This.name = name
69 This.baseType = baseType
70 End Sub
71
72 /*
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
78 End Sub
79 */
80
81 Sub ~TypeBaseImpl()
82 End Sub
83
84Public
85
86
87 '----------------------------------------------------------------
88 ' Public properties
89 '----------------------------------------------------------------
90
91 Override Function BaseType() As TypeInfo
92 Return baseType
93 End Function
94
95 Sub SetBaseType( baseType As TypeInfo )
96 This.baseType = baseType
97 End Sub
98
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
150 Inherits TypeBaseImpl
151Public
152 Sub _System_TypeForValueType( name As String )
153 TypeBaseImpl( "", name )
154 End Sub
155
156 Override Function IsValueType() As Boolean
157 Return True
158 End Function
159End Class
160
161' クラスを管理するためのクラス
162Class _System_TypeForClass
163 Inherits TypeBaseImpl
164Public
165 Sub _System_TypeForClass( strNamespace As String, name As String )
166 TypeBaseImpl( strNamespace, name )
167 End Sub
168 Sub ~_System_TypeForClass()
169 End Sub
170 Override Function IsClass() As Boolean
171 Return True
172 End Function
173End Class
174
175' インターフェイスを管理するためのクラス
176Class _System_TypeForInterface
177 Inherits TypeBaseImpl
178Public
179End Class
180
181' 列挙体を管理するためのクラス
182Class _System_TypeForEnum
183 Inherits TypeBaseImpl
184Public
185End Class
186
187' デリゲートを管理するためのクラス
188Class _System_TypeForDelegate
189 Inherits TypeBaseImpl
190Public
191End Class
192
193
194'--------------------------------------------------------------------
195' プロセスに存在するすべての型を管理する
196'--------------------------------------------------------------------
197Class _System_TypeBase
198 Static pTypes As *TypeBaseImpl
199 Static count As Long
200 Static isReady = False
201
202 Static Sub Add( typeInfo As TypeBaseImpl )
203 pTypes = realloc( pTypes, ( count + 1 ) * SizeOf(*TypeInfo) )
204 pTypes[count] = typeInfo
205 count++
206 End Sub
207
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
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
269End Class
270
271
272' End Namespace ' System
Note: See TracBrowser for help on using the repository browser.