Changeset 78d3a00 in mainline for uspace/app/bithenge/script.c
- Timestamp:
- 2012-07-31T21:07:26Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3f2ea63
- Parents:
- 20ac1a4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bithenge/script.c
r20ac1a4 r78d3a00 62 62 TOKEN_IF, 63 63 TOKEN_STRUCT, 64 TOKEN_SWITCH, 64 65 TOKEN_TRANSFORM, 65 66 TOKEN_TRUE, … … 219 220 } else if (!str_cmp(value, "struct")) { 220 221 state->token = TOKEN_STRUCT; 222 free(value); 223 } else if (!str_cmp(value, "switch")) { 224 state->token = TOKEN_SWITCH; 221 225 free(value); 222 226 } else if (!str_cmp(value, "transform")) { … … 548 552 } 549 553 554 static bithenge_transform_t *parse_switch(state_t *state, bool in_struct) 555 { 556 expect(state, TOKEN_SWITCH); 557 expect(state, '('); 558 bithenge_expression_t *ref_expr = parse_expression(state); 559 expect(state, ')'); 560 expect(state, '{'); 561 int num = 0; 562 bithenge_expression_t **exprs = NULL; 563 bithenge_transform_t **xforms = NULL; 564 while (state->error == EOK && state->token != '}') { 565 bithenge_expression_t *expr; 566 if (state->token == TOKEN_ELSE) { 567 next_token(state); 568 bithenge_node_t *node; 569 int rc = bithenge_new_boolean_node(&node, true); 570 if (rc != EOK) { 571 error_errno(state, rc); 572 break; 573 } 574 rc = bithenge_const_expression(&expr, node); 575 if (rc != EOK) { 576 error_errno(state, rc); 577 break; 578 } 579 } else { 580 expr = parse_expression(state); 581 if (state->error == EOK) { 582 bithenge_expression_inc_ref(ref_expr); 583 int rc = bithenge_binary_expression(&expr, 584 BITHENGE_EXPRESSION_EQUALS, ref_expr, 585 expr); 586 if (rc != EOK) { 587 error_errno(state, rc); 588 break; 589 } 590 } 591 } 592 593 expect(state, ':'); 594 bithenge_transform_t *xform; 595 if (in_struct) { 596 expect(state, '{'); 597 xform = parse_struct(state); 598 expect(state, '}'); 599 } else 600 xform = parse_transform(state); 601 expect(state, ';'); 602 603 exprs = state_realloc(state, exprs, 604 sizeof(*exprs) * (num + 1)); 605 xforms = state_realloc(state, xforms, 606 sizeof(*xforms) * (num + 1)); 607 if (state->error != EOK) { 608 bithenge_expression_dec_ref(expr); 609 bithenge_transform_dec_ref(xform); 610 break; 611 } 612 613 exprs[num] = expr; 614 xforms[num] = xform; 615 num++; 616 } 617 bithenge_expression_dec_ref(ref_expr); 618 619 bithenge_transform_t *switch_xform = &bithenge_invalid_transform; 620 bithenge_transform_inc_ref(switch_xform); 621 while (state->error == EOK && num >= 1) { 622 num--; 623 int rc = bithenge_if_transform(&switch_xform, exprs[num], 624 xforms[num], switch_xform); 625 if (rc != EOK) 626 error_errno(state, rc); 627 } 628 629 while (num >= 1) { 630 num--; 631 bithenge_expression_dec_ref(exprs[num]); 632 bithenge_transform_dec_ref(xforms[num]); 633 } 634 free(exprs); 635 free(xforms); 636 637 expect(state, '}'); 638 return switch_xform; 639 } 640 550 641 /* The TOKEN_STRUCT and '{' must already have been skipped. */ 551 642 static bithenge_transform_t *parse_struct(state_t *state) … … 558 649 if (state->token == TOKEN_IF) { 559 650 subxforms[num].transform = parse_if(state, true); 651 subxforms[num].name = NULL; 652 } else if (state->token == TOKEN_SWITCH) { 653 subxforms[num].transform = parse_switch(state, true); 560 654 subxforms[num].name = NULL; 561 655 } else { … … 609 703 expect(state, '}'); 610 704 return xform; 705 } else if (state->token == TOKEN_SWITCH) { 706 return parse_switch(state, false); 611 707 } else { 612 708 syntax_error(state, "unexpected (transform expected)");
Note:
See TracChangeset
for help on using the changeset viewer.