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

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

Issue 2729913005: [Fasta] include source code in dill (Closed)
Patch Set: Use Uint8List.view when possible Created 3 years, 9 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 5e508462945b3ac4b52d8aadfc046d5f5989957a..3a5f82b14d84062be8a60f28fc0398f0de646c53 100644
--- a/pkg/front_end/lib/src/fasta/source/source_loader.dart
+++ b/pkg/front_end/lib/src/fasta/source/source_loader.dart
@@ -8,6 +8,8 @@ import 'dart:async' show Future;
import 'dart:io' show FileSystemException;
+import 'dart:typed_data' show Uint8List;
+
import '../scanner/io.dart' show readBytesFromFile;
import '../scanner.dart' show ErrorToken, ScannerResult, Token, scan;
@@ -40,8 +42,11 @@ import 'diet_parser.dart' show DietParser;
import 'source_library_builder.dart' show SourceLibraryBuilder;
+import '../compiler_context.dart' show CompilerContext;
+
class SourceLoader<L> extends Loader<L> {
final Map<Uri, List<int>> sourceBytes = <Uri, List<int>>{};
+ final includeSource = CompilerContext.current.options.includeSource;
// Used when building directly to kernel.
ClassHierarchy hierarchy;
@@ -64,7 +69,8 @@ class SourceLoader<L> extends Loader<L> {
ScannerResult result = scan(bytes);
Token token = result.tokens;
if (!suppressLexicalErrors) {
- target.addLineStarts(library.fileUri, result.lineStarts);
+ List<int> source = getSource(bytes);
+ target.addSourceInformation(library.fileUri, result.lineStarts, source);
}
while (token is ErrorToken) {
if (!suppressLexicalErrors) {
@@ -84,6 +90,17 @@ class SourceLoader<L> extends Loader<L> {
}
}
+ List<int> getSource(List<int> bytes) {
+ if (!includeSource) return const <int>[];
+
+ // bytes is 0-terminated. We don't want that included.
+ if (bytes is Uint8List) {
+ return new Uint8List.view(
+ bytes.buffer, bytes.offsetInBytes, bytes.length - 1);
+ }
+ return bytes.sublist(0, bytes.length - 1);
+ }
+
Future<Null> buildOutline(SourceLibraryBuilder library) async {
Token tokens = await tokenize(library);
if (tokens == null) return;
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/kernel_target.dart ('k') | pkg/front_end/lib/src/fasta/target_implementation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698