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

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

Issue 2694403003: Add CompilationUnitElement.lineInfo and resynthesize it. (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) 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 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 /** 1030 /**
1031 * A task that builds a compilation unit element for a single compilation unit. 1031 * A task that builds a compilation unit element for a single compilation unit.
1032 */ 1032 */
1033 class BuildCompilationUnitElementTask extends SourceBasedAnalysisTask { 1033 class BuildCompilationUnitElementTask extends SourceBasedAnalysisTask {
1034 /** 1034 /**
1035 * The name of the input whose value is the AST for the compilation unit. 1035 * The name of the input whose value is the AST for the compilation unit.
1036 */ 1036 */
1037 static const String PARSED_UNIT_INPUT_NAME = 'PARSED_UNIT_INPUT_NAME'; 1037 static const String PARSED_UNIT_INPUT_NAME = 'PARSED_UNIT_INPUT_NAME';
1038 1038
1039 /** 1039 /**
1040 * The name of the input whose value is the source line info.
1041 */
1042 static const String LINE_INFO_INPUT_NAME = 'LINE_INFO_INPUT_NAME';
1043
1044 /**
1040 * The task descriptor describing this kind of task. 1045 * The task descriptor describing this kind of task.
1041 */ 1046 */
1042 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 1047 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
1043 'BuildCompilationUnitElementTask', 1048 'BuildCompilationUnitElementTask',
1044 createTask, 1049 createTask,
1045 buildInputs, <ResultDescriptor>[ 1050 buildInputs, <ResultDescriptor>[
1046 COMPILATION_UNIT_CONSTANTS, 1051 COMPILATION_UNIT_CONSTANTS,
1047 COMPILATION_UNIT_ELEMENT, 1052 COMPILATION_UNIT_ELEMENT,
1048 CREATED_RESOLVED_UNIT1, 1053 CREATED_RESOLVED_UNIT1,
1049 RESOLVED_UNIT1 1054 RESOLVED_UNIT1
(...skipping 11 matching lines...) Expand all
1061 TaskDescriptor get descriptor => DESCRIPTOR; 1066 TaskDescriptor get descriptor => DESCRIPTOR;
1062 1067
1063 @override 1068 @override
1064 void internalPerform() { 1069 void internalPerform() {
1065 // 1070 //
1066 // Prepare inputs. 1071 // Prepare inputs.
1067 // 1072 //
1068 LibrarySpecificUnit librarySpecificUnit = target; 1073 LibrarySpecificUnit librarySpecificUnit = target;
1069 Source source = getRequiredSource(); 1074 Source source = getRequiredSource();
1070 CompilationUnit unit = getRequiredInput(PARSED_UNIT_INPUT_NAME); 1075 CompilationUnit unit = getRequiredInput(PARSED_UNIT_INPUT_NAME);
1076 LineInfo lineInfo = getRequiredInput(LINE_INFO_INPUT_NAME);
1071 // 1077 //
1072 // Try to get the existing CompilationUnitElement. 1078 // Try to get the existing CompilationUnitElement.
1073 // 1079 //
1074 CompilationUnitElement element; 1080 CompilationUnitElement element;
1075 { 1081 {
1076 InternalAnalysisContext internalContext = 1082 InternalAnalysisContext internalContext =
1077 context as InternalAnalysisContext; 1083 context as InternalAnalysisContext;
1078 AnalysisCache analysisCache = internalContext.analysisCache; 1084 AnalysisCache analysisCache = internalContext.analysisCache;
1079 CacheEntry cacheEntry = internalContext.getCacheEntry(target); 1085 CacheEntry cacheEntry = internalContext.getCacheEntry(target);
1080 element = analysisCache.getValue(target, COMPILATION_UNIT_ELEMENT); 1086 element = analysisCache.getValue(target, COMPILATION_UNIT_ELEMENT);
1081 if (element == null && 1087 if (element == null &&
1082 internalContext.aboutToComputeResult( 1088 internalContext.aboutToComputeResult(
1083 cacheEntry, COMPILATION_UNIT_ELEMENT)) { 1089 cacheEntry, COMPILATION_UNIT_ELEMENT)) {
1084 element = analysisCache.getValue(target, COMPILATION_UNIT_ELEMENT); 1090 element = analysisCache.getValue(target, COMPILATION_UNIT_ELEMENT);
1085 } 1091 }
1086 } 1092 }
1087 // 1093 //
1088 // Build or reuse CompilationUnitElement. 1094 // Build or reuse CompilationUnitElement.
1089 // 1095 //
1090 if (element == null) { 1096 if (element == null) {
1091 CompilationUnitBuilder builder = new CompilationUnitBuilder(); 1097 CompilationUnitBuilder builder = new CompilationUnitBuilder();
1092 element = builder.buildCompilationUnit( 1098 element = builder.buildCompilationUnit(
1093 source, unit, librarySpecificUnit.library); 1099 source, unit, librarySpecificUnit.library);
1100 (element as CompilationUnitElementImpl).lineInfo = lineInfo;
1094 } else { 1101 } else {
1095 new DeclarationResolver().resolve(unit, element); 1102 new DeclarationResolver().resolve(unit, element);
1096 } 1103 }
1097 // 1104 //
1098 // Prepare constants. 1105 // Prepare constants.
1099 // 1106 //
1100 ConstantFinder constantFinder = new ConstantFinder(); 1107 ConstantFinder constantFinder = new ConstantFinder();
1101 unit.accept(constantFinder); 1108 unit.accept(constantFinder);
1102 List<ConstantEvaluationTarget> constants = 1109 List<ConstantEvaluationTarget> constants =
1103 constantFinder.constantsToCompute.toList(); 1110 constantFinder.constantsToCompute.toList();
1104 // 1111 //
1105 // Record outputs. 1112 // Record outputs.
1106 // 1113 //
1107 outputs[COMPILATION_UNIT_CONSTANTS] = constants; 1114 outputs[COMPILATION_UNIT_CONSTANTS] = constants;
1108 outputs[COMPILATION_UNIT_ELEMENT] = element; 1115 outputs[COMPILATION_UNIT_ELEMENT] = element;
1109 outputs[RESOLVED_UNIT1] = unit; 1116 outputs[RESOLVED_UNIT1] = unit;
1110 outputs[CREATED_RESOLVED_UNIT1] = true; 1117 outputs[CREATED_RESOLVED_UNIT1] = true;
1111 } 1118 }
1112 1119
1113 /** 1120 /**
1114 * Return a map from the names of the inputs of this kind of task to the task 1121 * Return a map from the names of the inputs of this kind of task to the task
1115 * input descriptors describing those inputs for a task with the given 1122 * input descriptors describing those inputs for a task with the given
1116 * [target]. 1123 * [target].
1117 */ 1124 */
1118 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 1125 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1119 LibrarySpecificUnit unit = target; 1126 LibrarySpecificUnit unit = target;
1120 return <String, TaskInput>{ 1127 return <String, TaskInput>{
1121 PARSED_UNIT_INPUT_NAME: PARSED_UNIT.of(unit.unit, flushOnAccess: true) 1128 PARSED_UNIT_INPUT_NAME: PARSED_UNIT.of(unit.unit, flushOnAccess: true),
1129 LINE_INFO_INPUT_NAME: LINE_INFO.of(unit.unit)
1122 }; 1130 };
1123 } 1131 }
1124 1132
1125 /** 1133 /**
1126 * Create a [BuildCompilationUnitElementTask] based on the given [target] in 1134 * Create a [BuildCompilationUnitElementTask] based on the given [target] in
1127 * the given [context]. 1135 * the given [context].
1128 */ 1136 */
1129 static BuildCompilationUnitElementTask createTask( 1137 static BuildCompilationUnitElementTask createTask(
1130 AnalysisContext context, AnalysisTarget target) { 1138 AnalysisContext context, AnalysisTarget target) {
1131 return new BuildCompilationUnitElementTask(context, target); 1139 return new BuildCompilationUnitElementTask(context, target);
(...skipping 5423 matching lines...) Expand 10 before | Expand all | Expand 10 after
6555 6563
6556 @override 6564 @override
6557 bool moveNext() { 6565 bool moveNext() {
6558 if (_newSources.isEmpty) { 6566 if (_newSources.isEmpty) {
6559 return false; 6567 return false;
6560 } 6568 }
6561 currentTarget = _newSources.removeLast(); 6569 currentTarget = _newSources.removeLast();
6562 return true; 6570 return true;
6563 } 6571 }
6564 } 6572 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698