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