Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2137)

Unified Diff: pkg/front_end/lib/src/fasta/source/source_loader.dart

Issue 2865843002: Use FileSystem to read files in SourceLoader and TranslateUri. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/front_end/lib/src/fasta/source/source_loader.dart
diff --git a/pkg/front_end/lib/src/fasta/source/source_loader.dart b/pkg/front_end/lib/src/fasta/source/source_loader.dart
index 699ab43c7728fe42a10d9434ea3c54604510decc..c538715b36d4bf56c3f23e2e41b8cbcdbf175900 100644
--- a/pkg/front_end/lib/src/fasta/source/source_loader.dart
+++ b/pkg/front_end/lib/src/fasta/source/source_loader.dart
@@ -6,8 +6,10 @@ library fasta.source_loader;
import 'dart:async' show Future;
+import 'dart:io';
import 'dart:typed_data' show Uint8List;
+import 'package:front_end/file_system.dart';
import 'package:front_end/src/base/instrumentation.dart' show Instrumentation;
import 'package:front_end/src/fasta/builder/ast_factory.dart' show AstFactory;
@@ -44,8 +46,6 @@ import '../parser/class_member_parser.dart' show ClassMemberParser;
import '../scanner.dart' show ErrorToken, ScannerResult, Token, scan;
-import '../io.dart' show readBytesFromFile;
-
import 'diet_listener.dart' show DietListener;
import 'diet_parser.dart' show DietParser;
@@ -57,6 +57,9 @@ import 'source_class_builder.dart' show SourceClassBuilder;
import 'source_library_builder.dart' show SourceLibraryBuilder;
class SourceLoader<L> extends Loader<L> {
+ /// The [FileSystem] which should be used to access files.
+ final FileSystem fileSystem;
+
final Map<Uri, List<int>> sourceBytes = <Uri, List<int>>{};
final bool excludeSource = CompilerContext.current.options.excludeSource;
@@ -70,7 +73,7 @@ class SourceLoader<L> extends Loader<L> {
Instrumentation instrumentation;
- SourceLoader(KernelTarget target) : super(target);
+ SourceLoader(this.fileSystem, KernelTarget target) : super(target);
Future<Token> tokenize(SourceLibraryBuilder library,
{bool suppressLexicalErrors: false}) async {
@@ -78,10 +81,27 @@ class SourceLoader<L> extends Loader<L> {
if (uri == null || uri.scheme != "file") {
return inputError(library.uri, -1, "Not found: ${library.uri}.");
}
+
+ // Get the library text from the cache, or read from the file system.
List<int> bytes = sourceBytes[uri];
if (bytes == null) {
- bytes = sourceBytes[uri] = await readBytesFromFile(uri);
+ try {
+ List<int> rawBytes = await fileSystem.entityForUri(uri).readAsBytes();
+ Uint8List zeroTerminatedBytes = new Uint8List(rawBytes.length + 1);
+ zeroTerminatedBytes.setRange(0, rawBytes.length, rawBytes);
ahe 2017/05/08 10:06:14 I'd appreciate if we can roll this back until the
Siggi Cherem (dart-lang) 2017/05/08 16:38:22 Another option: instead of adding an API to read i
scheglov 2017/05/08 16:53:36 Well, we could do this. OTOH API bloating is not n
+ bytes = zeroTerminatedBytes;
+ sourceBytes[uri] = bytes;
+ } on FileSystemException catch (e) {
+ // TODO(scheglov) Throw and catch abstract file-system exceptions.
+ String message = e.message;
+ String osMessage = e.osError?.message;
+ if (osMessage != null && osMessage.isNotEmpty) {
+ message = osMessage;
+ }
+ return inputError(uri, -1, message);
+ }
}
+
byteCount += bytes.length - 1;
ScannerResult result = scan(bytes);
Token token = result.tokens;
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/kernel_target.dart ('k') | pkg/front_end/lib/src/fasta/translate_uri.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698