[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 |
|
---|
[290] | 68 | Type( const Type &type )
|
---|
| 69 | : basicType( type.basicType )
|
---|
| 70 | , index( type.index )
|
---|
| 71 | , actualGenericTypes( type.actualGenericTypes )
|
---|
[299] | 72 | , formalTypeName( type.formalTypeName )
|
---|
| 73 | , formalTypeIndex( type.formalTypeIndex )
|
---|
[290] | 74 | {
|
---|
| 75 | }
|
---|
[206] | 76 |
|
---|
[290] | 77 | ~Type();
|
---|
| 78 |
|
---|
| 79 | void operator= ( const Type &type )
|
---|
| 80 | {
|
---|
| 81 | basicType = type.basicType;
|
---|
| 82 | index = type.index;
|
---|
| 83 | actualGenericTypes = type.actualGenericTypes;
|
---|
[299] | 84 | formalTypeName = type.formalTypeName;
|
---|
| 85 | formalTypeIndex = type.formalTypeIndex;
|
---|
[290] | 86 | }
|
---|
| 87 |
|
---|
[206] | 88 | __inline int GetBasicType() const
|
---|
| 89 | {
|
---|
| 90 | return basicType;
|
---|
| 91 | }
|
---|
| 92 | LONG_PTR GetIndex() const
|
---|
| 93 | {
|
---|
| 94 | return index;
|
---|
| 95 | }
|
---|
[290] | 96 | const CClass &GetClass() const;
|
---|
[206] | 97 |
|
---|
| 98 | void SetBasicType( int basicType ){
|
---|
| 99 | this->basicType = basicType;
|
---|
| 100 | }
|
---|
| 101 | void SetIndex( LONG_PTR index ){
|
---|
| 102 | this->index = index;
|
---|
| 103 | }
|
---|
| 104 | void SetClassPtr( const CClass *pClass )
|
---|
| 105 | {
|
---|
[290] | 106 | if( !HasMember() )
|
---|
| 107 | {
|
---|
| 108 | Jenga::Throw( "クラスまたは構造体でない型に対してSetClassPtrを呼び出した" );
|
---|
| 109 | }
|
---|
[206] | 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 | }
|
---|
[290] | 124 | void SetActualGenericTypes( const GenericTypes &genericTypes )
|
---|
| 125 | {
|
---|
| 126 | this->actualGenericTypes = genericTypes;
|
---|
| 127 | }
|
---|
[206] | 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 | }
|
---|
[632] | 139 | void SetPtrLevel( int level )
|
---|
| 140 | {
|
---|
| 141 | basicType = MAKE_PTR_TYPE( NATURAL_TYPE( basicType ), level );
|
---|
| 142 | }
|
---|
[206] | 143 |
|
---|
| 144 | bool Equals( const Type &type ) const;
|
---|
[447] | 145 | bool IsCovariant( const Type &type ) const;
|
---|
[448] | 146 | bool IsContravariant( const Type &type ) const;
|
---|
[206] | 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;
|
---|
[632] | 172 | bool IsValueType() const;
|
---|
[206] | 173 | bool IsProcPtr() const;
|
---|
| 174 | bool IsStruct() const;
|
---|
| 175 | bool IsStructPtr() const;
|
---|
| 176 | bool IsObject() const;
|
---|
| 177 | bool IsObjectPtr() const;
|
---|
[290] | 178 | bool IsTypeParameter() const;
|
---|
[206] | 179 | bool IsObjectClass() const;
|
---|
| 180 | bool IsStringClass() const;
|
---|
| 181 | bool IsVoidPtr() const;
|
---|
| 182 | bool IsAny() const;
|
---|
[332] | 183 | bool IsDelegate() const;
|
---|
[350] | 184 | bool IsInterface() const;
|
---|
[370] | 185 | bool IsComInterface() const;
|
---|
[206] | 186 |
|
---|
| 187 | // オブジェクトや構造体など、メンバを持つ型かどうかを判別する
|
---|
| 188 | bool HasMember() const;
|
---|
| 189 |
|
---|
[299] | 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 |
|
---|
[290] | 224 | // 未完成
|
---|
[301] | 225 | const Type &GetActualGenericType( int index ) const;
|
---|
[290] | 226 | bool HasActualGenericType() const;
|
---|
[206] | 227 |
|
---|
[378] | 228 | //型名を取得
|
---|
| 229 | std::string ToString() const;
|
---|
[206] | 230 |
|
---|
[640] | 231 | virtual bool Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors );
|
---|
[378] | 232 |
|
---|
[639] | 233 |
|
---|
[206] | 234 | private:
|
---|
| 235 | static const int basicTypeList[];
|
---|
| 236 | static const std::string basicTypeNameList[];
|
---|
| 237 | public:
|
---|
| 238 | static bool StringToBasicType( const std::string &typeName, int &basicType );
|
---|
| 239 | static const char *Type::BasicTypeToCharPtr( const Type &type );
|
---|
| 240 | static int GetBasicTypeFromSimpleName( const char *variable );
|
---|
| 241 | };
|
---|
| 242 |
|
---|
[632] | 243 | class Types
|
---|
| 244 | : public std::vector<Type>
|
---|
| 245 | {
|
---|
| 246 | // XMLシリアライズ用
|
---|
| 247 | private:
|
---|
| 248 | friend class boost::serialization::access;
|
---|
| 249 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 250 | {
|
---|
| 251 | ar & boost::serialization::make_nvp("vector_Type", boost::serialization::base_object<vector<Type>>(*this));
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | public:
|
---|
| 255 | bool IsEquals( const Types &Types ) const;
|
---|
| 256 | };
|
---|
| 257 |
|
---|
[424] | 258 | /*!
|
---|
| 259 | @brief ジェネリックな型を解決する
|
---|
| 260 | @param typeParameter ジェネリック型を指定する。ここに解決後の型が入る。
|
---|
| 261 | classType インスタンス化されているオブジェクトの型
|
---|
| 262 | pUserProc 現在コンパイル中の関数(ただしクラスメソッドのみ)
|
---|
| 263 | */
|
---|
[299] | 264 | void ResolveFormalGenericTypeParameter( Type &typeParameter, const Type &classType, const UserProc *pUserProc = NULL );
|
---|
| 265 |
|
---|
[290] | 266 | class GenericType
|
---|
| 267 | {
|
---|
| 268 | std::string name;
|
---|
| 269 | Type type;
|
---|
[293] | 270 |
|
---|
| 271 | // XMLシリアライズ用
|
---|
| 272 | private:
|
---|
| 273 | friend class boost::serialization::access;
|
---|
| 274 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 275 | {
|
---|
| 276 | trace_for_serialize( "serializing - GenericType" );
|
---|
| 277 |
|
---|
| 278 | ar & BOOST_SERIALIZATION_NVP( name );
|
---|
| 279 | ar & BOOST_SERIALIZATION_NVP( type );
|
---|
| 280 | }
|
---|
| 281 |
|
---|
[290] | 282 | public:
|
---|
| 283 | GenericType( const std::string &name, const Type &type )
|
---|
| 284 | : name( name )
|
---|
| 285 | , type( type )
|
---|
| 286 | {
|
---|
| 287 | }
|
---|
| 288 | GenericType()
|
---|
| 289 | {
|
---|
| 290 | }
|
---|
| 291 | ~GenericType()
|
---|
| 292 | {
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | const std::string &GetName() const
|
---|
| 296 | {
|
---|
| 297 | return name;
|
---|
| 298 | }
|
---|
| 299 | const Type &GetType() const
|
---|
| 300 | {
|
---|
| 301 | return type;
|
---|
| 302 | }
|
---|
[639] | 303 | Type &GetType()
|
---|
| 304 | {
|
---|
| 305 | return type;
|
---|
| 306 | }
|
---|
[290] | 307 | };
|
---|
| 308 |
|
---|
[206] | 309 | class BlittableType
|
---|
| 310 | {
|
---|
| 311 | Type basicType;
|
---|
[640] | 312 | const CClass *pClass;
|
---|
[206] | 313 |
|
---|
| 314 | // XMLシリアライズ用
|
---|
| 315 | private:
|
---|
| 316 | friend class boost::serialization::access;
|
---|
| 317 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 318 | {
|
---|
| 319 | trace_for_serialize( "serializing - BlittableType" );
|
---|
| 320 |
|
---|
| 321 | ar & BOOST_SERIALIZATION_NVP( basicType );
|
---|
[640] | 322 | ar & boost::serialization::make_nvp("pClass", const_cast<CClass *&>(pClass) );
|
---|
[206] | 323 | }
|
---|
| 324 |
|
---|
| 325 | public:
|
---|
[640] | 326 | BlittableType( const Type &basicType, const CClass *pClass )
|
---|
[206] | 327 | : basicType( basicType )
|
---|
| 328 | , pClass( pClass )
|
---|
| 329 | {
|
---|
| 330 | }
|
---|
| 331 | BlittableType()
|
---|
| 332 | {
|
---|
| 333 | }
|
---|
| 334 | const Type &GetBasicType() const
|
---|
| 335 | {
|
---|
| 336 | return basicType;
|
---|
| 337 | }
|
---|
| 338 | const CClass *GetClassPtr() const
|
---|
| 339 | {
|
---|
| 340 | return pClass;
|
---|
| 341 | }
|
---|
| 342 | const std::string GetCreateStaticMethodFullName() const;
|
---|
[640] | 343 |
|
---|
| 344 | virtual bool Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors );
|
---|
[206] | 345 | };
|
---|
| 346 | class BlittableTypes : public std::vector<BlittableType>
|
---|
| 347 | {
|
---|
| 348 | // XMLシリアライズ用
|
---|
| 349 | private:
|
---|
| 350 | friend class boost::serialization::access;
|
---|
| 351 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 352 | {
|
---|
| 353 | trace_for_serialize( "serializing - BlittableTypes" );
|
---|
| 354 |
|
---|
| 355 | ar & boost::serialization::make_nvp("vector_BlittableType",
|
---|
| 356 | boost::serialization::base_object<std::vector<BlittableType>>(*this));
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 | public:
|
---|
| 360 | bool IsExist( Type type ) const
|
---|
| 361 | {
|
---|
| 362 | const BlittableTypes &blittableTypes = *this;
|
---|
| 363 | BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
|
---|
| 364 | if( blittableType.GetBasicType().Equals( type ) ){
|
---|
| 365 | return true;
|
---|
| 366 | }
|
---|
| 367 | }
|
---|
| 368 | return false;
|
---|
| 369 | }
|
---|
| 370 | const BlittableType &Find( const Type &type ) const
|
---|
| 371 | {
|
---|
| 372 | const BlittableTypes &blittableTypes = *this;
|
---|
| 373 | BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
|
---|
| 374 | if( blittableType.GetBasicType().Equals( type ) ){
|
---|
| 375 | return blittableType;
|
---|
| 376 | }
|
---|
| 377 | }
|
---|
| 378 | Jenga::Throw( "Blittable型ではない" );
|
---|
| 379 |
|
---|
| 380 | static BlittableType dummy;
|
---|
| 381 | return dummy;
|
---|
| 382 | }
|
---|
| 383 | const CClass *GetClassPtr( const Type &type ) const
|
---|
| 384 | {
|
---|
| 385 | const BlittableTypes &blittableTypes = *this;
|
---|
| 386 | BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
|
---|
| 387 | if( blittableType.GetBasicType().Equals( type ) ){
|
---|
| 388 | return blittableType.GetClassPtr();
|
---|
| 389 | }
|
---|
| 390 | }
|
---|
| 391 | return NULL;
|
---|
| 392 | }
|
---|
| 393 | const CClass &GetClass( const Type &type ) const
|
---|
| 394 | {
|
---|
| 395 | return *GetClassPtr( type );
|
---|
| 396 | }
|
---|
| 397 | };
|
---|