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