Changeset 37f527b in mainline for uspace/app/sbi/src/parse.c


Ignore:
Timestamp:
2010-03-26T21:55:23Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4204ad9
Parents:
b535aeb
Message:

Update SBI to rev. 144.

File:
1 edited

Legend:

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

    rb535aeb r37f527b  
    4343#include "stree.h"
    4444#include "strtab.h"
     45#include "symbol.h"
    4546
    4647#include "parse.h"
     
    4950 * Module members
    5051 */
    51 static stree_csi_t *parse_csi(parse_t *parse, lclass_t dclass);
     52static stree_csi_t *parse_csi(parse_t *parse, lclass_t dclass,
     53    stree_csi_t *outer_csi);
    5254static stree_csimbr_t *parse_csimbr(parse_t *parse, stree_csi_t *outer_csi);
    5355
    54 static stree_fun_t *parse_fun(parse_t *parse);
    55 static stree_var_t *parse_var(parse_t *parse);
    56 static stree_prop_t *parse_prop(parse_t *parse);
     56static stree_fun_t *parse_fun(parse_t *parse, stree_csi_t *outer_csi);
     57static stree_var_t *parse_var(parse_t *parse, stree_csi_t *outer_csi);
     58static stree_prop_t *parse_prop(parse_t *parse, stree_csi_t *outer_csi);
     59
     60static stree_symbol_attr_t *parse_symbol_attr(parse_t *parse);
    5761
    5862static stree_proc_arg_t *parse_proc_arg(parse_t *parse);
     
    6367 */
    6468static stree_block_t *parse_block(parse_t *parse);
    65 static stree_stat_t *parse_stat(parse_t *parse);
    6669
    6770static stree_vdecl_t *parse_vdecl(parse_t *parse);
     
    8992        stree_csi_t *csi;
    9093        stree_modm_t *modm;
    91         stree_symbol_t *symbol;
    9294
    9395        while (lcur_lc(parse) != lc_eof) {
     
    9698                case lc_struct:
    9799                case lc_interface:
    98                         csi = parse_csi(parse, lcur_lc(parse));
     100                        csi = parse_csi(parse, lcur_lc(parse), NULL);
    99101                        modm = stree_modm_new(mc_csi);
    100102                        modm->u.csi = csi;
    101 
    102                         symbol = stree_symbol_new(sc_csi);
    103                         symbol->u.csi = csi;
    104                         symbol->outer_csi = NULL;
    105                         csi->symbol = symbol;
    106103
    107104                        list_append(&parse->cur_mod->members, modm);
     
    117114
    118115/** Parse class, struct or interface declaration. */
    119 static stree_csi_t *parse_csi(parse_t *parse, lclass_t dclass)
     116static stree_csi_t *parse_csi(parse_t *parse, lclass_t dclass,
     117    stree_csi_t *outer_csi)
    120118{
    121119        stree_csi_t *csi;
    122120        csi_class_t cc;
    123121        stree_csimbr_t *csimbr;
     122        stree_symbol_t *symbol;
    124123
    125124        switch (dclass) {
     
    134133        csi = stree_csi_new(cc);
    135134        csi->name = parse_ident(parse);
     135
     136        symbol = stree_symbol_new(sc_csi);
     137        symbol->u.csi = csi;
     138        symbol->outer_csi = outer_csi;
     139        csi->symbol = symbol;
    136140
    137141#ifdef DEBUG_PARSE_TRACE
     
    171175        stree_prop_t *prop;
    172176
    173         stree_symbol_t *symbol;
    174 
    175177        switch (lcur_lc(parse)) {
    176178        case lc_class:
    177179        case lc_struct:
    178180        case lc_interface:
    179                 csi = parse_csi(parse, lcur_lc(parse));
     181                csi = parse_csi(parse, lcur_lc(parse), outer_csi);
    180182                csimbr = stree_csimbr_new(csimbr_csi);
    181183                csimbr->u.csi = csi;
    182 
    183                 symbol = stree_symbol_new(sc_csi);
    184                 symbol->u.csi = csi;
    185                 symbol->outer_csi = outer_csi;
    186                 csi->symbol = symbol;
    187184                break;
    188185        case lc_fun:
    189                 fun = parse_fun(parse);
     186                fun = parse_fun(parse, outer_csi);
    190187                csimbr = stree_csimbr_new(csimbr_fun);
    191188                csimbr->u.fun = fun;
    192 
    193                 symbol = stree_symbol_new(sc_fun);
    194                 symbol->u.fun = fun;
    195                 symbol->outer_csi = outer_csi;
    196                 fun->symbol = symbol;
    197                 fun->proc->outer_symbol = symbol;
    198189                break;
    199190        case lc_var:
    200                 var = parse_var(parse);
     191                var = parse_var(parse, outer_csi);
    201192                csimbr = stree_csimbr_new(csimbr_var);
    202193                csimbr->u.var = var;
    203 
    204                 symbol = stree_symbol_new(sc_var);
    205                 symbol->u.var = var;
    206                 symbol->outer_csi = outer_csi;
    207                 var->symbol = symbol;
    208194                break;
    209195        case lc_prop:
    210                 prop = parse_prop(parse);
     196                prop = parse_prop(parse, outer_csi);
    211197                csimbr = stree_csimbr_new(csimbr_prop);
    212198                csimbr->u.prop = prop;
    213 
    214                 symbol = stree_symbol_new(sc_prop);
    215                 symbol->u.prop = prop;
    216                 symbol->outer_csi = outer_csi;
    217                 prop->symbol = symbol;
    218                 if (prop->getter)
    219                         prop->getter->outer_symbol = symbol;
    220                 if (prop->setter)
    221                         prop->setter->outer_symbol = symbol;
    222199                break;
    223200        default:
     
    231208
    232209/** Parse member function. */
    233 static stree_fun_t *parse_fun(parse_t *parse)
     210static stree_fun_t *parse_fun(parse_t *parse, stree_csi_t *outer_csi)
    234211{
    235212        stree_fun_t *fun;
    236213        stree_proc_arg_t *arg;
     214        stree_symbol_t *symbol;
     215        stree_symbol_attr_t *attr;
    237216
    238217        fun = stree_fun_new();
     218        symbol = stree_symbol_new(sc_fun);
     219
     220        symbol->u.fun = fun;
     221        symbol->outer_csi = outer_csi;
     222        fun->symbol = symbol;
    239223
    240224        lmatch(parse, lc_fun);
     
    277261        }
    278262
    279         lmatch(parse, lc_is);
     263        list_init(&symbol->attr);
     264
     265        /* Parse attributes. */
     266        while (lcur_lc(parse) == lc_comma) {
     267                lskip(parse);
     268                attr = parse_symbol_attr(parse);
     269                list_append(&symbol->attr, attr);
     270        }
     271
    280272        fun->proc = stree_proc_new();
    281         fun->proc->body = parse_block(parse);
    282         lmatch(parse, lc_end);
     273        fun->proc->outer_symbol = symbol;
     274
     275        if (lcur_lc(parse) == lc_scolon) {
     276                lskip(parse);
     277
     278                /* This function has no body. */
     279                if (!stree_symbol_has_attr(symbol, sac_builtin)) {
     280                        printf("Error: Function '");
     281                        symbol_print_fqn(symbol);
     282                        printf("' has no body.\n");
     283                        exit(1);
     284                }
     285                fun->proc->body = NULL;
     286        } else {
     287                lmatch(parse, lc_is);
     288                fun->proc->body = parse_block(parse);
     289                lmatch(parse, lc_end);
     290        }
    283291
    284292        return fun;
     
    286294
    287295/** Parse member variable. */
    288 static stree_var_t *parse_var(parse_t *parse)
     296static stree_var_t *parse_var(parse_t *parse, stree_csi_t *outer_csi)
    289297{
    290298        stree_var_t *var;
     299        stree_symbol_t *symbol;
    291300
    292301        var = stree_var_new();
     302        symbol = stree_symbol_new(sc_var);
     303        symbol->u.var = var;
     304        symbol->outer_csi = outer_csi;
     305        var->symbol = symbol;
    293306
    294307        lmatch(parse, lc_var);
     
    302315
    303316/** Parse member property. */
    304 static stree_prop_t *parse_prop(parse_t *parse)
     317static stree_prop_t *parse_prop(parse_t *parse, stree_csi_t *outer_csi)
    305318{
    306319        stree_prop_t *prop;
     320        stree_symbol_t *symbol;
     321
    307322        stree_ident_t *ident;
    308323        stree_proc_arg_t *arg;
     
    310325        prop = stree_prop_new();
    311326        list_init(&prop->args);
     327
     328        symbol = stree_symbol_new(sc_prop);
     329        symbol->u.prop = prop;
     330        symbol->outer_csi = outer_csi;
     331        prop->symbol = symbol;
    312332
    313333        lmatch(parse, lc_prop);
     
    363383                        prop->getter = stree_proc_new();
    364384                        prop->getter->body = parse_block(parse);
     385                        prop->getter->outer_symbol = symbol;
    365386
    366387                        lmatch(parse, lc_end);
     
    380401                        prop->setter = stree_proc_new();
    381402                        prop->setter->body = parse_block(parse);
     403                        prop->setter->outer_symbol = symbol;
    382404
    383405                        lmatch(parse, lc_end);
     
    393415}
    394416
     417/** Parse symbol attribute. */
     418static stree_symbol_attr_t *parse_symbol_attr(parse_t *parse)
     419{
     420        stree_symbol_attr_t *attr;
     421
     422        if (lcur_lc(parse) != lc_builtin) {
     423                printf("Error: Unexpected attribute '");
     424                lem_print(lcur(parse));
     425                printf("'.\n");
     426                exit(1);
     427        }
     428
     429        lskip(parse);
     430
     431        attr = stree_symbol_attr_new(sac_builtin);
     432        return attr;
     433}
     434
    395435/** Parse formal function argument. */
    396436static stree_proc_arg_t *parse_proc_arg(parse_t *parse)
     
    455495
    456496/** Parse statement. */
    457 static stree_stat_t *parse_stat(parse_t *parse)
     497stree_stat_t *parse_stat(parse_t *parse)
    458498{
    459499        stree_stat_t *stat;
     
    719759lem_t *lcur(parse_t *parse)
    720760{
    721         return &parse->lex->current;
     761        return lex_get_current(parse->lex);
    722762}
    723763
     
    725765lclass_t lcur_lc(parse_t *parse)
    726766{
    727         return parse->lex->current.lclass;
     767        lem_t *lem;
     768
     769        lem = lcur(parse);
     770        return lem->lclass;
    728771}
    729772
Note: See TracChangeset for help on using the changeset viewer.