Changes in uspace/app/sbi/src/symbol.c [051bc69a:38aaacc2] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/symbol.c
r051bc69a r38aaacc2 42 42 static stree_symbol_t *symbol_find_epoint_rec(stree_program_t *prog, 43 43 stree_ident_t *name, stree_csi_t *csi); 44 static stree_symbol_t *csimbr_to_symbol(stree_csimbr_t *csimbr);45 44 static stree_ident_t *symbol_get_ident(stree_symbol_t *symbol); 46 45 … … 89 88 /** Lookup symbol reference in CSI. 90 89 * 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 *94 90 * @param prog Program to look in 95 91 * @param scope CSI in @a prog which is the base for references … … 132 128 stree_csi_t *scope, stree_ident_t *name) 133 129 { 130 list_node_t *node; 131 stree_csimbr_t *csimbr; 132 stree_symbol_t *symbol; 133 stree_ident_t *mbr_name; 134 134 stree_symbol_t *base_csi_sym; 135 135 stree_csi_t *base_csi; 136 stree_symbol_t *symbol; 136 137 (void) prog; 137 138 138 139 /* 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 } 142 181 143 182 /* Try inherited members. */ … … 155 194 } 156 195 157 /** Look for symbol strictly in CSI.158 *159 * Look for symbol in definition of a CSI and its ancestors. (But not160 * in lexically enclosing CSI or in base CSI.)161 *162 * @param prog Program to look in163 * @param scope CSI in which to look164 * @param name Identifier of the symbol165 *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 195 196 /** Look for symbol in global scope. 196 197 * … … 206 207 stree_modm_t *modm; 207 208 stree_symbol_t *symbol; 208 stree_ident_t *mbr_name;209 209 210 210 node = list_first(&prog->module->members); 211 211 while (node != NULL) { 212 212 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) { 220 214 /* Match */ 221 215 switch (modm->mc) { … … 223 217 symbol = csi_to_symbol(modm->u.csi); 224 218 break; 225 case mc_enum: 226 symbol = enum_to_symbol(modm->u.enum_d); 227 break; 219 default: 220 assert(b_false); 228 221 } 229 222 return symbol; … … 353 346 } 354 347 355 /** Convert symbol to enum (base to derived).356 *357 * @param symbol Symbol358 * @return Enum or @c NULL if symbol is not a enum359 */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 Enum371 * @return Symbol372 */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 379 348 /** Convert symbol to CSI (base to derived). 380 349 * … … 401 370 } 402 371 403 /** Convert symbol to constructor (base to derived).404 *405 * @param symbol Symbol406 * @return Constructor or @c NULL if symbol is not a constructor407 */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 Constructor419 * @return Symbol420 */421 stree_symbol_t *ctor_to_symbol(stree_ctor_t *ctor)422 {423 assert(ctor->symbol);424 return ctor->symbol;425 }426 427 428 372 /** Convert symbol to function (base to derived). 429 373 * … … 486 430 return symbol->u.prop; 487 431 } 488 489 /** Get symbol from CSI member.490 *491 * A symbol corresponds to any CSI member. Return it.492 *493 * @param csimbr CSI member494 * @return Symbol495 */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 531 432 532 433 /** Convert property to symbol (derived to base). … … 571 472 switch (symbol->sc) { 572 473 case sc_csi: ident = symbol->u.csi->name; break; 573 case sc_ctor: ident = symbol->u.ctor->name; break;574 474 case sc_deleg: ident = symbol->u.deleg->name; break; 575 case sc_enum: ident = symbol->u.enum_d->name; break;576 475 case sc_fun: ident = symbol->u.fun->name; break; 577 476 case sc_var: ident = symbol->u.var->name; break;
Note:
See TracChangeset
for help on using the changeset viewer.