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 source_file_provider; | 5 library source_file_provider; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:math' as math; | 10 import 'dart:math' as math; |
11 | 11 |
12 import '../compiler.dart' as api show Diagnostic, DiagnosticHandler; | 12 import '../compiler.dart' as api show Diagnostic, DiagnosticHandler; |
13 import '../compiler_new.dart' as api show CompilerInput, CompilerDiagnostics; | |
13 import 'dart2js.dart' show AbortLeg; | 14 import 'dart2js.dart' show AbortLeg; |
14 import 'colors.dart' as colors; | 15 import 'colors.dart' as colors; |
15 import 'io/source_file.dart'; | 16 import 'io/source_file.dart'; |
16 import 'filenames.dart'; | 17 import 'filenames.dart'; |
17 import 'util/uri_extras.dart'; | 18 import 'util/uri_extras.dart'; |
18 import 'dart:typed_data'; | 19 import 'dart:typed_data'; |
20 import '../compiler_new.dart'; | |
19 | 21 |
20 List<int> readAll(String filename) { | 22 List<int> readAll(String filename) { |
21 var file = (new File(filename)).openSync(); | 23 var file = (new File(filename)).openSync(); |
22 var length = file.lengthSync(); | 24 var length = file.lengthSync(); |
23 // +1 to have a 0 terminated list, see [Scanner]. | 25 // +1 to have a 0 terminated list, see [Scanner]. |
24 var buffer = new Uint8List(length + 1); | 26 var buffer = new Uint8List(length + 1); |
25 file.readIntoSync(buffer, 0, length); | 27 file.readIntoSync(buffer, 0, length); |
26 file.closeSync(); | 28 file.closeSync(); |
27 return buffer; | 29 return buffer; |
28 } | 30 } |
29 | 31 |
30 abstract class SourceFileProvider { | 32 abstract class SourceFileProvider implements CompilerInput { |
31 bool isWindows = (Platform.operatingSystem == 'windows'); | 33 bool isWindows = (Platform.operatingSystem == 'windows'); |
32 Uri cwd = currentDirectory; | 34 Uri cwd = currentDirectory; |
33 Map<Uri, SourceFile> sourceFiles = <Uri, SourceFile>{}; | 35 Map<Uri, SourceFile> sourceFiles = <Uri, SourceFile>{}; |
34 int dartCharactersRead = 0; | 36 int dartCharactersRead = 0; |
35 | 37 |
36 Future<String> readStringFromUri(Uri resourceUri) { | 38 Future<String> readStringFromUri(Uri resourceUri) { |
37 return readUtf8BytesFromUri(resourceUri).then(UTF8.decode); | 39 return readUtf8BytesFromUri(resourceUri).then(UTF8.decode); |
38 } | 40 } |
39 | 41 |
40 Future<List<int>> readUtf8BytesFromUri(Uri resourceUri) { | 42 Future<List<int>> readUtf8BytesFromUri(Uri resourceUri) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 Future/*<List<int> | String>*/ call(Uri resourceUri); | 105 Future/*<List<int> | String>*/ call(Uri resourceUri); |
104 | 106 |
105 relativizeUri(Uri uri) => relativize(cwd, uri, isWindows); | 107 relativizeUri(Uri uri) => relativize(cwd, uri, isWindows); |
106 | 108 |
107 SourceFile getSourceFile(Uri resourceUri) { | 109 SourceFile getSourceFile(Uri resourceUri) { |
108 return sourceFiles[resourceUri]; | 110 return sourceFiles[resourceUri]; |
109 } | 111 } |
110 } | 112 } |
111 | 113 |
112 class CompilerSourceFileProvider extends SourceFileProvider { | 114 class CompilerSourceFileProvider extends SourceFileProvider { |
113 Future<List<int>> call(Uri resourceUri) => readUtf8BytesFromUri(resourceUri); | 115 |
116 Future<List<int>> call(Uri resourceUri) => readFromUri(resourceUri); | |
Siggi Cherem (dart-lang)
2015/07/13 17:28:37
After we are done with the refactor, will we need
Johnni Winther
2015/07/13 17:45:19
These _are_ going away. Adding TODOs.
| |
117 | |
118 @override | |
119 Future readFromUri(Uri uri) => readUtf8BytesFromUri(uri); | |
114 } | 120 } |
115 | 121 |
116 class FormattingDiagnosticHandler { | 122 class FormattingDiagnosticHandler implements CompilerDiagnostics { |
117 final SourceFileProvider provider; | 123 final SourceFileProvider provider; |
118 bool showWarnings = true; | 124 bool showWarnings = true; |
119 bool showHints = true; | 125 bool showHints = true; |
120 bool verbose = false; | 126 bool verbose = false; |
121 bool isAborting = false; | 127 bool isAborting = false; |
122 bool enableColors = false; | 128 bool enableColors = false; |
123 bool throwOnError = false; | 129 bool throwOnError = false; |
124 int throwOnErrorCount = 0; | 130 int throwOnErrorCount = 0; |
125 api.Diagnostic lastKind = null; | 131 api.Diagnostic lastKind = null; |
126 int fatalCount = 0; | 132 int fatalCount = 0; |
(...skipping 26 matching lines...) Expand all Loading... | |
153 return 'Hint: $message'; | 159 return 'Hint: $message'; |
154 case api.Diagnostic.CRASH: | 160 case api.Diagnostic.CRASH: |
155 return 'Internal Error: $message'; | 161 return 'Internal Error: $message'; |
156 case api.Diagnostic.INFO: | 162 case api.Diagnostic.INFO: |
157 case api.Diagnostic.VERBOSE_INFO: | 163 case api.Diagnostic.VERBOSE_INFO: |
158 return 'Info: $message'; | 164 return 'Info: $message'; |
159 } | 165 } |
160 throw 'Unexpected diagnostic kind: $kind (${kind.ordinal})'; | 166 throw 'Unexpected diagnostic kind: $kind (${kind.ordinal})'; |
161 } | 167 } |
162 | 168 |
163 void diagnosticHandler(Uri uri, int begin, int end, String message, | 169 @override |
164 api.Diagnostic kind) { | 170 void reportDiagnostic(Uri uri, int begin, int end, String message, |
171 api.Diagnostic kind) { | |
165 // TODO(ahe): Remove this when source map is handled differently. | 172 // TODO(ahe): Remove this when source map is handled differently. |
166 if (identical(kind.name, 'source map')) return; | 173 if (identical(kind.name, 'source map')) return; |
167 | 174 |
168 if (isAborting) return; | 175 if (isAborting) return; |
169 isAborting = (kind == api.Diagnostic.CRASH); | 176 isAborting = (kind == api.Diagnostic.CRASH); |
170 | 177 |
171 bool fatal = (kind.ordinal & FATAL) != 0; | 178 bool fatal = (kind.ordinal & FATAL) != 0; |
172 bool isInfo = (kind.ordinal & INFO) != 0; | 179 bool isInfo = (kind.ordinal & INFO) != 0; |
173 if (isInfo && uri == null && kind != api.Diagnostic.INFO) { | 180 if (isInfo && uri == null && kind != api.Diagnostic.INFO) { |
174 info(message, kind); | 181 info(message, kind); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 print('${provider.relativizeUri(uri)}$position:\n' | 223 print('${provider.relativizeUri(uri)}$position:\n' |
217 '${color(message)}'); | 224 '${color(message)}'); |
218 } | 225 } |
219 } | 226 } |
220 if (fatal && ++fatalCount >= throwOnErrorCount && throwOnError) { | 227 if (fatal && ++fatalCount >= throwOnErrorCount && throwOnError) { |
221 isAborting = true; | 228 isAborting = true; |
222 throw new AbortLeg(message); | 229 throw new AbortLeg(message); |
223 } | 230 } |
224 } | 231 } |
225 | 232 |
226 void call(Uri uri, int begin, int end, String message, api.Diagnostic kind) { | 233 void call(Uri uri, int begin, int end, String message, api.Diagnostic kind) { |
Siggi Cherem (dart-lang)
2015/07/13 17:28:37
same here
Johnni Winther
2015/07/13 19:02:22
Done.
| |
227 return diagnosticHandler(uri, begin, end, message, kind); | 234 return reportDiagnostic(uri, begin, end, message, kind); |
228 } | 235 } |
229 } | 236 } |
230 | 237 |
231 typedef void MessageCallback(String message); | 238 typedef void MessageCallback(String message); |
232 | 239 |
233 class RandomAccessFileOutputProvider { | 240 class RandomAccessFileOutputProvider { |
234 final Uri out; | 241 final Uri out; |
235 final Uri sourceMapOut; | 242 final Uri sourceMapOut; |
236 final MessageCallback onInfo; | 243 final MessageCallback onInfo; |
237 final MessageCallback onFailure; | 244 final MessageCallback onFailure; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 var onAdd, onClose; | 332 var onAdd, onClose; |
326 | 333 |
327 EventSinkWrapper(this.onAdd, this.onClose); | 334 EventSinkWrapper(this.onAdd, this.onClose); |
328 | 335 |
329 void add(String data) => onAdd(data); | 336 void add(String data) => onAdd(data); |
330 | 337 |
331 void addError(error, [StackTrace stackTrace]) => throw error; | 338 void addError(error, [StackTrace stackTrace]) => throw error; |
332 | 339 |
333 void close() => onClose(); | 340 void close() => onClose(); |
334 } | 341 } |
OLD | NEW |