Ignore:
File:
1 edited

Legend:

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

    r051b3db8 rc5cb943d  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2010 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    7676static void stype_vdecl(stype_t *stype, stree_vdecl_t *vdecl_s);
    7777static void stype_if(stype_t *stype, stree_if_t *if_s);
    78 static void stype_switch(stype_t *stype, stree_switch_t *switch_s);
    7978static void stype_while(stype_t *stype, stree_while_t *while_s);
    8079static void stype_for(stype_t *stype, stree_for_t *for_s);
     
    890889        case st_vdecl: stype_vdecl(stype, stat->u.vdecl_s); break;
    891890        case st_if: stype_if(stype, stat->u.if_s); break;
    892         case st_switch: stype_switch(stype, stat->u.switch_s); break;
    893891        case st_while: stype_while(stype, stat->u.while_s); break;
    894892        case st_for: stype_for(stype, stat->u.for_s); break;
     
    933931        }
    934932
    935         /* Annotate with variable type */
    936         vdecl_s->titem = titem;
    937 
    938933        intmap_set(&block_vr->vdecls, vdecl_s->name->sid, vdecl_s);
    939934}
     
    978973        if (if_s->else_block != NULL)
    979974                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);
    1047975}
    1048976
     
    12401168        while (ec_n != NULL) {
    12411169                ec = list_node_data(ec_n, stree_except_t *);
    1242                 run_texpr(stype->program, stype->current_csi, ec->etype,
    1243                     &ec->titem);
    12441170                stype_block(stype, ec->block);
    12451171
Note: See TracChangeset for help on using the changeset viewer.