Changeset 5e3eea10 in mainline for uspace/app/sbi/src/stype.c


Ignore:
Timestamp:
2011-03-22T19:55:06Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e7ffdd3
Parents:
c3f95d8 (diff), 432f68a (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.
Message:

Merge mainline changes

File:
1 edited

Legend:

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

    rc3f95d8 r5e3eea10  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 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);
     78static void stype_switch(stype_t *stype, stree_switch_t *switch_s);
    7879static void stype_while(stype_t *stype, stree_while_t *while_s);
    7980static void stype_for(stype_t *stype, stree_for_t *for_s);
     
    889890        case st_vdecl: stype_vdecl(stype, stat->u.vdecl_s); break;
    890891        case st_if: stype_if(stype, stat->u.if_s); break;
     892        case st_switch: stype_switch(stype, stat->u.switch_s); break;
    891893        case st_while: stype_while(stype, stat->u.while_s); break;
    892894        case st_for: stype_for(stype, stat->u.for_s); break;
     
    931933        }
    932934
     935        /* Annotate with variable type */
     936        vdecl_s->titem = titem;
     937
    933938        intmap_set(&block_vr->vdecls, vdecl_s->name->sid, vdecl_s);
    934939}
     
    973978        if (if_s->else_block != NULL)
    974979                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 */
     987static 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);
    9751047}
    9761048
     
    11681240        while (ec_n != NULL) {
    11691241                ec = list_node_data(ec_n, stree_except_t *);
     1242                run_texpr(stype->program, stype->current_csi, ec->etype,
     1243                    &ec->titem);
    11701244                stype_block(stype, ec->block);
    11711245
Note: See TracChangeset for help on using the changeset viewer.