| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of js; | 5 part of js; |
| 6 | 6 |
| 7 abstract class NodeVisitor<T> { | 7 abstract class NodeVisitor<T> { |
| 8 T visitProgram(Program node); | 8 T visitProgram(Program node); |
| 9 | 9 |
| 10 T visitBlock(Block node); | 10 T visitBlock(Block node); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 T visitVariableInitialization(VariableInitialization node) { | 118 T visitVariableInitialization(VariableInitialization node) { |
| 119 if (node.value != null) { | 119 if (node.value != null) { |
| 120 return visitAssignment(node); | 120 return visitAssignment(node); |
| 121 } else { | 121 } else { |
| 122 return visitExpression(node); | 122 return visitExpression(node); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 T visitConditional(Conditional node) => visitExpression(node); | 125 T visitConditional(Conditional node) => visitExpression(node); |
| 126 T visitNew(New node) => visitExpression(node); | 126 T visitNew(New node) => visitExpression(node); |
| 127 T visitCall(Call node) => visitExpression(node); | 127 T visitCall(Call node) => visitExpression(node); |
| 128 T visitBinary(Binary node) => visitCall(node); | 128 T visitBinary(Binary node) => visitExpression(node); |
| 129 T visitPrefix(Prefix node) => visitCall(node); | 129 T visitPrefix(Prefix node) => visitExpression(node); |
| 130 T visitPostfix(Postfix node) => visitCall(node); | 130 T visitPostfix(Postfix node) => visitExpression(node); |
| 131 T visitAccess(PropertyAccess node) => visitExpression(node); | 131 T visitAccess(PropertyAccess node) => visitExpression(node); |
| 132 | 132 |
| 133 T visitVariableUse(VariableUse node) => visitVariableReference(node); | 133 T visitVariableUse(VariableUse node) => visitVariableReference(node); |
| 134 T visitVariableDeclaration(VariableDeclaration node) | 134 T visitVariableDeclaration(VariableDeclaration node) |
| 135 => visitVariableReference(node); | 135 => visitVariableReference(node); |
| 136 T visitParameter(Parameter node) => visitVariableDeclaration(node); | 136 T visitParameter(Parameter node) => visitVariableDeclaration(node); |
| 137 T visitThis(This node) => visitParameter(node); | 137 T visitThis(This node) => visitParameter(node); |
| 138 | 138 |
| 139 T visitNamedFunction(NamedFunction node) => visitExpression(node); | 139 T visitNamedFunction(NamedFunction node) => visitExpression(node); |
| 140 T visitFun(Fun node) => visitExpression(node); | 140 T visitFun(Fun node) => visitExpression(node); |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 for (Expression expr in expressions) expr.accept(visitor); | 612 for (Expression expr in expressions) expr.accept(visitor); |
| 613 } | 613 } |
| 614 | 614 |
| 615 Sequence _clone() => new Sequence(expressions); | 615 Sequence _clone() => new Sequence(expressions); |
| 616 | 616 |
| 617 int get precedenceLevel => EXPRESSION; | 617 int get precedenceLevel => EXPRESSION; |
| 618 } | 618 } |
| 619 | 619 |
| 620 class Assignment extends Expression { | 620 class Assignment extends Expression { |
| 621 final Expression leftHandSide; | 621 final Expression leftHandSide; |
| 622 // Null, if the assignment is not compound. | 622 final String op; // Null, if the assignment is not compound. |
| 623 final VariableReference compoundTarget; | |
| 624 final Expression value; // May be null, for [VariableInitialization]s. | 623 final Expression value; // May be null, for [VariableInitialization]s. |
| 625 | 624 |
| 626 Assignment(leftHandSide, value) | 625 Assignment(leftHandSide, value) |
| 627 : this._internal(leftHandSide, null, value); | 626 : this.compound(leftHandSide, null, value); |
| 628 Assignment.compound(leftHandSide, String op, value) | 627 Assignment.compound(this.leftHandSide, this.op, this.value); |
| 629 : this._internal(leftHandSide, new VariableUse(op), value); | |
| 630 Assignment._internal(this.leftHandSide, this.compoundTarget, this.value); | |
| 631 | 628 |
| 632 int get precedenceLevel => ASSIGNMENT; | 629 int get precedenceLevel => ASSIGNMENT; |
| 633 | 630 |
| 634 bool get isCompound => compoundTarget != null; | 631 bool get isCompound => op != null; |
| 635 String get op => compoundTarget == null ? null : compoundTarget.name; | |
| 636 | 632 |
| 637 accept(NodeVisitor visitor) => visitor.visitAssignment(this); | 633 accept(NodeVisitor visitor) => visitor.visitAssignment(this); |
| 638 | 634 |
| 639 void visitChildren(NodeVisitor visitor) { | 635 void visitChildren(NodeVisitor visitor) { |
| 640 leftHandSide.accept(visitor); | 636 leftHandSide.accept(visitor); |
| 641 if (compoundTarget != null) compoundTarget.accept(visitor); | |
| 642 if (value != null) value.accept(visitor); | 637 if (value != null) value.accept(visitor); |
| 643 } | 638 } |
| 644 | 639 |
| 645 Assignment _clone() => | 640 Assignment _clone() => |
| 646 new Assignment._internal(leftHandSide, compoundTarget, value); | 641 new Assignment.compound(leftHandSide, op, value); |
| 647 } | 642 } |
| 648 | 643 |
| 649 class VariableInitialization extends Assignment { | 644 class VariableInitialization extends Assignment { |
| 650 /** [value] may be null. */ | 645 /** [value] may be null. */ |
| 651 VariableInitialization(VariableDeclaration declaration, Expression value) | 646 VariableInitialization(VariableDeclaration declaration, Expression value) |
| 652 : super(declaration, value); | 647 : super(declaration, value); |
| 653 | 648 |
| 654 VariableDeclaration get declaration => leftHandSide; | 649 VariableDeclaration get declaration => leftHandSide; |
| 655 | 650 |
| 656 accept(NodeVisitor visitor) => visitor.visitVariableInitialization(this); | 651 accept(NodeVisitor visitor) => visitor.visitVariableInitialization(this); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 } | 693 } |
| 699 | 694 |
| 700 class New extends Call { | 695 class New extends Call { |
| 701 New(Expression cls, List<Expression> arguments) : super(cls, arguments); | 696 New(Expression cls, List<Expression> arguments) : super(cls, arguments); |
| 702 | 697 |
| 703 accept(NodeVisitor visitor) => visitor.visitNew(this); | 698 accept(NodeVisitor visitor) => visitor.visitNew(this); |
| 704 | 699 |
| 705 New _clone() => new New(target, arguments); | 700 New _clone() => new New(target, arguments); |
| 706 } | 701 } |
| 707 | 702 |
| 708 class Binary extends Call { | 703 class Binary extends Expression { |
| 709 Binary(String op, Expression left, Expression right) | 704 final String op; |
| 710 : this._internal(new VariableUse(op), <Expression>[left, right]); | 705 final Expression left; |
| 706 final Expression right; |
| 711 | 707 |
| 712 Binary._internal(Expression target, List<Expression> arguments) | 708 Binary(this.op, this.left, this.right); |
| 713 : super(target, arguments); | |
| 714 | |
| 715 String get op { | |
| 716 VariableUse use = target; | |
| 717 return use.name; | |
| 718 } | |
| 719 | |
| 720 Expression get left => arguments[0]; | |
| 721 Expression get right => arguments[1]; | |
| 722 | 709 |
| 723 accept(NodeVisitor visitor) => visitor.visitBinary(this); | 710 accept(NodeVisitor visitor) => visitor.visitBinary(this); |
| 724 | 711 |
| 725 Binary _clone() => new Binary._internal(target, arguments); | 712 Binary _clone() => new Binary(op, left, right); |
| 713 |
| 714 void visitChildren(NodeVisitor visitor) { |
| 715 left.accept(visitor); |
| 716 right.accept(visitor); |
| 717 } |
| 726 | 718 |
| 727 int get precedenceLevel { | 719 int get precedenceLevel { |
| 728 // TODO(floitsch): switch to constant map. | 720 // TODO(floitsch): switch to constant map. |
| 729 switch (op) { | 721 switch (op) { |
| 730 case "*": | 722 case "*": |
| 731 case "/": | 723 case "/": |
| 732 case "%": | 724 case "%": |
| 733 return MULTIPLICATIVE; | 725 return MULTIPLICATIVE; |
| 734 case "+": | 726 case "+": |
| 735 case "-": | 727 case "-": |
| (...skipping 26 matching lines...) Expand all Loading... |
| 762 return LOGICAL_OR; | 754 return LOGICAL_OR; |
| 763 case ',': | 755 case ',': |
| 764 return EXPRESSION; | 756 return EXPRESSION; |
| 765 default: | 757 default: |
| 766 throw new leg.CompilerCancelledException( | 758 throw new leg.CompilerCancelledException( |
| 767 "Internal Error: Unhandled binary operator: $op"); | 759 "Internal Error: Unhandled binary operator: $op"); |
| 768 } | 760 } |
| 769 } | 761 } |
| 770 } | 762 } |
| 771 | 763 |
| 772 class Prefix extends Call { | 764 class Prefix extends Expression { |
| 773 Prefix(String op, Expression arg) | 765 final String op; |
| 774 : this._internal(new VariableUse(op), <Expression>[arg]); | 766 final Expression argument; |
| 775 | 767 |
| 776 Prefix._internal(Expression target, List<Expression> arguments) | 768 Prefix(this.op, this.argument); |
| 777 : super(target, arguments); | |
| 778 | |
| 779 String get op => (target as VariableUse).name; | |
| 780 Expression get argument => arguments[0]; | |
| 781 | 769 |
| 782 accept(NodeVisitor visitor) => visitor.visitPrefix(this); | 770 accept(NodeVisitor visitor) => visitor.visitPrefix(this); |
| 783 | 771 |
| 784 Prefix _clone() => new Prefix._internal(target, arguments); | 772 Prefix _clone() => new Prefix(op, argument); |
| 773 |
| 774 void visitChildren(NodeVisitor visitor) { |
| 775 argument.accept(visitor); |
| 776 } |
| 785 | 777 |
| 786 int get precedenceLevel => UNARY; | 778 int get precedenceLevel => UNARY; |
| 787 } | 779 } |
| 788 | 780 |
| 789 class Postfix extends Call { | 781 class Postfix extends Expression { |
| 790 Postfix(String op, Expression arg) | 782 final String op; |
| 791 : this._internal(new VariableUse(op), <Expression>[arg]); | 783 final Expression argument; |
| 792 | 784 |
| 793 Postfix._internal(Expression target, List<Expression> arguments) | 785 Postfix(this.op, this.argument); |
| 794 : super(target, arguments); | |
| 795 | |
| 796 String get op => (target as VariableUse).name; | |
| 797 Expression get argument => arguments[0]; | |
| 798 | 786 |
| 799 accept(NodeVisitor visitor) => visitor.visitPostfix(this); | 787 accept(NodeVisitor visitor) => visitor.visitPostfix(this); |
| 800 | 788 |
| 801 Postfix _clone() => new Postfix._internal(target, arguments); | 789 Postfix _clone() => new Postfix(op, argument); |
| 790 |
| 791 void visitChildren(NodeVisitor visitor) { |
| 792 argument.accept(visitor); |
| 793 } |
| 794 |
| 802 | 795 |
| 803 int get precedenceLevel => UNARY; | 796 int get precedenceLevel => UNARY; |
| 804 } | 797 } |
| 805 | 798 |
| 806 abstract class VariableReference extends Expression { | 799 abstract class VariableReference extends Expression { |
| 807 final String name; | 800 final String name; |
| 808 | 801 |
| 809 // We treat operators as if they were special functions. They can thus be | 802 // We treat operators as if they were special functions. They can thus be |
| 810 // referenced like other variables. | 803 // referenced like other variables. |
| 811 VariableReference(this.name); | 804 VariableReference(this.name); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 class Comment extends Statement { | 1123 class Comment extends Statement { |
| 1131 final String comment; | 1124 final String comment; |
| 1132 | 1125 |
| 1133 Comment(this.comment); | 1126 Comment(this.comment); |
| 1134 | 1127 |
| 1135 accept(NodeVisitor visitor) => visitor.visitComment(this); | 1128 accept(NodeVisitor visitor) => visitor.visitComment(this); |
| 1136 Comment _clone() => new Comment(comment); | 1129 Comment _clone() => new Comment(comment); |
| 1137 | 1130 |
| 1138 void visitChildren(NodeVisitor visitor) {} | 1131 void visitChildren(NodeVisitor visitor) {} |
| 1139 } | 1132 } |
| OLD | NEW |