Changes in uspace/app/sbi/src/parse.c [c5cb943d:051bc69a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/parse.c
rc5cb943d r051bc69a 35 35 #include <assert.h> 36 36 #include <stdlib.h> 37 #include "cspan.h"38 37 #include "debug.h" 39 38 #include "lex.h" … … 65 64 static stree_prop_t *parse_prop(parse_t *parse, stree_csi_t *outer_csi); 66 65 67 static void parse_symbol_attrs(parse_t *parse, stree_symbol_t *symbol);68 66 static stree_symbol_attr_t *parse_symbol_attr(parse_t *parse); 69 67 … … 72 70 static stree_fun_sig_t *parse_fun_sig(parse_t *parse); 73 71 74 static void parse_prop_get(parse_t *parse, stree_prop_t *prop);75 static void parse_prop_set(parse_t *parse, stree_prop_t *prop);76 72 77 73 /* … … 179 175 stree_ident_t *targ_name; 180 176 stree_targ_t *targ; 181 stree_texpr_t *pref;182 177 183 178 switch (dclass) { … … 217 212 /* Inheritance list */ 218 213 lskip(parse); 219 220 while (b_true) { 221 pref = parse_texpr(parse); 222 if (parse_is_error(parse)) 223 break; 224 225 list_append(&csi->inherit, pref); 226 if (lcur_lc(parse) != lc_plus) 227 break; 228 229 lskip(parse); 230 } 214 csi->base_csi_ref = parse_texpr(parse); 215 } else { 216 csi->base_csi_ref = NULL; 231 217 } 232 218 … … 238 224 csimbr = parse_csimbr(parse, csi); 239 225 if (csimbr == NULL) 240 continue;226 break; 241 227 242 228 list_append(&csi->members, csimbr); … … 244 230 245 231 lmatch(parse, lc_end); 246 247 if (outer_csi != NULL) {248 switch (outer_csi->cc) {249 case csi_class:250 case csi_struct:251 break;252 case csi_interface:253 cspan_print(csi->name->cspan);254 printf(" Error: CSI declared inside interface.\n");255 parse_note_error(parse);256 /* XXX Free csi */257 return NULL;258 }259 }260 232 261 233 return csi; … … 281 253 stree_prop_t *prop; 282 254 283 csimbr = NULL;284 285 255 switch (lcur_lc(parse)) { 286 256 case lc_class: … … 288 258 case lc_interface: 289 259 csi = parse_csi(parse, lcur_lc(parse), outer_csi); 290 if (csi != NULL) { 291 csimbr = stree_csimbr_new(csimbr_csi); 292 csimbr->u.csi = csi; 293 } 260 csimbr = stree_csimbr_new(csimbr_csi); 261 csimbr->u.csi = csi; 294 262 break; 295 263 case lc_new: 296 264 ctor = parse_ctor(parse, outer_csi); 297 if (ctor != NULL) { 298 csimbr = stree_csimbr_new(csimbr_ctor); 299 csimbr->u.ctor = ctor; 300 } 265 csimbr = stree_csimbr_new(csimbr_ctor); 266 csimbr->u.ctor = ctor; 301 267 break; 302 268 case lc_deleg: 303 269 deleg = parse_deleg(parse, outer_csi); 304 if (deleg != NULL) { 305 csimbr = stree_csimbr_new(csimbr_deleg); 306 csimbr->u.deleg = deleg; 307 } 270 csimbr = stree_csimbr_new(csimbr_deleg); 271 csimbr->u.deleg = deleg; 308 272 break; 309 273 case lc_enum: 310 274 enum_d = parse_enum(parse, outer_csi); 311 if (enum_d != NULL) { 312 csimbr = stree_csimbr_new(csimbr_enum); 313 csimbr->u.enum_d = enum_d; 314 } 275 csimbr = stree_csimbr_new(csimbr_enum); 276 csimbr->u.enum_d = enum_d; 315 277 break; 316 278 case lc_fun: … … 321 283 case lc_var: 322 284 var = parse_var(parse, outer_csi); 323 if (var != NULL) { 324 csimbr = stree_csimbr_new(csimbr_var); 325 csimbr->u.var = var; 326 } 285 csimbr = stree_csimbr_new(csimbr_var); 286 csimbr->u.var = var; 327 287 break; 328 288 case lc_prop: … … 334 294 lunexpected_error(parse); 335 295 lex_next(parse->lex); 296 csimbr = NULL; 336 297 break; 337 298 } … … 350 311 stree_ctor_t *ctor; 351 312 stree_symbol_t *symbol; 352 cspan_t *cspan;313 stree_symbol_attr_t *attr; 353 314 354 315 ctor = stree_ctor_new(); … … 360 321 361 322 lmatch(parse, lc_new); 362 cspan = lprev_span(parse);363 323 364 324 /* Fake identifier. */ … … 374 334 ctor->sig = parse_fun_sig(parse); 375 335 if (ctor->sig->rtype != NULL) { 376 cspan_print(cspan); 377 printf(" Error: Constructor of CSI '"); 336 printf("Error: Constructor of CSI '"); 378 337 symbol_print_fqn(csi_to_symbol(outer_csi)); 379 338 printf("' has a return type.\n"); … … 381 340 } 382 341 342 list_init(&symbol->attr); 343 383 344 /* Parse attributes. */ 384 parse_symbol_attrs(parse, symbol); 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 } 385 350 386 351 ctor->proc = stree_proc_new(); … … 391 356 392 357 /* This constructor has no body. */ 393 cspan_print(cspan); 394 printf(" Error: Constructor of CSI '"); 358 printf("Error: Constructor of CSI '"); 395 359 symbol_print_fqn(csi_to_symbol(outer_csi)); 396 360 printf("' has no body.\n"); … … 404 368 } 405 369 406 switch (outer_csi->cc) {407 case csi_class:408 case csi_struct:409 break;410 case csi_interface:411 cspan_print(ctor->name->cspan);412 printf(" Error: Constructor declared inside interface.\n");413 parse_note_error(parse);414 /* XXX Free ctor */415 return NULL;416 }417 418 370 return ctor; 419 371 } … … 457 409 458 410 if (list_is_empty(&enum_d->members)) { 459 cspan_print(enum_d->name->cspan);460 411 printf("Error: Enum type '%s' has no members.\n", 461 412 strtab_get_str(enum_d->name->sid)); … … 465 416 lmatch(parse, lc_end); 466 417 467 if (outer_csi != NULL) {468 switch (outer_csi->cc) {469 case csi_class:470 case csi_struct:471 break;472 case csi_interface:473 cspan_print(enum_d->name->cspan);474 printf(" Error: Enum declared inside interface.\n");475 parse_note_error(parse);476 /* XXX Free enum */477 return NULL;478 }479 }480 481 418 return enum_d; 482 419 } … … 512 449 stree_deleg_t *deleg; 513 450 stree_symbol_t *symbol; 451 stree_symbol_attr_t *attr; 514 452 515 453 deleg = stree_deleg_new(); … … 529 467 deleg->sig = parse_fun_sig(parse); 530 468 469 list_init(&symbol->attr); 470 531 471 /* Parse attributes. */ 532 parse_symbol_attrs(parse, symbol); 472 while (lcur_lc(parse) == lc_comma && !parse_is_error(parse)) { 473 lskip(parse); 474 attr = parse_symbol_attr(parse); 475 list_append(&symbol->attr, attr); 476 } 533 477 534 478 lmatch(parse, lc_scolon); 535 536 switch (outer_csi->cc) {537 case csi_class:538 case csi_struct:539 break;540 case csi_interface:541 cspan_print(deleg->name->cspan);542 printf(" Error: Delegate declared inside interface.\n");543 parse_note_error(parse);544 /* XXX Free deleg */545 return NULL;546 }547 479 548 480 return deleg; … … 559 491 stree_fun_t *fun; 560 492 stree_symbol_t *symbol; 561 bool_t body_expected;493 stree_symbol_attr_t *attr; 562 494 563 495 fun = stree_fun_new(); … … 576 508 fun->sig = parse_fun_sig(parse); 577 509 510 list_init(&symbol->attr); 511 578 512 /* Parse attributes. */ 579 parse_symbol_attrs(parse, symbol); 580 581 body_expected = !stree_symbol_has_attr(symbol, sac_builtin) && 582 (outer_csi->cc != csi_interface); 513 while (lcur_lc(parse) == lc_comma && !parse_is_error(parse)) { 514 lskip(parse); 515 attr = parse_symbol_attr(parse); 516 list_append(&symbol->attr, attr); 517 } 583 518 584 519 fun->proc = stree_proc_new(); … … 588 523 lskip(parse); 589 524 590 /* Body not present */ 591 if (body_expected) { 592 cspan_print(fun->name->cspan); 593 printf(" Error: Function '"); 525 /* This function has no body. */ 526 if (!stree_symbol_has_attr(symbol, sac_builtin)) { 527 printf("Error: Function '"); 594 528 symbol_print_fqn(symbol); 595 printf("' should have abody.\n");529 printf("' has no body.\n"); 596 530 parse_note_error(parse); 597 531 } 598 599 532 fun->proc->body = NULL; 600 533 } else { … … 602 535 fun->proc->body = parse_block(parse); 603 536 lmatch(parse, lc_end); 604 605 /* Body present */606 if (!body_expected) {607 cspan_print(fun->name->cspan);608 printf(" Error: Function declaration '");609 symbol_print_fqn(symbol);610 printf("' should not have a body.\n");611 parse_note_error(parse);612 }613 537 } 614 538 … … 637 561 lmatch(parse, lc_colon); 638 562 var->type = parse_texpr(parse); 639 640 parse_symbol_attrs(parse, symbol);641 642 563 lmatch(parse, lc_scolon); 643 644 switch (outer_csi->cc) {645 case csi_class:646 case csi_struct:647 break;648 case csi_interface:649 cspan_print(var->name->cspan);650 printf(" Error: Variable declared inside interface.\n");651 parse_note_error(parse);652 /* XXX Free var */653 return NULL;654 }655 564 656 565 return var; … … 667 576 stree_prop_t *prop; 668 577 stree_symbol_t *symbol; 669 bool_t body_expected;670 578 671 579 stree_ident_t *ident; … … 717 625 lmatch(parse, lc_colon); 718 626 prop->type = parse_texpr(parse); 719 720 /* Parse attributes. */721 parse_symbol_attrs(parse, symbol);722 723 body_expected = (outer_csi->cc != csi_interface);724 725 627 lmatch(parse, lc_is); 726 628 … … 728 630 switch (lcur_lc(parse)) { 729 631 case lc_get: 730 parse_prop_get(parse, prop); 632 lskip(parse); 633 lmatch(parse, lc_is); 634 if (prop->getter != NULL) { 635 printf("Error: Duplicate getter.\n"); 636 (void) parse_block(parse); /* XXX Free */ 637 lmatch(parse, lc_end); 638 parse_note_error(parse); 639 break; 640 } 641 642 /* Create setter procedure */ 643 prop->getter = stree_proc_new(); 644 prop->getter->body = parse_block(parse); 645 prop->getter->outer_symbol = symbol; 646 647 lmatch(parse, lc_end); 731 648 break; 732 649 case lc_set: 733 parse_prop_set(parse, prop); 650 lskip(parse); 651 prop->setter_arg = stree_proc_arg_new(); 652 prop->setter_arg->name = parse_ident(parse); 653 prop->setter_arg->type = prop->type; 654 lmatch(parse, lc_is); 655 if (prop->setter != NULL) { 656 printf("Error: Duplicate setter.\n"); 657 (void) parse_block(parse); /* XXX Free */ 658 lmatch(parse, lc_end); 659 parse_note_error(parse); 660 } 661 662 /* Create setter procedure */ 663 prop->setter = stree_proc_new(); 664 prop->setter->body = parse_block(parse); 665 prop->setter->outer_symbol = symbol; 666 667 lmatch(parse, lc_end); 734 668 break; 735 669 default: … … 743 677 } 744 678 745 /** Parse symbol attributes. 746 * 747 * Parse list of attributes and add them to @a symbol. 748 * 749 * @param parse Parser object 750 * @param symbol Symbol to add these attributes to 751 */ 752 static void parse_symbol_attrs(parse_t *parse, stree_symbol_t *symbol) 679 /** Parse symbol attribute. 680 * 681 * @param parse Parser object. 682 * @param outer_csi CSI containing this declaration or @c NULL if global. 683 * @return New syntax tree node. 684 */ 685 static stree_symbol_attr_t *parse_symbol_attr(parse_t *parse) 753 686 { 754 687 stree_symbol_attr_t *attr; 755 688 756 /* Parse attributes. */ 757 while (lcur_lc(parse) == lc_comma && !parse_is_error(parse)) { 758 lskip(parse); 759 attr = parse_symbol_attr(parse); 760 list_append(&symbol->attr, attr); 761 } 762 } 763 764 /** Parse symbol attribute. 765 * 766 * @param parse Parser object 767 * @return New syntax tree node 768 */ 769 static stree_symbol_attr_t *parse_symbol_attr(parse_t *parse) 770 { 771 stree_symbol_attr_t *attr; 772 symbol_attr_class_t sac; 773 774 /* Make compiler happy. */ 775 sac = 0; 776 777 switch (lcur_lc(parse)) { 778 case lc_builtin: sac = sac_builtin; break; 779 case lc_static: sac = sac_static; break; 780 default: 781 cspan_print(lcur_span(parse)); 782 printf(" Error: Unexpected attribute '"); 689 if (lcur_lc(parse) != lc_builtin) { 690 printf("Error: Unexpected attribute '"); 783 691 lem_print(lcur(parse)); 784 692 printf("'.\n"); 785 693 parse_note_error(parse); 786 break;787 694 } 788 695 789 696 lskip(parse); 790 697 791 attr = stree_symbol_attr_new(sac );698 attr = stree_symbol_attr_new(sac_builtin); 792 699 return attr; 793 700 } … … 811 718 printf("Parse procedure argument.\n"); 812 719 #endif 813 list_init(&arg->attr);720 list_init(&arg->attr); 814 721 815 722 /* Parse attributes. */ … … 833 740 834 741 if (lcur_lc(parse) != lc_packed) { 835 cspan_print(lcur_span(parse)); 836 printf(" Error: Unexpected attribute '"); 742 printf("Error: Unexpected attribute '"); 837 743 lem_print(lcur(parse)); 838 744 printf("'.\n"); … … 896 802 897 803 return sig; 898 }899 900 /** Parse member property getter.901 *902 * @param parse Parser object.903 * @param prop Property containing this declaration.904 */905 static void parse_prop_get(parse_t *parse, stree_prop_t *prop)906 {907 cspan_t *cspan;908 stree_block_t *block;909 stree_proc_t *getter;910 bool_t body_expected;911 912 body_expected = (prop->symbol->outer_csi->cc != csi_interface);913 914 lskip(parse);915 cspan = lprev_span(parse);916 917 if (prop->getter != NULL) {918 cspan_print(cspan);919 printf(" Error: Duplicate getter.\n");920 parse_note_error(parse);921 return;922 }923 924 if (lcur_lc(parse) == lc_scolon) {925 /* Body not present */926 lskip(parse);927 block = NULL;928 929 if (body_expected) {930 cspan_print(prop->name->cspan);931 printf(" Error: Property '");932 symbol_print_fqn(prop->symbol);933 printf("' getter should have "934 "a body.\n");935 parse_note_error(parse);936 }937 } else {938 /* Body present */939 lmatch(parse, lc_is);940 block = parse_block(parse);941 lmatch(parse, lc_end);942 943 if (!body_expected) {944 cspan_print(prop->name->cspan);945 printf(" Error: Property '");946 symbol_print_fqn(prop->symbol);947 printf("' getter declaration should "948 "not have a body.\n");949 parse_note_error(parse);950 951 /* XXX Free block */952 block = NULL;953 }954 }955 956 /* Create getter procedure */957 getter = stree_proc_new();958 getter->body = block;959 getter->outer_symbol = prop->symbol;960 961 /* Store getter in property. */962 prop->getter = getter;963 }964 965 966 /** Parse member property setter.967 *968 * @param parse Parser object.969 * @param prop Property containing this declaration.970 */971 static void parse_prop_set(parse_t *parse, stree_prop_t *prop)972 {973 cspan_t *cspan;974 stree_block_t *block;975 stree_proc_t *setter;976 bool_t body_expected;977 978 body_expected = (prop->symbol->outer_csi->cc != csi_interface);979 980 lskip(parse);981 cspan = lprev_span(parse);982 983 if (prop->setter != NULL) {984 cspan_print(cspan);985 printf(" Error: Duplicate setter.\n");986 parse_note_error(parse);987 return;988 }989 990 prop->setter_arg = stree_proc_arg_new();991 prop->setter_arg->name = parse_ident(parse);992 prop->setter_arg->type = prop->type;993 994 if (lcur_lc(parse) == lc_scolon) {995 /* Body not present */996 lskip(parse);997 998 block = NULL;999 1000 if (body_expected) {1001 cspan_print(prop->name->cspan);1002 printf(" Error: Property '");1003 symbol_print_fqn(prop->symbol);1004 printf("' setter should have "1005 "a body.\n");1006 parse_note_error(parse);1007 }1008 } else {1009 /* Body present */1010 lmatch(parse, lc_is);1011 block = parse_block(parse);1012 lmatch(parse, lc_end);1013 1014 if (!body_expected) {1015 cspan_print(prop->name->cspan);1016 printf(" Error: Property '");1017 symbol_print_fqn(prop->symbol);1018 printf("' setter declaration should "1019 "not have a body.\n");1020 parse_note_error(parse);1021 }1022 }1023 1024 1025 /* Create setter procedure */1026 setter = stree_proc_new();1027 setter->body = block;1028 setter->outer_symbol = prop->symbol;1029 1030 /* Store setter in property. */1031 prop->setter = setter;1032 804 } 1033 805
Note:
See TracChangeset
for help on using the changeset viewer.