Changeset 23de644 in mainline for uspace/app/sbi/src/stype_expr.c
- Timestamp:
- 2010-04-04T22:31:01Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 074444f, ecb6ac32
- Parents:
- 3aae4e8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/stype_expr.c
r3aae4e8 r23de644 60 60 static void stype_unop(stype_t *stype, stree_unop_t *unop, 61 61 tdata_item_t **rtitem); 62 static void stype_unop_tprimitive(stype_t *stype, stree_unop_t *unop, 63 tdata_item_t *ta, tdata_item_t **rtitem); 62 64 static void stype_new(stype_t *stype, stree_new_t *new, 63 65 tdata_item_t **rtitem); … … 276 278 { 277 279 bool_t equal; 278 tdata_item_t *titem ;280 tdata_item_t *titem1, *titem2; 279 281 280 282 #ifdef DEBUG_TYPE_TRACE … … 284 286 stype_expr(stype, binop->arg2); 285 287 286 /* XXX This should be checked properly. */ 287 assert(binop->arg1->titem != NULL); 288 assert(binop->arg2->titem != NULL); 289 290 if (binop->arg1->titem == NULL) { 291 printf("Error First binary operand has no value.\n"); 292 stype_note_error(stype); 293 if (binop->arg2->titem != NULL) 294 *rtitem = binop->arg2->titem; 295 else 296 *rtitem = stype_recovery_titem(stype); 297 return; 298 } 299 300 if (binop->arg2->titem == NULL) { 301 printf("Error: Second binary operand has no value.\n"); 302 stype_note_error(stype); 303 *rtitem = binop->arg1->titem; 304 return; 305 } 306 307 equal = tdata_item_equal(binop->arg1->titem, binop->arg2->titem); 288 titem1 = binop->arg1->titem; 289 titem2 = binop->arg2->titem; 290 291 if (titem1 == NULL || titem2 == NULL) { 292 printf("Error: Binary operand has no value.\n"); 293 stype_note_error(stype); 294 *rtitem = stype_recovery_titem(stype); 295 return; 296 } 297 298 if (titem1->tic == tic_ignore || titem2->tic == tic_ignore) { 299 *rtitem = stype_recovery_titem(stype); 300 return; 301 } 302 303 equal = tdata_item_equal(titem1, titem2); 308 304 if (equal != b_true) { 309 305 printf("Error: Binary operation arguments " 310 306 "have different types ('"); 311 tdata_item_print( binop->arg1->titem);307 tdata_item_print(titem1); 312 308 printf("' and '"); 313 tdata_item_print( binop->arg2->titem);309 tdata_item_print(titem2); 314 310 printf("').\n"); 315 311 stype_note_error(stype); 316 *rtitem = binop->arg1->titem; 317 return; 318 } 319 320 titem = binop->arg1->titem; 321 322 switch (titem->tic) { 312 *rtitem = stype_recovery_titem(stype); 313 return; 314 } 315 316 switch (titem1->tic) { 323 317 case tic_tprimitive: 324 stype_binop_tprimitive(stype, binop, binop->arg1->titem, 325 binop->arg2->titem, rtitem); 318 stype_binop_tprimitive(stype, binop, titem1, titem2, rtitem); 326 319 break; 327 320 case tic_tobject: 328 stype_binop_tobject(stype, binop, binop->arg1->titem, 329 binop->arg2->titem, rtitem); 321 stype_binop_tobject(stype, binop, titem1, titem2, rtitem); 330 322 break; 331 323 default: 332 324 printf("Error: Binary operation on value which is not of a " 333 325 "supported type (found '"); 334 tdata_item_print(titem );326 tdata_item_print(titem1); 335 327 printf("').\n"); 336 328 stype_note_error(stype); 337 *rtitem = titem;329 *rtitem = stype_recovery_titem(stype); 338 330 break; 339 331 } … … 417 409 tdata_item_t **rtitem) 418 410 { 411 tdata_item_t *titem; 412 419 413 #ifdef DEBUG_TYPE_TRACE 420 414 printf("Evaluate type of unary operation.\n"); … … 422 416 stype_expr(stype, unop->arg); 423 417 424 *rtitem = NULL; 418 titem = unop->arg->titem; 419 420 if (titem->tic == tic_ignore) { 421 *rtitem = stype_recovery_titem(stype); 422 return; 423 } 424 425 switch (titem->tic) { 426 case tic_tprimitive: 427 stype_unop_tprimitive(stype, unop, titem, rtitem); 428 break; 429 default: 430 printf("Error: Unary operation on value which is not of a " 431 "supported type (found '"); 432 tdata_item_print(titem); 433 printf("').\n"); 434 stype_note_error(stype); 435 *rtitem = stype_recovery_titem(stype); 436 break; 437 } 438 } 439 440 /** Type a binary operation arguments of primitive type. */ 441 static void stype_unop_tprimitive(stype_t *stype, stree_unop_t *unop, 442 tdata_item_t *ta, tdata_item_t **rtitem) 443 { 444 tprimitive_class_t rtpc; 445 tdata_item_t *res_ti; 446 447 (void) stype; 448 (void) unop; 449 450 assert(ta->tic == tic_tprimitive); 451 452 switch (ta->u.tprimitive->tpc) { 453 case tpc_int: 454 rtpc = tpc_int; 455 break; 456 default: 457 printf("Error: Unary operator applied on unsupported " 458 "primitive type %d.\n", ta->u.tprimitive->tpc); 459 stype_note_error(stype); 460 *rtitem = stype_recovery_titem(stype); 461 return; 462 } 463 464 res_ti = tdata_item_new(tic_tprimitive); 465 res_ti->u.tprimitive = tdata_primitive_new(rtpc); 466 467 *rtitem = res_ti; 425 468 } 426 469 … … 474 517 printf("Error: Using '.' operator on a function.\n"); 475 518 stype_note_error(stype); 519 *rtitem = stype_recovery_titem(stype); 520 break; 521 case tic_ignore: 476 522 *rtitem = stype_recovery_titem(stype); 477 523 break; … … 613 659 stype_expr(stype, call->fun); 614 660 661 /* Check type item class */ 662 615 663 fun_ti = call->fun->titem; 616 assert(fun_ti->tic == tic_tfun); 664 switch (fun_ti->tic) { 665 case tic_tfun: 666 /* The expected case */ 667 break; 668 case tic_ignore: 669 *rtitem = stype_recovery_titem(stype); 670 return; 671 default: 672 printf("Error: Calling something which is not a function "); 673 printf("(found '"); 674 tdata_item_print(fun_ti); 675 printf("').\n"); 676 stype_note_error(stype); 677 *rtitem = stype_recovery_titem(stype); 678 return; 679 } 680 617 681 fun = fun_ti->u.tfun->fun; 618 682 fun_sym = fun_to_symbol(fun); … … 734 798 printf("Error: Indexing a function.\n"); 735 799 stype_note_error(stype); 800 *rtitem = stype_recovery_titem(stype); 801 break; 802 case tic_ignore: 736 803 *rtitem = stype_recovery_titem(stype); 737 804 break;
Note:
See TracChangeset
for help on using the changeset viewer.