Changeset 94d484a in mainline for uspace/app/sbi/src/parse.c


Ignore:
Timestamp:
2010-03-07T17:45:33Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d0febca
Parents:
fa36f29
Message:

Update SBI to rev. 90.

File:
1 edited

Legend:

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

    rfa36f29 r94d484a  
    5656
    5757static stree_fun_arg_t *parse_fun_arg(parse_t *parse);
     58static stree_arg_attr_t *parse_arg_attr(parse_t *parse);
    5859
    5960/*
     
    7273static stree_exps_t *parse_exps(parse_t *parse);
    7374
     75static stree_except_t *parse_except(parse_t *parse);
     76
    7477void parse_init(parse_t *parse, stree_program_t *prog, struct lex *lex)
    7578{
     
    8790        stree_symbol_t *symbol;
    8891
    89 /*      do {
    90                 lex_next(parse->lex);
    91                 printf("Read token: "); lem_print(&parse->lex->current);
    92                 putchar('\n');
    93         } while (parse->lex->current.lclass != lc_eof);
    94 */
    9592        while (lcur_lc(parse) != lc_eof) {
    9693                switch (lcur_lc(parse)) {
     
    245242                while (b_true) {
    246243                        arg = parse_fun_arg(parse);
    247                         list_append(&fun->args, arg);
     244                        if (stree_arg_has_attr(arg, aac_packed)) {
     245                                fun->varg = arg;
     246                                break;
     247                        } else {
     248                                list_append(&fun->args, arg);
     249                        }
    248250
    249251                        if (lcur_lc(parse) == lc_rparen)
     
    307309{
    308310        stree_fun_arg_t *arg;
     311        stree_arg_attr_t *attr;
    309312
    310313        arg = stree_fun_arg_new();
     
    313316        arg->type = parse_texpr(parse);
    314317
     318        list_init(&arg->attr);
     319
     320        /* Parse attributes. */
     321        while (lcur_lc(parse) == lc_comma) {
     322                lskip(parse);
     323                attr = parse_arg_attr(parse);
     324                list_append(&arg->attr, attr);
     325        }
     326
    315327        return arg;
     328}
     329
     330/** Parse argument attribute. */
     331static stree_arg_attr_t *parse_arg_attr(parse_t *parse)
     332{
     333        stree_arg_attr_t *attr;
     334
     335        if (lcur_lc(parse) != lc_packed) {
     336                printf("Error: Unexpected attribute '");
     337                lem_print(lcur(parse));
     338                printf("'.\n");
     339                exit(1);
     340        }
     341
     342        lskip(parse);
     343
     344        attr = stree_arg_attr_new(aac_packed);
     345        return attr;
    316346}
    317347
     
    378408                stat->u.return_s = return_s;
    379409                break;
     410        case lc_do:
    380411        case lc_with:
    381412                wef_s = parse_wef(parse);
     
    485516static stree_raise_t *parse_raise(parse_t *parse)
    486517{
     518        stree_raise_t *raise_s;
     519
     520        raise_s = stree_raise_new();
    487521        lmatch(parse, lc_raise);
    488         (void) parse_expr(parse);
     522        raise_s->expr = parse_expr(parse);
    489523        lmatch(parse, lc_scolon);
    490524
    491         return stree_raise_new();
     525        return raise_s;
    492526}
    493527
     
    510544{
    511545        stree_wef_t *wef_s;
    512         stree_block_t *block;
     546        stree_except_t *except_c;
    513547
    514548        wef_s = stree_wef_new();
    515         list_init(&wef_s->except_blocks);
    516 
    517         lmatch(parse, lc_with);
    518         lmatch(parse, lc_ident);
    519         lmatch(parse, lc_colon);
    520         (void) parse_texpr(parse);
    521         lmatch(parse, lc_assign);
    522         (void) parse_expr(parse);
    523         lmatch(parse, lc_do);
    524         wef_s->with_block = parse_block(parse);
    525 
    526         while (lcur_lc(parse) == lc_except) {
    527                 lmatch(parse, lc_except);
     549        list_init(&wef_s->except_clauses);
     550
     551        if (lcur_lc(parse) == lc_with) {
     552                lmatch(parse, lc_with);
    528553                lmatch(parse, lc_ident);
    529554                lmatch(parse, lc_colon);
    530555                (void) parse_texpr(parse);
     556                lmatch(parse, lc_assign);
     557                (void) parse_expr(parse);
     558        }
     559
     560        lmatch(parse, lc_do);
     561        wef_s->with_block = parse_block(parse);
     562
     563        while (lcur_lc(parse) == lc_except) {
     564                except_c = parse_except(parse);
     565                list_append(&wef_s->except_clauses, except_c);
     566        }
     567
     568        if (lcur_lc(parse) == lc_finally) {
     569                lmatch(parse, lc_finally);
    531570                lmatch(parse, lc_do);
    532 
    533                 block = parse_block(parse);
    534                 list_append(&wef_s->except_blocks, block);
    535         }
    536 
    537         lmatch(parse, lc_finally);
    538         lmatch(parse, lc_do);
    539         wef_s->finally_block = parse_block(parse);
     571                wef_s->finally_block = parse_block(parse);
     572        } else {
     573                wef_s->finally_block = NULL;
     574        }
     575
    540576        lmatch(parse, lc_end);
    541577
     
    556592
    557593        return exps;
     594}
     595
     596/* Parse @c except clause. */
     597static stree_except_t *parse_except(parse_t *parse)
     598{
     599        stree_except_t *except_c;
     600
     601        except_c = stree_except_new();
     602
     603        lmatch(parse, lc_except);
     604        except_c->evar = parse_ident(parse);
     605        lmatch(parse, lc_colon);
     606        except_c->etype = parse_texpr(parse);
     607        lmatch(parse, lc_do);
     608
     609        except_c->block = parse_block(parse);
     610
     611        return except_c;
    558612}
    559613
Note: See TracChangeset for help on using the changeset viewer.