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 'dart:collection'; | 6 import 'dart:collection'; |
7 import '../constants/values.dart' as values; | 7 import '../constants/values.dart' as values; |
8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; | 8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; |
9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
10 import '../io/source_information.dart' show SourceInformation; | 10 import '../io/source_information.dart' show SourceInformation; |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 | 506 |
507 /// JS receiver is an interceptor, the first argument is the Dart receiver. | 507 /// JS receiver is an interceptor, the first argument is the Dart receiver. |
508 /// | 508 /// |
509 /// For example: `getInterceptor(foo).bar$1(foo, x)` | 509 /// For example: `getInterceptor(foo).bar$1(foo, x)` |
510 Intercepted, | 510 Intercepted, |
511 | 511 |
512 /// JS receiver is the Dart receiver, the first argument is a dummy value. | 512 /// JS receiver is the Dart receiver, the first argument is a dummy value. |
513 /// | 513 /// |
514 /// For example: `foo.bar$1(0, x)` | 514 /// For example: `foo.bar$1(0, x)` |
515 DummyIntercepted, | 515 DummyIntercepted, |
| 516 |
| 517 /// JS receiver is the Dart receiver, there are no extra arguments. |
| 518 /// |
| 519 /// Compiles to a one-shot interceptor, e.g: `J.bar$1(foo, x)` |
| 520 OneShotIntercepted, |
516 } | 521 } |
517 | 522 |
518 /// Invoke a method on an object. | 523 /// Invoke a method on an object. |
519 /// | 524 /// |
520 /// This includes getters, setters, operators, and index getter/setters. | 525 /// This includes getters, setters, operators, and index getter/setters. |
521 /// | 526 /// |
522 /// Tearing off a method is treated like a getter invocation (getters and | 527 /// Tearing off a method is treated like a getter invocation (getters and |
523 /// tear-offs cannot be distinguished at compile-time). | 528 /// tear-offs cannot be distinguished at compile-time). |
524 /// | 529 /// |
525 /// The [selector] records the names of named arguments. The value of named | 530 /// The [selector] records the names of named arguments. The value of named |
526 /// arguments occur at the end of the [arguments] list, in normalized order. | 531 /// arguments occur at the end of the [arguments] list, in normalized order. |
527 class InvokeMethod extends UnsafePrimitive { | 532 class InvokeMethod extends UnsafePrimitive { |
528 Reference<Primitive> receiver; | 533 Reference<Primitive> receiver; |
529 Selector selector; | 534 Selector selector; |
530 TypeMask mask; | 535 TypeMask mask; |
531 final List<Reference<Primitive>> arguments; | 536 final List<Reference<Primitive>> arguments; |
532 final SourceInformation sourceInformation; | 537 final SourceInformation sourceInformation; |
533 | 538 |
534 CallingConvention callingConvention = CallingConvention.Normal; | 539 CallingConvention callingConvention = CallingConvention.Normal; |
535 | 540 |
536 Reference<Primitive> get dartReceiverReference { | 541 Reference<Primitive> get dartReceiverReference { |
537 return callingConvention == CallingConvention.Intercepted | 542 return callingConvention == CallingConvention.Intercepted |
538 ? arguments[0] | 543 ? arguments[0] |
539 : receiver; | 544 : receiver; |
540 } | 545 } |
541 | 546 |
542 Primitive get dartReceiver => dartReceiverReference.definition; | 547 Primitive get dartReceiver => dartReceiverReference.definition; |
543 | 548 |
544 Reference<Primitive> dartArgumentReference(int n) { | 549 Reference<Primitive> dartArgumentReference(int n) { |
545 return callingConvention == CallingConvention.Normal | 550 switch (callingConvention) { |
546 ? arguments[n] | 551 case CallingConvention.Normal: |
547 : arguments[n + 1]; | 552 case CallingConvention.OneShotIntercepted: |
| 553 return arguments[n]; |
| 554 |
| 555 case CallingConvention.Intercepted: |
| 556 case CallingConvention.DummyIntercepted: |
| 557 return arguments[n + 1]; |
| 558 } |
548 } | 559 } |
549 | 560 |
550 Primitive dartArgument(int n) => dartArgumentReference(n).definition; | 561 Primitive dartArgument(int n) => dartArgumentReference(n).definition; |
551 | 562 |
552 /// If true, it is known that the receiver cannot be `null`. | 563 /// If true, it is known that the receiver cannot be `null`. |
553 bool receiverIsNotNull = false; | 564 bool receiverIsNotNull = false; |
554 | 565 |
555 InvokeMethod(Primitive receiver, | 566 InvokeMethod(Primitive receiver, |
556 this.selector, | 567 this.selector, |
557 this.mask, | 568 this.mask, |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 if (condition != null) { | 865 if (condition != null) { |
855 condition.parent = this; | 866 condition.parent = this; |
856 } | 867 } |
857 } | 868 } |
858 | 869 |
859 Primitive get effectiveDefinition => value.definition.effectiveDefinition; | 870 Primitive get effectiveDefinition => value.definition.effectiveDefinition; |
860 } | 871 } |
861 | 872 |
862 /// An "is" type test. | 873 /// An "is" type test. |
863 /// | 874 /// |
864 /// Returns `true` if [value] is an instance of [type]. | 875 /// Returns `true` if [value] is an instance of [dartType]. |
865 /// | 876 /// |
866 /// [type] must not be the [Object], `dynamic` or [Null] types (though it might | 877 /// [type] must not be the [Object], `dynamic` or [Null] types (though it might |
867 /// be a type variable containing one of these types). This design is chosen | 878 /// be a type variable containing one of these types). This design is chosen |
868 /// to simplify code generation for type tests. | 879 /// to simplify code generation for type tests. |
869 class TypeTest extends Primitive { | 880 class TypeTest extends Primitive { |
870 Reference<Primitive> value; | 881 Reference<Primitive> value; |
871 final DartType dartType; | 882 final DartType dartType; |
872 | 883 |
873 /// If [dartType] is an [InterfaceType], this holds the internal | 884 /// If [dartType] is an [InterfaceType], this holds the internal |
874 /// representation of the type arguments to [dartType]. Since these may | 885 /// representation of the type arguments to [dartType]. Since these may |
(...skipping 1499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2374 /// Visit a just-deleted subterm and unlink all [Reference]s in it. | 2385 /// Visit a just-deleted subterm and unlink all [Reference]s in it. |
2375 class RemovalVisitor extends TrampolineRecursiveVisitor { | 2386 class RemovalVisitor extends TrampolineRecursiveVisitor { |
2376 processReference(Reference reference) { | 2387 processReference(Reference reference) { |
2377 reference.unlink(); | 2388 reference.unlink(); |
2378 } | 2389 } |
2379 | 2390 |
2380 static void remove(Node node) { | 2391 static void remove(Node node) { |
2381 (new RemovalVisitor()).visit(node); | 2392 (new RemovalVisitor()).visit(node); |
2382 } | 2393 } |
2383 } | 2394 } |
OLD | NEW |