| 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 Future; | 7 import 'dart:async' show Future; |
| 8 | 8 |
| 9 import 'dart:typed_data' show Uint8List; | 9 import 'dart:typed_data' show Uint8List; |
| 10 | 10 |
| 11 import 'package:front_end/src/base/instrumentation.dart' show Instrumentation; | 11 import 'package:front_end/src/base/instrumentation.dart' show Instrumentation; |
| 12 | 12 |
| 13 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' | 13 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' |
| 14 show KernelTypeInferrer; | 14 show KernelTypeInferrer; |
| 15 | 15 |
| 16 import 'package:front_end/src/fasta/kernel/kernel_target.dart' |
| 17 show KernelTarget; |
| 18 |
| 16 import 'package:kernel/ast.dart' show Program; | 19 import 'package:kernel/ast.dart' show Program; |
| 17 | 20 |
| 18 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; | 21 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; |
| 19 | 22 |
| 20 import 'package:kernel/core_types.dart' show CoreTypes; | 23 import 'package:kernel/core_types.dart' show CoreTypes; |
| 21 | 24 |
| 22 import '../builder/builder.dart' show Builder, ClassBuilder, LibraryBuilder; | 25 import '../builder/builder.dart' show Builder, ClassBuilder, LibraryBuilder; |
| 23 | 26 |
| 24 import '../compiler_context.dart' show CompilerContext; | 27 import '../compiler_context.dart' show CompilerContext; |
| 25 | 28 |
| 26 import '../errors.dart' show inputError; | 29 import '../errors.dart' show inputError; |
| 27 | 30 |
| 28 import '../export.dart' show Export; | 31 import '../export.dart' show Export; |
| 29 | 32 |
| 30 import '../loader.dart' show Loader; | 33 import '../loader.dart' show Loader; |
| 31 | 34 |
| 32 import '../parser/class_member_parser.dart' show ClassMemberParser; | 35 import '../parser/class_member_parser.dart' show ClassMemberParser; |
| 33 | 36 |
| 34 import '../scanner.dart' show ErrorToken, ScannerResult, Token, scan; | 37 import '../scanner.dart' show ErrorToken, ScannerResult, Token, scan; |
| 35 | 38 |
| 36 import '../io.dart' show readBytesFromFile; | 39 import '../io.dart' show readBytesFromFile; |
| 37 | 40 |
| 38 import '../target_implementation.dart' show TargetImplementation; | |
| 39 | |
| 40 import 'diet_listener.dart' show DietListener; | 41 import 'diet_listener.dart' show DietListener; |
| 41 | 42 |
| 42 import 'diet_parser.dart' show DietParser; | 43 import 'diet_parser.dart' show DietParser; |
| 43 | 44 |
| 44 import 'outline_builder.dart' show OutlineBuilder; | 45 import 'outline_builder.dart' show OutlineBuilder; |
| 45 | 46 |
| 46 import 'source_class_builder.dart' show SourceClassBuilder; | 47 import 'source_class_builder.dart' show SourceClassBuilder; |
| 47 | 48 |
| 48 import 'source_library_builder.dart' show SourceLibraryBuilder; | 49 import 'source_library_builder.dart' show SourceLibraryBuilder; |
| 49 | 50 |
| 50 class SourceLoader<L> extends Loader<L> { | 51 class SourceLoader<L> extends Loader<L> { |
| 51 final Map<Uri, List<int>> sourceBytes = <Uri, List<int>>{}; | 52 final Map<Uri, List<int>> sourceBytes = <Uri, List<int>>{}; |
| 52 final bool excludeSource = CompilerContext.current.options.excludeSource; | 53 final bool excludeSource = CompilerContext.current.options.excludeSource; |
| 53 | 54 |
| 54 // Used when building directly to kernel. | 55 // Used when building directly to kernel. |
| 55 ClassHierarchy hierarchy; | 56 ClassHierarchy hierarchy; |
| 56 CoreTypes coreTypes; | 57 CoreTypes coreTypes; |
| 57 | 58 |
| 58 Instrumentation instrumentation; | 59 Instrumentation instrumentation; |
| 59 | 60 |
| 60 SourceLoader(TargetImplementation target) : super(target); | 61 SourceLoader(KernelTarget target) : super(target); |
| 61 | 62 |
| 62 Future<Token> tokenize(SourceLibraryBuilder library, | 63 Future<Token> tokenize(SourceLibraryBuilder library, |
| 63 {bool suppressLexicalErrors: false}) async { | 64 {bool suppressLexicalErrors: false}) async { |
| 64 Uri uri = library.fileUri; | 65 Uri uri = library.fileUri; |
| 65 if (uri == null || uri.scheme != "file") { | 66 if (uri == null || uri.scheme != "file") { |
| 66 return inputError(library.uri, -1, "Not found: ${library.uri}."); | 67 return inputError(library.uri, -1, "Not found: ${library.uri}."); |
| 67 } | 68 } |
| 68 List<int> bytes = sourceBytes[uri]; | 69 List<int> bytes = sourceBytes[uri]; |
| 69 if (bytes == null) { | 70 if (bytes == null) { |
| 70 bytes = sourceBytes[uri] = await readBytesFromFile(uri); | 71 bytes = sourceBytes[uri] = await readBytesFromFile(uri); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 for (SourceLibraryBuilder part in library.parts) { | 119 for (SourceLibraryBuilder part in library.parts) { |
| 119 Token tokens = await tokenize(part); | 120 Token tokens = await tokenize(part); |
| 120 if (tokens != null) { | 121 if (tokens != null) { |
| 121 listener.uri = part.fileUri; | 122 listener.uri = part.fileUri; |
| 122 parser.parseUnit(tokens); | 123 parser.parseUnit(tokens); |
| 123 } | 124 } |
| 124 } | 125 } |
| 125 } | 126 } |
| 126 } | 127 } |
| 127 | 128 |
| 129 KernelTarget get target => super.target; |
| 130 |
| 128 DietListener createDietListener(LibraryBuilder library) { | 131 DietListener createDietListener(LibraryBuilder library) { |
| 129 return new DietListener(library, hierarchy, coreTypes, | 132 var typeInferrer = target.strongMode |
| 130 new KernelTypeInferrer(coreTypes, hierarchy, instrumentation)); | 133 ? new KernelTypeInferrer(coreTypes, hierarchy, instrumentation) |
| 134 : null; |
| 135 return new DietListener(library, hierarchy, coreTypes, typeInferrer); |
| 131 } | 136 } |
| 132 | 137 |
| 133 void resolveParts() { | 138 void resolveParts() { |
| 134 List<Uri> parts = <Uri>[]; | 139 List<Uri> parts = <Uri>[]; |
| 135 builders.forEach((Uri uri, LibraryBuilder library) { | 140 builders.forEach((Uri uri, LibraryBuilder library) { |
| 136 if (library is SourceLibraryBuilder) { | 141 if (library is SourceLibraryBuilder) { |
| 137 if (library.isPart) { | 142 if (library.isPart) { |
| 138 library.validatePart(); | 143 library.validatePart(); |
| 139 parts.add(uri); | 144 parts.add(uri); |
| 140 } else { | 145 } else { |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 void checkOverrides(List<SourceClassBuilder> sourceClasses) { | 364 void checkOverrides(List<SourceClassBuilder> sourceClasses) { |
| 360 assert(hierarchy != null); | 365 assert(hierarchy != null); |
| 361 for (SourceClassBuilder builder in sourceClasses) { | 366 for (SourceClassBuilder builder in sourceClasses) { |
| 362 builder.checkOverrides(hierarchy); | 367 builder.checkOverrides(hierarchy); |
| 363 } | 368 } |
| 364 ticker.logMs("Checked overrides"); | 369 ticker.logMs("Checked overrides"); |
| 365 } | 370 } |
| 366 | 371 |
| 367 List<Uri> getDependencies() => sourceBytes.keys.toList(); | 372 List<Uri> getDependencies() => sourceBytes.keys.toList(); |
| 368 } | 373 } |
| OLD | NEW |