| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 'memory_source_file_helper.dart'; | 7 import 'memory_source_file_helper.dart'; |
| 8 | 8 |
| 9 import 'package:compiler/src/compile_time_constants.dart'; | 9 import 'package:compiler/src/compile_time_constants.dart'; |
| 10 | 10 |
| 11 import 'package:compiler/src/dart2jslib.dart' | 11 import 'package:compiler/src/dart2jslib.dart' |
| 12 show NullSink; | 12 show NullSink; |
| 13 | 13 |
| 14 import 'package:compiler/compiler.dart' | 14 import 'package:compiler/compiler.dart' show |
| 15 show Diagnostic, DiagnosticHandler, CompilerOutputProvider; | 15 CompilerOutputProvider, |
| 16 Diagnostic, |
| 17 DiagnosticHandler, |
| 18 PackagesDiscoveryProvider; |
| 16 | 19 |
| 17 import 'dart:async'; | 20 import 'dart:async'; |
| 18 | 21 |
| 19 import 'package:compiler/src/mirrors/source_mirrors.dart'; | 22 import 'package:compiler/src/mirrors/source_mirrors.dart'; |
| 20 import 'package:compiler/src/mirrors/analyze.dart'; | 23 import 'package:compiler/src/mirrors/analyze.dart'; |
| 21 | 24 |
| 22 import 'package:compiler/src/library_loader.dart' | 25 import 'package:compiler/src/library_loader.dart' |
| 23 show LoadedLibraries; | 26 show LoadedLibraries; |
| 24 | 27 |
| 25 export 'output_collector.dart'; | 28 export 'output_collector.dart'; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 85 } |
| 83 } else if (diagnosticHandler == null) { | 86 } else if (diagnosticHandler == null) { |
| 84 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {}; | 87 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {}; |
| 85 } | 88 } |
| 86 return handler; | 89 return handler; |
| 87 } | 90 } |
| 88 | 91 |
| 89 Expando<MemorySourceFileProvider> expando = | 92 Expando<MemorySourceFileProvider> expando = |
| 90 new Expando<MemorySourceFileProvider>(); | 93 new Expando<MemorySourceFileProvider>(); |
| 91 | 94 |
| 92 Compiler compilerFor(Map<String,String> memorySourceFiles, | 95 Compiler compilerFor( |
| 93 {DiagnosticHandler diagnosticHandler, | 96 Map<String, String> memorySourceFiles, |
| 94 CompilerOutputProvider outputProvider, | 97 {DiagnosticHandler diagnosticHandler, |
| 95 List<String> options: const [], | 98 CompilerOutputProvider outputProvider, |
| 96 Compiler cachedCompiler, | 99 List<String> options: const [], |
| 97 bool showDiagnostics: true, | 100 Compiler cachedCompiler, |
| 98 Uri packageRoot}) { | 101 bool showDiagnostics: true, |
| 102 Uri packageRoot, |
| 103 Uri packageConfig, |
| 104 PackagesDiscoveryProvider packagesDiscoveryProvider}) { |
| 99 Uri libraryRoot = Uri.base.resolve('sdk/'); | 105 Uri libraryRoot = Uri.base.resolve('sdk/'); |
| 100 if (packageRoot == null) { | 106 if (packageRoot == null && |
| 107 packageConfig == null && |
| 108 packagesDiscoveryProvider == null) { |
| 101 packageRoot = Uri.base.resolveUri(new Uri.file('${Platform.packageRoot}/')); | 109 packageRoot = Uri.base.resolveUri(new Uri.file('${Platform.packageRoot}/')); |
| 102 } | 110 } |
| 103 | 111 |
| 104 MemorySourceFileProvider provider; | 112 MemorySourceFileProvider provider; |
| 105 var readStringFromUri; | 113 var readStringFromUri; |
| 106 if (cachedCompiler == null) { | 114 if (cachedCompiler == null) { |
| 107 provider = new MemorySourceFileProvider(memorySourceFiles); | 115 provider = new MemorySourceFileProvider(memorySourceFiles); |
| 108 readStringFromUri = provider.readStringFromUri; | 116 readStringFromUri = provider.readStringFromUri; |
| 109 // Saving the provider in case we need it later for a cached compiler. | 117 // Saving the provider in case we need it later for a cached compiler. |
| 110 expando[readStringFromUri] = provider; | 118 expando[readStringFromUri] = provider; |
| 111 } else { | 119 } else { |
| 112 // When using a cached compiler, it has read a number of files from disk | 120 // When using a cached compiler, it has read a number of files from disk |
| 113 // already (and will not attempt to read them again due to caching). These | 121 // already (and will not attempt to read them again due to caching). These |
| 114 // files must be available to the new diagnostic handler. | 122 // files must be available to the new diagnostic handler. |
| 115 provider = expando[cachedCompiler.provider]; | 123 provider = expando[cachedCompiler.provider]; |
| 116 readStringFromUri = cachedCompiler.provider; | 124 readStringFromUri = cachedCompiler.provider; |
| 117 provider.memorySourceFiles = memorySourceFiles; | 125 provider.memorySourceFiles = memorySourceFiles; |
| 118 } | 126 } |
| 119 var handler = | 127 var handler = |
| 120 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics); | 128 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics); |
| 121 | 129 |
| 122 EventSink<String> noOutputProvider(String name, String extension) { | 130 EventSink<String> noOutputProvider(String name, String extension) { |
| 123 if (name != '') throw 'Attempt to output file "$name.$extension"'; | 131 if (name != '') throw 'Attempt to output file "$name.$extension"'; |
| 124 return new NullSink('$name.$extension'); | 132 return new NullSink('$name.$extension'); |
| 125 } | 133 } |
| 126 if (outputProvider == null) { | 134 if (outputProvider == null) { |
| 127 outputProvider = noOutputProvider; | 135 outputProvider = noOutputProvider; |
| 128 } | 136 } |
| 129 | 137 |
| 130 Compiler compiler = new Compiler(readStringFromUri, | 138 Compiler compiler = new Compiler( |
| 131 outputProvider, | 139 readStringFromUri, |
| 132 handler, | 140 outputProvider, |
| 133 libraryRoot, | 141 handler, |
| 134 packageRoot, | 142 libraryRoot, |
| 135 options, | 143 packageRoot, |
| 136 {}); | 144 options, |
| 145 {}, |
| 146 packageConfig, |
| 147 packagesDiscoveryProvider); |
| 148 |
| 137 if (cachedCompiler != null) { | 149 if (cachedCompiler != null) { |
| 138 compiler.coreLibrary = | 150 compiler.coreLibrary = |
| 139 cachedCompiler.libraryLoader.lookupLibrary(Uri.parse('dart:core')); | 151 cachedCompiler.libraryLoader.lookupLibrary(Uri.parse('dart:core')); |
| 140 compiler.types = cachedCompiler.types.copy(compiler); | 152 compiler.types = cachedCompiler.types.copy(compiler); |
| 141 Map copiedLibraries = {}; | 153 Map copiedLibraries = {}; |
| 142 cachedCompiler.libraryLoader.libraries.forEach((library) { | 154 cachedCompiler.libraryLoader.libraries.forEach((library) { |
| 143 if (library.isPlatformLibrary) { | 155 if (library.isPlatformLibrary) { |
| 144 var libraryLoader = compiler.libraryLoader; | 156 var libraryLoader = compiler.libraryLoader; |
| 145 libraryLoader.mapLibrary(library); | 157 libraryLoader.mapLibrary(library); |
| 146 compiler.onLibraryCreated(library); | 158 compiler.onLibraryCreated(library); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics); | 249 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics); |
| 238 | 250 |
| 239 List<Uri> libraries = <Uri>[]; | 251 List<Uri> libraries = <Uri>[]; |
| 240 memorySourceFiles.forEach((String path, _) { | 252 memorySourceFiles.forEach((String path, _) { |
| 241 libraries.add(new Uri(scheme: 'memory', path: path)); | 253 libraries.add(new Uri(scheme: 'memory', path: path)); |
| 242 }); | 254 }); |
| 243 | 255 |
| 244 return analyze(libraries, libraryRoot, packageRoot, | 256 return analyze(libraries, libraryRoot, packageRoot, |
| 245 provider, handler, options); | 257 provider, handler, options); |
| 246 } | 258 } |
| OLD | NEW |