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

Side by Side Diff: pkg/analyzer/lib/src/task/dart.dart

Issue 1131953004: Create a task in the new task model to compute constant dependencies. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 | Annotate | Revision Log
OLDNEW
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';
11 import 'package:analyzer/src/generated/constant.dart';
11 import 'package:analyzer/src/generated/element.dart'; 12 import 'package:analyzer/src/generated/element.dart';
12 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; 13 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask;
13 import 'package:analyzer/src/generated/error.dart'; 14 import 'package:analyzer/src/generated/error.dart';
14 import 'package:analyzer/src/generated/error_verifier.dart'; 15 import 'package:analyzer/src/generated/error_verifier.dart';
15 import 'package:analyzer/src/generated/java_engine.dart'; 16 import 'package:analyzer/src/generated/java_engine.dart';
16 import 'package:analyzer/src/generated/parser.dart'; 17 import 'package:analyzer/src/generated/parser.dart';
17 import 'package:analyzer/src/generated/resolver.dart'; 18 import 'package:analyzer/src/generated/resolver.dart';
18 import 'package:analyzer/src/generated/scanner.dart'; 19 import 'package:analyzer/src/generated/scanner.dart';
19 import 'package:analyzer/src/generated/sdk.dart'; 20 import 'package:analyzer/src/generated/sdk.dart';
20 import 'package:analyzer/src/generated/source.dart'; 21 import 'package:analyzer/src/generated/source.dart';
(...skipping 1612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 /** 1634 /**
1634 * Create a [BuildTypeProviderTask] based on the given [context]. 1635 * Create a [BuildTypeProviderTask] based on the given [context].
1635 */ 1636 */
1636 static BuildTypeProviderTask createTask( 1637 static BuildTypeProviderTask createTask(
1637 AnalysisContext context, AnalysisContextTarget target) { 1638 AnalysisContext context, AnalysisContextTarget target) {
1638 return new BuildTypeProviderTask(context, target); 1639 return new BuildTypeProviderTask(context, target);
1639 } 1640 }
1640 } 1641 }
1641 1642
1642 /** 1643 /**
1644 * A task that computes [CONSTANT_DEPENDENCIES] for a constant.
1645 */
1646 class ComputeConstantDependenciesTask extends AnalysisTask {
1647 /**
1648 * The name of the [RESOLVED_UNIT] input.
1649 */
1650 static const String UNIT_INPUT = 'UNIT_INPUT';
Brian Wilkerson 2015/05/07 22:46:59 Perhaps "RESOLVED_UNIT_INPUT" to be consistent?
Paul Berry 2015/05/08 00:24:35 Personally I don't see much benefit in the longer
1651
1652 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1653 'ComputeConstantDependenciesTask', createTask, buildInputs,
1654 <ResultDescriptor>[CONSTANT_DEPENDENCIES]);
1655
1656 ComputeConstantDependenciesTask(
1657 InternalAnalysisContext context, AnalysisTarget target)
1658 : super(context, target);
1659
1660 @override
1661 String get description {
1662 Source source = target.source;
1663 String sourceName = source == null ? '<unknown source>' : source.fullName;
1664 return '${descriptor.name} for element $target in source $sourceName';
1665 }
1666
1667 @override
1668 TaskDescriptor get descriptor => DESCRIPTOR;
1669
1670 @override
1671 void internalPerform() {
1672 //
1673 // Prepare inputs.
1674 //
1675 // Note: UNIT_INPUT is not needed. It is merely a bookkeeping dependency
1676 // to ensure that resolution has occurred before we attempto to determine
Brian Wilkerson 2015/05/07 22:46:59 "attempto" --> "attempt to"
scheglov 2015/05/07 22:52:09 attempto -> attempt
Paul Berry 2015/05/08 00:24:35 Done.
1677 // constant dependencies.
1678 //
1679 Element element = target;
1680 AnalysisContext context = element.context;
1681 TypeProvider typeProvider = context.typeProvider;
Brian Wilkerson 2015/05/07 22:46:59 I believe that you want to have a TYPE_PROVIDER in
Paul Berry 2015/05/08 00:24:35 Hmm, I believe you are right, since some analysis
scheglov 2015/05/08 03:53:00 I don't think we want to request all information w
Brian Wilkerson 2015/05/08 14:11:29 But not doing so could (although I admit the proba
scheglov 2015/05/08 15:14:36 No, there isn't. Just consistency.
1682 //
1683 // Compute dependencies.
1684 //
1685 List<Element> dependencies = <Element>[];
1686 new ConstantEvaluationEngine(typeProvider, context.declaredVariables)
1687 .computeDependencies(element, dependencies.add);
1688 //
1689 // Record outputs.
1690 //
1691 outputs[CONSTANT_DEPENDENCIES] = dependencies;
1692 }
1693
1694 /**
1695 * Return a map from the names of the inputs of this kind of task to the task
1696 * input descriptors describing those inputs for a task with the
1697 * given [target].
1698 */
1699 static Map<String, TaskInput> buildInputs(Element target) {
1700 return <String, TaskInput>{
1701 UNIT_INPUT: RESOLVED_UNIT
1702 .of(new LibrarySpecificUnit(target.library.source, target.source))
1703 };
1704 }
1705
1706 /**
1707 * Create a [ResolveReferencesTask] based on the given [target] in
1708 * the given [context].
1709 */
1710 static ComputeConstantDependenciesTask createTask(
1711 AnalysisContext context, AnalysisTarget target) {
1712 return new ComputeConstantDependenciesTask(context, target);
1713 }
1714 }
1715
1716 /**
1643 * A task that computes a list of the libraries containing the target source. 1717 * A task that computes a list of the libraries containing the target source.
1644 */ 1718 */
1645 class ContainingLibrariesTask extends SourceBasedAnalysisTask { 1719 class ContainingLibrariesTask extends SourceBasedAnalysisTask {
1646 /** 1720 /**
1647 * The task descriptor describing this kind of task. 1721 * The task descriptor describing this kind of task.
1648 */ 1722 */
1649 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1723 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1650 'ContainingLibrariesTask', createTask, buildInputs, 1724 'ContainingLibrariesTask', createTask, buildInputs,
1651 <ResultDescriptor>[CONTAINING_LIBRARIES]); 1725 <ResultDescriptor>[CONTAINING_LIBRARIES]);
1652 1726
(...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after
2982 @override 3056 @override
2983 bool moveNext() { 3057 bool moveNext() {
2984 if (_newSources.isEmpty) { 3058 if (_newSources.isEmpty) {
2985 return false; 3059 return false;
2986 } 3060 }
2987 currentTarget = _newSources.first; 3061 currentTarget = _newSources.first;
2988 _newSources.remove(currentTarget); 3062 _newSources.remove(currentTarget);
2989 return true; 3063 return true;
2990 } 3064 }
2991 } 3065 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698