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

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

Issue 1124703005: Use memento in ParseDartTask. (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';
(...skipping 1888 matching lines...) Expand 10 before | Expand all | Expand 10 after
1899 * Create a [GenerateHintsTask] based on the given [target] in 1899 * Create a [GenerateHintsTask] based on the given [target] in
1900 * the given [context]. 1900 * the given [context].
1901 */ 1901 */
1902 static GenerateHintsTask createTask( 1902 static GenerateHintsTask createTask(
1903 AnalysisContext context, AnalysisTarget target) { 1903 AnalysisContext context, AnalysisTarget target) {
1904 return new GenerateHintsTask(context, target); 1904 return new GenerateHintsTask(context, target);
1905 } 1905 }
1906 } 1906 }
1907 1907
1908 /** 1908 /**
1909 * The memento for [ParseDartTask].
1910 */
1911 class ParseDartMemento {
1912 final Token inputTokenStream;
1913 final List<Source> exportedLibraries;
1914 final List<Source> importedLibraries;
1915 final List<Source> includedParts;
1916 final List<AnalysisError> parseErrors;
1917 final CompilationUnit parsedUnit;
1918 final SourceKind sourceKind;
1919 final List<Source> units;
1920 ParseDartMemento(this.inputTokenStream, this.exportedLibraries,
1921 this.importedLibraries, this.includedParts, this.parseErrors,
1922 this.parsedUnit, this.sourceKind, this.units);
1923 }
1924
1925 /**
1909 * A task that parses the content of a Dart file, producing an AST structure. 1926 * A task that parses the content of a Dart file, producing an AST structure.
1910 */ 1927 */
1911 class ParseDartTask extends SourceBasedAnalysisTask { 1928 class ParseDartTask extends SourceBasedAnalysisTask {
1912 /** 1929 /**
1913 * The name of the input whose value is the line information produced for the 1930 * The name of the input whose value is the line information produced for the
1914 * file. 1931 * file.
1915 */ 1932 */
1916 static const String LINE_INFO_INPUT_NAME = 'LINE_INFO_INPUT_NAME'; 1933 static const String LINE_INFO_INPUT_NAME = 'LINE_INFO_INPUT_NAME';
1917 1934
1918 /** 1935 /**
(...skipping 24 matching lines...) Expand all
1943 1960
1944 @override 1961 @override
1945 TaskDescriptor get descriptor => DESCRIPTOR; 1962 TaskDescriptor get descriptor => DESCRIPTOR;
1946 1963
1947 @override 1964 @override
1948 void internalPerform() { 1965 void internalPerform() {
1949 Source source = getRequiredSource(); 1966 Source source = getRequiredSource();
1950 LineInfo lineInfo = getRequiredInput(LINE_INFO_INPUT_NAME); 1967 LineInfo lineInfo = getRequiredInput(LINE_INFO_INPUT_NAME);
1951 Token tokenStream = getRequiredInput(TOKEN_STREAM_INPUT_NAME); 1968 Token tokenStream = getRequiredInput(TOKEN_STREAM_INPUT_NAME);
1952 1969
1970 if (inputMemento is ParseDartMemento) {
1971 ParseDartMemento memento = inputMemento;
1972 if (identical(memento.inputTokenStream, tokenStream)) {
1973 outputMemento = memento;
1974 outputs[EXPORTED_LIBRARIES] = memento.exportedLibraries;
1975 outputs[IMPORTED_LIBRARIES] = memento.importedLibraries;
1976 outputs[INCLUDED_PARTS] = memento.includedParts;
1977 outputs[PARSE_ERRORS] = memento.parseErrors;
1978 outputs[PARSED_UNIT] = memento.parsedUnit;
1979 outputs[SOURCE_KIND] = memento.sourceKind;
1980 outputs[UNITS] = memento.units;
1981 return;
1982 }
1983 }
1984
1953 RecordingErrorListener errorListener = new RecordingErrorListener(); 1985 RecordingErrorListener errorListener = new RecordingErrorListener();
1954 Parser parser = new Parser(source, errorListener); 1986 Parser parser = new Parser(source, errorListener);
1955 AnalysisOptions options = context.analysisOptions; 1987 AnalysisOptions options = context.analysisOptions;
1956 parser.parseFunctionBodies = options.analyzeFunctionBodiesPredicate(source); 1988 parser.parseFunctionBodies = options.analyzeFunctionBodiesPredicate(source);
1957 CompilationUnit unit = parser.parseCompilationUnit(tokenStream); 1989 CompilationUnit unit = parser.parseCompilationUnit(tokenStream);
1958 unit.lineInfo = lineInfo; 1990 unit.lineInfo = lineInfo;
1959 1991
1960 bool hasNonPartOfDirective = false; 1992 bool hasNonPartOfDirective = false;
1961 bool hasPartOfDirective = false; 1993 bool hasPartOfDirective = false;
1962 HashSet<Source> exportedSources = new HashSet<Source>(); 1994 HashSet<Source> exportedSourceSet = new HashSet<Source>();
1963 HashSet<Source> importedSources = new HashSet<Source>(); 1995 HashSet<Source> importedSourceSet = new HashSet<Source>();
1964 HashSet<Source> includedSources = new HashSet<Source>(); 1996 HashSet<Source> includedSourceSet = new HashSet<Source>();
1965 for (Directive directive in unit.directives) { 1997 for (Directive directive in unit.directives) {
1966 if (directive is PartOfDirective) { 1998 if (directive is PartOfDirective) {
1967 hasPartOfDirective = true; 1999 hasPartOfDirective = true;
1968 } else { 2000 } else {
1969 hasNonPartOfDirective = true; 2001 hasNonPartOfDirective = true;
1970 if (directive is UriBasedDirective) { 2002 if (directive is UriBasedDirective) {
1971 Source referencedSource = 2003 Source referencedSource =
1972 resolveDirective(context, source, directive, errorListener); 2004 resolveDirective(context, source, directive, errorListener);
1973 if (referencedSource != null) { 2005 if (referencedSource != null) {
1974 if (directive is ExportDirective) { 2006 if (directive is ExportDirective) {
1975 exportedSources.add(referencedSource); 2007 exportedSourceSet.add(referencedSource);
1976 } else if (directive is ImportDirective) { 2008 } else if (directive is ImportDirective) {
1977 importedSources.add(referencedSource); 2009 importedSourceSet.add(referencedSource);
1978 } else if (directive is PartDirective) { 2010 } else if (directive is PartDirective) {
1979 if (referencedSource != source) { 2011 if (referencedSource != source) {
1980 includedSources.add(referencedSource); 2012 includedSourceSet.add(referencedSource);
1981 } 2013 }
1982 } else { 2014 } else {
1983 throw new AnalysisException( 2015 throw new AnalysisException(
1984 '$runtimeType failed to handle a ${directive.runtimeType}'); 2016 '$runtimeType failed to handle a ${directive.runtimeType}');
1985 } 2017 }
1986 } 2018 }
1987 } 2019 }
1988 } 2020 }
1989 } 2021 }
1990 // 2022 //
1991 // Always include "dart:core" source. 2023 // Always include "dart:core" source.
1992 // 2024 //
1993 Source coreLibrarySource = context.sourceFactory.forUri(DartSdk.DART_CORE); 2025 Source coreLibrarySource = context.sourceFactory.forUri(DartSdk.DART_CORE);
1994 importedSources.add(coreLibrarySource); 2026 importedSourceSet.add(coreLibrarySource);
1995 // 2027 //
1996 // Compute kind. 2028 // Compute kind.
1997 // 2029 //
1998 SourceKind sourceKind = SourceKind.LIBRARY; 2030 SourceKind sourceKind = SourceKind.LIBRARY;
1999 if (!hasNonPartOfDirective && hasPartOfDirective) { 2031 if (!hasNonPartOfDirective && hasPartOfDirective) {
2000 sourceKind = SourceKind.PART; 2032 sourceKind = SourceKind.PART;
2001 } 2033 }
2002 // 2034 //
2003 // Record outputs. 2035 // Record outputs.
2004 // 2036 //
2005 outputs[EXPORTED_LIBRARIES] = exportedSources.toList(); 2037 List<Source> exportedSources = exportedSourceSet.toList();
2006 outputs[IMPORTED_LIBRARIES] = importedSources.toList(); 2038 List<Source> importedSources = importedSourceSet.toList();
2007 outputs[INCLUDED_PARTS] = includedSources.toList(); 2039 List<Source> includedSources = includedSourceSet.toList();
2008 outputs[PARSE_ERRORS] = errorListener.getErrorsForSource(source); 2040 List<AnalysisError> parseErrors = errorListener.errors;
2041 List<Source> unitSources = <Source>[source]..addAll(includedSourceSet);
2042 outputs[EXPORTED_LIBRARIES] = exportedSources;
2043 outputs[IMPORTED_LIBRARIES] = importedSources;
2044 outputs[INCLUDED_PARTS] = includedSources;
2045 outputs[PARSE_ERRORS] = parseErrors;
2009 outputs[PARSED_UNIT] = unit; 2046 outputs[PARSED_UNIT] = unit;
2010 outputs[SOURCE_KIND] = sourceKind; 2047 outputs[SOURCE_KIND] = sourceKind;
2011 outputs[UNITS] = <Source>[source]..addAll(includedSources); 2048 outputs[UNITS] = unitSources;
2049 outputMemento = new ParseDartMemento(tokenStream, exportedSources,
2050 importedSources, includedSources, parseErrors, unit, sourceKind,
2051 unitSources);
2012 } 2052 }
2013 2053
2014 /** 2054 /**
2015 * Return a map from the names of the inputs of this kind of task to the task 2055 * Return a map from the names of the inputs of this kind of task to the task
2016 * input descriptors describing those inputs for a task with the given 2056 * input descriptors describing those inputs for a task with the given
2017 * [source]. 2057 * [source].
2018 */ 2058 */
2019 static Map<String, TaskInput> buildInputs(Source source) { 2059 static Map<String, TaskInput> buildInputs(Source source) {
2020 return <String, TaskInput>{ 2060 return <String, TaskInput>{
2021 LINE_INFO_INPUT_NAME: LINE_INFO.of(source), 2061 LINE_INFO_INPUT_NAME: LINE_INFO.of(source),
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
2634 @override 2674 @override
2635 bool moveNext() { 2675 bool moveNext() {
2636 if (_newSources.isEmpty) { 2676 if (_newSources.isEmpty) {
2637 return false; 2677 return false;
2638 } 2678 }
2639 currentTarget = _newSources.first; 2679 currentTarget = _newSources.first;
2640 _newSources.remove(currentTarget); 2680 _newSources.remove(currentTarget);
2641 return true; 2681 return true;
2642 } 2682 }
2643 } 2683 }
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