Changeset d011038 in mainline for uspace/app/sbi/src/stype.c
- Timestamp:
- 2011-03-29T20:12:44Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8f17503
- Parents:
- c4fb95d3 (diff), 93ebe4e (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/stype.c
rc4fb95d3 rd011038 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 76 76 static void stype_vdecl(stype_t *stype, stree_vdecl_t *vdecl_s); 77 77 static void stype_if(stype_t *stype, stree_if_t *if_s); 78 static void stype_switch(stype_t *stype, stree_switch_t *switch_s); 78 79 static void stype_while(stype_t *stype, stree_while_t *while_s); 79 80 static void stype_for(stype_t *stype, stree_for_t *for_s); … … 889 890 case st_vdecl: stype_vdecl(stype, stat->u.vdecl_s); break; 890 891 case st_if: stype_if(stype, stat->u.if_s); break; 892 case st_switch: stype_switch(stype, stat->u.switch_s); break; 891 893 case st_while: stype_while(stype, stat->u.while_s); break; 892 894 case st_for: stype_for(stype, stat->u.for_s); break; … … 931 933 } 932 934 935 /* Annotate with variable type */ 936 vdecl_s->titem = titem; 937 933 938 intmap_set(&block_vr->vdecls, vdecl_s->name->sid, vdecl_s); 934 939 } … … 973 978 if (if_s->else_block != NULL) 974 979 stype_block(stype, if_s->else_block); 980 } 981 982 /** Type @c switch statement. 983 * 984 * @param stype Static typing object 985 * @param switch_s @c switch statement 986 */ 987 static void stype_switch(stype_t *stype, stree_switch_t *switch_s) 988 { 989 stree_expr_t *expr, *cexpr; 990 list_node_t *whenc_node; 991 stree_when_t *whenc; 992 list_node_t *expr_node; 993 tdata_item_t *titem1, *titem2; 994 995 #ifdef DEBUG_TYPE_TRACE 996 printf("Type 'switch' statement.\n"); 997 #endif 998 stype_expr(stype, switch_s->expr); 999 1000 titem1 = switch_s->expr->titem; 1001 if (titem1 == NULL) { 1002 cspan_print(switch_s->expr->cspan); 1003 printf(" Error: Switch expression has no value.\n"); 1004 stype_note_error(stype); 1005 return; 1006 } 1007 1008 /* Walk through all when clauses. */ 1009 whenc_node = list_first(&switch_s->when_clauses); 1010 1011 while (whenc_node != NULL) { 1012 /* Get when clause */ 1013 whenc = list_node_data(whenc_node, stree_when_t *); 1014 1015 /* Walk through all expressions of the when clause */ 1016 expr_node = list_first(&whenc->exprs); 1017 while (expr_node != NULL) { 1018 expr = list_node_data(expr_node, stree_expr_t *); 1019 1020 stype_expr(stype, expr); 1021 titem2 = expr->titem; 1022 if (titem2 == NULL) { 1023 cspan_print(expr->cspan); 1024 printf(" Error: When expression has no value.\n"); 1025 stype_note_error(stype); 1026 return; 1027 } 1028 1029 /* Convert expression to same type as switch expr. */ 1030 cexpr = stype_convert(stype, expr, titem1); 1031 1032 /* Patch code with augmented expression. */ 1033 list_node_setdata(expr_node, cexpr); 1034 1035 expr_node = list_next(&whenc->exprs, expr_node); 1036 } 1037 1038 /* Type the @c when block */ 1039 stype_block(stype, whenc->block); 1040 1041 whenc_node = list_next(&switch_s->when_clauses, whenc_node); 1042 } 1043 1044 /* Type the @c else block */ 1045 if (switch_s->else_block != NULL) 1046 stype_block(stype, switch_s->else_block); 975 1047 } 976 1048 … … 1168 1240 while (ec_n != NULL) { 1169 1241 ec = list_node_data(ec_n, stree_except_t *); 1242 run_texpr(stype->program, stype->current_csi, ec->etype, 1243 &ec->titem); 1170 1244 stype_block(stype, ec->block); 1171 1245
Note:
See TracChangeset
for help on using the changeset viewer.