Changeset 37f527b in mainline for uspace/app/sbi/src/run_expr.c


Ignore:
Timestamp:
2010-03-26T21:55:23Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4204ad9
Parents:
b535aeb
Message:

Update SBI to rev. 144.

File:
1 edited

Legend:

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

    rb535aeb r37f527b  
    9696    rdata_item_t *base, list_t *args, rdata_item_t **res);
    9797static void run_assign(run_t *run, stree_assign_t *assign, rdata_item_t **res);
     98static void run_as(run_t *run, stree_as_t *as_op, rdata_item_t **res);
    9899
    99100/** Evaluate expression. */
     
    134135        case ec_assign:
    135136                run_assign(run, expr->u.assign, res);
     137                break;
     138        case ec_as:
     139                run_as(run, expr->u.as_op, res);
    136140                break;
    137141        }
     
    13601364}
    13611365
    1362 
    13631366/** Execute assignment. */
    13641367static void run_assign(run_t *run, stree_assign_t *assign, rdata_item_t **res)
     
    13871390
    13881391        *res = NULL;
     1392}
     1393
     1394/** Execute @c as conversion. */
     1395static void run_as(run_t *run, stree_as_t *as_op, rdata_item_t **res)
     1396{
     1397        rdata_item_t *rarg_i;
     1398        rdata_item_t *rarg_vi;
     1399        rdata_item_t *rarg_di;
     1400        rdata_var_t *arg_vref;
     1401        tdata_item_t *dtype;
     1402        run_proc_ar_t *proc_ar;
     1403
     1404        stree_symbol_t *obj_csi_sym;
     1405        stree_csi_t *obj_csi;
     1406
     1407#ifdef DEBUG_RUN_TRACE
     1408        printf("Run @c as conversion operation.\n");
     1409#endif
     1410        run_expr(run, as_op->arg, &rarg_i);
     1411
     1412        /*
     1413         * This should always be a reference if the argument is indeed
     1414         * a class instance.
     1415         */
     1416        assert(run_item_get_vc(run, rarg_i) == vc_ref);
     1417        run_cvt_value_item(run, rarg_i, &rarg_vi);
     1418        assert(rarg_vi->ic == ic_value);
     1419
     1420        if (rarg_vi->u.value->var->u.ref_v->vref == NULL) {
     1421                /* Nil reference is always okay. */
     1422                *res = rarg_vi;
     1423                return;
     1424        }
     1425
     1426        run_dereference(run, rarg_vi, &rarg_di);
     1427
     1428        /* Now we should have a variable address. */
     1429        assert(rarg_di->ic == ic_address);
     1430        assert(rarg_di->u.address->ac == ac_var);
     1431
     1432        arg_vref = rarg_di->u.address->u.var_a->vref;
     1433
     1434        proc_ar = run_get_current_proc_ar(run);
     1435        /* XXX Memoize to avoid recomputing. */
     1436        run_texpr(run->program, proc_ar->proc->outer_symbol->outer_csi,
     1437            as_op->dtype, &dtype);
     1438
     1439        assert(arg_vref->vc == vc_object);
     1440        obj_csi_sym = arg_vref->u.object_v->class_sym;
     1441        obj_csi = symbol_to_csi(obj_csi_sym);
     1442        assert(obj_csi != NULL);
     1443
     1444        if (tdata_is_csi_derived_from_ti(obj_csi, dtype) != b_true) {
     1445                printf("Error: Run-time type conversion error. Object is "
     1446                    "of type '");
     1447                symbol_print_fqn(obj_csi_sym);
     1448                printf("' which is not derived from '");
     1449                tdata_item_print(dtype);
     1450                printf("'.\n");
     1451                exit(1);
     1452        }
     1453
     1454        *res = rarg_vi;
    13891455}
    13901456
Note: See TracChangeset for help on using the changeset viewer.