Changeset c5cb943d in mainline for uspace/app/sbi/src/stype_expr.c
- Timestamp:
- 2010-06-09T19:01:08Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1113c9e
- Parents:
- 051bc69a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/stype_expr.c
r051bc69a rc5cb943d 97 97 static void stype_new(stype_t *stype, stree_new_t *new, 98 98 tdata_item_t **rtitem); 99 static void stype_new_object _args(stype_t *stype, stree_new_t *new_op,99 static void stype_new_object(stype_t *stype, stree_new_t *new_op, 100 100 tdata_item_t *obj_ti); 101 101 … … 194 194 tdata_ebase_t *tebase; 195 195 stree_fun_t *fun; 196 bool_t static_ctx; 196 197 197 198 #ifdef DEBUG_TYPE_TRACE … … 257 258 } 258 259 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 259 286 switch (sym->sc) { 260 287 case sc_var: … … 263 290 break; 264 291 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; 267 295 break; 268 296 case sc_csi: … … 274 302 titem->u.tobject = tobject; 275 303 276 /* This is a static CSI reference. */ 277 tobject->static_ref = b_true; 304 tobject->static_ref = sn_static; 278 305 tobject->csi = csi; 279 306 break; … … 330 357 (void) stype; 331 358 359 /* Make compiler happy. */ 360 tpc = 0; 361 332 362 switch (literal->ltc) { 333 363 case ltc_bool: tpc = tpc_bool; break; … … 375 405 titem->u.tobject = tobject; 376 406 377 tobject->static_ref = b_false;407 tobject->static_ref = sn_nonstatic; 378 408 tobject->csi = cur_csi; 379 409 list_init(&tobject->targs); … … 513 543 tdata_item_t *res_ti; 514 544 545 /* Make compiler happy. */ 546 rtpc = 0; 547 515 548 switch (binop->bc) { 516 549 case bo_equal: … … 560 593 (void) stype; 561 594 595 /* Make compiler happy. */ 596 rtpc = 0; 597 562 598 switch (binop->bc) { 563 599 case bo_equal: … … 604 640 (void) stype; 605 641 642 /* Make compiler happy. */ 643 rtpc = 0; 644 606 645 switch (binop->bc) { 607 646 case bo_equal: … … 666 705 tdata_item_t *res_ti; 667 706 707 /* Make compiler happy. */ 708 rtpc = 0; 709 668 710 switch (binop->bc) { 669 711 case bo_equal: … … 941 983 942 984 if ((*rtitem)->tic == tic_tobject) 943 stype_new_object _args(stype, new_op, *rtitem);985 stype_new_object(stype, new_op, *rtitem); 944 986 } 945 987 … … 949 991 * @param new_op @c new operation 950 992 */ 951 static void stype_new_object _args(stype_t *stype, stree_new_t *new_op,993 static void stype_new_object(stype_t *stype, stree_new_t *new_op, 952 994 tdata_item_t *obj_ti) 953 995 { … … 957 999 stree_ident_t *ctor_ident; 958 1000 tdata_fun_sig_t *tsig; 1001 tdata_tvv_t *obj_tvv; 1002 tdata_item_t *ctor_sti; 959 1003 960 1004 assert(obj_ti->tic == tic_tobject); 961 1005 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 962 1014 ctor_ident = stree_ident_new(); 963 1015 ctor_ident->sid = strtab_get_sid(CTOR_IDENT); … … 986 1038 return; 987 1039 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; 990 1047 991 1048 stype_call_args(stype, new_op->expr->cspan, &tsig->arg_ti, … … 1104 1161 tdata_item_t *mtitem; 1105 1162 tdata_tvv_t *tvv; 1163 stree_csi_t *member_csi; 1106 1164 1107 1165 #ifdef DEBUG_TYPE_TRACE … … 1131 1189 strtab_get_str(access->member_name->sid)); 1132 1190 #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; 1133 1217 1134 1218 switch (member_sym->sc) { 1135 1219 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; 1142 1230 case sc_ctor: 1143 1231 /* It is not possible to reference a constructor explicitly. */ … … 1337 1425 stree_expr_t *carg; 1338 1426 1339 int cnt;1340 1341 1427 /* Type and check regular arguments. */ 1342 1428 fargt_n = list_first(farg_tis); 1343 1429 arg_n = list_first(args); 1344 1430 1345 cnt = 0;1346 1431 while (fargt_n != NULL && arg_n != NULL) { 1347 1432 farg_ti = list_node_data(fargt_n, tdata_item_t *); … … 1656 1741 { 1657 1742 tdata_item_t *titem; 1743 tdata_item_t *pred_ti; 1658 1744 1659 1745 #ifdef DEBUG_TYPE_TRACE … … 1664 1750 run_texpr(stype->program, stype->current_csi, as_op->dtype, &titem); 1665 1751 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; 1675 1769 } 1676 1770 … … 1720 1814 1721 1815 btitem->u.tobject = tobject; 1722 tobject->static_ref = b_false;1816 tobject->static_ref = sn_nonstatic; 1723 1817 tobject->csi = symbol_to_csi(csi_sym); 1724 1818 assert(tobject->csi != NULL);
Note:
See TracChangeset
for help on using the changeset viewer.