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 |
|
---|
140 | bool Equals( const Type &type ) const;
|
---|
141 | bool IsCovariant( const Type &type ) const;
|
---|
142 | bool IsContravariant( const Type &type ) const;
|
---|
143 |
|
---|
144 | int GetBasicSize() const;
|
---|
145 | int GetSize() const;
|
---|
146 |
|
---|
147 | bool IsNull() const;
|
---|
148 |
|
---|
149 | bool IsByte() const;
|
---|
150 | bool IsSByte() const;
|
---|
151 | bool IsWord() const;
|
---|
152 | bool IsInteger() const;
|
---|
153 | bool IsDWord() const;
|
---|
154 | bool IsLong() const;
|
---|
155 | bool IsQWord() const;
|
---|
156 | bool IsInt64() const;
|
---|
157 | bool IsSingle() const;
|
---|
158 | bool IsDouble() const;
|
---|
159 | bool IsBoolean() const;
|
---|
160 |
|
---|
161 | static bool IsPointer( int basicType );
|
---|
162 | bool IsPointer() const;
|
---|
163 | bool IsSigned() const;
|
---|
164 | bool IsNaturalWhole() const;
|
---|
165 | bool IsWhole() const;
|
---|
166 | bool IsReal() const;
|
---|
167 | bool Is64() const;
|
---|
168 | bool IsProcPtr() const;
|
---|
169 | bool IsStruct() const;
|
---|
170 | bool IsStructPtr() const;
|
---|
171 | bool IsObject() const;
|
---|
172 | bool IsObjectPtr() const;
|
---|
173 | bool IsTypeParameter() const;
|
---|
174 | bool IsObjectClass() const;
|
---|
175 | bool IsStringClass() const;
|
---|
176 | bool IsVoidPtr() const;
|
---|
177 | bool IsAny() const;
|
---|
178 | bool IsDelegate() const;
|
---|
179 | bool IsInterface() const;
|
---|
180 | bool IsComInterface() const;
|
---|
181 |
|
---|
182 | // オブジェクトや構造体など、メンバを持つ型かどうかを判別する
|
---|
183 | bool HasMember() const;
|
---|
184 |
|
---|
185 | // 型パラメータの名前を取得
|
---|
186 | const std::string &GetFormalTypeName() const
|
---|
187 | {
|
---|
188 | if( !IsTypeParameter() )
|
---|
189 | {
|
---|
190 | Jenga::Throw( "型パラメータでない型に対してGetFormalTypeNameメソッドが呼ばれた" );
|
---|
191 | }
|
---|
192 | return formalTypeName;
|
---|
193 | }
|
---|
194 | void SetFormalTypeName( const std::string &formalTypeName )
|
---|
195 | {
|
---|
196 | if( !IsTypeParameter() )
|
---|
197 | {
|
---|
198 | Jenga::Throw( "型パラメータでない型に対してSetFormalTypeNameメソッドが呼ばれた" );
|
---|
199 | }
|
---|
200 | this->formalTypeName = formalTypeName;
|
---|
201 | }
|
---|
202 | int GetFormalTypeIndex() const
|
---|
203 | {
|
---|
204 | if( !IsTypeParameter() )
|
---|
205 | {
|
---|
206 | Jenga::Throw( "型パラメータでない型に対してGetFormalTypeIndexメソッドが呼ばれた" );
|
---|
207 | }
|
---|
208 | return formalTypeIndex;
|
---|
209 | }
|
---|
210 | void SetFormalTypeIndex( int formalTypeIndex )
|
---|
211 | {
|
---|
212 | if( !IsTypeParameter() )
|
---|
213 | {
|
---|
214 | Jenga::Throw( "型パラメータでない型に対してSetFormalTypeIndexメソッドが呼ばれた" );
|
---|
215 | }
|
---|
216 | this->formalTypeIndex = formalTypeIndex;
|
---|
217 | }
|
---|
218 |
|
---|
219 | // 未完成
|
---|
220 | const Type &GetActualGenericType( int index ) const;
|
---|
221 | bool HasActualGenericType() const;
|
---|
222 |
|
---|
223 | //型名を取得
|
---|
224 | std::string ToString() const;
|
---|
225 |
|
---|
226 |
|
---|
227 | private:
|
---|
228 | static const int basicTypeList[];
|
---|
229 | static const std::string basicTypeNameList[];
|
---|
230 | public:
|
---|
231 | static bool StringToBasicType( const std::string &typeName, int &basicType );
|
---|
232 | static const char *Type::BasicTypeToCharPtr( const Type &type );
|
---|
233 | static int GetBasicTypeFromSimpleName( const char *variable );
|
---|
234 | };
|
---|
235 | typedef std::vector<Type> Types;
|
---|
236 |
|
---|
237 | /*!
|
---|
238 | @brief ジェネリックな型を解決する
|
---|
239 | @param typeParameter ジェネリック型を指定する。ここに解決後の型が入る。
|
---|
240 | classType インスタンス化されているオブジェクトの型
|
---|
241 | pUserProc 現在コンパイル中の関数(ただしクラスメソッドのみ)
|
---|
242 | */
|
---|
243 | void ResolveFormalGenericTypeParameter( Type &typeParameter, const Type &classType, const UserProc *pUserProc = NULL );
|
---|
244 |
|
---|
245 | class GenericType
|
---|
246 | {
|
---|
247 | std::string name;
|
---|
248 | Type type;
|
---|
249 |
|
---|
250 | // XMLシリアライズ用
|
---|
251 | private:
|
---|
252 | friend class boost::serialization::access;
|
---|
253 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
254 | {
|
---|
255 | trace_for_serialize( "serializing - GenericType" );
|
---|
256 |
|
---|
257 | ar & BOOST_SERIALIZATION_NVP( name );
|
---|
258 | ar & BOOST_SERIALIZATION_NVP( type );
|
---|
259 | }
|
---|
260 |
|
---|
261 | public:
|
---|
262 | GenericType( const std::string &name, const Type &type )
|
---|
263 | : name( name )
|
---|
264 | , type( type )
|
---|
265 | {
|
---|
266 | }
|
---|
267 | GenericType()
|
---|
268 | {
|
---|
269 | }
|
---|
270 | ~GenericType()
|
---|
271 | {
|
---|
272 | }
|
---|
273 |
|
---|
274 | const std::string &GetName() const
|
---|
275 | {
|
---|
276 | return name;
|
---|
277 | }
|
---|
278 | const Type &GetType() const
|
---|
279 | {
|
---|
280 | return type;
|
---|
281 | }
|
---|
282 | };
|
---|
283 |
|
---|
284 | class BlittableType
|
---|
285 | {
|
---|
286 | Type basicType;
|
---|
287 | CClass *pClass;
|
---|
288 |
|
---|
289 | // XMLシリアライズ用
|
---|
290 | private:
|
---|
291 | friend class boost::serialization::access;
|
---|
292 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
293 | {
|
---|
294 | trace_for_serialize( "serializing - BlittableType" );
|
---|
295 |
|
---|
296 | ar & BOOST_SERIALIZATION_NVP( basicType );
|
---|
297 | ar & BOOST_SERIALIZATION_NVP( pClass );
|
---|
298 | }
|
---|
299 |
|
---|
300 | public:
|
---|
301 | bool isTargetObjectModule;
|
---|
302 | BlittableType( const Type &basicType, CClass *pClass )
|
---|
303 | : basicType( basicType )
|
---|
304 | , pClass( pClass )
|
---|
305 | , isTargetObjectModule( true )
|
---|
306 | {
|
---|
307 | }
|
---|
308 | BlittableType()
|
---|
309 | : isTargetObjectModule( true )
|
---|
310 | {
|
---|
311 | }
|
---|
312 | const Type &GetBasicType() const
|
---|
313 | {
|
---|
314 | return basicType;
|
---|
315 | }
|
---|
316 | const CClass *GetClassPtr() const
|
---|
317 | {
|
---|
318 | return pClass;
|
---|
319 | }
|
---|
320 | const std::string GetCreateStaticMethodFullName() const;
|
---|
321 | };
|
---|
322 | class BlittableTypes : public std::vector<BlittableType>
|
---|
323 | {
|
---|
324 | // XMLシリアライズ用
|
---|
325 | private:
|
---|
326 | friend class boost::serialization::access;
|
---|
327 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
328 | {
|
---|
329 | trace_for_serialize( "serializing - BlittableTypes" );
|
---|
330 |
|
---|
331 | ar & boost::serialization::make_nvp("vector_BlittableType",
|
---|
332 | boost::serialization::base_object<std::vector<BlittableType>>(*this));
|
---|
333 | }
|
---|
334 |
|
---|
335 | public:
|
---|
336 | bool IsExist( Type type ) const
|
---|
337 | {
|
---|
338 | const BlittableTypes &blittableTypes = *this;
|
---|
339 | BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
|
---|
340 | if( blittableType.GetBasicType().Equals( type ) ){
|
---|
341 | return true;
|
---|
342 | }
|
---|
343 | }
|
---|
344 | return false;
|
---|
345 | }
|
---|
346 | const BlittableType &Find( const Type &type ) const
|
---|
347 | {
|
---|
348 | const BlittableTypes &blittableTypes = *this;
|
---|
349 | BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
|
---|
350 | if( blittableType.GetBasicType().Equals( type ) ){
|
---|
351 | return blittableType;
|
---|
352 | }
|
---|
353 | }
|
---|
354 | Jenga::Throw( "Blittable型ではない" );
|
---|
355 |
|
---|
356 | static BlittableType dummy;
|
---|
357 | return dummy;
|
---|
358 | }
|
---|
359 | const CClass *GetClassPtr( 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.GetClassPtr();
|
---|
365 | }
|
---|
366 | }
|
---|
367 | return NULL;
|
---|
368 | }
|
---|
369 | const CClass &GetClass( const Type &type ) const
|
---|
370 | {
|
---|
371 | return *GetClassPtr( type );
|
---|
372 | }
|
---|
373 | };
|
---|