| OLD | NEW |
| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 * - Where possible, we favor method dispatch instead of "is" and "as" | 57 * - Where possible, we favor method dispatch instead of "is" and "as" |
| 58 * checks. E.g. see [ReferenceableElementForLink.asConstructor]. | 58 * checks. E.g. see [ReferenceableElementForLink.asConstructor]. |
| 59 */ | 59 */ |
| 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/generated/engine.dart'; |
| 67 import 'package:analyzer/src/generated/resolver.dart'; | 68 import 'package:analyzer/src/generated/resolver.dart'; |
| 68 import 'package:analyzer/src/generated/utilities_dart.dart'; | 69 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 69 import 'package:analyzer/src/summary/format.dart'; | 70 import 'package:analyzer/src/summary/format.dart'; |
| 70 import 'package:analyzer/src/summary/idl.dart'; | 71 import 'package:analyzer/src/summary/idl.dart'; |
| 71 import 'package:analyzer/src/summary/prelink.dart'; | 72 import 'package:analyzer/src/summary/prelink.dart'; |
| 72 import 'package:analyzer/src/task/strong_mode.dart'; | 73 import 'package:analyzer/src/task/strong_mode.dart'; |
| 73 | 74 |
| 74 bool isIncrementOrDecrement(UnlinkedExprAssignOperator operator) { | 75 bool isIncrementOrDecrement(UnlinkedExprAssignOperator operator) { |
| 75 switch (operator) { | 76 switch (operator) { |
| 76 case UnlinkedExprAssignOperator.prefixDecrement: | 77 case UnlinkedExprAssignOperator.prefixDecrement: |
| (...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1403 List<ConstNode> dependencies = <ConstNode>[]; | 1404 List<ConstNode> dependencies = <ConstNode>[]; |
| 1404 collectDependencies( | 1405 collectDependencies( |
| 1405 dependencies, | 1406 dependencies, |
| 1406 variableElement.unlinkedVariable.constExpr, | 1407 variableElement.unlinkedVariable.constExpr, |
| 1407 variableElement.compilationUnit); | 1408 variableElement.compilationUnit); |
| 1408 return dependencies; | 1409 return dependencies; |
| 1409 } | 1410 } |
| 1410 } | 1411 } |
| 1411 | 1412 |
| 1412 /** | 1413 /** |
| 1414 * Stub implementation of [AnalysisContext] which provides just those methods |
| 1415 * needed during linking. |
| 1416 */ |
| 1417 class ContextForLink implements AnalysisContext { |
| 1418 final Linker _linker; |
| 1419 |
| 1420 ContextForLink(this._linker); |
| 1421 |
| 1422 @override |
| 1423 TypeSystem get typeSystem => _linker.typeSystem; |
| 1424 |
| 1425 @override |
| 1426 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 1427 } |
| 1428 |
| 1429 /** |
| 1413 * An instance of [DependencyWalker] contains the core algorithms for | 1430 * An instance of [DependencyWalker] contains the core algorithms for |
| 1414 * walking a dependency graph and evaluating nodes in a safe order. | 1431 * walking a dependency graph and evaluating nodes in a safe order. |
| 1415 */ | 1432 */ |
| 1416 abstract class DependencyWalker<NodeType extends Node<NodeType>> { | 1433 abstract class DependencyWalker<NodeType extends Node<NodeType>> { |
| 1417 /** | 1434 /** |
| 1418 * Called by [walk] to evaluate a single non-cyclical node, after | 1435 * Called by [walk] to evaluate a single non-cyclical node, after |
| 1419 * all that node's dependencies have been evaluated. | 1436 * all that node's dependencies have been evaluated. |
| 1420 */ | 1437 */ |
| 1421 void evaluate(NodeType v); | 1438 void evaluate(NodeType v); |
| 1422 | 1439 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1546 * The unlinked representation of the method in the summary. | 1563 * The unlinked representation of the method in the summary. |
| 1547 */ | 1564 */ |
| 1548 final UnlinkedExecutable _unlinkedExecutable; | 1565 final UnlinkedExecutable _unlinkedExecutable; |
| 1549 | 1566 |
| 1550 DartType _declaredReturnType; | 1567 DartType _declaredReturnType; |
| 1551 DartType _inferredReturnType; | 1568 DartType _inferredReturnType; |
| 1552 FunctionTypeImpl _type; | 1569 FunctionTypeImpl _type; |
| 1553 List<TypeParameterElementForLink> _typeParameters; | 1570 List<TypeParameterElementForLink> _typeParameters; |
| 1554 String _name; | 1571 String _name; |
| 1555 List<ParameterElementForLink> _parameters; | 1572 List<ParameterElementForLink> _parameters; |
| 1573 String _displayName; |
| 1556 | 1574 |
| 1557 /** | 1575 /** |
| 1558 * TODO(paulberry): this won't always be a class element. | 1576 * TODO(paulberry): this won't always be a class element. |
| 1559 */ | 1577 */ |
| 1560 @override | 1578 @override |
| 1561 final ClassElementForLink_Class enclosingElement; | 1579 final ClassElementForLink_Class enclosingElement; |
| 1562 | 1580 |
| 1563 ExecutableElementForLink(this.enclosingElement, this._unlinkedExecutable); | 1581 ExecutableElementForLink(this.enclosingElement, this._unlinkedExecutable); |
| 1564 | 1582 |
| 1565 /** | 1583 /** |
| 1566 * Return the compilation unit in which this executable appears. | 1584 * Return the compilation unit in which this executable appears. |
| 1567 */ | 1585 */ |
| 1568 CompilationUnitElementForLink get compilationUnit => | 1586 CompilationUnitElementForLink get compilationUnit => |
| 1569 enclosingElement.enclosingElement; | 1587 enclosingElement.enclosingElement; |
| 1570 | 1588 |
| 1571 @override | 1589 @override |
| 1590 String get displayName { |
| 1591 if (_displayName == null) { |
| 1592 _displayName = _unlinkedExecutable.name; |
| 1593 if (_unlinkedExecutable.kind == UnlinkedExecutableKind.setter) { |
| 1594 _displayName = _displayName.substring(0, _displayName.length - 1); |
| 1595 } |
| 1596 } |
| 1597 return _displayName; |
| 1598 } |
| 1599 |
| 1600 @override |
| 1572 TypeParameterizedElementForLink get enclosingTypeParameterContext => | 1601 TypeParameterizedElementForLink get enclosingTypeParameterContext => |
| 1573 enclosingElement; | 1602 enclosingElement; |
| 1574 | 1603 |
| 1575 @override | 1604 @override |
| 1576 bool get hasImplicitReturnType => _unlinkedExecutable.returnType == null; | 1605 bool get hasImplicitReturnType => _unlinkedExecutable.returnType == null; |
| 1577 | 1606 |
| 1578 @override | 1607 @override |
| 1579 bool get isStatic => _unlinkedExecutable.isStatic; | 1608 bool get isStatic => _unlinkedExecutable.isStatic; |
| 1580 | 1609 |
| 1581 @override | 1610 @override |
| (...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2646 UnlinkedUnit _definingUnlinkedUnit; | 2675 UnlinkedUnit _definingUnlinkedUnit; |
| 2647 List<LibraryElementForLink> _importedLibraries; | 2676 List<LibraryElementForLink> _importedLibraries; |
| 2648 List<LibraryElementForLink> _exportedLibraries; | 2677 List<LibraryElementForLink> _exportedLibraries; |
| 2649 | 2678 |
| 2650 LibraryElementForLink(this._linker, this._absoluteUri) { | 2679 LibraryElementForLink(this._linker, this._absoluteUri) { |
| 2651 if (_linkedLibrary != null) { | 2680 if (_linkedLibrary != null) { |
| 2652 _dependencies.length = _linkedLibrary.dependencies.length; | 2681 _dependencies.length = _linkedLibrary.dependencies.length; |
| 2653 } | 2682 } |
| 2654 } | 2683 } |
| 2655 | 2684 |
| 2685 @override |
| 2686 ContextForLink get context => _linker.context; |
| 2687 |
| 2656 /** | 2688 /** |
| 2657 * Get the [UnlinkedUnit] for the defining compilation unit of this library. | 2689 * Get the [UnlinkedUnit] for the defining compilation unit of this library. |
| 2658 */ | 2690 */ |
| 2659 UnlinkedUnit get definingUnlinkedUnit => | 2691 UnlinkedUnit get definingUnlinkedUnit => |
| 2660 _definingUnlinkedUnit ??= _linker.getUnit(_absoluteUri.toString()); | 2692 _definingUnlinkedUnit ??= _linker.getUnit(_absoluteUri.toString()); |
| 2661 | 2693 |
| 2662 @override | 2694 @override |
| 2663 Element get enclosingElement => null; | 2695 Element get enclosingElement => null; |
| 2664 | 2696 |
| 2665 @override | 2697 @override |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2927 */ | 2959 */ |
| 2928 final bool strongMode; | 2960 final bool strongMode; |
| 2929 | 2961 |
| 2930 LibraryElementForLink _coreLibrary; | 2962 LibraryElementForLink _coreLibrary; |
| 2931 LibraryElementForLink _asyncLibrary; | 2963 LibraryElementForLink _asyncLibrary; |
| 2932 TypeProviderForLink _typeProvider; | 2964 TypeProviderForLink _typeProvider; |
| 2933 TypeSystem _typeSystem; | 2965 TypeSystem _typeSystem; |
| 2934 SpecialTypeElementForLink _voidElement; | 2966 SpecialTypeElementForLink _voidElement; |
| 2935 SpecialTypeElementForLink _dynamicElement; | 2967 SpecialTypeElementForLink _dynamicElement; |
| 2936 SpecialTypeElementForLink _bottomElement; | 2968 SpecialTypeElementForLink _bottomElement; |
| 2969 ContextForLink _context; |
| 2937 | 2970 |
| 2938 Linker(Map<String, LinkedLibraryBuilder> linkedLibraries, this.getDependency, | 2971 Linker(Map<String, LinkedLibraryBuilder> linkedLibraries, this.getDependency, |
| 2939 this.getUnit, this.strongMode) { | 2972 this.getUnit, this.strongMode) { |
| 2940 // Create elements for the libraries to be linked. The rest of | 2973 // Create elements for the libraries to be linked. The rest of |
| 2941 // the element model will be created on demand. | 2974 // the element model will be created on demand. |
| 2942 linkedLibraries | 2975 linkedLibraries |
| 2943 .forEach((String absoluteUri, LinkedLibraryBuilder linkedLibrary) { | 2976 .forEach((String absoluteUri, LinkedLibraryBuilder linkedLibrary) { |
| 2944 Uri uri = Uri.parse(absoluteUri); | 2977 Uri uri = Uri.parse(absoluteUri); |
| 2945 _librariesInBuildUnit.add(_libraries[uri] = | 2978 _librariesInBuildUnit.add(_libraries[uri] = |
| 2946 new LibraryElementInBuildUnit(this, uri, linkedLibrary)); | 2979 new LibraryElementInBuildUnit(this, uri, linkedLibrary)); |
| 2947 }); | 2980 }); |
| 2948 } | 2981 } |
| 2949 | 2982 |
| 2950 /** | 2983 /** |
| 2951 * Get the library element for `dart:async`. | 2984 * Get the library element for `dart:async`. |
| 2952 */ | 2985 */ |
| 2953 LibraryElementForLink get asyncLibrary => | 2986 LibraryElementForLink get asyncLibrary => |
| 2954 _asyncLibrary ??= getLibrary(Uri.parse('dart:async')); | 2987 _asyncLibrary ??= getLibrary(Uri.parse('dart:async')); |
| 2955 | 2988 |
| 2956 /** | 2989 /** |
| 2957 * Get the element representing the "bottom" type. | 2990 * Get the element representing the "bottom" type. |
| 2958 */ | 2991 */ |
| 2959 SpecialTypeElementForLink get bottomElement => _bottomElement ??= | 2992 SpecialTypeElementForLink get bottomElement => _bottomElement ??= |
| 2960 new SpecialTypeElementForLink(this, BottomTypeImpl.instance); | 2993 new SpecialTypeElementForLink(this, BottomTypeImpl.instance); |
| 2961 | 2994 |
| 2962 /** | 2995 /** |
| 2996 * Get a stub implementation of [AnalysisContext] which can be used during |
| 2997 * linking. |
| 2998 */ |
| 2999 get context => _context ??= new ContextForLink(this); |
| 3000 |
| 3001 /** |
| 2963 * Get the library element for `dart:core`. | 3002 * Get the library element for `dart:core`. |
| 2964 */ | 3003 */ |
| 2965 LibraryElementForLink get coreLibrary => | 3004 LibraryElementForLink get coreLibrary => |
| 2966 _coreLibrary ??= getLibrary(Uri.parse('dart:core')); | 3005 _coreLibrary ??= getLibrary(Uri.parse('dart:core')); |
| 2967 | 3006 |
| 2968 /** | 3007 /** |
| 2969 * Get the element representing `dynamic`. | 3008 * Get the element representing `dynamic`. |
| 2970 */ | 3009 */ |
| 2971 SpecialTypeElementForLink get dynamicElement => _dynamicElement ??= | 3010 SpecialTypeElementForLink get dynamicElement => _dynamicElement ??= |
| 2972 new SpecialTypeElementForLink(this, DynamicTypeImpl.instance); | 3011 new SpecialTypeElementForLink(this, DynamicTypeImpl.instance); |
| (...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4034 List<int> implicitFunctionTypeIndices) => | 4073 List<int> implicitFunctionTypeIndices) => |
| 4035 DynamicTypeImpl.instance; | 4074 DynamicTypeImpl.instance; |
| 4036 | 4075 |
| 4037 ReferenceableElementForLink getContainedName(String name) { | 4076 ReferenceableElementForLink getContainedName(String name) { |
| 4038 return new NonstaticMemberElementForLink(_constNode); | 4077 return new NonstaticMemberElementForLink(_constNode); |
| 4039 } | 4078 } |
| 4040 | 4079 |
| 4041 @override | 4080 @override |
| 4042 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 4081 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 4043 } | 4082 } |
| OLD | NEW |