Changeset 640ffe6 in mainline for uspace/app/sbi/src/symbol.c
- Timestamp:
- 2010-05-08T08:15:57Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4039c77
- Parents:
- 1317380 (diff), 051bc69a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/symbol.c
r1317380 r640ffe6 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); 44 45 static stree_ident_t *symbol_get_ident(stree_symbol_t *symbol); 45 46 … … 88 89 /** Lookup symbol reference in CSI. 89 90 * 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 * 90 94 * @param prog Program to look in 91 95 * @param scope CSI in @a prog which is the base for references … … 128 132 stree_csi_t *scope, stree_ident_t *name) 129 133 { 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 137 (void) prog; 136 stree_symbol_t *symbol; 138 137 139 138 /* Look in new members in this class. */ 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 } 139 symbol = symbol_search_csi_no_base(prog, scope, name); 140 if (symbol != NULL) 141 return symbol; 181 142 182 143 /* Try inherited members. */ … … 194 155 } 195 156 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 196 195 /** Look for symbol in global scope. 197 196 * … … 207 206 stree_modm_t *modm; 208 207 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 if (name->sid == modm->u.csi->name->sid) { 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) { 214 220 /* Match */ 215 221 switch (modm->mc) { … … 217 223 symbol = csi_to_symbol(modm->u.csi); 218 224 break; 219 default: 220 assert(b_false); 225 case mc_enum: 226 symbol = enum_to_symbol(modm->u.enum_d); 227 break; 221 228 } 222 229 return symbol; … … 346 353 } 347 354 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 348 379 /** Convert symbol to CSI (base to derived). 349 380 * … … 370 401 } 371 402 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 372 428 /** Convert symbol to function (base to derived). 373 429 * … … 430 486 return symbol->u.prop; 431 487 } 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 432 531 433 532 /** Convert property to symbol (derived to base). … … 472 571 switch (symbol->sc) { 473 572 case sc_csi: ident = symbol->u.csi->name; break; 573 case sc_ctor: ident = symbol->u.ctor->name; break; 474 574 case sc_deleg: ident = symbol->u.deleg->name; break; 575 case sc_enum: ident = symbol->u.enum_d->name; break; 475 576 case sc_fun: ident = symbol->u.fun->name; break; 476 577 case sc_var: ident = symbol->u.var->name; break;
Note:
See TracChangeset
for help on using the changeset viewer.