Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library analyzer.src.task.dart; | 5 library analyzer.src.task.dart; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' as math; | 8 import 'dart:math' as math; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 * | 170 * |
| 171 * In addition to [LIBRARY_ELEMENT2] the [LibraryElement.publicNamespace] is set . | 171 * In addition to [LIBRARY_ELEMENT2] the [LibraryElement.publicNamespace] is set . |
| 172 * | 172 * |
| 173 * The result is only available for targets representing a Dart library. | 173 * The result is only available for targets representing a Dart library. |
| 174 */ | 174 */ |
| 175 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT3 = | 175 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT3 = |
| 176 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT3', null, | 176 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT3', null, |
| 177 cachingPolicy: ELEMENT_CACHING_POLICY); | 177 cachingPolicy: ELEMENT_CACHING_POLICY); |
| 178 | 178 |
| 179 /** | 179 /** |
| 180 * An [Element] that has been successfully constant-evaluated. | |
| 181 * | |
| 182 * TODO(paulberry): is ELEMENT_CACHING_POLICY the correct caching policy? | |
|
Brian Wilkerson
2015/05/08 19:22:38
Long term, probably not. But I don't think it will
Paul Berry
2015/05/08 19:44:22
Ok, I will leave the TODO message as a reminder to
| |
| 183 */ | |
| 184 final ResultDescriptor<Element> CONSTANT_EVALUATED_ELEMENT = new ResultDescripto r<Element>('CONST_EVALUATED_ELEMENT', null, cachingPolicy: ELEMENT_CACHING_POLIC Y); | |
|
Brian Wilkerson
2015/05/08 19:22:38
Perhaps format the file?
Paul Berry
2015/05/08 19:44:22
Done.
| |
| 185 | |
| 186 /** | |
| 180 * The partial [LibraryElement] associated with a library. | 187 * The partial [LibraryElement] associated with a library. |
| 181 * | 188 * |
| 182 * In addition to [LIBRARY_ELEMENT3] the [LibraryElement.entryPoint] is set, | 189 * In addition to [LIBRARY_ELEMENT3] the [LibraryElement.entryPoint] is set, |
| 183 * if the library does not declare one already and one of the exported | 190 * if the library does not declare one already and one of the exported |
| 184 * libraries exports one. | 191 * libraries exports one. |
| 185 * | 192 * |
| 186 * Also [LibraryElement.exportNamespace] is set. | 193 * Also [LibraryElement.exportNamespace] is set. |
| 187 * | 194 * |
| 188 * The result is only available for targets representing a Dart library. | 195 * The result is only available for targets representing a Dart library. |
| 189 */ | 196 */ |
| (...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1605 /** | 1612 /** |
| 1606 * Create a [BuildTypeProviderTask] based on the given [context]. | 1613 * Create a [BuildTypeProviderTask] based on the given [context]. |
| 1607 */ | 1614 */ |
| 1608 static BuildTypeProviderTask createTask( | 1615 static BuildTypeProviderTask createTask( |
| 1609 AnalysisContext context, AnalysisContextTarget target) { | 1616 AnalysisContext context, AnalysisContextTarget target) { |
| 1610 return new BuildTypeProviderTask(context, target); | 1617 return new BuildTypeProviderTask(context, target); |
| 1611 } | 1618 } |
| 1612 } | 1619 } |
| 1613 | 1620 |
| 1614 /** | 1621 /** |
| 1622 * A task that computes the value of a constant ([CONSTANT_EVALUATED_ELEMENT]) a nd | |
| 1623 * stores it in the element model. | |
| 1624 */ | |
| 1625 class ComputeConstantValueTask extends ElementBasedAnalysisTask { | |
| 1626 /** | |
| 1627 * The name of the input which ensures that dependent constants are evaluated | |
| 1628 * before the target. | |
| 1629 */ | |
| 1630 static const String DEPENDENCIES_INPUT = 'DEPENDENCIES_INPUT'; | |
| 1631 | |
| 1632 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('ComputeConstantVa lueTask', | |
| 1633 createTask, buildInputs, <ResultDescriptor>[CONSTANT_EVALUATED_ELEMENT]); | |
| 1634 | |
| 1635 ComputeConstantValueTask(InternalAnalysisContext context, Element element) | |
| 1636 : super(context, element); | |
| 1637 | |
| 1638 @override | |
| 1639 TaskDescriptor get descriptor => DESCRIPTOR; | |
| 1640 | |
| 1641 @override | |
| 1642 void internalPerform() { | |
| 1643 // | |
| 1644 // Prepare inputs. | |
| 1645 // | |
| 1646 // Note: DEPENDENCIES_INPUT is not needed. It is merely a bookkeeping | |
| 1647 // dependency to ensure that the constants that this constant depends on | |
| 1648 // are computed first. | |
|
scheglov
2015/05/08 18:46:07
Should this comment be removed?
Paul Berry
2015/05/08 19:44:22
I think it should stay. I was trying to explain w
| |
| 1649 Element element = target; | |
| 1650 AnalysisContext context = element.context; | |
| 1651 TypeProvider typeProvider = context.typeProvider; | |
| 1652 // | |
| 1653 // Compute the value of the constant. | |
| 1654 // | |
| 1655 new ConstantEvaluationEngine(typeProvider, context.declaredVariables).comput eConstantValue(element); | |
| 1656 // | |
| 1657 // Record outputs. | |
| 1658 // | |
| 1659 outputs[CONSTANT_EVALUATED_ELEMENT] = element; | |
| 1660 } | |
| 1661 | |
| 1662 /** | |
| 1663 * Return a map from the names of the inputs of this kind of task to the task | |
| 1664 * input descriptors describing those inputs for a task with the given | |
| 1665 * [target]. | |
| 1666 */ | |
| 1667 static Map<String, TaskInput> buildInputs(Element target) { | |
| 1668 return <String, TaskInput>{ | |
| 1669 DEPENDENCIES_INPUT: CONSTANT_DEPENDENCIES.of(target).toListOf(CONSTANT_EVA LUATED_ELEMENT) | |
| 1670 }; | |
| 1671 } | |
| 1672 | |
| 1673 /** | |
| 1674 * Create a [ComputeConstantValueTask] based on the given [target] in the | |
| 1675 * given [context]. | |
| 1676 */ | |
| 1677 static ComputeConstantValueTask createTask(AnalysisContext context, AnalysisTa rget target) { | |
| 1678 return new ComputeConstantValueTask(context, target); | |
| 1679 } | |
| 1680 } | |
| 1681 | |
| 1682 /** | |
| 1615 * A task that computes [CONSTANT_DEPENDENCIES] for a constant. | 1683 * A task that computes [CONSTANT_DEPENDENCIES] for a constant. |
| 1616 */ | 1684 */ |
| 1617 class ComputeConstantDependenciesTask extends AnalysisTask { | 1685 class ComputeConstantDependenciesTask extends ElementBasedAnalysisTask { |
| 1618 /** | 1686 /** |
| 1619 * The name of the [RESOLVED_UNIT] input. | 1687 * The name of the [RESOLVED_UNIT] input. |
| 1620 */ | 1688 */ |
| 1621 static const String UNIT_INPUT = 'UNIT_INPUT'; | 1689 static const String UNIT_INPUT = 'UNIT_INPUT'; |
| 1622 | 1690 |
| 1623 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 1691 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 1624 'ComputeConstantDependenciesTask', createTask, buildInputs, | 1692 'ComputeConstantDependenciesTask', createTask, buildInputs, |
| 1625 <ResultDescriptor>[CONSTANT_DEPENDENCIES]); | 1693 <ResultDescriptor>[CONSTANT_DEPENDENCIES]); |
| 1626 | 1694 |
| 1627 ComputeConstantDependenciesTask( | 1695 ComputeConstantDependenciesTask( |
| 1628 InternalAnalysisContext context, AnalysisTarget target) | 1696 InternalAnalysisContext context, Element element) |
| 1629 : super(context, target); | 1697 : super(context, element); |
| 1630 | |
| 1631 @override | |
| 1632 String get description { | |
| 1633 Source source = target.source; | |
| 1634 String sourceName = source == null ? '<unknown source>' : source.fullName; | |
| 1635 return '${descriptor.name} for element $target in source $sourceName'; | |
| 1636 } | |
| 1637 | 1698 |
| 1638 @override | 1699 @override |
| 1639 TaskDescriptor get descriptor => DESCRIPTOR; | 1700 TaskDescriptor get descriptor => DESCRIPTOR; |
| 1640 | 1701 |
| 1641 @override | 1702 @override |
| 1642 void internalPerform() { | 1703 void internalPerform() { |
| 1643 // | 1704 // |
| 1644 // Prepare inputs. | 1705 // Prepare inputs. |
| 1645 // | 1706 // |
| 1646 // Note: UNIT_INPUT is not needed. It is merely a bookkeeping dependency | 1707 // Note: UNIT_INPUT is not needed. It is merely a bookkeeping dependency |
| (...skipping 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2966 @override | 3027 @override |
| 2967 bool moveNext() { | 3028 bool moveNext() { |
| 2968 if (_newSources.isEmpty) { | 3029 if (_newSources.isEmpty) { |
| 2969 return false; | 3030 return false; |
| 2970 } | 3031 } |
| 2971 currentTarget = _newSources.first; | 3032 currentTarget = _newSources.first; |
| 2972 _newSources.remove(currentTarget); | 3033 _newSources.remove(currentTarget); |
| 2973 return true; | 3034 return true; |
| 2974 } | 3035 } |
| 2975 } | 3036 } |
| OLD | NEW |