| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 dart2js.compiler_base; | 5 library dart2js.compiler_base; |
| 6 | 6 |
| 7 import 'dart:async' show EventSink, Future; | 7 import 'dart:async' show EventSink, Future; |
| 8 | 8 |
| 9 import '../compiler_new.dart' as api; | 9 import '../compiler_new.dart' as api; |
| 10 import 'cache_strategy.dart' show CacheStrategy; | |
| 11 import 'closure.dart' as closureMapping show ClosureTask; | 10 import 'closure.dart' as closureMapping show ClosureTask; |
| 12 import 'common/backend_api.dart' show Backend; | 11 import 'common/backend_api.dart' show Backend; |
| 13 import 'common/names.dart' show Selectors; | 12 import 'common/names.dart' show Selectors; |
| 14 import 'common/names.dart' show Identifiers, Uris; | 13 import 'common/names.dart' show Identifiers, Uris; |
| 15 import 'common/resolution.dart' | 14 import 'common/resolution.dart' |
| 16 show | 15 show |
| 17 ParsingContext, | 16 ParsingContext, |
| 18 Resolution, | 17 Resolution, |
| 19 ResolutionWorkItem, | 18 ResolutionWorkItem, |
| 20 ResolutionImpact, | 19 ResolutionImpact, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 abstract class Compiler implements LibraryLoaderListener { | 92 abstract class Compiler implements LibraryLoaderListener { |
| 94 Measurer get measurer; | 93 Measurer get measurer; |
| 95 | 94 |
| 96 final IdGenerator idGenerator = new IdGenerator(); | 95 final IdGenerator idGenerator = new IdGenerator(); |
| 97 Types types; | 96 Types types; |
| 98 _CompilerCommonElements _commonElements; | 97 _CompilerCommonElements _commonElements; |
| 99 CompilerDiagnosticReporter _reporter; | 98 CompilerDiagnosticReporter _reporter; |
| 100 CompilerResolution _resolution; | 99 CompilerResolution _resolution; |
| 101 ParsingContext _parsingContext; | 100 ParsingContext _parsingContext; |
| 102 | 101 |
| 103 final CacheStrategy cacheStrategy; | |
| 104 | |
| 105 ImpactStrategy impactStrategy = const ImpactStrategy(); | 102 ImpactStrategy impactStrategy = const ImpactStrategy(); |
| 106 | 103 |
| 107 /** | 104 /** |
| 108 * Map from token to the first preceding comment token. | 105 * Map from token to the first preceding comment token. |
| 109 */ | 106 */ |
| 110 final TokenMap commentMap = new TokenMap(); | 107 final TokenMap commentMap = new TokenMap(); |
| 111 | 108 |
| 112 /** | 109 /** |
| 113 * Records global dependencies, that is, dependencies that don't | 110 * Records global dependencies, that is, dependencies that don't |
| 114 * correspond to a particular element. | 111 * correspond to a particular element. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 193 |
| 197 bool compilationFailed = false; | 194 bool compilationFailed = false; |
| 198 | 195 |
| 199 Compiler( | 196 Compiler( |
| 200 {CompilerOptions options, | 197 {CompilerOptions options, |
| 201 api.CompilerOutput outputProvider, | 198 api.CompilerOutput outputProvider, |
| 202 this.environment: const _EmptyEnvironment(), | 199 this.environment: const _EmptyEnvironment(), |
| 203 MakeBackendFunction makeBackend, | 200 MakeBackendFunction makeBackend, |
| 204 MakeReporterFunction makeReporter}) | 201 MakeReporterFunction makeReporter}) |
| 205 : this.options = options, | 202 : this.options = options, |
| 206 this.cacheStrategy = new CacheStrategy(options.hasIncrementalSupport), | |
| 207 this.userOutputProvider = outputProvider == null | 203 this.userOutputProvider = outputProvider == null |
| 208 ? const NullCompilerOutput() | 204 ? const NullCompilerOutput() |
| 209 : outputProvider { | 205 : outputProvider { |
| 210 if (makeReporter != null) { | 206 if (makeReporter != null) { |
| 211 _reporter = makeReporter(this, options); | 207 _reporter = makeReporter(this, options); |
| 212 } else { | 208 } else { |
| 213 _reporter = new CompilerDiagnosticReporter(this, options); | 209 _reporter = new CompilerDiagnosticReporter(this, options); |
| 214 } | 210 } |
| 215 _resolution = createResolution(); | 211 _resolution = createResolution(); |
| 216 _commonElements = new _CompilerCommonElements(_resolution, reporter); | 212 _commonElements = new _CompilerCommonElements(_resolution, reporter); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 StringToken.canonicalizedSubstrings.clear(); | 478 StringToken.canonicalizedSubstrings.clear(); |
| 483 Selector.canonicalizedValues.clear(); | 479 Selector.canonicalizedValues.clear(); |
| 484 | 480 |
| 485 // The selector objects held in static fields must remain canonical. | 481 // The selector objects held in static fields must remain canonical. |
| 486 for (Selector selector in Selectors.ALL) { | 482 for (Selector selector in Selectors.ALL) { |
| 487 Selector.canonicalizedValues | 483 Selector.canonicalizedValues |
| 488 .putIfAbsent(selector.hashCode, () => <Selector>[]) | 484 .putIfAbsent(selector.hashCode, () => <Selector>[]) |
| 489 .add(selector); | 485 .add(selector); |
| 490 } | 486 } |
| 491 | 487 |
| 492 assert(uri != null || options.analyzeOnly || options.hasIncrementalSupport); | 488 assert(uri != null || options.analyzeOnly); |
| 493 return new Future.sync(() { | 489 return new Future.sync(() { |
| 494 if (librariesToAnalyzeWhenRun != null) { | 490 if (librariesToAnalyzeWhenRun != null) { |
| 495 return Future.forEach(librariesToAnalyzeWhenRun, (libraryUri) { | 491 return Future.forEach(librariesToAnalyzeWhenRun, (libraryUri) { |
| 496 reporter.log('Analyzing $libraryUri (${options.buildId})'); | 492 reporter.log('Analyzing $libraryUri (${options.buildId})'); |
| 497 return libraryLoader.loadLibrary(libraryUri); | 493 return libraryLoader.loadLibrary(libraryUri); |
| 498 }); | 494 }); |
| 499 } | 495 } |
| 500 }).then((_) { | 496 }).then((_) { |
| 501 if (uri != null) { | 497 if (uri != null) { |
| 502 if (options.analyzeOnly) { | 498 if (options.analyzeOnly) { |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 if (libraryUri.scheme == 'package') { | 1061 if (libraryUri.scheme == 'package') { |
| 1066 int slashPos = libraryUri.path.indexOf('/'); | 1062 int slashPos = libraryUri.path.indexOf('/'); |
| 1067 if (slashPos != -1) { | 1063 if (slashPos != -1) { |
| 1068 String packageName = libraryUri.path.substring(0, slashPos); | 1064 String packageName = libraryUri.path.substring(0, slashPos); |
| 1069 return new Uri(scheme: 'package', path: packageName); | 1065 return new Uri(scheme: 'package', path: packageName); |
| 1070 } | 1066 } |
| 1071 } | 1067 } |
| 1072 return libraryUri; | 1068 return libraryUri; |
| 1073 } | 1069 } |
| 1074 | 1070 |
| 1075 void forgetElement(Element element) { | |
| 1076 resolution.forgetElement(element); | |
| 1077 enqueuer.forgetEntity(element); | |
| 1078 if (element is MemberElement) { | |
| 1079 for (Element closure in element.nestedClosures) { | |
| 1080 // TODO(ahe): It would be nice to reuse names of nested closures. | |
| 1081 closureToClassMapper.forgetElement(closure); | |
| 1082 } | |
| 1083 } | |
| 1084 backend.forgetElement(element); | |
| 1085 } | |
| 1086 | |
| 1087 /// Returns [true] if a compile-time error has been reported for element. | 1071 /// Returns [true] if a compile-time error has been reported for element. |
| 1088 bool elementHasCompileTimeError(Element element) { | 1072 bool elementHasCompileTimeError(Element element) { |
| 1089 return elementsWithCompileTimeErrors.containsKey(element); | 1073 return elementsWithCompileTimeErrors.containsKey(element); |
| 1090 } | 1074 } |
| 1091 | 1075 |
| 1092 /// Associate [element] with a compile-time error [message]. | 1076 /// Associate [element] with a compile-time error [message]. |
| 1093 void registerCompileTimeError(Element element, DiagnosticMessage message) { | 1077 void registerCompileTimeError(Element element, DiagnosticMessage message) { |
| 1094 // The information is only needed if [generateCodeWithCompileTimeErrors]. | 1078 // The information is only needed if [generateCodeWithCompileTimeErrors]. |
| 1095 if (options.generateCodeWithCompileTimeErrors) { | 1079 if (options.generateCodeWithCompileTimeErrors) { |
| 1096 if (element == null) { | 1080 if (element == null) { |
| (...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1916 | 1900 |
| 1917 @override | 1901 @override |
| 1918 ResolutionWorkItem createWorkItem(Element element) { | 1902 ResolutionWorkItem createWorkItem(Element element) { |
| 1919 if (_compiler.serialization.isDeserialized(element)) { | 1903 if (_compiler.serialization.isDeserialized(element)) { |
| 1920 return _compiler.serialization.createResolutionWorkItem(element); | 1904 return _compiler.serialization.createResolutionWorkItem(element); |
| 1921 } else { | 1905 } else { |
| 1922 return new ResolutionWorkItem(this, element); | 1906 return new ResolutionWorkItem(this, element); |
| 1923 } | 1907 } |
| 1924 } | 1908 } |
| 1925 | 1909 |
| 1926 @override | |
| 1927 void forgetElement(Element element) { | |
| 1928 _worldImpactCache.remove(element); | |
| 1929 _resolutionImpactCache.remove(element); | |
| 1930 } | |
| 1931 | |
| 1932 ConstantValue _proxyConstant; | 1910 ConstantValue _proxyConstant; |
| 1933 | 1911 |
| 1934 @override | 1912 @override |
| 1935 bool isProxyConstant(ConstantValue value) { | 1913 bool isProxyConstant(ConstantValue value) { |
| 1936 FieldElement field = coreLibrary.find('proxy'); | 1914 FieldElement field = coreLibrary.find('proxy'); |
| 1937 if (field == null) return false; | 1915 if (field == null) return false; |
| 1938 if (!hasBeenResolved(field)) return false; | 1916 if (!hasBeenResolved(field)) return false; |
| 1939 if (_proxyConstant == null) { | 1917 if (_proxyConstant == null) { |
| 1940 _proxyConstant = constants | 1918 _proxyConstant = constants |
| 1941 .getConstantValue(resolver.constantCompiler.compileConstant(field)); | 1919 .getConstantValue(resolver.constantCompiler.compileConstant(field)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1989 _ElementScanner(this.scanner); | 1967 _ElementScanner(this.scanner); |
| 1990 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 1968 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
| 1991 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 1969 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
| 1992 } | 1970 } |
| 1993 | 1971 |
| 1994 class _EmptyEnvironment implements Environment { | 1972 class _EmptyEnvironment implements Environment { |
| 1995 const _EmptyEnvironment(); | 1973 const _EmptyEnvironment(); |
| 1996 | 1974 |
| 1997 String valueOf(String key) => null; | 1975 String valueOf(String key) => null; |
| 1998 } | 1976 } |
| OLD | NEW |