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