| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Implementation of the new compiler API in '../compiler_new.dart' through the | 5 /// Implementation of the new compiler API in '../compiler_new.dart' through the |
| 6 /// old compiler API in '../compiler.dart'. | 6 /// old compiler API in '../compiler.dart'. |
| 7 | 7 |
| 8 library compiler.api.legacy; | 8 library compiler.api.legacy; |
| 9 | 9 |
| 10 import 'dart:async' show EventSink, Future; | 10 import 'dart:async' show EventSink, Future; |
| 11 | 11 |
| 12 import '../compiler.dart'; | 12 import '../compiler.dart'; |
| 13 import '../compiler_new.dart'; | 13 import '../compiler_new.dart'; |
| 14 import 'io/source_file.dart'; |
| 14 import 'null_compiler_output.dart' show NullSink; | 15 import 'null_compiler_output.dart' show NullSink; |
| 15 | 16 |
| 16 /// Implementation of [CompilerInput] using a [CompilerInputProvider]. | 17 /// Implementation of [CompilerInput] using a [CompilerInputProvider]. |
| 17 class LegacyCompilerInput implements CompilerInput { | 18 class LegacyCompilerInput implements CompilerInput { |
| 18 final CompilerInputProvider _inputProvider; | 19 final CompilerInputProvider _inputProvider; |
| 19 | 20 |
| 20 LegacyCompilerInput(this._inputProvider); | 21 LegacyCompilerInput(this._inputProvider); |
| 21 | 22 |
| 22 @override | 23 @override |
| 23 Future readFromUri(Uri uri) { | 24 Future<Input> readFromUri(Uri uri, {InputKind inputKind: InputKind.utf8}) { |
| 24 return _inputProvider(uri); | 25 return _inputProvider(uri).then((/*String|List<int>*/ data) { |
| 26 switch (inputKind) { |
| 27 case InputKind.utf8: |
| 28 SourceFile sourceFile; |
| 29 if (data is List<int>) { |
| 30 sourceFile = new Utf8BytesSourceFile(uri, data); |
| 31 } else if (data is String) { |
| 32 sourceFile = new StringSourceFile.fromUri(uri, data); |
| 33 } else { |
| 34 throw "Expected a 'String' or a 'List<int>' from the input " |
| 35 "provider, but got: ${Error.safeToString(data)}."; |
| 36 } |
| 37 return sourceFile; |
| 38 case InputKind.binary: |
| 39 if (data is String) { |
| 40 data = data.codeUnits; |
| 41 } |
| 42 return new Binary(uri, data); |
| 43 } |
| 44 }); |
| 25 } | 45 } |
| 26 } | 46 } |
| 27 | 47 |
| 28 /// Implementation of [CompilerDiagnostics] using a [DiagnosticHandler]. | 48 /// Implementation of [CompilerDiagnostics] using a [DiagnosticHandler]. |
| 29 class LegacyCompilerDiagnostics implements CompilerDiagnostics { | 49 class LegacyCompilerDiagnostics implements CompilerDiagnostics { |
| 30 final DiagnosticHandler _handler; | 50 final DiagnosticHandler _handler; |
| 31 | 51 |
| 32 LegacyCompilerDiagnostics(this._handler); | 52 LegacyCompilerDiagnostics(this._handler); |
| 33 | 53 |
| 34 @override | 54 @override |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 final EventSink<String> sink; | 88 final EventSink<String> sink; |
| 69 | 89 |
| 70 LegacyOutputSink(this.sink); | 90 LegacyOutputSink(this.sink); |
| 71 | 91 |
| 72 @override | 92 @override |
| 73 void add(String event) => sink.add(event); | 93 void add(String event) => sink.add(event); |
| 74 | 94 |
| 75 @override | 95 @override |
| 76 void close() => sink.close(); | 96 void close() => sink.close(); |
| 77 } | 97 } |
| OLD | NEW |