| 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 library dart2js.ir_nodes; | 4 library dart2js.ir_nodes; |
| 5 | 5 |
| 6 import '../constants/values.dart' as values show ConstantValue; | 6 import '../constants/values.dart' as values show ConstantValue; |
| 7 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; | 7 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; |
| 8 import '../elements/elements.dart'; | 8 import '../elements/elements.dart'; |
| 9 import '../io/source_information.dart' show SourceInformation; | 9 import '../io/source_information.dart' show SourceInformation; |
| 10 import '../types/types.dart' show TypeMask; | 10 import '../types/types.dart' show TypeMask; |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 /// (e.g., in the translation of break and continue). | 647 /// (e.g., in the translation of break and continue). |
| 648 InvokeContinuation.uninitialized({this.isRecursive: false, | 648 InvokeContinuation.uninitialized({this.isRecursive: false, |
| 649 this.isEscapingTry: false}) | 649 this.isEscapingTry: false}) |
| 650 : continuation = null, | 650 : continuation = null, |
| 651 arguments = null, | 651 arguments = null, |
| 652 sourceInformation = null; | 652 sourceInformation = null; |
| 653 | 653 |
| 654 accept(Visitor visitor) => visitor.visitInvokeContinuation(this); | 654 accept(Visitor visitor) => visitor.visitInvokeContinuation(this); |
| 655 } | 655 } |
| 656 | 656 |
| 657 /// The base class of things which can be tested and branched on. | |
| 658 abstract class Condition extends Node { | |
| 659 } | |
| 660 | |
| 661 class IsTrue extends Condition { | |
| 662 final Reference<Primitive> value; | |
| 663 | |
| 664 IsTrue(Primitive val) : value = new Reference<Primitive>(val); | |
| 665 | |
| 666 accept(Visitor visitor) => visitor.visitIsTrue(this); | |
| 667 } | |
| 668 | |
| 669 /// Choose between a pair of continuations based on a condition value. | 657 /// Choose between a pair of continuations based on a condition value. |
| 670 /// | 658 /// |
| 671 /// The two continuations must not declare any parameters. | 659 /// The two continuations must not declare any parameters. |
| 672 class Branch extends TailExpression { | 660 class Branch extends TailExpression { |
| 673 final Condition condition; | 661 final Reference<Primitive> condition; |
| 674 final Reference<Continuation> trueContinuation; | 662 final Reference<Continuation> trueContinuation; |
| 675 final Reference<Continuation> falseContinuation; | 663 final Reference<Continuation> falseContinuation; |
| 676 | 664 |
| 677 Branch(this.condition, Continuation trueCont, Continuation falseCont) | 665 /// If true, only the value `true` satisfies the condition. Otherwise, any |
| 678 : trueContinuation = new Reference<Continuation>(trueCont), | 666 /// truthy value satisfies the check. |
| 679 falseContinuation = new Reference<Continuation>(falseCont); | 667 /// |
| 668 /// Non-strict checks are preferable when the condition is known to be a |
| 669 /// boolean. |
| 670 bool isStrictCheck; |
| 671 |
| 672 Branch.strict(Primitive condition, |
| 673 Continuation trueCont, |
| 674 Continuation falseCont) |
| 675 : this.condition = new Reference<Primitive>(condition), |
| 676 trueContinuation = new Reference<Continuation>(trueCont), |
| 677 falseContinuation = new Reference<Continuation>(falseCont), |
| 678 isStrictCheck = true; |
| 679 |
| 680 Branch.loose(Primitive condition, |
| 681 Continuation trueCont, |
| 682 Continuation falseCont) |
| 683 : this.condition = new Reference<Primitive>(condition), |
| 684 trueContinuation = new Reference<Continuation>(trueCont), |
| 685 falseContinuation = new Reference<Continuation>(falseCont), |
| 686 this.isStrictCheck = false; |
| 680 | 687 |
| 681 accept(Visitor visitor) => visitor.visitBranch(this); | 688 accept(Visitor visitor) => visitor.visitBranch(this); |
| 682 } | 689 } |
| 683 | 690 |
| 684 /// Directly assigns to a field on a given object. | 691 /// Directly assigns to a field on a given object. |
| 685 class SetField extends Primitive { | 692 class SetField extends Primitive { |
| 686 final Reference<Primitive> object; | 693 final Reference<Primitive> object; |
| 687 FieldElement field; | 694 FieldElement field; |
| 688 final Reference<Primitive> value; | 695 final Reference<Primitive> value; |
| 689 | 696 |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1184 T visitReadTypeVariable(ReadTypeVariable node); | 1191 T visitReadTypeVariable(ReadTypeVariable node); |
| 1185 T visitTypeExpression(TypeExpression node); | 1192 T visitTypeExpression(TypeExpression node); |
| 1186 T visitCreateInvocationMirror(CreateInvocationMirror node); | 1193 T visitCreateInvocationMirror(CreateInvocationMirror node); |
| 1187 T visitTypeTest(TypeTest node); | 1194 T visitTypeTest(TypeTest node); |
| 1188 T visitApplyBuiltinOperator(ApplyBuiltinOperator node); | 1195 T visitApplyBuiltinOperator(ApplyBuiltinOperator node); |
| 1189 T visitApplyBuiltinMethod(ApplyBuiltinMethod node); | 1196 T visitApplyBuiltinMethod(ApplyBuiltinMethod node); |
| 1190 T visitGetLength(GetLength node); | 1197 T visitGetLength(GetLength node); |
| 1191 T visitGetIndex(GetIndex node); | 1198 T visitGetIndex(GetIndex node); |
| 1192 T visitSetIndex(SetIndex node); | 1199 T visitSetIndex(SetIndex node); |
| 1193 | 1200 |
| 1194 // Conditions. | |
| 1195 T visitIsTrue(IsTrue node); | |
| 1196 | |
| 1197 // Support for literal foreign code. | 1201 // Support for literal foreign code. |
| 1198 T visitForeignCode(ForeignCode node); | 1202 T visitForeignCode(ForeignCode node); |
| 1199 } | 1203 } |
| 1200 | 1204 |
| 1201 /// Visits all non-recursive children of a CPS term, i.e. anything | 1205 /// Visits all non-recursive children of a CPS term, i.e. anything |
| 1202 /// not of type [Expression] or [Continuation]. | 1206 /// not of type [Expression] or [Continuation]. |
| 1203 /// | 1207 /// |
| 1204 /// Note that the non-recursive nodes can contain other nodes inside of them, | |
| 1205 /// e.g. [Branch] contains an [IsTrue] which contains a [Reference]. | |
| 1206 /// | |
| 1207 /// The `process*` methods are called in pre-order for every node visited. | 1208 /// The `process*` methods are called in pre-order for every node visited. |
| 1208 /// These can be overridden without disrupting the visitor traversal. | 1209 /// These can be overridden without disrupting the visitor traversal. |
| 1209 class LeafVisitor implements Visitor { | 1210 class LeafVisitor implements Visitor { |
| 1210 const LeafVisitor(); | 1211 const LeafVisitor(); |
| 1211 | 1212 |
| 1212 visit(Node node) => node.accept(this); | 1213 visit(Node node) => node.accept(this); |
| 1213 | 1214 |
| 1214 processReference(Reference ref) {} | 1215 processReference(Reference ref) {} |
| 1215 | 1216 |
| 1216 processFunctionDefinition(FunctionDefinition node) {} | 1217 processFunctionDefinition(FunctionDefinition node) {} |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 processRethrow(Rethrow node) {} | 1294 processRethrow(Rethrow node) {} |
| 1294 visitRethrow(Rethrow node) { | 1295 visitRethrow(Rethrow node) { |
| 1295 processRethrow(node); | 1296 processRethrow(node); |
| 1296 } | 1297 } |
| 1297 | 1298 |
| 1298 processBranch(Branch node) {} | 1299 processBranch(Branch node) {} |
| 1299 visitBranch(Branch node) { | 1300 visitBranch(Branch node) { |
| 1300 processBranch(node); | 1301 processBranch(node); |
| 1301 processReference(node.trueContinuation); | 1302 processReference(node.trueContinuation); |
| 1302 processReference(node.falseContinuation); | 1303 processReference(node.falseContinuation); |
| 1303 visit(node.condition); | 1304 processReference(node.condition); |
| 1304 } | 1305 } |
| 1305 | 1306 |
| 1306 processTypeCast(TypeCast node) {} | 1307 processTypeCast(TypeCast node) {} |
| 1307 visitTypeCast(TypeCast node) { | 1308 visitTypeCast(TypeCast node) { |
| 1308 processTypeCast(node); | 1309 processTypeCast(node); |
| 1309 processReference(node.continuation); | 1310 processReference(node.continuation); |
| 1310 processReference(node.value); | 1311 processReference(node.value); |
| 1311 node.typeArguments.forEach(processReference); | 1312 node.typeArguments.forEach(processReference); |
| 1312 } | 1313 } |
| 1313 | 1314 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1372 visitParameter(Parameter node) { | 1373 visitParameter(Parameter node) { |
| 1373 processParameter(node); | 1374 processParameter(node); |
| 1374 } | 1375 } |
| 1375 | 1376 |
| 1376 processContinuation(Continuation node) {} | 1377 processContinuation(Continuation node) {} |
| 1377 visitContinuation(Continuation node) { | 1378 visitContinuation(Continuation node) { |
| 1378 processContinuation(node); | 1379 processContinuation(node); |
| 1379 node.parameters.forEach(visitParameter); | 1380 node.parameters.forEach(visitParameter); |
| 1380 } | 1381 } |
| 1381 | 1382 |
| 1382 processIsTrue(IsTrue node) {} | |
| 1383 visitIsTrue(IsTrue node) { | |
| 1384 processIsTrue(node); | |
| 1385 processReference(node.value); | |
| 1386 } | |
| 1387 | |
| 1388 processInterceptor(Interceptor node) {} | 1383 processInterceptor(Interceptor node) {} |
| 1389 visitInterceptor(Interceptor node) { | 1384 visitInterceptor(Interceptor node) { |
| 1390 processInterceptor(node); | 1385 processInterceptor(node); |
| 1391 processReference(node.input); | 1386 processReference(node.input); |
| 1392 } | 1387 } |
| 1393 | 1388 |
| 1394 processCreateInstance(CreateInstance node) {} | 1389 processCreateInstance(CreateInstance node) {} |
| 1395 visitCreateInstance(CreateInstance node) { | 1390 visitCreateInstance(CreateInstance node) { |
| 1396 processCreateInstance(node); | 1391 processCreateInstance(node); |
| 1397 node.arguments.forEach(processReference); | 1392 node.arguments.forEach(processReference); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1629 /// Visit a just-deleted subterm and unlink all [Reference]s in it. | 1624 /// Visit a just-deleted subterm and unlink all [Reference]s in it. |
| 1630 class RemovalVisitor extends RecursiveVisitor { | 1625 class RemovalVisitor extends RecursiveVisitor { |
| 1631 processReference(Reference reference) { | 1626 processReference(Reference reference) { |
| 1632 reference.unlink(); | 1627 reference.unlink(); |
| 1633 } | 1628 } |
| 1634 | 1629 |
| 1635 static void remove(Node node) { | 1630 static void remove(Node node) { |
| 1636 (new RemovalVisitor()).visit(node); | 1631 (new RemovalVisitor()).visit(node); |
| 1637 } | 1632 } |
| 1638 } | 1633 } |
| OLD | NEW |