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 fasta; | 5 library fasta; |
6 | 6 |
7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
8 | 8 |
9 import 'dart:convert' show JSON; | 9 import 'dart:convert' show JSON; |
10 | 10 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 Uri uri = c.options.output; | 157 Uri uri = c.options.output; |
158 await kernelTarget.writeProgram(uri, | 158 await kernelTarget.writeProgram(uri, |
159 dumpIr: c.options.dumpIr, verify: c.options.verify); | 159 dumpIr: c.options.dumpIr, verify: c.options.verify); |
160 return uri; | 160 return uri; |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 Future<CompilationResult> parseScript( | 164 Future<CompilationResult> parseScript( |
165 Uri fileName, Uri packages, Uri patchedSdk, | 165 Uri fileName, Uri packages, Uri patchedSdk, |
166 {bool verbose: false, bool strongMode: false}) async { | 166 {bool verbose: false, bool strongMode: false}) async { |
| 167 return parseScriptInFileSystem( |
| 168 fileName, PhysicalFileSystem.instance, packages, patchedSdk, |
| 169 verbose: verbose, strongMode: strongMode); |
| 170 } |
| 171 |
| 172 Future<CompilationResult> parseScriptInFileSystem( |
| 173 Uri fileName, FileSystem fileSystem, Uri packages, Uri patchedSdk, |
| 174 {bool verbose: false, bool strongMode: false}) async { |
167 try { | 175 try { |
168 if (!await new File.fromUri(fileName).exists()) { | 176 if (!await fileSystem.entityForUri(fileName).exists()) { |
169 return new CompilationResult.error( | 177 return new CompilationResult.error( |
170 formatUnexpected(fileName, -1, "No such file.")); | 178 formatUnexpected(fileName, -1, "No such file.")); |
171 } | 179 } |
172 if (!await new Directory.fromUri(patchedSdk).exists()) { | 180 if (!await new Directory.fromUri(patchedSdk).exists()) { |
173 return new CompilationResult.error( | 181 return new CompilationResult.error( |
174 formatUnexpected(patchedSdk, -1, "Patched sdk directory not found.")); | 182 formatUnexpected(patchedSdk, -1, "Patched sdk directory not found.")); |
175 } | 183 } |
176 | 184 |
177 Program program; | 185 Program program; |
178 try { | 186 try { |
179 TranslateUri uriTranslator = | 187 TranslateUri uriTranslator = |
180 await TranslateUri.parse(PhysicalFileSystem.instance, null, packages); | 188 await TranslateUri.parse(fileSystem, null, packages); |
181 final Ticker ticker = new Ticker(isVerbose: verbose); | 189 final Ticker ticker = new Ticker(isVerbose: verbose); |
182 final DillTarget dillTarget = new DillTarget(ticker, uriTranslator); | 190 final DillTarget dillTarget = new DillTarget(ticker, uriTranslator); |
183 _appendDillForUri(dillTarget, patchedSdk.resolve('platform.dill')); | 191 _appendDillForUri(dillTarget, patchedSdk.resolve('platform.dill')); |
184 final KernelTarget kernelTarget = new KernelTarget( | 192 final KernelTarget kernelTarget = |
185 PhysicalFileSystem.instance, dillTarget, uriTranslator, strongMode); | 193 new KernelTarget(fileSystem, dillTarget, uriTranslator, strongMode); |
186 kernelTarget.read(fileName); | 194 kernelTarget.read(fileName); |
187 await dillTarget.writeOutline(null); | 195 await dillTarget.writeOutline(null); |
188 program = await kernelTarget.writeOutline(null); | 196 program = await kernelTarget.writeOutline(null); |
189 program = await kernelTarget.writeProgram(null); | 197 program = await kernelTarget.writeProgram(null); |
190 if (kernelTarget.errors.isNotEmpty) { | 198 if (kernelTarget.errors.isNotEmpty) { |
191 return new CompilationResult.errors(kernelTarget.errors | 199 return new CompilationResult.errors(kernelTarget.errors |
192 .map((err) => err.toString()) | 200 .map((err) => err.toString()) |
193 .toList(growable: false)); | 201 .toList(growable: false)); |
194 } | 202 } |
195 } on InputError catch (e) { | 203 } on InputError catch (e) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 final BytesBuilder builder = new BytesBuilder(); | 286 final BytesBuilder builder = new BytesBuilder(); |
279 | 287 |
280 void add(List<int> data) { | 288 void add(List<int> data) { |
281 builder.add(data); | 289 builder.add(data); |
282 } | 290 } |
283 | 291 |
284 void close() { | 292 void close() { |
285 // Nothing to do. | 293 // Nothing to do. |
286 } | 294 } |
287 } | 295 } |
OLD | NEW |