| 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; | 10 import 'cache_strategy.dart' show CacheStrategy; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 LibraryElement typedDataLibrary; | 159 LibraryElement typedDataLibrary; |
| 160 | 160 |
| 161 DiagnosticReporter get reporter => _reporter; | 161 DiagnosticReporter get reporter => _reporter; |
| 162 CoreClasses get coreClasses => _coreTypes; | 162 CoreClasses get coreClasses => _coreTypes; |
| 163 CoreTypes get coreTypes => _coreTypes; | 163 CoreTypes get coreTypes => _coreTypes; |
| 164 Resolution get resolution => _resolution; | 164 Resolution get resolution => _resolution; |
| 165 ParsingContext get parsingContext => _parsingContext; | 165 ParsingContext get parsingContext => _parsingContext; |
| 166 | 166 |
| 167 ClassElement typedDataClass; | 167 ClassElement typedDataClass; |
| 168 | 168 |
| 169 /// The constant for the [proxy] variable defined in dart:core. | |
| 170 ConstantValue proxyConstant; | |
| 171 | |
| 172 // TODO(johnniwinther): Move this to the JavaScriptBackend. | 169 // TODO(johnniwinther): Move this to the JavaScriptBackend. |
| 173 /// The class for patch annotation defined in dart:_js_helper. | 170 /// The class for patch annotation defined in dart:_js_helper. |
| 174 ClassElement patchAnnotationClass; | 171 ClassElement patchAnnotationClass; |
| 175 | 172 |
| 176 // TODO(johnniwinther): Move this to the JavaScriptBackend. | 173 // TODO(johnniwinther): Move this to the JavaScriptBackend. |
| 177 ClassElement nativeAnnotationClass; | 174 ClassElement nativeAnnotationClass; |
| 178 | 175 |
| 179 ConstructorElement _symbolConstructor; | 176 ConstructorElement _symbolConstructor; |
| 180 ConstructorElement get symbolConstructor { | 177 ConstructorElement get symbolConstructor { |
| 181 if (_symbolConstructor == null) { | 178 if (_symbolConstructor == null) { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 /// | 363 /// |
| 367 /// Override this to mock the scanner for testing. | 364 /// Override this to mock the scanner for testing. |
| 368 ScannerTask createScannerTask() => | 365 ScannerTask createScannerTask() => |
| 369 new ScannerTask(dietParser, reporter, measurer, | 366 new ScannerTask(dietParser, reporter, measurer, |
| 370 preserveComments: options.preserveComments, commentMap: commentMap); | 367 preserveComments: options.preserveComments, commentMap: commentMap); |
| 371 | 368 |
| 372 /// Creates the resolver task. | 369 /// Creates the resolver task. |
| 373 /// | 370 /// |
| 374 /// Override this to mock the resolver for testing. | 371 /// Override this to mock the resolver for testing. |
| 375 ResolverTask createResolverTask() { | 372 ResolverTask createResolverTask() { |
| 376 return new ResolverTask(this, backend.constantCompilerTask); | 373 return new ResolverTask( |
| 374 resolution, backend.constantCompilerTask, world, measurer); |
| 377 } | 375 } |
| 378 | 376 |
| 379 Universe get resolverWorld => enqueuer.resolution.universe; | 377 Universe get resolverWorld => enqueuer.resolution.universe; |
| 380 Universe get codegenWorld => enqueuer.codegen.universe; | 378 Universe get codegenWorld => enqueuer.codegen.universe; |
| 381 | 379 |
| 382 bool get analyzeAll => options.analyzeAll || compileAll; | 380 bool get analyzeAll => options.analyzeAll || compileAll; |
| 383 | 381 |
| 384 bool get compileAll => false; | 382 bool get compileAll => false; |
| 385 | 383 |
| 386 bool get disableTypeInference => | 384 bool get disableTypeInference => |
| 387 options.disableTypeInference || compilationFailed; | 385 options.disableTypeInference || compilationFailed; |
| 388 | 386 |
| 387 // TODO(het): remove this from here. Either inline at all use sites or add it |
| 388 // to Reporter. |
| 389 void unimplemented(Spannable spannable, String methodName) { | 389 void unimplemented(Spannable spannable, String methodName) { |
| 390 reporter.internalError(spannable, "$methodName not implemented."); | 390 reporter.internalError(spannable, "$methodName not implemented."); |
| 391 } | 391 } |
| 392 | 392 |
| 393 // Compiles the dart script at [uri]. | 393 // Compiles the dart script at [uri]. |
| 394 // | 394 // |
| 395 // The resulting future will complete with true if the compilation | 395 // The resulting future will complete with true if the compilation |
| 396 // succeeded. | 396 // succeeded. |
| 397 Future<bool> run(Uri uri) => selfTask.measureSubtask("Compiler.run", () { | 397 Future<bool> run(Uri uri) => selfTask.measureSubtask("Compiler.run", () { |
| 398 measurer.startWallClock(); | 398 measurer.startWallClock(); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 if (options.preserveComments) { | 574 if (options.preserveComments) { |
| 575 return libraryLoader | 575 return libraryLoader |
| 576 .loadLibrary(Uris.dart_mirrors) | 576 .loadLibrary(Uris.dart_mirrors) |
| 577 .then((LibraryElement libraryElement) { | 577 .then((LibraryElement libraryElement) { |
| 578 documentClass = libraryElement.find('Comment'); | 578 documentClass = libraryElement.find('Comment'); |
| 579 }); | 579 }); |
| 580 } | 580 } |
| 581 }).then((_) => backend.onLibrariesLoaded(loadedLibraries)); | 581 }).then((_) => backend.onLibrariesLoaded(loadedLibraries)); |
| 582 } | 582 } |
| 583 | 583 |
| 584 bool isProxyConstant(ConstantValue value) { | |
| 585 FieldElement field = coreLibrary.find('proxy'); | |
| 586 if (field == null) return false; | |
| 587 if (!resolution.hasBeenResolved(field)) return false; | |
| 588 if (proxyConstant == null) { | |
| 589 proxyConstant = constants | |
| 590 .getConstantValue(resolver.constantCompiler.compileConstant(field)); | |
| 591 } | |
| 592 return proxyConstant == value; | |
| 593 } | |
| 594 | |
| 595 Element findRequiredElement(LibraryElement library, String name) { | 584 Element findRequiredElement(LibraryElement library, String name) { |
| 596 var element = library.find(name); | 585 var element = library.find(name); |
| 597 if (element == null) { | 586 if (element == null) { |
| 598 reporter.internalError( | 587 reporter.internalError( |
| 599 library, | 588 library, |
| 600 "The library '${library.canonicalUri}' does not contain required " | 589 "The library '${library.canonicalUri}' does not contain required " |
| 601 "element: '$name'."); | 590 "element: '$name'."); |
| 602 } | 591 } |
| 603 return element; | 592 return element; |
| 604 } | 593 } |
| (...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1899 @override | 1888 @override |
| 1900 CoreTypes get coreTypes => compiler.coreTypes; | 1889 CoreTypes get coreTypes => compiler.coreTypes; |
| 1901 | 1890 |
| 1902 @override | 1891 @override |
| 1903 Types get types => compiler.types; | 1892 Types get types => compiler.types; |
| 1904 | 1893 |
| 1905 @override | 1894 @override |
| 1906 Target get target => compiler.backend; | 1895 Target get target => compiler.backend; |
| 1907 | 1896 |
| 1908 @override | 1897 @override |
| 1898 ResolverTask get resolver => compiler.resolver; |
| 1899 |
| 1900 @override |
| 1901 ResolutionEnqueuer get enqueuer => compiler.enqueuer.resolution; |
| 1902 |
| 1903 @override |
| 1904 CompilerOptions get options => compiler.options; |
| 1905 |
| 1906 @override |
| 1907 IdGenerator get idGenerator => compiler.idGenerator; |
| 1908 |
| 1909 @override |
| 1910 ConstantEnvironment get constants => compiler.constants; |
| 1911 |
| 1912 @override |
| 1913 MirrorUsageAnalyzerTask get mirrorUsageAnalyzerTask => |
| 1914 compiler.mirrorUsageAnalyzerTask; |
| 1915 |
| 1916 @override |
| 1917 LibraryElement get coreLibrary => compiler.coreLibrary; |
| 1918 |
| 1919 @override |
| 1920 FunctionElement get identicalFunction => compiler.identicalFunction; |
| 1921 |
| 1922 @override |
| 1923 ClassElement get mirrorSystemClass => compiler.mirrorSystemClass; |
| 1924 |
| 1925 @override |
| 1926 FunctionElement get mirrorSystemGetNameFunction => |
| 1927 compiler.mirrorSystemGetNameFunction; |
| 1928 |
| 1929 @override |
| 1930 ConstructorElement get mirrorsUsedConstructor => |
| 1931 compiler.mirrorsUsedConstructor; |
| 1932 |
| 1933 @override |
| 1934 ConstructorElement get symbolConstructor => compiler.symbolConstructor; |
| 1935 |
| 1936 @override |
| 1937 ConstantValue proxyConstant; |
| 1938 |
| 1939 @override |
| 1909 void registerClass(ClassElement cls) { | 1940 void registerClass(ClassElement cls) { |
| 1910 compiler.world.registerClass(cls); | 1941 compiler.world.registerClass(cls); |
| 1911 } | 1942 } |
| 1912 | 1943 |
| 1913 @override | 1944 @override |
| 1914 void resolveClass(ClassElement cls) { | 1945 void resolveClass(ClassElement cls) { |
| 1915 compiler.resolver.resolveClass(cls); | 1946 compiler.resolver.resolveClass(cls); |
| 1916 } | 1947 } |
| 1917 | 1948 |
| 1918 @override | 1949 @override |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1937 | 1968 |
| 1938 @override | 1969 @override |
| 1939 void ensureResolved(Element element) { | 1970 void ensureResolved(Element element) { |
| 1940 if (compiler.serialization.isDeserialized(element)) { | 1971 if (compiler.serialization.isDeserialized(element)) { |
| 1941 return; | 1972 return; |
| 1942 } | 1973 } |
| 1943 computeWorldImpact(element); | 1974 computeWorldImpact(element); |
| 1944 } | 1975 } |
| 1945 | 1976 |
| 1946 @override | 1977 @override |
| 1978 void onClassResolved(ClassElement element) => |
| 1979 compiler.onClassResolved(element); |
| 1980 |
| 1981 @override |
| 1982 void registerCompiletimeError(Element element, DiagnosticMessage message) => |
| 1983 compiler.registerCompiletimeError(element, message); |
| 1984 |
| 1985 @override |
| 1947 bool hasResolvedAst(ExecutableElement element) { | 1986 bool hasResolvedAst(ExecutableElement element) { |
| 1948 assert(invariant(element, element.isDeclaration, | 1987 assert(invariant(element, element.isDeclaration, |
| 1949 message: "Element $element must be the declaration.")); | 1988 message: "Element $element must be the declaration.")); |
| 1950 if (compiler.serialization.isDeserialized(element)) { | 1989 if (compiler.serialization.isDeserialized(element)) { |
| 1951 return compiler.serialization.hasResolvedAst(element); | 1990 return compiler.serialization.hasResolvedAst(element); |
| 1952 } | 1991 } |
| 1953 return hasBeenResolved(element.memberContext.declaration) && | 1992 return hasBeenResolved(element.memberContext.declaration) && |
| 1954 element.hasResolvedAst; | 1993 element.hasResolvedAst; |
| 1955 } | 1994 } |
| 1956 | 1995 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2077 } else { | 2116 } else { |
| 2078 return new ResolutionWorkItem(element, compilationContext); | 2117 return new ResolutionWorkItem(element, compilationContext); |
| 2079 } | 2118 } |
| 2080 } | 2119 } |
| 2081 | 2120 |
| 2082 @override | 2121 @override |
| 2083 void forgetElement(Element element) { | 2122 void forgetElement(Element element) { |
| 2084 _worldImpactCache.remove(element); | 2123 _worldImpactCache.remove(element); |
| 2085 _resolutionImpactCache.remove(element); | 2124 _resolutionImpactCache.remove(element); |
| 2086 } | 2125 } |
| 2126 |
| 2127 @override |
| 2128 bool isProxyConstant(ConstantValue value) { |
| 2129 FieldElement field = coreLibrary.find('proxy'); |
| 2130 if (field == null) return false; |
| 2131 if (!hasBeenResolved(field)) return false; |
| 2132 if (proxyConstant == null) { |
| 2133 proxyConstant = constants |
| 2134 .getConstantValue(resolver.constantCompiler.compileConstant(field)); |
| 2135 } |
| 2136 return proxyConstant == value; |
| 2137 } |
| 2087 } | 2138 } |
| 2088 | 2139 |
| 2089 class GlobalDependencyRegistry extends EagerRegistry { | 2140 class GlobalDependencyRegistry extends EagerRegistry { |
| 2090 final Compiler compiler; | 2141 final Compiler compiler; |
| 2091 Setlet<Element> _otherDependencies; | 2142 Setlet<Element> _otherDependencies; |
| 2092 | 2143 |
| 2093 GlobalDependencyRegistry(this.compiler) : super('GlobalDependencies', null); | 2144 GlobalDependencyRegistry(this.compiler) : super('GlobalDependencies', null); |
| 2094 | 2145 |
| 2095 // TODO(johnniwinther): Rename world/universe/enqueuer through out the | 2146 // TODO(johnniwinther): Rename world/universe/enqueuer through out the |
| 2096 // compiler. | 2147 // compiler. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2123 _ElementScanner(this.scanner); | 2174 _ElementScanner(this.scanner); |
| 2124 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 2175 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
| 2125 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 2176 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
| 2126 } | 2177 } |
| 2127 | 2178 |
| 2128 class _EmptyEnvironment implements Environment { | 2179 class _EmptyEnvironment implements Environment { |
| 2129 const _EmptyEnvironment(); | 2180 const _EmptyEnvironment(); |
| 2130 | 2181 |
| 2131 String valueOf(String key) => null; | 2182 String valueOf(String key) => null; |
| 2132 } | 2183 } |
| OLD | NEW |