[206] | 1 | #pragma once
|
---|
| 2 |
|
---|
| 3 | class CClass;
|
---|
| 4 |
|
---|
[290] | 5 | class GenericType;
|
---|
| 6 | typedef std::vector<GenericType> GenericTypes;
|
---|
| 7 |
|
---|
[639] | 8 | class Type
|
---|
| 9 | {
|
---|
[206] | 10 | int basicType;
|
---|
| 11 | union{
|
---|
| 12 | LONG_PTR index;
|
---|
| 13 | const CClass *pClass;
|
---|
| 14 | };
|
---|
[299] | 15 |
|
---|
| 16 | // ジェネリクス クラス インスタンス型の場合に使う
|
---|
[290] | 17 | GenericTypes actualGenericTypes;
|
---|
[206] | 18 |
|
---|
[299] | 19 | // 型パラメータで使う
|
---|
| 20 | std::string formalTypeName; // 型パラメータの名前
|
---|
| 21 | int formalTypeIndex; // 型パラメータの引数番号
|
---|
| 22 |
|
---|
[206] | 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));
|
---|
[293] | 34 | ar & BOOST_SERIALIZATION_NVP( actualGenericTypes );
|
---|
[206] | 35 | }
|
---|
| 36 | else
|
---|
| 37 | {
|
---|
| 38 | ar & BOOST_SERIALIZATION_NVP( index );
|
---|
| 39 | }
|
---|
[299] | 40 |
|
---|
| 41 | if( IsTypeParameter() )
|
---|
| 42 | {
|
---|
| 43 | ar & BOOST_SERIALIZATION_NVP( formalTypeName );
|
---|
| 44 | ar & BOOST_SERIALIZATION_NVP( formalTypeIndex );
|
---|
| 45 | }
|
---|
[206] | 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 |
|
---|
[290] | 58 | Type( int basicType, LONG_PTR index )
|
---|
| 59 | : basicType( basicType )
|
---|
| 60 | , index( index )
|
---|
| 61 | {
|
---|
| 62 | }
|
---|
[206] | 63 |
|
---|
| 64 | Type( int basicType, const CClass &objClass ):
|
---|
| 65 | basicType( basicType ),
|
---|
| 66 | index( (LONG_PTR)&objClass ){}
|
---|
| 67 |
|
---|
[816] | 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))
|
---|
[290] | 74 | {
|
---|
| 75 | }
|
---|
[206] | 76 |
|
---|
[816] | 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 |
|
---|
[290] | 86 | ~Type();
|
---|
| 87 |
|
---|
[816] | 88 | Type& operator =(Type&& type)
|
---|
[290] | 89 | {
|
---|
[816] | 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;
|
---|
[290] | 96 | }
|
---|
| 97 |
|
---|
[816] | 98 | Type& operator =(Type const& type)
|
---|
[206] | 99 | {
|
---|
[816] | 100 | return *this = Type(type);
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | inline int GetBasicType() const
|
---|
| 104 | {
|
---|
[206] | 105 | return basicType;
|
---|
| 106 | }
|
---|
| 107 | LONG_PTR GetIndex() const
|
---|
| 108 | {
|
---|
| 109 | return index;
|
---|
| 110 | }
|
---|
[290] | 111 | const CClass &GetClass() const;
|
---|
[206] | 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 | {
|
---|
[290] | 121 | if( !HasMember() )
|
---|
| 122 | {
|
---|
| 123 | Jenga::Throw( "クラスまたは構造体でない型に対してSetClassPtrを呼び出した" );
|
---|
| 124 | }
|
---|
[206] | 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 | }
|
---|
[290] | 139 | void SetActualGenericTypes( const GenericTypes &genericTypes )
|
---|
| 140 | {
|
---|
| 141 | this->actualGenericTypes = genericTypes;
|
---|
| 142 | }
|
---|
[206] | 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 | }
|
---|
[632] | 154 | void SetPtrLevel( int level )
|
---|
| 155 | {
|
---|
| 156 | basicType = MAKE_PTR_TYPE( NATURAL_TYPE( basicType ), level );
|
---|
| 157 | }
|
---|
[206] | 158 |
|
---|
| 159 | bool Equals( const Type &type ) const;
|
---|
[447] | 160 | bool IsCovariant( const Type &type ) const;
|
---|
[448] | 161 | bool IsContravariant( const Type &type ) const;
|
---|
[206] | 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;
|
---|
[632] | 187 | bool IsValueType() const;
|
---|
[206] | 188 | bool IsProcPtr() const;
|
---|
| 189 | bool IsStruct() const;
|
---|
| 190 | bool IsStructPtr() const;
|
---|
| 191 | bool IsObject() const;
|
---|
| 192 | bool IsObjectPtr() const;
|
---|
[290] | 193 | bool IsTypeParameter() const;
|
---|
[206] | 194 | bool IsObjectClass() const;
|
---|
| 195 | bool IsStringClass() const;
|
---|
| 196 | bool IsVoidPtr() const;
|
---|
| 197 | bool IsAny() const;
|
---|
[332] | 198 | bool IsDelegate() const;
|
---|
[350] | 199 | bool IsInterface() const;
|
---|
[370] | 200 | bool IsComInterface() const;
|
---|
[206] | 201 |
|
---|
| 202 | // オブジェクトや構造体など、メンバを持つ型かどうかを判別する
|
---|
| 203 | bool HasMember() const;
|
---|
| 204 |
|
---|
[299] | 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 |
|
---|
[290] | 239 | // 未完成
|
---|
[301] | 240 | const Type &GetActualGenericType( int index ) const;
|
---|
[290] | 241 | bool HasActualGenericType() const;
|
---|
[206] | 242 |
|
---|
[378] | 243 | //型名を取得
|
---|
| 244 | std::string ToString() const;
|
---|
[206] | 245 |
|
---|
[640] | 246 | virtual bool Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors );
|
---|
[378] | 247 |
|
---|
[639] | 248 |
|
---|
[206] | 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 |
|
---|
[632] | 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:
|
---|
[816] | 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 |
|
---|
[632] | 285 | bool IsEquals( const Types &Types ) const;
|
---|
| 286 | };
|
---|
| 287 |
|
---|
[424] | 288 | /*!
|
---|
| 289 | @brief ジェネリックな型を解決する
|
---|
| 290 | @param typeParameter ジェネリック型を指定する。ここに解決後の型が入る。
|
---|
| 291 | classType インスタンス化されているオブジェクトの型
|
---|
| 292 | pUserProc 現在コンパイル中の関数(ただしクラスメソッドのみ)
|
---|
| 293 | */
|
---|
[299] | 294 | void ResolveFormalGenericTypeParameter( Type &typeParameter, const Type &classType, const UserProc *pUserProc = NULL );
|
---|
| 295 |
|
---|
[290] | 296 | class GenericType
|
---|
| 297 | {
|
---|
| 298 | std::string name;
|
---|
| 299 | Type type;
|
---|
[293] | 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 |
|
---|
[290] | 312 | public:
|
---|
[816] | 313 | GenericType( std::string name, Type type )
|
---|
| 314 | : name(std::move(name))
|
---|
| 315 | , type(std::move(type))
|
---|
[290] | 316 | {
|
---|
| 317 | }
|
---|
[816] | 318 |
|
---|
[290] | 319 | GenericType()
|
---|
| 320 | {
|
---|
| 321 | }
|
---|
[816] | 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 |
|
---|
[290] | 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 | }
|
---|
[639] | 359 | Type &GetType()
|
---|
| 360 | {
|
---|
| 361 | return type;
|
---|
| 362 | }
|
---|
[290] | 363 | };
|
---|
| 364 |
|
---|
[206] | 365 | class BlittableType
|
---|
| 366 | {
|
---|
| 367 | Type basicType;
|
---|
[640] | 368 | const CClass *pClass;
|
---|
[206] | 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 );
|
---|
[640] | 378 | ar & boost::serialization::make_nvp("pClass", const_cast<CClass *&>(pClass) );
|
---|
[206] | 379 | }
|
---|
| 380 |
|
---|
| 381 | public:
|
---|
[640] | 382 | BlittableType( const Type &basicType, const CClass *pClass )
|
---|
[206] | 383 | : basicType( basicType )
|
---|
| 384 | , pClass( pClass )
|
---|
| 385 | {
|
---|
| 386 | }
|
---|
[816] | 387 |
|
---|
[206] | 388 | BlittableType()
|
---|
[816] | 389 | : basicType()
|
---|
| 390 | , pClass()
|
---|
[206] | 391 | {
|
---|
| 392 | }
|
---|
[816] | 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 |
|
---|
[206] | 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;
|
---|
[640] | 427 |
|
---|
| 428 | virtual bool Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors );
|
---|
[206] | 429 | };
|
---|
[816] | 430 |
|
---|
[206] | 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:
|
---|
[816] | 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 |
|
---|
[206] | 458 | bool IsExist( Type type ) const
|
---|
| 459 | {
|
---|
| 460 | const BlittableTypes &blittableTypes = *this;
|
---|
[750] | 461 | foreach( const BlittableType &blittableType, blittableTypes ){
|
---|
[206] | 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;
|
---|
[750] | 471 | foreach( const BlittableType &blittableType, blittableTypes ){
|
---|
[206] | 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;
|
---|
[750] | 484 | foreach( const BlittableType &blittableType, blittableTypes ){
|
---|
[206] | 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 | };
|
---|