OLD | NEW |
---|---|
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.test.memory_compiler; | 5 library dart2js.test.memory_compiler; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:compiler/compiler.dart' show DiagnosticHandler; | 9 import 'package:compiler/compiler.dart' show DiagnosticHandler; |
10 import 'package:compiler/compiler_new.dart' | 10 import 'package:compiler/compiler_new.dart' |
11 show | 11 show |
12 CompilationResult, | 12 CompilationResult, |
13 CompilerDiagnostics, | 13 CompilerDiagnostics, |
14 CompilerOutput, | 14 CompilerOutput, |
15 Diagnostic, | 15 Diagnostic, |
16 PackagesDiscoveryProvider; | 16 PackagesDiscoveryProvider; |
17 import 'package:compiler/src/diagnostics/messages.dart' show Message; | 17 import 'package:compiler/src/diagnostics/messages.dart' show Message; |
18 import 'package:compiler/src/elements/elements.dart' show LibraryElement; | |
18 import 'package:compiler/src/enqueue.dart' show ResolutionEnqueuer; | 19 import 'package:compiler/src/enqueue.dart' show ResolutionEnqueuer; |
19 import 'package:compiler/src/null_compiler_output.dart' show NullCompilerOutput; | 20 import 'package:compiler/src/null_compiler_output.dart' show NullCompilerOutput; |
20 import 'package:compiler/src/library_loader.dart' show LoadedLibraries; | 21 import 'package:compiler/src/library_loader.dart' show LoadedLibraries; |
21 import 'package:compiler/src/options.dart' show CompilerOptions; | 22 import 'package:compiler/src/options.dart' show CompilerOptions; |
22 | 23 |
23 import 'memory_source_file_helper.dart'; | 24 import 'memory_source_file_helper.dart'; |
24 | 25 |
25 export 'output_collector.dart'; | 26 export 'output_collector.dart'; |
26 export 'package:compiler/compiler_new.dart' show CompilationResult; | 27 export 'package:compiler/compiler_new.dart' show CompilationResult; |
27 export 'diagnostic_helper.dart'; | 28 export 'diagnostic_helper.dart'; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 packageConfig: packageConfig, | 160 packageConfig: packageConfig, |
160 packagesDiscoveryProvider: packagesDiscoveryProvider)); | 161 packagesDiscoveryProvider: packagesDiscoveryProvider)); |
161 | 162 |
162 if (cachedCompiler != null) { | 163 if (cachedCompiler != null) { |
163 compiler.types = cachedCompiler.types.copy(compiler.resolution); | 164 compiler.types = cachedCompiler.types.copy(compiler.resolution); |
164 Map copiedLibraries = {}; | 165 Map copiedLibraries = {}; |
165 cachedCompiler.libraryLoader.libraries.forEach((library) { | 166 cachedCompiler.libraryLoader.libraries.forEach((library) { |
166 if (library.isPlatformLibrary) { | 167 if (library.isPlatformLibrary) { |
167 var libraryLoader = compiler.libraryLoader; | 168 var libraryLoader = compiler.libraryLoader; |
168 libraryLoader.mapLibrary(library); | 169 libraryLoader.mapLibrary(library); |
169 compiler.onLibraryCreated(library); | |
170 compiler.onLibraryScanned(library, null); | |
171 if (library.isPatched) { | |
172 var patchLibrary = library.patch; | |
173 compiler.onLibraryCreated(patchLibrary); | |
174 compiler.onLibraryScanned(patchLibrary, null); | |
175 } | |
176 copiedLibraries[library.canonicalUri] = library; | 170 copiedLibraries[library.canonicalUri] = library; |
177 } | 171 } |
178 }); | 172 }); |
179 // TODO(johnniwinther): Assert that no libraries are loaded lazily from | 173 compiler.processLoadedLibraries(new MemoryLoadedLibraries(copiedLibraries)); |
180 // this call. | |
181 compiler.onLibrariesLoaded(new MemoryLoadedLibraries(copiedLibraries)); | |
182 ResolutionEnqueuer resolutionEnqueuer = compiler.startResolution(); | 174 ResolutionEnqueuer resolutionEnqueuer = compiler.startResolution(); |
183 | 175 |
184 compiler.backend.constantCompilerTask | 176 compiler.backend.constantCompilerTask |
185 .copyConstantValues(cachedCompiler.backend.constantCompilerTask); | 177 .copyConstantValues(cachedCompiler.backend.constantCompilerTask); |
186 | 178 |
187 Iterable cachedTreeElements = | 179 Iterable cachedTreeElements = |
188 cachedCompiler.enqueuer.resolution.processedEntities; | 180 cachedCompiler.enqueuer.resolution.processedEntities; |
189 cachedTreeElements.forEach((element) { | 181 cachedTreeElements.forEach((element) { |
190 if (element.library.isPlatformLibrary) { | 182 if (element.library.isPlatformLibrary) { |
191 resolutionEnqueuer.registerProcessedElementInternal(element); | 183 resolutionEnqueuer.registerProcessedElementInternal(element); |
(...skipping 17 matching lines...) Expand all Loading... | |
209 // more than once. | 201 // more than once. |
210 cachedCompiler.deferredLoadTask = null; | 202 cachedCompiler.deferredLoadTask = null; |
211 cachedCompiler.mirrorUsageAnalyzerTask = null; | 203 cachedCompiler.mirrorUsageAnalyzerTask = null; |
212 cachedCompiler.dumpInfoTask = null; | 204 cachedCompiler.dumpInfoTask = null; |
213 } | 205 } |
214 return compiler; | 206 return compiler; |
215 } | 207 } |
216 | 208 |
217 class MemoryLoadedLibraries implements LoadedLibraries { | 209 class MemoryLoadedLibraries implements LoadedLibraries { |
218 final Map copiedLibraries; | 210 final Map copiedLibraries; |
211 final loader = null; | |
Siggi Cherem (dart-lang)
2017/03/24 17:40:28
delete?
| |
219 | 212 |
220 MemoryLoadedLibraries(this.copiedLibraries); | 213 MemoryLoadedLibraries(this.copiedLibraries); |
221 | 214 |
222 @override | 215 @override |
223 bool containsLibrary(Uri uri) => copiedLibraries.containsKey(uri); | 216 bool containsLibrary(Uri uri) => copiedLibraries.containsKey(uri); |
224 | 217 |
225 @override | 218 @override |
226 void forEachImportChain(f, {callback}) {} | 219 void forEachImportChain(f, {callback}) { |
220 throw new UnimplementedError(); | |
221 } | |
227 | 222 |
228 @override | 223 @override |
229 void forEachLibrary(f) {} | 224 void forEachLibrary(f) => copiedLibraries.values.forEach(f); |
230 | 225 |
231 @override | 226 @override |
232 getLibrary(Uri uri) => copiedLibraries[uri]; | 227 getLibrary(Uri uri) => copiedLibraries[uri]; |
233 | 228 |
234 @override | 229 @override |
235 Uri get rootUri => null; | 230 LibraryElement get rootLibrary => copiedLibraries.values.first; |
236 } | 231 } |
237 | 232 |
238 DiagnosticHandler createDiagnosticHandler(DiagnosticHandler diagnosticHandler, | 233 DiagnosticHandler createDiagnosticHandler(DiagnosticHandler diagnosticHandler, |
239 SourceFileProvider provider, bool showDiagnostics) { | 234 SourceFileProvider provider, bool showDiagnostics) { |
240 var handler = diagnosticHandler; | 235 var handler = diagnosticHandler; |
241 if (showDiagnostics) { | 236 if (showDiagnostics) { |
242 if (diagnosticHandler == null) { | 237 if (diagnosticHandler == null) { |
243 handler = new FormattingDiagnosticHandler(provider); | 238 handler = new FormattingDiagnosticHandler(provider); |
244 } else { | 239 } else { |
245 var formattingHandler = new FormattingDiagnosticHandler(provider); | 240 var formattingHandler = new FormattingDiagnosticHandler(provider); |
246 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) { | 241 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) { |
247 diagnosticHandler(uri, begin, end, message, kind); | 242 diagnosticHandler(uri, begin, end, message, kind); |
248 formattingHandler(uri, begin, end, message, kind); | 243 formattingHandler(uri, begin, end, message, kind); |
249 }; | 244 }; |
250 } | 245 } |
251 } else if (diagnosticHandler == null) { | 246 } else if (diagnosticHandler == null) { |
252 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {}; | 247 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {}; |
253 } | 248 } |
254 return handler; | 249 return handler; |
255 } | 250 } |
OLD | NEW |