Changeset 051bc69a in mainline for uspace/app/sbi/src/parse.c
- Timestamp:
- 2010-05-08T08:10:44Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 640ffe6, c5cb943d
- Parents:
- 25a76ab8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/parse.c
r25a76ab8 r051bc69a 48 48 49 49 /* 50 * Module members50 * Module and CSI members 51 51 */ 52 52 static stree_csi_t *parse_csi(parse_t *parse, lclass_t dclass, 53 53 stree_csi_t *outer_csi); 54 54 static stree_csimbr_t *parse_csimbr(parse_t *parse, stree_csi_t *outer_csi); 55 56 static stree_ctor_t *parse_ctor(parse_t *parse, stree_csi_t *outer_csi); 57 58 static stree_enum_t *parse_enum(parse_t *parse, stree_csi_t *outer_csi); 59 static stree_embr_t *parse_embr(parse_t *parse, stree_enum_t *outer_enum); 55 60 56 61 static stree_deleg_t *parse_deleg(parse_t *parse, stree_csi_t *outer_csi); … … 76 81 static stree_for_t *parse_for(parse_t *parse); 77 82 static stree_raise_t *parse_raise(parse_t *parse); 83 static stree_break_t *parse_break(parse_t *parse); 78 84 static stree_return_t *parse_return(parse_t *parse); 79 85 static stree_wef_t *parse_wef(parse_t *parse); … … 123 129 { 124 130 stree_csi_t *csi; 131 stree_enum_t *enum_d; 125 132 stree_modm_t *modm; 126 133 … … 136 143 list_append(&parse->cur_mod->members, modm); 137 144 break; 145 case lc_enum: 146 enum_d = parse_enum(parse, NULL); 147 modm = stree_modm_new(mc_enum); 148 modm->u.enum_d = enum_d; 149 150 list_append(&parse->cur_mod->members, modm); 151 break; 138 152 default: 139 153 lunexpected_error(parse); … … 223 237 * 224 238 * @param parse Parser object. 225 * @param outer_csi CSI containing this declaration or @c NULL if global.239 * @param outer_csi CSI containing this declaration. 226 240 * @return New syntax tree node. In case of parse error, 227 241 * @c NULL may (but need not) be returned. … … 232 246 233 247 stree_csi_t *csi; 248 stree_ctor_t *ctor; 234 249 stree_deleg_t *deleg; 250 stree_enum_t *enum_d; 235 251 stree_fun_t *fun; 236 252 stree_var_t *var; … … 245 261 csimbr->u.csi = csi; 246 262 break; 263 case lc_new: 264 ctor = parse_ctor(parse, outer_csi); 265 csimbr = stree_csimbr_new(csimbr_ctor); 266 csimbr->u.ctor = ctor; 267 break; 247 268 case lc_deleg: 248 269 deleg = parse_deleg(parse, outer_csi); … … 250 271 csimbr->u.deleg = deleg; 251 272 break; 273 case lc_enum: 274 enum_d = parse_enum(parse, outer_csi); 275 csimbr = stree_csimbr_new(csimbr_enum); 276 csimbr->u.enum_d = enum_d; 277 break; 252 278 case lc_fun: 253 279 fun = parse_fun(parse, outer_csi); … … 273 299 274 300 return csimbr; 301 } 302 303 /** Parse constructor. 304 * 305 * @param parse Parser object. 306 * @param outer_csi CSI containing this declaration or @c NULL if global. 307 * @return New syntax tree node. 308 */ 309 static stree_ctor_t *parse_ctor(parse_t *parse, stree_csi_t *outer_csi) 310 { 311 stree_ctor_t *ctor; 312 stree_symbol_t *symbol; 313 stree_symbol_attr_t *attr; 314 315 ctor = stree_ctor_new(); 316 symbol = stree_symbol_new(sc_ctor); 317 318 symbol->u.ctor = ctor; 319 symbol->outer_csi = outer_csi; 320 ctor->symbol = symbol; 321 322 lmatch(parse, lc_new); 323 324 /* Fake identifier. */ 325 ctor->name = stree_ident_new(); 326 ctor->name->sid = strtab_get_sid(CTOR_IDENT); 327 ctor->name->cspan = lprev_span(parse); 328 329 #ifdef DEBUG_PARSE_TRACE 330 printf("Parsing constructor of CSI '"); 331 symbol_print_fqn(csi_to_symbol(outer_csi)); 332 printf("'.\n"); 333 #endif 334 ctor->sig = parse_fun_sig(parse); 335 if (ctor->sig->rtype != NULL) { 336 printf("Error: Constructor of CSI '"); 337 symbol_print_fqn(csi_to_symbol(outer_csi)); 338 printf("' has a return type.\n"); 339 parse_note_error(parse); 340 } 341 342 list_init(&symbol->attr); 343 344 /* Parse attributes. */ 345 while (lcur_lc(parse) == lc_comma && !parse_is_error(parse)) { 346 lskip(parse); 347 attr = parse_symbol_attr(parse); 348 list_append(&symbol->attr, attr); 349 } 350 351 ctor->proc = stree_proc_new(); 352 ctor->proc->outer_symbol = symbol; 353 354 if (lcur_lc(parse) == lc_scolon) { 355 lskip(parse); 356 357 /* This constructor has no body. */ 358 printf("Error: Constructor of CSI '"); 359 symbol_print_fqn(csi_to_symbol(outer_csi)); 360 printf("' has no body.\n"); 361 parse_note_error(parse); 362 363 ctor->proc->body = NULL; 364 } else { 365 lmatch(parse, lc_is); 366 ctor->proc->body = parse_block(parse); 367 lmatch(parse, lc_end); 368 } 369 370 return ctor; 371 } 372 373 /** Parse @c enum declaration. 374 * 375 * @param parse Parser object. 376 * @param outer_csi CSI containing this declaration or @c NULL if global. 377 * @return New syntax tree node. 378 */ 379 static stree_enum_t *parse_enum(parse_t *parse, stree_csi_t *outer_csi) 380 { 381 stree_enum_t *enum_d; 382 stree_symbol_t *symbol; 383 stree_embr_t *embr; 384 385 enum_d = stree_enum_new(); 386 symbol = stree_symbol_new(sc_enum); 387 388 symbol->u.enum_d = enum_d; 389 symbol->outer_csi = outer_csi; 390 enum_d->symbol = symbol; 391 392 lmatch(parse, lc_enum); 393 enum_d->name = parse_ident(parse); 394 list_init(&enum_d->members); 395 396 #ifdef DEBUG_PARSE_TRACE 397 printf("Parse enum '%s'.\n", strtab_get_str(enum_d->name->sid)); 398 #endif 399 lmatch(parse, lc_is); 400 401 /* Parse enum members. */ 402 while (lcur_lc(parse) != lc_end && !parse_is_error(parse)) { 403 embr = parse_embr(parse, enum_d); 404 if (embr == NULL) 405 break; 406 407 list_append(&enum_d->members, embr); 408 } 409 410 if (list_is_empty(&enum_d->members)) { 411 printf("Error: Enum type '%s' has no members.\n", 412 strtab_get_str(enum_d->name->sid)); 413 parse_note_error(parse); 414 } 415 416 lmatch(parse, lc_end); 417 418 return enum_d; 419 } 420 421 /** Parse enum member. 422 * 423 * @param parse Parser object. 424 * @param outer_enum Enum containing this declaration. 425 * @return New syntax tree node. In case of parse error, 426 * @c NULL may (but need not) be returned. 427 */ 428 static stree_embr_t *parse_embr(parse_t *parse, stree_enum_t *outer_enum) 429 { 430 stree_embr_t *embr; 431 432 embr = stree_embr_new(); 433 embr->outer_enum = outer_enum; 434 embr->name = parse_ident(parse); 435 436 lmatch(parse, lc_scolon); 437 438 return embr; 275 439 } 276 440 … … 681 845 stree_for_t *for_s; 682 846 stree_raise_t *raise_s; 847 stree_break_t *break_s; 683 848 stree_return_t *return_s; 684 849 stree_wef_t *wef_s; … … 714 879 stat->u.raise_s = raise_s; 715 880 break; 881 case lc_break: 882 break_s = parse_break(parse); 883 stat = stree_stat_new(st_break); 884 stat->u.break_s = break_s; 885 break; 716 886 case lc_return: 717 887 return_s = parse_return(parse); … … 777 947 { 778 948 stree_if_t *if_s; 949 stree_if_clause_t *if_c; 779 950 780 951 #ifdef DEBUG_PARSE_TRACE … … 782 953 #endif 783 954 if_s = stree_if_new(); 784 955 list_init(&if_s->if_clauses); 956 957 /* Parse @c if clause. */ 785 958 lmatch(parse, lc_if); 786 if_s->cond = parse_expr(parse); 959 960 if_c = stree_if_clause_new(); 961 if_c->cond = parse_expr(parse); 787 962 lmatch(parse, lc_then); 788 if_s->if_block = parse_block(parse); 789 963 if_c->block = parse_block(parse); 964 965 list_append(&if_s->if_clauses, if_c); 966 967 /* Parse @c elif clauses. */ 968 while (lcur_lc(parse) == lc_elif) { 969 lskip(parse); 970 if_c = stree_if_clause_new(); 971 if_c->cond = parse_expr(parse); 972 lmatch(parse, lc_then); 973 if_c->block = parse_block(parse); 974 975 list_append(&if_s->if_clauses, if_c); 976 } 977 978 /* Parse @c else clause. */ 790 979 if (lcur_lc(parse) == lc_else) { 791 980 lskip(parse); … … 867 1056 } 868 1057 1058 /** Parse @c break statement. 1059 * 1060 * @param parse Parser object. 1061 * @return New syntax tree node. 1062 */ 1063 static stree_break_t *parse_break(parse_t *parse) 1064 { 1065 stree_break_t *break_s; 1066 1067 #ifdef DEBUG_PARSE_TRACE 1068 printf("Parse 'break' statement.\n"); 1069 #endif 1070 break_s = stree_break_new(); 1071 1072 lmatch(parse, lc_break); 1073 lmatch(parse, lc_scolon); 1074 1075 return break_s; 1076 } 1077 869 1078 /** Parse @c return statement. 870 1079 * … … 882 1091 883 1092 lmatch(parse, lc_return); 884 return_s->expr = parse_expr(parse); 1093 1094 if (lcur_lc(parse) != lc_scolon) 1095 return_s->expr = parse_expr(parse); 1096 885 1097 lmatch(parse, lc_scolon); 886 1098 … … 996 1208 ident = stree_ident_new(); 997 1209 ident->sid = lcur(parse)->u.ident.sid; 1210 ident->cspan = lcur_span(parse); 998 1211 lskip(parse); 999 1212 … … 1059 1272 /** Return current lem lclass. 1060 1273 * 1061 * @param parse Parser object .1062 * @return Lclass of the current lem .1274 * @param parse Parser object 1275 * @return Lclass of the current lem 1063 1276 */ 1064 1277 lclass_t lcur_lc(parse_t *parse) … … 1081 1294 } 1082 1295 1296 /** Return coordinate span of current lem. 1297 * 1298 * @param parse Parser object 1299 * @return Coordinate span of current lem or @c NULL if a 1300 * parse error is active 1301 */ 1302 cspan_t *lcur_span(parse_t *parse) 1303 { 1304 lem_t *lem; 1305 1306 if (parse_is_error(parse)) 1307 return NULL; 1308 1309 lem = lcur(parse); 1310 return lem->cspan; 1311 } 1312 1313 /** Return coordinate span of previous lem. 1314 * 1315 * @param parse Parser object 1316 * @return Coordinate span of previous lem or @c NULL if 1317 * parse error is active or previous lem is not 1318 * available. 1319 */ 1320 cspan_t *lprev_span(parse_t *parse) 1321 { 1322 lem_t *lem; 1323 1324 if (parse_is_error(parse)) 1325 return NULL; 1326 1327 lem = lex_peek_prev(parse->lex); 1328 if (lem == NULL) 1329 return NULL; 1330 1331 return lem->cspan; 1332 } 1333 1083 1334 /** Skip to next lem. 1084 1335 * … … 1170 1421 { 1171 1422 switch (lclass) { 1423 case lc_elif: 1172 1424 case lc_else: 1173 1425 case lc_end:
Note:
See TracChangeset
for help on using the changeset viewer.