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

Side by Side Diff: pkg/compiler/lib/src/js_backend/element_strategy.dart

Issue 2894893002: Add ElementCodegenWorldBuilder (Closed)
Patch Set: Updated cf. comments. Created 3 years, 7 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library dart2js.js_backend.element_strategy;
6
7 import '../backend_strategy.dart';
8 import '../common.dart';
9 import '../common/codegen.dart';
10 import '../common/work.dart';
11 import '../compiler.dart';
12 import '../elements/elements.dart';
13 import '../enqueue.dart';
14 import '../js_backend/backend.dart';
15 import '../js_backend/native_data.dart';
16 import '../js_emitter/sorter.dart';
17 import '../options.dart';
18 import '../universe/world_builder.dart';
19 import '../universe/world_impact.dart';
20 import '../world.dart';
21
22 /// Strategy for using the [Element] model from the resolver as the backend
23 /// model.
24 class ElementBackendStrategy implements BackendStrategy {
25 final Compiler _compiler;
26
27 ElementBackendStrategy(this._compiler);
28
29 ClosedWorldRefiner createClosedWorldRefiner(ClosedWorldImpl closedWorld) =>
30 closedWorld;
31
32 Sorter get sorter => const ElementSorter();
33
34 void convertClosures(ClosedWorldRefiner closedWorldRefiner) {
35 _compiler.closureToClassMapper.createClosureClasses(closedWorldRefiner);
36 }
37
38 @override
39 CodegenWorldBuilder createCodegenWorldBuilder(
40 NativeBasicData nativeBasicData,
41 ClosedWorld closedWorld,
42 SelectorConstraintsStrategy selectorConstraintsStrategy) {
43 return new ElementCodegenWorldBuilderImpl(
44 _compiler.elementEnvironment,
45 nativeBasicData,
46 closedWorld,
47 _compiler.backend.constants,
48 selectorConstraintsStrategy);
49 }
50
51 @override
52 WorkItemBuilder createCodegenWorkItemBuilder(ClosedWorld closedWorld) {
53 return new ElementCodegenWorkItemBuilder(
54 _compiler.backend, closedWorld, _compiler.options);
55 }
56 }
57
58 /// Builder that creates the work item necessary for the code generation of a
59 /// [MemberElement].
60 class ElementCodegenWorkItemBuilder extends WorkItemBuilder {
61 final JavaScriptBackend _backend;
62 final ClosedWorld _closedWorld;
63 final CompilerOptions _options;
64
65 ElementCodegenWorkItemBuilder(
66 this._backend, this._closedWorld, this._options);
67
68 @override
69 WorkItem createWorkItem(MemberElement element) {
70 assert(invariant(element, element.isDeclaration));
71 // Don't generate code for foreign elements.
72 if (_backend.isForeign(element)) return null;
73 if (element.isAbstract) return null;
74
75 // Codegen inlines field initializers. It only needs to generate
76 // code for checked setters.
77 if (element.isField && element.isInstanceMember) {
78 if (!_options.enableTypeAssertions ||
79 element.enclosingElement.isClosure) {
80 return null;
81 }
82 }
83 return new ElementCodegenWorkItem(_backend, _closedWorld, element);
84 }
85 }
86
87 class ElementCodegenWorkItem extends CodegenWorkItem {
88 CodegenRegistry registry;
89 final ResolvedAst resolvedAst;
90 final JavaScriptBackend _backend;
91 final ClosedWorld _closedWorld;
92
93 factory ElementCodegenWorkItem(JavaScriptBackend backend,
94 ClosedWorld closedWorld, MemberElement element) {
95 // If this assertion fails, the resolution callbacks of the backend may be
96 // missing call of form registry.registerXXX. Alternatively, the code
97 // generation could spuriously be adding dependencies on things we know we
98 // don't need.
99 assert(invariant(element, element.hasResolvedAst,
100 message: "$element has no resolved ast."));
101 ResolvedAst resolvedAst = element.resolvedAst;
102 return new ElementCodegenWorkItem.internal(
103 resolvedAst, backend, closedWorld);
104 }
105
106 ElementCodegenWorkItem.internal(
107 this.resolvedAst, this._backend, this._closedWorld);
108
109 MemberElement get element => resolvedAst.element;
110
111 WorldImpact run() {
112 registry = new CodegenRegistry(element);
113 return _backend.codegen(this, _closedWorld);
114 }
115
116 String toString() => 'CodegenWorkItem(${resolvedAst.element})';
117 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/codegen_listener.dart ('k') | pkg/compiler/lib/src/js_backend/enqueuer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698