Changeset 37f527b in mainline for uspace/app/sbi/src/parse.c
- Timestamp:
- 2010-03-26T21:55:23Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4204ad9
- Parents:
- b535aeb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/parse.c
rb535aeb r37f527b 43 43 #include "stree.h" 44 44 #include "strtab.h" 45 #include "symbol.h" 45 46 46 47 #include "parse.h" … … 49 50 * Module members 50 51 */ 51 static stree_csi_t *parse_csi(parse_t *parse, lclass_t dclass); 52 static stree_csi_t *parse_csi(parse_t *parse, lclass_t dclass, 53 stree_csi_t *outer_csi); 52 54 static stree_csimbr_t *parse_csimbr(parse_t *parse, stree_csi_t *outer_csi); 53 55 54 static stree_fun_t *parse_fun(parse_t *parse); 55 static stree_var_t *parse_var(parse_t *parse); 56 static stree_prop_t *parse_prop(parse_t *parse); 56 static stree_fun_t *parse_fun(parse_t *parse, stree_csi_t *outer_csi); 57 static stree_var_t *parse_var(parse_t *parse, stree_csi_t *outer_csi); 58 static stree_prop_t *parse_prop(parse_t *parse, stree_csi_t *outer_csi); 59 60 static stree_symbol_attr_t *parse_symbol_attr(parse_t *parse); 57 61 58 62 static stree_proc_arg_t *parse_proc_arg(parse_t *parse); … … 63 67 */ 64 68 static stree_block_t *parse_block(parse_t *parse); 65 static stree_stat_t *parse_stat(parse_t *parse);66 69 67 70 static stree_vdecl_t *parse_vdecl(parse_t *parse); … … 89 92 stree_csi_t *csi; 90 93 stree_modm_t *modm; 91 stree_symbol_t *symbol;92 94 93 95 while (lcur_lc(parse) != lc_eof) { … … 96 98 case lc_struct: 97 99 case lc_interface: 98 csi = parse_csi(parse, lcur_lc(parse) );100 csi = parse_csi(parse, lcur_lc(parse), NULL); 99 101 modm = stree_modm_new(mc_csi); 100 102 modm->u.csi = csi; 101 102 symbol = stree_symbol_new(sc_csi);103 symbol->u.csi = csi;104 symbol->outer_csi = NULL;105 csi->symbol = symbol;106 103 107 104 list_append(&parse->cur_mod->members, modm); … … 117 114 118 115 /** Parse class, struct or interface declaration. */ 119 static stree_csi_t *parse_csi(parse_t *parse, lclass_t dclass) 116 static stree_csi_t *parse_csi(parse_t *parse, lclass_t dclass, 117 stree_csi_t *outer_csi) 120 118 { 121 119 stree_csi_t *csi; 122 120 csi_class_t cc; 123 121 stree_csimbr_t *csimbr; 122 stree_symbol_t *symbol; 124 123 125 124 switch (dclass) { … … 134 133 csi = stree_csi_new(cc); 135 134 csi->name = parse_ident(parse); 135 136 symbol = stree_symbol_new(sc_csi); 137 symbol->u.csi = csi; 138 symbol->outer_csi = outer_csi; 139 csi->symbol = symbol; 136 140 137 141 #ifdef DEBUG_PARSE_TRACE … … 171 175 stree_prop_t *prop; 172 176 173 stree_symbol_t *symbol;174 175 177 switch (lcur_lc(parse)) { 176 178 case lc_class: 177 179 case lc_struct: 178 180 case lc_interface: 179 csi = parse_csi(parse, lcur_lc(parse) );181 csi = parse_csi(parse, lcur_lc(parse), outer_csi); 180 182 csimbr = stree_csimbr_new(csimbr_csi); 181 183 csimbr->u.csi = csi; 182 183 symbol = stree_symbol_new(sc_csi);184 symbol->u.csi = csi;185 symbol->outer_csi = outer_csi;186 csi->symbol = symbol;187 184 break; 188 185 case lc_fun: 189 fun = parse_fun(parse );186 fun = parse_fun(parse, outer_csi); 190 187 csimbr = stree_csimbr_new(csimbr_fun); 191 188 csimbr->u.fun = fun; 192 193 symbol = stree_symbol_new(sc_fun);194 symbol->u.fun = fun;195 symbol->outer_csi = outer_csi;196 fun->symbol = symbol;197 fun->proc->outer_symbol = symbol;198 189 break; 199 190 case lc_var: 200 var = parse_var(parse );191 var = parse_var(parse, outer_csi); 201 192 csimbr = stree_csimbr_new(csimbr_var); 202 193 csimbr->u.var = var; 203 204 symbol = stree_symbol_new(sc_var);205 symbol->u.var = var;206 symbol->outer_csi = outer_csi;207 var->symbol = symbol;208 194 break; 209 195 case lc_prop: 210 prop = parse_prop(parse );196 prop = parse_prop(parse, outer_csi); 211 197 csimbr = stree_csimbr_new(csimbr_prop); 212 198 csimbr->u.prop = prop; 213 214 symbol = stree_symbol_new(sc_prop);215 symbol->u.prop = prop;216 symbol->outer_csi = outer_csi;217 prop->symbol = symbol;218 if (prop->getter)219 prop->getter->outer_symbol = symbol;220 if (prop->setter)221 prop->setter->outer_symbol = symbol;222 199 break; 223 200 default: … … 231 208 232 209 /** Parse member function. */ 233 static stree_fun_t *parse_fun(parse_t *parse )210 static stree_fun_t *parse_fun(parse_t *parse, stree_csi_t *outer_csi) 234 211 { 235 212 stree_fun_t *fun; 236 213 stree_proc_arg_t *arg; 214 stree_symbol_t *symbol; 215 stree_symbol_attr_t *attr; 237 216 238 217 fun = stree_fun_new(); 218 symbol = stree_symbol_new(sc_fun); 219 220 symbol->u.fun = fun; 221 symbol->outer_csi = outer_csi; 222 fun->symbol = symbol; 239 223 240 224 lmatch(parse, lc_fun); … … 277 261 } 278 262 279 lmatch(parse, lc_is); 263 list_init(&symbol->attr); 264 265 /* Parse attributes. */ 266 while (lcur_lc(parse) == lc_comma) { 267 lskip(parse); 268 attr = parse_symbol_attr(parse); 269 list_append(&symbol->attr, attr); 270 } 271 280 272 fun->proc = stree_proc_new(); 281 fun->proc->body = parse_block(parse); 282 lmatch(parse, lc_end); 273 fun->proc->outer_symbol = symbol; 274 275 if (lcur_lc(parse) == lc_scolon) { 276 lskip(parse); 277 278 /* This function has no body. */ 279 if (!stree_symbol_has_attr(symbol, sac_builtin)) { 280 printf("Error: Function '"); 281 symbol_print_fqn(symbol); 282 printf("' has no body.\n"); 283 exit(1); 284 } 285 fun->proc->body = NULL; 286 } else { 287 lmatch(parse, lc_is); 288 fun->proc->body = parse_block(parse); 289 lmatch(parse, lc_end); 290 } 283 291 284 292 return fun; … … 286 294 287 295 /** Parse member variable. */ 288 static stree_var_t *parse_var(parse_t *parse )296 static stree_var_t *parse_var(parse_t *parse, stree_csi_t *outer_csi) 289 297 { 290 298 stree_var_t *var; 299 stree_symbol_t *symbol; 291 300 292 301 var = stree_var_new(); 302 symbol = stree_symbol_new(sc_var); 303 symbol->u.var = var; 304 symbol->outer_csi = outer_csi; 305 var->symbol = symbol; 293 306 294 307 lmatch(parse, lc_var); … … 302 315 303 316 /** Parse member property. */ 304 static stree_prop_t *parse_prop(parse_t *parse )317 static stree_prop_t *parse_prop(parse_t *parse, stree_csi_t *outer_csi) 305 318 { 306 319 stree_prop_t *prop; 320 stree_symbol_t *symbol; 321 307 322 stree_ident_t *ident; 308 323 stree_proc_arg_t *arg; … … 310 325 prop = stree_prop_new(); 311 326 list_init(&prop->args); 327 328 symbol = stree_symbol_new(sc_prop); 329 symbol->u.prop = prop; 330 symbol->outer_csi = outer_csi; 331 prop->symbol = symbol; 312 332 313 333 lmatch(parse, lc_prop); … … 363 383 prop->getter = stree_proc_new(); 364 384 prop->getter->body = parse_block(parse); 385 prop->getter->outer_symbol = symbol; 365 386 366 387 lmatch(parse, lc_end); … … 380 401 prop->setter = stree_proc_new(); 381 402 prop->setter->body = parse_block(parse); 403 prop->setter->outer_symbol = symbol; 382 404 383 405 lmatch(parse, lc_end); … … 393 415 } 394 416 417 /** Parse symbol attribute. */ 418 static stree_symbol_attr_t *parse_symbol_attr(parse_t *parse) 419 { 420 stree_symbol_attr_t *attr; 421 422 if (lcur_lc(parse) != lc_builtin) { 423 printf("Error: Unexpected attribute '"); 424 lem_print(lcur(parse)); 425 printf("'.\n"); 426 exit(1); 427 } 428 429 lskip(parse); 430 431 attr = stree_symbol_attr_new(sac_builtin); 432 return attr; 433 } 434 395 435 /** Parse formal function argument. */ 396 436 static stree_proc_arg_t *parse_proc_arg(parse_t *parse) … … 455 495 456 496 /** Parse statement. */ 457 st atic stree_stat_t *parse_stat(parse_t *parse)497 stree_stat_t *parse_stat(parse_t *parse) 458 498 { 459 499 stree_stat_t *stat; … … 719 759 lem_t *lcur(parse_t *parse) 720 760 { 721 return &parse->lex->current;761 return lex_get_current(parse->lex); 722 762 } 723 763 … … 725 765 lclass_t lcur_lc(parse_t *parse) 726 766 { 727 return parse->lex->current.lclass; 767 lem_t *lem; 768 769 lem = lcur(parse); 770 return lem->lclass; 728 771 } 729 772
Note:
See TracChangeset
for help on using the changeset viewer.