| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // IrNodes are kept in a separate library to have precise control over their | 5 // IrNodes are kept in a separate library to have precise control over their |
| 6 // dependencies on other parts of the system. | 6 // dependencies on other parts of the system. |
| 7 library dart2js.ir_nodes; | 7 library dart2js.ir_nodes; |
| 8 | 8 |
| 9 import '../dart2jslib.dart' as dart2js show Constant, ConstructedConstant, | 9 import '../dart2jslib.dart' as dart2js show Constant, ConstructedConstant, |
| 10 StringConstant, ListConstant, MapConstant; | 10 StringConstant, ListConstant, MapConstant; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 : continuation = new Reference(cont), | 230 : continuation = new Reference(cont), |
| 231 arguments = _referenceList(args) { | 231 arguments = _referenceList(args) { |
| 232 assert(target.isErroneous || target.isConstructor); | 232 assert(target.isErroneous || target.isConstructor); |
| 233 assert(target.isErroneous || type.isDynamic || | 233 assert(target.isErroneous || type.isDynamic || |
| 234 type.element == target.enclosingElement); | 234 type.element == target.enclosingElement); |
| 235 } | 235 } |
| 236 | 236 |
| 237 accept(Visitor visitor) => visitor.visitInvokeConstructor(this); | 237 accept(Visitor visitor) => visitor.visitInvokeConstructor(this); |
| 238 } | 238 } |
| 239 | 239 |
| 240 class AsCast extends Expression { | 240 /// "as" casts and "is" checks. |
| 241 // We might want to turn "is"-checks into a [Primitive] as it can never diverge. |
| 242 // But then we need to special-case for is-checks with an erroneous .type as |
| 243 // these will throw. |
| 244 class TypeOperator extends Expression { |
| 241 final Reference receiver; | 245 final Reference receiver; |
| 242 final DartType type; | 246 final DartType type; |
| 243 final Reference continuation; | 247 final Reference continuation; |
| 248 final String operator; |
| 244 | 249 |
| 245 AsCast(Primitive receiver, this.type, Continuation cont) | 250 TypeOperator(this.operator, |
| 251 Primitive receiver, |
| 252 this.type, |
| 253 Continuation cont) |
| 246 : this.receiver = new Reference(receiver), | 254 : this.receiver = new Reference(receiver), |
| 247 this.continuation = new Reference(cont); | 255 this.continuation = new Reference(cont) { |
| 256 assert(operator == "is" || operator == "as"); |
| 257 } |
| 248 | 258 |
| 249 accept(Visitor visitor) => visitor.visitAsCast(this); | 259 accept(Visitor visitor) => visitor.visitTypeOperator(this); |
| 250 } | 260 } |
| 251 | 261 |
| 252 /// Invoke [toString] on each argument and concatenate the results. | 262 /// Invoke [toString] on each argument and concatenate the results. |
| 253 class ConcatenateStrings extends Expression { | 263 class ConcatenateStrings extends Expression { |
| 254 final Reference continuation; | 264 final Reference continuation; |
| 255 final List<Reference> arguments; | 265 final List<Reference> arguments; |
| 256 | 266 |
| 257 ConcatenateStrings(Continuation cont, List<Definition> args) | 267 ConcatenateStrings(Continuation cont, List<Definition> args) |
| 258 : continuation = new Reference(cont), | 268 : continuation = new Reference(cont), |
| 259 arguments = _referenceList(args); | 269 arguments = _referenceList(args); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 | 450 |
| 441 /// Create a non-recursive function. | 451 /// Create a non-recursive function. |
| 442 class CreateFunction extends Primitive { | 452 class CreateFunction extends Primitive { |
| 443 final FunctionDefinition definition; | 453 final FunctionDefinition definition; |
| 444 | 454 |
| 445 CreateFunction(this.definition); | 455 CreateFunction(this.definition); |
| 446 | 456 |
| 447 accept(Visitor visitor) => visitor.visitCreateFunction(this); | 457 accept(Visitor visitor) => visitor.visitCreateFunction(this); |
| 448 } | 458 } |
| 449 | 459 |
| 450 class IsCheck extends Primitive { | |
| 451 final Reference receiver; | |
| 452 final DartType type; | |
| 453 | |
| 454 dart2js.Constant get constant => null; | |
| 455 | |
| 456 IsCheck(Primitive receiver, this.type) | |
| 457 : this.receiver = new Reference(receiver); | |
| 458 | |
| 459 accept(Visitor visitor) => visitor.visitIsCheck(this); | |
| 460 } | |
| 461 | |
| 462 class Parameter extends Primitive { | 460 class Parameter extends Primitive { |
| 463 Parameter(Element element) { | 461 Parameter(Element element) { |
| 464 super.hint = element; | 462 super.hint = element; |
| 465 } | 463 } |
| 466 | 464 |
| 467 accept(Visitor visitor) => visitor.visitParameter(this); | 465 accept(Visitor visitor) => visitor.visitParameter(this); |
| 468 } | 466 } |
| 469 | 467 |
| 470 /// Continuations are normally bound by 'let cont'. A continuation with no | 468 /// Continuations are normally bound by 'let cont'. A continuation with no |
| 471 /// parameter (or body) is used to represent a function's return continuation. | 469 /// parameter (or body) is used to represent a function's return continuation. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 // Expressions. | 520 // Expressions. |
| 523 T visitLetPrim(LetPrim node) => visitExpression(node); | 521 T visitLetPrim(LetPrim node) => visitExpression(node); |
| 524 T visitLetCont(LetCont node) => visitExpression(node); | 522 T visitLetCont(LetCont node) => visitExpression(node); |
| 525 T visitInvokeStatic(InvokeStatic node) => visitExpression(node); | 523 T visitInvokeStatic(InvokeStatic node) => visitExpression(node); |
| 526 T visitInvokeContinuation(InvokeContinuation node) => visitExpression(node); | 524 T visitInvokeContinuation(InvokeContinuation node) => visitExpression(node); |
| 527 T visitInvokeMethod(InvokeMethod node) => visitExpression(node); | 525 T visitInvokeMethod(InvokeMethod node) => visitExpression(node); |
| 528 T visitInvokeSuperMethod(InvokeSuperMethod node) => visitExpression(node); | 526 T visitInvokeSuperMethod(InvokeSuperMethod node) => visitExpression(node); |
| 529 T visitInvokeConstructor(InvokeConstructor node) => visitExpression(node); | 527 T visitInvokeConstructor(InvokeConstructor node) => visitExpression(node); |
| 530 T visitConcatenateStrings(ConcatenateStrings node) => visitExpression(node); | 528 T visitConcatenateStrings(ConcatenateStrings node) => visitExpression(node); |
| 531 T visitBranch(Branch node) => visitExpression(node); | 529 T visitBranch(Branch node) => visitExpression(node); |
| 532 T visitAsCast(AsCast node) => visitExpression(node); | 530 T visitTypeOperator(TypeOperator node) => visitExpression(node); |
| 533 T visitSetClosureVariable(SetClosureVariable node) => visitExpression(node); | 531 T visitSetClosureVariable(SetClosureVariable node) => visitExpression(node); |
| 534 T visitDeclareFunction(DeclareFunction node) => visitExpression(node); | 532 T visitDeclareFunction(DeclareFunction node) => visitExpression(node); |
| 535 | 533 |
| 536 // Definitions. | 534 // Definitions. |
| 537 T visitLiteralList(LiteralList node) => visitPrimitive(node); | 535 T visitLiteralList(LiteralList node) => visitPrimitive(node); |
| 538 T visitLiteralMap(LiteralMap node) => visitPrimitive(node); | 536 T visitLiteralMap(LiteralMap node) => visitPrimitive(node); |
| 539 T visitIsCheck(IsCheck node) => visitPrimitive(node); | |
| 540 T visitConstant(Constant node) => visitPrimitive(node); | 537 T visitConstant(Constant node) => visitPrimitive(node); |
| 541 T visitThis(This node) => visitPrimitive(node); | 538 T visitThis(This node) => visitPrimitive(node); |
| 542 T visitReifyTypeVar(ReifyTypeVar node) => visitPrimitive(node); | 539 T visitReifyTypeVar(ReifyTypeVar node) => visitPrimitive(node); |
| 543 T visitCreateFunction(CreateFunction node) => visitPrimitive(node); | 540 T visitCreateFunction(CreateFunction node) => visitPrimitive(node); |
| 544 T visitGetClosureVariable(GetClosureVariable node) => visitPrimitive(node); | 541 T visitGetClosureVariable(GetClosureVariable node) => visitPrimitive(node); |
| 545 T visitParameter(Parameter node) => visitPrimitive(node); | 542 T visitParameter(Parameter node) => visitPrimitive(node); |
| 546 T visitContinuation(Continuation node) => visitDefinition(node); | 543 T visitContinuation(Continuation node) => visitDefinition(node); |
| 547 | 544 |
| 548 // Conditions. | 545 // Conditions. |
| 549 T visitIsTrue(IsTrue node) => visitCondition(node); | 546 T visitIsTrue(IsTrue node) => visitCondition(node); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 | 777 |
| 781 void visitLetCont(LetCont node) { | 778 void visitLetCont(LetCont node) { |
| 782 visit(node.continuation); | 779 visit(node.continuation); |
| 783 visit(node.body); | 780 visit(node.body); |
| 784 } | 781 } |
| 785 | 782 |
| 786 void visitInvokeStatic(InvokeStatic node) { | 783 void visitInvokeStatic(InvokeStatic node) { |
| 787 node.arguments.forEach(visitReference); | 784 node.arguments.forEach(visitReference); |
| 788 } | 785 } |
| 789 | 786 |
| 790 void visitAsCast(AsCast node) { | |
| 791 visitReference(node.receiver); | |
| 792 } | |
| 793 | |
| 794 void visitInvokeContinuation(InvokeContinuation node) { | 787 void visitInvokeContinuation(InvokeContinuation node) { |
| 795 node.arguments.forEach(visitReference); | 788 node.arguments.forEach(visitReference); |
| 796 } | 789 } |
| 797 | 790 |
| 798 void visitInvokeMethod(InvokeMethod node) { | 791 void visitInvokeMethod(InvokeMethod node) { |
| 799 visitReference(node.receiver); | 792 visitReference(node.receiver); |
| 800 node.arguments.forEach(visitReference); | 793 node.arguments.forEach(visitReference); |
| 801 } | 794 } |
| 802 | 795 |
| 803 void visitInvokeSuperMethod(InvokeSuperMethod node) { | 796 void visitInvokeSuperMethod(InvokeSuperMethod node) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 820 node.values.forEach(visitReference); | 813 node.values.forEach(visitReference); |
| 821 } | 814 } |
| 822 | 815 |
| 823 void visitLiteralMap(LiteralMap node) { | 816 void visitLiteralMap(LiteralMap node) { |
| 824 for (int i = 0; i < node.keys.length; ++i) { | 817 for (int i = 0; i < node.keys.length; ++i) { |
| 825 visitReference(node.keys[i]); | 818 visitReference(node.keys[i]); |
| 826 visitReference(node.values[i]); | 819 visitReference(node.values[i]); |
| 827 } | 820 } |
| 828 } | 821 } |
| 829 | 822 |
| 830 void visitIsCheck(IsCheck node) { | 823 void visitTypeOperator(TypeOperator node) { |
| 831 visitReference(node.receiver); | 824 visitReference(node.receiver); |
| 832 } | 825 } |
| 833 | 826 |
| 834 void visitConstant(Constant node) { | 827 void visitConstant(Constant node) { |
| 835 } | 828 } |
| 836 | 829 |
| 837 void visitThis(This node) { | 830 void visitThis(This node) { |
| 838 } | 831 } |
| 839 | 832 |
| 840 void visitReifyTypeVar(ReifyTypeVar node) { | 833 void visitReifyTypeVar(ReifyTypeVar node) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 870 for (int i = node.parameters.length - 1; i >= 0; --i) { | 863 for (int i = node.parameters.length - 1; i >= 0; --i) { |
| 871 release(node.parameters[i]); | 864 release(node.parameters[i]); |
| 872 } | 865 } |
| 873 } | 866 } |
| 874 | 867 |
| 875 void visitIsTrue(IsTrue node) { | 868 void visitIsTrue(IsTrue node) { |
| 876 visitReference(node.value); | 869 visitReference(node.value); |
| 877 } | 870 } |
| 878 | 871 |
| 879 } | 872 } |
| OLD | NEW |