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


Ignore:
Timestamp:
2010-06-09T19:01:08Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1113c9e
Parents:
051bc69a
Message:

Update SBI to rev. 291.

File:
1 edited

Legend:

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

    r051bc69a rc5cb943d  
    9797static void stype_new(stype_t *stype, stree_new_t *new,
    9898    tdata_item_t **rtitem);
    99 static void stype_new_object_args(stype_t *stype, stree_new_t *new_op,
     99static void stype_new_object(stype_t *stype, stree_new_t *new_op,
    100100    tdata_item_t *obj_ti);
    101101
     
    194194        tdata_ebase_t *tebase;
    195195        stree_fun_t *fun;
     196        bool_t static_ctx;
    196197
    197198#ifdef DEBUG_TYPE_TRACE
     
    257258        }
    258259
     260        /* Determine if current procedure is static. */
     261        static_ctx = stree_symbol_is_static(stype->proc_vr->proc->outer_symbol);
     262
     263        /*
     264         * If the symbol is not found in current CSI, then we access it
     265         * in a static context. (Context of current object cannot be used.)
     266         */
     267        if (sym->outer_csi != stype->current_csi)
     268                static_ctx = b_true;
     269
     270        /* Check for referencing non-static symbol in static context. */
     271        if (static_ctx && !stree_symbol_is_static(sym)) {
     272                cspan_print(nameref->expr->cspan);
     273                printf(" Error: Referencing non-static symbol '");
     274                symbol_print_fqn(sym);
     275                printf("' in static context.\n");
     276                stype_note_error(stype);
     277                *rtitem = stype_recovery_titem(stype);
     278                return;
     279        }
     280
     281        /* Referencing static member in non-static context is allowed. */
     282
     283        /* Make compiler happy. */
     284        titem = NULL;
     285
    259286        switch (sym->sc) {
    260287        case sc_var:
     
    263290                break;
    264291        case sc_prop:
    265                 run_texpr(stype->program, stype->current_csi,
    266                     sym->u.prop->type, &titem);
     292                /* Type property header if it has not been typed yet. */
     293                stype_prop_header(stype, sym->u.prop);
     294                titem = sym->u.prop->titem;
    267295                break;
    268296        case sc_csi:
     
    274302                titem->u.tobject = tobject;
    275303
    276                 /* This is a static CSI reference. */
    277                 tobject->static_ref = b_true;
     304                tobject->static_ref = sn_static;
    278305                tobject->csi = csi;
    279306                break;
     
    330357        (void) stype;
    331358
     359        /* Make compiler happy. */
     360        tpc = 0;
     361
    332362        switch (literal->ltc) {
    333363        case ltc_bool: tpc = tpc_bool; break;
     
    375405        titem->u.tobject = tobject;
    376406
    377         tobject->static_ref = b_false;
     407        tobject->static_ref = sn_nonstatic;
    378408        tobject->csi = cur_csi;
    379409        list_init(&tobject->targs);
     
    513543        tdata_item_t *res_ti;
    514544
     545        /* Make compiler happy. */
     546        rtpc = 0;
     547
    515548        switch (binop->bc) {
    516549        case bo_equal:
     
    560593        (void) stype;
    561594
     595        /* Make compiler happy. */
     596        rtpc = 0;
     597
    562598        switch (binop->bc) {
    563599        case bo_equal:
     
    604640        (void) stype;
    605641
     642        /* Make compiler happy. */
     643        rtpc = 0;
     644
    606645        switch (binop->bc) {
    607646        case bo_equal:
     
    666705        tdata_item_t *res_ti;
    667706
     707        /* Make compiler happy. */
     708        rtpc = 0;
     709
    668710        switch (binop->bc) {
    669711        case bo_equal:
     
    941983
    942984        if ((*rtitem)->tic == tic_tobject)
    943                 stype_new_object_args(stype, new_op, *rtitem);
     985                stype_new_object(stype, new_op, *rtitem);
    944986}
    945987
     
    949991 * @param new_op        @c new operation
    950992 */
    951 static void stype_new_object_args(stype_t *stype, stree_new_t *new_op,
     993static void stype_new_object(stype_t *stype, stree_new_t *new_op,
    952994    tdata_item_t *obj_ti)
    953995{
     
    957999        stree_ident_t *ctor_ident;
    9581000        tdata_fun_sig_t *tsig;
     1001        tdata_tvv_t *obj_tvv;
     1002        tdata_item_t *ctor_sti;
    9591003
    9601004        assert(obj_ti->tic == tic_tobject);
    9611005        csi = obj_ti->u.tobject->csi;
     1006
     1007        if (csi->cc == csi_interface) {
     1008                cspan_print(new_op->expr->cspan);
     1009                printf(" Error: Cannot instantiate an interface.\n");
     1010                stype_note_error(stype);
     1011                return;
     1012        }
     1013
    9621014        ctor_ident = stree_ident_new();
    9631015        ctor_ident->sid = strtab_get_sid(CTOR_IDENT);
     
    9861038                return;
    9871039
    988         assert(ctor->titem->tic == tic_tfun);
    989         tsig = ctor->titem->u.tfun->tsig;
     1040        /* Substitute type arguments in constructor type. */
     1041        stype_titem_to_tvv(stype, obj_ti, &obj_tvv);
     1042        tdata_item_subst(ctor->titem, obj_tvv, &ctor_sti);
     1043        /* XXX Free obj_tvv */
     1044
     1045        assert(ctor_sti->tic == tic_tfun);
     1046        tsig = ctor_sti->u.tfun->tsig;
    9901047
    9911048        stype_call_args(stype, new_op->expr->cspan, &tsig->arg_ti,
     
    11041161        tdata_item_t *mtitem;
    11051162        tdata_tvv_t *tvv;
     1163        stree_csi_t *member_csi;
    11061164
    11071165#ifdef DEBUG_TYPE_TRACE
     
    11311189            strtab_get_str(access->member_name->sid));
    11321190#endif
     1191        /* Check for accessing non-static member in static context. */
     1192        if (tobject->static_ref == sn_static &&
     1193            !stree_symbol_is_static(member_sym)) {
     1194                cspan_print(access->member_name->cspan);
     1195                printf(" Error: Accessing non-static member '");
     1196                symbol_print_fqn(member_sym);
     1197                printf("' in static context.\n");
     1198                stype_note_error(stype);
     1199                *rtitem = stype_recovery_titem(stype);
     1200                return;
     1201        }
     1202
     1203        /* Check for accessing static member in non-static context. */
     1204        if (tobject->static_ref != sn_static &&
     1205            stree_symbol_is_static(member_sym)) {
     1206                cspan_print(access->member_name->cspan);
     1207                printf(" Error: Accessing static member '");
     1208                symbol_print_fqn(member_sym);
     1209                printf("' in non-static context.\n");
     1210                stype_note_error(stype);
     1211                *rtitem = stype_recovery_titem(stype);
     1212                return;
     1213        }
     1214
     1215        /* Make compiler happy. */
     1216        mtitem = NULL;
    11331217
    11341218        switch (member_sym->sc) {
    11351219        case sc_csi:
    1136                 cspan_print(access->member_name->cspan);
    1137                 printf(" Error: Accessing object member which is nested "
    1138                     "CSI.\n");
    1139                 stype_note_error(stype);
    1140                 *rtitem = stype_recovery_titem(stype);
    1141                 return;
     1220                member_csi = symbol_to_csi(member_sym);
     1221                assert(member_csi != NULL);
     1222
     1223                mtitem = tdata_item_new(tic_tobject);
     1224                tobject = tdata_object_new();
     1225                mtitem->u.tobject = tobject;
     1226
     1227                tobject->static_ref = sn_static;
     1228                tobject->csi = member_csi;
     1229                break;
    11421230        case sc_ctor:
    11431231                /* It is not possible to reference a constructor explicitly. */
     
    13371425        stree_expr_t *carg;
    13381426
    1339         int cnt;
    1340 
    13411427        /* Type and check regular arguments. */
    13421428        fargt_n = list_first(farg_tis);
    13431429        arg_n = list_first(args);
    13441430
    1345         cnt = 0;
    13461431        while (fargt_n != NULL && arg_n != NULL) {
    13471432                farg_ti = list_node_data(fargt_n, tdata_item_t *);
     
    16561741{
    16571742        tdata_item_t *titem;
     1743        tdata_item_t *pred_ti;
    16581744
    16591745#ifdef DEBUG_TYPE_TRACE
     
    16641750        run_texpr(stype->program, stype->current_csi, as_op->dtype, &titem);
    16651751
    1666         /* Check that target type is derived from argument type. */
    1667         if (tdata_is_ti_derived_from_ti(titem, as_op->arg->titem) != b_true) {
    1668                 cspan_print(as_op->dtype->cspan);
    1669                 printf(" Error: Target of 'as' operator '");
    1670                 tdata_item_print(titem);
    1671                 printf("' is not derived from '");
    1672                 tdata_item_print(as_op->arg->titem);
    1673                 printf("'.\n");
    1674                 stype_note_error(stype);
     1752        pred_ti = stype_tobject_find_pred(stype, titem, as_op->arg->titem);
     1753        if (pred_ti == NULL) {
     1754                /* No CSI match. */
     1755                stype_convert_failure(stype, convc_as, as_op->arg, titem);
     1756                *rtitem = titem;
     1757                return;
     1758        }
     1759
     1760        /*
     1761         * Verify that type arguments match with those specified for
     1762         * conversion destination.
     1763         */
     1764        if (stype_targs_check_equal(stype, pred_ti, as_op->arg->titem)
     1765            != EOK) {
     1766                stype_convert_failure(stype, convc_as, as_op->arg, titem);
     1767                *rtitem = titem;
     1768                return;
    16751769        }
    16761770
     
    17201814
    17211815        btitem->u.tobject = tobject;
    1722         tobject->static_ref = b_false;
     1816        tobject->static_ref = sn_nonstatic;
    17231817        tobject->csi = symbol_to_csi(csi_sym);
    17241818        assert(tobject->csi != NULL);
Note: See TracChangeset for help on using the changeset viewer.