| 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 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 8 import 'memory_source_file_helper.dart'; | 8 import 'memory_source_file_helper.dart'; |
| 9 | 9 |
| 10 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' | 10 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 diagnosticHandler(uri, begin, end, message, kind); | 67 diagnosticHandler(uri, begin, end, message, kind); |
| 68 formattingHandler(uri, begin, end, message, kind); | 68 formattingHandler(uri, begin, end, message, kind); |
| 69 }; | 69 }; |
| 70 } | 70 } |
| 71 } else if (diagnosticHandler == null) { | 71 } else if (diagnosticHandler == null) { |
| 72 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {}; | 72 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {}; |
| 73 } | 73 } |
| 74 return handler; | 74 return handler; |
| 75 } | 75 } |
| 76 | 76 |
| 77 Expando<MemorySourceFileProvider> expando = |
| 78 new Expando<MemorySourceFileProvider>(); |
| 79 |
| 77 Compiler compilerFor(Map<String,String> memorySourceFiles, | 80 Compiler compilerFor(Map<String,String> memorySourceFiles, |
| 78 {DiagnosticHandler diagnosticHandler, | 81 {DiagnosticHandler diagnosticHandler, |
| 79 List<String> options: const [], | 82 List<String> options: const [], |
| 80 Compiler cachedCompiler, | 83 Compiler cachedCompiler, |
| 81 bool showDiagnostics: true}) { | 84 bool showDiagnostics: true}) { |
| 82 Uri script = currentDirectory.resolveUri(Platform.script); | 85 Uri script = currentDirectory.resolveUri(Platform.script); |
| 83 Uri libraryRoot = script.resolve('../../../sdk/'); | 86 Uri libraryRoot = script.resolve('../../../sdk/'); |
| 84 Uri packageRoot = script.resolve('./packages/'); | 87 Uri packageRoot = script.resolve('./packages/'); |
| 85 | 88 |
| 86 var provider = new MemorySourceFileProvider(memorySourceFiles); | 89 MemorySourceFileProvider provider; |
| 90 var readStringFromUri; |
| 91 if (cachedCompiler == null) { |
| 92 provider = new MemorySourceFileProvider(memorySourceFiles); |
| 93 readStringFromUri = provider.readStringFromUri; |
| 94 // Saving the provider in case we need it later for a cached compiler. |
| 95 expando[readStringFromUri] = provider; |
| 96 } else { |
| 97 // When using a cached compiler, it has read a number of files from disk |
| 98 // already (and will not attemp to read them again due to caching). These |
| 99 // files must be available to the new diagnostic handler. |
| 100 provider = expando[cachedCompiler.provider]; |
| 101 readStringFromUri = cachedCompiler.provider; |
| 102 provider.memorySourceFiles.clear(); |
| 103 memorySourceFiles.forEach((key, value) { |
| 104 provider.memorySourceFiles[key] = value; |
| 105 }); |
| 106 } |
| 87 var handler = | 107 var handler = |
| 88 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics); | 108 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics); |
| 89 | 109 |
| 90 EventSink<String> outputProvider(String name, String extension) { | 110 EventSink<String> outputProvider(String name, String extension) { |
| 91 if (name != '') throw 'Attempt to output file "$name.$extension"'; | 111 if (name != '') throw 'Attempt to output file "$name.$extension"'; |
| 92 return new NullSink('$name.$extension'); | 112 return new NullSink('$name.$extension'); |
| 93 } | 113 } |
| 94 | 114 |
| 95 Compiler compiler = new Compiler(provider.readStringFromUri, | 115 Compiler compiler = new Compiler(readStringFromUri, |
| 96 outputProvider, | 116 outputProvider, |
| 97 handler, | 117 handler, |
| 98 libraryRoot, | 118 libraryRoot, |
| 99 packageRoot, | 119 packageRoot, |
| 100 options, | 120 options, |
| 101 {}); | 121 {}); |
| 102 if (cachedCompiler != null) { | 122 if (cachedCompiler != null) { |
| 103 compiler.coreLibrary = cachedCompiler.libraries['dart:core']; | 123 compiler.coreLibrary = cachedCompiler.libraries['dart:core']; |
| 104 compiler.types = cachedCompiler.types; | 124 compiler.types = cachedCompiler.types; |
| 105 cachedCompiler.libraries.forEach((String uri, library) { | 125 cachedCompiler.libraries.forEach((String uri, library) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics); | 166 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics); |
| 147 | 167 |
| 148 List<Uri> libraries = <Uri>[]; | 168 List<Uri> libraries = <Uri>[]; |
| 149 memorySourceFiles.forEach((String path, _) { | 169 memorySourceFiles.forEach((String path, _) { |
| 150 libraries.add(new Uri(scheme: 'memory', path: path)); | 170 libraries.add(new Uri(scheme: 'memory', path: path)); |
| 151 }); | 171 }); |
| 152 | 172 |
| 153 return analyze(libraries, libraryRoot, packageRoot, | 173 return analyze(libraries, libraryRoot, packageRoot, |
| 154 provider, handler, options); | 174 provider, handler, options); |
| 155 } | 175 } |
| OLD | NEW |