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