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

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

Issue 2729913005: [Fasta] include source code in dill (Closed)
Patch Set: Addressed comments 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 fasta.source_loader; 5 library fasta.source_loader;
6 6
7 import 'dart:async' show Future; 7 import 'dart:async' show Future;
8 8
9 import 'dart:io' show FileSystemException; 9 import 'dart:io' show FileSystemException;
10 10
(...skipping 22 matching lines...) Expand all
33 import '../loader.dart' show Loader; 33 import '../loader.dart' show Loader;
34 34
35 import '../target_implementation.dart' show TargetImplementation; 35 import '../target_implementation.dart' show TargetImplementation;
36 36
37 import 'diet_listener.dart' show DietListener; 37 import 'diet_listener.dart' show DietListener;
38 38
39 import 'diet_parser.dart' show DietParser; 39 import 'diet_parser.dart' show DietParser;
40 40
41 import 'source_library_builder.dart' show SourceLibraryBuilder; 41 import 'source_library_builder.dart' show SourceLibraryBuilder;
42 42
43 import '../compiler_context.dart' show CompilerContext;
44
43 class SourceLoader<L> extends Loader<L> { 45 class SourceLoader<L> extends Loader<L> {
44 final Map<Uri, List<int>> sourceBytes = <Uri, List<int>>{}; 46 final Map<Uri, List<int>> sourceBytes = <Uri, List<int>>{};
47 bool get includeSource => CompilerContext.current.options.includeSource;
ahe 2017/03/03 13:14:50 This should be set when constructing this object:
jensj 2017/03/06 07:38:36 Done.
45 48
46 // Used when building directly to kernel. 49 // Used when building directly to kernel.
47 ClassHierarchy hierarchy; 50 ClassHierarchy hierarchy;
48 CoreTypes coreTypes; 51 CoreTypes coreTypes;
49 52
50 SourceLoader(TargetImplementation target) : super(target); 53 SourceLoader(TargetImplementation target) : super(target);
51 54
52 Future<Token> tokenize(SourceLibraryBuilder library, 55 Future<Token> tokenize(SourceLibraryBuilder library,
53 {bool suppressLexicalErrors: false}) async { 56 {bool suppressLexicalErrors: false}) async {
54 Uri uri = library.fileUri; 57 Uri uri = library.fileUri;
55 if (uri == null || uri.scheme != "file") { 58 if (uri == null || uri.scheme != "file") {
56 return inputError(library.uri, -1, "Not found: ${library.uri}."); 59 return inputError(library.uri, -1, "Not found: ${library.uri}.");
57 } 60 }
58 try { 61 try {
59 List<int> bytes = sourceBytes[uri]; 62 List<int> bytes = sourceBytes[uri];
60 if (bytes == null) { 63 if (bytes == null) {
61 bytes = sourceBytes[uri] = await readBytesFromFile(uri); 64 bytes = sourceBytes[uri] = await readBytesFromFile(uri);
62 } 65 }
63 byteCount += bytes.length - 1; 66 byteCount += bytes.length - 1;
64 ScannerResult result = scan(bytes); 67 ScannerResult result = scan(bytes);
65 Token token = result.tokens; 68 Token token = result.tokens;
66 if (!suppressLexicalErrors) { 69 if (!suppressLexicalErrors) {
67 target.addLineStarts(library.fileUri, result.lineStarts); 70 var source = includeSource ? bytes : const <int>[];
ahe 2017/03/03 13:14:50 var -> List<int>
jensj 2017/03/06 07:38:36 Done.
71 target.addSourceInformation(library.fileUri, result.lineStarts, source);
68 } 72 }
69 while (token is ErrorToken) { 73 while (token is ErrorToken) {
70 if (!suppressLexicalErrors) { 74 if (!suppressLexicalErrors) {
71 ErrorToken error = token; 75 ErrorToken error = token;
72 printUnexpected(uri, token.charOffset, error.assertionMessage); 76 printUnexpected(uri, token.charOffset, error.assertionMessage);
73 } 77 }
74 token = token.next; 78 token = token.next;
75 } 79 }
76 return token; 80 return token;
77 } on FileSystemException catch (e) { 81 } on FileSystemException catch (e) {
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 341
338 void computeHierarchy(Program program) { 342 void computeHierarchy(Program program) {
339 hierarchy = new ClassHierarchy(program); 343 hierarchy = new ClassHierarchy(program);
340 ticker.logMs("Computed class hierarchy"); 344 ticker.logMs("Computed class hierarchy");
341 coreTypes = new CoreTypes(program); 345 coreTypes = new CoreTypes(program);
342 ticker.logMs("Computed core types"); 346 ticker.logMs("Computed core types");
343 } 347 }
344 348
345 List<Uri> getDependencies() => sourceBytes.keys.toList(); 349 List<Uri> getDependencies() => sourceBytes.keys.toList();
346 } 350 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698