[206] | 1 | #include "stdafx.h"
|
---|
[820] | 2 | #include <jenga/include/jenga.h>
|
---|
| 3 | #include <abdev/ab_common/include/ab_common.h>
|
---|
| 4 | #include "Lexical/Type.h"
|
---|
[206] | 5 |
|
---|
| 6 | const int Type::basicTypeList[] = {
|
---|
| 7 | DEF_BYTE,
|
---|
| 8 | DEF_SBYTE,
|
---|
| 9 | DEF_WORD,
|
---|
| 10 | DEF_INTEGER,
|
---|
| 11 | DEF_DWORD,
|
---|
| 12 | DEF_LONG,
|
---|
| 13 | DEF_QWORD,
|
---|
| 14 | DEF_INT64,
|
---|
| 15 |
|
---|
| 16 | DEF_SINGLE,
|
---|
| 17 | DEF_DOUBLE,
|
---|
| 18 |
|
---|
| 19 | DEF_BOOLEAN,
|
---|
| 20 |
|
---|
| 21 | DEF_PTR_VOID,
|
---|
| 22 |
|
---|
| 23 | DEF_ANY,
|
---|
| 24 |
|
---|
| 25 | DEF_NON
|
---|
| 26 | };
|
---|
| 27 |
|
---|
[523] | 28 | const std::string Type::basicTypeNameList[] = {
|
---|
[206] | 29 | "Byte",
|
---|
| 30 | "SByte",
|
---|
| 31 | "Word",
|
---|
| 32 | "Integer",
|
---|
| 33 | "DWord",
|
---|
| 34 | "Long",
|
---|
| 35 | "QWord",
|
---|
| 36 | "Int64",
|
---|
| 37 |
|
---|
| 38 | "Single",
|
---|
| 39 | "Double",
|
---|
| 40 |
|
---|
| 41 | "Boolean",
|
---|
| 42 |
|
---|
| 43 | "VoidPtr",
|
---|
| 44 |
|
---|
| 45 | "Any",
|
---|
| 46 |
|
---|
| 47 | ""
|
---|
| 48 | };
|
---|
| 49 |
|
---|
[290] | 50 | Type::~Type()
|
---|
| 51 | {
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[523] | 54 | bool Type::StringToBasicType( const std::string &typeName, int &basicType ){
|
---|
[206] | 55 | for( int i=0; ; i++ ){
|
---|
| 56 | if( basicTypeList[i] == DEF_NON ){
|
---|
| 57 | break;
|
---|
| 58 | }
|
---|
| 59 | if( basicTypeNameList[i] == typeName ){
|
---|
| 60 | basicType = basicTypeList[i];
|
---|
| 61 | return true;
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 | return false;
|
---|
| 65 | }
|
---|
| 66 | const char *Type::BasicTypeToCharPtr( const Type &type )
|
---|
| 67 | {
|
---|
| 68 | for( int i=0; ; i++ ){
|
---|
| 69 | if( basicTypeList[i] == DEF_NON ){
|
---|
| 70 | break;
|
---|
| 71 | }
|
---|
| 72 | if( basicTypeList[i] == type.GetBasicType() ){
|
---|
| 73 | return basicTypeNameList[i].c_str();
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 | return NULL;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | int Type::GetBasicSize( int basicType )
|
---|
| 80 | {
|
---|
| 81 |
|
---|
| 82 | // 基本型
|
---|
| 83 | switch( basicType ){
|
---|
| 84 | case DEF_SBYTE:
|
---|
| 85 | case DEF_BYTE:
|
---|
| 86 | case DEF_BOOLEAN:
|
---|
| 87 | return sizeof(BYTE);
|
---|
| 88 |
|
---|
| 89 | case DEF_INTEGER:
|
---|
| 90 | case DEF_WORD:
|
---|
| 91 | return sizeof(WORD);
|
---|
| 92 |
|
---|
| 93 | case DEF_LONG:
|
---|
| 94 | case DEF_DWORD:
|
---|
| 95 | return sizeof(DWORD);
|
---|
| 96 |
|
---|
| 97 | case DEF_INT64:
|
---|
| 98 | case DEF_QWORD:
|
---|
| 99 | return sizeof(_int64);
|
---|
| 100 |
|
---|
| 101 | case DEF_DOUBLE:
|
---|
| 102 | return sizeof(double);
|
---|
| 103 | case DEF_SINGLE:
|
---|
| 104 | return sizeof(float);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | // ポインタ
|
---|
| 108 | if(IsPointer( basicType )){
|
---|
| 109 | return PTR_SIZE;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | // オブジェクト
|
---|
| 113 | if(basicType==DEF_OBJECT){
|
---|
| 114 | return PTR_SIZE;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
[556] | 117 | throw;
|
---|
[206] | 118 |
|
---|
| 119 | return 0;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
[290] | 122 | const CClass &Type::GetClass() const
|
---|
| 123 | {
|
---|
| 124 | if( !HasMember() )
|
---|
| 125 | {
|
---|
| 126 | Jenga::Throw( "クラスまたは構造体でない型に対してGetClassを呼び出した" );
|
---|
| 127 | }
|
---|
[206] | 128 |
|
---|
[290] | 129 | return *pClass;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[206] | 132 | bool Type::Equals( const Type &type ) const
|
---|
| 133 | {
|
---|
[640] | 134 | if( basicType == type.basicType )
|
---|
| 135 | {
|
---|
| 136 | if( NATURAL_TYPE( basicType ) == DEF_OBJECT || NATURAL_TYPE( basicType ) == DEF_STRUCT )
|
---|
| 137 | {
|
---|
| 138 | // ポインタが等しいかどうかを見てみる
|
---|
| 139 | if( this->pClass == type.pClass )
|
---|
| 140 | {
|
---|
| 141 | return true;
|
---|
| 142 | }
|
---|
| 143 | else if( this->pClass->IsNeedResolve() || type.pClass->IsNeedResolve() )
|
---|
| 144 | {
|
---|
| 145 | // 依存関係解決前の状態であれば、パスが等しいかどうかを見てみる
|
---|
| 146 | if( this->pClass->IsDuplication( type.pClass ) )
|
---|
| 147 | {
|
---|
[206] | 148 | return true;
|
---|
| 149 | }
|
---|
[640] | 150 | }
|
---|
[206] | 151 | }
|
---|
[640] | 152 | else
|
---|
| 153 | {
|
---|
[206] | 154 | return true;
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
| 157 | return false;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
[447] | 160 | bool Type::IsCovariant( const Type &type ) const
|
---|
| 161 | {
|
---|
| 162 | if( !this->IsObject() || !type.IsObject() )
|
---|
| 163 | {
|
---|
| 164 | // 共変性の判別はクラス型のみ
|
---|
| 165 | return false;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | return this->GetClass().IsSubClass( &type.GetClass() );
|
---|
| 169 | }
|
---|
[448] | 170 | bool Type::IsContravariant( const Type &type ) const
|
---|
| 171 | {
|
---|
| 172 | if( !this->IsObject() || !type.IsObject() )
|
---|
| 173 | {
|
---|
| 174 | // 反変性の判別はクラス型のみ
|
---|
| 175 | return false;
|
---|
| 176 | }
|
---|
[447] | 177 |
|
---|
[448] | 178 | return type.GetClass().IsSubClass( &this->GetClass() );
|
---|
| 179 | }
|
---|
| 180 |
|
---|
[206] | 181 | int Type::GetBasicSize() const
|
---|
| 182 | {
|
---|
| 183 | return GetBasicSize( basicType );
|
---|
| 184 | }
|
---|
| 185 | int Type::GetSize() const
|
---|
| 186 | {
|
---|
| 187 |
|
---|
| 188 | // 基本型
|
---|
| 189 | switch( basicType ){
|
---|
| 190 | case DEF_LONG:
|
---|
| 191 | if(index==LITERAL_NULL||index==LITERAL_M128_0||index==LITERAL_0_255){
|
---|
| 192 | return sizeof(BYTE);
|
---|
| 193 | }
|
---|
| 194 | else if(index==LITERAL_M32768_0||index==LITERAL_0_65535){
|
---|
| 195 | return sizeof(WORD);
|
---|
| 196 | }
|
---|
| 197 | return sizeof(DWORD);
|
---|
| 198 |
|
---|
| 199 | case DEF_SBYTE:
|
---|
| 200 | case DEF_BYTE:
|
---|
| 201 | case DEF_BOOLEAN:
|
---|
| 202 | return sizeof(BYTE);
|
---|
| 203 |
|
---|
| 204 | case DEF_INTEGER:
|
---|
| 205 | case DEF_WORD:
|
---|
| 206 | return sizeof(WORD);
|
---|
| 207 |
|
---|
| 208 | case DEF_DWORD:
|
---|
| 209 | return sizeof(DWORD);
|
---|
| 210 |
|
---|
| 211 | case DEF_INT64:
|
---|
| 212 | case DEF_QWORD:
|
---|
| 213 | return sizeof(_int64);
|
---|
| 214 |
|
---|
| 215 | case DEF_DOUBLE:
|
---|
| 216 | return sizeof(double);
|
---|
| 217 | case DEF_SINGLE:
|
---|
| 218 | return sizeof(float);
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | // ポインタ
|
---|
| 222 | if(IsPointer()){
|
---|
| 223 | return PTR_SIZE;
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | // 構造体
|
---|
[290] | 227 | if( IsStruct() )
|
---|
| 228 | {
|
---|
[206] | 229 | if( !pClass ){
|
---|
[556] | 230 | throw;
|
---|
[206] | 231 | }
|
---|
| 232 |
|
---|
| 233 | return pClass->GetSize();
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | // オブジェクト
|
---|
[290] | 237 | if( IsObject() )
|
---|
| 238 | {
|
---|
[206] | 239 | return PTR_SIZE;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
[556] | 242 | throw;
|
---|
[206] | 243 | }
|
---|
| 244 |
|
---|
| 245 | bool Type::IsNull() const{
|
---|
| 246 | if( basicType == DEF_NON ){
|
---|
| 247 | return true;
|
---|
| 248 | }
|
---|
| 249 | return false;
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 | bool Type::IsByte() const{
|
---|
| 253 | if( basicType == DEF_BYTE ){
|
---|
| 254 | return true;
|
---|
| 255 | }
|
---|
| 256 | return false;
|
---|
| 257 | }
|
---|
| 258 | bool Type::IsSByte() const{
|
---|
| 259 | if( basicType == DEF_SBYTE ){
|
---|
| 260 | return true;
|
---|
| 261 | }
|
---|
| 262 | return false;
|
---|
| 263 | }
|
---|
| 264 | bool Type::IsWord() const{
|
---|
| 265 | if( basicType == DEF_WORD ){
|
---|
| 266 | return true;
|
---|
| 267 | }
|
---|
| 268 | return false;
|
---|
| 269 | }
|
---|
| 270 | bool Type::IsInteger() const{
|
---|
| 271 | if( basicType == DEF_INTEGER ){
|
---|
| 272 | return true;
|
---|
| 273 | }
|
---|
| 274 | return false;
|
---|
| 275 | }
|
---|
| 276 | bool Type::IsDWord() const{
|
---|
| 277 | if( basicType == DEF_DWORD ){
|
---|
| 278 | return true;
|
---|
| 279 | }
|
---|
| 280 | return false;
|
---|
| 281 | }
|
---|
| 282 | bool Type::IsLong() const{
|
---|
| 283 | if( basicType == DEF_LONG ){
|
---|
| 284 | return true;
|
---|
| 285 | }
|
---|
| 286 | return false;
|
---|
| 287 | }
|
---|
| 288 | bool Type::IsQWord() const{
|
---|
| 289 | if( basicType == DEF_QWORD ){
|
---|
| 290 | return true;
|
---|
| 291 | }
|
---|
| 292 | return false;
|
---|
| 293 | }
|
---|
| 294 | bool Type::IsInt64() const{
|
---|
| 295 | if( basicType == DEF_INT64 ){
|
---|
| 296 | return true;
|
---|
| 297 | }
|
---|
| 298 | return false;
|
---|
| 299 | }
|
---|
| 300 | bool Type::IsSingle() const{
|
---|
| 301 | if( basicType == DEF_SINGLE ){
|
---|
| 302 | return true;
|
---|
| 303 | }
|
---|
| 304 | return false;
|
---|
| 305 | }
|
---|
| 306 | bool Type::IsDouble() const{
|
---|
| 307 | if( basicType == DEF_DOUBLE ){
|
---|
| 308 | return true;
|
---|
| 309 | }
|
---|
| 310 | return false;
|
---|
| 311 | }
|
---|
| 312 | bool Type::IsBoolean() const{
|
---|
| 313 | if( basicType == DEF_BOOLEAN ){
|
---|
| 314 | return true;
|
---|
| 315 | }
|
---|
| 316 | return false;
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 | bool Type::IsPointer( int basicType )
|
---|
| 320 | {
|
---|
[350] | 321 | if( basicType == DEF_NON )
|
---|
| 322 | {
|
---|
| 323 | return false;
|
---|
| 324 | }
|
---|
| 325 |
|
---|
[206] | 326 | if(PTR_LEVEL( basicType )|| basicType == DEF_PTR_VOID || basicType == DEF_PTR_PROC
|
---|
| 327 | || ( basicType & FLAG_PTR ) ){
|
---|
| 328 | return true;
|
---|
| 329 | }
|
---|
| 330 |
|
---|
| 331 | return false;
|
---|
| 332 | }
|
---|
| 333 | bool Type::IsPointer() const
|
---|
| 334 | {
|
---|
| 335 | return IsPointer( basicType );
|
---|
| 336 | }
|
---|
| 337 | bool Type::IsSigned() const
|
---|
| 338 | {
|
---|
| 339 | switch( basicType ){
|
---|
| 340 | case DEF_SBYTE:
|
---|
| 341 | case DEF_INTEGER:
|
---|
| 342 | case DEF_LONG:
|
---|
| 343 | case DEF_INT64:
|
---|
| 344 | case DEF_SINGLE:
|
---|
| 345 | case DEF_DOUBLE:
|
---|
| 346 | return true;
|
---|
| 347 | default:
|
---|
| 348 | break;
|
---|
| 349 | }
|
---|
| 350 | return false;
|
---|
| 351 | }
|
---|
| 352 | bool Type::IsNaturalWhole() const
|
---|
| 353 | {
|
---|
| 354 | switch( basicType ){
|
---|
| 355 | case DEF_SBYTE:
|
---|
| 356 | case DEF_BYTE:
|
---|
| 357 | case DEF_INTEGER:
|
---|
| 358 | case DEF_WORD:
|
---|
| 359 | case DEF_LONG:
|
---|
| 360 | case DEF_DWORD:
|
---|
| 361 | case DEF_INT64:
|
---|
| 362 | case DEF_QWORD:
|
---|
| 363 | return true;
|
---|
| 364 | default:
|
---|
| 365 | break;
|
---|
| 366 | }
|
---|
| 367 | return false;
|
---|
| 368 | }
|
---|
| 369 | bool Type::IsWhole() const
|
---|
| 370 | {
|
---|
| 371 | return (
|
---|
| 372 | IsNaturalWhole()
|
---|
| 373 | || IsPointer( basicType )
|
---|
| 374 | || basicType == DEF_BOOLEAN
|
---|
| 375 | );
|
---|
| 376 | }
|
---|
| 377 | bool Type::IsReal() const
|
---|
| 378 | {
|
---|
| 379 | switch( basicType ){
|
---|
| 380 | case DEF_SINGLE:
|
---|
| 381 | case DEF_DOUBLE:
|
---|
| 382 | return true;
|
---|
| 383 | default:
|
---|
| 384 | break;
|
---|
| 385 | }
|
---|
| 386 | return false;
|
---|
| 387 | }
|
---|
| 388 | bool Type::Is64() const
|
---|
| 389 | {
|
---|
| 390 | switch( basicType ){
|
---|
| 391 | case DEF_QWORD:
|
---|
| 392 | case DEF_INT64:
|
---|
| 393 | return true;
|
---|
| 394 | default:
|
---|
| 395 | break;
|
---|
| 396 | }
|
---|
| 397 | return false;
|
---|
| 398 | }
|
---|
[632] | 399 |
|
---|
| 400 | bool Type::IsValueType() const
|
---|
| 401 | {
|
---|
| 402 | return ( IsWhole() || IsReal() );
|
---|
| 403 | }
|
---|
| 404 |
|
---|
[206] | 405 | bool Type::IsProcPtr() const
|
---|
| 406 | {
|
---|
| 407 | if( basicType == DEF_PTR_PROC ){
|
---|
| 408 | return true;
|
---|
| 409 | }
|
---|
| 410 | return false;
|
---|
| 411 | }
|
---|
| 412 | bool Type::IsStruct() const
|
---|
| 413 | {
|
---|
| 414 | if( basicType == DEF_STRUCT ){
|
---|
| 415 | return true;
|
---|
| 416 | }
|
---|
| 417 | return false;
|
---|
| 418 | }
|
---|
| 419 | bool Type::IsStructPtr() const
|
---|
| 420 | {
|
---|
| 421 | if( basicType == DEF_PTR_STRUCT ){
|
---|
| 422 | return true;
|
---|
| 423 | }
|
---|
| 424 | return false;
|
---|
| 425 | }
|
---|
| 426 | bool Type::IsObject() const
|
---|
| 427 | {
|
---|
[290] | 428 | return (
|
---|
| 429 | basicType == DEF_OBJECT
|
---|
[316] | 430 | || basicType == DEF_TYPE_PARAMETER
|
---|
[290] | 431 | );
|
---|
[206] | 432 | }
|
---|
| 433 | bool Type::IsObjectPtr() const
|
---|
| 434 | {
|
---|
| 435 | if( basicType == DEF_PTR_OBJECT ){
|
---|
| 436 | return true;
|
---|
| 437 | }
|
---|
| 438 | return false;
|
---|
| 439 | }
|
---|
[290] | 440 | bool Type::IsTypeParameter() const
|
---|
| 441 | {
|
---|
[292] | 442 | return ( NATURAL_TYPE(basicType) == DEF_TYPE_PARAMETER );
|
---|
[290] | 443 | }
|
---|
[206] | 444 | bool Type::IsObjectClass() const
|
---|
| 445 | {
|
---|
| 446 | if( basicType == DEF_OBJECT ){
|
---|
| 447 | if( pClass->GetName() == "Object" ){
|
---|
| 448 | return true;
|
---|
| 449 | }
|
---|
| 450 | }
|
---|
| 451 | return false;
|
---|
| 452 | }
|
---|
| 453 | bool Type::IsStringClass() const
|
---|
| 454 | {
|
---|
| 455 | if( basicType == DEF_OBJECT ){
|
---|
| 456 | if( pClass->GetName() == "String" ){
|
---|
| 457 | return true;
|
---|
| 458 | }
|
---|
| 459 | }
|
---|
| 460 | return false;
|
---|
| 461 | }
|
---|
| 462 | bool Type::IsVoidPtr() const
|
---|
| 463 | {
|
---|
| 464 | if( basicType == DEF_PTR_VOID ){
|
---|
| 465 | return true;
|
---|
| 466 | }
|
---|
| 467 | return false;
|
---|
| 468 | }
|
---|
| 469 |
|
---|
| 470 | bool Type::IsAny() const
|
---|
| 471 | {
|
---|
| 472 | if( basicType == DEF_ANY ){
|
---|
| 473 | return true;
|
---|
| 474 | }
|
---|
| 475 | return false;
|
---|
| 476 | }
|
---|
| 477 |
|
---|
[332] | 478 | bool Type::IsDelegate() const
|
---|
| 479 | {
|
---|
| 480 | return ( IsObject() && GetClass().IsDelegate() );
|
---|
| 481 | }
|
---|
[350] | 482 | bool Type::IsInterface() const
|
---|
| 483 | {
|
---|
| 484 | return ( IsObject() && GetClass().IsInterface() );
|
---|
| 485 | }
|
---|
[370] | 486 | bool Type::IsComInterface() const
|
---|
| 487 | {
|
---|
| 488 | return ( IsObject() && GetClass().IsComInterface() );
|
---|
| 489 | }
|
---|
[332] | 490 |
|
---|
[350] | 491 |
|
---|
[206] | 492 | bool Type::HasMember() const
|
---|
| 493 | {
|
---|
| 494 | if( NATURAL_TYPE( basicType ) == DEF_OBJECT
|
---|
[290] | 495 | || NATURAL_TYPE( basicType ) == DEF_STRUCT
|
---|
| 496 | || NATURAL_TYPE( basicType ) == DEF_TYPE_PARAMETER
|
---|
| 497 | ){
|
---|
| 498 | return true;
|
---|
[206] | 499 | }
|
---|
| 500 | return false;
|
---|
| 501 | }
|
---|
| 502 |
|
---|
[301] | 503 | const Type &Type::GetActualGenericType( int index ) const
|
---|
[290] | 504 | {
|
---|
[301] | 505 | return actualGenericTypes[index].GetType();
|
---|
[290] | 506 | }
|
---|
| 507 | bool Type::HasActualGenericType() const
|
---|
| 508 | {
|
---|
| 509 | return ( actualGenericTypes.size() > 0 );
|
---|
| 510 | }
|
---|
| 511 |
|
---|
[378] | 512 | std::string Type::ToString() const
|
---|
| 513 | {
|
---|
| 514 | const char *basicTypeName = BasicTypeToCharPtr( *this );
|
---|
| 515 | if( basicTypeName )
|
---|
| 516 | {
|
---|
| 517 | return basicTypeName;
|
---|
| 518 | }
|
---|
| 519 |
|
---|
| 520 | if( IsTypeParameter() )
|
---|
| 521 | {
|
---|
| 522 | return GetFormalTypeName();
|
---|
| 523 | }
|
---|
| 524 |
|
---|
| 525 | std::string typeName = GetClass().GetFullName();
|
---|
| 526 | if( HasActualGenericType() )
|
---|
| 527 | {
|
---|
| 528 | std::string actualGenericTypesName;
|
---|
[750] | 529 | foreach( const GenericType &actualGenericType, actualGenericTypes )
|
---|
[378] | 530 | {
|
---|
| 531 | if( actualGenericTypesName.size() )
|
---|
| 532 | {
|
---|
| 533 | actualGenericTypesName += ",";
|
---|
| 534 | }
|
---|
| 535 | actualGenericTypesName += actualGenericType.GetName();
|
---|
| 536 | }
|
---|
| 537 |
|
---|
| 538 | typeName += "<" + actualGenericTypesName + ">";
|
---|
| 539 | }
|
---|
| 540 | return typeName;
|
---|
| 541 | }
|
---|
| 542 |
|
---|
[206] | 543 | int Type::GetBasicTypeFromSimpleName( const char *variable ){
|
---|
[821] | 544 | assert(variable != nullptr);
|
---|
| 545 | auto length = std::strlen(variable);
|
---|
| 546 | assert(length > 0);
|
---|
| 547 |
|
---|
[206] | 548 | int i;
|
---|
| 549 | char name[VN_SIZE];
|
---|
| 550 |
|
---|
| 551 | //構造体メンバの場合を考慮
|
---|
[821] | 552 | for(i=length;i>0;i--){
|
---|
[206] | 553 | if(variable[i]=='.'){
|
---|
| 554 | i++;
|
---|
| 555 | break;
|
---|
| 556 | }
|
---|
| 557 | }
|
---|
| 558 |
|
---|
| 559 | for(;;i++){
|
---|
| 560 | if(variable[i]=='('||variable[i]=='\0'){
|
---|
| 561 | name[i]=0;
|
---|
| 562 | break;
|
---|
| 563 | }
|
---|
| 564 | name[i]=variable[i];
|
---|
| 565 | }
|
---|
| 566 | //変数名から選択
|
---|
| 567 | i--;
|
---|
| 568 | if(name[i]=='#') return DEF_DOUBLE;
|
---|
| 569 | if(name[i]=='!') return DEF_SINGLE;
|
---|
| 570 | if(name[i]=='%') return DEF_INTEGER;
|
---|
| 571 | return DEF_DOUBLE;
|
---|
| 572 | }
|
---|
| 573 |
|
---|
[640] | 574 | bool Type::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
|
---|
[639] | 575 | {
|
---|
| 576 | if( this->HasMember() )
|
---|
| 577 | {
|
---|
| 578 | if( this->pClass->IsNeedResolve() )
|
---|
| 579 | {
|
---|
[640] | 580 | const CClass *pTempClass = resolver.meta.GetClasses().FindLike( this->pClass );
|
---|
| 581 | if( pTempClass )
|
---|
| 582 | {
|
---|
| 583 | this->pClass = pTempClass;
|
---|
| 584 | }
|
---|
| 585 | else
|
---|
| 586 | {
|
---|
| 587 | resolveErrors.Add( ResolveError( this->pClass->GetRelationalObjectModuleIndex(), this->pClass->GetFullName() ) );
|
---|
| 588 | }
|
---|
[639] | 589 | }
|
---|
| 590 |
|
---|
| 591 | BOOST_FOREACH( GenericType &actualGenericType, actualGenericTypes )
|
---|
| 592 | {
|
---|
[640] | 593 | actualGenericType.GetType().Resolve( resolver, resolveErrors );
|
---|
[639] | 594 | }
|
---|
| 595 | }
|
---|
| 596 | return true;
|
---|
| 597 | }
|
---|
| 598 |
|
---|
[632] | 599 | bool Types::IsEquals( const Types &types ) const
|
---|
| 600 | {
|
---|
| 601 | if( this->size() != types.size() )
|
---|
| 602 | {
|
---|
| 603 | // アイテム数が違う
|
---|
| 604 | return false;
|
---|
| 605 | }
|
---|
[206] | 606 |
|
---|
[632] | 607 | const Types &thisTypes = *this;
|
---|
| 608 | for( int i=0; i<static_cast<int>(this->size()); i++ )
|
---|
| 609 | {
|
---|
| 610 | if( !thisTypes[i].Equals( types[i] ) )
|
---|
| 611 | {
|
---|
| 612 | return false;
|
---|
| 613 | }
|
---|
| 614 | }
|
---|
| 615 |
|
---|
| 616 | return true;
|
---|
| 617 | }
|
---|
| 618 |
|
---|
[299] | 619 | void ResolveFormalGenericTypeParameter( Type &typeParameter, const Type &classType, const UserProc *pUserProc )
|
---|
| 620 | {
|
---|
[424] | 621 | if( !typeParameter.IsTypeParameter() )
|
---|
| 622 | {
|
---|
| 623 | // ジェネリックな型ではなかったとき
|
---|
| 624 | return;
|
---|
| 625 | }
|
---|
| 626 |
|
---|
[299] | 627 | /////////////////////////////////////////////////////////
|
---|
| 628 | // ☆★☆ ジェネリクスサポート ☆★☆
|
---|
| 629 |
|
---|
[424] | 630 | // ポインタレベルを抽出
|
---|
| 631 | int ptrLevel = PTR_LEVEL( typeParameter.GetBasicType() );
|
---|
| 632 |
|
---|
| 633 | if( pUserProc )
|
---|
[299] | 634 | {
|
---|
[424] | 635 | if( classType.IsObject() )
|
---|
[299] | 636 | {
|
---|
[424] | 637 | // 基底クラスでの自己解決
|
---|
| 638 | const CClass *pClass = &classType.GetClass();
|
---|
| 639 | while( pClass->HasSuperClass() )
|
---|
[299] | 640 | {
|
---|
[424] | 641 | if( pUserProc->GetParentClassPtr() == &pClass->GetSuperClass() )
|
---|
[299] | 642 | {
|
---|
[424] | 643 | if( pClass->GetSuperClassActualTypeParameters().size() )
|
---|
[299] | 644 | {
|
---|
[424] | 645 | // TODO: 適切な形に実装し直す(暫定的にトップの型を持ってきている)
|
---|
| 646 | typeParameter = pClass->GetSuperClassActualTypeParameters()[0];
|
---|
[299] | 647 | }
|
---|
| 648 | }
|
---|
[424] | 649 | pClass = &pClass->GetSuperClass();
|
---|
[299] | 650 | }
|
---|
| 651 | }
|
---|
[424] | 652 | }
|
---|
[299] | 653 |
|
---|
[424] | 654 | if( typeParameter.IsTypeParameter() )
|
---|
| 655 | {
|
---|
| 656 | if( classType.HasActualGenericType() )
|
---|
[299] | 657 | {
|
---|
[424] | 658 | typeParameter = classType.GetActualGenericType( typeParameter.GetFormalTypeIndex() );
|
---|
[299] | 659 | }
|
---|
[424] | 660 | else
|
---|
[299] | 661 | {
|
---|
[424] | 662 | // 制約クラス(指定されていないときはObjectクラス)にセットする
|
---|
| 663 | typeParameter.SetBasicType( DEF_OBJECT );
|
---|
[299] | 664 | }
|
---|
| 665 | }
|
---|
| 666 |
|
---|
[424] | 667 | for( int i=0; i<ptrLevel; i++ )
|
---|
| 668 | {
|
---|
| 669 | typeParameter.PtrLevelUp();
|
---|
| 670 | }
|
---|
| 671 |
|
---|
[299] | 672 | //
|
---|
| 673 | /////////////////////////////////////////////////////////
|
---|
| 674 | }
|
---|
| 675 |
|
---|
| 676 |
|
---|
[523] | 677 | const std::string BlittableType::GetCreateStaticMethodFullName() const
|
---|
[206] | 678 | {
|
---|
| 679 | return pClass->GetNamespaceScopes().ToString() + "." + pClass->GetName() + "._Create";
|
---|
| 680 | }
|
---|
[640] | 681 |
|
---|
| 682 | bool BlittableType::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
|
---|
| 683 | {
|
---|
| 684 | basicType.Resolve( resolver, resolveErrors );
|
---|
| 685 |
|
---|
| 686 | if( this->pClass->IsNeedResolve() )
|
---|
| 687 | {
|
---|
| 688 | const CClass *pTempClass = resolver.meta.GetClasses().FindLike( this->pClass );
|
---|
| 689 | if( pTempClass )
|
---|
| 690 | {
|
---|
| 691 | this->pClass = pTempClass;
|
---|
| 692 | }
|
---|
| 693 | else
|
---|
| 694 | {
|
---|
| 695 | resolveErrors.Add( ResolveError( this->pClass->GetRelationalObjectModuleIndex(), this->pClass->GetFullName() ) );
|
---|
| 696 | }
|
---|
| 697 | }
|
---|
| 698 |
|
---|
| 699 | return true;
|
---|
| 700 | }
|
---|