| 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/builder/ast_factory.dart' show AstFactory; | 13 import 'package:front_end/src/fasta/builder/ast_factory.dart' show AstFactory; |
| 14 | 14 |
| 15 import 'package:front_end/src/fasta/kernel/kernel_ast_factory.dart' | 15 import 'package:front_end/src/fasta/kernel/kernel_ast_factory.dart' |
| 16 show KernelAstFactory; | 16 show KernelAstFactory; |
| 17 | 17 |
| 18 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' | 18 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart' |
| 19 show KernelTypeInferrer; | 19 show KernelTypeInferenceEngine; |
| 20 | 20 |
| 21 import 'package:front_end/src/fasta/kernel/kernel_target.dart' | 21 import 'package:front_end/src/fasta/kernel/kernel_target.dart' |
| 22 show KernelTarget; | 22 show KernelTarget; |
| 23 | 23 |
| 24 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart' | 24 import 'package:front_end/src/fasta/type_inference/type_inference_engine.dart' |
| 25 show TypeInferrer; | 25 show TypeInferenceEngine; |
| 26 | 26 |
| 27 import 'package:kernel/ast.dart' show Program; | 27 import 'package:kernel/ast.dart' show Program; |
| 28 | 28 |
| 29 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; | 29 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; |
| 30 | 30 |
| 31 import 'package:kernel/core_types.dart' show CoreTypes; | 31 import 'package:kernel/core_types.dart' show CoreTypes; |
| 32 | 32 |
| 33 import '../builder/builder.dart' show Builder, ClassBuilder, LibraryBuilder; | 33 import '../builder/builder.dart' show Builder, ClassBuilder, LibraryBuilder; |
| 34 | 34 |
| 35 import '../compiler_context.dart' show CompilerContext; | 35 import '../compiler_context.dart' show CompilerContext; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 59 class SourceLoader<L> extends Loader<L> { | 59 class SourceLoader<L> extends Loader<L> { |
| 60 final Map<Uri, List<int>> sourceBytes = <Uri, List<int>>{}; | 60 final Map<Uri, List<int>> sourceBytes = <Uri, List<int>>{}; |
| 61 final bool excludeSource = CompilerContext.current.options.excludeSource; | 61 final bool excludeSource = CompilerContext.current.options.excludeSource; |
| 62 | 62 |
| 63 // Used when building directly to kernel. | 63 // Used when building directly to kernel. |
| 64 ClassHierarchy hierarchy; | 64 ClassHierarchy hierarchy; |
| 65 CoreTypes coreTypes; | 65 CoreTypes coreTypes; |
| 66 | 66 |
| 67 final AstFactory astFactory = new KernelAstFactory(); | 67 final AstFactory astFactory = new KernelAstFactory(); |
| 68 | 68 |
| 69 TypeInferrer topLevelTypeInferrer; | 69 TypeInferenceEngine typeInferenceEngine; |
| 70 | 70 |
| 71 Instrumentation instrumentation; | 71 Instrumentation instrumentation; |
| 72 | 72 |
| 73 SourceLoader(KernelTarget target) : super(target); | 73 SourceLoader(KernelTarget target) : super(target); |
| 74 | 74 |
| 75 Future<Token> tokenize(SourceLibraryBuilder library, | 75 Future<Token> tokenize(SourceLibraryBuilder library, |
| 76 {bool suppressLexicalErrors: false}) async { | 76 {bool suppressLexicalErrors: false}) async { |
| 77 Uri uri = library.fileUri; | 77 Uri uri = library.fileUri; |
| 78 if (uri == null || uri.scheme != "file") { | 78 if (uri == null || uri.scheme != "file") { |
| 79 return inputError(library.uri, -1, "Not found: ${library.uri}."); | 79 return inputError(library.uri, -1, "Not found: ${library.uri}."); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 listener.uri = part.fileUri; | 134 listener.uri = part.fileUri; |
| 135 parser.parseUnit(tokens); | 135 parser.parseUnit(tokens); |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 KernelTarget get target => super.target; | 141 KernelTarget get target => super.target; |
| 142 | 142 |
| 143 DietListener createDietListener(LibraryBuilder library) { | 143 DietListener createDietListener(LibraryBuilder library) { |
| 144 return new DietListener( | 144 return new DietListener(library, hierarchy, coreTypes, typeInferenceEngine); |
| 145 library, hierarchy, coreTypes, createLocalTypeInferrer()); | |
| 146 } | 145 } |
| 147 | 146 |
| 148 void resolveParts() { | 147 void resolveParts() { |
| 149 List<Uri> parts = <Uri>[]; | 148 List<Uri> parts = <Uri>[]; |
| 150 builders.forEach((Uri uri, LibraryBuilder library) { | 149 builders.forEach((Uri uri, LibraryBuilder library) { |
| 151 if (library is SourceLibraryBuilder) { | 150 if (library is SourceLibraryBuilder) { |
| 152 if (library.isPart) { | 151 if (library.isPart) { |
| 153 library.validatePart(); | 152 library.validatePart(); |
| 154 parts.add(uri); | 153 parts.add(uri); |
| 155 } else { | 154 } else { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 } | 371 } |
| 373 | 372 |
| 374 void checkOverrides(List<SourceClassBuilder> sourceClasses) { | 373 void checkOverrides(List<SourceClassBuilder> sourceClasses) { |
| 375 assert(hierarchy != null); | 374 assert(hierarchy != null); |
| 376 for (SourceClassBuilder builder in sourceClasses) { | 375 for (SourceClassBuilder builder in sourceClasses) { |
| 377 builder.checkOverrides(hierarchy); | 376 builder.checkOverrides(hierarchy); |
| 378 } | 377 } |
| 379 ticker.logMs("Checked overrides"); | 378 ticker.logMs("Checked overrides"); |
| 380 } | 379 } |
| 381 | 380 |
| 382 void createTopLevelTypeInferrer() { | 381 void createTypeInferenceEngine() { |
| 383 topLevelTypeInferrer = | 382 typeInferenceEngine = |
| 384 new KernelTypeInferrer(instrumentation, target.strongMode); | 383 new KernelTypeInferenceEngine(instrumentation, target.strongMode); |
| 385 } | 384 } |
| 386 | 385 |
| 387 /// Performs the first phase of top level initializer inference, which | 386 /// Performs the first phase of top level initializer inference, which |
| 388 /// consists of creating kernel objects for all fields and top level variables | 387 /// consists of creating kernel objects for all fields and top level variables |
| 389 /// that might be subject to type inference, and records dependencies between | 388 /// that might be subject to type inference, and records dependencies between |
| 390 /// them. | 389 /// them. |
| 391 void prepareInitializerInference() { | 390 void prepareInitializerInference() { |
| 392 topLevelTypeInferrer.coreTypes = coreTypes; | 391 typeInferenceEngine.prepareTopLevel(coreTypes, hierarchy); |
| 393 topLevelTypeInferrer.classHierarchy = hierarchy; | |
| 394 builders.forEach((Uri uri, LibraryBuilder library) { | 392 builders.forEach((Uri uri, LibraryBuilder library) { |
| 395 if (library is SourceLibraryBuilder) { | 393 if (library is SourceLibraryBuilder) { |
| 396 library.prepareInitializerInference( | 394 library.prepareInitializerInference(typeInferenceEngine, library, null); |
| 397 topLevelTypeInferrer, library, null); | |
| 398 } | 395 } |
| 399 }); | 396 }); |
| 400 ticker.logMs("Prepared initializer inference"); | 397 ticker.logMs("Prepared initializer inference"); |
| 401 } | 398 } |
| 402 | 399 |
| 403 /// Performs the second phase of top level initializer inference, which is to | 400 /// Performs the second phase of top level initializer inference, which is to |
| 404 /// visit fields and top level variables in topologically-sorted order and | 401 /// visit fields and top level variables in topologically-sorted order and |
| 405 /// assign their types. | 402 /// assign their types. |
| 406 void performInitializerInference() { | 403 void performInitializerInference() { |
| 407 topLevelTypeInferrer.performInitializerInference(); | 404 typeInferenceEngine.finishTopLevel(); |
| 408 ticker.logMs("Performed initializer inference"); | 405 ticker.logMs("Performed initializer inference"); |
| 409 } | 406 } |
| 410 | 407 |
| 411 /// Creates the type inferrer that should be used inside of method bodies. | |
| 412 TypeInferrer createLocalTypeInferrer() { | |
| 413 // For kernel, the top level and local type inferrers are the same. | |
| 414 return topLevelTypeInferrer; | |
| 415 } | |
| 416 | |
| 417 List<Uri> getDependencies() => sourceBytes.keys.toList(); | 408 List<Uri> getDependencies() => sourceBytes.keys.toList(); |
| 418 } | 409 } |
| OLD | NEW |