Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(794)

Unified Diff: pkg/compiler/lib/src/kernel/world_builder.dart

Issue 2841583002: Add FrontEndStrategy, ResolutionFrontEndStrategy and KernelFrontEndStrategy (Closed)
Patch Set: Updated cf. comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/kernel/kernel_strategy.dart ('k') | pkg/compiler/lib/src/library_loader.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/kernel/world_builder.dart
diff --git a/pkg/compiler/lib/src/kernel/world_builder.dart b/pkg/compiler/lib/src/kernel/world_builder.dart
index 519b33f585de80d48e628fdd505ccba91faa1500..beeb5c9580a8a224b45d8fcbaaacb7507ad5a04b 100644
--- a/pkg/compiler/lib/src/kernel/world_builder.dart
+++ b/pkg/compiler/lib/src/kernel/world_builder.dart
@@ -18,6 +18,7 @@ import '../common_elements.dart';
import '../elements/elements.dart';
import '../elements/entities.dart';
import '../elements/types.dart';
+import '../frontend_strategy.dart';
import '../js_backend/constant_system_javascript.dart';
import '../js_backend/native_data.dart';
import '../js_backend/no_such_method_registry.dart';
@@ -49,7 +50,7 @@ class KernelWorldBuilder extends KernelElementAdapterMixin {
_KernelDartTypes _types;
/// Library environment. Used for fast lookup.
- KEnv _env;
+ KEnv _env = new KEnv();
/// List of library environments by `KLibrary.libraryIndex`. This is used for
/// fast lookup into library classes and members.
@@ -81,8 +82,7 @@ class KernelWorldBuilder extends KernelElementAdapterMixin {
Map<ir.TreeNode, KLocalFunction> _localFunctionMap =
<ir.TreeNode, KLocalFunction>{};
- KernelWorldBuilder(this.reporter, ir.Program program)
- : _env = new KEnv(program) {
+ KernelWorldBuilder(this.reporter) {
_elementEnvironment = new KernelElementEnvironment(this);
_commonElements = new CommonElements(_elementEnvironment);
_constantEnvironment = new KernelConstantEnvironment(this);
@@ -92,15 +92,21 @@ class KernelWorldBuilder extends KernelElementAdapterMixin {
_typeConverter = new DartTypeConverter(this);
}
+ /// Adds libraries in [program] to the set of libraries.
+ ///
+ /// The main method of the first program is used as the main method for the
+ /// compilation.
+ void addProgram(ir.Program program) {
+ _env.addProgram(program);
+ }
+
KMethod get _mainFunction {
- return _env.program.mainMethod != null
- ? _getMethod(_env.program.mainMethod)
- : null;
+ return _env.mainMethod != null ? _getMethod(_env.mainMethod) : null;
}
KLibrary get _mainLibrary {
- return _env.program.mainMethod != null
- ? _getLibrary(_env.program.mainMethod.enclosingLibrary)
+ return _env.mainMethod != null
+ ? _getLibrary(_env.mainMethod.enclosingLibrary)
: null;
}
@@ -597,17 +603,32 @@ class KernelWorldBuilder extends KernelElementAdapterMixin {
/// Environment for fast lookup of program libraries.
class KEnv {
- final ir.Program program;
+ final Set<ir.Program> programs = new Set<ir.Program>();
Map<Uri, KLibraryEnv> _libraryMap;
- KEnv(this.program);
+ /// TODO(johnniwinther): Handle arbitrary load order if needed.
+ ir.Member get mainMethod => programs.first?.mainMethod;
+
+ void addProgram(ir.Program program) {
+ if (programs.add(program)) {
+ if (_libraryMap != null) {
+ _addLibraries(program);
+ }
+ }
+ }
+
+ void _addLibraries(ir.Program program) {
+ for (ir.Library library in program.libraries) {
+ _libraryMap[library.importUri] = new KLibraryEnv(library);
+ }
+ }
void _ensureLibraryMap() {
if (_libraryMap == null) {
_libraryMap = <Uri, KLibraryEnv>{};
- for (ir.Library library in program.libraries) {
- _libraryMap[library.importUri] = new KLibraryEnv(library);
+ for (ir.Program program in programs) {
+ _addLibraries(program);
}
}
}
« no previous file with comments | « pkg/compiler/lib/src/kernel/kernel_strategy.dart ('k') | pkg/compiler/lib/src/library_loader.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698