| 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 library inferrer_visitor; | 5 library inferrer_visitor; |
| 6 | 6 |
| 7 import '../dart2jslib.dart' hide Selector, TypedSelector; | 7 import '../dart2jslib.dart' hide Selector, TypedSelector; |
| 8 import '../dart_types.dart'; | 8 import '../dart_types.dart'; |
| 9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 10 import '../tree/tree.dart'; | 10 import '../tree/tree.dart'; |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 LocalsHandler<T> locals; | 605 LocalsHandler<T> locals; |
| 606 final List<T> cascadeReceiverStack = new List<T>(); | 606 final List<T> cascadeReceiverStack = new List<T>(); |
| 607 | 607 |
| 608 bool accumulateIsChecks = false; | 608 bool accumulateIsChecks = false; |
| 609 bool conditionIsSimple = false; | 609 bool conditionIsSimple = false; |
| 610 List<Send> isChecks; | 610 List<Send> isChecks; |
| 611 int loopLevel = 0; | 611 int loopLevel = 0; |
| 612 | 612 |
| 613 bool get inLoop => loopLevel > 0; | 613 bool get inLoop => loopLevel > 0; |
| 614 bool get isThisExposed { | 614 bool get isThisExposed { |
| 615 return analyzedElement.isGenerativeConstructor() | 615 return analyzedElement.isGenerativeConstructor |
| 616 ? locals.fieldScope.isThisExposed | 616 ? locals.fieldScope.isThisExposed |
| 617 : true; | 617 : true; |
| 618 } | 618 } |
| 619 void set isThisExposed(value) { | 619 void set isThisExposed(value) { |
| 620 if (analyzedElement.isGenerativeConstructor()) { | 620 if (analyzedElement.isGenerativeConstructor) { |
| 621 locals.fieldScope.isThisExposed = value; | 621 locals.fieldScope.isThisExposed = value; |
| 622 } | 622 } |
| 623 } | 623 } |
| 624 | 624 |
| 625 InferrerVisitor(Element analyzedElement, | 625 InferrerVisitor(Element analyzedElement, |
| 626 this.inferrer, | 626 this.inferrer, |
| 627 this.types, | 627 this.types, |
| 628 Compiler compiler, | 628 Compiler compiler, |
| 629 [LocalsHandler<T> handler]) | 629 [LocalsHandler<T> handler]) |
| 630 : this.analyzedElement = analyzedElement, | 630 : this.analyzedElement = analyzedElement, |
| 631 this.locals = handler, | 631 this.locals = handler, |
| 632 super(compiler.enqueuer.resolution.getCachedElements(analyzedElement), | 632 super(compiler.enqueuer.resolution.getCachedElements(analyzedElement), |
| 633 compiler) { | 633 compiler) { |
| 634 if (handler != null) return; | 634 if (handler != null) return; |
| 635 Node node = analyzedElement.parseNode(compiler); | 635 Node node = analyzedElement.parseNode(compiler); |
| 636 FieldInitializationScope<T> fieldScope = | 636 FieldInitializationScope<T> fieldScope = |
| 637 analyzedElement.isGenerativeConstructor() | 637 analyzedElement.isGenerativeConstructor |
| 638 ? new FieldInitializationScope<T>(types) | 638 ? new FieldInitializationScope<T>(types) |
| 639 : null; | 639 : null; |
| 640 locals = new LocalsHandler<T>(inferrer, types, compiler, node, fieldScope); | 640 locals = new LocalsHandler<T>(inferrer, types, compiler, node, fieldScope); |
| 641 } | 641 } |
| 642 | 642 |
| 643 T visitSendSet(SendSet node); | 643 T visitSendSet(SendSet node); |
| 644 | 644 |
| 645 T visitSuperSend(Send node); | 645 T visitSuperSend(Send node); |
| 646 | 646 |
| 647 T visitStaticSend(Send node); | 647 T visitStaticSend(Send node); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 T visitLiteralInt(LiteralInt node) { | 711 T visitLiteralInt(LiteralInt node) { |
| 712 ConstantSystem constantSystem = compiler.backend.constantSystem; | 712 ConstantSystem constantSystem = compiler.backend.constantSystem; |
| 713 // The JavaScript backend may turn this literal into a double at | 713 // The JavaScript backend may turn this literal into a double at |
| 714 // runtime. | 714 // runtime. |
| 715 return types.getConcreteTypeFor( | 715 return types.getConcreteTypeFor( |
| 716 constantSystem.createInt(node.value).computeMask(compiler)); | 716 constantSystem.createInt(node.value).computeMask(compiler)); |
| 717 } | 717 } |
| 718 | 718 |
| 719 T visitLiteralList(LiteralList node) { | 719 T visitLiteralList(LiteralList node) { |
| 720 node.visitChildren(this); | 720 node.visitChildren(this); |
| 721 return node.isConst() ? types.constListType : types.growableListType; | 721 return node.isConst ? types.constListType : types.growableListType; |
| 722 } | 722 } |
| 723 | 723 |
| 724 T visitLiteralMap(LiteralMap node) { | 724 T visitLiteralMap(LiteralMap node) { |
| 725 node.visitChildren(this); | 725 node.visitChildren(this); |
| 726 return node.isConst() ? types.constMapType : types.mapType; | 726 return node.isConst ? types.constMapType : types.mapType; |
| 727 } | 727 } |
| 728 | 728 |
| 729 T visitLiteralNull(LiteralNull node) { | 729 T visitLiteralNull(LiteralNull node) { |
| 730 return types.nullType; | 730 return types.nullType; |
| 731 } | 731 } |
| 732 | 732 |
| 733 T visitLiteralSymbol(LiteralSymbol node) { | 733 T visitLiteralSymbol(LiteralSymbol node) { |
| 734 // TODO(kasperl): We should be able to tell that the type of a literal | 734 // TODO(kasperl): We should be able to tell that the type of a literal |
| 735 // symbol is always a non-null exact symbol implementation -- not just | 735 // symbol is always a non-null exact symbol implementation -- not just |
| 736 // any non-null subtype of the symbol interface. | 736 // any non-null subtype of the symbol interface. |
| 737 return types.nonNullSubtype(compiler.symbolClass); | 737 return types.nonNullSubtype(compiler.symbolClass); |
| 738 } | 738 } |
| 739 | 739 |
| 740 T visitTypeReferenceSend(Send node) { | 740 T visitTypeReferenceSend(Send node) { |
| 741 return elements.isTypeLiteral(node) ? types.typeType : types.dynamicType; | 741 return elements.isTypeLiteral(node) ? types.typeType : types.dynamicType; |
| 742 } | 742 } |
| 743 | 743 |
| 744 bool isThisOrSuper(Node node) => node.isThis() || node.isSuper(); | 744 bool isThisOrSuper(Node node) => node.isThis() || node.isSuper(); |
| 745 | 745 |
| 746 Element get outermostElement { | 746 Element get outermostElement { |
| 747 return | 747 return analyzedElement.outermostEnclosingMemberOrTopLevel.implementation; |
| 748 analyzedElement.getOutermostEnclosingMemberOrTopLevel().implementation; | |
| 749 } | 748 } |
| 750 | 749 |
| 751 T _thisType; | 750 T _thisType; |
| 752 T get thisType { | 751 T get thisType { |
| 753 if (_thisType != null) return _thisType; | 752 if (_thisType != null) return _thisType; |
| 754 ClassElement cls = outermostElement.getEnclosingClass(); | 753 ClassElement cls = outermostElement.enclosingClass; |
| 755 if (compiler.world.isUsedAsMixin(cls)) { | 754 if (compiler.world.isUsedAsMixin(cls)) { |
| 756 return _thisType = types.nonNullSubtype(cls); | 755 return _thisType = types.nonNullSubtype(cls); |
| 757 } else if (compiler.world.hasAnySubclass(cls)) { | 756 } else if (compiler.world.hasAnySubclass(cls)) { |
| 758 return _thisType = types.nonNullSubclass(cls); | 757 return _thisType = types.nonNullSubclass(cls); |
| 759 } else { | 758 } else { |
| 760 return _thisType = types.nonNullExact(cls); | 759 return _thisType = types.nonNullExact(cls); |
| 761 } | 760 } |
| 762 } | 761 } |
| 763 | 762 |
| 764 T _superType; | 763 T _superType; |
| 765 T get superType { | 764 T get superType { |
| 766 if (_superType != null) return _superType; | 765 if (_superType != null) return _superType; |
| 767 return _superType = types.nonNullExact( | 766 return _superType = types.nonNullExact( |
| 768 outermostElement.getEnclosingClass().superclass); | 767 outermostElement.enclosingClass.superclass); |
| 769 } | 768 } |
| 770 | 769 |
| 771 T visitIdentifier(Identifier node) { | 770 T visitIdentifier(Identifier node) { |
| 772 if (node.isThis()) { | 771 if (node.isThis()) { |
| 773 return thisType; | 772 return thisType; |
| 774 } else if (node.isSuper()) { | 773 } else if (node.isSuper()) { |
| 775 return superType; | 774 return superType; |
| 776 } else { | 775 } else { |
| 777 Element element = elements[node]; | 776 Element element = elements[node]; |
| 778 if (Elements.isLocal(element)) { | 777 if (Elements.isLocal(element)) { |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1214 return type; | 1213 return type; |
| 1215 } | 1214 } |
| 1216 | 1215 |
| 1217 T visitCascade(Cascade node) { | 1216 T visitCascade(Cascade node) { |
| 1218 // Ignore the result of the cascade send and return the type of the cascade | 1217 // Ignore the result of the cascade send and return the type of the cascade |
| 1219 // receiver. | 1218 // receiver. |
| 1220 visit(node.expression); | 1219 visit(node.expression); |
| 1221 return cascadeReceiverStack.removeLast(); | 1220 return cascadeReceiverStack.removeLast(); |
| 1222 } | 1221 } |
| 1223 } | 1222 } |
| OLD | NEW |