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