Ignore:
File:
1 edited

Legend:

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

    r051bc69a r38aaacc2  
    4242static stree_symbol_t *symbol_find_epoint_rec(stree_program_t *prog,
    4343    stree_ident_t *name, stree_csi_t *csi);
    44 static stree_symbol_t *csimbr_to_symbol(stree_csimbr_t *csimbr);
    4544static stree_ident_t *symbol_get_ident(stree_symbol_t *symbol);
    4645
     
    8988/** Lookup symbol reference in CSI.
    9089 *
    91  * XXX These functions should take just an sid, not a full identifier.
    92  * Sometimes we search for a name which has no associated cspan.
    93  *
    9490 * @param prog  Program to look in
    9591 * @param scope CSI in @a prog which is the base for references
     
    132128    stree_csi_t *scope, stree_ident_t *name)
    133129{
     130        list_node_t *node;
     131        stree_csimbr_t *csimbr;
     132        stree_symbol_t *symbol;
     133        stree_ident_t *mbr_name;
    134134        stree_symbol_t *base_csi_sym;
    135135        stree_csi_t *base_csi;
    136         stree_symbol_t *symbol;
     136
     137        (void) prog;
    137138
    138139        /* Look in new members in this class. */
    139         symbol = symbol_search_csi_no_base(prog, scope, name);
    140         if (symbol != NULL)
    141                 return symbol;
     140
     141        node = list_first(&scope->members);
     142        while (node != NULL) {
     143                csimbr = list_node_data(node, stree_csimbr_t *);
     144
     145                /* Keep compiler happy. */
     146                mbr_name = NULL;
     147
     148                switch (csimbr->cc) {
     149                case csimbr_csi: mbr_name = csimbr->u.csi->name; break;
     150                case csimbr_deleg: mbr_name = csimbr->u.deleg->name; break;
     151                case csimbr_fun: mbr_name = csimbr->u.fun->name; break;
     152                case csimbr_var: mbr_name = csimbr->u.var->name; break;
     153                case csimbr_prop: mbr_name = csimbr->u.prop->name; break;
     154                }
     155
     156                if (name->sid == mbr_name->sid) {
     157                        /* Match */
     158                        switch (csimbr->cc) {
     159                        case csimbr_csi:
     160                                symbol = csi_to_symbol(csimbr->u.csi);
     161                                break;
     162                        case csimbr_deleg:
     163                                symbol = deleg_to_symbol(csimbr->u.deleg);
     164                                break;
     165                        case csimbr_fun:
     166                                symbol = fun_to_symbol(csimbr->u.fun);
     167                                break;
     168                        case csimbr_var:
     169                                symbol = var_to_symbol(csimbr->u.var);
     170                                break;
     171                        case csimbr_prop:
     172                                symbol = prop_to_symbol(csimbr->u.prop);
     173                                break;
     174                        default:
     175                                assert(b_false);
     176                        }
     177                        return symbol;
     178                }
     179                node = list_next(&scope->members, node);
     180        }
    142181
    143182        /* Try inherited members. */
     
    155194}
    156195
    157 /** Look for symbol strictly in CSI.
    158  *
    159  * Look for symbol in definition of a CSI and its ancestors. (But not
    160  * in lexically enclosing CSI or in base CSI.)
    161  *
    162  * @param prog  Program to look in
    163  * @param scope CSI in which to look
    164  * @param name  Identifier of the symbol
    165  *
    166  * @return      Symbol or @c NULL if symbol not found.
    167  */
    168 stree_symbol_t *symbol_search_csi_no_base(stree_program_t *prog,
    169     stree_csi_t *scope, stree_ident_t *name)
    170 {
    171         list_node_t *node;
    172         stree_csimbr_t *csimbr;
    173         stree_ident_t *mbr_name;
    174 
    175         (void) prog;
    176 
    177         /* Look in new members in this class. */
    178 
    179         node = list_first(&scope->members);
    180         while (node != NULL) {
    181                 csimbr = list_node_data(node, stree_csimbr_t *);
    182                 mbr_name = stree_csimbr_get_name(csimbr);
    183 
    184                 if (name->sid == mbr_name->sid) {
    185                         /* Match */
    186                         return csimbr_to_symbol(csimbr);
    187                 }
    188 
    189                 node = list_next(&scope->members, node);
    190         }
    191         /* No match */
    192         return NULL;
    193 }
    194 
    195196/** Look for symbol in global scope.
    196197 *
     
    206207        stree_modm_t *modm;
    207208        stree_symbol_t *symbol;
    208         stree_ident_t *mbr_name;
    209209
    210210        node = list_first(&prog->module->members);
    211211        while (node != NULL) {
    212212                modm = list_node_data(node, stree_modm_t *);
    213 
    214                 switch (modm->mc) {
    215                 case mc_csi: mbr_name = modm->u.csi->name; break;
    216                 case mc_enum: mbr_name = modm->u.enum_d->name; break;
    217                 }
    218 
    219                 if (name->sid == mbr_name->sid) {
     213                if (name->sid == modm->u.csi->name->sid) {
    220214                        /* Match */
    221215                        switch (modm->mc) {
     
    223217                                symbol = csi_to_symbol(modm->u.csi);
    224218                                break;
    225                         case mc_enum:
    226                                 symbol = enum_to_symbol(modm->u.enum_d);
    227                                 break;
     219                        default:
     220                                assert(b_false);
    228221                        }
    229222                        return symbol;
     
    353346}
    354347
    355 /** Convert symbol to enum (base to derived).
    356  *
    357  * @param symbol        Symbol
    358  * @return              Enum or @c NULL if symbol is not a enum
    359  */
    360 stree_enum_t *symbol_to_enum(stree_symbol_t *symbol)
    361 {
    362         if (symbol->sc != sc_enum)
    363                 return NULL;
    364 
    365         return symbol->u.enum_d;
    366 }
    367 
    368 /** Convert enum to symbol (derived to base).
    369  *
    370  * @param deleg         Enum
    371  * @return              Symbol
    372  */
    373 stree_symbol_t *enum_to_symbol(stree_enum_t *enum_d)
    374 {
    375         assert(enum_d->symbol);
    376         return enum_d->symbol;
    377 }
    378 
    379348/** Convert symbol to CSI (base to derived).
    380349 *
     
    401370}
    402371
    403 /** Convert symbol to constructor (base to derived).
    404  *
    405  * @param symbol        Symbol
    406  * @return              Constructor or @c NULL if symbol is not a constructor
    407  */
    408 stree_ctor_t *symbol_to_ctor(stree_symbol_t *symbol)
    409 {
    410         if (symbol->sc != sc_ctor)
    411                 return NULL;
    412 
    413         return symbol->u.ctor;
    414 }
    415 
    416 /** Convert constructor to symbol (derived to base).
    417  *
    418  * @param ctor          Constructor
    419  * @return              Symbol
    420  */
    421 stree_symbol_t *ctor_to_symbol(stree_ctor_t *ctor)
    422 {
    423         assert(ctor->symbol);
    424         return ctor->symbol;
    425 }
    426 
    427 
    428372/** Convert symbol to function (base to derived).
    429373 *
     
    486430        return symbol->u.prop;
    487431}
    488 
    489 /** Get symbol from CSI member.
    490  *
    491  * A symbol corresponds to any CSI member. Return it.
    492  *
    493  * @param csimbr        CSI member
    494  * @return              Symbol
    495  */
    496 static stree_symbol_t *csimbr_to_symbol(stree_csimbr_t *csimbr)
    497 {
    498         stree_symbol_t *symbol;
    499 
    500         /* Keep compiler happy. */
    501         symbol = NULL;
    502 
    503         /* Match */
    504         switch (csimbr->cc) {
    505         case csimbr_csi:
    506                 symbol = csi_to_symbol(csimbr->u.csi);
    507                 break;
    508         case csimbr_ctor:
    509                 symbol = ctor_to_symbol(csimbr->u.ctor);
    510                 break;
    511         case csimbr_deleg:
    512                 symbol = deleg_to_symbol(csimbr->u.deleg);
    513                 break;
    514         case csimbr_enum:
    515                 symbol = enum_to_symbol(csimbr->u.enum_d);
    516                 break;
    517         case csimbr_fun:
    518                 symbol = fun_to_symbol(csimbr->u.fun);
    519                 break;
    520         case csimbr_var:
    521                 symbol = var_to_symbol(csimbr->u.var);
    522                 break;
    523         case csimbr_prop:
    524                 symbol = prop_to_symbol(csimbr->u.prop);
    525                 break;
    526         }
    527 
    528         return symbol;
    529 }
    530 
    531432
    532433/** Convert property to symbol (derived to base).
     
    571472        switch (symbol->sc) {
    572473        case sc_csi: ident = symbol->u.csi->name; break;
    573         case sc_ctor: ident = symbol->u.ctor->name; break;
    574474        case sc_deleg: ident = symbol->u.deleg->name; break;
    575         case sc_enum: ident = symbol->u.enum_d->name; break;
    576475        case sc_fun: ident = symbol->u.fun->name; break;
    577476        case sc_var: ident = symbol->u.var->name; break;
Note: See TracChangeset for help on using the changeset viewer.