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

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

Issue 2045223002: Compute and cache element NativeBehavior during resolution. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Temporarily skip compilation subtest Created 4 years, 6 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) 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 js_backend.native_data; 5 library js_backend.native_data;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../elements/elements.dart' 8 import '../elements/elements.dart'
9 show ClassElement, Element, FunctionElement, MemberElement; 9 show ClassElement, Element, FieldElement, FunctionElement, MemberElement;
10 import '../native/behavior.dart' show NativeBehavior;
10 11
11 /// Additional element information for native classes and methods and js-interop 12 /// Additional element information for native classes and methods and js-interop
12 /// methods. 13 /// methods.
13 class NativeData { 14 class NativeData {
14 /// The JavaScript names for elements implemented via typed JavaScript 15 /// The JavaScript names for elements implemented via typed JavaScript
15 /// interop. 16 /// interop.
16 Map<Element, String> jsInteropNames = <Element, String>{}; 17 Map<Element, String> jsInteropNames = <Element, String>{};
17 18
18 /// The JavaScript names for native JavaScript elements implemented. 19 /// The JavaScript names for native JavaScript elements implemented.
19 Map<Element, String> nativeMemberName = <Element, String>{}; 20 Map<Element, String> nativeMemberName = <Element, String>{};
20 21
21 /// Tag info for native JavaScript classes names. See 22 /// Tag info for native JavaScript classes names. See
22 /// [setNativeClassTagInfo]. 23 /// [setNativeClassTagInfo].
23 Map<ClassElement, String> nativeClassTagInfo = <ClassElement, String>{}; 24 Map<ClassElement, String> nativeClassTagInfo = <ClassElement, String>{};
24 25
26 // TODO(johnniwinther): Serialize these.
27 /// Cache for [NativeBehavior]s for calling native methods.
28 Map<FunctionElement, NativeBehavior> nativeMethodBehavior =
29 <FunctionElement, NativeBehavior>{};
30
31 /// Cache for [NativeBehavior]s for reading from native fields.
32 Map<MemberElement, NativeBehavior> nativeFieldLoadBehavior =
33 <FieldElement, NativeBehavior>{};
34
35 /// Cache for [NativeBehavior]s for writing to native fields.
36 Map<MemberElement, NativeBehavior> nativeFieldStoreBehavior =
37 <FieldElement, NativeBehavior>{};
38
25 /// Returns `true` if [element] is explicitly marked as part of JsInterop. 39 /// Returns `true` if [element] is explicitly marked as part of JsInterop.
26 bool _isJsInterop(Element element) { 40 bool _isJsInterop(Element element) {
27 return jsInteropNames.containsKey(element.declaration); 41 return jsInteropNames.containsKey(element.declaration);
28 } 42 }
29 43
30 /// Returns [element] as an explicit part of JsInterop. The js interop name is 44 /// Returns [element] as an explicit part of JsInterop. The js interop name is
31 /// expected to be computed later. 45 /// expected to be computed later.
32 void markAsJsInterop(Element element) { 46 void markAsJsInterop(Element element) {
33 jsInteropNames[element.declaration] = null; 47 jsInteropNames[element.declaration] = null;
34 } 48 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 List<String> getNativeTagsOfClass(ClassElement cls) { 170 List<String> getNativeTagsOfClass(ClassElement cls) {
157 return getNativeTagsOfClassRaw(cls) 171 return getNativeTagsOfClassRaw(cls)
158 .where((s) => !s.startsWith('!')) 172 .where((s) => !s.startsWith('!'))
159 .toList(); 173 .toList();
160 } 174 }
161 175
162 /// Returns `true` if [cls] has a `!nonleaf` tag word. 176 /// Returns `true` if [cls] has a `!nonleaf` tag word.
163 bool hasNativeTagsForcedNonLeaf(ClassElement cls) { 177 bool hasNativeTagsForcedNonLeaf(ClassElement cls) {
164 return getNativeTagsOfClassRaw(cls).contains('!nonleaf'); 178 return getNativeTagsOfClassRaw(cls).contains('!nonleaf');
165 } 179 }
180
181 /// Returns the [NativeBehavior] for calling the native [method].
182 NativeBehavior getNativeMethodBehavior(FunctionElement method) {
183 assert(invariant(method, nativeMethodBehavior.containsKey(method),
184 message: "No native method behavior has been computed for $method."));
185 return nativeMethodBehavior[method];
186 }
187
188 /// Returns the [NativeBehavior] for reading from the native [field].
189 NativeBehavior getNativeFieldLoadBehavior(FieldElement field) {
190 assert(invariant(field, nativeFieldLoadBehavior.containsKey(field),
191 message: "No native field load behavior has been "
192 "computed for $field."));
193 return nativeFieldLoadBehavior[field];
194 }
195
196 /// Returns the [NativeBehavior] for writing to the native [field].
197 NativeBehavior getNativeFieldStoreBehavior(FieldElement field) {
198 assert(invariant(field, nativeFieldStoreBehavior.containsKey(field),
199 message: "No native field store behavior has been "
200 "computed for $field."));
201 return nativeFieldStoreBehavior[field];
202 }
203
204 /// Registers the [behavior] for calling the native [method].
205 void setNativeMethodBehavior(
206 FunctionElement method, NativeBehavior behavior) {
207 nativeMethodBehavior[method] = behavior;
208 }
209
210 /// Registers the [behavior] for reading from the native [field].
211 void setNativeFieldLoadBehavior(FieldElement field, NativeBehavior behavior) {
212 nativeFieldLoadBehavior[field] = behavior;
213 }
214
215 /// Registers the [behavior] for writing to the native [field].
216 void setNativeFieldStoreBehavior(
217 FieldElement field, NativeBehavior behavior) {
218 nativeFieldStoreBehavior[field] = behavior;
219 }
166 } 220 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/js_backend.dart ('k') | pkg/compiler/lib/src/native/behavior.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698