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

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

Issue 2946273002: Implement override-based type inference for instance methods. (Closed)
Patch Set: Created 3 years, 6 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 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 KernelMember member, Member overriddenMember) { 1310 KernelMember member, Member overriddenMember) {
1311 if (member._accessorNode != null) { 1311 if (member._accessorNode != null) {
1312 member._accessorNode.crossOverrides.add(overriddenMember); 1312 member._accessorNode.crossOverrides.add(overriddenMember);
1313 } 1313 }
1314 } 1314 }
1315 1315
1316 static void recordOverride(KernelMember member, Member overriddenMember) { 1316 static void recordOverride(KernelMember member, Member overriddenMember) {
1317 if (member._accessorNode != null) { 1317 if (member._accessorNode != null) {
1318 member._accessorNode.overrides.add(overriddenMember); 1318 member._accessorNode.overrides.add(overriddenMember);
1319 } 1319 }
1320 if (member is KernelProcedure && member._methodNode != null) {
1321 member._methodNode.overrides.add(overriddenMember);
1322 }
1320 } 1323 }
1321 } 1324 }
1322 1325
1323 /// Shadow object for [MethodInvocation]. 1326 /// Shadow object for [MethodInvocation].
1324 class KernelMethodInvocation extends MethodInvocation 1327 class KernelMethodInvocation extends MethodInvocation
1325 implements KernelExpression { 1328 implements KernelExpression {
1326 /// Indicates whether this method invocation is a call to a `call` method 1329 /// Indicates whether this method invocation is a call to a `call` method
1327 /// resulting from the invocation of a function expression. 1330 /// resulting from the invocation of a function expression.
1328 final bool _isImplicitCall; 1331 final bool _isImplicitCall;
1329 1332
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 inferrer.listener.nullLiteralExit(this, inferredType); 1471 inferrer.listener.nullLiteralExit(this, inferredType);
1469 return inferredType; 1472 return inferredType;
1470 } 1473 }
1471 } 1474 }
1472 1475
1473 /// Concrete shadow object representing a procedure in kernel form. 1476 /// Concrete shadow object representing a procedure in kernel form.
1474 class KernelProcedure extends Procedure implements KernelMember { 1477 class KernelProcedure extends Procedure implements KernelMember {
1475 @override 1478 @override
1476 AccessorNode _accessorNode; 1479 AccessorNode _accessorNode;
1477 1480
1481 MethodNode _methodNode;
1482
1478 @override 1483 @override
1479 KernelTypeInferrer _typeInferrer; 1484 KernelTypeInferrer _typeInferrer;
1480 1485
1486 final bool _hasImplicitReturnType;
1487
1481 KernelProcedure(Name name, ProcedureKind kind, FunctionNode function, 1488 KernelProcedure(Name name, ProcedureKind kind, FunctionNode function,
1489 this._hasImplicitReturnType,
1482 {String fileUri}) 1490 {String fileUri})
1483 : super(name, kind, function, fileUri: fileUri); 1491 : super(name, kind, function, fileUri: fileUri);
1484 1492
1485 @override 1493 @override
1486 void setInferredType( 1494 void setInferredType(
1487 TypeInferenceEngineImpl engine, String uri, DartType inferredType) { 1495 TypeInferenceEngineImpl engine, String uri, DartType inferredType) {
1488 if (isSetter) { 1496 if (isSetter) {
1489 if (function.positionalParameters.length > 0) { 1497 if (function.positionalParameters.length > 0) {
1490 var parameter = function.positionalParameters[0]; 1498 var parameter = function.positionalParameters[0];
1491 engine.instrumentation?.record(Uri.parse(uri), parameter.fileOffset, 1499 engine.instrumentation?.record(Uri.parse(uri), parameter.fileOffset,
1492 'topType', new InstrumentationValueForType(inferredType)); 1500 'topType', new InstrumentationValueForType(inferredType));
1493 parameter.type = inferredType; 1501 parameter.type = inferredType;
1494 } 1502 }
1495 } else if (isGetter) { 1503 } else if (isGetter) {
1496 engine.instrumentation?.record(Uri.parse(uri), fileOffset, 'topType', 1504 engine.instrumentation?.record(Uri.parse(uri), fileOffset, 'topType',
1497 new InstrumentationValueForType(inferredType)); 1505 new InstrumentationValueForType(inferredType));
1498 function.returnType = inferredType; 1506 function.returnType = inferredType;
1499 } else { 1507 } else {
1500 internalError( 1508 internalError(
1501 'setInferredType called on a procedure that is not an accessor'); 1509 'setInferredType called on a procedure that is not an accessor');
1502 } 1510 }
1503 } 1511 }
1512
1513 static MethodNode getMethodNode(Procedure procedure) {
1514 if (procedure is KernelProcedure) return procedure._methodNode;
1515 return null;
1516 }
1517
1518 static bool hasImplicitReturnType(KernelProcedure procedure) {
1519 return procedure._hasImplicitReturnType;
1520 }
1504 } 1521 }
1505 1522
1506 /// Concrete shadow object representing an assignment to a property. 1523 /// Concrete shadow object representing an assignment to a property.
1507 class KernelPropertyAssign extends KernelComplexAssignmentWithReceiver { 1524 class KernelPropertyAssign extends KernelComplexAssignmentWithReceiver {
1508 /// If this assignment uses null-aware access (`?.`), the conditional 1525 /// If this assignment uses null-aware access (`?.`), the conditional
1509 /// expression that guards the access; otherwise `null`. 1526 /// expression that guards the access; otherwise `null`.
1510 Expression nullAwareGuard; 1527 Expression nullAwareGuard;
1511 1528
1512 KernelPropertyAssign(Expression receiver, Expression rhs, 1529 KernelPropertyAssign(Expression receiver, Expression rhs,
1513 {bool isSuper: false}) 1530 {bool isSuper: false})
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 } 1949 }
1933 1950
1934 @override 1951 @override
1935 KernelTypeInferrer createLocalTypeInferrer( 1952 KernelTypeInferrer createLocalTypeInferrer(
1936 Uri uri, TypeInferenceListener listener, InterfaceType thisType) { 1953 Uri uri, TypeInferenceListener listener, InterfaceType thisType) {
1937 return new KernelTypeInferrer._( 1954 return new KernelTypeInferrer._(
1938 this, uri.toString(), listener, false, thisType, null); 1955 this, uri.toString(), listener, false, thisType, null);
1939 } 1956 }
1940 1957
1941 @override 1958 @override
1959 MethodNode createMethodNode(KernelProcedure procedure) {
1960 MethodNode methodNode = new MethodNode(procedure);
1961 procedure._methodNode = methodNode;
1962 return methodNode;
1963 }
1964
1965 @override
1942 KernelTypeInferrer createTopLevelTypeInferrer(TypeInferenceListener listener, 1966 KernelTypeInferrer createTopLevelTypeInferrer(TypeInferenceListener listener,
1943 InterfaceType thisType, KernelMember member) { 1967 InterfaceType thisType, KernelMember member) {
1944 return member._typeInferrer = new KernelTypeInferrer._( 1968 return member._typeInferrer = new KernelTypeInferrer._(
1945 this, member.fileUri, listener, true, thisType, member._accessorNode); 1969 this, member.fileUri, listener, true, thisType, member._accessorNode);
1946 } 1970 }
1947 1971
1948 @override 1972 @override
1949 KernelTypeInferrer getMemberTypeInferrer(KernelMember member) { 1973 KernelTypeInferrer getMemberTypeInferrer(KernelMember member) {
1950 return member._typeInferrer; 1974 return member._typeInferrer;
1951 } 1975 }
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
2280 } 2304 }
2281 2305
2282 transformChildren(v) { 2306 transformChildren(v) {
2283 return internalError("Internal error: Unsupported operation."); 2307 return internalError("Internal error: Unsupported operation.");
2284 } 2308 }
2285 2309
2286 visitChildren(v) { 2310 visitChildren(v) {
2287 return internalError("Internal error: Unsupported operation."); 2311 return internalError("Internal error: Unsupported operation.");
2288 } 2312 }
2289 } 2313 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698