| 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:front_end/src/fasta/scanner/io.dart' show | 13 import 'package:front_end/src/fasta/scanner/io.dart' show |
| 14 readBytesFromFile; | 14 readBytesFromFile; |
| 15 | 15 |
| 16 import 'package:front_end/src/fasta/scanner.dart' show | 16 import 'package:front_end/src/fasta/scanner.dart' show |
| 17 ErrorToken, | 17 ErrorToken, |
| 18 ScannerResult, |
| 18 Token, | 19 Token, |
| 19 scan; | 20 scan; |
| 20 | 21 |
| 21 import 'package:front_end/src/fasta/parser/class_member_parser.dart' show | 22 import 'package:front_end/src/fasta/parser/class_member_parser.dart' show |
| 22 ClassMemberParser; | 23 ClassMemberParser; |
| 23 | 24 |
| 24 import 'package:kernel/ast.dart' show | 25 import 'package:kernel/ast.dart' show |
| 25 Program; | 26 Program; |
| 26 | 27 |
| 27 import 'package:kernel/class_hierarchy.dart' show | 28 import 'package:kernel/class_hierarchy.dart' show |
| 28 ClassHierarchy; | 29 ClassHierarchy; |
| 29 | 30 |
| 30 import 'package:kernel/core_types.dart' show | 31 import 'package:kernel/core_types.dart' show |
| 31 CoreTypes; | 32 CoreTypes; |
| 32 | 33 |
| 33 import '../errors.dart' show | 34 import '../errors.dart' show |
| 34 InputError, | 35 InputError, |
| 35 inputError; | 36 inputError; |
| 36 | 37 |
| 38 import '../messages.dart' show |
| 39 warning; |
| 40 |
| 37 import '../export.dart' show | 41 import '../export.dart' show |
| 38 Export; | 42 Export; |
| 39 | 43 |
| 40 import '../analyzer/element_store.dart' show | 44 import '../analyzer/element_store.dart' show |
| 41 ElementStore; | 45 ElementStore; |
| 42 | 46 |
| 43 import '../builder/builder.dart' show | 47 import '../builder/builder.dart' show |
| 44 Builder, | 48 Builder, |
| 45 ClassBuilder, | 49 ClassBuilder, |
| 46 LibraryBuilder; | 50 LibraryBuilder; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 83 |
| 80 Future<Token> tokenize(SourceLibraryBuilder library, | 84 Future<Token> tokenize(SourceLibraryBuilder library, |
| 81 {bool suppressLexicalErrors: false}) async { | 85 {bool suppressLexicalErrors: false}) async { |
| 82 Uri uri = library.fileUri; | 86 Uri uri = library.fileUri; |
| 83 if (uri == null || uri.scheme != "file") { | 87 if (uri == null || uri.scheme != "file") { |
| 84 return inputError(library.uri, -1, "Not found: ${library.uri}."); | 88 return inputError(library.uri, -1, "Not found: ${library.uri}."); |
| 85 } | 89 } |
| 86 try { | 90 try { |
| 87 List<int> bytes = await readBytesFromFile(uri); | 91 List<int> bytes = await readBytesFromFile(uri); |
| 88 byteCount += bytes.length - 1; | 92 byteCount += bytes.length - 1; |
| 89 Token token = scan(bytes).tokens; | 93 ScannerResult result = scan(bytes); |
| 94 Token token = result.tokens; |
| 95 if (!suppressLexicalErrors) { |
| 96 target.addLineStarts(library.fileUri, result.lineStarts); |
| 97 } |
| 90 while (token is ErrorToken) { | 98 while (token is ErrorToken) { |
| 91 if (!suppressLexicalErrors) { | 99 if (!suppressLexicalErrors) { |
| 92 ErrorToken error = token; | 100 ErrorToken error = token; |
| 93 String message = new InputError( | 101 print(new InputError(uri, token.charOffset, error.assertionMessage) |
| 94 uri, token.charOffset, error.assertionMessage).format(); | 102 .format()); |
| 95 print(message); | |
| 96 } | 103 } |
| 97 token = token.next; | 104 token = token.next; |
| 98 } | 105 } |
| 99 return token; | 106 return token; |
| 100 } on FileSystemException catch (e) { | 107 } on FileSystemException catch (e) { |
| 101 String message = e.message; | 108 String message = e.message; |
| 102 String osMessage = e.osError?.message; | 109 String osMessage = e.osError?.message; |
| 103 if (osMessage != null && osMessage.isNotEmpty) { | 110 if (osMessage != null && osMessage.isNotEmpty) { |
| 104 message = osMessage; | 111 message = osMessage; |
| 105 } | 112 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 121 // time we suppress lexical errors. | 128 // time we suppress lexical errors. |
| 122 Token tokens = await tokenize(library, suppressLexicalErrors: true); | 129 Token tokens = await tokenize(library, suppressLexicalErrors: true); |
| 123 if (tokens == null) return; | 130 if (tokens == null) return; |
| 124 DietListener listener = new DietListener( | 131 DietListener listener = new DietListener( |
| 125 library, elementStore, hierarchy, coreTypes, astKind); | 132 library, elementStore, hierarchy, coreTypes, astKind); |
| 126 DietParser parser = new DietParser(listener); | 133 DietParser parser = new DietParser(listener); |
| 127 parser.parseUnit(tokens); | 134 parser.parseUnit(tokens); |
| 128 for (SourceLibraryBuilder part in library.parts) { | 135 for (SourceLibraryBuilder part in library.parts) { |
| 129 Token tokens = await tokenize(part); | 136 Token tokens = await tokenize(part); |
| 130 if (tokens != null) { | 137 if (tokens != null) { |
| 138 listener.uri = part.fileUri; |
| 131 parser.parseUnit(tokens); | 139 parser.parseUnit(tokens); |
| 132 } | 140 } |
| 133 } | 141 } |
| 134 } | 142 } |
| 135 } | 143 } |
| 136 | 144 |
| 137 void resolveParts() { | 145 void resolveParts() { |
| 138 List<Uri> parts = <Uri>[]; | 146 List<Uri> parts = <Uri>[]; |
| 139 builders.forEach((Uri uri, LibraryBuilder library) { | 147 builders.forEach((Uri uri, LibraryBuilder library) { |
| 140 if (library is SourceLibraryBuilder) { | 148 if (library is SourceLibraryBuilder) { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 realCycles.forEach((ClassBuilder cls, Set<ClassBuilder> cycles) { | 336 realCycles.forEach((ClassBuilder cls, Set<ClassBuilder> cycles) { |
| 329 target.breakCycle(cls); | 337 target.breakCycle(cls); |
| 330 if (reported.add(cls)) { | 338 if (reported.add(cls)) { |
| 331 List<ClassBuilder> involved = <ClassBuilder>[]; | 339 List<ClassBuilder> involved = <ClassBuilder>[]; |
| 332 for (ClassBuilder cls in cycles) { | 340 for (ClassBuilder cls in cycles) { |
| 333 if (realCycles.containsKey(cls)) { | 341 if (realCycles.containsKey(cls)) { |
| 334 involved.add(cls); | 342 involved.add(cls); |
| 335 reported.add(cls); | 343 reported.add(cls); |
| 336 } | 344 } |
| 337 } | 345 } |
| 338 print("${cls.name} is a supertype of itself via " | 346 warning(cls.fileUri, cls.charOffset, "'${cls.name}' is a supertype of " |
| 339 "${involved.map((c) => c.name).join(' ')}"); | 347 "itself via '${involved.map((c) => c.name).join(' ')}'."); |
| 340 } | 348 } |
| 341 }); | 349 }); |
| 342 ticker.logMs("Found cycles"); | 350 ticker.logMs("Found cycles"); |
| 343 } | 351 } |
| 344 | 352 |
| 345 void buildProgram() { | 353 void buildProgram() { |
| 346 builders.forEach((Uri uri, LibraryBuilder library) { | 354 builders.forEach((Uri uri, LibraryBuilder library) { |
| 347 if (library is SourceLibraryBuilder) { | 355 if (library is SourceLibraryBuilder) { |
| 348 libraries.add(library.build()); | 356 libraries.add(library.build()); |
| 349 } | 357 } |
| 350 }); | 358 }); |
| 351 ticker.logMs("Built program"); | 359 ticker.logMs("Built program"); |
| 352 } | 360 } |
| 353 | 361 |
| 354 void buildElementStore() { | 362 void buildElementStore() { |
| 355 elementStore = new ElementStore(coreLibrary, builders); | 363 elementStore = new ElementStore(coreLibrary, builders); |
| 356 ticker.logMs("Built analyzer element model."); | 364 ticker.logMs("Built analyzer element model."); |
| 357 } | 365 } |
| 358 | 366 |
| 359 void computeHierarchy(Program program) { | 367 void computeHierarchy(Program program) { |
| 360 hierarchy = new ClassHierarchy(program); | 368 hierarchy = new ClassHierarchy(program); |
| 361 ticker.logMs("Computed class hierarchy"); | 369 ticker.logMs("Computed class hierarchy"); |
| 362 coreTypes = new CoreTypes(program); | 370 coreTypes = new CoreTypes(program); |
| 363 ticker.logMs("Computed core types"); | 371 ticker.logMs("Computed core types"); |
| 364 } | 372 } |
| 365 } | 373 } |
| OLD | NEW |