Changeset 1ef0fc3 in mainline for uspace/app/sbi/src/stype_expr.c
- Timestamp:
- 2010-04-10T11:19:18Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d7e45c8
- Parents:
- 2721a75 (diff), 074444f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/stype_expr.c
r2721a75 r1ef0fc3 53 53 static void stype_binop(stype_t *stype, stree_binop_t *binop, 54 54 tdata_item_t **rtitem); 55 55 56 static void stype_binop_tprimitive(stype_t *stype, stree_binop_t *binop, 56 57 tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem); 58 static void stype_binop_bool(stype_t *stype, stree_binop_t *binop, 59 tdata_item_t **rtitem); 60 static void stype_binop_char(stype_t *stype, stree_binop_t *binop, 61 tdata_item_t **rtitem); 62 static void stype_binop_int(stype_t *stype, stree_binop_t *binop, 63 tdata_item_t **rtitem); 64 static void stype_binop_nil(stype_t *stype, stree_binop_t *binop, 65 tdata_item_t **rtitem); 66 static void stype_binop_string(stype_t *stype, stree_binop_t *binop, 67 tdata_item_t **rtitem); 68 static void stype_binop_resource(stype_t *stype, stree_binop_t *binop, 69 tdata_item_t **rtitem); 70 57 71 static void stype_binop_tobject(stype_t *stype, stree_binop_t *binop, 58 72 tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem); … … 73 87 static void stype_access_tarray(stype_t *stype, stree_access_t *access, 74 88 tdata_item_t *arg_ti, tdata_item_t **rtitem); 75 static void stype_access_tgeneric(stype_t *stype, stree_access_t *access,76 tdata_item_t *arg_ti, tdata_item_t **rtitem);77 89 78 90 static void stype_call(stype_t *stype, stree_call_t *call, … … 86 98 tdata_item_t *base_ti, tdata_item_t **rtitem); 87 99 static void stype_index_tarray(stype_t *stype, stree_index_t *index, 88 tdata_item_t *base_ti, tdata_item_t **rtitem);89 static void stype_index_tgeneric(stype_t *stype, stree_index_t *index,90 100 tdata_item_t *base_ti, tdata_item_t **rtitem); 91 101 … … 248 258 249 259 switch (literal->ltc) { 260 case ltc_bool: tpc = tpc_bool; break; 261 case ltc_char: tpc = tpc_char; break; 250 262 case ltc_int: tpc = tpc_int; break; 251 263 case ltc_ref: tpc = tpc_nil; break; … … 333 345 } 334 346 335 /** Type a binary operation arguments of primitive type. */347 /** Type a binary operation with arguments of primitive type. */ 336 348 static void stype_binop_tprimitive(stype_t *stype, stree_binop_t *binop, 337 349 tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem) 338 350 { 351 assert(ta->tic == tic_tprimitive); 352 assert(tb->tic == tic_tprimitive); 353 354 switch (ta->u.tprimitive->tpc) { 355 case tpc_bool: 356 stype_binop_bool(stype, binop, rtitem); 357 break; 358 case tpc_char: 359 stype_binop_char(stype, binop, rtitem); 360 break; 361 case tpc_int: 362 stype_binop_int(stype, binop, rtitem); 363 break; 364 case tpc_nil: 365 stype_binop_nil(stype, binop, rtitem); 366 break; 367 case tpc_string: 368 stype_binop_string(stype, binop, rtitem); 369 break; 370 case tpc_resource: 371 stype_binop_resource(stype, binop, rtitem); 372 break; 373 } 374 } 375 376 /** Type a binary operation with bool arguments. */ 377 static void stype_binop_bool(stype_t *stype, stree_binop_t *binop, 378 tdata_item_t **rtitem) 379 { 339 380 tprimitive_class_t rtpc; 340 381 tdata_item_t *res_ti; 341 382 342 (void) stype; 343 344 assert(ta->tic == tic_tprimitive); 345 assert(tb->tic == tic_tprimitive); 346 347 switch (ta->u.tprimitive->tpc) { 348 case tpc_int: 349 rtpc = tpc_int; 350 break; 351 case tpc_nil: 352 printf("Unimplemented; Binary operation on nil.\n"); 353 stype_note_error(stype); 354 rtpc = tpc_nil; 355 break; 356 case tpc_string: 357 if (binop->bc != bo_plus) { 358 printf("Unimplemented: Binary operation(%d) " 359 "on strings.\n", binop->bc); 360 stype_note_error(stype); 361 } 362 rtpc = tpc_string; 363 break; 364 case tpc_resource: 365 printf("Error: Cannot apply operator to resource type.\n"); 366 stype_note_error(stype); 367 rtpc = tpc_resource; 383 switch (binop->bc) { 384 case bo_equal: 385 case bo_notequal: 386 case bo_lt: 387 case bo_gt: 388 case bo_lt_equal: 389 case bo_gt_equal: 390 /* Comparison -> boolean type */ 391 rtpc = tpc_bool; 392 break; 393 case bo_plus: 394 case bo_minus: 395 case bo_mult: 396 /* Arithmetic -> error */ 397 printf("Error: Binary operation (%d) on booleans.\n", 398 binop->bc); 399 stype_note_error(stype); 400 *rtitem = stype_recovery_titem(stype); 401 return; 368 402 } 369 403 … … 374 408 } 375 409 376 /** Type a binary operation arguments of an object type. */ 410 /** Type a binary operation with char arguments. */ 411 static void stype_binop_char(stype_t *stype, stree_binop_t *binop, 412 tdata_item_t **rtitem) 413 { 414 tprimitive_class_t rtpc; 415 tdata_item_t *res_ti; 416 417 (void) stype; 418 419 switch (binop->bc) { 420 case bo_equal: 421 case bo_notequal: 422 case bo_lt: 423 case bo_gt: 424 case bo_lt_equal: 425 case bo_gt_equal: 426 /* Comparison -> boolean type */ 427 rtpc = tpc_bool; 428 break; 429 case bo_plus: 430 case bo_minus: 431 case bo_mult: 432 /* Arithmetic -> error */ 433 printf("Error: Binary operation (%d) on characters.\n", 434 binop->bc); 435 stype_note_error(stype); 436 rtpc = tpc_char; 437 break; 438 } 439 440 res_ti = tdata_item_new(tic_tprimitive); 441 res_ti->u.tprimitive = tdata_primitive_new(rtpc); 442 443 *rtitem = res_ti; 444 } 445 446 /** Type a binary operation with int arguments. */ 447 static void stype_binop_int(stype_t *stype, stree_binop_t *binop, 448 tdata_item_t **rtitem) 449 { 450 tprimitive_class_t rtpc; 451 tdata_item_t *res_ti; 452 453 (void) stype; 454 455 switch (binop->bc) { 456 case bo_equal: 457 case bo_notequal: 458 case bo_lt: 459 case bo_gt: 460 case bo_lt_equal: 461 case bo_gt_equal: 462 /* Comparison -> boolean type */ 463 rtpc = tpc_bool; 464 break; 465 case bo_plus: 466 case bo_minus: 467 case bo_mult: 468 /* Arithmetic -> int type */ 469 rtpc = tpc_int; 470 break; 471 } 472 473 res_ti = tdata_item_new(tic_tprimitive); 474 res_ti->u.tprimitive = tdata_primitive_new(rtpc); 475 476 *rtitem = res_ti; 477 } 478 479 /** Type a binary operation with nil arguments. */ 480 static void stype_binop_nil(stype_t *stype, stree_binop_t *binop, 481 tdata_item_t **rtitem) 482 { 483 (void) binop; 484 485 printf("Unimplemented; Binary operation on nil.\n"); 486 stype_note_error(stype); 487 *rtitem = stype_recovery_titem(stype); 488 } 489 490 /** Type a binary operation with string arguments. */ 491 static void stype_binop_string(stype_t *stype, stree_binop_t *binop, 492 tdata_item_t **rtitem) 493 { 494 tprimitive_class_t rtpc; 495 tdata_item_t *res_ti; 496 497 if (binop->bc != bo_plus) { 498 printf("Unimplemented: Binary operation(%d) " 499 "on strings.\n", binop->bc); 500 stype_note_error(stype); 501 *rtitem = stype_recovery_titem(stype); 502 return; 503 } 504 505 rtpc = tpc_string; 506 507 res_ti = tdata_item_new(tic_tprimitive); 508 res_ti->u.tprimitive = tdata_primitive_new(rtpc); 509 510 *rtitem = res_ti; 511 } 512 513 /** Type a binary operation with resource arguments. */ 514 static void stype_binop_resource(stype_t *stype, stree_binop_t *binop, 515 tdata_item_t **rtitem) 516 { 517 tprimitive_class_t rtpc; 518 tdata_item_t *res_ti; 519 520 (void) binop; 521 522 printf("Error: Cannot apply operator to resource type.\n"); 523 stype_note_error(stype); 524 rtpc = tpc_resource; 525 526 res_ti = tdata_item_new(tic_tprimitive); 527 res_ti->u.tprimitive = tdata_primitive_new(rtpc); 528 529 *rtitem = res_ti; 530 } 531 532 /** Type a binary operation with arguments of an object type. */ 377 533 static void stype_binop_tobject(stype_t *stype, stree_binop_t *binop, 378 534 tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem) … … 390 546 case bo_equal: 391 547 case bo_notequal: 392 /* Comparing objects -> boolean (XXX int for now) type */ 393 res_ti = tdata_item_new(tic_tprimitive); 394 res_ti->u.tprimitive = tdata_primitive_new(tpc_int); 548 /* Comparing objects -> boolean type */ 549 res_ti = stype_boolean_titem(stype); 395 550 break; 396 551 default: 397 552 printf("Error: Binary operation (%d) on objects.\n", 398 553 binop->bc); 399 res_ti = NULL; 554 stype_note_error(stype); 555 *rtitem = stype_recovery_titem(stype); 400 556 return; 401 557 } … … 451 607 452 608 switch (ta->u.tprimitive->tpc) { 609 case tpc_bool: 610 rtpc = tpc_bool; 611 break; 453 612 case tpc_int: 454 613 rtpc = tpc_int; … … 480 639 */ 481 640 run_texpr(stype->program, stype->current_csi, new_op->texpr, rtitem); 641 642 if ((*rtitem)->tic == tic_ignore) { 643 /* An error occured when evaluating the type expression. */ 644 stype_note_error(stype); 645 } 482 646 } 483 647 … … 510 674 case tic_tarray: 511 675 stype_access_tarray(stype, access, arg_ti, rtitem); 512 break;513 case tic_tgeneric:514 stype_access_tgeneric(stype, access, arg_ti, rtitem);515 676 break; 516 677 case tic_tfun: … … 566 727 printf("' has no member named '%s'.\n", 567 728 strtab_get_str(access->member_name->sid)); 729 stype_note_error(stype); 568 730 *rtitem = stype_recovery_titem(stype); 569 731 return; … … 615 777 616 778 printf("Error: Unimplemented: Accessing array type '"); 617 tdata_item_print(arg_ti);618 printf("'.\n");619 stype_note_error(stype);620 *rtitem = stype_recovery_titem(stype);621 }622 623 /** Type a generic access operation. */624 static void stype_access_tgeneric(stype_t *stype, stree_access_t *access,625 tdata_item_t *arg_ti, tdata_item_t **rtitem)626 {627 (void) stype;628 (void) access;629 (void) rtitem;630 631 printf("Error: Unimplemented: Accessing generic type '");632 779 tdata_item_print(arg_ti); 633 780 printf("'.\n"); … … 792 939 stype_index_tarray(stype, index, base_ti, rtitem); 793 940 break; 794 case tic_tgeneric:795 stype_index_tgeneric(stype, index, base_ti, rtitem);796 break;797 941 case tic_tfun: 798 942 printf("Error: Indexing a function.\n"); … … 821 965 if (tprimitive->tpc == tpc_string) { 822 966 titem = tdata_item_new(tic_tprimitive); 823 titem->u.tprimitive = tdata_primitive_new(tpc_ int);967 titem->u.tprimitive = tdata_primitive_new(tpc_char); 824 968 *rtitem = titem; 825 969 return; … … 914 1058 } 915 1059 916 /** Type a generic indexing operation. */917 static void stype_index_tgeneric(stype_t *stype, stree_index_t *index,918 tdata_item_t *base_ti, tdata_item_t **rtitem)919 {920 (void) stype;921 (void) index;922 (void) rtitem;923 924 printf("Error: Unimplemented: Indexing generic type '");925 tdata_item_print(base_ti);926 printf("'.\n");927 stype_note_error(stype);928 *rtitem = stype_recovery_titem(stype);929 }930 931 1060 /** Type an assignment. */ 932 1061 static void stype_assign(stype_t *stype, stree_assign_t *assign,
Note:
See TracChangeset
for help on using the changeset viewer.