Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: pkg/compiler/lib/src/resolution/members.dart

Issue 1438453002: Use Feature directly in resolution. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 dart2js.resolution.members; 5 library dart2js.resolution.members;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/names.dart' show 8 import '../common/names.dart' show
9 Selectors; 9 Selectors;
10 import '../common/resolution.dart' show
11 Feature;
10 import '../compiler.dart' show 12 import '../compiler.dart' show
11 Compiler; 13 Compiler;
12 import '../constants/constructors.dart' show 14 import '../constants/constructors.dart' show
13 RedirectingFactoryConstantConstructor; 15 RedirectingFactoryConstantConstructor;
14 import '../constants/expressions.dart'; 16 import '../constants/expressions.dart';
15 import '../constants/values.dart'; 17 import '../constants/values.dart';
16 import '../core_types.dart'; 18 import '../core_types.dart';
17 import '../dart_types.dart'; 19 import '../dart_types.dart';
18 import '../elements/elements.dart'; 20 import '../elements/elements.dart';
19 import '../elements/modelx.dart' show 21 import '../elements/modelx.dart' show
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 var functionName = enclosingElement.name; 330 var functionName = enclosingElement.name;
329 if (functionName == '') { 331 if (functionName == '') {
330 kind = MessageKind.CANNOT_RESOLVE_AWAIT_IN_CLOSURE; 332 kind = MessageKind.CANNOT_RESOLVE_AWAIT_IN_CLOSURE;
331 } else { 333 } else {
332 kind = MessageKind.CANNOT_RESOLVE_AWAIT; 334 kind = MessageKind.CANNOT_RESOLVE_AWAIT;
333 arguments['functionName'] = functionName; 335 arguments['functionName'] = functionName;
334 } 336 }
335 } else { 337 } else {
336 kind = MessageKind.CANNOT_RESOLVE; 338 kind = MessageKind.CANNOT_RESOLVE;
337 } 339 }
338 registry.registerThrowNoSuchMethod(); 340 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
339 return reportAndCreateErroneousElement( 341 return reportAndCreateErroneousElement(
340 node, name, kind, arguments, isError: inInitializer); 342 node, name, kind, arguments, isError: inInitializer);
341 } 343 }
342 344
343 ResolutionResult visitIdentifier(Identifier node) { 345 ResolutionResult visitIdentifier(Identifier node) {
344 if (node.isThis()) { 346 if (node.isThis()) {
345 if (!inInstanceContext) { 347 if (!inInstanceContext) {
346 reporter.reportErrorMessage( 348 reporter.reportErrorMessage(
347 node, MessageKind.NO_INSTANCE_AVAILABLE, {'name': node}); 349 node, MessageKind.NO_INSTANCE_AVAILABLE, {'name': node});
348 } 350 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 496
495 ResolutionResult visitAssert(Assert node) { 497 ResolutionResult visitAssert(Assert node) {
496 if (!compiler.enableAssertMessage) { 498 if (!compiler.enableAssertMessage) {
497 if (node.hasMessage) { 499 if (node.hasMessage) {
498 reporter.reportErrorMessage( 500 reporter.reportErrorMessage(
499 node, MessageKind.EXPERIMENTAL_ASSERT_MESSAGE); 501 node, MessageKind.EXPERIMENTAL_ASSERT_MESSAGE);
500 } 502 }
501 } 503 }
502 // TODO(sra): We could completely ignore the assert in production mode if we 504 // TODO(sra): We could completely ignore the assert in production mode if we
503 // didn't need it to be resolved for type checking. 505 // didn't need it to be resolved for type checking.
504 registry.registerAssert(node.hasMessage); 506 registry.registerFeature(
507 node.hasMessage ? Feature.ASSERT_WITH_MESSAGE : Feature.ASSERT);
505 visit(node.condition); 508 visit(node.condition);
506 visit(node.message); 509 visit(node.message);
507 return const NoneResult(); 510 return const NoneResult();
508 } 511 }
509 512
510 ResolutionResult visitCascade(Cascade node) { 513 ResolutionResult visitCascade(Cascade node) {
511 visit(node.expression); 514 visit(node.expression);
512 return const NoneResult(); 515 return const NoneResult();
513 } 516 }
514 517
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 } 771 }
769 772
770 /// Check that access to `super` is currently allowed. Returns an 773 /// Check that access to `super` is currently allowed. Returns an
771 /// [AccessSemantics] in case of an error, `null` otherwise. 774 /// [AccessSemantics] in case of an error, `null` otherwise.
772 AccessSemantics checkSuperAccess(Send node) { 775 AccessSemantics checkSuperAccess(Send node) {
773 if (!inInstanceContext) { 776 if (!inInstanceContext) {
774 ErroneousElement error = reportAndCreateErroneousElement( 777 ErroneousElement error = reportAndCreateErroneousElement(
775 node, 'super', 778 node, 'super',
776 MessageKind.NO_SUPER_IN_STATIC, {}, 779 MessageKind.NO_SUPER_IN_STATIC, {},
777 isError: true); 780 isError: true);
778 registry.registerCompileTimeError(error); 781 registry.registerFeature(Feature.COMPILE_TIME_ERROR);
779 return new StaticAccess.invalid(error); 782 return new StaticAccess.invalid(error);
780 } 783 }
781 if (node.isConditional) { 784 if (node.isConditional) {
782 // `super?.foo` is not allowed. 785 // `super?.foo` is not allowed.
783 ErroneousElement error = reportAndCreateErroneousElement( 786 ErroneousElement error = reportAndCreateErroneousElement(
784 node, 'super', 787 node, 'super',
785 MessageKind.INVALID_USE_OF_SUPER, {}, 788 MessageKind.INVALID_USE_OF_SUPER, {},
786 isError: true); 789 isError: true);
787 registry.registerCompileTimeError(error); 790 registry.registerFeature(Feature.COMPILE_TIME_ERROR);
788 return new StaticAccess.invalid(error); 791 return new StaticAccess.invalid(error);
789 } 792 }
790 if (currentClass.supertype == null) { 793 if (currentClass.supertype == null) {
791 // This is just to guard against internal errors, so no need 794 // This is just to guard against internal errors, so no need
792 // for a real error message. 795 // for a real error message.
793 ErroneousElement error = reportAndCreateErroneousElement( 796 ErroneousElement error = reportAndCreateErroneousElement(
794 node, 'super', 797 node, 'super',
795 MessageKind.GENERIC, 798 MessageKind.GENERIC,
796 {'text': "Object has no superclass"}, 799 {'text': "Object has no superclass"},
797 isError: true); 800 isError: true);
798 registry.registerCompileTimeError(error); 801 registry.registerFeature(Feature.COMPILE_TIME_ERROR);
799 return new StaticAccess.invalid(error); 802 return new StaticAccess.invalid(error);
800 } 803 }
801 registry.registerSuperUse(node); 804 registry.registerSuperUse(node);
802 return null; 805 return null;
803 } 806 }
804 807
805 /// Check that access to `this` is currently allowed. Returns an 808 /// Check that access to `this` is currently allowed. Returns an
806 /// [AccessSemantics] in case of an error, `null` otherwise. 809 /// [AccessSemantics] in case of an error, `null` otherwise.
807 AccessSemantics checkThisAccess(Send node) { 810 AccessSemantics checkThisAccess(Send node) {
808 if (!inInstanceContext) { 811 if (!inInstanceContext) {
809 ErroneousElement error = reportAndCreateErroneousElement( 812 ErroneousElement error = reportAndCreateErroneousElement(
810 node, 'this', 813 node, 'this',
811 MessageKind.NO_THIS_AVAILABLE, const {}, 814 MessageKind.NO_THIS_AVAILABLE, const {},
812 isError: true); 815 isError: true);
813 registry.registerCompileTimeError(error); 816 registry.registerFeature(Feature.COMPILE_TIME_ERROR);
814 return new StaticAccess.invalid(error); 817 return new StaticAccess.invalid(error);
815 } 818 }
816 return null; 819 return null;
817 } 820 }
818 821
819 /// Compute the [AccessSemantics] corresponding to a super access of [target]. 822 /// Compute the [AccessSemantics] corresponding to a super access of [target].
820 AccessSemantics computeSuperAccessSemantics(Spannable node, Element target) { 823 AccessSemantics computeSuperAccessSemantics(Spannable node, Element target) {
821 if (target.isMalformed) { 824 if (target.isMalformed) {
822 return new StaticAccess.unresolvedSuper(target); 825 return new StaticAccess.unresolvedSuper(target);
823 } else if (target.isGetter) { 826 } else if (target.isGetter) {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 node, name.text, MessageKind.NO_SUCH_SUPER_MEMBER, 1031 node, name.text, MessageKind.NO_SUCH_SUPER_MEMBER,
1029 {'className': currentClass.name, 'memberName': name}); 1032 {'className': currentClass.name, 'memberName': name});
1030 } 1033 }
1031 if (target == null) { 1034 if (target == null) {
1032 // If a setter wasn't resolved, use the [ErroneousElement]. 1035 // If a setter wasn't resolved, use the [ErroneousElement].
1033 target = error; 1036 target = error;
1034 } 1037 }
1035 // We still need to register the invocation, because we might 1038 // We still need to register the invocation, because we might
1036 // call [:super.noSuchMethod:] which calls [JSInvocationMirror._invokeOn]. 1039 // call [:super.noSuchMethod:] which calls [JSInvocationMirror._invokeOn].
1037 registry.registerDynamicUse(new DynamicUse(selector, null)); 1040 registry.registerDynamicUse(new DynamicUse(selector, null));
1038 registry.registerSuperNoSuchMethod(); 1041 registry.registerFeature(Feature.SUPER_NO_SUCH_METHOD);
1039 } 1042 }
1040 return computeSuperAccessSemantics(node, target); 1043 return computeSuperAccessSemantics(node, target);
1041 } 1044 }
1042 1045
1043 /// Compute the [AccessSemantics] for accessing the name of [selector] on the 1046 /// Compute the [AccessSemantics] for accessing the name of [selector] on the
1044 /// super class. 1047 /// super class.
1045 /// 1048 ///
1046 /// If no matching super member is found and error is reported and 1049 /// If no matching super member is found and error is reported and
1047 /// `noSuchMethod` on `super` is registered. Furthermore, if [alternateName] 1050 /// `noSuchMethod` on `super` is registered. Furthermore, if [alternateName]
1048 /// is provided, the [AccessSemantics] corresponding to the alternate name is 1051 /// is provided, the [AccessSemantics] corresponding to the alternate name is
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 registry.registerDynamicUse( 1107 registry.registerDynamicUse(
1105 new DynamicUse(getterSelector, null)); 1108 new DynamicUse(getterSelector, null));
1106 } 1109 }
1107 if (setterError) { 1110 if (setterError) {
1108 // We still need to register the invocation, because we might 1111 // We still need to register the invocation, because we might
1109 // call [:super.noSuchMethod:] which calls [JSInvocationMirror._invokeOn]. 1112 // call [:super.noSuchMethod:] which calls [JSInvocationMirror._invokeOn].
1110 registry.registerDynamicUse( 1113 registry.registerDynamicUse(
1111 new DynamicUse(setterSelector, null)); 1114 new DynamicUse(setterSelector, null));
1112 } 1115 }
1113 if (getterError || setterError) { 1116 if (getterError || setterError) {
1114 registry.registerSuperNoSuchMethod(); 1117 registry.registerFeature(Feature.SUPER_NO_SUCH_METHOD);
1115 } 1118 }
1116 return computeCompoundSuperAccessSemantics( 1119 return computeCompoundSuperAccessSemantics(
1117 node, getter, setter, isIndex: isIndex); 1120 node, getter, setter, isIndex: isIndex);
1118 } 1121 }
1119 1122
1120 /// Resolve [node] as a subexpression that is _not_ the prefix of a member 1123 /// Resolve [node] as a subexpression that is _not_ the prefix of a member
1121 /// access. For instance `a` in `a + b`, as opposed to `a` in `a.b`. 1124 /// access. For instance `a` in `a + b`, as opposed to `a` in `a.b`.
1122 ResolutionResult visitExpression(Node node) { 1125 ResolutionResult visitExpression(Node node) {
1123 bool oldSendIsMemberAccess = sendIsMemberAccess; 1126 bool oldSendIsMemberAccess = sendIsMemberAccess;
1124 sendIsMemberAccess = false; 1127 sendIsMemberAccess = false;
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1601 node, selector, alternateName: name.setter); 1604 node, selector, alternateName: name.setter);
1602 } 1605 }
1603 if (node.isCall) { 1606 if (node.isCall) {
1604 bool isIncompatibleInvoke = false; 1607 bool isIncompatibleInvoke = false;
1605 switch (semantics.kind) { 1608 switch (semantics.kind) {
1606 case AccessKind.SUPER_METHOD: 1609 case AccessKind.SUPER_METHOD:
1607 MethodElementX superMethod = semantics.element; 1610 MethodElementX superMethod = semantics.element;
1608 superMethod.computeType(resolution); 1611 superMethod.computeType(resolution);
1609 if (!callStructure.signatureApplies( 1612 if (!callStructure.signatureApplies(
1610 superMethod.functionSignature)) { 1613 superMethod.functionSignature)) {
1611 registry.registerThrowNoSuchMethod(); 1614 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
1612 registry.registerDynamicUse( 1615 registry.registerDynamicUse(
1613 new DynamicUse(selector, null)); 1616 new DynamicUse(selector, null));
1614 registry.registerSuperNoSuchMethod(); 1617 registry.registerFeature(Feature.SUPER_NO_SUCH_METHOD);
1615 isIncompatibleInvoke = true; 1618 isIncompatibleInvoke = true;
1616 } else { 1619 } else {
1617 registry.registerStaticUse( 1620 registry.registerStaticUse(
1618 new StaticUse.superInvoke(semantics.element, callStructure)); 1621 new StaticUse.superInvoke(semantics.element, callStructure));
1619 } 1622 }
1620 break; 1623 break;
1621 case AccessKind.SUPER_FIELD: 1624 case AccessKind.SUPER_FIELD:
1622 case AccessKind.SUPER_FINAL_FIELD: 1625 case AccessKind.SUPER_FINAL_FIELD:
1623 case AccessKind.SUPER_GETTER: 1626 case AccessKind.SUPER_GETTER:
1624 registry.registerStaticUse( 1627 registry.registerStaticUse(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1738 } 1741 }
1739 } 1742 }
1740 } 1743 }
1741 1744
1742 /// Handle qualified access to an unresolved static class member, like `a.b` 1745 /// Handle qualified access to an unresolved static class member, like `a.b`
1743 /// or `a.b()` where `a` is a class and `b` is unresolved. 1746 /// or `a.b()` where `a` is a class and `b` is unresolved.
1744 ResolutionResult handleUnresolvedStaticMemberAccess( 1747 ResolutionResult handleUnresolvedStaticMemberAccess(
1745 Send node, Name name, ClassElement receiverClass) { 1748 Send node, Name name, ClassElement receiverClass) {
1746 // TODO(johnniwinther): Share code with [handleStaticInstanceMemberAccess] 1749 // TODO(johnniwinther): Share code with [handleStaticInstanceMemberAccess]
1747 // and [handlePrivateStaticMemberAccess]. 1750 // and [handlePrivateStaticMemberAccess].
1748 registry.registerThrowNoSuchMethod(); 1751 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
1749 // TODO(johnniwinther): Produce a different error if [name] is resolves to 1752 // TODO(johnniwinther): Produce a different error if [name] is resolves to
1750 // a constructor. 1753 // a constructor.
1751 1754
1752 // TODO(johnniwinther): With the simplified [TreeElements] invariant, 1755 // TODO(johnniwinther): With the simplified [TreeElements] invariant,
1753 // try to resolve injected elements if [currentClass] is in the patch 1756 // try to resolve injected elements if [currentClass] is in the patch
1754 // library of [receiverClass]. 1757 // library of [receiverClass].
1755 1758
1756 // TODO(karlklose): this should be reported by the caller of 1759 // TODO(karlklose): this should be reported by the caller of
1757 // [resolveSend] to select better warning messages for getters and 1760 // [resolveSend] to select better warning messages for getters and
1758 // setters. 1761 // setters.
1759 ErroneousElement error = reportAndCreateErroneousElement( 1762 ErroneousElement error = reportAndCreateErroneousElement(
1760 node, name.text, MessageKind.MEMBER_NOT_FOUND, 1763 node, name.text, MessageKind.MEMBER_NOT_FOUND,
1761 {'className': receiverClass.name, 'memberName': name.text}); 1764 {'className': receiverClass.name, 'memberName': name.text});
1762 // TODO(johnniwinther): Add an [AccessSemantics] for unresolved static 1765 // TODO(johnniwinther): Add an [AccessSemantics] for unresolved static
1763 // member access. 1766 // member access.
1764 return handleErroneousAccess( 1767 return handleErroneousAccess(
1765 node, name, new StaticAccess.unresolved(error)); 1768 node, name, new StaticAccess.unresolved(error));
1766 } 1769 }
1767 1770
1768 /// Handle qualified update to an unresolved static class member, like 1771 /// Handle qualified update to an unresolved static class member, like
1769 /// `a.b = c` or `a.b++` where `a` is a class and `b` is unresolved. 1772 /// `a.b = c` or `a.b++` where `a` is a class and `b` is unresolved.
1770 ResolutionResult handleUnresolvedStaticMemberUpdate( 1773 ResolutionResult handleUnresolvedStaticMemberUpdate(
1771 SendSet node, Name name, ClassElement receiverClass) { 1774 SendSet node, Name name, ClassElement receiverClass) {
1772 // TODO(johnniwinther): Share code with [handleStaticInstanceMemberUpdate] 1775 // TODO(johnniwinther): Share code with [handleStaticInstanceMemberUpdate]
1773 // and [handlePrivateStaticMemberUpdate]. 1776 // and [handlePrivateStaticMemberUpdate].
1774 registry.registerThrowNoSuchMethod(); 1777 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
1775 // TODO(johnniwinther): Produce a different error if [name] is resolves to 1778 // TODO(johnniwinther): Produce a different error if [name] is resolves to
1776 // a constructor. 1779 // a constructor.
1777 1780
1778 // TODO(johnniwinther): With the simplified [TreeElements] invariant, 1781 // TODO(johnniwinther): With the simplified [TreeElements] invariant,
1779 // try to resolve injected elements if [currentClass] is in the patch 1782 // try to resolve injected elements if [currentClass] is in the patch
1780 // library of [receiverClass]. 1783 // library of [receiverClass].
1781 1784
1782 // TODO(johnniwinther): Produce a different error for complex update. 1785 // TODO(johnniwinther): Produce a different error for complex update.
1783 ErroneousElement error = reportAndCreateErroneousElement( 1786 ErroneousElement error = reportAndCreateErroneousElement(
1784 node, name.text, MessageKind.MEMBER_NOT_FOUND, 1787 node, name.text, MessageKind.MEMBER_NOT_FOUND,
1785 {'className': receiverClass.name, 'memberName': name.text}); 1788 {'className': receiverClass.name, 'memberName': name.text});
1786 // TODO(johnniwinther): Add an [AccessSemantics] for unresolved static 1789 // TODO(johnniwinther): Add an [AccessSemantics] for unresolved static
1787 // member access. 1790 // member access.
1788 return handleUpdate(node, name, new StaticAccess.unresolved(error)); 1791 return handleUpdate(node, name, new StaticAccess.unresolved(error));
1789 } 1792 }
1790 1793
1791 /// Handle qualified access of an instance member, like `a.b` or `a.b()` where 1794 /// Handle qualified access of an instance member, like `a.b` or `a.b()` where
1792 /// `a` is a class and `b` is a non-static member. 1795 /// `a` is a class and `b` is a non-static member.
1793 ResolutionResult handleStaticInstanceMemberAccess( 1796 ResolutionResult handleStaticInstanceMemberAccess(
1794 Send node, Name name, ClassElement receiverClass, Element member) { 1797 Send node, Name name, ClassElement receiverClass, Element member) {
1795 1798
1796 registry.registerThrowNoSuchMethod(); 1799 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
1797 // TODO(johnniwinther): With the simplified [TreeElements] invariant, 1800 // TODO(johnniwinther): With the simplified [TreeElements] invariant,
1798 // try to resolve injected elements if [currentClass] is in the patch 1801 // try to resolve injected elements if [currentClass] is in the patch
1799 // library of [receiverClass]. 1802 // library of [receiverClass].
1800 1803
1801 // TODO(karlklose): this should be reported by the caller of 1804 // TODO(karlklose): this should be reported by the caller of
1802 // [resolveSend] to select better warning messages for getters and 1805 // [resolveSend] to select better warning messages for getters and
1803 // setters. 1806 // setters.
1804 ErroneousElement error = reportAndCreateErroneousElement( 1807 ErroneousElement error = reportAndCreateErroneousElement(
1805 node, name.text, MessageKind.MEMBER_NOT_STATIC, 1808 node, name.text, MessageKind.MEMBER_NOT_STATIC,
1806 {'className': receiverClass.name, 'memberName': name}); 1809 {'className': receiverClass.name, 'memberName': name});
1807 1810
1808 // TODO(johnniwinther): Add an [AccessSemantics] for statically accessed 1811 // TODO(johnniwinther): Add an [AccessSemantics] for statically accessed
1809 // instance members. 1812 // instance members.
1810 return handleErroneousAccess( 1813 return handleErroneousAccess(
1811 node, name, new StaticAccess.unresolved(error)); 1814 node, name, new StaticAccess.unresolved(error));
1812 } 1815 }
1813 1816
1814 /// Handle qualified update of an instance member, like `a.b = c` or `a.b++` 1817 /// Handle qualified update of an instance member, like `a.b = c` or `a.b++`
1815 /// where `a` is a class and `b` is a non-static member. 1818 /// where `a` is a class and `b` is a non-static member.
1816 ResolutionResult handleStaticInstanceMemberUpdate( 1819 ResolutionResult handleStaticInstanceMemberUpdate(
1817 SendSet node, Name name, ClassElement receiverClass, Element member) { 1820 SendSet node, Name name, ClassElement receiverClass, Element member) {
1818 1821
1819 registry.registerThrowNoSuchMethod(); 1822 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
1820 // TODO(johnniwinther): With the simplified [TreeElements] invariant, 1823 // TODO(johnniwinther): With the simplified [TreeElements] invariant,
1821 // try to resolve injected elements if [currentClass] is in the patch 1824 // try to resolve injected elements if [currentClass] is in the patch
1822 // library of [receiverClass]. 1825 // library of [receiverClass].
1823 1826
1824 // TODO(johnniwinther): Produce a different error for complex update. 1827 // TODO(johnniwinther): Produce a different error for complex update.
1825 ErroneousElement error = reportAndCreateErroneousElement( 1828 ErroneousElement error = reportAndCreateErroneousElement(
1826 node, name.text, MessageKind.MEMBER_NOT_STATIC, 1829 node, name.text, MessageKind.MEMBER_NOT_STATIC,
1827 {'className': receiverClass.name, 'memberName': name}); 1830 {'className': receiverClass.name, 'memberName': name});
1828 1831
1829 // TODO(johnniwinther): Add an [AccessSemantics] for statically accessed 1832 // TODO(johnniwinther): Add an [AccessSemantics] for statically accessed
1830 // instance members. 1833 // instance members.
1831 return handleUpdate(node, name, new StaticAccess.unresolved(error)); 1834 return handleUpdate(node, name, new StaticAccess.unresolved(error));
1832 } 1835 }
1833 1836
1834 /// Handle qualified access of an inaccessible private static class member, 1837 /// Handle qualified access of an inaccessible private static class member,
1835 /// like `a._b` or `a._b()` where `a` is class, `_b` is static member of `a` 1838 /// like `a._b` or `a._b()` where `a` is class, `_b` is static member of `a`
1836 /// but `a` is not defined in the current library. 1839 /// but `a` is not defined in the current library.
1837 ResolutionResult handlePrivateStaticMemberAccess( 1840 ResolutionResult handlePrivateStaticMemberAccess(
1838 Send node, Name name, ClassElement receiverClass, Element member) { 1841 Send node, Name name, ClassElement receiverClass, Element member) {
1839 registry.registerThrowNoSuchMethod(); 1842 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
1840 ErroneousElement error = reportAndCreateErroneousElement( 1843 ErroneousElement error = reportAndCreateErroneousElement(
1841 node, name.text, MessageKind.PRIVATE_ACCESS, 1844 node, name.text, MessageKind.PRIVATE_ACCESS,
1842 {'libraryName': member.library.libraryOrScriptName, 1845 {'libraryName': member.library.libraryOrScriptName,
1843 'name': name}); 1846 'name': name});
1844 // TODO(johnniwinther): Add an [AccessSemantics] for unresolved static 1847 // TODO(johnniwinther): Add an [AccessSemantics] for unresolved static
1845 // member access. 1848 // member access.
1846 return handleErroneousAccess( 1849 return handleErroneousAccess(
1847 node, name, new StaticAccess.unresolved(error)); 1850 node, name, new StaticAccess.unresolved(error));
1848 } 1851 }
1849 1852
1850 /// Handle qualified update of an inaccessible private static class member, 1853 /// Handle qualified update of an inaccessible private static class member,
1851 /// like `a._b = c` or `a._b++` where `a` is class, `_b` is static member of 1854 /// like `a._b = c` or `a._b++` where `a` is class, `_b` is static member of
1852 /// `a` but `a` is not defined in the current library. 1855 /// `a` but `a` is not defined in the current library.
1853 ResolutionResult handlePrivateStaticMemberUpdate( 1856 ResolutionResult handlePrivateStaticMemberUpdate(
1854 SendSet node, Name name, ClassElement receiverClass, Element member) { 1857 SendSet node, Name name, ClassElement receiverClass, Element member) {
1855 registry.registerThrowNoSuchMethod(); 1858 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
1856 ErroneousElement error = reportAndCreateErroneousElement( 1859 ErroneousElement error = reportAndCreateErroneousElement(
1857 node, name.text, MessageKind.PRIVATE_ACCESS, 1860 node, name.text, MessageKind.PRIVATE_ACCESS,
1858 {'libraryName': member.library.libraryOrScriptName, 1861 {'libraryName': member.library.libraryOrScriptName,
1859 'name': name}); 1862 'name': name});
1860 // TODO(johnniwinther): Add an [AccessSemantics] for unresolved static 1863 // TODO(johnniwinther): Add an [AccessSemantics] for unresolved static
1861 // member access. 1864 // member access.
1862 return handleUpdate(node, name, new StaticAccess.unresolved(error)); 1865 return handleUpdate(node, name, new StaticAccess.unresolved(error));
1863 } 1866 }
1864 1867
1865 /// Handle qualified access to a static member, like `a.b` or `a.b()` where 1868 /// Handle qualified access to a static member, like `a.b` or `a.b()` where
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 Name name, 1935 Name name,
1933 TypeVariableElement element) { 1936 TypeVariableElement element) {
1934 AccessSemantics semantics; 1937 AccessSemantics semantics;
1935 if (!Elements.hasAccessToTypeVariables(enclosingElement)) { 1938 if (!Elements.hasAccessToTypeVariables(enclosingElement)) {
1936 // TODO(johnniwinther): Add another access semantics for this. 1939 // TODO(johnniwinther): Add another access semantics for this.
1937 ErroneousElement error = reportAndCreateErroneousElement( 1940 ErroneousElement error = reportAndCreateErroneousElement(
1938 node, name.text, 1941 node, name.text,
1939 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER, 1942 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER,
1940 {'typeVariableName': name}, 1943 {'typeVariableName': name},
1941 isError: true); 1944 isError: true);
1942 registry.registerCompileTimeError(error); 1945 registry.registerFeature(Feature.COMPILE_TIME_ERROR);
1943 semantics = new StaticAccess.invalid(error); 1946 semantics = new StaticAccess.invalid(error);
1944 // TODO(johnniwinther): Clean up registration of elements and selectors 1947 // TODO(johnniwinther): Clean up registration of elements and selectors
1945 // for this case. 1948 // for this case.
1946 } else { 1949 } else {
1947 semantics = new StaticAccess.typeParameterTypeLiteral(element); 1950 semantics = new StaticAccess.typeParameterTypeLiteral(element);
1948 } 1951 }
1949 1952
1950 registry.useElement(node, element); 1953 registry.useElement(node, element);
1951 registry.registerTypeLiteral(node, element.type); 1954 registry.registerTypeLiteral(node, element.type);
1952 1955
(...skipping 21 matching lines...) Expand all
1974 Name name, 1977 Name name,
1975 TypeVariableElement element) { 1978 TypeVariableElement element) {
1976 AccessSemantics semantics; 1979 AccessSemantics semantics;
1977 if (!Elements.hasAccessToTypeVariables(enclosingElement)) { 1980 if (!Elements.hasAccessToTypeVariables(enclosingElement)) {
1978 // TODO(johnniwinther): Add another access semantics for this. 1981 // TODO(johnniwinther): Add another access semantics for this.
1979 ErroneousElement error = reportAndCreateErroneousElement( 1982 ErroneousElement error = reportAndCreateErroneousElement(
1980 node, name.text, 1983 node, name.text,
1981 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER, 1984 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER,
1982 {'typeVariableName': name}, 1985 {'typeVariableName': name},
1983 isError: true); 1986 isError: true);
1984 registry.registerCompileTimeError(error); 1987 registry.registerFeature(Feature.COMPILE_TIME_ERROR);
1985 semantics = new StaticAccess.invalid(error); 1988 semantics = new StaticAccess.invalid(error);
1986 } else { 1989 } else {
1987 ErroneousElement error; 1990 ErroneousElement error;
1988 if (node.isIfNullAssignment) { 1991 if (node.isIfNullAssignment) {
1989 error = reportAndCreateErroneousElement( 1992 error = reportAndCreateErroneousElement(
1990 node.selector, name.text, 1993 node.selector, name.text,
1991 MessageKind.IF_NULL_ASSIGNING_TYPE, const {}); 1994 MessageKind.IF_NULL_ASSIGNING_TYPE, const {});
1992 // TODO(23998): Remove these when all information goes through 1995 // TODO(23998): Remove these when all information goes through
1993 // the [SendStructure]. 1996 // the [SendStructure].
1994 registry.useElement(node.selector, element); 1997 registry.useElement(node.selector, element);
1995 } else { 1998 } else {
1996 error = reportAndCreateErroneousElement( 1999 error = reportAndCreateErroneousElement(
1997 node.selector, name.text, 2000 node.selector, name.text,
1998 MessageKind.ASSIGNING_TYPE, const {}); 2001 MessageKind.ASSIGNING_TYPE, const {});
1999 } 2002 }
2000 2003
2001 // TODO(23998): Remove this when all information goes through 2004 // TODO(23998): Remove this when all information goes through
2002 // the [SendStructure]. 2005 // the [SendStructure].
2003 registry.useElement(node, error); 2006 registry.useElement(node, error);
2004 // TODO(johnniwinther): Register only on read? 2007 // TODO(johnniwinther): Register only on read?
2005 registry.registerTypeLiteral(node, element.type); 2008 registry.registerTypeLiteral(node, element.type);
2006 registry.registerThrowNoSuchMethod(); 2009 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
2007 semantics = new StaticAccess.typeParameterTypeLiteral(element); 2010 semantics = new StaticAccess.typeParameterTypeLiteral(element);
2008 } 2011 }
2009 return handleUpdate(node, name, semantics); 2012 return handleUpdate(node, name, semantics);
2010 } 2013 }
2011 2014
2012 /// Handle access to a constant type literal of [type]. 2015 /// Handle access to a constant type literal of [type].
2013 // TODO(johnniwinther): Remove [name] when [Selector] is not required for the 2016 // TODO(johnniwinther): Remove [name] when [Selector] is not required for the
2014 // the [GetStructure]. 2017 // the [GetStructure].
2015 // TODO(johnniwinther): Remove [element] when it is no longer needed for 2018 // TODO(johnniwinther): Remove [element] when it is no longer needed for
2016 // evaluating constants. 2019 // evaluating constants.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2075 } else { 2078 } else {
2076 error = reportAndCreateErroneousElement( 2079 error = reportAndCreateErroneousElement(
2077 node.selector, name.text, 2080 node.selector, name.text,
2078 MessageKind.ASSIGNING_TYPE, const {}); 2081 MessageKind.ASSIGNING_TYPE, const {});
2079 } 2082 }
2080 2083
2081 // TODO(23998): Remove this when all information goes through 2084 // TODO(23998): Remove this when all information goes through
2082 // the [SendStructure]. 2085 // the [SendStructure].
2083 registry.useElement(node, error); 2086 registry.useElement(node, error);
2084 registry.registerTypeLiteral(node, type); 2087 registry.registerTypeLiteral(node, type);
2085 registry.registerThrowNoSuchMethod(); 2088 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
2086 2089
2087 return handleUpdate(node, name, semantics); 2090 return handleUpdate(node, name, semantics);
2088 } 2091 }
2089 2092
2090 /// Handle access to a type literal of a typedef. Like `F` or 2093 /// Handle access to a type literal of a typedef. Like `F` or
2091 /// `F()` where 'F' is typedef. 2094 /// `F()` where 'F' is typedef.
2092 ResolutionResult handleTypedefTypeLiteralAccess( 2095 ResolutionResult handleTypedefTypeLiteralAccess(
2093 Send node, 2096 Send node,
2094 Name name, 2097 Name name,
2095 TypedefElement typdef) { 2098 TypedefElement typdef) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
2204 } 2207 }
2205 2208
2206 /// Handle qualified [Send] where the receiver resolves to a [prefix], 2209 /// Handle qualified [Send] where the receiver resolves to a [prefix],
2207 /// like `prefix.toplevelFunction()` or `prefix.Class.staticField` where 2210 /// like `prefix.toplevelFunction()` or `prefix.Class.staticField` where
2208 /// `prefix` is a library prefix. 2211 /// `prefix` is a library prefix.
2209 ResolutionResult handleLibraryPrefixSend( 2212 ResolutionResult handleLibraryPrefixSend(
2210 Send node, Name name, PrefixElement prefix) { 2213 Send node, Name name, PrefixElement prefix) {
2211 ResolutionResult result; 2214 ResolutionResult result;
2212 Element member = prefix.lookupLocalMember(name.text); 2215 Element member = prefix.lookupLocalMember(name.text);
2213 if (member == null) { 2216 if (member == null) {
2214 registry.registerThrowNoSuchMethod(); 2217 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
2215 Element error = reportAndCreateErroneousElement( 2218 Element error = reportAndCreateErroneousElement(
2216 node, name.text, MessageKind.NO_SUCH_LIBRARY_MEMBER, 2219 node, name.text, MessageKind.NO_SUCH_LIBRARY_MEMBER,
2217 {'libraryName': prefix.name, 'memberName': name}); 2220 {'libraryName': prefix.name, 'memberName': name});
2218 result = handleUnresolvedAccess(node, name, error); 2221 result = handleUnresolvedAccess(node, name, error);
2219 } else { 2222 } else {
2220 result = handleResolvedSend(node, name, member); 2223 result = handleResolvedSend(node, name, member);
2221 } 2224 }
2222 if (result.kind == ResultKind.PREFIX) { 2225 if (result.kind == ResultKind.PREFIX) {
2223 // [member] is a class prefix of a static access like `prefix.Class` of 2226 // [member] is a class prefix of a static access like `prefix.Class` of
2224 // `prefix.Class.foo`. No need to call [handleDeferredAccess]; it will 2227 // `prefix.Class.foo`. No need to call [handleDeferredAccess]; it will
2225 // called on the parent `prefix.Class.foo` node. 2228 // called on the parent `prefix.Class.foo` node.
2226 result = new PrefixResult(prefix, result.element); 2229 result = new PrefixResult(prefix, result.element);
2227 } else if (prefix.isDeferred && 2230 } else if (prefix.isDeferred &&
2228 (member == null || !member.isDeferredLoaderGetter)) { 2231 (member == null || !member.isDeferredLoaderGetter)) {
2229 result = handleDeferredAccess(node, prefix, result); 2232 result = handleDeferredAccess(node, prefix, result);
2230 } 2233 }
2231 return result; 2234 return result;
2232 } 2235 }
2233 2236
2234 /// Handle qualified [SendSet] where the receiver resolves to a [prefix], 2237 /// Handle qualified [SendSet] where the receiver resolves to a [prefix],
2235 /// like `prefix.toplevelField = b` or `prefix.Class.staticField++` where 2238 /// like `prefix.toplevelField = b` or `prefix.Class.staticField++` where
2236 /// `prefix` is a library prefix. 2239 /// `prefix` is a library prefix.
2237 ResolutionResult handleLibraryPrefixSendSet( 2240 ResolutionResult handleLibraryPrefixSendSet(
2238 SendSet node, Name name, PrefixElement prefix) { 2241 SendSet node, Name name, PrefixElement prefix) {
2239 ResolutionResult result; 2242 ResolutionResult result;
2240 Element member = prefix.lookupLocalMember(name.text); 2243 Element member = prefix.lookupLocalMember(name.text);
2241 if (member == null) { 2244 if (member == null) {
2242 registry.registerThrowNoSuchMethod(); 2245 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
2243 Element error = reportAndCreateErroneousElement( 2246 Element error = reportAndCreateErroneousElement(
2244 node, name.text, MessageKind.NO_SUCH_LIBRARY_MEMBER, 2247 node, name.text, MessageKind.NO_SUCH_LIBRARY_MEMBER,
2245 {'libraryName': prefix.name, 'memberName': name}); 2248 {'libraryName': prefix.name, 'memberName': name});
2246 return handleUpdate(node, name, new StaticAccess.unresolved(error)); 2249 return handleUpdate(node, name, new StaticAccess.unresolved(error));
2247 } else { 2250 } else {
2248 result = handleResolvedSendSet(node, name, member); 2251 result = handleResolvedSendSet(node, name, member);
2249 } 2252 }
2250 if (result.kind == ResultKind.PREFIX) { 2253 if (result.kind == ResultKind.PREFIX) {
2251 // [member] is a class prefix of a static access like `prefix.Class` of 2254 // [member] is a class prefix of a static access like `prefix.Class` of
2252 // `prefix.Class.foo`. No need to call [handleDeferredAccess]; it will 2255 // `prefix.Class.foo`. No need to call [handleDeferredAccess]; it will
(...skipping 13 matching lines...) Expand all
2266 Send node, 2269 Send node,
2267 Name name, 2270 Name name,
2268 PrefixElement prefix) { 2271 PrefixElement prefix) {
2269 if ((ElementCategory.PREFIX & allowedCategory) == 0) { 2272 if ((ElementCategory.PREFIX & allowedCategory) == 0) {
2270 ErroneousElement error = reportAndCreateErroneousElement( 2273 ErroneousElement error = reportAndCreateErroneousElement(
2271 node, 2274 node,
2272 name.text, 2275 name.text,
2273 MessageKind.PREFIX_AS_EXPRESSION, 2276 MessageKind.PREFIX_AS_EXPRESSION,
2274 {'prefix': name}, 2277 {'prefix': name},
2275 isError: true); 2278 isError: true);
2276 registry.registerCompileTimeError(error); 2279 registry.registerFeature(Feature.COMPILE_TIME_ERROR);
2277 return handleErroneousAccess( 2280 return handleErroneousAccess(
2278 node, name, new StaticAccess.invalid(error)); 2281 node, name, new StaticAccess.invalid(error));
2279 } 2282 }
2280 if (prefix.isDeferred) { 2283 if (prefix.isDeferred) {
2281 // TODO(23998): Remove this when deferred access is detected 2284 // TODO(23998): Remove this when deferred access is detected
2282 // through a [SendStructure]. 2285 // through a [SendStructure].
2283 registry.useElement(node.selector, prefix); 2286 registry.useElement(node.selector, prefix);
2284 } 2287 }
2285 registry.useElement(node, prefix); 2288 registry.useElement(node, prefix);
2286 return new PrefixResult(prefix, null); 2289 return new PrefixResult(prefix, null);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2385 return handleUpdate(node, name, semantics); 2388 return handleUpdate(node, name, semantics);
2386 } 2389 }
2387 2390
2388 /// Handle `this` as a qualified property, like `a.this`. 2391 /// Handle `this` as a qualified property, like `a.this`.
2389 ResolutionResult handleQualifiedThisAccess(Send node, Name name) { 2392 ResolutionResult handleQualifiedThisAccess(Send node, Name name) {
2390 ErroneousElement error = reportAndCreateErroneousElement( 2393 ErroneousElement error = reportAndCreateErroneousElement(
2391 node.selector, 2394 node.selector,
2392 name.text, 2395 name.text,
2393 MessageKind.THIS_PROPERTY, {}, 2396 MessageKind.THIS_PROPERTY, {},
2394 isError: true); 2397 isError: true);
2395 registry.registerCompileTimeError(error); 2398 registry.registerFeature(Feature.COMPILE_TIME_ERROR);
2396 AccessSemantics accessSemantics = new StaticAccess.invalid(error); 2399 AccessSemantics accessSemantics = new StaticAccess.invalid(error);
2397 return handleErroneousAccess(node, name, accessSemantics); 2400 return handleErroneousAccess(node, name, accessSemantics);
2398 } 2401 }
2399 2402
2400 /// Handle a qualified [Send], that is where the receiver is non-null, like 2403 /// Handle a qualified [Send], that is where the receiver is non-null, like
2401 /// `a.b`, `a.b()`, `this.a()` and `super.a()`. 2404 /// `a.b`, `a.b()`, `this.a()` and `super.a()`.
2402 ResolutionResult handleQualifiedSend(Send node) { 2405 ResolutionResult handleQualifiedSend(Send node) {
2403 Identifier selector = node.selector.asIdentifier(); 2406 Identifier selector = node.selector.asIdentifier();
2404 String text = selector.source; 2407 String text = selector.source;
2405 Name name = new Name(text, enclosingElement.library); 2408 Name name = new Name(text, enclosingElement.library);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2504 Send node, 2507 Send node,
2505 Name name, 2508 Name name,
2506 AmbiguousElement element) { 2509 AmbiguousElement element) {
2507 2510
2508 ErroneousElement error = reportAndCreateErroneousElement( 2511 ErroneousElement error = reportAndCreateErroneousElement(
2509 node, 2512 node,
2510 name.text, 2513 name.text,
2511 element.messageKind, 2514 element.messageKind,
2512 element.messageArguments, 2515 element.messageArguments,
2513 infos: element.computeInfos(enclosingElement, reporter)); 2516 infos: element.computeInfos(enclosingElement, reporter));
2514 registry.registerThrowNoSuchMethod(); 2517 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
2515 2518
2516 // TODO(johnniwinther): Support ambiguous access as an [AccessSemantics]. 2519 // TODO(johnniwinther): Support ambiguous access as an [AccessSemantics].
2517 AccessSemantics semantics = new StaticAccess.unresolved(error); 2520 AccessSemantics semantics = new StaticAccess.unresolved(error);
2518 return handleErroneousAccess(node, name, semantics); 2521 return handleErroneousAccess(node, name, semantics);
2519 } 2522 }
2520 2523
2521 /// Handle update to an ambiguous element, that is, a name imported twice. 2524 /// Handle update to an ambiguous element, that is, a name imported twice.
2522 ResolutionResult handleAmbiguousUpdate( 2525 ResolutionResult handleAmbiguousUpdate(
2523 SendSet node, 2526 SendSet node,
2524 Name name, 2527 Name name,
2525 AmbiguousElement element) { 2528 AmbiguousElement element) {
2526 2529
2527 ErroneousElement error = reportAndCreateErroneousElement( 2530 ErroneousElement error = reportAndCreateErroneousElement(
2528 node, 2531 node,
2529 name.text, 2532 name.text,
2530 element.messageKind, 2533 element.messageKind,
2531 element.messageArguments, 2534 element.messageArguments,
2532 infos: element.computeInfos(enclosingElement, reporter)); 2535 infos: element.computeInfos(enclosingElement, reporter));
2533 registry.registerThrowNoSuchMethod(); 2536 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
2534 2537
2535 // TODO(johnniwinther): Support ambiguous access as an [AccessSemantics]. 2538 // TODO(johnniwinther): Support ambiguous access as an [AccessSemantics].
2536 AccessSemantics accessSemantics = new StaticAccess.unresolved(error); 2539 AccessSemantics accessSemantics = new StaticAccess.unresolved(error);
2537 return handleUpdate(node, name, accessSemantics); 2540 return handleUpdate(node, name, accessSemantics);
2538 } 2541 }
2539 2542
2540 /// Report access of an instance [member] from a non-instance context. 2543 /// Report access of an instance [member] from a non-instance context.
2541 AccessSemantics reportStaticInstanceAccess(Send node, Name name) { 2544 AccessSemantics reportStaticInstanceAccess(Send node, Name name) {
2542 ErroneousElement error = reportAndCreateErroneousElement( 2545 ErroneousElement error = reportAndCreateErroneousElement(
2543 node, name.text, 2546 node, name.text,
2544 MessageKind.NO_INSTANCE_AVAILABLE, {'name': name}, 2547 MessageKind.NO_INSTANCE_AVAILABLE, {'name': name},
2545 isError: true); 2548 isError: true);
2546 // TODO(johnniwinther): Support static instance access as an 2549 // TODO(johnniwinther): Support static instance access as an
2547 // [AccessSemantics]. 2550 // [AccessSemantics].
2548 registry.registerCompileTimeError(error); 2551 registry.registerFeature(Feature.COMPILE_TIME_ERROR);
2549 return new StaticAccess.invalid(error); 2552 return new StaticAccess.invalid(error);
2550 } 2553 }
2551 2554
2552 /// Handle access of a parameter, local variable or local function. 2555 /// Handle access of a parameter, local variable or local function.
2553 ResolutionResult handleLocalAccess(Send node, Name name, Element element) { 2556 ResolutionResult handleLocalAccess(Send node, Name name, Element element) {
2554 ResolutionResult result = const NoneResult(); 2557 ResolutionResult result = const NoneResult();
2555 AccessSemantics semantics = computeLocalAccessSemantics(node, element); 2558 AccessSemantics semantics = computeLocalAccessSemantics(node, element);
2556 Selector selector; 2559 Selector selector;
2557 if (node.isCall) { 2560 if (node.isCall) {
2558 CallStructure callStructure = 2561 CallStructure callStructure =
2559 resolveArguments(node.argumentsNode).callStructure; 2562 resolveArguments(node.argumentsNode).callStructure;
2560 selector = new Selector.call(name, callStructure); 2563 selector = new Selector.call(name, callStructure);
2561 bool isIncompatibleInvoke = false; 2564 bool isIncompatibleInvoke = false;
2562 switch (semantics.kind) { 2565 switch (semantics.kind) {
2563 case AccessKind.LOCAL_FUNCTION: 2566 case AccessKind.LOCAL_FUNCTION:
2564 LocalFunctionElementX function = semantics.element; 2567 LocalFunctionElementX function = semantics.element;
2565 function.computeType(resolution); 2568 function.computeType(resolution);
2566 if (!callStructure.signatureApplies(function.functionSignature)) { 2569 if (!callStructure.signatureApplies(function.functionSignature)) {
2567 registry.registerThrowNoSuchMethod(); 2570 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
2568 registry.registerDynamicUse( 2571 registry.registerDynamicUse(
2569 new DynamicUse(selector, null)); 2572 new DynamicUse(selector, null));
2570 isIncompatibleInvoke = true; 2573 isIncompatibleInvoke = true;
2571 } 2574 }
2572 break; 2575 break;
2573 case AccessKind.PARAMETER: 2576 case AccessKind.PARAMETER:
2574 case AccessKind.FINAL_PARAMETER: 2577 case AccessKind.FINAL_PARAMETER:
2575 case AccessKind.LOCAL_VARIABLE: 2578 case AccessKind.LOCAL_VARIABLE:
2576 case AccessKind.FINAL_LOCAL_VARIABLE: 2579 case AccessKind.FINAL_LOCAL_VARIABLE:
2577 selector = callStructure.callSelector; 2580 selector = callStructure.callSelector;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2678 if (enclosingElement != element.enclosingElement) { 2681 if (enclosingElement != element.enclosingElement) {
2679 registry.registerPotentialMutationInClosure(element, node); 2682 registry.registerPotentialMutationInClosure(element, node);
2680 } 2683 }
2681 for (Node scope in promotionScope) { 2684 for (Node scope in promotionScope) {
2682 registry.registerPotentialMutationIn(scope, element, node); 2685 registry.registerPotentialMutationIn(scope, element, node);
2683 } 2686 }
2684 } 2687 }
2685 2688
2686 ResolutionResult result = handleUpdate(node, name, semantics); 2689 ResolutionResult result = handleUpdate(node, name, semantics);
2687 if (error != null) { 2690 if (error != null) {
2688 registry.registerThrowNoSuchMethod(); 2691 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
2689 // TODO(23998): Remove this when all information goes through 2692 // TODO(23998): Remove this when all information goes through
2690 // the [SendStructure]. 2693 // the [SendStructure].
2691 registry.useElement(node, error); 2694 registry.useElement(node, error);
2692 } 2695 }
2693 return result; 2696 return result;
2694 } 2697 }
2695 2698
2696 /// Handle access of a static or top level [element]. 2699 /// Handle access of a static or top level [element].
2697 ResolutionResult handleStaticOrTopLevelAccess( 2700 ResolutionResult handleStaticOrTopLevelAccess(
2698 Send node, Name name, Element element) { 2701 Send node, Name name, Element element) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2730 CallStructure callStructure = argumentsResult.callStructure; 2733 CallStructure callStructure = argumentsResult.callStructure;
2731 selector = new Selector.call(name, callStructure); 2734 selector = new Selector.call(name, callStructure);
2732 2735
2733 bool isIncompatibleInvoke = false; 2736 bool isIncompatibleInvoke = false;
2734 switch (semantics.kind) { 2737 switch (semantics.kind) {
2735 case AccessKind.STATIC_METHOD: 2738 case AccessKind.STATIC_METHOD:
2736 case AccessKind.TOPLEVEL_METHOD: 2739 case AccessKind.TOPLEVEL_METHOD:
2737 MethodElement method = semantics.element; 2740 MethodElement method = semantics.element;
2738 method.computeType(resolution); 2741 method.computeType(resolution);
2739 if (!callStructure.signatureApplies(method.functionSignature)) { 2742 if (!callStructure.signatureApplies(method.functionSignature)) {
2740 registry.registerThrowNoSuchMethod(); 2743 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
2741 registry.registerDynamicUse( 2744 registry.registerDynamicUse(
2742 new DynamicUse(selector, null)); 2745 new DynamicUse(selector, null));
2743 isIncompatibleInvoke = true; 2746 isIncompatibleInvoke = true;
2744 } else { 2747 } else {
2745 registry.registerStaticUse( 2748 registry.registerStaticUse(
2746 new StaticUse.staticInvoke(semantics.element, callStructure)); 2749 new StaticUse.staticInvoke(semantics.element, callStructure));
2747 handleForeignCall(node, semantics.element, callStructure); 2750 handleForeignCall(node, semantics.element, callStructure);
2748 if (method == compiler.identicalFunction && 2751 if (method == compiler.identicalFunction &&
2749 argumentsResult.isValidAsConstant) { 2752 argumentsResult.isValidAsConstant) {
2750 result = new ConstantResult(node, 2753 result = new ConstantResult(node,
(...skipping 11 matching lines...) Expand all
2762 case AccessKind.TOPLEVEL_GETTER: 2765 case AccessKind.TOPLEVEL_GETTER:
2763 registry.registerStaticUse( 2766 registry.registerStaticUse(
2764 new StaticUse.staticGet(semantics.element)); 2767 new StaticUse.staticGet(semantics.element));
2765 selector = callStructure.callSelector; 2768 selector = callStructure.callSelector;
2766 registry.registerDynamicUse( 2769 registry.registerDynamicUse(
2767 new DynamicUse(selector, null)); 2770 new DynamicUse(selector, null));
2768 break; 2771 break;
2769 case AccessKind.STATIC_SETTER: 2772 case AccessKind.STATIC_SETTER:
2770 case AccessKind.TOPLEVEL_SETTER: 2773 case AccessKind.TOPLEVEL_SETTER:
2771 case AccessKind.UNRESOLVED: 2774 case AccessKind.UNRESOLVED:
2772 registry.registerThrowNoSuchMethod(); 2775 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
2773 member = reportAndCreateErroneousElement( 2776 member = reportAndCreateErroneousElement(
2774 node.selector, name.text, 2777 node.selector, name.text,
2775 MessageKind.CANNOT_RESOLVE_GETTER, const {}); 2778 MessageKind.CANNOT_RESOLVE_GETTER, const {});
2776 break; 2779 break;
2777 default: 2780 default:
2778 reporter.internalError(node, 2781 reporter.internalError(node,
2779 "Unexpected statically resolved access $semantics."); 2782 "Unexpected statically resolved access $semantics.");
2780 break; 2783 break;
2781 } 2784 }
2782 registry.registerSendStructure(node, 2785 registry.registerSendStructure(node,
(...skipping 13 matching lines...) Expand all
2796 case AccessKind.STATIC_GETTER: 2799 case AccessKind.STATIC_GETTER:
2797 case AccessKind.TOPLEVEL_FIELD: 2800 case AccessKind.TOPLEVEL_FIELD:
2798 case AccessKind.FINAL_TOPLEVEL_FIELD: 2801 case AccessKind.FINAL_TOPLEVEL_FIELD:
2799 case AccessKind.TOPLEVEL_GETTER: 2802 case AccessKind.TOPLEVEL_GETTER:
2800 registry.registerStaticUse( 2803 registry.registerStaticUse(
2801 new StaticUse.staticGet(semantics.element)); 2804 new StaticUse.staticGet(semantics.element));
2802 break; 2805 break;
2803 case AccessKind.STATIC_SETTER: 2806 case AccessKind.STATIC_SETTER:
2804 case AccessKind.TOPLEVEL_SETTER: 2807 case AccessKind.TOPLEVEL_SETTER:
2805 case AccessKind.UNRESOLVED: 2808 case AccessKind.UNRESOLVED:
2806 registry.registerThrowNoSuchMethod(); 2809 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
2807 member = reportAndCreateErroneousElement( 2810 member = reportAndCreateErroneousElement(
2808 node.selector, name.text, 2811 node.selector, name.text,
2809 MessageKind.CANNOT_RESOLVE_GETTER, const {}); 2812 MessageKind.CANNOT_RESOLVE_GETTER, const {});
2810 break; 2813 break;
2811 default: 2814 default:
2812 reporter.internalError(node, 2815 reporter.internalError(node,
2813 "Unexpected statically resolved access $semantics."); 2816 "Unexpected statically resolved access $semantics.");
2814 break; 2817 break;
2815 } 2818 }
2816 registry.registerSendStructure(node, new GetStructure(semantics)); 2819 registry.registerSendStructure(node, new GetStructure(semantics));
(...skipping 17 matching lines...) Expand all
2834 /// Handle update of a static or top level [element]. 2837 /// Handle update of a static or top level [element].
2835 ResolutionResult handleStaticOrTopLevelUpdate( 2838 ResolutionResult handleStaticOrTopLevelUpdate(
2836 SendSet node, Name name, Element element) { 2839 SendSet node, Name name, Element element) {
2837 AccessSemantics semantics; 2840 AccessSemantics semantics;
2838 if (element.isAbstractField) { 2841 if (element.isAbstractField) {
2839 AbstractFieldElement abstractField = element; 2842 AbstractFieldElement abstractField = element;
2840 if (abstractField.setter == null) { 2843 if (abstractField.setter == null) {
2841 ErroneousElement error = reportAndCreateErroneousElement( 2844 ErroneousElement error = reportAndCreateErroneousElement(
2842 node.selector, name.text, 2845 node.selector, name.text,
2843 MessageKind.CANNOT_RESOLVE_SETTER, const {}); 2846 MessageKind.CANNOT_RESOLVE_SETTER, const {});
2844 registry.registerThrowNoSuchMethod(); 2847 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
2845 2848
2846 if (node.isComplex) { 2849 if (node.isComplex) {
2847 // `a++` or `a += b` where `a` has no setter. 2850 // `a++` or `a += b` where `a` has no setter.
2848 semantics = new CompoundAccessSemantics( 2851 semantics = new CompoundAccessSemantics(
2849 element.isTopLevel 2852 element.isTopLevel
2850 ? CompoundAccessKind.UNRESOLVED_TOPLEVEL_SETTER 2853 ? CompoundAccessKind.UNRESOLVED_TOPLEVEL_SETTER
2851 : CompoundAccessKind.UNRESOLVED_STATIC_SETTER, 2854 : CompoundAccessKind.UNRESOLVED_STATIC_SETTER,
2852 abstractField.getter, 2855 abstractField.getter,
2853 error); 2856 error);
2854 } else { 2857 } else {
2855 // `a = b` where `a` has no setter. 2858 // `a = b` where `a` has no setter.
2856 semantics = element.isTopLevel 2859 semantics = element.isTopLevel
2857 ? new StaticAccess.topLevelGetter(abstractField.getter) 2860 ? new StaticAccess.topLevelGetter(abstractField.getter)
2858 : new StaticAccess.staticGetter(abstractField.getter); 2861 : new StaticAccess.staticGetter(abstractField.getter);
2859 } 2862 }
2860 registry.registerStaticUse( 2863 registry.registerStaticUse(
2861 new StaticUse.staticGet(abstractField.getter)); 2864 new StaticUse.staticGet(abstractField.getter));
2862 } else if (node.isComplex) { 2865 } else if (node.isComplex) {
2863 if (abstractField.getter == null) { 2866 if (abstractField.getter == null) {
2864 ErroneousElement error = reportAndCreateErroneousElement( 2867 ErroneousElement error = reportAndCreateErroneousElement(
2865 node.selector, name.text, 2868 node.selector, name.text,
2866 MessageKind.CANNOT_RESOLVE_GETTER, const {}); 2869 MessageKind.CANNOT_RESOLVE_GETTER, const {});
2867 registry.registerThrowNoSuchMethod(); 2870 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
2868 // `a++` or `a += b` where `a` has no getter. 2871 // `a++` or `a += b` where `a` has no getter.
2869 semantics = new CompoundAccessSemantics( 2872 semantics = new CompoundAccessSemantics(
2870 element.isTopLevel 2873 element.isTopLevel
2871 ? CompoundAccessKind.UNRESOLVED_TOPLEVEL_GETTER 2874 ? CompoundAccessKind.UNRESOLVED_TOPLEVEL_GETTER
2872 : CompoundAccessKind.UNRESOLVED_STATIC_GETTER, 2875 : CompoundAccessKind.UNRESOLVED_STATIC_GETTER,
2873 error, 2876 error,
2874 abstractField.setter); 2877 abstractField.setter);
2875 registry.registerStaticUse( 2878 registry.registerStaticUse(
2876 new StaticUse.staticSet(abstractField.setter)); 2879 new StaticUse.staticSet(abstractField.setter));
2877 } else { 2880 } else {
(...skipping 23 matching lines...) Expand all
2901 // of parse errors to make [element] erroneous. Fix this! 2904 // of parse errors to make [element] erroneous. Fix this!
2902 member.computeType(resolution); 2905 member.computeType(resolution);
2903 if (member.isMalformed) { 2906 if (member.isMalformed) {
2904 // [member] has parse errors. 2907 // [member] has parse errors.
2905 semantics = new StaticAccess.unresolved(member); 2908 semantics = new StaticAccess.unresolved(member);
2906 } else if (member.isFunction) { 2909 } else if (member.isFunction) {
2907 // `a = b`, `a++` or `a += b` where `a` is a function. 2910 // `a = b`, `a++` or `a += b` where `a` is a function.
2908 ErroneousElement error = reportAndCreateErroneousElement( 2911 ErroneousElement error = reportAndCreateErroneousElement(
2909 node.selector, name.text, 2912 node.selector, name.text,
2910 MessageKind.ASSIGNING_METHOD, const {}); 2913 MessageKind.ASSIGNING_METHOD, const {});
2911 registry.registerThrowNoSuchMethod(); 2914 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
2912 if (node.isComplex) { 2915 if (node.isComplex) {
2913 // `a++` or `a += b` where `a` is a function. 2916 // `a++` or `a += b` where `a` is a function.
2914 registry.registerStaticUse( 2917 registry.registerStaticUse(
2915 new StaticUse.staticTearOff(element)); 2918 new StaticUse.staticTearOff(element));
2916 } 2919 }
2917 semantics = member.isTopLevel 2920 semantics = member.isTopLevel
2918 ? new StaticAccess.topLevelMethod(member) 2921 ? new StaticAccess.topLevelMethod(member)
2919 : new StaticAccess.staticMethod(member); 2922 : new StaticAccess.staticMethod(member);
2920 } else { 2923 } else {
2921 // `a = b`, `a++` or `a += b` where `a` is a field. 2924 // `a = b`, `a++` or `a += b` where `a` is a field.
2922 assert(invariant(node, member.isField, 2925 assert(invariant(node, member.isField,
2923 message: "Unexpected element: $member.")); 2926 message: "Unexpected element: $member."));
2924 if (node.isComplex) { 2927 if (node.isComplex) {
2925 // `a++` or `a += b` where `a` is a field. 2928 // `a++` or `a += b` where `a` is a field.
2926 registry.registerStaticUse(new StaticUse.staticGet(member)); 2929 registry.registerStaticUse(new StaticUse.staticGet(member));
2927 } 2930 }
2928 if (member.isFinal || member.isConst) { 2931 if (member.isFinal || member.isConst) {
2929 ErroneousElement error = reportAndCreateErroneousElement( 2932 ErroneousElement error = reportAndCreateErroneousElement(
2930 node.selector, name.text, 2933 node.selector, name.text,
2931 MessageKind.CANNOT_RESOLVE_SETTER, const {}); 2934 MessageKind.CANNOT_RESOLVE_SETTER, const {});
2932 registry.registerThrowNoSuchMethod(); 2935 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
2933 semantics = member.isTopLevel 2936 semantics = member.isTopLevel
2934 ? new StaticAccess.finalTopLevelField(member) 2937 ? new StaticAccess.finalTopLevelField(member)
2935 : new StaticAccess.finalStaticField(member); 2938 : new StaticAccess.finalStaticField(member);
2936 } else { 2939 } else {
2937 registry.registerStaticUse(new StaticUse.staticSet(member)); 2940 registry.registerStaticUse(new StaticUse.staticSet(member));
2938 semantics = member.isTopLevel 2941 semantics = member.isTopLevel
2939 ? new StaticAccess.topLevelField(member) 2942 ? new StaticAccess.topLevelField(member)
2940 : new StaticAccess.staticField(member); 2943 : new StaticAccess.staticField(member);
2941 } 2944 }
2942 } 2945 }
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
3411 switch (semantics.kind) { 3414 switch (semantics.kind) {
3412 case AccessKind.SUPER_FINAL_FIELD: 3415 case AccessKind.SUPER_FINAL_FIELD:
3413 reporter.reportWarningMessage( 3416 reporter.reportWarningMessage(
3414 node, 3417 node,
3415 MessageKind.ASSIGNING_FINAL_FIELD_IN_SUPER, 3418 MessageKind.ASSIGNING_FINAL_FIELD_IN_SUPER,
3416 {'name': name, 3419 {'name': name,
3417 'superclassName': semantics.setter.enclosingClass.name}); 3420 'superclassName': semantics.setter.enclosingClass.name});
3418 // TODO(johnniwinther): This shouldn't be needed. 3421 // TODO(johnniwinther): This shouldn't be needed.
3419 registry.registerDynamicUse( 3422 registry.registerDynamicUse(
3420 new DynamicUse(setterSelector, null)); 3423 new DynamicUse(setterSelector, null));
3421 registry.registerSuperNoSuchMethod(); 3424 registry.registerFeature(Feature.SUPER_NO_SUCH_METHOD);
3422 break; 3425 break;
3423 case AccessKind.SUPER_METHOD: 3426 case AccessKind.SUPER_METHOD:
3424 reporter.reportWarningMessage( 3427 reporter.reportWarningMessage(
3425 node, MessageKind.ASSIGNING_METHOD_IN_SUPER, 3428 node, MessageKind.ASSIGNING_METHOD_IN_SUPER,
3426 {'name': name, 3429 {'name': name,
3427 'superclassName': semantics.setter.enclosingClass.name}); 3430 'superclassName': semantics.setter.enclosingClass.name});
3428 // TODO(johnniwinther): This shouldn't be needed. 3431 // TODO(johnniwinther): This shouldn't be needed.
3429 registry.registerDynamicUse( 3432 registry.registerDynamicUse(
3430 new DynamicUse(setterSelector, null)); 3433 new DynamicUse(setterSelector, null));
3431 registry.registerSuperNoSuchMethod(); 3434 registry.registerFeature(Feature.SUPER_NO_SUCH_METHOD);
3432 break; 3435 break;
3433 case AccessKind.SUPER_FIELD: 3436 case AccessKind.SUPER_FIELD:
3434 case AccessKind.SUPER_SETTER: 3437 case AccessKind.SUPER_SETTER:
3435 registry.registerStaticUse( 3438 registry.registerStaticUse(
3436 new StaticUse.superSet(semantics.setter)); 3439 new StaticUse.superSet(semantics.setter));
3437 break; 3440 break;
3438 default: 3441 default:
3439 break; 3442 break;
3440 } 3443 }
3441 } 3444 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3479 registry.useElement(node, semantics.setter); 3482 registry.useElement(node, semantics.setter);
3480 registry.useElement(node.selector, semantics.getter); 3483 registry.useElement(node.selector, semantics.getter);
3481 3484
3482 registry.registerDynamicUse( 3485 registry.registerDynamicUse(
3483 new DynamicUse(operatorSelector, null)); 3486 new DynamicUse(operatorSelector, null));
3484 3487
3485 SendStructure sendStructure = node.isPrefix 3488 SendStructure sendStructure = node.isPrefix
3486 ? new PrefixStructure(semantics, operator) 3489 ? new PrefixStructure(semantics, operator)
3487 : new PostfixStructure(semantics, operator); 3490 : new PostfixStructure(semantics, operator);
3488 registry.registerSendStructure(node, sendStructure); 3491 registry.registerSendStructure(node, sendStructure);
3489 registry.registerIncDecOperation(); 3492 registry.registerFeature(Feature.INC_DEC_OPERATION);
3490 } else { 3493 } else {
3491 Node rhs = node.arguments.head; 3494 Node rhs = node.arguments.head;
3492 visitExpression(rhs); 3495 visitExpression(rhs);
3493 3496
3494 AssignmentOperator operator = AssignmentOperator.parse(operatorText); 3497 AssignmentOperator operator = AssignmentOperator.parse(operatorText);
3495 if (operator.kind == AssignmentOperatorKind.ASSIGN) { 3498 if (operator.kind == AssignmentOperatorKind.ASSIGN) {
3496 // `e1 = e2`. 3499 // `e1 = e2`.
3497 3500
3498 // TODO(23998): Remove these when elements are only accessed 3501 // TODO(23998): Remove these when elements are only accessed
3499 // through the send structure. 3502 // through the send structure.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3551 } else if (node.receiver == null) { 3554 } else if (node.receiver == null) {
3552 // `a = c` 3555 // `a = c`
3553 return handleUnqualifiedSendSet(node); 3556 return handleUnqualifiedSendSet(node);
3554 } else { 3557 } else {
3555 // `a.b = c` 3558 // `a.b = c`
3556 return handleQualifiedSendSet(node); 3559 return handleQualifiedSendSet(node);
3557 } 3560 }
3558 } 3561 }
3559 3562
3560 ConstantResult visitLiteralInt(LiteralInt node) { 3563 ConstantResult visitLiteralInt(LiteralInt node) {
3561 // TODO(johnniwinther): Make this a feature instead.
3562 registry.registerTypeUse(new TypeUse.instantiation(coreTypes.intType));
3563 ConstantExpression constant = new IntConstantExpression(node.value); 3564 ConstantExpression constant = new IntConstantExpression(node.value);
3565 registry.registerConstantLiteral(constant);
3564 registry.setConstant(node, constant); 3566 registry.setConstant(node, constant);
3565 return new ConstantResult(node, constant); 3567 return new ConstantResult(node, constant);
3566 } 3568 }
3567 3569
3568 ConstantResult visitLiteralDouble(LiteralDouble node) { 3570 ConstantResult visitLiteralDouble(LiteralDouble node) {
3569 // TODO(johnniwinther): Make this a feature instead.
3570 registry.registerTypeUse(new TypeUse.instantiation(coreTypes.doubleType));
3571 ConstantExpression constant = new DoubleConstantExpression(node.value); 3571 ConstantExpression constant = new DoubleConstantExpression(node.value);
3572 registry.registerConstantLiteral(constant);
3572 registry.setConstant(node, constant); 3573 registry.setConstant(node, constant);
3573 return new ConstantResult(node, constant); 3574 return new ConstantResult(node, constant);
3574 } 3575 }
3575 3576
3576 ConstantResult visitLiteralBool(LiteralBool node) { 3577 ConstantResult visitLiteralBool(LiteralBool node) {
3577 // TODO(johnniwinther): Make this a feature instead.
3578 registry.registerTypeUse(new TypeUse.instantiation(coreTypes.boolType));
3579 ConstantExpression constant = new BoolConstantExpression(node.value); 3578 ConstantExpression constant = new BoolConstantExpression(node.value);
3579 registry.registerConstantLiteral(constant);
3580 registry.setConstant(node, constant); 3580 registry.setConstant(node, constant);
3581 return new ConstantResult(node, constant); 3581 return new ConstantResult(node, constant);
3582 } 3582 }
3583 3583
3584 ResolutionResult visitLiteralString(LiteralString node) { 3584 ResolutionResult visitLiteralString(LiteralString node) {
3585 // TODO(johnniwinther): Make this a feature instead.
3586 registry.registerTypeUse(new TypeUse.instantiation(coreTypes.stringType));
3587 if (node.dartString != null) { 3585 if (node.dartString != null) {
3588 // [dartString] might be null on parser errors. 3586 // [dartString] might be null on parser errors.
3589 ConstantExpression constant = 3587 ConstantExpression constant =
3590 new StringConstantExpression(node.dartString.slowToString()); 3588 new StringConstantExpression(node.dartString.slowToString());
3589 registry.registerConstantLiteral(constant);
3591 registry.setConstant(node, constant); 3590 registry.setConstant(node, constant);
3592 return new ConstantResult(node, constant); 3591 return new ConstantResult(node, constant);
3593 } 3592 }
3594 return const NoneResult(); 3593 return const NoneResult();
3595 } 3594 }
3596 3595
3597 ConstantResult visitLiteralNull(LiteralNull node) { 3596 ConstantResult visitLiteralNull(LiteralNull node) {
3598 registry.registerTypeUse(new TypeUse.instantiation(coreTypes.nullType));
3599 ConstantExpression constant = new NullConstantExpression(); 3597 ConstantExpression constant = new NullConstantExpression();
3598 registry.registerConstantLiteral(constant);
3600 registry.setConstant(node, constant); 3599 registry.setConstant(node, constant);
3601 return new ConstantResult(node, constant); 3600 return new ConstantResult(node, constant);
3602 } 3601 }
3603 3602
3604 ConstantResult visitLiteralSymbol(LiteralSymbol node) { 3603 ConstantResult visitLiteralSymbol(LiteralSymbol node) {
3605 // TODO(johnniwinther): Make this a feature instead.
3606 String name = node.slowNameString; 3604 String name = node.slowNameString;
3605 // TODO(johnniwinther): Use [registerConstantLiteral] instead.
3607 registry.registerConstSymbol(name); 3606 registry.registerConstSymbol(name);
3608 if (!validateSymbol(node, name, reportError: false)) { 3607 if (!validateSymbol(node, name, reportError: false)) {
3609 reporter.reportErrorMessage( 3608 reporter.reportErrorMessage(
3610 node, 3609 node,
3611 MessageKind.UNSUPPORTED_LITERAL_SYMBOL, 3610 MessageKind.UNSUPPORTED_LITERAL_SYMBOL,
3612 {'value': name}); 3611 {'value': name});
3613 } 3612 }
3614 analyzeConstantDeferred(node); 3613 analyzeConstantDeferred(node);
3615 ConstantExpression constant = new SymbolConstantExpression(name); 3614 ConstantExpression constant = new SymbolConstantExpression(name);
3616 registry.setConstant(node, constant); 3615 registry.setConstant(node, constant);
3617 return new ConstantResult(node, constant); 3616 return new ConstantResult(node, constant);
3618 } 3617 }
3619 3618
3620 ResolutionResult visitStringJuxtaposition(StringJuxtaposition node) { 3619 ResolutionResult visitStringJuxtaposition(StringJuxtaposition node) {
3621 // TODO(johnniwinther): Make this a feature instead. 3620 registry.registerFeature(Feature.STRING_JUXTAPOSITION);
3622 registry.registerTypeUse(new TypeUse.instantiation(coreTypes.stringType));
3623 ResolutionResult first = visit(node.first); 3621 ResolutionResult first = visit(node.first);
3624 ResolutionResult second = visit(node.second); 3622 ResolutionResult second = visit(node.second);
3625 if (first.isConstant && second.isConstant) { 3623 if (first.isConstant && second.isConstant) {
3626 ConstantExpression constant = new ConcatenateConstantExpression( 3624 ConstantExpression constant = new ConcatenateConstantExpression(
3627 <ConstantExpression>[first.constant, second.constant]); 3625 <ConstantExpression>[first.constant, second.constant]);
3628 registry.setConstant(node, constant); 3626 registry.setConstant(node, constant);
3629 return new ConstantResult(node, constant); 3627 return new ConstantResult(node, constant);
3630 } 3628 }
3631 return const NoneResult(); 3629 return const NoneResult();
3632 } 3630 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3691 3689
3692 Node constructorReference = node.constructorReference; 3690 Node constructorReference = node.constructorReference;
3693 if (constructorReference is Send) { 3691 if (constructorReference is Send) {
3694 constructor.redirectionDeferredPrefix = 3692 constructor.redirectionDeferredPrefix =
3695 compiler.deferredLoadTask.deferredPrefixElement(constructorReference, 3693 compiler.deferredLoadTask.deferredPrefixElement(constructorReference,
3696 registry.mapping); 3694 registry.mapping);
3697 } 3695 }
3698 3696
3699 registry.setRedirectingTargetConstructor(node, redirectionTarget); 3697 registry.setRedirectingTargetConstructor(node, redirectionTarget);
3700 if (Elements.isUnresolved(redirectionTarget)) { 3698 if (Elements.isUnresolved(redirectionTarget)) {
3701 registry.registerThrowNoSuchMethod(); 3699 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
3702 return const NoneResult(); 3700 return const NoneResult();
3703 } else { 3701 } else {
3704 if (isConstConstructor && 3702 if (isConstConstructor &&
3705 !redirectionTarget.isConst) { 3703 !redirectionTarget.isConst) {
3706 reporter.reportErrorMessage( 3704 reporter.reportErrorMessage(
3707 node, MessageKind.CONSTRUCTOR_IS_NOT_CONST); 3705 node, MessageKind.CONSTRUCTOR_IS_NOT_CONST);
3708 isValidAsConstant = false; 3706 isValidAsConstant = false;
3709 } 3707 }
3710 if (redirectionTarget == constructor) { 3708 if (redirectionTarget == constructor) {
3711 reporter.reportErrorMessage( 3709 reporter.reportErrorMessage(
(...skipping 22 matching lines...) Expand all
3734 // TODO(johnniwinther): Handle this (potentially) erroneous case. 3732 // TODO(johnniwinther): Handle this (potentially) erroneous case.
3735 isValidAsConstant = false; 3733 isValidAsConstant = false;
3736 } 3734 }
3737 3735
3738 redirectionTarget.computeType(resolution); 3736 redirectionTarget.computeType(resolution);
3739 FunctionSignature targetSignature = redirectionTarget.functionSignature; 3737 FunctionSignature targetSignature = redirectionTarget.functionSignature;
3740 constructor.computeType(resolution); 3738 constructor.computeType(resolution);
3741 FunctionSignature constructorSignature = constructor.functionSignature; 3739 FunctionSignature constructorSignature = constructor.functionSignature;
3742 if (!targetSignature.isCompatibleWith(constructorSignature)) { 3740 if (!targetSignature.isCompatibleWith(constructorSignature)) {
3743 assert(!isSubtype); 3741 assert(!isSubtype);
3744 registry.registerThrowNoSuchMethod(); 3742 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
3745 isValidAsConstant = false; 3743 isValidAsConstant = false;
3746 } 3744 }
3747 3745
3748 // Register a post process to check for cycles in the redirection chain and 3746 // Register a post process to check for cycles in the redirection chain and
3749 // set the actual generative constructor at the end of the chain. 3747 // set the actual generative constructor at the end of the chain.
3750 addDeferredAction(constructor, () { 3748 addDeferredAction(constructor, () {
3751 compiler.resolver.resolveRedirectionChain(constructor, node); 3749 compiler.resolver.resolveRedirectionChain(constructor, node);
3752 }); 3750 });
3753 3751
3754 registry.registerStaticUse( 3752 registry.registerStaticUse(
3755 new StaticUse.constructorRedirect(redirectionTarget)); 3753 new StaticUse.constructorRedirect(redirectionTarget));
3756 // TODO(johnniwinther): Register the effective target type as part of the 3754 // TODO(johnniwinther): Register the effective target type as part of the
3757 // static use instead. 3755 // static use instead.
3758 registry.registerTypeUse(new TypeUse.instantiation( 3756 registry.registerTypeUse(new TypeUse.instantiation(
3759 redirectionTarget.enclosingClass.thisType 3757 redirectionTarget.enclosingClass.thisType
3760 .subst(type.typeArguments, targetClass.typeVariables))); 3758 .subst(type.typeArguments, targetClass.typeVariables)));
3761 if (isSymbolConstructor) { 3759 if (isSymbolConstructor) {
3762 registry.registerSymbolConstructor(); 3760 registry.registerFeature(Feature.SYMBOL_CONSTRUCTOR);
3763 } 3761 }
3764 if (isValidAsConstant) { 3762 if (isValidAsConstant) {
3765 List<String> names = <String>[]; 3763 List<String> names = <String>[];
3766 List<ConstantExpression> arguments = <ConstantExpression>[]; 3764 List<ConstantExpression> arguments = <ConstantExpression>[];
3767 int index = 0; 3765 int index = 0;
3768 constructorSignature.forEachParameter((ParameterElement parameter) { 3766 constructorSignature.forEachParameter((ParameterElement parameter) {
3769 if (parameter.isNamed) { 3767 if (parameter.isNamed) {
3770 String name = parameter.name; 3768 String name = parameter.name;
3771 names.add(name); 3769 names.add(name);
3772 arguments.add(new NamedArgumentReference(name)); 3770 arguments.add(new NamedArgumentReference(name));
3773 } else { 3771 } else {
3774 arguments.add(new PositionalArgumentReference(index)); 3772 arguments.add(new PositionalArgumentReference(index));
3775 } 3773 }
3776 index++; 3774 index++;
3777 }); 3775 });
3778 CallStructure callStructure = 3776 CallStructure callStructure =
3779 new CallStructure(constructorSignature.parameterCount, names); 3777 new CallStructure(constructorSignature.parameterCount, names);
3780 constructor.constantConstructor = 3778 constructor.constantConstructor =
3781 new RedirectingFactoryConstantConstructor( 3779 new RedirectingFactoryConstantConstructor(
3782 new ConstructedConstantExpression( 3780 new ConstructedConstantExpression(
3783 type, 3781 type,
3784 redirectionTarget, 3782 redirectionTarget,
3785 callStructure, 3783 callStructure,
3786 arguments)); 3784 arguments));
3787 } 3785 }
3788 return const NoneResult(); 3786 return const NoneResult();
3789 } 3787 }
3790 3788
3791 ResolutionResult visitThrow(Throw node) { 3789 ResolutionResult visitThrow(Throw node) {
3792 registry.registerThrowExpression(); 3790 registry.registerFeature(Feature.THROW_EXPRESSION);
3793 visit(node.expression); 3791 visit(node.expression);
3794 return const NoneResult(); 3792 return const NoneResult();
3795 } 3793 }
3796 3794
3797 ResolutionResult visitAwait(Await node) { 3795 ResolutionResult visitAwait(Await node) {
3798 coreClasses.futureClass.ensureResolved(resolution); 3796 coreClasses.futureClass.ensureResolved(resolution);
3799 visit(node.expression); 3797 visit(node.expression);
3800 return const NoneResult(); 3798 return const NoneResult();
3801 } 3799 }
3802 3800
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
3885 inConstantContext(() => resolveArguments(node.send.argumentsNode)); 3883 inConstantContext(() => resolveArguments(node.send.argumentsNode));
3886 } else { 3884 } else {
3887 argumentsResult = resolveArguments(node.send.argumentsNode); 3885 argumentsResult = resolveArguments(node.send.argumentsNode);
3888 } 3886 }
3889 registry.useElement(node.send, constructor); 3887 registry.useElement(node.send, constructor);
3890 if (Elements.isUnresolved(constructor)) { 3888 if (Elements.isUnresolved(constructor)) {
3891 return new ResolutionResult.forElement(constructor); 3889 return new ResolutionResult.forElement(constructor);
3892 } 3890 }
3893 constructor.computeType(resolution); 3891 constructor.computeType(resolution);
3894 if (!callSelector.applies(constructor, compiler.world)) { 3892 if (!callSelector.applies(constructor, compiler.world)) {
3895 registry.registerThrowNoSuchMethod(); 3893 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD);
3896 } 3894 }
3897 3895
3898 // [constructor] might be the implementation element 3896 // [constructor] might be the implementation element
3899 // and only declaration elements may be registered. 3897 // and only declaration elements may be registered.
3900 registry.registerStaticUse( 3898 registry.registerStaticUse(
3901 new StaticUse.constructorInvoke( 3899 new StaticUse.constructorInvoke(
3902 constructor.declaration, callSelector.callStructure)); 3900 constructor.declaration, callSelector.callStructure));
3903 ClassElement cls = constructor.enclosingClass; 3901 ClassElement cls = constructor.enclosingClass;
3904 if (cls.isEnumClass && currentClass != cls) { 3902 if (cls.isEnumClass && currentClass != cls) {
3905 reporter.reportErrorMessage( 3903 reporter.reportErrorMessage(
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
4159 registry.setConstant(node, constant); 4157 registry.setConstant(node, constant);
4160 return new ConstantResult(node, constant); 4158 return new ConstantResult(node, constant);
4161 } 4159 }
4162 return const NoneResult(); 4160 return const NoneResult();
4163 } 4161 }
4164 4162
4165 ResolutionResult visitStringInterpolation(StringInterpolation node) { 4163 ResolutionResult visitStringInterpolation(StringInterpolation node) {
4166 // TODO(johnniwinther): This should be a consequence of the registration 4164 // TODO(johnniwinther): This should be a consequence of the registration
4167 // of [registerStringInterpolation]. 4165 // of [registerStringInterpolation].
4168 registry.registerTypeUse(new TypeUse.instantiation(coreTypes.stringType)); 4166 registry.registerTypeUse(new TypeUse.instantiation(coreTypes.stringType));
4169 registry.registerStringInterpolation(); 4167 registry.registerFeature(Feature.STRING_INTERPOLATION);
4170 registerImplicitInvocation(Selectors.toString_); 4168 registerImplicitInvocation(Selectors.toString_);
4171 4169
4172 bool isValidAsConstant = true; 4170 bool isValidAsConstant = true;
4173 List<ConstantExpression> parts = <ConstantExpression>[]; 4171 List<ConstantExpression> parts = <ConstantExpression>[];
4174 4172
4175 void resolvePart(Node subnode) { 4173 void resolvePart(Node subnode) {
4176 ResolutionResult result = visit(subnode); 4174 ResolutionResult result = visit(subnode);
4177 if (isValidAsConstant && result.isConstant) { 4175 if (isValidAsConstant && result.isConstant) {
4178 parts.add(result.constant); 4176 parts.add(result.constant);
4179 } else { 4177 } else {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
4254 } 4252 }
4255 registry.registerTargetOf(node, target); 4253 registry.registerTargetOf(node, target);
4256 return const NoneResult(); 4254 return const NoneResult();
4257 } 4255 }
4258 4256
4259 registerImplicitInvocation(Selector selector) { 4257 registerImplicitInvocation(Selector selector) {
4260 registry.registerDynamicUse(new DynamicUse(selector, null)); 4258 registry.registerDynamicUse(new DynamicUse(selector, null));
4261 } 4259 }
4262 4260
4263 ResolutionResult visitAsyncForIn(AsyncForIn node) { 4261 ResolutionResult visitAsyncForIn(AsyncForIn node) {
4264 registry.registerAsyncForIn(node); 4262 registry.registerFeature(Feature.ASYNC_FOR_IN);
4265 registry.registerDynamicUse( 4263 registry.registerDynamicUse(
4266 new DynamicUse(Selectors.current, null)); 4264 new DynamicUse(Selectors.current, null));
4267 registry.registerDynamicUse( 4265 registry.registerDynamicUse(
4268 new DynamicUse(Selectors.moveNext, null)); 4266 new DynamicUse(Selectors.moveNext, null));
4269 4267
4270 visit(node.expression); 4268 visit(node.expression);
4271 4269
4272 Scope blockScope = new BlockScope(scope); 4270 Scope blockScope = new BlockScope(scope);
4273 visitForInDeclaredIdentifierIn(node.declaredIdentifier, node, blockScope); 4271 visitForInDeclaredIdentifierIn(node.declaredIdentifier, node, blockScope);
4274 visitLoopBodyIn(node, node.body, blockScope); 4272 visitLoopBodyIn(node, node.body, blockScope);
4275 return const NoneResult(); 4273 return const NoneResult();
4276 } 4274 }
4277 4275
4278 ResolutionResult visitSyncForIn(SyncForIn node) { 4276 ResolutionResult visitSyncForIn(SyncForIn node) {
4279 registry.registerSyncForIn(node); 4277 registry.registerFeature(Feature.SYNC_FOR_IN);
4280 registry.registerDynamicUse( 4278 registry.registerDynamicUse(
4281 new DynamicUse(Selectors.iterator, null)); 4279 new DynamicUse(Selectors.iterator, null));
4282 registry.registerDynamicUse( 4280 registry.registerDynamicUse(
4283 new DynamicUse(Selectors.current, null)); 4281 new DynamicUse(Selectors.current, null));
4284 registry.registerDynamicUse( 4282 registry.registerDynamicUse(
4285 new DynamicUse(Selectors.moveNext, null)); 4283 new DynamicUse(Selectors.moveNext, null));
4286 4284
4287 visit(node.expression); 4285 visit(node.expression);
4288 4286
4289 Scope blockScope = new BlockScope(scope); 4287 Scope blockScope = new BlockScope(scope);
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
4645 continueLabels.forEach((String key, LabelDefinition label) { 4643 continueLabels.forEach((String key, LabelDefinition label) {
4646 if (!label.isContinueTarget) { 4644 if (!label.isContinueTarget) {
4647 JumpTarget targetElement = label.target; 4645 JumpTarget targetElement = label.target;
4648 SwitchCase switchCase = targetElement.statement; 4646 SwitchCase switchCase = targetElement.statement;
4649 registry.undefineTarget(switchCase); 4647 registry.undefineTarget(switchCase);
4650 registry.undefineLabel(label.label); 4648 registry.undefineLabel(label.label);
4651 } 4649 }
4652 }); 4650 });
4653 // TODO(15575): We should warn if we can detect a fall through 4651 // TODO(15575): We should warn if we can detect a fall through
4654 // error. 4652 // error.
4655 registry.registerFallThroughError(); 4653 registry.registerFeature(Feature.FALL_THROUGH_ERROR);
4656 return const NoneResult(); 4654 return const NoneResult();
4657 } 4655 }
4658 4656
4659 ResolutionResult visitSwitchCase(SwitchCase node) { 4657 ResolutionResult visitSwitchCase(SwitchCase node) {
4660 node.labelsAndCases.accept(this); 4658 node.labelsAndCases.accept(this);
4661 visitIn(node.statements, new BlockScope(scope)); 4659 visitIn(node.statements, new BlockScope(scope));
4662 return const NoneResult(); 4660 return const NoneResult();
4663 } 4661 }
4664 4662
4665 ResolutionResult visitCaseMatch(CaseMatch node) { 4663 ResolutionResult visitCaseMatch(CaseMatch node) {
(...skipping 10 matching lines...) Expand all
4676 if (node.catchBlocks.isEmpty && node.finallyBlock == null) { 4674 if (node.catchBlocks.isEmpty && node.finallyBlock == null) {
4677 reporter.reportErrorMessage( 4675 reporter.reportErrorMessage(
4678 node.getEndToken().next, MessageKind.NO_CATCH_NOR_FINALLY); 4676 node.getEndToken().next, MessageKind.NO_CATCH_NOR_FINALLY);
4679 } 4677 }
4680 visit(node.catchBlocks); 4678 visit(node.catchBlocks);
4681 visit(node.finallyBlock); 4679 visit(node.finallyBlock);
4682 return const NoneResult(); 4680 return const NoneResult();
4683 } 4681 }
4684 4682
4685 ResolutionResult visitCatchBlock(CatchBlock node) { 4683 ResolutionResult visitCatchBlock(CatchBlock node) {
4686 registry.registerCatchStatement(); 4684 registry.registerFeature(Feature.CATCH_STATEMENT);
4687 // Check that if catch part is present, then 4685 // Check that if catch part is present, then
4688 // it has one or two formal parameters. 4686 // it has one or two formal parameters.
4689 VariableDefinitions exceptionDefinition; 4687 VariableDefinitions exceptionDefinition;
4690 VariableDefinitions stackTraceDefinition; 4688 VariableDefinitions stackTraceDefinition;
4691 if (node.formals != null) { 4689 if (node.formals != null) {
4692 Link<Node> formalsToProcess = node.formals.nodes; 4690 Link<Node> formalsToProcess = node.formals.nodes;
4693 if (formalsToProcess.isEmpty) { 4691 if (formalsToProcess.isEmpty) {
4694 reporter.reportErrorMessage( 4692 reporter.reportErrorMessage(
4695 node, MessageKind.EMPTY_CATCH_DECLARATION); 4693 node, MessageKind.EMPTY_CATCH_DECLARATION);
4696 } else { 4694 } else {
4697 exceptionDefinition = formalsToProcess.head.asVariableDefinitions(); 4695 exceptionDefinition = formalsToProcess.head.asVariableDefinitions();
4698 formalsToProcess = formalsToProcess.tail; 4696 formalsToProcess = formalsToProcess.tail;
4699 if (!formalsToProcess.isEmpty) { 4697 if (!formalsToProcess.isEmpty) {
4700 stackTraceDefinition = formalsToProcess.head.asVariableDefinitions(); 4698 stackTraceDefinition = formalsToProcess.head.asVariableDefinitions();
4701 formalsToProcess = formalsToProcess.tail; 4699 formalsToProcess = formalsToProcess.tail;
4702 if (!formalsToProcess.isEmpty) { 4700 if (!formalsToProcess.isEmpty) {
4703 for (Node extra in formalsToProcess) { 4701 for (Node extra in formalsToProcess) {
4704 reporter.reportErrorMessage( 4702 reporter.reportErrorMessage(
4705 extra, MessageKind.EXTRA_CATCH_DECLARATION); 4703 extra, MessageKind.EXTRA_CATCH_DECLARATION);
4706 } 4704 }
4707 } 4705 }
4708 registry.registerStackTraceInCatch(); 4706 registry.registerFeature(Feature.STACK_TRACE_IN_CATCH);
4709 } 4707 }
4710 } 4708 }
4711 4709
4712 // Check that the formals aren't optional and that they have no 4710 // Check that the formals aren't optional and that they have no
4713 // modifiers or type. 4711 // modifiers or type.
4714 for (Link<Node> link = node.formals.nodes; 4712 for (Link<Node> link = node.formals.nodes;
4715 !link.isEmpty; 4713 !link.isEmpty;
4716 link = link.tail) { 4714 link = link.tail) {
4717 // If the formal parameter is a node list, it means that it is a 4715 // If the formal parameter is a node list, it means that it is a
4718 // sequence of optional parameters. 4716 // sequence of optional parameters.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
4762 } 4760 }
4763 return const NoneResult(); 4761 return const NoneResult();
4764 } 4762 }
4765 } 4763 }
4766 4764
4767 /// Looks up [name] in [scope] and unwraps the result. 4765 /// Looks up [name] in [scope] and unwraps the result.
4768 Element lookupInScope(DiagnosticReporter reporter, Node node, 4766 Element lookupInScope(DiagnosticReporter reporter, Node node,
4769 Scope scope, String name) { 4767 Scope scope, String name) {
4770 return Elements.unwrap(scope.lookup(name), reporter, node); 4768 return Elements.unwrap(scope.lookup(name), reporter, node);
4771 } 4769 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/constructors.dart ('k') | pkg/compiler/lib/src/resolution/registry.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698