[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 | };
|
---|
[290] | 28 | GenericTypes actualGenericTypes;
|
---|
[206] | 29 |
|
---|
| 30 | // XMLシリアライズ用
|
---|
| 31 | private:
|
---|
| 32 | friend class boost::serialization::access;
|
---|
| 33 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 34 | {
|
---|
| 35 | trace_for_serialize( "serializing - Type" );
|
---|
| 36 |
|
---|
| 37 | ar & BOOST_SERIALIZATION_NVP( basicType );
|
---|
| 38 | if( HasMember() )
|
---|
| 39 | {
|
---|
| 40 | ar & boost::serialization::make_nvp("pClass", const_cast<CClass *&>(pClass));
|
---|
| 41 | }
|
---|
| 42 | else
|
---|
| 43 | {
|
---|
| 44 | ar & BOOST_SERIALIZATION_NVP( index );
|
---|
| 45 | }
|
---|
| 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 )
|
---|
| 72 | {
|
---|
| 73 | }
|
---|
[206] | 74 |
|
---|
[290] | 75 | ~Type();
|
---|
| 76 |
|
---|
| 77 | void operator= ( const Type &type )
|
---|
| 78 | {
|
---|
| 79 | basicType = type.basicType;
|
---|
| 80 | index = type.index;
|
---|
| 81 | actualGenericTypes = type.actualGenericTypes;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[206] | 84 | __inline int GetBasicType() const
|
---|
| 85 | {
|
---|
| 86 | return basicType;
|
---|
| 87 | }
|
---|
| 88 | LONG_PTR GetIndex() const
|
---|
| 89 | {
|
---|
| 90 | return index;
|
---|
| 91 | }
|
---|
[290] | 92 | const CClass &GetClass() const;
|
---|
[206] | 93 |
|
---|
| 94 | void SetBasicType( int basicType ){
|
---|
| 95 | this->basicType = basicType;
|
---|
| 96 | }
|
---|
| 97 | void SetIndex( LONG_PTR index ){
|
---|
| 98 | this->index = index;
|
---|
| 99 | }
|
---|
| 100 | void SetClassPtr( const CClass *pClass )
|
---|
| 101 | {
|
---|
[290] | 102 | int naturalBasicType = NATURAL_TYPE( basicType );
|
---|
| 103 | if( !HasMember() )
|
---|
| 104 | {
|
---|
| 105 | Jenga::Throw( "クラスまたは構造体でない型に対してSetClassPtrを呼び出した" );
|
---|
| 106 | }
|
---|
[206] | 107 | this->pClass = pClass;
|
---|
| 108 | }
|
---|
| 109 | void SetNull(){
|
---|
| 110 | SetBasicType( DEF_NON );
|
---|
| 111 | SetIndex( -1 );
|
---|
| 112 | }
|
---|
| 113 | void SetType( int basicType, LONG_PTR index ){
|
---|
| 114 | SetBasicType( basicType );
|
---|
| 115 | SetIndex( index );
|
---|
| 116 | }
|
---|
| 117 | void SetType( int basicType, const CClass *pClass ){
|
---|
| 118 | SetBasicType( basicType );
|
---|
| 119 | this->pClass = pClass;
|
---|
| 120 | }
|
---|
[290] | 121 | void SetActualGenericTypes( const GenericTypes &genericTypes )
|
---|
| 122 | {
|
---|
| 123 | this->actualGenericTypes = genericTypes;
|
---|
| 124 | }
|
---|
[206] | 125 |
|
---|
| 126 | int PtrLevel() const
|
---|
| 127 | {
|
---|
| 128 | return PTR_LEVEL( basicType );
|
---|
| 129 | }
|
---|
| 130 | void PtrLevelUp(){
|
---|
| 131 | PTR_LEVEL_UP( basicType );
|
---|
| 132 | }
|
---|
| 133 | void PtrLevelDown(){
|
---|
| 134 | PTR_LEVEL_DOWN( basicType );
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | bool Equals( const Type &type ) const;
|
---|
| 138 |
|
---|
| 139 | int GetBasicSize() const;
|
---|
| 140 | int GetSize() const;
|
---|
| 141 |
|
---|
| 142 | bool IsNull() const;
|
---|
| 143 |
|
---|
| 144 | bool IsByte() const;
|
---|
| 145 | bool IsSByte() const;
|
---|
| 146 | bool IsWord() const;
|
---|
| 147 | bool IsInteger() const;
|
---|
| 148 | bool IsDWord() const;
|
---|
| 149 | bool IsLong() const;
|
---|
| 150 | bool IsQWord() const;
|
---|
| 151 | bool IsInt64() const;
|
---|
| 152 | bool IsSingle() const;
|
---|
| 153 | bool IsDouble() const;
|
---|
| 154 | bool IsBoolean() const;
|
---|
| 155 |
|
---|
| 156 | static bool IsPointer( int basicType );
|
---|
| 157 | bool IsPointer() const;
|
---|
| 158 | bool IsSigned() const;
|
---|
| 159 | bool IsNaturalWhole() const;
|
---|
| 160 | bool IsWhole() const;
|
---|
| 161 | bool IsReal() const;
|
---|
| 162 | bool Is64() const;
|
---|
| 163 | bool IsProcPtr() const;
|
---|
| 164 | bool IsStruct() const;
|
---|
| 165 | bool IsStructPtr() const;
|
---|
| 166 | bool IsObject() const;
|
---|
| 167 | bool IsObjectPtr() const;
|
---|
[290] | 168 | bool IsTypeParameter() const;
|
---|
[206] | 169 | bool IsObjectClass() const;
|
---|
| 170 | bool IsStringClass() const;
|
---|
| 171 | bool IsVoidPtr() const;
|
---|
| 172 | bool IsAny() const;
|
---|
| 173 |
|
---|
| 174 | // オブジェクトや構造体など、メンバを持つ型かどうかを判別する
|
---|
| 175 | bool HasMember() const;
|
---|
| 176 |
|
---|
[290] | 177 | // 未完成
|
---|
| 178 | const Type &GetDummyActualGenericType() const;
|
---|
| 179 | bool HasActualGenericType() const;
|
---|
[206] | 180 |
|
---|
| 181 |
|
---|
| 182 | private:
|
---|
| 183 | static const int basicTypeList[];
|
---|
| 184 | static const std::string basicTypeNameList[];
|
---|
| 185 | public:
|
---|
| 186 | static bool StringToBasicType( const std::string &typeName, int &basicType );
|
---|
| 187 | static const char *Type::BasicTypeToCharPtr( const Type &type );
|
---|
| 188 | static int GetBasicTypeFromSimpleName( const char *variable );
|
---|
| 189 | };
|
---|
| 190 |
|
---|
[290] | 191 | class GenericType
|
---|
| 192 | {
|
---|
| 193 | std::string name;
|
---|
| 194 | Type type;
|
---|
| 195 | public:
|
---|
| 196 | GenericType( const std::string &name, const Type &type )
|
---|
| 197 | : name( name )
|
---|
| 198 | , type( type )
|
---|
| 199 | {
|
---|
| 200 | }
|
---|
| 201 | GenericType()
|
---|
| 202 | {
|
---|
| 203 | }
|
---|
| 204 | ~GenericType()
|
---|
| 205 | {
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | const std::string &GetName() const
|
---|
| 209 | {
|
---|
| 210 | return name;
|
---|
| 211 | }
|
---|
| 212 | const Type &GetType() const
|
---|
| 213 | {
|
---|
| 214 | return type;
|
---|
| 215 | }
|
---|
| 216 | };
|
---|
| 217 |
|
---|
[206] | 218 | class BlittableType
|
---|
| 219 | {
|
---|
| 220 | Type basicType;
|
---|
| 221 | CClass *pClass;
|
---|
| 222 |
|
---|
| 223 | // XMLシリアライズ用
|
---|
| 224 | private:
|
---|
| 225 | friend class boost::serialization::access;
|
---|
| 226 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 227 | {
|
---|
| 228 | trace_for_serialize( "serializing - BlittableType" );
|
---|
| 229 |
|
---|
| 230 | ar & BOOST_SERIALIZATION_NVP( basicType );
|
---|
| 231 | ar & BOOST_SERIALIZATION_NVP( pClass );
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | public:
|
---|
[271] | 235 | bool isTargetObjectModule;
|
---|
[206] | 236 | BlittableType( const Type &basicType, CClass *pClass )
|
---|
| 237 | : basicType( basicType )
|
---|
| 238 | , pClass( pClass )
|
---|
[271] | 239 | , isTargetObjectModule( true )
|
---|
[206] | 240 | {
|
---|
| 241 | }
|
---|
| 242 | BlittableType()
|
---|
[271] | 243 | : isTargetObjectModule( true )
|
---|
[206] | 244 | {
|
---|
| 245 | }
|
---|
| 246 | const Type &GetBasicType() const
|
---|
| 247 | {
|
---|
| 248 | return basicType;
|
---|
| 249 | }
|
---|
| 250 | const CClass *GetClassPtr() const
|
---|
| 251 | {
|
---|
| 252 | return pClass;
|
---|
| 253 | }
|
---|
| 254 | const std::string GetCreateStaticMethodFullName() const;
|
---|
| 255 | };
|
---|
| 256 | class BlittableTypes : public std::vector<BlittableType>
|
---|
| 257 | {
|
---|
| 258 | // XMLシリアライズ用
|
---|
| 259 | private:
|
---|
| 260 | friend class boost::serialization::access;
|
---|
| 261 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 262 | {
|
---|
| 263 | trace_for_serialize( "serializing - BlittableTypes" );
|
---|
| 264 |
|
---|
| 265 | ar & boost::serialization::make_nvp("vector_BlittableType",
|
---|
| 266 | boost::serialization::base_object<std::vector<BlittableType>>(*this));
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | public:
|
---|
| 270 | bool IsExist( Type type ) const
|
---|
| 271 | {
|
---|
| 272 | const BlittableTypes &blittableTypes = *this;
|
---|
| 273 | BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
|
---|
| 274 | if( blittableType.GetBasicType().Equals( type ) ){
|
---|
| 275 | return true;
|
---|
| 276 | }
|
---|
| 277 | }
|
---|
| 278 | return false;
|
---|
| 279 | }
|
---|
| 280 | const BlittableType &Find( const Type &type ) const
|
---|
| 281 | {
|
---|
| 282 | const BlittableTypes &blittableTypes = *this;
|
---|
| 283 | BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
|
---|
| 284 | if( blittableType.GetBasicType().Equals( type ) ){
|
---|
| 285 | return blittableType;
|
---|
| 286 | }
|
---|
| 287 | }
|
---|
| 288 | Jenga::Throw( "Blittable型ではない" );
|
---|
| 289 |
|
---|
| 290 | static BlittableType dummy;
|
---|
| 291 | return dummy;
|
---|
| 292 | }
|
---|
| 293 | const CClass *GetClassPtr( const Type &type ) const
|
---|
| 294 | {
|
---|
| 295 | const BlittableTypes &blittableTypes = *this;
|
---|
| 296 | BOOST_FOREACH( const BlittableType &blittableType, blittableTypes ){
|
---|
| 297 | if( blittableType.GetBasicType().Equals( type ) ){
|
---|
| 298 | return blittableType.GetClassPtr();
|
---|
| 299 | }
|
---|
| 300 | }
|
---|
| 301 | return NULL;
|
---|
| 302 | }
|
---|
| 303 | const CClass &GetClass( const Type &type ) const
|
---|
| 304 | {
|
---|
| 305 | return *GetClassPtr( type );
|
---|
| 306 | }
|
---|
| 307 | };
|
---|