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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart

Issue 2959823002: Add type inference for super property gets. (Closed)
Patch Set: Created 3 years, 5 months 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 /// This file declares a "shadow hierarchy" of concrete classes which extend 5 /// This file declares a "shadow hierarchy" of concrete classes which extend
6 /// the kernel class hierarchy, adding methods and fields needed by the 6 /// the kernel class hierarchy, adding methods and fields needed by the
7 /// BodyBuilder. 7 /// BodyBuilder.
8 /// 8 ///
9 /// Instances of these classes may be created using the factory methods in 9 /// Instances of these classes may be created using the factory methods in
10 /// `ast_factory.dart`. 10 /// `ast_factory.dart`.
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 interfaceMember: target, methodName: target.name, arguments: arguments); 549 interfaceMember: target, methodName: target.name, arguments: arguments);
550 } 550 }
551 } 551 }
552 552
553 /// Shadow object for [DirectPropertyGet]. 553 /// Shadow object for [DirectPropertyGet].
554 class KernelDirectPropertyGet extends DirectPropertyGet 554 class KernelDirectPropertyGet extends DirectPropertyGet
555 implements KernelExpression { 555 implements KernelExpression {
556 KernelDirectPropertyGet(Expression receiver, Member target) 556 KernelDirectPropertyGet(Expression receiver, Member target)
557 : super(receiver, target); 557 : super(receiver, target);
558 558
559 KernelDirectPropertyGet.byReference(
560 Expression receiver, Reference targetReference)
561 : super.byReference(receiver, targetReference);
562
563 @override 559 @override
564 void _collectDependencies(KernelDependencyCollector collector) { 560 void _collectDependencies(KernelDependencyCollector collector) {
565 // TODO(paulberry): Determine the right thing to do here. 561 // DirectPropertyGet can only occur as a result of a use of `super`, and
566 throw 'TODO(paulberry)'; 562 // `super` can't appear inside a field initializer. So this code should
563 // never be reached.
564 internalError(
565 'Unexpected call to _collectDependencies for DirectPropertyGet');
567 } 566 }
568 567
569 @override 568 @override
570 DartType _inferExpression( 569 DartType _inferExpression(
571 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { 570 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) {
572 // TODO(scheglov): implement. 571 return inferrer.inferPropertyGet(
573 return typeNeeded ? const DynamicType() : null; 572 this, receiver, fileOffset, typeContext, typeNeeded,
573 propertyName: target.name);
574 } 574 }
575 } 575 }
576 576
577 /// Concrete shadow object representing a do loop in kernel form. 577 /// Concrete shadow object representing a do loop in kernel form.
578 class KernelDoStatement extends DoStatement implements KernelStatement { 578 class KernelDoStatement extends DoStatement implements KernelStatement {
579 KernelDoStatement(Statement body, Expression condition) 579 KernelDoStatement(Statement body, Expression condition)
580 : super(body, condition); 580 : super(body, condition);
581 581
582 @override 582 @override
583 void _inferStatement(KernelTypeInferrer inferrer) { 583 void _inferStatement(KernelTypeInferrer inferrer) {
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 1374
1375 @override 1375 @override
1376 void _collectDependencies(KernelDependencyCollector collector) { 1376 void _collectDependencies(KernelDependencyCollector collector) {
1377 // Null aware expressions are not immediately evident. 1377 // Null aware expressions are not immediately evident.
1378 collector.recordNotImmediatelyEvident(fileOffset); 1378 collector.recordNotImmediatelyEvident(fileOffset);
1379 } 1379 }
1380 1380
1381 @override 1381 @override
1382 DartType _inferExpression( 1382 DartType _inferExpression(
1383 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { 1383 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) {
1384 var inferredType = inferrer.inferPropertyGet( 1384 var inferredType = inferrer.inferPropertyGet(this, variable.initializer,
1385 this, 1385 fileOffset, typeContext, typeNeeded || inferrer.strongMode,
1386 variable.initializer, 1386 receiverVariable: variable, desugaredGet: _desugaredGet);
1387 fileOffset,
1388 _desugaredGet,
1389 typeContext,
1390 typeNeeded || inferrer.strongMode,
1391 receiverVariable: variable);
1392 if (inferrer.strongMode) { 1387 if (inferrer.strongMode) {
1393 body.staticType = inferredType; 1388 body.staticType = inferredType;
1394 } 1389 }
1395 return inferredType; 1390 return inferredType;
1396 } 1391 }
1397 } 1392 }
1398 1393
1399 /// Concrete shadow object representing a null literal in kernel form. 1394 /// Concrete shadow object representing a null literal in kernel form.
1400 class KernelNullLiteral extends NullLiteral implements KernelExpression { 1395 class KernelNullLiteral extends NullLiteral implements KernelExpression {
1401 @override 1396 @override
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 // For a property get, the only things we could be looking at are an 1550 // For a property get, the only things we could be looking at are an
1556 // instance field, an instance getter, or an instance method. For the first 1551 // instance field, an instance getter, or an instance method. For the first
1557 // two, we disallow them in [_inferExpression]. For the last, there are no 1552 // two, we disallow them in [_inferExpression]. For the last, there are no
1558 // field dependencies. So we don't need to do anything here. 1553 // field dependencies. So we don't need to do anything here.
1559 } 1554 }
1560 1555
1561 @override 1556 @override
1562 DartType _inferExpression( 1557 DartType _inferExpression(
1563 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { 1558 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) {
1564 return inferrer.inferPropertyGet( 1559 return inferrer.inferPropertyGet(
1565 this, receiver, fileOffset, this, typeContext, typeNeeded); 1560 this, receiver, fileOffset, typeContext, typeNeeded,
1561 desugaredGet: this);
1566 } 1562 }
1567 } 1563 }
1568 1564
1569 /// Concrete shadow object representing a redirecting initializer in kernel 1565 /// Concrete shadow object representing a redirecting initializer in kernel
1570 /// form. 1566 /// form.
1571 class KernelRedirectingInitializer extends RedirectingInitializer 1567 class KernelRedirectingInitializer extends RedirectingInitializer
1572 implements KernelInitializer { 1568 implements KernelInitializer {
1573 KernelRedirectingInitializer(Constructor target, Arguments arguments) 1569 KernelRedirectingInitializer(Constructor target, Arguments arguments)
1574 : super(target, arguments); 1570 : super(target, arguments);
1575 1571
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1789 } 1785 }
1790 } 1786 }
1791 1787
1792 /// Shadow object for [SuperMethodInvocation]. 1788 /// Shadow object for [SuperMethodInvocation].
1793 class KernelSuperMethodInvocation extends SuperMethodInvocation 1789 class KernelSuperMethodInvocation extends SuperMethodInvocation
1794 implements KernelExpression { 1790 implements KernelExpression {
1795 KernelSuperMethodInvocation(Name name, Arguments arguments, 1791 KernelSuperMethodInvocation(Name name, Arguments arguments,
1796 [Procedure interfaceTarget]) 1792 [Procedure interfaceTarget])
1797 : super(name, arguments, interfaceTarget); 1793 : super(name, arguments, interfaceTarget);
1798 1794
1799 KernelSuperMethodInvocation.byReference(
1800 Name name, Arguments arguments, Reference interfaceTargetReference)
1801 : super.byReference(name, arguments, interfaceTargetReference);
1802
1803 @override 1795 @override
1804 void _collectDependencies(KernelDependencyCollector collector) { 1796 void _collectDependencies(KernelDependencyCollector collector) {
1805 // Super expressions should never occur in top level type inference. 1797 // Super expressions should never occur in top level type inference.
1806 // TODO(paulberry): but could they occur due to invalid code? 1798 // TODO(paulberry): but could they occur due to invalid code?
1807 assert(false); 1799 assert(false);
1808 } 1800 }
1809 1801
1810 @override 1802 @override
1811 DartType _inferExpression( 1803 DartType _inferExpression(
1812 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { 1804 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) {
1813 inferrer.instrumentation?.record(Uri.parse(inferrer.uri), fileOffset, 1805 inferrer.instrumentation?.record(Uri.parse(inferrer.uri), fileOffset,
1814 'target', new InstrumentationValueForMember(interfaceTarget)); 1806 'target', new InstrumentationValueForMember(interfaceTarget));
1815 return inferrer.inferMethodInvocation(this, new KernelThisExpression(), 1807 return inferrer.inferMethodInvocation(this, new KernelThisExpression(),
1816 fileOffset, false, typeContext, typeNeeded, 1808 fileOffset, false, typeContext, typeNeeded,
1817 interfaceMember: interfaceTarget, 1809 interfaceMember: interfaceTarget,
1818 methodName: name, 1810 methodName: name,
1819 arguments: arguments); 1811 arguments: arguments);
1820 } 1812 }
1821 } 1813 }
1822 1814
1823 /// Shadow object for [SuperPropertyGet]. 1815 /// Shadow object for [SuperPropertyGet].
1824 class KernelSuperPropertyGet extends SuperPropertyGet 1816 class KernelSuperPropertyGet extends SuperPropertyGet
1825 implements KernelExpression { 1817 implements KernelExpression {
1826 KernelSuperPropertyGet(Name name, [Member interfaceTarget]) 1818 KernelSuperPropertyGet(Name name, [Member interfaceTarget])
1827 : super(name, interfaceTarget); 1819 : super(name, interfaceTarget);
1828 1820
1829 KernelSuperPropertyGet.byReference(
1830 Name name, Reference interfaceTargetReference)
1831 : super.byReference(name, interfaceTargetReference);
1832
1833 @override 1821 @override
1834 void _collectDependencies(KernelDependencyCollector collector) { 1822 void _collectDependencies(KernelDependencyCollector collector) {
1835 // Super expressions should never occur in top level type inference. 1823 // Super expressions should never occur in top level type inference.
1836 // TODO(paulberry): but could they occur due to invalid code? 1824 // TODO(paulberry): but could they occur due to invalid code?
1837 assert(false); 1825 assert(false);
1838 } 1826 }
1839 1827
1840 @override 1828 @override
1841 DartType _inferExpression( 1829 DartType _inferExpression(
1842 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { 1830 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) {
1843 // TODO(scheglov): implement. 1831 return inferrer.inferPropertyGet(
1844 return typeNeeded ? const DynamicType() : null; 1832 this, new KernelThisExpression(), fileOffset, typeContext, typeNeeded,
1833 propertyName: name);
1845 } 1834 }
1846 } 1835 }
1847 1836
1848 /// Concrete shadow object representing a switch statement in kernel form. 1837 /// Concrete shadow object representing a switch statement in kernel form.
1849 class KernelSwitchStatement extends SwitchStatement implements KernelStatement { 1838 class KernelSwitchStatement extends SwitchStatement implements KernelStatement {
1850 KernelSwitchStatement(Expression expression, List<SwitchCase> cases) 1839 KernelSwitchStatement(Expression expression, List<SwitchCase> cases)
1851 : super(expression, cases); 1840 : super(expression, cases);
1852 1841
1853 @override 1842 @override
1854 void _inferStatement(KernelTypeInferrer inferrer) { 1843 void _inferStatement(KernelTypeInferrer inferrer) {
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
2332 } 2321 }
2333 2322
2334 transformChildren(v) { 2323 transformChildren(v) {
2335 return internalError("Internal error: Unsupported operation."); 2324 return internalError("Internal error: Unsupported operation.");
2336 } 2325 }
2337 2326
2338 visitChildren(v) { 2327 visitChildren(v) {
2339 return internalError("Internal error: Unsupported operation."); 2328 return internalError("Internal error: Unsupported operation.");
2340 } 2329 }
2341 } 2330 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698