| 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 /// class will still require an explicit argument. | 337 /// class will still require an explicit argument. |
| 338 /// | 338 /// |
| 339 /// All optional arguments declared by [target] are passed in explicitly, and | 339 /// All optional arguments declared by [target] are passed in explicitly, and |
| 340 /// occur at the end of [arguments] list, in normalized order. | 340 /// occur at the end of [arguments] list, in normalized order. |
| 341 class InvokeMethodDirectly extends Expression implements Invoke { | 341 class InvokeMethodDirectly extends Expression implements Invoke { |
| 342 Reference<Primitive> receiver; | 342 Reference<Primitive> receiver; |
| 343 final FunctionElement target; | 343 final FunctionElement target; |
| 344 final Selector selector; | 344 final Selector selector; |
| 345 final List<Reference<Primitive>> arguments; | 345 final List<Reference<Primitive>> arguments; |
| 346 final Reference<Continuation> continuation; | 346 final Reference<Continuation> continuation; |
| 347 final SourceInformation sourceInformation; |
| 347 | 348 |
| 348 InvokeMethodDirectly(Primitive receiver, | 349 InvokeMethodDirectly(Primitive receiver, |
| 349 this.target, | 350 this.target, |
| 350 this.selector, | 351 this.selector, |
| 351 List<Primitive> arguments, | 352 List<Primitive> arguments, |
| 352 Continuation continuation) | 353 Continuation continuation, |
| 354 this.sourceInformation) |
| 353 : this.receiver = new Reference<Primitive>(receiver), | 355 : this.receiver = new Reference<Primitive>(receiver), |
| 354 this.arguments = _referenceList(arguments), | 356 this.arguments = _referenceList(arguments), |
| 355 this.continuation = new Reference<Continuation>(continuation); | 357 this.continuation = new Reference<Continuation>(continuation); |
| 356 | 358 |
| 357 accept(Visitor visitor) => visitor.visitInvokeMethodDirectly(this); | 359 accept(Visitor visitor) => visitor.visitInvokeMethodDirectly(this); |
| 358 } | 360 } |
| 359 | 361 |
| 360 /// Non-const call to a constructor. | 362 /// Non-const call to a constructor. |
| 361 /// | 363 /// |
| 362 /// The [target] may be a generative constructor (forwarding or normal) | 364 /// The [target] may be a generative constructor (forwarding or normal) |
| 363 /// or a non-redirecting factory. | 365 /// or a non-redirecting factory. |
| 364 /// | 366 /// |
| 365 /// All optional arguments declared by [target] are passed in explicitly, and | 367 /// All optional arguments declared by [target] are passed in explicitly, and |
| 366 /// occur in the [arguments] list, in normalized order. | 368 /// occur in the [arguments] list, in normalized order. |
| 367 /// | 369 /// |
| 368 /// Last in the [arguments] list, after the mandatory and optional arguments, | 370 /// Last in the [arguments] list, after the mandatory and optional arguments, |
| 369 /// the internal representation of each type argument occurs, unless it could | 371 /// the internal representation of each type argument occurs, unless it could |
| 370 /// be determined at build-time that the constructed class has no need for its | 372 /// be determined at build-time that the constructed class has no need for its |
| 371 /// runtime type information. | 373 /// runtime type information. |
| 372 /// | 374 /// |
| 373 /// Note that [InvokeConstructor] does it itself allocate an object. | 375 /// Note that [InvokeConstructor] does it itself allocate an object. |
| 374 /// The invoked constructor will do that using [CreateInstance]. | 376 /// The invoked constructor will do that using [CreateInstance]. |
| 375 class InvokeConstructor extends Expression implements Invoke { | 377 class InvokeConstructor extends Expression implements Invoke { |
| 376 final DartType type; | 378 final DartType type; |
| 377 final ConstructorElement target; | 379 final ConstructorElement target; |
| 378 final List<Reference<Primitive>> arguments; | 380 final List<Reference<Primitive>> arguments; |
| 379 final Reference<Continuation> continuation; | 381 final Reference<Continuation> continuation; |
| 380 final Selector selector; | 382 final Selector selector; |
| 383 final SourceInformation sourceInformation; |
| 381 | 384 |
| 382 InvokeConstructor(this.type, | 385 InvokeConstructor(this.type, |
| 383 this.target, | 386 this.target, |
| 384 this.selector, | 387 this.selector, |
| 385 List<Primitive> args, | 388 List<Primitive> args, |
| 386 Continuation cont) | 389 Continuation cont, |
| 390 this.sourceInformation) |
| 387 : arguments = _referenceList(args), | 391 : arguments = _referenceList(args), |
| 388 continuation = new Reference<Continuation>(cont); | 392 continuation = new Reference<Continuation>(cont); |
| 389 | 393 |
| 390 accept(Visitor visitor) => visitor.visitInvokeConstructor(this); | 394 accept(Visitor visitor) => visitor.visitInvokeConstructor(this); |
| 391 } | 395 } |
| 392 | 396 |
| 393 /// An "is" type test. | 397 /// An "is" type test. |
| 394 /// | 398 /// |
| 395 /// Returns `true` if [value] is an instance of [type]. | 399 /// Returns `true` if [value] is an instance of [type]. |
| 396 /// | 400 /// |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 Expression plug(Expression expr) { | 560 Expression plug(Expression expr) { |
| 557 assert(body == null); | 561 assert(body == null); |
| 558 return body = expr; | 562 return body = expr; |
| 559 } | 563 } |
| 560 } | 564 } |
| 561 | 565 |
| 562 /// Invoke a continuation in tail position. | 566 /// Invoke a continuation in tail position. |
| 563 class InvokeContinuation extends Expression { | 567 class InvokeContinuation extends Expression { |
| 564 Reference<Continuation> continuation; | 568 Reference<Continuation> continuation; |
| 565 List<Reference<Primitive>> arguments; | 569 List<Reference<Primitive>> arguments; |
| 570 SourceInformation sourceInformation; |
| 566 | 571 |
| 567 // An invocation of a continuation is recursive if it occurs in the body of | 572 // An invocation of a continuation is recursive if it occurs in the body of |
| 568 // the continuation itself. | 573 // the continuation itself. |
| 569 bool isRecursive; | 574 bool isRecursive; |
| 570 | 575 |
| 571 /// True if this invocation escapes from the body of a [LetHandler] | 576 /// True if this invocation escapes from the body of a [LetHandler] |
| 572 /// (i.e. a try block). Notably, such an invocation cannot be inlined. | 577 /// (i.e. a try block). Notably, such an invocation cannot be inlined. |
| 573 bool isEscapingTry; | 578 bool isEscapingTry; |
| 574 | 579 |
| 575 InvokeContinuation(Continuation cont, List<Primitive> args, | 580 InvokeContinuation(Continuation cont, List<Primitive> args, |
| 576 {this.isRecursive: false, | 581 {this.isRecursive: false, |
| 577 this.isEscapingTry: false}) | 582 this.isEscapingTry: false, |
| 583 this.sourceInformation}) |
| 578 : continuation = new Reference<Continuation>(cont), | 584 : continuation = new Reference<Continuation>(cont), |
| 579 arguments = _referenceList(args) { | 585 arguments = _referenceList(args) { |
| 580 assert(cont.parameters == null || cont.parameters.length == args.length); | 586 assert(cont.parameters == null || cont.parameters.length == args.length); |
| 581 if (isRecursive) cont.isRecursive = true; | 587 if (isRecursive) cont.isRecursive = true; |
| 582 } | 588 } |
| 583 | 589 |
| 584 /// A continuation invocation whose target and arguments will be filled | 590 /// A continuation invocation whose target and arguments will be filled |
| 585 /// in later. | 591 /// in later. |
| 586 /// | 592 /// |
| 587 /// Used as a placeholder for a jump whose target is not yet created | 593 /// Used as a placeholder for a jump whose target is not yet created |
| 588 /// (e.g., in the translation of break and continue). | 594 /// (e.g., in the translation of break and continue). |
| 589 InvokeContinuation.uninitialized({this.isRecursive: false, | 595 InvokeContinuation.uninitialized({this.isRecursive: false, |
| 590 this.isEscapingTry: false}) | 596 this.isEscapingTry: false}) |
| 591 : continuation = null, | 597 : continuation = null, |
| 592 arguments = null; | 598 arguments = null, |
| 599 sourceInformation = null; |
| 593 | 600 |
| 594 accept(Visitor visitor) => visitor.visitInvokeContinuation(this); | 601 accept(Visitor visitor) => visitor.visitInvokeContinuation(this); |
| 595 } | 602 } |
| 596 | 603 |
| 597 /// The base class of things which can be tested and branched on. | 604 /// The base class of things which can be tested and branched on. |
| 598 abstract class Condition extends Node { | 605 abstract class Condition extends Node { |
| 599 } | 606 } |
| 600 | 607 |
| 601 class IsTrue extends Condition { | 608 class IsTrue extends Condition { |
| 602 final Reference<Primitive> value; | 609 final Reference<Primitive> value; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 /// The order corresponds to the order of fields on the class. | 798 /// The order corresponds to the order of fields on the class. |
| 792 final List<Reference<Primitive>> arguments; | 799 final List<Reference<Primitive>> arguments; |
| 793 | 800 |
| 794 /// The runtime type information structure which contains the type arguments. | 801 /// The runtime type information structure which contains the type arguments. |
| 795 /// | 802 /// |
| 796 /// May be `null` to indicate that no type information is needed because the | 803 /// May be `null` to indicate that no type information is needed because the |
| 797 /// compiler determined that the type information for instances of this class | 804 /// compiler determined that the type information for instances of this class |
| 798 /// is not needed at runtime. | 805 /// is not needed at runtime. |
| 799 final List<Reference<Primitive>> typeInformation; | 806 final List<Reference<Primitive>> typeInformation; |
| 800 | 807 |
| 808 final SourceInformation sourceInformation; |
| 809 |
| 801 CreateInstance(this.classElement, List<Primitive> arguments, | 810 CreateInstance(this.classElement, List<Primitive> arguments, |
| 802 List<Primitive> typeInformation) | 811 List<Primitive> typeInformation, |
| 812 this.sourceInformation) |
| 803 : this.arguments = _referenceList(arguments), | 813 : this.arguments = _referenceList(arguments), |
| 804 this.typeInformation = _referenceList(typeInformation); | 814 this.typeInformation = _referenceList(typeInformation); |
| 805 | 815 |
| 806 accept(Visitor visitor) => visitor.visitCreateInstance(this); | 816 accept(Visitor visitor) => visitor.visitCreateInstance(this); |
| 807 | 817 |
| 808 bool get isSafeForElimination => true; | 818 bool get isSafeForElimination => true; |
| 809 bool get isSafeForReordering => true; | 819 bool get isSafeForReordering => true; |
| 810 } | 820 } |
| 811 | 821 |
| 812 class Interceptor extends Primitive { | 822 class Interceptor extends Primitive { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 this.nativeBehavior, {Continuation continuation, this.dependency}) | 859 this.nativeBehavior, {Continuation continuation, this.dependency}) |
| 850 : arguments = _referenceList(arguments), | 860 : arguments = _referenceList(arguments), |
| 851 continuation = continuation == null ? null | 861 continuation = continuation == null ? null |
| 852 : new Reference<Continuation>(continuation); | 862 : new Reference<Continuation>(continuation); |
| 853 | 863 |
| 854 accept(Visitor visitor) => visitor.visitForeignCode(this); | 864 accept(Visitor visitor) => visitor.visitForeignCode(this); |
| 855 } | 865 } |
| 856 | 866 |
| 857 class Constant extends Primitive { | 867 class Constant extends Primitive { |
| 858 final values.ConstantValue value; | 868 final values.ConstantValue value; |
| 869 final SourceInformation sourceInformation; |
| 859 | 870 |
| 860 Constant(this.value); | 871 Constant(this.value, {this.sourceInformation}); |
| 861 | 872 |
| 862 accept(Visitor visitor) => visitor.visitConstant(this); | 873 accept(Visitor visitor) => visitor.visitConstant(this); |
| 863 | 874 |
| 864 bool get isSafeForElimination => true; | 875 bool get isSafeForElimination => true; |
| 865 bool get isSafeForReordering => true; | 876 bool get isSafeForReordering => true; |
| 866 } | 877 } |
| 867 | 878 |
| 868 class LiteralList extends Primitive { | 879 class LiteralList extends Primitive { |
| 869 /// The List type being created; this is not the type argument. | 880 /// The List type being created; this is not the type argument. |
| 870 final InterfaceType type; | 881 final InterfaceType type; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 // gives constant-time access to the continuation from the parent. | 963 // gives constant-time access to the continuation from the parent. |
| 953 int parent_index; | 964 int parent_index; |
| 954 | 965 |
| 955 // A continuation is recursive if it has any recursive invocations. | 966 // A continuation is recursive if it has any recursive invocations. |
| 956 bool isRecursive; | 967 bool isRecursive; |
| 957 | 968 |
| 958 bool get isReturnContinuation => body == null; | 969 bool get isReturnContinuation => body == null; |
| 959 | 970 |
| 960 Continuation(this.parameters, {this.isRecursive: false}); | 971 Continuation(this.parameters, {this.isRecursive: false}); |
| 961 | 972 |
| 962 Continuation.retrn() | 973 Continuation.retrn() |
| 963 : parameters = <Parameter>[new Parameter(null)], | 974 : parameters = <Parameter>[new Parameter(null)], |
| 964 isRecursive = false; | 975 isRecursive = false; |
| 965 | 976 |
| 966 accept(Visitor visitor) => visitor.visitContinuation(this); | 977 accept(Visitor visitor) => visitor.visitContinuation(this); |
| 967 } | 978 } |
| 968 | 979 |
| 969 /// Identifies a mutable variable. | 980 /// Identifies a mutable variable. |
| 970 class MutableVariable extends Definition { | 981 class MutableVariable extends Definition { |
| 971 Entity hint; | 982 Entity hint; |
| 972 | 983 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 994 | 1005 |
| 995 accept(Visitor visitor) => visitor.visitFunctionDefinition(this); | 1006 accept(Visitor visitor) => visitor.visitFunctionDefinition(this); |
| 996 } | 1007 } |
| 997 | 1008 |
| 998 /// Converts the internal representation of a type to a Dart object of type | 1009 /// Converts the internal representation of a type to a Dart object of type |
| 999 /// [Type]. | 1010 /// [Type]. |
| 1000 class ReifyRuntimeType extends Primitive { | 1011 class ReifyRuntimeType extends Primitive { |
| 1001 /// Reference to the internal representation of a type (as produced, for | 1012 /// Reference to the internal representation of a type (as produced, for |
| 1002 /// example, by [ReadTypeVariable]). | 1013 /// example, by [ReadTypeVariable]). |
| 1003 final Reference<Primitive> value; | 1014 final Reference<Primitive> value; |
| 1004 ReifyRuntimeType(Primitive value) | 1015 |
| 1016 final SourceInformation sourceInformation; |
| 1017 |
| 1018 ReifyRuntimeType(Primitive value, this.sourceInformation) |
| 1005 : this.value = new Reference<Primitive>(value); | 1019 : this.value = new Reference<Primitive>(value); |
| 1006 | 1020 |
| 1007 @override | 1021 @override |
| 1008 accept(Visitor visitor) => visitor.visitReifyRuntimeType(this); | 1022 accept(Visitor visitor) => visitor.visitReifyRuntimeType(this); |
| 1009 | 1023 |
| 1010 bool get isSafeForElimination => true; | 1024 bool get isSafeForElimination => true; |
| 1011 bool get isSafeForReordering => true; | 1025 bool get isSafeForReordering => true; |
| 1012 } | 1026 } |
| 1013 | 1027 |
| 1014 /// Read the value the type variable [variable] from the target object. | 1028 /// Read the value the type variable [variable] from the target object. |
| 1015 /// | 1029 /// |
| 1016 /// The resulting value is an internal representation (and not neccessarily a | 1030 /// The resulting value is an internal representation (and not neccessarily a |
| 1017 /// Dart object), and must be reified by [ReifyRuntimeType], if it should be | 1031 /// Dart object), and must be reified by [ReifyRuntimeType], if it should be |
| 1018 /// used as a Dart value. | 1032 /// used as a Dart value. |
| 1019 class ReadTypeVariable extends Primitive { | 1033 class ReadTypeVariable extends Primitive { |
| 1020 final TypeVariableType variable; | 1034 final TypeVariableType variable; |
| 1021 final Reference<Primitive> target; | 1035 final Reference<Primitive> target; |
| 1036 final SourceInformation sourceInformation; |
| 1022 | 1037 |
| 1023 ReadTypeVariable(this.variable, Primitive target) | 1038 ReadTypeVariable(this.variable, Primitive target, this.sourceInformation) |
| 1024 : this.target = new Reference<Primitive>(target); | 1039 : this.target = new Reference<Primitive>(target); |
| 1025 | 1040 |
| 1026 @override | 1041 @override |
| 1027 accept(Visitor visitor) => visitor.visitReadTypeVariable(this); | 1042 accept(Visitor visitor) => visitor.visitReadTypeVariable(this); |
| 1028 | 1043 |
| 1029 bool get isSafeForElimination => true; | 1044 bool get isSafeForElimination => true; |
| 1030 bool get isSafeForReordering => true; | 1045 bool get isSafeForReordering => true; |
| 1031 } | 1046 } |
| 1032 | 1047 |
| 1033 /// Representation of a closed type (that is, a type without type variables). | 1048 /// Representation of a closed type (that is, a type without type variables). |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1429 const RemovalVisitor(); | 1444 const RemovalVisitor(); |
| 1430 | 1445 |
| 1431 processReference(Reference reference) { | 1446 processReference(Reference reference) { |
| 1432 reference.unlink(); | 1447 reference.unlink(); |
| 1433 } | 1448 } |
| 1434 | 1449 |
| 1435 static void remove(Node node) { | 1450 static void remove(Node node) { |
| 1436 (const RemovalVisitor()).visit(node); | 1451 (const RemovalVisitor()).visit(node); |
| 1437 } | 1452 } |
| 1438 } | 1453 } |
| OLD | NEW |