1 | #pragma once
|
---|
2 |
|
---|
3 | class CClass;
|
---|
4 |
|
---|
5 | class GenericType;
|
---|
6 | typedef std::vector<GenericType> GenericTypes;
|
---|
7 |
|
---|
8 | class Type
|
---|
9 | {
|
---|
10 | int basicType;
|
---|
11 | union{
|
---|
12 | LONG_PTR index;
|
---|
13 | const CClass *pClass;
|
---|
14 | };
|
---|
15 |
|
---|
16 | // ジェネリクス クラス インスタンス型の場合に使う
|
---|
17 | GenericTypes actualGenericTypes;
|
---|
18 |
|
---|
19 | // 型パラメータで使う
|
---|
20 | std::string formalTypeName; // 型パラメータの名前
|
---|
21 | int formalTypeIndex; // 型パラメータの引数番号
|
---|
22 |
|
---|
23 | // XMLシリアライズ用
|
---|
24 | private:
|
---|
25 | friend class boost::serialization::access;
|
---|
26 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
27 | {
|
---|
28 | trace_for_serialize( "serializing - Type" );
|
---|
29 |
|
---|
30 | ar & BOOST_SERIALIZATION_NVP( basicType );
|
---|
31 | if( HasMember() )
|
---|
32 | {
|
---|
33 | ar & boost::serialization::make_nvp("pClass", const_cast<CClass *&>(pClass));
|
---|
34 | ar & BOOST_SERIALIZATION_NVP( actualGenericTypes );
|
---|
35 | }
|
---|
36 | else
|
---|
37 | {
|
---|
38 | ar & BOOST_SERIALIZATION_NVP( index );
|
---|
39 | }
|
---|
40 |
|
---|
41 | if( IsTypeParameter() )
|
---|
42 | {
|
---|
43 | ar & BOOST_SERIALIZATION_NVP( formalTypeName );
|
---|
44 | ar & BOOST_SERIALIZATION_NVP( formalTypeIndex );
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | public:
|
---|
49 | static int GetBasicSize( int basicType );
|
---|
50 |
|
---|
51 | Type():
|
---|
52 | basicType( DEF_NON ),
|
---|
53 | index( -1 ){}
|
---|
54 | Type( int basicType ):
|
---|
55 | basicType( basicType ),
|
---|
56 | index( -1 ){}
|
---|
57 |
|
---|
58 | Type( int basicType, LONG_PTR index )
|
---|
59 | : basicType( basicType )
|
---|
60 | , index( index )
|
---|
61 | {
|
---|
62 | }
|
---|
63 |
|
---|
64 | Type( int basicType, const CClass &objClass ):
|
---|
65 | basicType( basicType ),
|
---|
66 | index( (LONG_PTR)&objClass ){}
|
---|
67 |
|
---|
68 | Type( const Type &type )
|
---|
69 | : basicType( type.basicType )
|
---|
70 | , index( type.index )
|
---|
71 | , actualGenericTypes( type.actualGenericTypes )
|
---|
72 | , formalTypeName( type.formalTypeName )
|
---|
73 | , formalTypeIndex( type.formalTypeIndex )
|
---|
74 | {
|
---|
75 | }
|
---|
76 |
|
---|
77 | ~Type();
|
---|
78 |
|
---|
79 | void operator= ( const Type &type )
|
---|
80 | {
|
---|
81 | basicType = type.basicType;
|
---|
82 | index = type.index;
|
---|
83 | actualGenericTypes = type.actualGenericTypes;
|
---|
84 | formalTypeName = type.formalTypeName;
|
---|
85 | formalTypeIndex = type.formalTypeIndex;
|
---|
86 | }
|
---|
87 |
|
---|
88 | __inline int GetBasicType() const
|
---|
89 | {
|
---|
90 | return basicType;
|
---|
91 | }
|
---|
92 | LONG_PTR GetIndex() const
|
---|
93 | {
|
---|
94 | return index;
|
---|
95 | }
|
---|
96 | const CClass &GetClass() const;
|
---|
97 |
|
---|
98 | void SetBasicType( int basicType ){
|
---|
99 | this->basicType = basicType;
|
---|
100 | }
|
---|
101 | void SetIndex( LONG_PTR index ){
|
---|
102 | this->index = index;
|
---|
103 | }
|
---|
104 | void SetClassPtr( const CClass *pClass )
|
---|
105 | {
|
---|
106 | int naturalBasicType = NATURAL_TYPE( basicType );
|
---|
107 | if( !HasMember() )
|
---|
108 | {
|
---|
109 | Jenga::Throw( "クラスまたは構造体でない型に対してSetClassPtrを呼び出した" );
|
---|
110 | }
|
---|
111 | this->pClass = pClass;
|
---|
112 | }
|
---|
113 | void SetNull(){
|
---|
114 | SetBasicType( DEF_NON );
|
---|
115 | SetIndex( -1 );
|
---|
116 | }
|
---|
117 | void SetType( int basicType, LONG_PTR index ){
|
---|
118 | SetBasicType( basicType );
|
---|
119 | SetIndex( index );
|
---|
120 | }
|
---|
121 | void SetType( int basicType, const CClass *pClass ){
|
---|
122 | SetBasicType( basicType );
|
---|
123 | this->pClass = pClass;
|
---|
124 | }
|
---|
125 | void SetActualGenericTypes( const GenericTypes &genericTypes )
|
---|
126 | {
|
---|
127 | this->actualGenericTypes = genericTypes;
|
---|
128 | }
|
---|
129 |
|
---|
130 | int PtrLevel() const
|
---|
131 | {
|
---|
132 | return PTR_LEVEL( basicType );
|
---|
133 | }
|
---|
134 | void PtrLevelUp(){
|
---|
135 | PTR_LEVEL_UP( basicType );
|
---|
136 | }
|
---|
137 | void PtrLevelDown(){
|
---|
138 | PTR_LEVEL_DOWN( basicType );
|
---|
139 | }
|
---|
140 | void SetPtrLevel( int level )
|
---|
141 | {
|
---|
142 | basicType = MAKE_PTR_TYPE( NATURAL_TYPE( basicType ), level );
|
---|
143 | }
|
---|
144 |
|
---|
145 | bool Equals( const Type &type ) const;
|
---|
146 | bool IsCovariant( const Type &type ) const;
|
---|
147 | bool IsContravariant( const Type &type ) const;
|
---|
148 |
|
---|
149 | int GetBasicSize() const;
|
---|
150 | int GetSize() const;
|
---|
151 |
|
---|
152 | bool IsNull() const;
|
---|
153 |
|
---|
154 | bool IsByte() const;
|
---|
155 | bool IsSByte() const;
|
---|
156 | bool IsWord() const;
|
---|
157 | bool IsInteger() const;
|
---|
158 | bool IsDWord() const;
|
---|
159 | bool IsLong() const;
|
---|
160 | bool IsQWord() const;
|
---|
161 | bool IsInt64() const;
|
---|
162 | bool IsSingle() const;
|
---|
163 | bool IsDouble() const;
|
---|
164 | bool IsBoolean() const;
|
---|
165 |
|
---|
166 | static bool IsPointer( int basicType );
|
---|
167 | bool IsPointer() const;
|
---|
168 | bool IsSigned() const;
|
---|
169 | bool IsNaturalWhole() const;
|
---|
170 | bool IsWhole() const;
|
---|
171 | bool IsReal() const;
|
---|
172 | bool Is64() const;
|
---|
173 | bool IsValueType() const;
|
---|
174 | bool IsProcPtr() const;
|
---|
175 | bool IsStruct() const;
|
---|
176 | bool IsStructPtr() const;
|
---|
177 | bool IsObject() const;
|
---|
178 | bool IsObjectPtr() const;
|
---|
179 | bool IsTypeParameter() const;
|
---|
180 | bool IsObjectClass() const;
|
---|
181 | bool IsStringClass() const;
|
---|
182 | bool IsVoidPtr() const;
|
---|
183 | bool IsAny() const;
|
---|
184 | bool IsDelegate() const;
|
---|
185 | bool IsInterface() const;
|
---|
186 | bool IsComInterface() const;
|
---|
187 |
|
---|
188 | // オブジェクトや構造体など、メンバを持つ型かどうかを判別する
|
---|
189 | bool HasMember() const;
|
---|
190 |
|
---|
191 | // 型パラメータの名前を取得
|
---|
192 | const std::string &GetFormalTypeName() const
|
---|
193 | {
|
---|
194 | if( !IsTypeParameter() )
|
---|
195 | {
|
---|
196 | Jenga::Throw( "型パラメータでない型に対してGetFormalTypeNameメソッドが呼ばれた" );
|
---|
197 | }
|
---|
198 | return formalTypeName;
|
---|
199 | }
|
---|
200 | void SetFormalTypeName( const std::string &formalTypeName )
|
---|
201 | {
|
---|
202 | if( !IsTypeParameter() )
|
---|
203 | {
|
---|
204 | Jenga::Throw( "型パラメータでない型に対してSetFormalTypeNameメソッドが呼ばれた" );
|
---|
205 | }
|
---|
206 | this->formalTypeName = formalTypeName;
|
---|
207 | }
|
---|
208 | int GetFormalTypeIndex() const
|
---|
209 | {
|
---|
210 | if( !IsTypeParameter() )
|
---|
211 | {
|
---|
212 | Jenga::Throw( "型パラメータでない型に対してGetFormalTypeIndexメソッドが呼ばれた" );
|
---|
213 | }
|
---|
214 | return formalTypeIndex;
|
---|
215 | }
|
---|
216 | void SetFormalTypeIndex( int formalTypeIndex )
|
---|
217 | {
|
---|
218 | if( !IsTypeParameter() )
|
---|
219 | {
|
---|
220 | Jenga::Throw( "型パラメータでない型に対してSetFormalTypeIndexメソッドが呼ばれた" );
|
---|
221 | }
|
---|
222 | this->formalTypeIndex = formalTypeIndex;
|
---|
223 | }
|
---|
224 |
|
---|
225 | // 未完成
|
---|
226 | const Type &GetActualGenericType( int index ) const;
|
---|
227 | bool HasActualGenericType() const;
|
---|
228 |
|
---|
229 | //型名を取得
|
---|
230 | std::string ToString() const;
|
---|
231 |
|
---|
232 | virtual bool Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors );
|
---|
233 |
|
---|
234 |
|
---|
235 | private:
|
---|
236 | static const int basicTypeList[];
|
---|
237 | static const std::string basicTypeNameList[];
|
---|
238 | public:
|
---|
239 | static bool StringToBasicType( const std::string &typeName, int &basicType );
|
---|
240 | static const char *Type::BasicTypeToCharPtr( const Type &type );
|
---|
241 | static int GetBasicTypeFromSimpleName( const char *variable );
|
---|
242 | };
|
---|
243 |
|
---|
244 | class Types
|
---|
245 | : public std::vector<Type>
|
---|
246 | {
|
---|
247 | // XMLシリアライズ用
|
---|
248 | private:
|
---|
249 | friend class boost::serialization::access;
|
---|
250 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
251 | {
|
---|
252 | ar & boost::serialization::make_nvp("vector_Type", boost::serialization::base_object<vector<Type>>(*this));
|
---|
253 | }
|
---|
254 |
|
---|
255 | public:
|
---|
256 | bool IsEquals( const Types &Types ) const;
|
---|
257 | };
|
---|
258 |
|
---|
259 | /*!
|
---|
260 | @brief ジェネリックな型を解決する
|
---|
261 | @param typeParameter ジェネリック型を指定する。ここに解決後の型が入る。
|
---|
262 | classType インスタンス化されているオブジェクトの型
|
---|
263 | pUserProc 現在コンパイル中の関数(ただしクラスメソッドのみ)
|
---|
264 | */
|
---|
265 | void ResolveFormalGenericTypeParameter( Type &typeParameter, const Type &classType, const UserProc *pUserProc = NULL );
|
---|
266 |
|
---|
267 | class GenericType
|
---|
268 | {
|
---|
269 | std::string name;
|
---|
270 | Type type;
|
---|
271 |
|
---|
272 | // XMLシリアライズ用
|
---|
273 | private:
|
---|
274 | friend class boost::serialization::access;
|
---|
275 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
276 | {
|
---|
277 | trace_for_serialize( "serializing - GenericType" );
|
---|
278 |
|
---|
279 | ar & BOOST_SERIALIZATION_NVP( name );
|
---|
280 | ar & BOOST_SERIALIZATION_NVP( type );
|
---|
281 | }
|
---|
282 |
|
---|
283 | public:
|
---|
284 | GenericType( const std::string &name, const Type &type )
|
---|
285 | : name( name )
|
---|
286 | , type( type )
|
---|
287 | {
|
---|
288 | }
|
---|
289 | GenericType()
|
---|
290 | {
|
---|
291 | }
|
---|
292 | ~GenericType()
|
---|
293 | {
|
---|
294 | }
|
---|
295 |
|
---|
296 | const std::string &GetName() const
|
---|
297 | {
|
---|
298 | return name;
|
---|
299 | }
|
---|
300 | const Type &GetType() const
|
---|
301 | {
|
---|
302 | return type;
|
---|
303 | }
|
---|
304 | Type &GetType()
|
---|
305 | {
|
---|
306 | return type;
|
---|
307 | }
|
---|
308 | };
|
---|
309 |
|
---|
310 | class BlittableType
|
---|
311 | {
|
---|
312 | Type basicType;
|
---|
313 | const CClass *pClass;
|
---|
314 |
|
---|
315 | // XMLシリアライズ用
|
---|
316 | private:
|
---|
317 | friend class boost::serialization::access;
|
---|
318 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
319 | {
|
---|
320 | trace_for_serialize( "serializing - BlittableType" );
|
---|
321 |
|
---|
322 | ar & BOOST_SERIALIZATION_NVP( basicType );
|
---|
323 | ar & boost::serialization::make_nvp("pClass", const_cast<CClass *&>(pClass) );
|
---|
324 | }
|
---|
325 |
|
---|
326 | public:
|
---|
327 | BlittableType( const Type &basicType, const CClass *pClass )
|
---|
328 | : basicType( basicType )
|
---|
329 | , pClass( pClass )
|
---|
330 | {
|
---|
331 | }
|
---|
332 | BlittableType()
|
---|
333 | {
|
---|
334 | }
|
---|
335 | const Type &GetBasicType() const
|
---|
336 | {
|
---|
337 | return basicType;
|
---|
338 | }
|
---|
339 | const CClass *GetClassPtr() const
|
---|
340 | {
|
---|
341 | return pClass;
|
---|
342 | }
|
---|
343 | const std::string GetCreateStaticMethodFullName() const;
|
---|
344 |
|
---|
345 | virtual bool Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors );
|
---|
346 | };
|
---|
347 | class BlittableTypes : public std::vector<BlittableType>
|
---|
348 | {
|
---|
349 | // XMLシリアライズ用
|
---|
350 | private:
|
---|
351 | friend class boost::serialization::access;
|
---|
352 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
353 | {
|
---|
354 | trace_for_serialize( "serializing - BlittableTypes" );
|
---|
355 |
|
---|
356 | ar & boost::serialization::make_nvp("vector_BlittableType",
|
---|
357 | boost::serialization::base_object<std::vector<BlittableType>>(*this));
|
---|
358 | }
|
---|
359 |
|
---|
360 | public:
|
---|
361 | bool IsExist( Type type ) const
|
---|
362 | {
|
---|
363 | const BlittableTypes &blittableTypes = *this;
|
---|
364 | BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
|
---|
365 | if( blittableType.GetBasicType().Equals( type ) ){
|
---|
366 | return true;
|
---|
367 | }
|
---|
368 | }
|
---|
369 | return false;
|
---|
370 | }
|
---|
371 | const BlittableType &Find( const Type &type ) const
|
---|
372 | {
|
---|
373 | const BlittableTypes &blittableTypes = *this;
|
---|
374 | BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
|
---|
375 | if( blittableType.GetBasicType().Equals( type ) ){
|
---|
376 | return blittableType;
|
---|
377 | }
|
---|
378 | }
|
---|
379 | Jenga::Throw( "Blittable型ではない" );
|
---|
380 |
|
---|
381 | static BlittableType dummy;
|
---|
382 | return dummy;
|
---|
383 | }
|
---|
384 | const CClass *GetClassPtr( const Type &type ) const
|
---|
385 | {
|
---|
386 | const BlittableTypes &blittableTypes = *this;
|
---|
387 | BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
|
---|
388 | if( blittableType.GetBasicType().Equals( type ) ){
|
---|
389 | return blittableType.GetClassPtr();
|
---|
390 | }
|
---|
391 | }
|
---|
392 | return NULL;
|
---|
393 | }
|
---|
394 | const CClass &GetClass( const Type &type ) const
|
---|
395 | {
|
---|
396 | return *GetClassPtr( type );
|
---|
397 | }
|
---|
398 | };
|
---|