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