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

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

Issue 1113223006: Use IncrementalCompilationUnitElementBuilder in BuildCompilationUnitElementTask. (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
« no previous file with comments | « no previous file | 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 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/element.dart'; 11 import 'package:analyzer/src/generated/element.dart';
12 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; 12 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask;
13 import 'package:analyzer/src/generated/error.dart'; 13 import 'package:analyzer/src/generated/error.dart';
14 import 'package:analyzer/src/generated/error_verifier.dart'; 14 import 'package:analyzer/src/generated/error_verifier.dart';
15 import 'package:analyzer/src/generated/java_engine.dart'; 15 import 'package:analyzer/src/generated/java_engine.dart';
16 import 'package:analyzer/src/generated/parser.dart'; 16 import 'package:analyzer/src/generated/parser.dart';
17 import 'package:analyzer/src/generated/resolver.dart'; 17 import 'package:analyzer/src/generated/resolver.dart';
18 import 'package:analyzer/src/generated/scanner.dart'; 18 import 'package:analyzer/src/generated/scanner.dart';
19 import 'package:analyzer/src/generated/sdk.dart'; 19 import 'package:analyzer/src/generated/sdk.dart';
20 import 'package:analyzer/src/generated/source.dart'; 20 import 'package:analyzer/src/generated/source.dart';
21 import 'package:analyzer/src/task/general.dart'; 21 import 'package:analyzer/src/task/general.dart';
22 import 'package:analyzer/task/dart.dart'; 22 import 'package:analyzer/task/dart.dart';
23 import 'package:analyzer/task/general.dart'; 23 import 'package:analyzer/task/general.dart';
24 import 'package:analyzer/task/model.dart'; 24 import 'package:analyzer/task/model.dart';
25 import 'package:analyzer/src/task/incremental_element_builder.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 *
29 * The list will be empty if there were no errors, but will not be `null`. 30 * The list will be empty if there were no errors, but will not be `null`.
30 * 31 *
31 * The result is only available for targets representing a Dart library. 32 * The result is only available for targets representing a Dart library.
32 */ 33 */
33 final ResultDescriptor<List<AnalysisError>> BUILD_DIRECTIVES_ERRORS = 34 final ResultDescriptor<List<AnalysisError>> BUILD_DIRECTIVES_ERRORS =
34 new ResultDescriptor<List<AnalysisError>>( 35 new ResultDescriptor<List<AnalysisError>>(
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 } 521 }
521 for (int i = argumentCount; i < parameterCount; i++) { 522 for (int i = argumentCount; i < parameterCount; i++) {
522 types[i] = dynamic; 523 types[i] = dynamic;
523 } 524 }
524 } 525 }
525 return types; 526 return types;
526 } 527 }
527 } 528 }
528 529
529 /** 530 /**
531 * The memento for [BuildCompilationUnitElementTask].
532 */
533 class BuildCompilationUnitElementMemento {
534 final List<ClassElement> classElements;
535 final CompilationUnit unit;
536 final CompilationUnitElement unitElement;
537 BuildCompilationUnitElementMemento(
538 this.classElements, this.unit, this.unitElement);
539 }
540
541 /**
530 * A task that builds a compilation unit element for a single compilation unit. 542 * A task that builds a compilation unit element for a single compilation unit.
531 */ 543 */
532 class BuildCompilationUnitElementTask extends SourceBasedAnalysisTask { 544 class BuildCompilationUnitElementTask extends SourceBasedAnalysisTask {
533 /** 545 /**
534 * The name of the input whose value is the line information for the
535 * compilation unit.
536 */
537 static const String LINE_INFO_INPUT_NAME = 'LINE_INFO_INPUT_NAME';
538
539 /**
540 * The name of the input whose value is the AST for the compilation unit. 546 * The name of the input whose value is the AST for the compilation unit.
541 */ 547 */
542 static const String PARSED_UNIT_INPUT_NAME = 'PARSED_UNIT_INPUT_NAME'; 548 static const String PARSED_UNIT_INPUT_NAME = 'PARSED_UNIT_INPUT_NAME';
543 549
544 /** 550 /**
545 * The task descriptor describing this kind of task. 551 * The task descriptor describing this kind of task.
546 */ 552 */
547 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( 553 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
548 'BuildCompilationUnitElementTask', createTask, buildInputs, 554 'BuildCompilationUnitElementTask', createTask, buildInputs,
549 <ResultDescriptor>[ 555 <ResultDescriptor>[
(...skipping 14 matching lines...) Expand all
564 TaskDescriptor get descriptor => DESCRIPTOR; 570 TaskDescriptor get descriptor => DESCRIPTOR;
565 571
566 @override 572 @override
567 void internalPerform() { 573 void internalPerform() {
568 // 574 //
569 // Prepare inputs. 575 // Prepare inputs.
570 // 576 //
571 Source source = getRequiredSource(); 577 Source source = getRequiredSource();
572 CompilationUnit unit = getRequiredInput(PARSED_UNIT_INPUT_NAME); 578 CompilationUnit unit = getRequiredInput(PARSED_UNIT_INPUT_NAME);
573 // 579 //
580 // Use memento.
581 //
582 if (inputMemento is BuildCompilationUnitElementMemento) {
583 BuildCompilationUnitElementMemento memento = inputMemento;
584 unit = AstCloner.clone(unit);
585 new IncrementalCompilationUnitElementBuilder(memento.unit, unit).build();
586 CompilationUnitElement element = unit.element;
587 outputs[CLASS_ELEMENTS] = element.types;
588 outputs[COMPILATION_UNIT_ELEMENT] = element;
589 outputs[RESOLVED_UNIT1] = unit;
590 outputMemento =
591 new BuildCompilationUnitElementMemento(element.types, unit, element);
592 return;
593 }
594 //
574 // Process inputs. 595 // Process inputs.
575 // 596 //
576 unit = AstCloner.clone(unit); 597 unit = AstCloner.clone(unit);
577 CompilationUnitBuilder builder = new CompilationUnitBuilder(); 598 CompilationUnitBuilder builder = new CompilationUnitBuilder();
578 CompilationUnitElement element = builder.buildCompilationUnit(source, unit); 599 CompilationUnitElement element = builder.buildCompilationUnit(source, unit);
579 // 600 //
580 // Record outputs. 601 // Record outputs.
581 // 602 //
582 outputs[CLASS_ELEMENTS] = element.types; 603 outputs[CLASS_ELEMENTS] = element.types;
583 outputs[COMPILATION_UNIT_ELEMENT] = element; 604 outputs[COMPILATION_UNIT_ELEMENT] = element;
584 outputs[RESOLVED_UNIT1] = unit; 605 outputs[RESOLVED_UNIT1] = unit;
606 outputMemento =
607 new BuildCompilationUnitElementMemento(element.types, unit, element);
585 } 608 }
586 609
587 /** 610 /**
588 * Return a map from the names of the inputs of this kind of task to the task 611 * Return a map from the names of the inputs of this kind of task to the task
589 * input descriptors describing those inputs for a task with the given 612 * input descriptors describing those inputs for a task with the given
590 * [target]. 613 * [target].
591 */ 614 */
592 static Map<String, TaskInput> buildInputs(LibrarySpecificUnit target) { 615 static Map<String, TaskInput> buildInputs(LibrarySpecificUnit target) {
593 return <String, TaskInput>{ 616 return <String, TaskInput>{
594 PARSED_UNIT_INPUT_NAME: PARSED_UNIT.of(target.unit) 617 PARSED_UNIT_INPUT_NAME: PARSED_UNIT.of(target.unit)
(...skipping 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1911 class ParseDartMemento { 1934 class ParseDartMemento {
1912 final Token inputTokenStream; 1935 final Token inputTokenStream;
1913 final List<Source> explicitlyImportedLibraries; 1936 final List<Source> explicitlyImportedLibraries;
1914 final List<Source> exportedLibraries; 1937 final List<Source> exportedLibraries;
1915 final List<Source> importedLibraries; 1938 final List<Source> importedLibraries;
1916 final List<Source> includedParts; 1939 final List<Source> includedParts;
1917 final List<AnalysisError> parseErrors; 1940 final List<AnalysisError> parseErrors;
1918 final CompilationUnit parsedUnit; 1941 final CompilationUnit parsedUnit;
1919 final SourceKind sourceKind; 1942 final SourceKind sourceKind;
1920 final List<Source> units; 1943 final List<Source> units;
1921 ParseDartMemento(this.inputTokenStream, this.explicitlyImportedLibraries, this .exportedLibraries, 1944 ParseDartMemento(this.inputTokenStream, this.explicitlyImportedLibraries,
1922 this.importedLibraries, this.includedParts, this.parseErrors, 1945 this.exportedLibraries, this.importedLibraries, this.includedParts,
1923 this.parsedUnit, this.sourceKind, this.units); 1946 this.parseErrors, this.parsedUnit, this.sourceKind, this.units);
1924 } 1947 }
1925 1948
1926 /** 1949 /**
1927 * A task that parses the content of a Dart file, producing an AST structure. 1950 * A task that parses the content of a Dart file, producing an AST structure.
1928 */ 1951 */
1929 class ParseDartTask extends SourceBasedAnalysisTask { 1952 class ParseDartTask extends SourceBasedAnalysisTask {
1930 /** 1953 /**
1931 * The name of the input whose value is the line information produced for the 1954 * The name of the input whose value is the line information produced for the
1932 * file. 1955 * file.
1933 */ 1956 */
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1966 @override 1989 @override
1967 void internalPerform() { 1990 void internalPerform() {
1968 Source source = getRequiredSource(); 1991 Source source = getRequiredSource();
1969 LineInfo lineInfo = getRequiredInput(LINE_INFO_INPUT_NAME); 1992 LineInfo lineInfo = getRequiredInput(LINE_INFO_INPUT_NAME);
1970 Token tokenStream = getRequiredInput(TOKEN_STREAM_INPUT_NAME); 1993 Token tokenStream = getRequiredInput(TOKEN_STREAM_INPUT_NAME);
1971 1994
1972 if (inputMemento is ParseDartMemento) { 1995 if (inputMemento is ParseDartMemento) {
1973 ParseDartMemento memento = inputMemento; 1996 ParseDartMemento memento = inputMemento;
1974 if (identical(memento.inputTokenStream, tokenStream)) { 1997 if (identical(memento.inputTokenStream, tokenStream)) {
1975 outputMemento = memento; 1998 outputMemento = memento;
1976 outputs[EXPLICITLY_IMPORTED_LIBRARIES] = memento.explicitlyImportedLibra ries; 1999 outputs[EXPLICITLY_IMPORTED_LIBRARIES] =
2000 memento.explicitlyImportedLibraries;
1977 outputs[EXPORTED_LIBRARIES] = memento.exportedLibraries; 2001 outputs[EXPORTED_LIBRARIES] = memento.exportedLibraries;
1978 outputs[IMPORTED_LIBRARIES] = memento.importedLibraries; 2002 outputs[IMPORTED_LIBRARIES] = memento.importedLibraries;
1979 outputs[INCLUDED_PARTS] = memento.includedParts; 2003 outputs[INCLUDED_PARTS] = memento.includedParts;
1980 outputs[PARSE_ERRORS] = memento.parseErrors; 2004 outputs[PARSE_ERRORS] = memento.parseErrors;
1981 outputs[PARSED_UNIT] = memento.parsedUnit; 2005 outputs[PARSED_UNIT] = memento.parsedUnit;
1982 outputs[SOURCE_KIND] = memento.sourceKind; 2006 outputs[SOURCE_KIND] = memento.sourceKind;
1983 outputs[UNITS] = memento.units; 2007 outputs[UNITS] = memento.units;
1984 return; 2008 return;
1985 } 2009 }
1986 } 2010 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2018 throw new AnalysisException( 2042 throw new AnalysisException(
2019 '$runtimeType failed to handle a ${directive.runtimeType}'); 2043 '$runtimeType failed to handle a ${directive.runtimeType}');
2020 } 2044 }
2021 } 2045 }
2022 } 2046 }
2023 } 2047 }
2024 } 2048 }
2025 // 2049 //
2026 // Always include "dart:core" source. 2050 // Always include "dart:core" source.
2027 // 2051 //
2028 HashSet<Source> importedSourceSet = new HashSet.from(explicitlyImportedSourc eSet); 2052 HashSet<Source> importedSourceSet =
2053 new HashSet.from(explicitlyImportedSourceSet);
2029 Source coreLibrarySource = context.sourceFactory.forUri(DartSdk.DART_CORE); 2054 Source coreLibrarySource = context.sourceFactory.forUri(DartSdk.DART_CORE);
2030 importedSourceSet.add(coreLibrarySource); 2055 importedSourceSet.add(coreLibrarySource);
2031 // 2056 //
2032 // Compute kind. 2057 // Compute kind.
2033 // 2058 //
2034 SourceKind sourceKind = SourceKind.LIBRARY; 2059 SourceKind sourceKind = SourceKind.LIBRARY;
2035 if (!hasNonPartOfDirective && hasPartOfDirective) { 2060 if (!hasNonPartOfDirective && hasPartOfDirective) {
2036 sourceKind = SourceKind.PART; 2061 sourceKind = SourceKind.PART;
2037 } 2062 }
2038 // 2063 //
2039 // Record outputs. 2064 // Record outputs.
2040 // 2065 //
2041 List<Source> explicitlyImportedSources = explicitlyImportedSourceSet.toList( ); 2066 List<Source> explicitlyImportedSources =
2067 explicitlyImportedSourceSet.toList();
2042 List<Source> exportedSources = exportedSourceSet.toList(); 2068 List<Source> exportedSources = exportedSourceSet.toList();
2043 List<Source> importedSources = importedSourceSet.toList(); 2069 List<Source> importedSources = importedSourceSet.toList();
2044 List<Source> includedSources = includedSourceSet.toList(); 2070 List<Source> includedSources = includedSourceSet.toList();
2045 List<AnalysisError> parseErrors = errorListener.errors; 2071 List<AnalysisError> parseErrors = errorListener.errors;
2046 List<Source> unitSources = <Source>[source]..addAll(includedSourceSet); 2072 List<Source> unitSources = <Source>[source]..addAll(includedSourceSet);
2047 outputs[EXPLICITLY_IMPORTED_LIBRARIES] = explicitlyImportedSources; 2073 outputs[EXPLICITLY_IMPORTED_LIBRARIES] = explicitlyImportedSources;
2048 outputs[EXPORTED_LIBRARIES] = exportedSources; 2074 outputs[EXPORTED_LIBRARIES] = exportedSources;
2049 outputs[IMPORTED_LIBRARIES] = importedSources; 2075 outputs[IMPORTED_LIBRARIES] = importedSources;
2050 outputs[INCLUDED_PARTS] = includedSources; 2076 outputs[INCLUDED_PARTS] = includedSources;
2051 outputs[PARSE_ERRORS] = parseErrors; 2077 outputs[PARSE_ERRORS] = parseErrors;
2052 outputs[PARSED_UNIT] = unit; 2078 outputs[PARSED_UNIT] = unit;
2053 outputs[SOURCE_KIND] = sourceKind; 2079 outputs[SOURCE_KIND] = sourceKind;
2054 outputs[UNITS] = unitSources; 2080 outputs[UNITS] = unitSources;
2055 outputMemento = new ParseDartMemento(tokenStream, explicitlyImportedSources, exportedSources, 2081 outputMemento = new ParseDartMemento(tokenStream, explicitlyImportedSources,
2056 importedSources, includedSources, parseErrors, unit, sourceKind, 2082 exportedSources, importedSources, includedSources, parseErrors, unit,
2057 unitSources); 2083 sourceKind, unitSources);
2058 } 2084 }
2059 2085
2060 /** 2086 /**
2061 * Return a map from the names of the inputs of this kind of task to the task 2087 * Return a map from the names of the inputs of this kind of task to the task
2062 * input descriptors describing those inputs for a task with the given 2088 * input descriptors describing those inputs for a task with the given
2063 * [source]. 2089 * [source].
2064 */ 2090 */
2065 static Map<String, TaskInput> buildInputs(Source source) { 2091 static Map<String, TaskInput> buildInputs(Source source) {
2066 return <String, TaskInput>{ 2092 return <String, TaskInput>{
2067 LINE_INFO_INPUT_NAME: LINE_INFO.of(source), 2093 LINE_INFO_INPUT_NAME: LINE_INFO.of(source),
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
2680 @override 2706 @override
2681 bool moveNext() { 2707 bool moveNext() {
2682 if (_newSources.isEmpty) { 2708 if (_newSources.isEmpty) {
2683 return false; 2709 return false;
2684 } 2710 }
2685 currentTarget = _newSources.first; 2711 currentTarget = _newSources.first;
2686 _newSources.remove(currentTarget); 2712 _newSources.remove(currentTarget);
2687 return true; 2713 return true;
2688 } 2714 }
2689 } 2715 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698