[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
| 3 | #include <jenga/include/smoothie/Smoothie.h>
|
---|
| 4 | #include <jenga/include/smoothie/SmoothieException.h>
|
---|
| 5 |
|
---|
| 6 | #include <Class.h>
|
---|
| 7 |
|
---|
| 8 | using namespace std;
|
---|
| 9 |
|
---|
| 10 | const int Type::basicTypeList[] = {
|
---|
| 11 | DEF_BYTE,
|
---|
| 12 | DEF_SBYTE,
|
---|
| 13 | DEF_WORD,
|
---|
| 14 | DEF_INTEGER,
|
---|
| 15 | DEF_DWORD,
|
---|
| 16 | DEF_LONG,
|
---|
| 17 | DEF_QWORD,
|
---|
| 18 | DEF_INT64,
|
---|
| 19 |
|
---|
| 20 | DEF_SINGLE,
|
---|
| 21 | DEF_DOUBLE,
|
---|
| 22 |
|
---|
| 23 | DEF_BOOLEAN,
|
---|
| 24 |
|
---|
| 25 | DEF_PTR_VOID,
|
---|
| 26 |
|
---|
| 27 | DEF_ANY,
|
---|
| 28 |
|
---|
| 29 | DEF_NON
|
---|
| 30 | };
|
---|
| 31 |
|
---|
| 32 | const string Type::basicTypeNameList[] = {
|
---|
| 33 | "Byte",
|
---|
| 34 | "SByte",
|
---|
| 35 | "Word",
|
---|
| 36 | "Integer",
|
---|
| 37 | "DWord",
|
---|
| 38 | "Long",
|
---|
| 39 | "QWord",
|
---|
| 40 | "Int64",
|
---|
| 41 |
|
---|
| 42 | "Single",
|
---|
| 43 | "Double",
|
---|
| 44 |
|
---|
| 45 | "Boolean",
|
---|
| 46 |
|
---|
| 47 | "VoidPtr",
|
---|
| 48 |
|
---|
| 49 | "Any",
|
---|
| 50 |
|
---|
| 51 | ""
|
---|
| 52 | };
|
---|
| 53 |
|
---|
[290] | 54 | Type::~Type()
|
---|
| 55 | {
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[206] | 58 | bool Type::StringToBasicType( const string &typeName, int &basicType ){
|
---|
| 59 | for( int i=0; ; i++ ){
|
---|
| 60 | if( basicTypeList[i] == DEF_NON ){
|
---|
| 61 | break;
|
---|
| 62 | }
|
---|
| 63 | if( basicTypeNameList[i] == typeName ){
|
---|
| 64 | basicType = basicTypeList[i];
|
---|
| 65 | return true;
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | return false;
|
---|
| 69 | }
|
---|
| 70 | const char *Type::BasicTypeToCharPtr( const Type &type )
|
---|
| 71 | {
|
---|
| 72 | for( int i=0; ; i++ ){
|
---|
| 73 | if( basicTypeList[i] == DEF_NON ){
|
---|
| 74 | break;
|
---|
| 75 | }
|
---|
| 76 | if( basicTypeList[i] == type.GetBasicType() ){
|
---|
| 77 | return basicTypeNameList[i].c_str();
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 | return NULL;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | int Type::GetBasicSize( int basicType )
|
---|
| 84 | {
|
---|
| 85 |
|
---|
| 86 | // 基本型
|
---|
| 87 | switch( basicType ){
|
---|
| 88 | case DEF_SBYTE:
|
---|
| 89 | case DEF_BYTE:
|
---|
| 90 | case DEF_BOOLEAN:
|
---|
| 91 | return sizeof(BYTE);
|
---|
| 92 |
|
---|
| 93 | case DEF_INTEGER:
|
---|
| 94 | case DEF_WORD:
|
---|
| 95 | return sizeof(WORD);
|
---|
| 96 |
|
---|
| 97 | case DEF_LONG:
|
---|
| 98 | case DEF_DWORD:
|
---|
| 99 | return sizeof(DWORD);
|
---|
| 100 |
|
---|
| 101 | case DEF_INT64:
|
---|
| 102 | case DEF_QWORD:
|
---|
| 103 | return sizeof(_int64);
|
---|
| 104 |
|
---|
| 105 | case DEF_DOUBLE:
|
---|
| 106 | return sizeof(double);
|
---|
| 107 | case DEF_SINGLE:
|
---|
| 108 | return sizeof(float);
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | // ポインタ
|
---|
| 112 | if(IsPointer( basicType )){
|
---|
| 113 | return PTR_SIZE;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | // オブジェクト
|
---|
| 117 | if(basicType==DEF_OBJECT){
|
---|
| 118 | return PTR_SIZE;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | SmoothieException::Throw();
|
---|
| 122 |
|
---|
| 123 | return 0;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[290] | 126 | const CClass &Type::GetClass() const
|
---|
| 127 | {
|
---|
| 128 | if( !HasMember() )
|
---|
| 129 | {
|
---|
| 130 | Jenga::Throw( "クラスまたは構造体でない型に対してGetClassを呼び出した" );
|
---|
| 131 | }
|
---|
[206] | 132 |
|
---|
[290] | 133 | return *pClass;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
[206] | 136 | bool Type::Equals( const Type &type ) const
|
---|
| 137 | {
|
---|
| 138 | if( basicType == type.basicType ){
|
---|
| 139 | if( NATURAL_TYPE( basicType ) == DEF_OBJECT
|
---|
| 140 | || NATURAL_TYPE( basicType ) == DEF_STRUCT ){
|
---|
| 141 |
|
---|
| 142 | if( index == type.index ){
|
---|
| 143 | return true;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | }
|
---|
| 147 | else{
|
---|
| 148 | return true;
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 | return false;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | int Type::GetBasicSize() const
|
---|
| 155 | {
|
---|
| 156 | return GetBasicSize( basicType );
|
---|
| 157 | }
|
---|
| 158 | int Type::GetSize() const
|
---|
| 159 | {
|
---|
| 160 |
|
---|
| 161 | // 基本型
|
---|
| 162 | switch( basicType ){
|
---|
| 163 | case DEF_LONG:
|
---|
| 164 | if(index==LITERAL_NULL||index==LITERAL_M128_0||index==LITERAL_0_255){
|
---|
| 165 | return sizeof(BYTE);
|
---|
| 166 | }
|
---|
| 167 | else if(index==LITERAL_M32768_0||index==LITERAL_0_65535){
|
---|
| 168 | return sizeof(WORD);
|
---|
| 169 | }
|
---|
| 170 | return sizeof(DWORD);
|
---|
| 171 |
|
---|
| 172 | case DEF_SBYTE:
|
---|
| 173 | case DEF_BYTE:
|
---|
| 174 | case DEF_BOOLEAN:
|
---|
| 175 | return sizeof(BYTE);
|
---|
| 176 |
|
---|
| 177 | case DEF_INTEGER:
|
---|
| 178 | case DEF_WORD:
|
---|
| 179 | return sizeof(WORD);
|
---|
| 180 |
|
---|
| 181 | case DEF_DWORD:
|
---|
| 182 | return sizeof(DWORD);
|
---|
| 183 |
|
---|
| 184 | case DEF_INT64:
|
---|
| 185 | case DEF_QWORD:
|
---|
| 186 | return sizeof(_int64);
|
---|
| 187 |
|
---|
| 188 | case DEF_DOUBLE:
|
---|
| 189 | return sizeof(double);
|
---|
| 190 | case DEF_SINGLE:
|
---|
| 191 | return sizeof(float);
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | // ポインタ
|
---|
| 195 | if(IsPointer()){
|
---|
| 196 | return PTR_SIZE;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | // 構造体
|
---|
[290] | 200 | if( IsStruct() )
|
---|
| 201 | {
|
---|
[206] | 202 | if( !pClass ){
|
---|
| 203 | SmoothieException::Throw();
|
---|
| 204 | return 0;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | return pClass->GetSize();
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | // オブジェクト
|
---|
[290] | 211 | if( IsObject() )
|
---|
| 212 | {
|
---|
[206] | 213 | if( GetClass().IsInterface() ){
|
---|
| 214 | // vtblOffsetのサイズを含める
|
---|
| 215 | return PTR_SIZE*2;
|
---|
| 216 | }
|
---|
| 217 | return PTR_SIZE;
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | SmoothieException::Throw();
|
---|
| 221 | return 0;
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | bool Type::IsNull() const{
|
---|
| 225 | if( basicType == DEF_NON ){
|
---|
| 226 | return true;
|
---|
| 227 | }
|
---|
| 228 | return false;
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | bool Type::IsByte() const{
|
---|
| 232 | if( basicType == DEF_BYTE ){
|
---|
| 233 | return true;
|
---|
| 234 | }
|
---|
| 235 | return false;
|
---|
| 236 | }
|
---|
| 237 | bool Type::IsSByte() const{
|
---|
| 238 | if( basicType == DEF_SBYTE ){
|
---|
| 239 | return true;
|
---|
| 240 | }
|
---|
| 241 | return false;
|
---|
| 242 | }
|
---|
| 243 | bool Type::IsWord() const{
|
---|
| 244 | if( basicType == DEF_WORD ){
|
---|
| 245 | return true;
|
---|
| 246 | }
|
---|
| 247 | return false;
|
---|
| 248 | }
|
---|
| 249 | bool Type::IsInteger() const{
|
---|
| 250 | if( basicType == DEF_INTEGER ){
|
---|
| 251 | return true;
|
---|
| 252 | }
|
---|
| 253 | return false;
|
---|
| 254 | }
|
---|
| 255 | bool Type::IsDWord() const{
|
---|
| 256 | if( basicType == DEF_DWORD ){
|
---|
| 257 | return true;
|
---|
| 258 | }
|
---|
| 259 | return false;
|
---|
| 260 | }
|
---|
| 261 | bool Type::IsLong() const{
|
---|
| 262 | if( basicType == DEF_LONG ){
|
---|
| 263 | return true;
|
---|
| 264 | }
|
---|
| 265 | return false;
|
---|
| 266 | }
|
---|
| 267 | bool Type::IsQWord() const{
|
---|
| 268 | if( basicType == DEF_QWORD ){
|
---|
| 269 | return true;
|
---|
| 270 | }
|
---|
| 271 | return false;
|
---|
| 272 | }
|
---|
| 273 | bool Type::IsInt64() const{
|
---|
| 274 | if( basicType == DEF_INT64 ){
|
---|
| 275 | return true;
|
---|
| 276 | }
|
---|
| 277 | return false;
|
---|
| 278 | }
|
---|
| 279 | bool Type::IsSingle() const{
|
---|
| 280 | if( basicType == DEF_SINGLE ){
|
---|
| 281 | return true;
|
---|
| 282 | }
|
---|
| 283 | return false;
|
---|
| 284 | }
|
---|
| 285 | bool Type::IsDouble() const{
|
---|
| 286 | if( basicType == DEF_DOUBLE ){
|
---|
| 287 | return true;
|
---|
| 288 | }
|
---|
| 289 | return false;
|
---|
| 290 | }
|
---|
| 291 | bool Type::IsBoolean() const{
|
---|
| 292 | if( basicType == DEF_BOOLEAN ){
|
---|
| 293 | return true;
|
---|
| 294 | }
|
---|
| 295 | return false;
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | bool Type::IsPointer( int basicType )
|
---|
| 299 | {
|
---|
| 300 | if(PTR_LEVEL( basicType )|| basicType == DEF_PTR_VOID || basicType == DEF_PTR_PROC
|
---|
| 301 | || ( basicType & FLAG_PTR ) ){
|
---|
| 302 | return true;
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | return false;
|
---|
| 306 | }
|
---|
| 307 | bool Type::IsPointer() const
|
---|
| 308 | {
|
---|
| 309 | return IsPointer( basicType );
|
---|
| 310 | }
|
---|
| 311 | bool Type::IsSigned() const
|
---|
| 312 | {
|
---|
| 313 | switch( basicType ){
|
---|
| 314 | case DEF_SBYTE:
|
---|
| 315 | case DEF_INTEGER:
|
---|
| 316 | case DEF_LONG:
|
---|
| 317 | case DEF_INT64:
|
---|
| 318 | case DEF_SINGLE:
|
---|
| 319 | case DEF_DOUBLE:
|
---|
| 320 | return true;
|
---|
| 321 | default:
|
---|
| 322 | break;
|
---|
| 323 | }
|
---|
| 324 | return false;
|
---|
| 325 | }
|
---|
| 326 | bool Type::IsNaturalWhole() const
|
---|
| 327 | {
|
---|
| 328 | switch( basicType ){
|
---|
| 329 | case DEF_SBYTE:
|
---|
| 330 | case DEF_BYTE:
|
---|
| 331 | case DEF_INTEGER:
|
---|
| 332 | case DEF_WORD:
|
---|
| 333 | case DEF_LONG:
|
---|
| 334 | case DEF_DWORD:
|
---|
| 335 | case DEF_INT64:
|
---|
| 336 | case DEF_QWORD:
|
---|
| 337 | return true;
|
---|
| 338 | default:
|
---|
| 339 | break;
|
---|
| 340 | }
|
---|
| 341 | return false;
|
---|
| 342 | }
|
---|
| 343 | bool Type::IsWhole() const
|
---|
| 344 | {
|
---|
| 345 | return (
|
---|
| 346 | IsNaturalWhole()
|
---|
| 347 | || IsPointer( basicType )
|
---|
| 348 | || basicType == DEF_BOOLEAN
|
---|
| 349 | );
|
---|
| 350 | }
|
---|
| 351 | bool Type::IsReal() const
|
---|
| 352 | {
|
---|
| 353 | switch( basicType ){
|
---|
| 354 | case DEF_SINGLE:
|
---|
| 355 | case DEF_DOUBLE:
|
---|
| 356 | return true;
|
---|
| 357 | default:
|
---|
| 358 | break;
|
---|
| 359 | }
|
---|
| 360 | return false;
|
---|
| 361 | }
|
---|
| 362 | bool Type::Is64() const
|
---|
| 363 | {
|
---|
| 364 | switch( basicType ){
|
---|
| 365 | case DEF_QWORD:
|
---|
| 366 | case DEF_INT64:
|
---|
| 367 | return true;
|
---|
| 368 | default:
|
---|
| 369 | break;
|
---|
| 370 | }
|
---|
| 371 | return false;
|
---|
| 372 | }
|
---|
| 373 | bool Type::IsProcPtr() const
|
---|
| 374 | {
|
---|
| 375 | if( basicType == DEF_PTR_PROC ){
|
---|
| 376 | return true;
|
---|
| 377 | }
|
---|
| 378 | return false;
|
---|
| 379 | }
|
---|
| 380 | bool Type::IsStruct() const
|
---|
| 381 | {
|
---|
| 382 | if( basicType == DEF_STRUCT ){
|
---|
| 383 | return true;
|
---|
| 384 | }
|
---|
| 385 | return false;
|
---|
| 386 | }
|
---|
| 387 | bool Type::IsStructPtr() const
|
---|
| 388 | {
|
---|
| 389 | if( basicType == DEF_PTR_STRUCT ){
|
---|
| 390 | return true;
|
---|
| 391 | }
|
---|
| 392 | return false;
|
---|
| 393 | }
|
---|
| 394 | bool Type::IsObject() const
|
---|
| 395 | {
|
---|
[290] | 396 | return (
|
---|
| 397 | basicType == DEF_OBJECT
|
---|
| 398 | || IsTypeParameter()
|
---|
| 399 | );
|
---|
[206] | 400 | }
|
---|
| 401 | bool Type::IsObjectPtr() const
|
---|
| 402 | {
|
---|
| 403 | if( basicType == DEF_PTR_OBJECT ){
|
---|
| 404 | return true;
|
---|
| 405 | }
|
---|
| 406 | return false;
|
---|
| 407 | }
|
---|
[290] | 408 | bool Type::IsTypeParameter() const
|
---|
| 409 | {
|
---|
[292] | 410 | return ( NATURAL_TYPE(basicType) == DEF_TYPE_PARAMETER );
|
---|
[290] | 411 | }
|
---|
[206] | 412 | bool Type::IsObjectClass() const
|
---|
| 413 | {
|
---|
| 414 | if( basicType == DEF_OBJECT ){
|
---|
| 415 | if( pClass->GetName() == "Object" ){
|
---|
| 416 | return true;
|
---|
| 417 | }
|
---|
| 418 | }
|
---|
| 419 | return false;
|
---|
| 420 | }
|
---|
| 421 | bool Type::IsStringClass() const
|
---|
| 422 | {
|
---|
| 423 | if( basicType == DEF_OBJECT ){
|
---|
| 424 | if( pClass->GetName() == "String" ){
|
---|
| 425 | return true;
|
---|
| 426 | }
|
---|
| 427 | }
|
---|
| 428 | return false;
|
---|
| 429 | }
|
---|
| 430 | bool Type::IsVoidPtr() const
|
---|
| 431 | {
|
---|
| 432 | if( basicType == DEF_PTR_VOID ){
|
---|
| 433 | return true;
|
---|
| 434 | }
|
---|
| 435 | return false;
|
---|
| 436 | }
|
---|
| 437 |
|
---|
| 438 | bool Type::IsAny() const
|
---|
| 439 | {
|
---|
| 440 | if( basicType == DEF_ANY ){
|
---|
| 441 | return true;
|
---|
| 442 | }
|
---|
| 443 | return false;
|
---|
| 444 | }
|
---|
| 445 |
|
---|
| 446 | bool Type::HasMember() const
|
---|
| 447 | {
|
---|
| 448 | if( NATURAL_TYPE( basicType ) == DEF_OBJECT
|
---|
[290] | 449 | || NATURAL_TYPE( basicType ) == DEF_STRUCT
|
---|
| 450 | || NATURAL_TYPE( basicType ) == DEF_TYPE_PARAMETER
|
---|
| 451 | ){
|
---|
| 452 | return true;
|
---|
[206] | 453 | }
|
---|
| 454 | return false;
|
---|
| 455 | }
|
---|
| 456 |
|
---|
[301] | 457 | const Type &Type::GetActualGenericType( int index ) const
|
---|
[290] | 458 | {
|
---|
[301] | 459 | return actualGenericTypes[index].GetType();
|
---|
[290] | 460 | }
|
---|
| 461 | bool Type::HasActualGenericType() const
|
---|
| 462 | {
|
---|
| 463 | return ( actualGenericTypes.size() > 0 );
|
---|
| 464 | }
|
---|
| 465 |
|
---|
[206] | 466 | int Type::GetBasicTypeFromSimpleName( const char *variable ){
|
---|
| 467 | extern char DefIntVari[26],DefSngVari[26],DefStrVari[26],divNum,dsvNum,dStrvNum;
|
---|
| 468 | int i;
|
---|
| 469 | char name[VN_SIZE];
|
---|
| 470 |
|
---|
| 471 | //構造体メンバの場合を考慮
|
---|
| 472 | for(i=lstrlen(variable);i>0;i--){
|
---|
| 473 | if(variable[i]=='.'){
|
---|
| 474 | i++;
|
---|
| 475 | break;
|
---|
| 476 | }
|
---|
| 477 | }
|
---|
| 478 |
|
---|
| 479 | for(;;i++){
|
---|
| 480 | if(variable[i]=='('||variable[i]=='\0'){
|
---|
| 481 | name[i]=0;
|
---|
| 482 | break;
|
---|
| 483 | }
|
---|
| 484 | name[i]=variable[i];
|
---|
| 485 | }
|
---|
| 486 | //変数名から選択
|
---|
| 487 | i--;
|
---|
| 488 | if(name[i]=='#') return DEF_DOUBLE;
|
---|
| 489 | if(name[i]=='!') return DEF_SINGLE;
|
---|
| 490 | if(name[i]=='%') return DEF_INTEGER;
|
---|
| 491 | return DEF_DOUBLE;
|
---|
| 492 | }
|
---|
| 493 |
|
---|
| 494 |
|
---|
[299] | 495 | void ResolveFormalGenericTypeParameter( Type &typeParameter, const Type &classType, const UserProc *pUserProc )
|
---|
| 496 | {
|
---|
| 497 | /////////////////////////////////////////////////////////
|
---|
| 498 | // ☆★☆ ジェネリクスサポート ☆★☆
|
---|
| 499 |
|
---|
| 500 | if( typeParameter.IsTypeParameter() )
|
---|
| 501 | {
|
---|
| 502 | // 型パラメータだったとき
|
---|
| 503 |
|
---|
| 504 | // ポインタレベルを抽出
|
---|
| 505 | int ptrLevel = PTR_LEVEL( typeParameter.GetBasicType() );
|
---|
| 506 |
|
---|
| 507 | if( pUserProc )
|
---|
| 508 | {
|
---|
| 509 | // 基底クラスでの自己解決
|
---|
| 510 | const CClass *pClass = &classType.GetClass();
|
---|
| 511 | while( pClass->HasSuperClass() )
|
---|
| 512 | {
|
---|
| 513 | if( pUserProc->GetParentClassPtr() == &pClass->GetSuperClass() )
|
---|
| 514 | {
|
---|
| 515 | if( pClass->GetSuperClassActualTypeParameters().size() )
|
---|
| 516 | {
|
---|
[301] | 517 | // TODO: 適切な形に実装し直す(暫定的にトップの型を持ってきている)
|
---|
[299] | 518 | typeParameter = pClass->GetSuperClassActualTypeParameters()[0];
|
---|
| 519 | }
|
---|
| 520 | }
|
---|
| 521 | pClass = &pClass->GetSuperClass();
|
---|
| 522 | }
|
---|
| 523 | }
|
---|
| 524 |
|
---|
| 525 | if( typeParameter.IsTypeParameter() )
|
---|
| 526 | {
|
---|
| 527 | if( classType.HasActualGenericType() )
|
---|
| 528 | {
|
---|
[301] | 529 | typeParameter = classType.GetActualGenericType( typeParameter.GetFormalTypeIndex() );
|
---|
[299] | 530 | }
|
---|
| 531 | else
|
---|
| 532 | {
|
---|
| 533 | // TODO: ベースオブジェクト(指定されていないときはObjectクラス)にセットする
|
---|
| 534 | typeParameter.SetBasicType( DEF_OBJECT );
|
---|
| 535 | }
|
---|
| 536 | }
|
---|
| 537 |
|
---|
| 538 | for( int i=0; i<ptrLevel; i++ )
|
---|
| 539 | {
|
---|
| 540 | typeParameter.PtrLevelUp();
|
---|
| 541 | }
|
---|
| 542 | }
|
---|
| 543 |
|
---|
| 544 | //
|
---|
| 545 | /////////////////////////////////////////////////////////
|
---|
| 546 | }
|
---|
| 547 |
|
---|
| 548 |
|
---|
[206] | 549 | const string BlittableType::GetCreateStaticMethodFullName() const
|
---|
| 550 | {
|
---|
| 551 | return pClass->GetNamespaceScopes().ToString() + "." + pClass->GetName() + "._Create";
|
---|
| 552 | }
|
---|