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


Ignore:
Timestamp:
2010-04-04T22:32:39Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0a72efc
Parents:
73060801 (diff), 23de644 (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.
Message:

Merge from lp:~jsvoboda/helenos/sysel.

File:
1 edited

Legend:

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

    r73060801 recb6ac32  
    6060static void stype_unop(stype_t *stype, stree_unop_t *unop,
    6161    tdata_item_t **rtitem);
     62static void stype_unop_tprimitive(stype_t *stype, stree_unop_t *unop,
     63    tdata_item_t *ta, tdata_item_t **rtitem);
    6264static void stype_new(stype_t *stype, stree_new_t *new,
    6365    tdata_item_t **rtitem);
     
    276278{
    277279        bool_t equal;
    278         tdata_item_t *titem;
     280        tdata_item_t *titem1, *titem2;
    279281
    280282#ifdef DEBUG_TYPE_TRACE
     
    284286        stype_expr(stype, binop->arg2);
    285287
    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);
    308304        if (equal != b_true) {
    309305                printf("Error: Binary operation arguments "
    310306                    "have different types ('");
    311                 tdata_item_print(binop->arg1->titem);
     307                tdata_item_print(titem1);
    312308                printf("' and '");
    313                 tdata_item_print(binop->arg2->titem);
     309                tdata_item_print(titem2);
    314310                printf("').\n");
    315311                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) {
    323317        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);
    326319                break;
    327320        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);
    330322                break;
    331323        default:
    332324                printf("Error: Binary operation on value which is not of a "
    333325                    "supported type (found '");
    334                 tdata_item_print(titem);
     326                tdata_item_print(titem1);
    335327                printf("').\n");
    336328                stype_note_error(stype);
    337                 *rtitem = titem;
     329                *rtitem = stype_recovery_titem(stype);
    338330                break;
    339331        }
     
    417409    tdata_item_t **rtitem)
    418410{
     411        tdata_item_t *titem;
     412
    419413#ifdef DEBUG_TYPE_TRACE
    420414        printf("Evaluate type of unary operation.\n");
     
    422416        stype_expr(stype, unop->arg);
    423417
    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. */
     441static 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;
    425468}
    426469
     
    474517                printf("Error: Using '.' operator on a function.\n");
    475518                stype_note_error(stype);
     519                *rtitem = stype_recovery_titem(stype);
     520                break;
     521        case tic_ignore:
    476522                *rtitem = stype_recovery_titem(stype);
    477523                break;
     
    613659        stype_expr(stype, call->fun);
    614660
     661        /* Check type item class */
     662
    615663        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
    617681        fun = fun_ti->u.tfun->fun;
    618682        fun_sym = fun_to_symbol(fun);
     
    734798                printf("Error: Indexing a function.\n");
    735799                stype_note_error(stype);
     800                *rtitem = stype_recovery_titem(stype);
     801                break;
     802        case tic_ignore:
    736803                *rtitem = stype_recovery_titem(stype);
    737804                break;
Note: See TracChangeset for help on using the changeset viewer.