comparison parser/Parser.d @ 150:6c5a3c0bb4fb

Make switch work again Also added locations to statements (only filled out for switch) Added a verification pass Removed some comments
author Anders Halager <halager@gmail.com>
date Mon, 21 Jul 2008 20:35:03 +0200
parents 8c09fdaa724e
children aeeef0dea14e
comparison
equal deleted inserted replaced
147:060b6eb16db9 150:6c5a3c0bb4fb
630 // Expression: a.b, a = b, a(b) etc. 630 // Expression: a.b, a = b, a(b) etc.
631 Exp exp = parseExpression(); 631 Exp exp = parseExpression();
632 require(Tok.Seperator); 632 require(Tok.Seperator);
633 return action.actOnExprStmt(exp); 633 return action.actOnExprStmt(exp);
634 } 634 }
635 else if(t.isSwitch) 635 else if (t.isSwitch)
636 { 636 {
637 next; 637 next();
638 require(Tok.OpenParentheses); 638 require(Tok.OpenParentheses);
639 auto target = parseExpression(); 639 auto target = parseExpression();
640 auto res = action.actOnStartOfSwitchStmt(target); 640 auto res = action.actOnStartOfSwitchStmt(t, target);
641 require(Tok.CloseParentheses); 641 require(Tok.CloseParentheses);
642 require(Tok.OpenBrace); 642 require(Tok.OpenBrace);
643 while (true) 643 while (true)
644 { 644 {
645 Stmt[] statements; 645 Stmt[] statements;
646 if (skip(Tok.Default)) 646 if (isa(Tok.Default))
647 { 647 {
648 Token _default = next();
648 require(Tok.Colon); 649 require(Tok.Colon);
649 statements.length = 0; 650 statements.length = 0;
650 while (peek.type != Tok.Case 651 while (peek.type != Tok.Case
651 && peek.type != Tok.Default 652 && peek.type != Tok.Default
652 && peek.type != Tok.CloseBrace) 653 && peek.type != Tok.CloseBrace)
653 statements ~= parseStatement(); 654 statements ~= parseStatement();
654 action.actOnDefaultStmt(res, statements); 655 action.actOnDefaultStmt(res, _default, statements);
655 continue; 656 continue;
656 } 657 }
657 658
658 Token _case = peek; 659 Token _case = peek;
659 if (_case.type != Tok.Case) 660 if (_case.type != Tok.Case)
662 663
663 Exp[] literals; 664 Exp[] literals;
664 do 665 do
665 { 666 {
666 Exp e = parseExpression(); 667 Exp e = parseExpression();
667 // IntegerLit lit = cast(IntegerLit)e;
668 // if (lit is null)
669 // messages.report(CaseValueMustBeInt, peek.location).arg(next.getType);
670 // else
671 literals ~= e; 668 literals ~= e;
672 } 669 }
673 while (skip(Tok.Comma)); 670 while (skip(Tok.Comma));
674 require(Tok.Colon); 671 require(Tok.Colon);
675 672
676 while (peek.type != Tok.Case 673 while (peek.type != Tok.Case
677 && peek.type != Tok.Default 674 && peek.type != Tok.Default
678 && peek.type != Tok.CloseBrace) 675 && peek.type != Tok.CloseBrace)
679 statements ~= parseStatement(); 676 statements ~= parseStatement();
680 677
681 action.actOnCaseStmt(res, literals, statements); 678 action.actOnCaseStmt(res, _case, literals, statements);
682 679
683 if (peek.type == Tok.CloseBrace) 680 if (peek.type == Tok.CloseBrace)
684 break; 681 break;
685 } 682 }
686 require(Tok.CloseBrace); 683 require(Tok.CloseBrace);