| OLD | NEW |
| 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 | 7 import 'dart:async' show |
| 8 Future; | 8 Future; |
| 9 | 9 |
| 10 import 'dart:io' show | 10 import 'dart:io' show |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 import 'diet_parser.dart' show | 64 import 'diet_parser.dart' show |
| 65 DietParser; | 65 DietParser; |
| 66 | 66 |
| 67 import 'source_library_builder.dart' show | 67 import 'source_library_builder.dart' show |
| 68 SourceLibraryBuilder; | 68 SourceLibraryBuilder; |
| 69 | 69 |
| 70 import '../ast_kind.dart' show | 70 import '../ast_kind.dart' show |
| 71 AstKind; | 71 AstKind; |
| 72 | 72 |
| 73 class SourceLoader<L> extends Loader<L> { | 73 class SourceLoader<L> extends Loader<L> { |
| 74 final Map<Uri, List<int>> sourceBytes = <Uri, List<int>>{}; |
| 75 |
| 74 // Used when building directly to kernel. | 76 // Used when building directly to kernel. |
| 75 ClassHierarchy hierarchy; | 77 ClassHierarchy hierarchy; |
| 76 CoreTypes coreTypes; | 78 CoreTypes coreTypes; |
| 77 | 79 |
| 78 // Used when building analyzer ASTs. | 80 // Used when building analyzer ASTs. |
| 79 ElementStore elementStore; | 81 ElementStore elementStore; |
| 80 | 82 |
| 81 SourceLoader(TargetImplementation target) | 83 SourceLoader(TargetImplementation target) |
| 82 : super(target); | 84 : super(target); |
| 83 | 85 |
| 84 Future<Token> tokenize(SourceLibraryBuilder library, | 86 Future<Token> tokenize(SourceLibraryBuilder library, |
| 85 {bool suppressLexicalErrors: false}) async { | 87 {bool suppressLexicalErrors: false}) async { |
| 86 Uri uri = library.fileUri; | 88 Uri uri = library.fileUri; |
| 87 if (uri == null || uri.scheme != "file") { | 89 if (uri == null || uri.scheme != "file") { |
| 88 return inputError(library.uri, -1, "Not found: ${library.uri}."); | 90 return inputError(library.uri, -1, "Not found: ${library.uri}."); |
| 89 } | 91 } |
| 90 try { | 92 try { |
| 91 List<int> bytes = await readBytesFromFile(uri); | 93 List<int> bytes = sourceBytes[uri]; |
| 94 if (bytes == null) { |
| 95 bytes = sourceBytes[uri] = await readBytesFromFile(uri); |
| 96 } |
| 92 byteCount += bytes.length - 1; | 97 byteCount += bytes.length - 1; |
| 93 ScannerResult result = scan(bytes); | 98 ScannerResult result = scan(bytes); |
| 94 Token token = result.tokens; | 99 Token token = result.tokens; |
| 95 if (!suppressLexicalErrors) { | 100 if (!suppressLexicalErrors) { |
| 96 target.addLineStarts(library.fileUri, result.lineStarts); | 101 target.addLineStarts(library.fileUri, result.lineStarts); |
| 97 } | 102 } |
| 98 while (token is ErrorToken) { | 103 while (token is ErrorToken) { |
| 99 if (!suppressLexicalErrors) { | 104 if (!suppressLexicalErrors) { |
| 100 ErrorToken error = token; | 105 ErrorToken error = token; |
| 101 print(new InputError(uri, token.charOffset, error.assertionMessage) | 106 print(new InputError(uri, token.charOffset, error.assertionMessage) |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 ticker.logMs("Built analyzer element model."); | 369 ticker.logMs("Built analyzer element model."); |
| 365 } | 370 } |
| 366 | 371 |
| 367 void computeHierarchy(Program program) { | 372 void computeHierarchy(Program program) { |
| 368 hierarchy = new ClassHierarchy(program); | 373 hierarchy = new ClassHierarchy(program); |
| 369 ticker.logMs("Computed class hierarchy"); | 374 ticker.logMs("Computed class hierarchy"); |
| 370 coreTypes = new CoreTypes(program); | 375 coreTypes = new CoreTypes(program); |
| 371 ticker.logMs("Computed core types"); | 376 ticker.logMs("Computed core types"); |
| 372 } | 377 } |
| 373 } | 378 } |
| OLD | NEW |