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 1018443003: Start analyzing LibraryUnitTarget(s) from BuildLibraryElementTask. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/ast.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
11 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; 11 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask;
12 import 'package:analyzer/src/generated/error.dart'; 12 import 'package:analyzer/src/generated/error.dart';
13 import 'package:analyzer/src/generated/java_engine.dart'; 13 import 'package:analyzer/src/generated/java_engine.dart';
14 import 'package:analyzer/src/generated/parser.dart'; 14 import 'package:analyzer/src/generated/parser.dart';
15 import 'package:analyzer/src/generated/resolver.dart'; 15 import 'package:analyzer/src/generated/resolver.dart';
16 import 'package:analyzer/src/generated/scanner.dart'; 16 import 'package:analyzer/src/generated/scanner.dart';
17 import 'package:analyzer/src/generated/sdk.dart'; 17 import 'package:analyzer/src/generated/sdk.dart';
18 import 'package:analyzer/src/generated/source.dart'; 18 import 'package:analyzer/src/generated/source.dart';
19 import 'package:analyzer/src/generated/utilities_general.dart';
19 import 'package:analyzer/src/task/driver.dart'; 20 import 'package:analyzer/src/task/driver.dart';
20 import 'package:analyzer/src/task/general.dart'; 21 import 'package:analyzer/src/task/general.dart';
21 import 'package:analyzer/src/task/inputs.dart'; 22 import 'package:analyzer/src/task/inputs.dart';
22 import 'package:analyzer/task/dart.dart'; 23 import 'package:analyzer/task/dart.dart';
23 import 'package:analyzer/task/general.dart'; 24 import 'package:analyzer/task/general.dart';
24 import 'package:analyzer/task/model.dart'; 25 import 'package:analyzer/task/model.dart';
25 26
26 /** 27 /**
27 * The errors produced while resolving a library directives. 28 * The errors produced while resolving a library directives.
28 * 29 *
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 */ 133 */
133 BuildCompilationUnitElementTask( 134 BuildCompilationUnitElementTask(
134 InternalAnalysisContext context, AnalysisTarget target) 135 InternalAnalysisContext context, AnalysisTarget target)
135 : super(context, target); 136 : super(context, target);
136 137
137 @override 138 @override
138 TaskDescriptor get descriptor => DESCRIPTOR; 139 TaskDescriptor get descriptor => DESCRIPTOR;
139 140
140 @override 141 @override
141 void internalPerform() { 142 void internalPerform() {
143 //
144 // Prepare inputs.
145 //
142 Source source = getRequiredSource(); 146 Source source = getRequiredSource();
143 CompilationUnit unit = getRequiredInput(PARSED_UNIT_INPUT_NAME); 147 CompilationUnit unit = getRequiredInput(PARSED_UNIT_INPUT_NAME);
144 148 //
149 // Process inputs.
150 //
151 unit = AstCloner.clone(unit);
145 CompilationUnitBuilder builder = new CompilationUnitBuilder(); 152 CompilationUnitBuilder builder = new CompilationUnitBuilder();
146 CompilationUnitElement element = builder.buildCompilationUnit(source, unit); 153 CompilationUnitElement element = builder.buildCompilationUnit(source, unit);
147 154 //
155 // Record outputs.
156 //
148 outputs[COMPILATION_UNIT_ELEMENT] = element; 157 outputs[COMPILATION_UNIT_ELEMENT] = element;
149 outputs[RESOLVED_UNIT1] = unit; 158 outputs[RESOLVED_UNIT1] = unit;
150 } 159 }
151 160
152 /** 161 /**
153 * Return a map from the names of the inputs of this kind of task to the task 162 * Return a map from the names of the inputs of this kind of task to the task
154 * input descriptors describing those inputs for a task with the given [target ]. 163 * input descriptors describing those inputs for a task with the given
164 * [target].
155 */ 165 */
156 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 166 static Map<String, TaskInput> buildInputs(LibraryUnitTarget target) {
157 return <String, TaskInput>{ 167 return <String, TaskInput>{
158 PARSED_UNIT_INPUT_NAME: PARSED_UNIT.inputFor(target) 168 PARSED_UNIT_INPUT_NAME: PARSED_UNIT.inputFor(target.unit)
159 }; 169 };
160 } 170 }
161 171
162 /** 172 /**
163 * Create a [BuildCompilationUnitElementTask] based on the given [target] in 173 * Create a [BuildCompilationUnitElementTask] based on the given [target] in
164 * the given [context]. 174 * the given [context].
165 */ 175 */
166 static BuildCompilationUnitElementTask createTask( 176 static BuildCompilationUnitElementTask createTask(
167 AnalysisContext context, AnalysisTarget target) { 177 AnalysisContext context, AnalysisTarget target) {
168 return new BuildCompilationUnitElementTask(context, target); 178 return new BuildCompilationUnitElementTask(context, target);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 // 361 //
352 // Record outputs. 362 // Record outputs.
353 // 363 //
354 outputs[RESOLVED_UNIT3] = libraryUnit; 364 outputs[RESOLVED_UNIT3] = libraryUnit;
355 outputs[BUILD_DIRECTIVES_ERRORS] = errors; 365 outputs[BUILD_DIRECTIVES_ERRORS] = errors;
356 } 366 }
357 367
358 /** 368 /**
359 * Return a map from the names of the inputs of this kind of task to the task 369 * Return a map from the names of the inputs of this kind of task to the task
360 * input descriptors describing those inputs for a task with the 370 * input descriptors describing those inputs for a task with the
361 * given [target]. 371 * given library [source].
362 */ 372 */
363 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 373 static Map<String, TaskInput> buildInputs(Source source) {
364 return <String, TaskInput>{ 374 return <String, TaskInput>{
365 RESOLVED_UNIT2_INPUT_NAME: RESOLVED_UNIT2.inputFor(target), 375 RESOLVED_UNIT2_INPUT_NAME: RESOLVED_UNIT2.inputFor(source),
366 IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME: 376 IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME:
367 new ListToMapTaskInput<Source, LibraryElement>( 377 new ListToMapTaskInput<Source, LibraryElement>(
368 IMPORTED_LIBRARIES.inputFor(target), 378 IMPORTED_LIBRARIES.inputFor(source),
369 (Source source) => LIBRARY_ELEMENT1.inputFor(source)), 379 (Source source) => LIBRARY_ELEMENT1.inputFor(source)),
370 EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME: 380 EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME:
371 new ListToMapTaskInput<Source, LibraryElement>( 381 new ListToMapTaskInput<Source, LibraryElement>(
372 EXPORTED_LIBRARIES.inputFor(target), 382 EXPORTED_LIBRARIES.inputFor(source),
373 (Source source) => LIBRARY_ELEMENT1.inputFor(source)), 383 (Source source) => LIBRARY_ELEMENT1.inputFor(source)),
374 IMPORTS_SOURCE_KIND_INPUT_NAME: 384 IMPORTS_SOURCE_KIND_INPUT_NAME:
375 new ListToMapTaskInput<Source, SourceKind>( 385 new ListToMapTaskInput<Source, SourceKind>(
376 IMPORTED_LIBRARIES.inputFor(target), 386 IMPORTED_LIBRARIES.inputFor(source),
377 (Source source) => SOURCE_KIND.inputFor(source)), 387 (Source source) => SOURCE_KIND.inputFor(source)),
378 EXPORTS_SOURCE_KIND_INPUT_NAME: 388 EXPORTS_SOURCE_KIND_INPUT_NAME:
379 new ListToMapTaskInput<Source, SourceKind>( 389 new ListToMapTaskInput<Source, SourceKind>(
380 EXPORTED_LIBRARIES.inputFor(target), 390 EXPORTED_LIBRARIES.inputFor(source),
381 (Source source) => SOURCE_KIND.inputFor(source)) 391 (Source source) => SOURCE_KIND.inputFor(source))
382 }; 392 };
383 } 393 }
384 394
385 /** 395 /**
386 * Create a [BuildDirectiveElementsTask] based on the given [target] in 396 * Create a [BuildDirectiveElementsTask] based on the given [target] in
387 * the given [context]. 397 * the given [context].
388 */ 398 */
389 static BuildDirectiveElementsTask createTask( 399 static BuildDirectiveElementsTask createTask(
390 AnalysisContext context, AnalysisTarget target) { 400 AnalysisContext context, AnalysisTarget target) {
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 setterUnit.replaceTopLevelVariable(setterVariable, variable); 739 setterUnit.replaceTopLevelVariable(setterVariable, variable);
730 variable.setter = setter; 740 variable.setter = setter;
731 setter.variable = variable; 741 setter.variable = variable;
732 } 742 }
733 } 743 }
734 } 744 }
735 745
736 /** 746 /**
737 * Return a map from the names of the inputs of this kind of task to the task 747 * Return a map from the names of the inputs of this kind of task to the task
738 * input descriptors describing those inputs for a task with the given 748 * input descriptors describing those inputs for a task with the given
739 * [target]. 749 * [librarySource].
740 */ 750 */
741 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 751 static Map<String, TaskInput> buildInputs(Source librarySource) {
742 return <String, TaskInput>{ 752 return <String, TaskInput>{
743 DEFINING_RESOLVER_UNIT1_INPUT_NAME: 753 DEFINING_RESOLVER_UNIT1_INPUT_NAME: RESOLVED_UNIT1
744 new SimpleTaskInput(target, RESOLVED_UNIT1), 754 .inputFor(new LibraryUnitTarget(librarySource, librarySource)),
745 PARTS_RESOLVED_UNIT1_INPUT_NAME: 755 PARTS_RESOLVED_UNIT1_INPUT_NAME:
746 new ListToListTaskInput<Source, CompilationUnit>( 756 new ListToListTaskInput<Source, CompilationUnit>(
747 INCLUDED_PARTS.inputFor(target), 757 INCLUDED_PARTS.inputFor(librarySource),
748 (Source source) => RESOLVED_UNIT1.inputFor(source)) 758 (Source source) => RESOLVED_UNIT1
759 .inputFor(new LibraryUnitTarget(librarySource, source)))
749 }; 760 };
750 } 761 }
751 762
752 /** 763 /**
753 * Create a [BuildLibraryElementTask] based on the given [target] in the 764 * Create a [BuildLibraryElementTask] based on the given [target] in the
754 * given [context]. 765 * given [context].
755 */ 766 */
756 static BuildLibraryElementTask createTask( 767 static BuildLibraryElementTask createTask(
757 AnalysisContext context, AnalysisTarget target) { 768 AnalysisContext context, AnalysisTarget target) {
758 return new BuildLibraryElementTask(context, target); 769 return new BuildLibraryElementTask(context, target);
(...skipping 30 matching lines...) Expand all
789 800
790 NamespaceBuilder builder = new NamespaceBuilder(); 801 NamespaceBuilder builder = new NamespaceBuilder();
791 Namespace namespace = builder.createPublicNamespaceForLibrary(library); 802 Namespace namespace = builder.createPublicNamespaceForLibrary(library);
792 803
793 outputs[PUBLIC_NAMESPACE] = namespace; 804 outputs[PUBLIC_NAMESPACE] = namespace;
794 } 805 }
795 806
796 /** 807 /**
797 * Return a map from the names of the inputs of this kind of task to the task 808 * Return a map from the names of the inputs of this kind of task to the task
798 * input descriptors describing those inputs for a task with the 809 * input descriptors describing those inputs for a task with the
799 * given [target]. 810 * given library [source].
800 */ 811 */
801 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 812 static Map<String, TaskInput> buildInputs(Source source) {
802 return <String, TaskInput>{ 813 return <String, TaskInput>{
803 BUILT_LIBRARY_ELEMENT_INPUT_NAME: LIBRARY_ELEMENT1.inputFor(target) 814 BUILT_LIBRARY_ELEMENT_INPUT_NAME: LIBRARY_ELEMENT1.inputFor(source)
804 }; 815 };
805 } 816 }
806 817
807 /** 818 /**
808 * Create a [BuildPublicNamespaceTask] based on the given [target] in 819 * Create a [BuildPublicNamespaceTask] based on the given [target] in
809 * the given [context]. 820 * the given [context].
810 */ 821 */
811 static BuildPublicNamespaceTask createTask( 822 static BuildPublicNamespaceTask createTask(
812 AnalysisContext context, AnalysisTarget target) { 823 AnalysisContext context, AnalysisTarget target) {
813 return new BuildPublicNamespaceTask(context, target); 824 return new BuildPublicNamespaceTask(context, target);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 /** 880 /**
870 * Create a [BuildTypeProviderTask] based on the given [context]. 881 * Create a [BuildTypeProviderTask] based on the given [context].
871 */ 882 */
872 static BuildTypeProviderTask createTask( 883 static BuildTypeProviderTask createTask(
873 AnalysisContext context, AnalysisContextTarget target) { 884 AnalysisContext context, AnalysisContextTarget target) {
874 return new BuildTypeProviderTask(context, target); 885 return new BuildTypeProviderTask(context, target);
875 } 886 }
876 } 887 }
877 888
878 /** 889 /**
890 * A pair of a library [Source] and a unit [Source] in this library.
891 */
892 class LibraryUnitTarget implements AnalysisTarget {
893 final Source library;
894 final Source unit;
895 LibraryUnitTarget(this.library, this.unit);
896
897 @override
898 int get hashCode {
899 return JenkinsSmiHash.combine(library.hashCode, unit.hashCode);
900 }
901
902 @override
903 Source get source => unit;
904
905 @override
906 bool operator ==(other) {
907 return other is LibraryUnitTarget &&
908 other.library == library &&
909 other.unit == unit;
910 }
911 }
912
913 /**
879 * A task that parses the content of a Dart file, producing an AST structure. 914 * A task that parses the content of a Dart file, producing an AST structure.
880 */ 915 */
881 class ParseDartTask extends SourceBasedAnalysisTask { 916 class ParseDartTask extends SourceBasedAnalysisTask {
882 /** 917 /**
883 * The name of the input whose value is the line information produced for the 918 * The name of the input whose value is the line information produced for the
884 * file. 919 * file.
885 */ 920 */
886 static const String LINE_INFO_INPUT_NAME = 'LINE_INFO_INPUT_NAME'; 921 static const String LINE_INFO_INPUT_NAME = 'LINE_INFO_INPUT_NAME';
887 922
888 /** 923 /**
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 outputs[EXPORTED_LIBRARIES] = exportedSources.toList(); 1009 outputs[EXPORTED_LIBRARIES] = exportedSources.toList();
975 outputs[IMPORTED_LIBRARIES] = importedSources.toList(); 1010 outputs[IMPORTED_LIBRARIES] = importedSources.toList();
976 outputs[INCLUDED_PARTS] = includedSources.toList(); 1011 outputs[INCLUDED_PARTS] = includedSources.toList();
977 outputs[PARSE_ERRORS] = errorListener.getErrorsForSource(source); 1012 outputs[PARSE_ERRORS] = errorListener.getErrorsForSource(source);
978 outputs[PARSED_UNIT] = unit; 1013 outputs[PARSED_UNIT] = unit;
979 outputs[SOURCE_KIND] = sourceKind; 1014 outputs[SOURCE_KIND] = sourceKind;
980 } 1015 }
981 1016
982 /** 1017 /**
983 * Return a map from the names of the inputs of this kind of task to the task 1018 * Return a map from the names of the inputs of this kind of task to the task
984 * input descriptors describing those inputs for a task with the given [target ]. 1019 * input descriptors describing those inputs for a task with the given
1020 * [source].
985 */ 1021 */
986 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 1022 static Map<String, TaskInput> buildInputs(Source source) {
987 return <String, TaskInput>{ 1023 return <String, TaskInput>{
988 LINE_INFO_INPUT_NAME: LINE_INFO.inputFor(target), 1024 LINE_INFO_INPUT_NAME: LINE_INFO.inputFor(source),
989 TOKEN_STREAM_INPUT_NAME: TOKEN_STREAM.inputFor(target) 1025 TOKEN_STREAM_INPUT_NAME: TOKEN_STREAM.inputFor(source)
990 }; 1026 };
991 } 1027 }
992 1028
993 /** 1029 /**
994 * Create a [ParseDartTask] based on the given [target] in the given 1030 * Create a [ParseDartTask] based on the given [target] in the given
995 * [context]. 1031 * [context].
996 */ 1032 */
997 static ParseDartTask createTask( 1033 static ParseDartTask createTask(
998 AnalysisContext context, AnalysisTarget target) { 1034 AnalysisContext context, AnalysisTarget target) {
999 return new ParseDartTask(context, target); 1035 return new ParseDartTask(context, target);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 Scanner scanner = 1115 Scanner scanner =
1080 new Scanner(source, new CharSequenceReader(content), errorListener); 1116 new Scanner(source, new CharSequenceReader(content), errorListener);
1081 scanner.preserveComments = context.analysisOptions.preserveComments; 1117 scanner.preserveComments = context.analysisOptions.preserveComments;
1082 outputs[TOKEN_STREAM] = scanner.tokenize(); 1118 outputs[TOKEN_STREAM] = scanner.tokenize();
1083 outputs[LINE_INFO] = new LineInfo(scanner.lineStarts); 1119 outputs[LINE_INFO] = new LineInfo(scanner.lineStarts);
1084 outputs[SCAN_ERRORS] = errorListener.getErrorsForSource(source); 1120 outputs[SCAN_ERRORS] = errorListener.getErrorsForSource(source);
1085 } 1121 }
1086 1122
1087 /** 1123 /**
1088 * Return a map from the names of the inputs of this kind of task to the task 1124 * Return a map from the names of the inputs of this kind of task to the task
1089 * input descriptors describing those inputs for a task with the given [target ]. 1125 * input descriptors describing those inputs for a task with the given
1126 * [source].
1090 */ 1127 */
1091 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 1128 static Map<String, TaskInput> buildInputs(Source source) {
1092 return <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.inputFor(target)}; 1129 return <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.inputFor(source)};
1093 } 1130 }
1094 1131
1095 /** 1132 /**
1096 * Create a [ScanDartTask] based on the given [target] in the given [context]. 1133 * Create a [ScanDartTask] based on the given [target] in the given [context].
1097 */ 1134 */
1098 static ScanDartTask createTask( 1135 static ScanDartTask createTask(
1099 AnalysisContext context, AnalysisTarget target) { 1136 AnalysisContext context, AnalysisTarget target) {
1100 return new ScanDartTask(context, target); 1137 return new ScanDartTask(context, target);
1101 } 1138 }
1102 } 1139 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/ast.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698