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