| 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 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:compiler/compiler.dart' show | 9 import 'package:compiler/compiler.dart' show |
| 10 DiagnosticHandler; | 10 DiagnosticHandler; |
| 11 import 'package:compiler/compiler_new.dart' show | 11 import 'package:compiler/compiler_new.dart' show |
| 12 CompilationResult, | 12 CompilationResult, |
| 13 CompilerDiagnostics, | 13 CompilerDiagnostics, |
| 14 CompilerOptions, |
| 14 CompilerOutput, | 15 CompilerOutput, |
| 15 Diagnostic, | 16 Diagnostic, |
| 16 PackagesDiscoveryProvider; | 17 PackagesDiscoveryProvider; |
| 17 import 'package:compiler/src/diagnostics/messages.dart' show | 18 import 'package:compiler/src/diagnostics/messages.dart' show |
| 18 Message; | 19 Message; |
| 19 import 'package:compiler/src/null_compiler_output.dart' show | 20 import 'package:compiler/src/null_compiler_output.dart' show |
| 20 NullCompilerOutput; | 21 NullCompilerOutput; |
| 21 import 'package:compiler/src/library_loader.dart' show | 22 import 'package:compiler/src/library_loader.dart' show |
| 22 LoadedLibraries; | 23 LoadedLibraries; |
| 23 | 24 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 CompilerImpl cachedCompiler, | 76 CompilerImpl cachedCompiler, |
| 76 bool showDiagnostics: true, | 77 bool showDiagnostics: true, |
| 77 Uri packageRoot, | 78 Uri packageRoot, |
| 78 Uri packageConfig, | 79 Uri packageConfig, |
| 79 PackagesDiscoveryProvider packagesDiscoveryProvider, | 80 PackagesDiscoveryProvider packagesDiscoveryProvider, |
| 80 void beforeRun(CompilerImpl compiler)}) async { | 81 void beforeRun(CompilerImpl compiler)}) async { |
| 81 if (entryPoint == null) { | 82 if (entryPoint == null) { |
| 82 entryPoint = Uri.parse('memory:main.dart'); | 83 entryPoint = Uri.parse('memory:main.dart'); |
| 83 } | 84 } |
| 84 CompilerImpl compiler = compilerFor( | 85 CompilerImpl compiler = compilerFor( |
| 86 entryPoint: entryPoint, |
| 85 memorySourceFiles: memorySourceFiles, | 87 memorySourceFiles: memorySourceFiles, |
| 86 diagnosticHandler: diagnosticHandler, | 88 diagnosticHandler: diagnosticHandler, |
| 87 outputProvider: outputProvider, | 89 outputProvider: outputProvider, |
| 88 options: options, | 90 options: options, |
| 89 cachedCompiler: cachedCompiler, | 91 cachedCompiler: cachedCompiler, |
| 90 showDiagnostics: showDiagnostics, | 92 showDiagnostics: showDiagnostics, |
| 91 packageRoot: packageRoot, | 93 packageRoot: packageRoot, |
| 92 packageConfig: packageConfig, | 94 packageConfig: packageConfig, |
| 93 packagesDiscoveryProvider: packagesDiscoveryProvider); | 95 packagesDiscoveryProvider: packagesDiscoveryProvider); |
| 94 compiler.librariesToAnalyzeWhenRun = entryPoints; | 96 compiler.librariesToAnalyzeWhenRun = entryPoints; |
| 95 if (beforeRun != null) { | 97 if (beforeRun != null) { |
| 96 beforeRun(compiler); | 98 beforeRun(compiler); |
| 97 } | 99 } |
| 98 bool isSuccess = await compiler.run(entryPoint); | 100 bool isSuccess = await compiler.run(entryPoint); |
| 99 return new CompilationResult(compiler, isSuccess: isSuccess); | 101 return new CompilationResult(compiler, isSuccess: isSuccess); |
| 100 } | 102 } |
| 101 | 103 |
| 102 CompilerImpl compilerFor( | 104 CompilerImpl compilerFor( |
| 103 {Map<String, String> memorySourceFiles: const <String, String>{}, | 105 {Uri entryPoint, |
| 106 Map<String, String> memorySourceFiles: const <String, String>{}, |
| 104 CompilerDiagnostics diagnosticHandler, | 107 CompilerDiagnostics diagnosticHandler, |
| 105 CompilerOutput outputProvider, | 108 CompilerOutput outputProvider, |
| 106 List<String> options: const <String>[], | 109 List<String> options: const <String>[], |
| 107 CompilerImpl cachedCompiler, | 110 CompilerImpl cachedCompiler, |
| 108 bool showDiagnostics: true, | 111 bool showDiagnostics: true, |
| 109 Uri packageRoot, | 112 Uri packageRoot, |
| 110 Uri packageConfig, | 113 Uri packageConfig, |
| 111 PackagesDiscoveryProvider packagesDiscoveryProvider}) { | 114 PackagesDiscoveryProvider packagesDiscoveryProvider}) { |
| 112 Uri libraryRoot = Uri.base.resolve('sdk/'); | 115 Uri libraryRoot = Uri.base.resolve('sdk/'); |
| 113 if (packageRoot == null && | 116 if (packageRoot == null && |
| (...skipping 20 matching lines...) Expand all Loading... |
| 134 verbose: options.contains('-v') || options.contains('--verbose')); | 137 verbose: options.contains('-v') || options.contains('--verbose')); |
| 135 | 138 |
| 136 if (outputProvider == null) { | 139 if (outputProvider == null) { |
| 137 outputProvider = const NullCompilerOutput(); | 140 outputProvider = const NullCompilerOutput(); |
| 138 } | 141 } |
| 139 | 142 |
| 140 CompilerImpl compiler = new CompilerImpl( | 143 CompilerImpl compiler = new CompilerImpl( |
| 141 provider, | 144 provider, |
| 142 outputProvider, | 145 outputProvider, |
| 143 diagnosticHandler, | 146 diagnosticHandler, |
| 144 libraryRoot, | 147 new CompilerOptions.parse( |
| 145 packageRoot, | 148 entryPoint: entryPoint, |
| 146 options, | 149 libraryRoot: libraryRoot, |
| 147 {}, | 150 packageRoot: packageRoot, |
| 148 packageConfig, | 151 options: options, |
| 149 packagesDiscoveryProvider); | 152 environment: {}, |
| 153 packageConfig: packageConfig, |
| 154 packagesDiscoveryProvider: packagesDiscoveryProvider)); |
| 150 | 155 |
| 151 if (cachedCompiler != null) { | 156 if (cachedCompiler != null) { |
| 152 compiler.coreLibrary = | 157 compiler.coreLibrary = |
| 153 cachedCompiler.libraryLoader.lookupLibrary(Uri.parse('dart:core')); | 158 cachedCompiler.libraryLoader.lookupLibrary(Uri.parse('dart:core')); |
| 154 compiler.types = cachedCompiler.types.copy(compiler.resolution); | 159 compiler.types = cachedCompiler.types.copy(compiler.resolution); |
| 155 Map copiedLibraries = {}; | 160 Map copiedLibraries = {}; |
| 156 cachedCompiler.libraryLoader.libraries.forEach((library) { | 161 cachedCompiler.libraryLoader.libraries.forEach((library) { |
| 157 if (library.isPlatformLibrary) { | 162 if (library.isPlatformLibrary) { |
| 158 var libraryLoader = compiler.libraryLoader; | 163 var libraryLoader = compiler.libraryLoader; |
| 159 libraryLoader.mapLibrary(library); | 164 libraryLoader.mapLibrary(library); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 cachedCompiler.resolver = null; | 209 cachedCompiler.resolver = null; |
| 205 cachedCompiler.closureToClassMapper = null; | 210 cachedCompiler.closureToClassMapper = null; |
| 206 cachedCompiler.checker = null; | 211 cachedCompiler.checker = null; |
| 207 cachedCompiler.typesTask = null; | 212 cachedCompiler.typesTask = null; |
| 208 cachedCompiler.backend = null; | 213 cachedCompiler.backend = null; |
| 209 // Don't null out the enqueuer as it prevents us from using cachedCompiler | 214 // Don't null out the enqueuer as it prevents us from using cachedCompiler |
| 210 // more than once. | 215 // more than once. |
| 211 cachedCompiler.deferredLoadTask = null; | 216 cachedCompiler.deferredLoadTask = null; |
| 212 cachedCompiler.mirrorUsageAnalyzerTask = null; | 217 cachedCompiler.mirrorUsageAnalyzerTask = null; |
| 213 cachedCompiler.dumpInfoTask = null; | 218 cachedCompiler.dumpInfoTask = null; |
| 214 cachedCompiler.buildId = null; | |
| 215 } | 219 } |
| 216 return compiler; | 220 return compiler; |
| 217 } | 221 } |
| 218 | 222 |
| 219 class MemoryLoadedLibraries implements LoadedLibraries { | 223 class MemoryLoadedLibraries implements LoadedLibraries { |
| 220 final Map copiedLibraries; | 224 final Map copiedLibraries; |
| 221 | 225 |
| 222 MemoryLoadedLibraries(this.copiedLibraries); | 226 MemoryLoadedLibraries(this.copiedLibraries); |
| 223 | 227 |
| 224 @override | 228 @override |
| (...skipping 25 matching lines...) Expand all Loading... |
| 250 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) { | 254 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) { |
| 251 diagnosticHandler(uri, begin, end, message, kind); | 255 diagnosticHandler(uri, begin, end, message, kind); |
| 252 formattingHandler(uri, begin, end, message, kind); | 256 formattingHandler(uri, begin, end, message, kind); |
| 253 }; | 257 }; |
| 254 } | 258 } |
| 255 } else if (diagnosticHandler == null) { | 259 } else if (diagnosticHandler == null) { |
| 256 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {}; | 260 handler = (Uri uri, int begin, int end, String message, Diagnostic kind) {}; |
| 257 } | 261 } |
| 258 return handler; | 262 return handler; |
| 259 } | 263 } |
| OLD | NEW |