Ignore:
File:
1 edited

Legend:

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

    r074444f r38aaacc2  
    4444static stree_ident_t *symbol_get_ident(stree_symbol_t *symbol);
    4545
    46 /** Lookup symbol in CSI using a type expression. */
     46/** Lookup symbol in CSI using a type expression.
     47 *
     48 * XXX This should be removed in favor of full type expression evaluation
     49 * (run_texpr). This cannot work properly with generics.
     50 *
     51 * @param prog          Program
     52 * @param scope         CSI used as base for relative references
     53 * @param texpr         Type expression
     54 *
     55 * @return              Symbol referenced by type expression or @c NULL
     56 *                      if not found
     57 */
    4758stree_symbol_t *symbol_xlookup_in_csi(stree_program_t *prog,
    4859    stree_csi_t *scope, stree_texpr_t *texpr)
     
    7788/** Lookup symbol reference in CSI.
    7889 *
    79  * @param prog  Program to look in.
    80  * @param scope CSI in @a prog which is the base for references.
    81  * @param name  Identifier of the symbol.
    82  *
    83  * @return      Symbol or @c NULL if symbol not found.
     90 * @param prog  Program to look in
     91 * @param scope CSI in @a prog which is the base for references
     92 * @param name  Identifier of the symbol
     93 *
     94 * @return      Symbol or @c NULL if symbol not found
    8495 */
    8596stree_symbol_t *symbol_lookup_in_csi(stree_program_t *prog, stree_csi_t *scope,
     
    107118 * Look for symbol in definition of a CSI and its ancestors. (But not
    108119 * in lexically enclosing CSI.)
     120 *
     121 * @param prog  Program to look in
     122 * @param scope CSI in which to look
     123 * @param name  Identifier of the symbol
     124 *
     125 * @return      Symbol or @c NULL if symbol not found.
    109126 */
    110127stree_symbol_t *symbol_search_csi(stree_program_t *prog,
     
    125142        while (node != NULL) {
    126143                csimbr = list_node_data(node, stree_csimbr_t *);
     144
     145                /* Keep compiler happy. */
     146                mbr_name = NULL;
     147
    127148                switch (csimbr->cc) {
    128149                case csimbr_csi: mbr_name = csimbr->u.csi->name; break;
     150                case csimbr_deleg: mbr_name = csimbr->u.deleg->name; break;
    129151                case csimbr_fun: mbr_name = csimbr->u.fun->name; break;
    130152                case csimbr_var: mbr_name = csimbr->u.var->name; break;
    131153                case csimbr_prop: mbr_name = csimbr->u.prop->name; break;
    132                 default: assert(b_false);
    133154                }
    134155
     
    138159                        case csimbr_csi:
    139160                                symbol = csi_to_symbol(csimbr->u.csi);
     161                                break;
     162                        case csimbr_deleg:
     163                                symbol = deleg_to_symbol(csimbr->u.deleg);
    140164                                break;
    141165                        case csimbr_fun:
     
    170194}
    171195
     196/** Look for symbol in global scope.
     197 *
     198 * @param prog  Program to look in
     199 * @param name  Identifier of the symbol
     200 *
     201 * @return      Symbol or @c NULL if symbol not found.
     202 */
    172203static stree_symbol_t *symbol_search_global(stree_program_t *prog,
    173204    stree_ident_t *name)
     
    197228}
    198229
    199 /** Find entry point. */
     230/** Find entry point.
     231 *
     232 * Perform a walk of all CSIs and look for a function with the name @a name.
     233 *
     234 * @param prog  Program to look in
     235 * @param name  Name of entry point
     236 *
     237 * @return      Symbol or @c NULL if symbol not found.
     238 */
    200239stree_symbol_t *symbol_find_epoint(stree_program_t *prog, stree_ident_t *name)
    201240{
     
    225264}
    226265
     266/** Find entry point under CSI.
     267 *
     268 * Internal part of symbol_find_epoint() that recursively walks CSIs.
     269 *
     270 * @param prog  Program to look in
     271 * @param name  Name of entry point
     272 *
     273 * @return      Symbol or @c NULL if symbol not found.
     274 */
    227275static stree_symbol_t *symbol_find_epoint_rec(stree_program_t *prog,
    228276    stree_ident_t *name, stree_csi_t *csi)
     
    267315}
    268316
     317/*
     318 * The notion of symbol is designed as a common base class for several
     319 * types of declarations with global and CSI scope. Here we simulate
     320 * conversion from this base class (symbol) to derived classes (CSI,
     321 * fun, ..) and vice versa.
     322 */
     323
     324/** Convert symbol to delegate (base to derived).
     325 *
     326 * @param symbol        Symbol
     327 * @return              Delegate or @c NULL if symbol is not a delegate
     328 */
     329stree_deleg_t *symbol_to_deleg(stree_symbol_t *symbol)
     330{
     331        if (symbol->sc != sc_deleg)
     332                return NULL;
     333
     334        return symbol->u.deleg;
     335}
     336
     337/** Convert delegate to symbol (derived to base).
     338 *
     339 * @param deleg         Delegate
     340 * @return              Symbol
     341 */
     342stree_symbol_t *deleg_to_symbol(stree_deleg_t *deleg)
     343{
     344        assert(deleg->symbol);
     345        return deleg->symbol;
     346}
     347
     348/** Convert symbol to CSI (base to derived).
     349 *
     350 * @param symbol        Symbol
     351 * @return              CSI or @c NULL if symbol is not a CSI
     352 */
    269353stree_csi_t *symbol_to_csi(stree_symbol_t *symbol)
    270354{
     
    275359}
    276360
     361/** Convert CSI to symbol (derived to base).
     362 *
     363 * @param csi           CSI
     364 * @return              Symbol
     365 */
    277366stree_symbol_t *csi_to_symbol(stree_csi_t *csi)
    278367{
     
    281370}
    282371
     372/** Convert symbol to function (base to derived).
     373 *
     374 * @param symbol        Symbol
     375 * @return              Function or @c NULL if symbol is not a function
     376 */
    283377stree_fun_t *symbol_to_fun(stree_symbol_t *symbol)
    284378{
     
    289383}
    290384
     385/** Convert function to symbol (derived to base).
     386 *
     387 * @param fun           Function
     388 * @return              Symbol
     389 */
    291390stree_symbol_t *fun_to_symbol(stree_fun_t *fun)
    292391{
     
    295394}
    296395
     396/** Convert symbol to member variable (base to derived).
     397 *
     398 * @param symbol        Symbol
     399 * @return              Variable or @c NULL if symbol is not a member variable
     400 */
    297401stree_var_t *symbol_to_var(stree_symbol_t *symbol)
    298402{
     
    303407}
    304408
     409/** Convert variable to symbol (derived to base).
     410 *
     411 * @param fun           Variable
     412 * @return              Symbol
     413 */
    305414stree_symbol_t *var_to_symbol(stree_var_t *var)
    306415{
     
    309418}
    310419
     420/** Convert symbol to property (base to derived).
     421 *
     422 * @param symbol        Symbol
     423 * @return              Property or @c NULL if symbol is not a property
     424 */
    311425stree_prop_t *symbol_to_prop(stree_symbol_t *symbol)
    312426{
     
    317431}
    318432
     433/** Convert property to symbol (derived to base).
     434 *
     435 * @param fun           Property
     436 * @return              Symbol
     437 */
    319438stree_symbol_t *prop_to_symbol(stree_prop_t *prop)
    320439{
     
    323442}
    324443
    325 /** Print fully qualified name of symbol. */
     444/** Print fully qualified name of symbol.
     445 *
     446 * @param symbol        Symbol
     447 */
    326448void symbol_print_fqn(stree_symbol_t *symbol)
    327449{
     
    339461}
    340462
     463/** Return symbol identifier.
     464 *
     465 * @param symbol        Symbol
     466 * @return              Symbol identifier
     467 */
    341468static stree_ident_t *symbol_get_ident(stree_symbol_t *symbol)
    342469{
     
    345472        switch (symbol->sc) {
    346473        case sc_csi: ident = symbol->u.csi->name; break;
     474        case sc_deleg: ident = symbol->u.deleg->name; break;
    347475        case sc_fun: ident = symbol->u.fun->name; break;
    348476        case sc_var: ident = symbol->u.var->name; break;
Note: See TracChangeset for help on using the changeset viewer.