Changeset 074444f in mainline for uspace/app/sbi/src/stype_expr.c


Ignore:
Timestamp:
2010-04-10T11:15:33Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1ef0fc3, 38aaacc2
Parents:
23de644
Message:

Update SBI to rev. 184.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sbi/src/stype_expr.c

    r23de644 r074444f  
    5353static void stype_binop(stype_t *stype, stree_binop_t *binop,
    5454    tdata_item_t **rtitem);
     55
    5556static void stype_binop_tprimitive(stype_t *stype, stree_binop_t *binop,
    5657    tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem);
     58static void stype_binop_bool(stype_t *stype, stree_binop_t *binop,
     59    tdata_item_t **rtitem);
     60static void stype_binop_char(stype_t *stype, stree_binop_t *binop,
     61    tdata_item_t **rtitem);
     62static void stype_binop_int(stype_t *stype, stree_binop_t *binop,
     63    tdata_item_t **rtitem);
     64static void stype_binop_nil(stype_t *stype, stree_binop_t *binop,
     65    tdata_item_t **rtitem);
     66static void stype_binop_string(stype_t *stype, stree_binop_t *binop,
     67    tdata_item_t **rtitem);
     68static void stype_binop_resource(stype_t *stype, stree_binop_t *binop,
     69    tdata_item_t **rtitem);
     70
    5771static void stype_binop_tobject(stype_t *stype, stree_binop_t *binop,
    5872    tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem);
     
    7387static void stype_access_tarray(stype_t *stype, stree_access_t *access,
    7488    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);
    7789
    7890static void stype_call(stype_t *stype, stree_call_t *call,
     
    8698    tdata_item_t *base_ti, tdata_item_t **rtitem);
    8799static 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,
    90100    tdata_item_t *base_ti, tdata_item_t **rtitem);
    91101
     
    248258
    249259        switch (literal->ltc) {
     260        case ltc_bool: tpc = tpc_bool; break;
     261        case ltc_char: tpc = tpc_char; break;
    250262        case ltc_int: tpc = tpc_int; break;
    251263        case ltc_ref: tpc = tpc_nil; break;
     
    333345}
    334346
    335 /** Type a binary operation arguments of primitive type. */
     347/** Type a binary operation with arguments of primitive type. */
    336348static void stype_binop_tprimitive(stype_t *stype, stree_binop_t *binop,
    337349    tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem)
    338350{
     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. */
     377static void stype_binop_bool(stype_t *stype, stree_binop_t *binop,
     378    tdata_item_t **rtitem)
     379{
    339380        tprimitive_class_t rtpc;
    340381        tdata_item_t *res_ti;
    341382
    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;
    368402        }
    369403
     
    374408}
    375409
    376 /** Type a binary operation arguments of an object type. */
     410/** Type a binary operation with char arguments. */
     411static 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. */
     447static 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. */
     480static 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. */
     491static 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. */
     514static 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. */
    377533static void stype_binop_tobject(stype_t *stype, stree_binop_t *binop,
    378534    tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem)
     
    390546        case bo_equal:
    391547        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);
    395550                break;
    396551        default:
    397552                printf("Error: Binary operation (%d) on objects.\n",
    398553                    binop->bc);
    399                 res_ti = NULL;
     554                stype_note_error(stype);
     555                *rtitem = stype_recovery_titem(stype);
    400556                return;
    401557        }
     
    451607
    452608        switch (ta->u.tprimitive->tpc) {
     609        case tpc_bool:
     610                rtpc = tpc_bool;
     611                break;
    453612        case tpc_int:
    454613                rtpc = tpc_int;
     
    480639         */
    481640        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        }
    482646}
    483647
     
    510674        case tic_tarray:
    511675                stype_access_tarray(stype, access, arg_ti, rtitem);
    512                 break;
    513         case tic_tgeneric:
    514                 stype_access_tgeneric(stype, access, arg_ti, rtitem);
    515676                break;
    516677        case tic_tfun:
     
    566727                printf("' has no member named '%s'.\n",
    567728                    strtab_get_str(access->member_name->sid));
     729                stype_note_error(stype);
    568730                *rtitem = stype_recovery_titem(stype);
    569731                return;
     
    615777
    616778        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 '");
    632779        tdata_item_print(arg_ti);
    633780        printf("'.\n");
     
    792939                stype_index_tarray(stype, index, base_ti, rtitem);
    793940                break;
    794         case tic_tgeneric:
    795                 stype_index_tgeneric(stype, index, base_ti, rtitem);
    796                 break;
    797941        case tic_tfun:
    798942                printf("Error: Indexing a function.\n");
     
    821965        if (tprimitive->tpc == tpc_string) {
    822966                titem = tdata_item_new(tic_tprimitive);
    823                 titem->u.tprimitive = tdata_primitive_new(tpc_int);
     967                titem->u.tprimitive = tdata_primitive_new(tpc_char);
    824968                *rtitem = titem;
    825969                return;
     
    9141058}
    9151059
    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 
    9311060/** Type an assignment. */
    9321061static void stype_assign(stype_t *stype, stree_assign_t *assign,
Note: See TracChangeset for help on using the changeset viewer.