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

Unified Diff: pkg/compiler/lib/src/io/source_file.dart

Issue 2897903003: Support loading binary data in dart2js (Closed)
Patch Set: Updated cf. comments 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
« no previous file with comments | « pkg/compiler/lib/src/diagnostics/messages.dart ('k') | pkg/compiler/lib/src/library_loader.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/io/source_file.dart
diff --git a/pkg/compiler/lib/src/io/source_file.dart b/pkg/compiler/lib/src/io/source_file.dart
index 2710be7f47e7505acf574958165653c77c73abc3..ff47c16eb54d6c4a921ee064bb290a0b72955da6 100644
--- a/pkg/compiler/lib/src/io/source_file.dart
+++ b/pkg/compiler/lib/src/io/source_file.dart
@@ -9,15 +9,17 @@ import 'dart:math';
import 'dart:typed_data' show Uint8List;
import 'package:kernel/ast.dart' as kernel show Location, Source;
-
import 'location_provider.dart' show LocationProvider;
+import '../../compiler_new.dart';
/// Represents a file of source code. The content can be either a [String] or
/// a UTF-8 encoded [List<int>] of bytes.
-abstract class SourceFile implements LocationProvider {
+abstract class SourceFile<T> implements Input<T>, LocationProvider {
/// The absolute URI of the source file.
Uri get uri;
+ InputKind get inputKind => InputKind.utf8;
+
kernel.Source cachedKernelSource;
kernel.Source get kernelSource {
@@ -166,7 +168,7 @@ List<int> _zeroTerminateIfNecessary(List<int> bytes) {
return result;
}
-class Utf8BytesSourceFile extends SourceFile {
+class Utf8BytesSourceFile extends SourceFile<List<int>> {
final Uri uri;
/// The UTF-8 encoded content of the source file.
@@ -179,6 +181,8 @@ class Utf8BytesSourceFile extends SourceFile {
Utf8BytesSourceFile(this.uri, List<int> content)
: this.zeroTerminatedContent = _zeroTerminateIfNecessary(content);
+ List<int> get data => zeroTerminatedContent;
+
String slowText() {
// Don't convert the trailing zero byte.
return UTF8.decoder
@@ -220,7 +224,7 @@ class CachingUtf8BytesSourceFile extends Utf8BytesSourceFile {
}
}
-class StringSourceFile extends SourceFile {
+class StringSourceFile extends SourceFile<String> {
final Uri uri;
final String filename;
final String text;
@@ -233,6 +237,8 @@ class StringSourceFile extends SourceFile {
StringSourceFile.fromName(String filename, String text)
: this(new Uri(path: filename), filename, text);
+ String get data => text;
+
int get length => text.length;
set length(int v) {}
@@ -244,3 +250,13 @@ class StringSourceFile extends SourceFile {
String slowSubstring(int start, int end) => text.substring(start, end);
}
+
+/// Binary input data.
+class Binary implements Input<List<int>> {
+ final Uri uri;
+ final List<int> data;
+
+ Binary(this.uri, this.data);
+
+ InputKind get inputKind => InputKind.binary;
+}
« no previous file with comments | « pkg/compiler/lib/src/diagnostics/messages.dart ('k') | pkg/compiler/lib/src/library_loader.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698