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

Side by Side Diff: pkg/compiler/lib/src/kernel/world_builder.dart

Issue 2841583002: Add FrontEndStrategy, ResolutionFrontEndStrategy and KernelFrontEndStrategy (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 dart2js.kernel.world_builder; 5 library dart2js.kernel.world_builder;
6 6
7 import 'package:kernel/ast.dart' as ir; 7 import 'package:kernel/ast.dart' as ir;
8 8
9 import '../common.dart'; 9 import '../common.dart';
10 import '../common/resolution.dart'; 10 import '../common/resolution.dart';
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 class KernelWorldBuilder extends KernelElementAdapterMixin { 42 class KernelWorldBuilder extends KernelElementAdapterMixin {
43 CommonElements _commonElements; 43 CommonElements _commonElements;
44 native.BehaviorBuilder _nativeBehaviorBuilder; 44 native.BehaviorBuilder _nativeBehaviorBuilder;
45 final DiagnosticReporter reporter; 45 final DiagnosticReporter reporter;
46 ElementEnvironment _elementEnvironment; 46 ElementEnvironment _elementEnvironment;
47 DartTypeConverter _typeConverter; 47 DartTypeConverter _typeConverter;
48 KernelConstantEnvironment _constantEnvironment; 48 KernelConstantEnvironment _constantEnvironment;
49 _KernelDartTypes _types; 49 _KernelDartTypes _types;
50 50
51 /// Library environment. Used for fast lookup. 51 /// Library environment. Used for fast lookup.
52 KEnv _env; 52 KEnv _env = new KEnv();
53 53
54 /// List of library environments by `KLibrary.libraryIndex`. This is used for 54 /// List of library environments by `KLibrary.libraryIndex`. This is used for
55 /// fast lookup into library classes and members. 55 /// fast lookup into library classes and members.
56 List<KLibraryEnv> _libraryEnvs = <KLibraryEnv>[]; 56 List<KLibraryEnv> _libraryEnvs = <KLibraryEnv>[];
57 57
58 /// List of class environments by `KClass.classIndex`. This is used for 58 /// List of class environments by `KClass.classIndex`. This is used for
59 /// fast lookup into class members. 59 /// fast lookup into class members.
60 List<KClassEnv> _classEnvs = <KClassEnv>[]; 60 List<KClassEnv> _classEnvs = <KClassEnv>[];
61 61
62 Map<ir.Library, KLibrary> _libraryMap = <ir.Library, KLibrary>{}; 62 Map<ir.Library, KLibrary> _libraryMap = <ir.Library, KLibrary>{};
(...skipping 11 matching lines...) Expand all
74 74
75 Map<ir.Procedure, KFunction> _methodMap = <ir.Procedure, KFunction>{}; 75 Map<ir.Procedure, KFunction> _methodMap = <ir.Procedure, KFunction>{};
76 76
77 Map<ir.Field, KField> _fieldMap = <ir.Field, KField>{}; 77 Map<ir.Field, KField> _fieldMap = <ir.Field, KField>{};
78 Map<KField, ConstantExpression> _fieldConstantMap = 78 Map<KField, ConstantExpression> _fieldConstantMap =
79 <KField, ConstantExpression>{}; 79 <KField, ConstantExpression>{};
80 80
81 Map<ir.TreeNode, KLocalFunction> _localFunctionMap = 81 Map<ir.TreeNode, KLocalFunction> _localFunctionMap =
82 <ir.TreeNode, KLocalFunction>{}; 82 <ir.TreeNode, KLocalFunction>{};
83 83
84 KernelWorldBuilder(this.reporter, ir.Program program) 84 KernelWorldBuilder(this.reporter) {
85 : _env = new KEnv(program) {
86 _elementEnvironment = new KernelElementEnvironment(this); 85 _elementEnvironment = new KernelElementEnvironment(this);
87 _commonElements = new CommonElements(_elementEnvironment); 86 _commonElements = new CommonElements(_elementEnvironment);
88 _constantEnvironment = new KernelConstantEnvironment(this); 87 _constantEnvironment = new KernelConstantEnvironment(this);
89 _nativeBehaviorBuilder = 88 _nativeBehaviorBuilder =
90 new KernelBehaviorBuilder(_commonElements, _constantEnvironment); 89 new KernelBehaviorBuilder(_commonElements, _constantEnvironment);
91 _types = new _KernelDartTypes(this); 90 _types = new _KernelDartTypes(this);
92 _typeConverter = new DartTypeConverter(this); 91 _typeConverter = new DartTypeConverter(this);
93 } 92 }
94 93
94 /// Adds libraries in [program] to the set of libraries.
95 ///
96 /// The main method of the first program is used as the main method for the
97 /// compilation.
98 void addProgram(ir.Program program) {
99 _env.addProgram(program);
100 }
101
95 KMethod get _mainFunction { 102 KMethod get _mainFunction {
96 return _env.program.mainMethod != null 103 return _env.mainMethod != null ? _getMethod(_env.mainMethod) : null;
97 ? _getMethod(_env.program.mainMethod) 104 }
105
106 KLibrary get _mainLibrary {
107 return _env.mainMethod != null
108 ? _getLibrary(_env.mainMethod.enclosingLibrary)
98 : null; 109 : null;
99 } 110 }
100 111
101 KLibrary get _mainLibrary {
102 return _env.program.mainMethod != null
103 ? _getLibrary(_env.program.mainMethod.enclosingLibrary)
104 : null;
105 }
106
107 Iterable<LibraryEntity> get _libraries { 112 Iterable<LibraryEntity> get _libraries {
108 if (_env.length != _libraryMap.length) { 113 if (_env.length != _libraryMap.length) {
109 // Create a [KLibrary] for each library. 114 // Create a [KLibrary] for each library.
110 _env.forEachLibrary((KLibraryEnv env) { 115 _env.forEachLibrary((KLibraryEnv env) {
111 _getLibrary(env.library, env); 116 _getLibrary(env.library, env);
112 }); 117 });
113 } 118 }
114 return _libraryMap.values; 119 return _libraryMap.values;
115 } 120 }
116 121
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 } 595 }
591 596
592 ResolutionImpact computeWorldImpact(KMember member) { 597 ResolutionImpact computeWorldImpact(KMember member) {
593 ir.Member node = _memberList[member.memberIndex]; 598 ir.Member node = _memberList[member.memberIndex];
594 return buildKernelImpact(node, this); 599 return buildKernelImpact(node, this);
595 } 600 }
596 } 601 }
597 602
598 /// Environment for fast lookup of program libraries. 603 /// Environment for fast lookup of program libraries.
599 class KEnv { 604 class KEnv {
600 final ir.Program program; 605 final Set<ir.Program> programs = new Set<ir.Program>();
601 606
602 Map<Uri, KLibraryEnv> _libraryMap; 607 Map<Uri, KLibraryEnv> _libraryMap;
603 608
604 KEnv(this.program); 609 /// TODO(johnniwinther): Handle arbitrary load order if needed.
610 ir.Member get mainMethod => programs.first?.mainMethod;
611
612 void addProgram(ir.Program program) {
613 if (programs.add(program)) {
614 if (_libraryMap != null) {
615 _addLibraries(program);
616 }
617 }
618 }
619
620 void _addLibraries(ir.Program program) {
621 for (ir.Library library in program.libraries) {
622 _libraryMap[library.importUri] = new KLibraryEnv(library);
623 }
624 }
605 625
606 void _ensureLibraryMap() { 626 void _ensureLibraryMap() {
607 if (_libraryMap == null) { 627 if (_libraryMap == null) {
608 _libraryMap = <Uri, KLibraryEnv>{}; 628 _libraryMap = <Uri, KLibraryEnv>{};
609 for (ir.Library library in program.libraries) { 629 for (ir.Program program in programs) {
610 _libraryMap[library.importUri] = new KLibraryEnv(library); 630 _addLibraries(program);
611 } 631 }
612 } 632 }
613 } 633 }
614 634
615 /// Return the [KLibraryEnv] for the library with the canonical [uri]. 635 /// Return the [KLibraryEnv] for the library with the canonical [uri].
616 KLibraryEnv lookupLibrary(Uri uri) { 636 KLibraryEnv lookupLibrary(Uri uri) {
617 _ensureLibraryMap(); 637 _ensureLibraryMap();
618 return _libraryMap[uri]; 638 return _libraryMap[uri];
619 } 639 }
620 640
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 } 1209 }
1190 1210
1191 InterfaceType getMixinTypeForClass(KClass cls) { 1211 InterfaceType getMixinTypeForClass(KClass cls) {
1192 KClassEnv env = builder._classEnvs[cls.classIndex]; 1212 KClassEnv env = builder._classEnvs[cls.classIndex];
1193 ir.Supertype mixedInType = env.cls.mixedInType; 1213 ir.Supertype mixedInType = env.cls.mixedInType;
1194 if (mixedInType == null) return null; 1214 if (mixedInType == null) return null;
1195 return builder.createInterfaceType( 1215 return builder.createInterfaceType(
1196 mixedInType.classNode, mixedInType.typeArguments); 1216 mixedInType.classNode, mixedInType.typeArguments);
1197 } 1217 }
1198 } 1218 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698