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

Side by Side Diff: pkg/analyzer/lib/src/summary/link.dart

Issue 2711733003: Issue 28862. Implement type inference for invokeConstructor. (Closed)
Patch Set: Created 3 years, 10 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 /** 5 /**
6 * This library is capable of producing linked summaries from unlinked 6 * This library is capable of producing linked summaries from unlinked
7 * ones (or prelinked ones). It functions by building a miniature 7 * ones (or prelinked ones). It functions by building a miniature
8 * element model to represent the contents of the summaries, and then 8 * element model to represent the contents of the summaries, and then
9 * scanning the element model to gather linked information and adding 9 * scanning the element model to gather linked information and adding
10 * it to the summary data structures. 10 * it to the summary data structures.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 import 'package:analyzer/dart/ast/ast.dart'; 60 import 'package:analyzer/dart/ast/ast.dart';
61 import 'package:analyzer/dart/ast/token.dart' show TokenType; 61 import 'package:analyzer/dart/ast/token.dart' show TokenType;
62 import 'package:analyzer/dart/element/element.dart'; 62 import 'package:analyzer/dart/element/element.dart';
63 import 'package:analyzer/dart/element/type.dart'; 63 import 'package:analyzer/dart/element/type.dart';
64 import 'package:analyzer/src/dart/constant/value.dart'; 64 import 'package:analyzer/src/dart/constant/value.dart';
65 import 'package:analyzer/src/dart/element/element.dart'; 65 import 'package:analyzer/src/dart/element/element.dart';
66 import 'package:analyzer/src/dart/element/type.dart'; 66 import 'package:analyzer/src/dart/element/type.dart';
67 import 'package:analyzer/src/dart/resolver/inheritance_manager.dart'; 67 import 'package:analyzer/src/dart/resolver/inheritance_manager.dart';
68 import 'package:analyzer/src/generated/engine.dart'; 68 import 'package:analyzer/src/generated/engine.dart';
69 import 'package:analyzer/src/generated/resolver.dart'; 69 import 'package:analyzer/src/generated/resolver.dart';
70 import 'package:analyzer/src/generated/static_type_analyzer.dart';
70 import 'package:analyzer/src/generated/utilities_dart.dart'; 71 import 'package:analyzer/src/generated/utilities_dart.dart';
71 import 'package:analyzer/src/summary/format.dart'; 72 import 'package:analyzer/src/summary/format.dart';
72 import 'package:analyzer/src/summary/idl.dart'; 73 import 'package:analyzer/src/summary/idl.dart';
73 import 'package:analyzer/src/summary/prelink.dart'; 74 import 'package:analyzer/src/summary/prelink.dart';
74 import 'package:analyzer/src/task/strong_mode.dart'; 75 import 'package:analyzer/src/task/strong_mode.dart';
75 import 'package:front_end/src/dependency_walker.dart'; 76 import 'package:front_end/src/dependency_walker.dart';
76 77
77 bool isIncrementOrDecrement(UnlinkedExprAssignOperator operator) { 78 bool isIncrementOrDecrement(UnlinkedExprAssignOperator operator) {
78 switch (operator) { 79 switch (operator) {
79 case UnlinkedExprAssignOperator.prefixDecrement: 80 case UnlinkedExprAssignOperator.prefixDecrement:
(...skipping 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 } 1674 }
1674 } 1675 }
1675 1676
1676 @override 1677 @override
1677 ConstructorElementForLink get asConstructor => this; 1678 ConstructorElementForLink get asConstructor => this;
1678 1679
1679 @override 1680 @override
1680 ClassElementImpl get enclosingElement => super.enclosingClass; 1681 ClassElementImpl get enclosingElement => super.enclosingClass;
1681 1682
1682 @override 1683 @override
1684 String get identifier => name;
1685
1686 @override
1683 bool get isCycleFree { 1687 bool get isCycleFree {
1684 if (!_constNode.isEvaluated) { 1688 if (!_constNode.isEvaluated) {
1685 new ConstDependencyWalker().walk(_constNode); 1689 new ConstDependencyWalker().walk(_constNode);
1686 } 1690 }
1687 return _constNode.isCycleFree; 1691 return _constNode.isCycleFree;
1688 } 1692 }
1689 1693
1694 @override
1695 DartType get returnType => enclosingElement.type;
1696
1697 @override
1698 List<TypeParameterElement> get typeParameters => const [];
1699
1690 /** 1700 /**
1691 * Perform const cycle detection on this constructor. 1701 * Perform const cycle detection on this constructor.
1692 */ 1702 */
1693 void link(CompilationUnitElementInBuildUnit compilationUnit) { 1703 void link(CompilationUnitElementInBuildUnit compilationUnit) {
1694 if (_constNode != null && !isCycleFree) { 1704 if (_constNode != null && !isCycleFree) {
1695 compilationUnit._storeConstCycle(_unlinkedExecutable.constCycleSlot); 1705 compilationUnit._storeConstCycle(_unlinkedExecutable.constCycleSlot);
1696 } 1706 }
1697 // TODO(paulberry): call super. 1707 // TODO(paulberry): call super.
1698 } 1708 }
1699 1709
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
2314 2324
2315 void _doIfNull() { 2325 void _doIfNull() {
2316 DartType secondType = stack.removeLast(); 2326 DartType secondType = stack.removeLast();
2317 DartType firstType = stack.removeLast(); 2327 DartType firstType = stack.removeLast();
2318 DartType type = _leastUpperBound(firstType, secondType); 2328 DartType type = _leastUpperBound(firstType, secondType);
2319 type = _dynamicIfNull(type); 2329 type = _dynamicIfNull(type);
2320 stack.add(type); 2330 stack.add(type);
2321 } 2331 }
2322 2332
2323 void _doInvokeConstructor() { 2333 void _doInvokeConstructor() {
2324 int numNamed = _getNextInt(); 2334 int numNamed = unlinkedConst.ints[intPtr++];
2325 int numPositional = _getNextInt(); 2335 int numPositional = unlinkedConst.ints[intPtr++];
2326 // TODO(paulberry): don't just pop the args; use their types 2336 List<String> namedArgNames = _getNextStrings(numNamed);
2327 // to infer the type of type arguments. 2337 List<DartType> namedArgTypeList = _popList(numNamed);
2328 stack.length -= numNamed + numPositional; 2338 List<DartType> positionalArgTypes = _popList(numPositional);
2329 strPtr += numNamed; 2339
2330 EntityRef ref = _getNextRef(); 2340 EntityRef ref = _getNextRef();
2331 ClassElementForLink_Class element = 2341 ReferenceableElementForLink refElement = unit.resolveRef(ref.reference);
2332 unit.resolveConstructorClassRef(ref.reference).asClass; 2342 ConstructorElementForLink constructorElement = refElement.asConstructor;
2333 if (element != null) { 2343
2334 stack.add(element.buildType((int i) { 2344 if (constructorElement != null) {
2335 // Type argument explicitly specified. 2345 stack.add(() {
2336 if (i < ref.typeArguments.length) { 2346 if (ref.typeArguments.isNotEmpty) {
2337 return unit.resolveTypeRef( 2347 return constructorElement.enclosingClass.buildType((int i) {
2338 ref.typeArguments[i], function.typeParameterContext); 2348 if (i < ref.typeArguments.length) {
2349 return unit.resolveTypeRef(
2350 ref.typeArguments[i], function.typeParameterContext);
2351 } else {
2352 return null;
2353 }
2354 }, const <int>[]);
2339 } else { 2355 } else {
2340 return null; 2356 FunctionType rawType = StaticTypeAnalyzer
2357 .constructorToGenericFunctionType(constructorElement);
2358 FunctionType inferredType = _inferExecutableType(
2359 rawType,
2360 numNamed,
2361 numPositional,
2362 namedArgNames,
2363 namedArgTypeList,
2364 positionalArgTypes, const <DartType>[]);
2365 if (identical(inferredType, rawType)) {
2366 inferredType = linker.typeSystem.instantiateToBounds(rawType);
2367 }
2368 return inferredType.returnType;
2341 } 2369 }
2342 }, const [])); 2370 }());
2343 } else { 2371 } else {
2344 stack.add(DynamicTypeImpl.instance); 2372 ClassElementForLink classElement =
2373 unit.resolveConstructorClassRef(ref.reference).asClass;
2374 stack.add(classElement?.type ?? DynamicTypeImpl.instance);
2345 } 2375 }
2346 } 2376 }
2347 2377
2348 void _doInvokeMethod() { 2378 void _doInvokeMethod() {
2349 int numNamed = unlinkedConst.ints[intPtr++]; 2379 int numNamed = unlinkedConst.ints[intPtr++];
2350 int numPositional = unlinkedConst.ints[intPtr++]; 2380 int numPositional = unlinkedConst.ints[intPtr++];
2351 List<String> namedArgNames = _getNextStrings(numNamed); 2381 List<String> namedArgNames = _getNextStrings(numNamed);
2352 List<DartType> namedArgTypeList = _popList(numNamed); 2382 List<DartType> namedArgTypeList = _popList(numNamed);
2353 List<DartType> positionalArgTypes = _popList(numPositional); 2383 List<DartType> positionalArgTypes = _popList(numPositional);
2354 // TODO(scheglov) if we pushed target and method name first, we might be 2384 // TODO(scheglov) if we pushed target and method name first, we might be
(...skipping 2671 matching lines...) Expand 10 before | Expand all | Expand 10 after
5026 * there are no type parameters in scope. 5056 * there are no type parameters in scope.
5027 */ 5057 */
5028 TypeParameterizedElementMixin get _typeParameterContext; 5058 TypeParameterizedElementMixin get _typeParameterContext;
5029 5059
5030 @override 5060 @override
5031 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 5061 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
5032 5062
5033 @override 5063 @override
5034 String toString() => '$enclosingElement.$name'; 5064 String toString() => '$enclosingElement.$name';
5035 } 5065 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/static_type_analyzer.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_ast_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698