Chromium Code Reviews| 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 |
| 11 FileSystemException; | 11 FileSystemException; |
| 12 | 12 |
| 13 import 'package:dart_scanner/io.dart' show | 13 import 'package:dart_scanner/io.dart' show |
| 14 readBytesFromFile; | 14 readBytesFromFile; |
| 15 | 15 |
| 16 import 'package:dart_scanner/src/token.dart' show | |
| 17 Token; | |
| 18 | |
| 19 import 'package:dart_scanner/dart_scanner.dart' show | 16 import 'package:dart_scanner/dart_scanner.dart' show |
| 17 ErrorToken, | |
| 18 Token, | |
| 20 scan; | 19 scan; |
| 21 | 20 |
| 22 import 'package:dart_parser/src/class_member_parser.dart' show | 21 import 'package:dart_parser/src/class_member_parser.dart' show |
| 23 ClassMemberParser; | 22 ClassMemberParser; |
| 24 | 23 |
| 25 import 'package:kernel/ast.dart' show | 24 import 'package:kernel/ast.dart' show |
| 26 Program; | 25 Program; |
| 27 | 26 |
| 28 import 'package:kernel/class_hierarchy.dart' show | 27 import 'package:kernel/class_hierarchy.dart' show |
| 29 ClassHierarchy; | 28 ClassHierarchy; |
| 30 | 29 |
| 31 import 'package:kernel/core_types.dart' show | 30 import 'package:kernel/core_types.dart' show |
| 32 CoreTypes; | 31 CoreTypes; |
| 33 | 32 |
| 34 import '../errors.dart' show | 33 import '../errors.dart' show |
| 34 InputError, | |
| 35 inputError; | 35 inputError; |
| 36 | 36 |
| 37 import '../export.dart' show | 37 import '../export.dart' show |
| 38 Export; | 38 Export; |
| 39 | 39 |
| 40 import '../analyzer/element_store.dart' show | 40 import '../analyzer/element_store.dart' show |
| 41 ElementStore; | 41 ElementStore; |
| 42 | 42 |
| 43 import '../builder/builder.dart' show | 43 import '../builder/builder.dart' show |
| 44 Builder, | 44 Builder, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 70 // Used when building directly to kernel. | 70 // Used when building directly to kernel. |
| 71 ClassHierarchy hierarchy; | 71 ClassHierarchy hierarchy; |
| 72 CoreTypes coreTypes; | 72 CoreTypes coreTypes; |
| 73 | 73 |
| 74 // Used when building analyzer ASTs. | 74 // Used when building analyzer ASTs. |
| 75 ElementStore elementStore; | 75 ElementStore elementStore; |
| 76 | 76 |
| 77 SourceLoader(TargetImplementation target) | 77 SourceLoader(TargetImplementation target) |
| 78 : super(target); | 78 : super(target); |
| 79 | 79 |
| 80 Future<Token> tokenize(SourceLibraryBuilder library) async { | 80 Future<Token> tokenize(SourceLibraryBuilder library, |
| 81 {bool suppressLexicalErrors: false}) async { | |
| 81 Uri uri = library.uri; | 82 Uri uri = library.uri; |
| 82 if (uri.scheme != "file") { | 83 if (uri.scheme != "file") { |
| 83 uri = target.translateUri(uri); | 84 uri = target.translateUri(uri); |
| 84 if (uri == null) { | 85 if (uri == null) { |
| 85 print("Skipping ${library.uri}"); | 86 print("Skipping ${library.uri}"); |
| 86 return null; | 87 return null; |
| 87 } | 88 } |
| 88 library.fileUri = uri; | 89 library.fileUri = uri; |
| 89 } | 90 } |
| 90 try { | 91 try { |
| 91 List<int> bytes = await readBytesFromFile(uri); | 92 List<int> bytes = await readBytesFromFile(uri); |
| 92 byteCount += bytes.length - 1; | 93 byteCount += bytes.length - 1; |
| 93 return scan(bytes).tokens; | 94 Token token = scan(bytes).tokens; |
| 95 while (token is ErrorToken) { | |
| 96 if (!suppressLexicalErrors) { | |
| 97 ErrorToken error = token; | |
| 98 String message = new InputError( | |
| 99 uri, token.charOffset, error.assertionMessage).format(); | |
| 100 print(message); | |
| 101 } | |
| 102 token = token.next; | |
| 103 } | |
| 104 return token; | |
| 94 } on FileSystemException catch (e) { | 105 } on FileSystemException catch (e) { |
| 95 String message = e.message; | 106 String message = e.message; |
| 96 String osMessage = e.osError?.message; | 107 String osMessage = e.osError?.message; |
| 97 if (osMessage != null && osMessage.isNotEmpty) { | 108 if (osMessage != null && osMessage.isNotEmpty) { |
| 98 message = osMessage; | 109 message = osMessage; |
| 99 } | 110 } |
| 100 return inputError(uri, -1, message); | 111 return inputError(uri, -1, message); |
| 101 } | 112 } |
| 102 } | 113 } |
| 103 | 114 |
| 104 Future<Null> buildOutline(SourceLibraryBuilder library) async { | 115 Future<Null> buildOutline(SourceLibraryBuilder library) async { |
| 105 Token tokens = await tokenize(library); | 116 Token tokens = await tokenize(library); |
| 106 if (tokens == null) return; | 117 if (tokens == null) return; |
| 107 OutlineBuilder listener = new OutlineBuilder(library); | 118 OutlineBuilder listener = new OutlineBuilder(library); |
| 108 new ClassMemberParser(listener).parseUnit(tokens); | 119 new ClassMemberParser(listener).parseUnit(tokens); |
| 109 } | 120 } |
| 110 | 121 |
| 111 Future<Null> buildBody(LibraryBuilder library, AstKind astKind) async { | 122 Future<Null> buildBody(LibraryBuilder library, AstKind astKind) async { |
| 112 if (library is SourceLibraryBuilder) { | 123 if (library is SourceLibraryBuilder) { |
| 113 Token tokens = await tokenize(library); | 124 Token tokens = await tokenize(library, suppressLexicalErrors: true); |
|
Johnni Winther
2017/01/30 09:04:39
Why suppress errors here?
ahe
2017/01/30 13:26:22
Added:
// We tokenize source files twice to
| |
| 114 if (tokens == null) return; | 125 if (tokens == null) return; |
| 115 DietListener listener = new DietListener( | 126 DietListener listener = new DietListener( |
| 116 library, elementStore, hierarchy, coreTypes, astKind); | 127 library, elementStore, hierarchy, coreTypes, astKind); |
| 117 DietParser parser = new DietParser(listener); | 128 DietParser parser = new DietParser(listener); |
| 118 parser.parseUnit(tokens); | 129 parser.parseUnit(tokens); |
| 119 for (SourceLibraryBuilder part in library.parts) { | 130 for (SourceLibraryBuilder part in library.parts) { |
| 120 Token tokens = await tokenize(part); | 131 Token tokens = await tokenize(part); |
| 121 if (tokens != null) { | 132 if (tokens != null) { |
| 122 parser.parseUnit(tokens); | 133 parser.parseUnit(tokens); |
| 123 } | 134 } |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 ticker.logMs("Built analyzer element model."); | 348 ticker.logMs("Built analyzer element model."); |
| 338 } | 349 } |
| 339 | 350 |
| 340 void computeHierarchy(Program program) { | 351 void computeHierarchy(Program program) { |
| 341 hierarchy = new ClassHierarchy(program); | 352 hierarchy = new ClassHierarchy(program); |
| 342 ticker.logMs("Computed class hierarchy"); | 353 ticker.logMs("Computed class hierarchy"); |
| 343 coreTypes = new CoreTypes(program); | 354 coreTypes = new CoreTypes(program); |
| 344 ticker.logMs("Computed core types"); | 355 ticker.logMs("Computed core types"); |
| 345 } | 356 } |
| 346 } | 357 } |
| OLD | NEW |