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