OLD | NEW |
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 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 computeConstructorReturnType(_initialTarget), | 655 computeConstructorReturnType(_initialTarget), |
656 arguments); | 656 arguments); |
657 inferrer.listener.constructorInvocationExit(this, inferredType); | 657 inferrer.listener.constructorInvocationExit(this, inferredType); |
658 return inferredType; | 658 return inferredType; |
659 } | 659 } |
660 } | 660 } |
661 | 661 |
662 /// Concrete shadow object representing a field in kernel form. | 662 /// Concrete shadow object representing a field in kernel form. |
663 class KernelField extends Field implements KernelMember { | 663 class KernelField extends Field implements KernelMember { |
664 @override | 664 @override |
665 FieldNode _fieldNode; | 665 AccessorNode _accessorNode; |
666 | 666 |
667 @override | 667 @override |
668 KernelTypeInferrer _typeInferrer; | 668 KernelTypeInferrer _typeInferrer; |
669 | 669 |
670 KernelField(Name name, {String fileUri}) : super(name, fileUri: fileUri) {} | 670 KernelField(Name name, {String fileUri}) : super(name, fileUri: fileUri) {} |
671 | 671 |
672 @override | 672 @override |
673 void setInferredType( | 673 void setInferredType( |
674 TypeInferenceEngineImpl engine, String uri, DartType inferredType) { | 674 TypeInferenceEngineImpl engine, String uri, DartType inferredType) { |
675 engine.instrumentation?.record(Uri.parse(uri), fileOffset, 'topType', | 675 engine.instrumentation?.record(Uri.parse(uri), fileOffset, 'topType', |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 : null; | 1305 : null; |
1306 inferrer.listener.mapLiteralExit(this, inferredType); | 1306 inferrer.listener.mapLiteralExit(this, inferredType); |
1307 return inferredType; | 1307 return inferredType; |
1308 } | 1308 } |
1309 } | 1309 } |
1310 | 1310 |
1311 /// Abstract shadow object representing a field or procedure in kernel form. | 1311 /// Abstract shadow object representing a field or procedure in kernel form. |
1312 abstract class KernelMember implements Member { | 1312 abstract class KernelMember implements Member { |
1313 String get fileUri; | 1313 String get fileUri; |
1314 | 1314 |
1315 FieldNode get _fieldNode; | 1315 AccessorNode get _accessorNode; |
1316 | 1316 |
1317 void set _fieldNode(FieldNode value); | 1317 void set _accessorNode(AccessorNode value); |
1318 | 1318 |
1319 KernelTypeInferrer get _typeInferrer; | 1319 KernelTypeInferrer get _typeInferrer; |
1320 | 1320 |
1321 void set _typeInferrer(KernelTypeInferrer value); | 1321 void set _typeInferrer(KernelTypeInferrer value); |
1322 | 1322 |
1323 void setInferredType( | 1323 void setInferredType( |
1324 TypeInferenceEngineImpl engine, String uri, DartType inferredType); | 1324 TypeInferenceEngineImpl engine, String uri, DartType inferredType); |
1325 | 1325 |
1326 static FieldNode getFieldNode(Member member) { | 1326 static AccessorNode getAccessorNode(Member member) { |
1327 if (member is KernelMember) return member._fieldNode; | 1327 if (member is KernelMember) return member._accessorNode; |
1328 return null; | 1328 return null; |
1329 } | 1329 } |
1330 | 1330 |
1331 static void recordOverride(KernelMember member, Member overriddenMember) { | 1331 static void recordOverride(KernelMember member, Member overriddenMember) { |
1332 if (member._fieldNode != null) { | 1332 if (member._accessorNode != null) { |
1333 member._fieldNode.overrides.add(overriddenMember); | 1333 member._accessorNode.overrides.add(overriddenMember); |
1334 } | 1334 } |
1335 } | 1335 } |
1336 } | 1336 } |
1337 | 1337 |
1338 /// Shadow object for [MethodInvocation]. | 1338 /// Shadow object for [MethodInvocation]. |
1339 class KernelMethodInvocation extends MethodInvocation | 1339 class KernelMethodInvocation extends MethodInvocation |
1340 implements KernelExpression { | 1340 implements KernelExpression { |
1341 /// Indicates whether this method invocation is a call to a `call` method | 1341 /// Indicates whether this method invocation is a call to a `call` method |
1342 /// resulting from the invocation of a function expression. | 1342 /// resulting from the invocation of a function expression. |
1343 final bool _isImplicitCall; | 1343 final bool _isImplicitCall; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 inferrer.listener.nullLiteralEnter(this, typeContext) || typeNeeded; | 1462 inferrer.listener.nullLiteralEnter(this, typeContext) || typeNeeded; |
1463 var inferredType = typeNeeded ? inferrer.coreTypes.nullClass.rawType : null; | 1463 var inferredType = typeNeeded ? inferrer.coreTypes.nullClass.rawType : null; |
1464 inferrer.listener.nullLiteralExit(this, inferredType); | 1464 inferrer.listener.nullLiteralExit(this, inferredType); |
1465 return inferredType; | 1465 return inferredType; |
1466 } | 1466 } |
1467 } | 1467 } |
1468 | 1468 |
1469 /// Concrete shadow object representing a procedure in kernel form. | 1469 /// Concrete shadow object representing a procedure in kernel form. |
1470 class KernelProcedure extends Procedure implements KernelMember { | 1470 class KernelProcedure extends Procedure implements KernelMember { |
1471 @override | 1471 @override |
1472 FieldNode _fieldNode; | 1472 AccessorNode _accessorNode; |
1473 | 1473 |
1474 @override | 1474 @override |
1475 KernelTypeInferrer _typeInferrer; | 1475 KernelTypeInferrer _typeInferrer; |
1476 | 1476 |
1477 KernelProcedure(Name name, ProcedureKind kind, FunctionNode function, | 1477 KernelProcedure(Name name, ProcedureKind kind, FunctionNode function, |
1478 {String fileUri}) | 1478 {String fileUri}) |
1479 : super(name, kind, function, fileUri: fileUri); | 1479 : super(name, kind, function, fileUri: fileUri); |
1480 | 1480 |
1481 @override | 1481 @override |
1482 void setInferredType( | 1482 void setInferredType( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 inferrer.findPropertyGetMember(receiverType, read, silent: true); | 1529 inferrer.findPropertyGetMember(receiverType, read, silent: true); |
1530 } | 1530 } |
1531 Member writeMember; | 1531 Member writeMember; |
1532 if (write != null) { | 1532 if (write != null) { |
1533 writeMember = inferrer.findPropertySetMember(receiverType, write); | 1533 writeMember = inferrer.findPropertySetMember(receiverType, write); |
1534 if (inferrer.isTopLevel && | 1534 if (inferrer.isTopLevel && |
1535 ((writeMember is Procedure && | 1535 ((writeMember is Procedure && |
1536 writeMember.kind == ProcedureKind.Setter) || | 1536 writeMember.kind == ProcedureKind.Setter) || |
1537 writeMember is Field)) { | 1537 writeMember is Field)) { |
1538 if (TypeInferenceEngineImpl.fullTopLevelInference) { | 1538 if (TypeInferenceEngineImpl.fullTopLevelInference) { |
1539 if (writeMember is KernelField && writeMember._fieldNode != null) { | 1539 if (writeMember is KernelField && writeMember._accessorNode != null) { |
1540 inferrer.engine | 1540 inferrer.engine.inferAccessorFused( |
1541 .inferFieldFused(writeMember._fieldNode, inferrer.fieldNode); | 1541 writeMember._accessorNode, inferrer.accessorNode); |
1542 } | 1542 } |
1543 } else { | 1543 } else { |
1544 // References to fields and setters can't be relied upon for top level | 1544 // References to fields and setters can't be relied upon for top level |
1545 // inference. | 1545 // inference. |
1546 inferrer.recordNotImmediatelyEvident(fileOffset); | 1546 inferrer.recordNotImmediatelyEvident(fileOffset); |
1547 } | 1547 } |
1548 } | 1548 } |
1549 } | 1549 } |
1550 // To replicate analyzer behavior, we base type inference on the write | 1550 // To replicate analyzer behavior, we base type inference on the write |
1551 // member. TODO(paulberry): would it be better to use the read member when | 1551 // member. TODO(paulberry): would it be better to use the read member when |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1665 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { | 1665 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { |
1666 typeNeeded = inferrer.listener.staticAssignEnter(desugared, typeContext) || | 1666 typeNeeded = inferrer.listener.staticAssignEnter(desugared, typeContext) || |
1667 typeNeeded; | 1667 typeNeeded; |
1668 // TODO(paulberry): record the appropriate types on let variables and | 1668 // TODO(paulberry): record the appropriate types on let variables and |
1669 // conditional expressions. | 1669 // conditional expressions. |
1670 DartType writeContext; | 1670 DartType writeContext; |
1671 var write = this.write; | 1671 var write = this.write; |
1672 if (write is StaticSet) { | 1672 if (write is StaticSet) { |
1673 writeContext = write.target.setterType; | 1673 writeContext = write.target.setterType; |
1674 var target = write.target; | 1674 var target = write.target; |
1675 if (target is KernelField && target._fieldNode != null) { | 1675 if (target is KernelField && target._accessorNode != null) { |
1676 if (inferrer.isDryRun) { | 1676 if (inferrer.isDryRun) { |
1677 inferrer.recordDryRunDependency(target._fieldNode); | 1677 inferrer.recordDryRunDependency(target._accessorNode); |
1678 } | 1678 } |
1679 if (TypeInferenceEngineImpl.fusedTopLevelInference && | 1679 if (TypeInferenceEngineImpl.fusedTopLevelInference && |
1680 inferrer.isTopLevel) { | 1680 inferrer.isTopLevel) { |
1681 inferrer.engine | 1681 inferrer.engine |
1682 .inferFieldFused(target._fieldNode, inferrer.fieldNode); | 1682 .inferAccessorFused(target._accessorNode, inferrer.accessorNode); |
1683 } | 1683 } |
1684 } | 1684 } |
1685 } | 1685 } |
1686 var inferredType = _inferRhs(inferrer, writeContext); | 1686 var inferredType = _inferRhs(inferrer, writeContext); |
1687 inferrer.listener.staticAssignExit(desugared, inferredType); | 1687 inferrer.listener.staticAssignExit(desugared, inferredType); |
1688 return inferredType; | 1688 return inferredType; |
1689 } | 1689 } |
1690 } | 1690 } |
1691 | 1691 |
1692 /// Concrete shadow object representing a read of a static variable in kernel | 1692 /// Concrete shadow object representing a read of a static variable in kernel |
1693 /// form. | 1693 /// form. |
1694 class KernelStaticGet extends StaticGet implements KernelExpression { | 1694 class KernelStaticGet extends StaticGet implements KernelExpression { |
1695 KernelStaticGet(Member target) : super(target); | 1695 KernelStaticGet(Member target) : super(target); |
1696 | 1696 |
1697 @override | 1697 @override |
1698 void _collectDependencies(KernelDependencyCollector collector) { | 1698 void _collectDependencies(KernelDependencyCollector collector) { |
1699 // A simple or qualified identifier referring to a top level function, | 1699 // A simple or qualified identifier referring to a top level function, |
1700 // static variable, field, getter; or a static class variable, static getter | 1700 // static variable, field, getter; or a static class variable, static getter |
1701 // or method; or an instance method; has the inferred type of the referent. | 1701 // or method; or an instance method; has the inferred type of the referent. |
1702 // - Otherwise, if the identifier has no inferred or annotated type then it | 1702 // - Otherwise, if the identifier has no inferred or annotated type then it |
1703 // is an error. | 1703 // is an error. |
1704 // - Note: specifically, references to instance fields and instance getters | 1704 // - Note: specifically, references to instance fields and instance getters |
1705 // are disallowed here. | 1705 // are disallowed here. |
1706 // - The inference dependency of the identifier is the referent if the | 1706 // - The inference dependency of the identifier is the referent if the |
1707 // referent is a candidate for inference. Otherwise there are no | 1707 // referent is a candidate for inference. Otherwise there are no |
1708 // inference dependencies. | 1708 // inference dependencies. |
1709 // TODO(paulberry): implement the proper error checking logic. | 1709 // TODO(paulberry): implement the proper error checking logic. |
1710 var target = this.target; | 1710 var target = this.target; |
1711 if (target is KernelField && target._fieldNode != null) { | 1711 if (target is KernelField && target._accessorNode != null) { |
1712 collector.recordDependency(target._fieldNode); | 1712 collector.recordDependency(target._accessorNode); |
1713 } | 1713 } |
1714 } | 1714 } |
1715 | 1715 |
1716 @override | 1716 @override |
1717 DartType _inferExpression( | 1717 DartType _inferExpression( |
1718 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { | 1718 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { |
1719 typeNeeded = | 1719 typeNeeded = |
1720 inferrer.listener.staticGetEnter(this, typeContext) || typeNeeded; | 1720 inferrer.listener.staticGetEnter(this, typeContext) || typeNeeded; |
1721 var target = this.target; | 1721 var target = this.target; |
1722 if (target is KernelField && target._fieldNode != null) { | 1722 if (target is KernelField && target._accessorNode != null) { |
1723 if (inferrer.isDryRun) { | 1723 if (inferrer.isDryRun) { |
1724 inferrer.recordDryRunDependency(target._fieldNode); | 1724 inferrer.recordDryRunDependency(target._accessorNode); |
1725 } | 1725 } |
1726 if (TypeInferenceEngineImpl.fusedTopLevelInference && | 1726 if (TypeInferenceEngineImpl.fusedTopLevelInference && |
1727 inferrer.isTopLevel) { | 1727 inferrer.isTopLevel) { |
1728 inferrer.engine.inferFieldFused(target._fieldNode, inferrer.fieldNode); | 1728 inferrer.engine |
| 1729 .inferAccessorFused(target._accessorNode, inferrer.accessorNode); |
1729 } | 1730 } |
1730 } | 1731 } |
1731 var inferredType = typeNeeded ? target.getterType : null; | 1732 var inferredType = typeNeeded ? target.getterType : null; |
1732 inferrer.listener.staticGetExit(this, inferredType); | 1733 inferrer.listener.staticGetExit(this, inferredType); |
1733 return inferredType; | 1734 return inferredType; |
1734 } | 1735 } |
1735 } | 1736 } |
1736 | 1737 |
1737 /// Shadow object for [StaticInvocation]. | 1738 /// Shadow object for [StaticInvocation]. |
1738 class KernelStaticInvocation extends StaticInvocation | 1739 class KernelStaticInvocation extends StaticInvocation |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1913 } | 1914 } |
1914 } | 1915 } |
1915 | 1916 |
1916 /// Concrete implementation of [TypeInferenceEngine] specialized to work with | 1917 /// Concrete implementation of [TypeInferenceEngine] specialized to work with |
1917 /// kernel objects. | 1918 /// kernel objects. |
1918 class KernelTypeInferenceEngine extends TypeInferenceEngineImpl { | 1919 class KernelTypeInferenceEngine extends TypeInferenceEngineImpl { |
1919 KernelTypeInferenceEngine(Instrumentation instrumentation, bool strongMode) | 1920 KernelTypeInferenceEngine(Instrumentation instrumentation, bool strongMode) |
1920 : super(instrumentation, strongMode); | 1921 : super(instrumentation, strongMode); |
1921 | 1922 |
1922 @override | 1923 @override |
1923 FieldNode createFieldNode(KernelMember member) { | 1924 AccessorNode createAccessorNode(KernelMember member) { |
1924 FieldNode fieldNode = new FieldNode(this, member); | 1925 AccessorNode accessorNode = new AccessorNode(this, member); |
1925 member._fieldNode = fieldNode; | 1926 member._accessorNode = accessorNode; |
1926 return fieldNode; | 1927 return accessorNode; |
1927 } | 1928 } |
1928 | 1929 |
1929 @override | 1930 @override |
1930 KernelTypeInferrer createLocalTypeInferrer( | 1931 KernelTypeInferrer createLocalTypeInferrer( |
1931 Uri uri, TypeInferenceListener listener, InterfaceType thisType) { | 1932 Uri uri, TypeInferenceListener listener, InterfaceType thisType) { |
1932 return new KernelTypeInferrer._( | 1933 return new KernelTypeInferrer._( |
1933 this, uri.toString(), listener, false, thisType, null); | 1934 this, uri.toString(), listener, false, thisType, null); |
1934 } | 1935 } |
1935 | 1936 |
1936 @override | 1937 @override |
1937 KernelTypeInferrer createTopLevelTypeInferrer(TypeInferenceListener listener, | 1938 KernelTypeInferrer createTopLevelTypeInferrer(TypeInferenceListener listener, |
1938 InterfaceType thisType, KernelMember member) { | 1939 InterfaceType thisType, KernelMember member) { |
1939 return member._typeInferrer = new KernelTypeInferrer._( | 1940 return member._typeInferrer = new KernelTypeInferrer._( |
1940 this, member.fileUri, listener, true, thisType, member._fieldNode); | 1941 this, member.fileUri, listener, true, thisType, member._accessorNode); |
1941 } | 1942 } |
1942 | 1943 |
1943 @override | 1944 @override |
1944 KernelTypeInferrer getFieldTypeInferrer(KernelMember member) { | 1945 KernelTypeInferrer getMemberTypeInferrer(KernelMember member) { |
1945 return member._typeInferrer; | 1946 return member._typeInferrer; |
1946 } | 1947 } |
1947 } | 1948 } |
1948 | 1949 |
1949 /// Concrete implementation of [TypeInferrer] specialized to work with kernel | 1950 /// Concrete implementation of [TypeInferrer] specialized to work with kernel |
1950 /// objects. | 1951 /// objects. |
1951 class KernelTypeInferrer extends TypeInferrerImpl { | 1952 class KernelTypeInferrer extends TypeInferrerImpl { |
1952 @override | 1953 @override |
1953 final typePromoter = new KernelTypePromoter(); | 1954 final typePromoter = new KernelTypePromoter(); |
1954 | 1955 |
1955 KernelTypeInferrer._( | 1956 KernelTypeInferrer._( |
1956 KernelTypeInferenceEngine engine, | 1957 KernelTypeInferenceEngine engine, |
1957 String uri, | 1958 String uri, |
1958 TypeInferenceListener listener, | 1959 TypeInferenceListener listener, |
1959 bool topLevel, | 1960 bool topLevel, |
1960 InterfaceType thisType, | 1961 InterfaceType thisType, |
1961 FieldNode fieldNode) | 1962 AccessorNode accessorNode) |
1962 : super(engine, uri, listener, topLevel, thisType, fieldNode); | 1963 : super(engine, uri, listener, topLevel, thisType, accessorNode); |
1963 | 1964 |
1964 @override | 1965 @override |
1965 Expression getFieldInitializer(KernelField field) { | 1966 Expression getFieldInitializer(KernelField field) { |
1966 return field.initializer; | 1967 return field.initializer; |
1967 } | 1968 } |
1968 | 1969 |
1969 @override | 1970 @override |
1970 DartType inferExpression( | 1971 DartType inferExpression( |
1971 Expression expression, DartType typeContext, bool typeNeeded) { | 1972 Expression expression, DartType typeContext, bool typeNeeded) { |
1972 // When doing top level inference, we skip subexpressions whose type isn't | 1973 // When doing top level inference, we skip subexpressions whose type isn't |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2275 } | 2276 } |
2276 | 2277 |
2277 transformChildren(v) { | 2278 transformChildren(v) { |
2278 return internalError("Internal error: Unsupported operation."); | 2279 return internalError("Internal error: Unsupported operation."); |
2279 } | 2280 } |
2280 | 2281 |
2281 visitChildren(v) { | 2282 visitChildren(v) { |
2282 return internalError("Internal error: Unsupported operation."); | 2283 return internalError("Internal error: Unsupported operation."); |
2283 } | 2284 } |
2284 } | 2285 } |
OLD | NEW |