Ignore:
File:
1 edited

Legend:

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

    r051bc69a rc5cb943d  
    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
     
    132131    stree_csi_t *scope, stree_ident_t *name)
    133132{
    134         stree_symbol_t *base_csi_sym;
    135133        stree_csi_t *base_csi;
    136134        stree_symbol_t *symbol;
     
    142140
    143141        /* Try inherited members. */
    144         if (scope->base_csi_ref != NULL) {
    145                 base_csi_sym = symbol_xlookup_in_csi(prog,
    146                     csi_to_symbol(scope)->outer_csi, scope->base_csi_ref);
    147                 base_csi = symbol_to_csi(base_csi_sym);
    148                 assert(base_csi != NULL);
    149 
     142        base_csi = symbol_get_base_class(prog, scope);
     143        if (base_csi != NULL)
    150144                return symbol_search_csi(prog, base_csi, name);
    151         }
    152145
    153146        /* No match */
     
    212205                modm = list_node_data(node, stree_modm_t *);
    213206
     207                /* Make compiler happy. */
     208                mbr_name = NULL;
     209
    214210                switch (modm->mc) {
    215211                case mc_csi: mbr_name = modm->u.csi->name; break;
     
    217213                }
    218214
     215                /* The Clang static analyzer is just too picky. */
     216                assert(mbr_name != NULL);
     217
    219218                if (name->sid == mbr_name->sid) {
     219                        /* Make compiler happy. */
     220                        symbol = NULL;
     221
    220222                        /* Match */
    221223                        switch (modm->mc) {
     
    231233                node = list_next(&prog->module->members, node);
    232234        }
     235
     236        return NULL;
     237}
     238
     239/** Get explicit base class for a CSI.
     240 *
     241 * Note that if there is no explicit base class (class is derived implicitly
     242 * from @c object, then @c NULL is returned.
     243 *
     244 * @param prog  Program to look in
     245 * @param csi   CSI
     246 *
     247 * @return      Base class (CSI) or @c NULL if no explicit base class.
     248 */
     249stree_csi_t *symbol_get_base_class(stree_program_t *prog, stree_csi_t *csi)
     250{
     251        list_node_t *pred_n;
     252        stree_texpr_t *pred;
     253        stree_symbol_t *pred_sym;
     254        stree_csi_t *pred_csi;
     255        stree_csi_t *outer_csi;
     256
     257        outer_csi = csi_to_symbol(csi)->outer_csi;
     258
     259        pred_n = list_first(&csi->inherit);
     260        if (pred_n == NULL)
     261                return NULL;
     262
     263        pred = list_node_data(pred_n, stree_texpr_t *);
     264        pred_sym = symbol_xlookup_in_csi(prog, outer_csi, pred);
     265        pred_csi = symbol_to_csi(pred_sym);
     266        assert(pred_csi != NULL); /* XXX! */
     267
     268        if (pred_csi->cc == csi_class)
     269                return pred_csi;
     270
     271        return NULL;
     272}
     273
     274/** Get type expression referencing base class for a CSI.
     275 *
     276 * Note that if there is no explicit base class (class is derived implicitly
     277 * from @c object, then @c NULL is returned.
     278 *
     279 * @param prog  Program to look in
     280 * @param csi   CSI
     281 *
     282 * @return      Type expression or @c NULL if no explicit base class.
     283 */
     284stree_texpr_t *symbol_get_base_class_ref(stree_program_t *prog,
     285    stree_csi_t *csi)
     286{
     287        list_node_t *pred_n;
     288        stree_texpr_t *pred;
     289        stree_symbol_t *pred_sym;
     290        stree_csi_t *pred_csi;
     291        stree_csi_t *outer_csi;
     292
     293        outer_csi = csi_to_symbol(csi)->outer_csi;
     294
     295        pred_n = list_first(&csi->inherit);
     296        if (pred_n == NULL)
     297                return NULL;
     298
     299        pred = list_node_data(pred_n, stree_texpr_t *);
     300        pred_sym = symbol_xlookup_in_csi(prog, outer_csi, pred);
     301        pred_csi = symbol_to_csi(pred_sym);
     302        assert(pred_csi != NULL); /* XXX! */
     303
     304        if (pred_csi->cc == csi_class)
     305                return pred;
    233306
    234307        return NULL;
     
    286359        stree_csimbr_t *csimbr;
    287360        stree_symbol_t *entry, *etmp;
     361        stree_symbol_t *fun_sym;
    288362
    289363        entry = NULL;
     
    305379                        break;
    306380                case csimbr_fun:
    307                         if (csimbr->u.fun->name->sid == name->sid) {
     381                        fun_sym = fun_to_symbol(csimbr->u.fun);
     382
     383                        if (csimbr->u.fun->name->sid == name->sid &&
     384                            stree_symbol_has_attr(fun_sym, sac_static)) {
    308385                                if (entry != NULL) {
    309386                                        printf("Error: Duplicate entry point.\n");
    310387                                        exit(1);
    311388                                }
    312                                 entry = fun_to_symbol(csimbr->u.fun);
     389                                entry = fun_sym;
    313390                        }
    314391                default:
     
    494571 * @return              Symbol
    495572 */
    496 static stree_symbol_t *csimbr_to_symbol(stree_csimbr_t *csimbr)
     573stree_symbol_t *csimbr_to_symbol(stree_csimbr_t *csimbr)
    497574{
    498575        stree_symbol_t *symbol;
     
    569646        stree_ident_t *ident;
    570647
     648        /* Make compiler happy. */
     649        ident = NULL;
     650
    571651        switch (symbol->sc) {
    572652        case sc_csi: ident = symbol->u.csi->name; break;
Note: See TracChangeset for help on using the changeset viewer.