Changeset 38aaacc2 in mainline for uspace/app/sbi/src/parse.c


Ignore:
Timestamp:
2010-04-23T21:41:10Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f4f866c
Parents:
074444f
Message:

Update SBI to rev. 207.

File:
1 edited

Legend:

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

    r074444f r38aaacc2  
    5454static stree_csimbr_t *parse_csimbr(parse_t *parse, stree_csi_t *outer_csi);
    5555
     56static stree_deleg_t *parse_deleg(parse_t *parse, stree_csi_t *outer_csi);
    5657static stree_fun_t *parse_fun(parse_t *parse, stree_csi_t *outer_csi);
    5758static stree_var_t *parse_var(parse_t *parse, stree_csi_t *outer_csi);
     
    6263static stree_proc_arg_t *parse_proc_arg(parse_t *parse);
    6364static stree_arg_attr_t *parse_arg_attr(parse_t *parse);
     65static stree_fun_sig_t *parse_fun_sig(parse_t *parse);
     66
    6467
    6568/*
     
    157160        stree_symbol_t *symbol;
    158161        stree_ident_t *targ_name;
     162        stree_targ_t *targ;
    159163
    160164        switch (dclass) {
     
    170174        csi->name = parse_ident(parse);
    171175
    172         list_init(&csi->targ_names);
     176        list_init(&csi->targ);
    173177
    174178        while (lcur_lc(parse) == lc_slash) {
    175179                lskip(parse);
    176180                targ_name = parse_ident(parse);
    177                 list_append(&csi->targ_names, targ_name);
     181
     182                targ = stree_targ_new();
     183                targ->name = targ_name;
     184
     185                list_append(&csi->targ, targ);
    178186        }
    179187
     
    201209        while (lcur_lc(parse) != lc_end && !parse_is_error(parse)) {
    202210                csimbr = parse_csimbr(parse, csi);
     211                if (csimbr == NULL)
     212                        break;
     213
    203214                list_append(&csi->members, csimbr);
    204215        }
     
    213224 * @param parse         Parser object.
    214225 * @param outer_csi     CSI containing this declaration or @c NULL if global.
    215  * @return              New syntax tree node.
     226 * @return              New syntax tree node. In case of parse error,
     227 *                      @c NULL may (but need not) be returned.
    216228 */
    217229static stree_csimbr_t *parse_csimbr(parse_t *parse, stree_csi_t *outer_csi)
     
    220232
    221233        stree_csi_t *csi;
     234        stree_deleg_t *deleg;
    222235        stree_fun_t *fun;
    223236        stree_var_t *var;
     
    232245                csimbr->u.csi = csi;
    233246                break;
     247        case lc_deleg:
     248                deleg = parse_deleg(parse, outer_csi);
     249                csimbr = stree_csimbr_new(csimbr_deleg);
     250                csimbr->u.deleg = deleg;
     251                break;
    234252        case lc_fun:
    235253                fun = parse_fun(parse, outer_csi);
     
    250268                lunexpected_error(parse);
    251269                lex_next(parse->lex);
     270                csimbr = NULL;
     271                break;
    252272        }
    253273
     
    255275}
    256276
     277/** Parse delegate.
     278 *
     279 * @param parse         Parser object.
     280 * @param outer_csi     CSI containing this declaration or @c NULL if global.
     281 * @return              New syntax tree node.
     282 */
     283static stree_deleg_t *parse_deleg(parse_t *parse, stree_csi_t *outer_csi)
     284{
     285        stree_deleg_t *deleg;
     286        stree_symbol_t *symbol;
     287        stree_symbol_attr_t *attr;
     288
     289        deleg = stree_deleg_new();
     290        symbol = stree_symbol_new(sc_deleg);
     291
     292        symbol->u.deleg = deleg;
     293        symbol->outer_csi = outer_csi;
     294        deleg->symbol = symbol;
     295
     296        lmatch(parse, lc_deleg);
     297        deleg->name = parse_ident(parse);
     298
     299#ifdef DEBUG_PARSE_TRACE
     300        printf("Parsing delegate '%s'.\n", strtab_get_str(deleg->name->sid));
     301#endif
     302
     303        deleg->sig = parse_fun_sig(parse);
     304
     305        list_init(&symbol->attr);
     306
     307        /* Parse attributes. */
     308        while (lcur_lc(parse) == lc_comma && !parse_is_error(parse)) {
     309                lskip(parse);
     310                attr = parse_symbol_attr(parse);
     311                list_append(&symbol->attr, attr);
     312        }
     313
     314        lmatch(parse, lc_scolon);
     315
     316        return deleg;
     317}
    257318
    258319/** Parse member function.
     
    265326{
    266327        stree_fun_t *fun;
    267         stree_proc_arg_t *arg;
    268328        stree_symbol_t *symbol;
    269329        stree_symbol_attr_t *attr;
     
    278338        lmatch(parse, lc_fun);
    279339        fun->name = parse_ident(parse);
    280         lmatch(parse, lc_lparen);
    281340
    282341#ifdef DEBUG_PARSE_TRACE
    283342        printf("Parsing function '%s'.\n", strtab_get_str(fun->name->sid));
    284343#endif
    285 
    286         list_init(&fun->args);
    287 
    288         if (lcur_lc(parse) != lc_rparen) {
    289 
    290                 /* Parse formal parameters. */
    291                 while (!parse_is_error(parse)) {
    292                         arg = parse_proc_arg(parse);
    293 
    294                         if (stree_arg_has_attr(arg, aac_packed)) {
    295                                 fun->varg = arg;
    296                                 break;
    297                         } else {
    298                                 list_append(&fun->args, arg);
    299                         }
    300 
    301                         if (lcur_lc(parse) == lc_rparen)
    302                                 break;
    303 
    304                         lmatch(parse, lc_scolon);
    305                 }
    306         }
    307 
    308         lmatch(parse, lc_rparen);
    309 
    310         if (lcur_lc(parse) == lc_colon) {
    311                 lskip(parse);
    312                 fun->rtype = parse_texpr(parse);
    313         } else {
    314                 fun->rtype = NULL;
    315         }
     344        fun->sig = parse_fun_sig(parse);
    316345
    317346        list_init(&symbol->attr);
     
    522551        arg->type = parse_texpr(parse);
    523552
    524         list_init(&arg->attr);
     553#ifdef DEBUG_PARSE_TRACE
     554        printf("Parse procedure argument.\n");
     555#endif
     556        list_init(&arg->attr);
    525557
    526558        /* Parse attributes. */
     
    531563        }
    532564
    533 #ifdef DEBUG_PARSE_TRACE
    534         printf("Parsed arg attr, type=%p.\n", arg->type);
    535 #endif
    536565        return arg;
    537566}
     
    557586        attr = stree_arg_attr_new(aac_packed);
    558587        return attr;
     588}
     589
     590/** Parse function signature.
     591 *
     592 * @param parse         Parser object.
     593 * @return              New syntax tree node.
     594 */
     595static stree_fun_sig_t *parse_fun_sig(parse_t *parse)
     596{
     597        stree_fun_sig_t *sig;
     598        stree_proc_arg_t *arg;
     599
     600        sig = stree_fun_sig_new();
     601
     602        lmatch(parse, lc_lparen);
     603
     604#ifdef DEBUG_PARSE_TRACE
     605        printf("Parsing function signature.\n");
     606#endif
     607
     608        list_init(&sig->args);
     609
     610        if (lcur_lc(parse) != lc_rparen) {
     611
     612                /* Parse formal parameters. */
     613                while (!parse_is_error(parse)) {
     614                        arg = parse_proc_arg(parse);
     615
     616                        if (stree_arg_has_attr(arg, aac_packed)) {
     617                                sig->varg = arg;
     618                                break;
     619                        } else {
     620                                list_append(&sig->args, arg);
     621                        }
     622
     623                        if (lcur_lc(parse) == lc_rparen)
     624                                break;
     625
     626                        lmatch(parse, lc_scolon);
     627                }
     628        }
     629
     630        lmatch(parse, lc_rparen);
     631
     632        if (lcur_lc(parse) == lc_colon) {
     633                lskip(parse);
     634                sig->rtype = parse_texpr(parse);
     635        } else {
     636                sig->rtype = NULL;
     637        }
     638
     639        return sig;
    559640}
    560641
Note: See TracChangeset for help on using the changeset viewer.