Changes in uspace/app/sbi/src/parse.c [051bc69a:38aaacc2] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/parse.c
r051bc69a r38aaacc2 48 48 49 49 /* 50 * Module and CSImembers50 * Module 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);60 55 61 56 static stree_deleg_t *parse_deleg(parse_t *parse, stree_csi_t *outer_csi); … … 81 76 static stree_for_t *parse_for(parse_t *parse); 82 77 static stree_raise_t *parse_raise(parse_t *parse); 83 static stree_break_t *parse_break(parse_t *parse);84 78 static stree_return_t *parse_return(parse_t *parse); 85 79 static stree_wef_t *parse_wef(parse_t *parse); … … 129 123 { 130 124 stree_csi_t *csi; 131 stree_enum_t *enum_d;132 125 stree_modm_t *modm; 133 126 … … 143 136 list_append(&parse->cur_mod->members, modm); 144 137 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;152 138 default: 153 139 lunexpected_error(parse); … … 237 223 * 238 224 * @param parse Parser object. 239 * @param outer_csi CSI containing this declaration .225 * @param outer_csi CSI containing this declaration or @c NULL if global. 240 226 * @return New syntax tree node. In case of parse error, 241 227 * @c NULL may (but need not) be returned. … … 246 232 247 233 stree_csi_t *csi; 248 stree_ctor_t *ctor;249 234 stree_deleg_t *deleg; 250 stree_enum_t *enum_d;251 235 stree_fun_t *fun; 252 236 stree_var_t *var; … … 261 245 csimbr->u.csi = csi; 262 246 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;268 247 case lc_deleg: 269 248 deleg = parse_deleg(parse, outer_csi); … … 271 250 csimbr->u.deleg = deleg; 272 251 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;278 252 case lc_fun: 279 253 fun = parse_fun(parse, outer_csi); … … 299 273 300 274 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_TRACE330 printf("Parsing constructor of CSI '");331 symbol_print_fqn(csi_to_symbol(outer_csi));332 printf("'.\n");333 #endif334 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_TRACE397 printf("Parse enum '%s'.\n", strtab_get_str(enum_d->name->sid));398 #endif399 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;439 275 } 440 276 … … 845 681 stree_for_t *for_s; 846 682 stree_raise_t *raise_s; 847 stree_break_t *break_s;848 683 stree_return_t *return_s; 849 684 stree_wef_t *wef_s; … … 879 714 stat->u.raise_s = raise_s; 880 715 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;886 716 case lc_return: 887 717 return_s = parse_return(parse); … … 947 777 { 948 778 stree_if_t *if_s; 949 stree_if_clause_t *if_c;950 779 951 780 #ifdef DEBUG_PARSE_TRACE … … 953 782 #endif 954 783 if_s = stree_if_new(); 955 list_init(&if_s->if_clauses); 956 957 /* Parse @c if clause. */ 784 958 785 lmatch(parse, lc_if); 959 960 if_c = stree_if_clause_new(); 961 if_c->cond = parse_expr(parse); 786 if_s->cond = parse_expr(parse); 962 787 lmatch(parse, lc_then); 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. */ 788 if_s->if_block = parse_block(parse); 789 979 790 if (lcur_lc(parse) == lc_else) { 980 791 lskip(parse); … … 1056 867 } 1057 868 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_TRACE1068 printf("Parse 'break' statement.\n");1069 #endif1070 break_s = stree_break_new();1071 1072 lmatch(parse, lc_break);1073 lmatch(parse, lc_scolon);1074 1075 return break_s;1076 }1077 1078 869 /** Parse @c return statement. 1079 870 * … … 1091 882 1092 883 lmatch(parse, lc_return); 1093 1094 if (lcur_lc(parse) != lc_scolon) 1095 return_s->expr = parse_expr(parse); 1096 884 return_s->expr = parse_expr(parse); 1097 885 lmatch(parse, lc_scolon); 1098 886 … … 1208 996 ident = stree_ident_new(); 1209 997 ident->sid = lcur(parse)->u.ident.sid; 1210 ident->cspan = lcur_span(parse);1211 998 lskip(parse); 1212 999 … … 1272 1059 /** Return current lem lclass. 1273 1060 * 1274 * @param parse Parser object 1275 * @return Lclass of the current lem 1061 * @param parse Parser object. 1062 * @return Lclass of the current lem. 1276 1063 */ 1277 1064 lclass_t lcur_lc(parse_t *parse) … … 1294 1081 } 1295 1082 1296 /** Return coordinate span of current lem.1297 *1298 * @param parse Parser object1299 * @return Coordinate span of current lem or @c NULL if a1300 * parse error is active1301 */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 object1316 * @return Coordinate span of previous lem or @c NULL if1317 * parse error is active or previous lem is not1318 * 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 1334 1083 /** Skip to next lem. 1335 1084 * … … 1421 1170 { 1422 1171 switch (lclass) { 1423 case lc_elif:1424 1172 case lc_else: 1425 1173 case lc_end:
Note:
See TracChangeset
for help on using the changeset viewer.