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