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

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

Issue 2855593002: Revert "Move JsInteropAnalysis.onQueueClosed to AnnotationProcessor.processJsInteropAnnotation" (Closed)
Patch Set: 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
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 '../common_elements.dart' show ElementEnvironment; 8 import '../common_elements.dart' show ElementEnvironment;
9 import '../elements/entities.dart'; 9 import '../elements/entities.dart';
10 import '../native/behavior.dart' show NativeBehavior; 10 import '../native/behavior.dart' show NativeBehavior;
(...skipping 12 matching lines...) Expand all
23 23
24 /// Returns the list of non-directive native tag words for [cls]. 24 /// Returns the list of non-directive native tag words for [cls].
25 List<String> getNativeTagsOfClass(ClassEntity cls); 25 List<String> getNativeTagsOfClass(ClassEntity cls);
26 26
27 /// Returns `true` if [cls] has a `!nonleaf` tag word. 27 /// Returns `true` if [cls] has a `!nonleaf` tag word.
28 bool hasNativeTagsForcedNonLeaf(ClassEntity cls); 28 bool hasNativeTagsForcedNonLeaf(ClassEntity cls);
29 29
30 /// Returns `true` if [element] or any of its superclasses is native. 30 /// Returns `true` if [element] or any of its superclasses is native.
31 bool isNativeOrExtendsNative(ClassEntity element); 31 bool isNativeOrExtendsNative(ClassEntity element);
32 32
33 /// Returns `true` if js interop features are used.
34 bool get isJsInteropUsed;
35
36 /// Returns `true` if [element] is a JsInterop library. 33 /// Returns `true` if [element] is a JsInterop library.
37 bool isJsInteropLibrary(LibraryEntity element); 34 bool isJsInteropLibrary(LibraryEntity element);
38 35
39 /// Returns `true` if [element] is a JsInterop class. 36 /// Returns `true` if [element] is a JsInterop class.
40 bool isJsInteropClass(ClassEntity element); 37 bool isJsInteropClass(ClassEntity element);
41 } 38 }
42 39
43 /// Additional element information for native classes and methods and js-interop 40 /// Additional element information for native classes and methods and js-interop
44 /// methods. 41 /// methods.
45 /// 42 ///
(...skipping 29 matching lines...) Expand all
75 /// For static and top-level members and constructors this is based on the 72 /// For static and top-level members and constructors this is based on the
76 /// JavaScript names for the library and/or the enclosing class. 73 /// JavaScript names for the library and/or the enclosing class.
77 String getFixedBackendMethodPath(FunctionEntity element); 74 String getFixedBackendMethodPath(FunctionEntity element);
78 75
79 /// Returns `true` if [element] is a JsInterop method. 76 /// Returns `true` if [element] is a JsInterop method.
80 bool isJsInteropMember(MemberEntity element); 77 bool isJsInteropMember(MemberEntity element);
81 78
82 /// Returns the explicit js interop name for library [element]. 79 /// Returns the explicit js interop name for library [element].
83 String getJsInteropLibraryName(LibraryEntity element); 80 String getJsInteropLibraryName(LibraryEntity element);
84 81
85 /// Returns `true` if [element] has an `@Anonymous` annotation.
86 bool isAnonymousJsInteropClass(ClassEntity element);
87
88 /// Returns the explicit js interop name for class [element]. 82 /// Returns the explicit js interop name for class [element].
89 String getJsInteropClassName(ClassEntity element); 83 String getJsInteropClassName(ClassEntity element);
90 84
91 /// Returns the explicit js interop name for member [element]. 85 /// Returns the explicit js interop name for member [element].
92 String getJsInteropMemberName(MemberEntity element); 86 String getJsInteropMemberName(MemberEntity element);
93 87
94 /// Apply JS$ escaping scheme to convert possible escaped Dart names into 88 /// Apply JS$ escaping scheme to convert possible escaped Dart names into
95 /// JS names. 89 /// JS names.
96 String computeUnescapedJSInteropName(String name); 90 String computeUnescapedJSInteropName(String name);
97 } 91 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 /// expected to be computed later. 125 /// expected to be computed later.
132 void markAsJsInteropMember(MemberEntity element); 126 void markAsJsInteropMember(MemberEntity element);
133 127
134 /// Sets the native [name] for the member [element]. This name is used for 128 /// Sets the native [name] for the member [element]. This name is used for
135 /// [element] in the generated JavaScript. 129 /// [element] in the generated JavaScript.
136 void setNativeMemberName(MemberEntity element, String name); 130 void setNativeMemberName(MemberEntity element, String name);
137 131
138 /// Sets the explicit js interop [name] for the library [element]. 132 /// Sets the explicit js interop [name] for the library [element].
139 void setJsInteropLibraryName(LibraryEntity element, String name); 133 void setJsInteropLibraryName(LibraryEntity element, String name);
140 134
141 /// Marks [element] as having an `@Anonymous` annotation.
142 void markJsInteropClassAsAnonymous(ClassEntity element);
143
144 /// Sets the explicit js interop [name] for the class [element]. 135 /// Sets the explicit js interop [name] for the class [element].
145 void setJsInteropClassName(ClassEntity element, String name); 136 void setJsInteropClassName(ClassEntity element, String name);
146 137
147 /// Sets the explicit js interop [name] for the member [element]. 138 /// Sets the explicit js interop [name] for the member [element].
148 void setJsInteropMemberName(MemberEntity element, String name); 139 void setJsInteropMemberName(MemberEntity element, String name);
149 } 140 }
150 141
151 class NativeBasicDataBuilderImpl implements NativeBasicDataBuilder { 142 class NativeBasicDataBuilderImpl implements NativeBasicDataBuilder {
152 /// Tag info for native JavaScript classes names. See 143 /// Tag info for native JavaScript classes names. See
153 /// [setNativeClassTagInfo]. 144 /// [setNativeClassTagInfo].
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 /// Returns the list of non-directive native tag words for [cls]. 212 /// Returns the list of non-directive native tag words for [cls].
222 List<String> getNativeTagsOfClass(ClassEntity cls) { 213 List<String> getNativeTagsOfClass(ClassEntity cls) {
223 return nativeClassTagInfo[cls].names; 214 return nativeClassTagInfo[cls].names;
224 } 215 }
225 216
226 /// Returns `true` if [cls] has a `!nonleaf` tag word. 217 /// Returns `true` if [cls] has a `!nonleaf` tag word.
227 bool hasNativeTagsForcedNonLeaf(ClassEntity cls) { 218 bool hasNativeTagsForcedNonLeaf(ClassEntity cls) {
228 return nativeClassTagInfo[cls].isNonLeaf; 219 return nativeClassTagInfo[cls].isNonLeaf;
229 } 220 }
230 221
231 bool get isJsInteropUsed =>
232 jsInteropLibraries.isNotEmpty || jsInteropClasses.isNotEmpty;
233
234 /// Returns `true` if [element] is explicitly marked as part of JsInterop. 222 /// Returns `true` if [element] is explicitly marked as part of JsInterop.
235 bool isJsInteropLibrary(LibraryEntity element) { 223 bool isJsInteropLibrary(LibraryEntity element) {
236 return jsInteropLibraries.contains(element); 224 return jsInteropLibraries.contains(element);
237 } 225 }
238 226
239 /// Returns `true` if [element] is explicitly marked as part of JsInterop. 227 /// Returns `true` if [element] is explicitly marked as part of JsInterop.
240 bool isJsInteropClass(ClassEntity element) { 228 bool isJsInteropClass(ClassEntity element) {
241 return jsInteropClasses.contains(element); 229 return jsInteropClasses.contains(element);
242 } 230 }
243 231
(...skipping 25 matching lines...) Expand all
269 Map<MemberEntity, NativeBehavior> nativeFieldLoadBehavior = 257 Map<MemberEntity, NativeBehavior> nativeFieldLoadBehavior =
270 <FieldEntity, NativeBehavior>{}; 258 <FieldEntity, NativeBehavior>{};
271 259
272 /// Cache for [NativeBehavior]s for writing to native fields. 260 /// Cache for [NativeBehavior]s for writing to native fields.
273 Map<MemberEntity, NativeBehavior> nativeFieldStoreBehavior = 261 Map<MemberEntity, NativeBehavior> nativeFieldStoreBehavior =
274 <FieldEntity, NativeBehavior>{}; 262 <FieldEntity, NativeBehavior>{};
275 263
276 /// The JavaScript names for elements implemented via typed JavaScript 264 /// The JavaScript names for elements implemented via typed JavaScript
277 /// interop. 265 /// interop.
278 Map<LibraryEntity, String> jsInteropLibraryNames = <LibraryEntity, String>{}; 266 Map<LibraryEntity, String> jsInteropLibraryNames = <LibraryEntity, String>{};
279 Set<ClassEntity> anonymousJsInteropClasses = new Set<ClassEntity>();
280 Map<ClassEntity, String> jsInteropClassNames = <ClassEntity, String>{}; 267 Map<ClassEntity, String> jsInteropClassNames = <ClassEntity, String>{};
281 268
282 /// The JavaScript names for elements implemented via typed JavaScript 269 /// The JavaScript names for elements implemented via typed JavaScript
283 /// interop. 270 /// interop.
284 Map<MemberEntity, String> jsInteropMemberNames = <MemberEntity, String>{}; 271 Map<MemberEntity, String> jsInteropMemberNames = <MemberEntity, String>{};
285 272
286 NativeDataImpl(this._nativeBasicData); 273 NativeDataImpl(this._nativeBasicData);
287 274
288 /// Sets the native [name] for the member [element]. This name is used for 275 /// Sets the native [name] for the member [element]. This name is used for
289 /// [element] in the generated JavaScript. 276 /// [element] in the generated JavaScript.
(...skipping 25 matching lines...) Expand all
315 } 302 }
316 303
317 /// Sets the explicit js interop [name] for the library [element]. 304 /// Sets the explicit js interop [name] for the library [element].
318 void setJsInteropLibraryName(LibraryEntity element, String name) { 305 void setJsInteropLibraryName(LibraryEntity element, String name) {
319 assert(invariant(element, _nativeBasicData.isJsInteropLibrary(element), 306 assert(invariant(element, _nativeBasicData.isJsInteropLibrary(element),
320 message: 307 message:
321 'Library $element is not js interop but given a js interop name.')); 308 'Library $element is not js interop but given a js interop name.'));
322 jsInteropLibraryNames[element] = name; 309 jsInteropLibraryNames[element] = name;
323 } 310 }
324 311
325 @override
326 bool isAnonymousJsInteropClass(ClassEntity element) {
327 return anonymousJsInteropClasses.contains(element);
328 }
329
330 @override
331 void markJsInteropClassAsAnonymous(ClassEntity element) {
332 anonymousJsInteropClasses.add(element);
333 }
334
335 /// Sets the explicit js interop [name] for the class [element]. 312 /// Sets the explicit js interop [name] for the class [element].
336 void setJsInteropClassName(ClassEntity element, String name) { 313 void setJsInteropClassName(ClassEntity element, String name) {
337 assert(invariant(element, _nativeBasicData.isJsInteropClass(element), 314 assert(invariant(element, _nativeBasicData.isJsInteropClass(element),
338 message: 315 message:
339 'Class $element is not js interop but given a js interop name.')); 316 'Class $element is not js interop but given a js interop name.'));
340 jsInteropClassNames[element] = name; 317 jsInteropClassNames[element] = name;
341 } 318 }
342 319
343 @override 320 @override
344 void markAsJsInteropMember(MemberEntity element) { 321 void markAsJsInteropMember(MemberEntity element) {
(...skipping 18 matching lines...) Expand all
363 _nativeBasicData.isNativeClass(element); 340 _nativeBasicData.isNativeClass(element);
364 341
365 /// Returns the list of non-directive native tag words for [cls]. 342 /// Returns the list of non-directive native tag words for [cls].
366 List<String> getNativeTagsOfClass(ClassEntity cls) => 343 List<String> getNativeTagsOfClass(ClassEntity cls) =>
367 _nativeBasicData.getNativeTagsOfClass(cls); 344 _nativeBasicData.getNativeTagsOfClass(cls);
368 345
369 /// Returns `true` if [cls] has a `!nonleaf` tag word. 346 /// Returns `true` if [cls] has a `!nonleaf` tag word.
370 bool hasNativeTagsForcedNonLeaf(ClassEntity cls) => 347 bool hasNativeTagsForcedNonLeaf(ClassEntity cls) =>
371 _nativeBasicData.hasNativeTagsForcedNonLeaf(cls); 348 _nativeBasicData.hasNativeTagsForcedNonLeaf(cls);
372 349
373 bool get isJsInteropUsed => _nativeBasicData.isJsInteropUsed;
374
375 /// Returns `true` if [element] is a JsInterop library. 350 /// Returns `true` if [element] is a JsInterop library.
376 bool isJsInteropLibrary(LibraryEntity element) => 351 bool isJsInteropLibrary(LibraryEntity element) =>
377 _nativeBasicData.isJsInteropLibrary(element); 352 _nativeBasicData.isJsInteropLibrary(element);
378 353
379 /// Returns `true` if [element] is a JsInterop class. 354 /// Returns `true` if [element] is a JsInterop class.
380 bool isJsInteropClass(ClassEntity element) => 355 bool isJsInteropClass(ClassEntity element) =>
381 _nativeBasicData.isJsInteropClass(element); 356 _nativeBasicData.isJsInteropClass(element);
382 357
383 /// Returns `true` if [element] or any of its superclasses is native. 358 /// Returns `true` if [element] or any of its superclasses is native.
384 bool isNativeOrExtendsNative(ClassEntity element) => 359 bool isNativeOrExtendsNative(ClassEntity element) =>
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 int get hashCode => Hashing.listHash(names, isNonLeaf.hashCode); 533 int get hashCode => Hashing.listHash(names, isNonLeaf.hashCode);
559 534
560 bool operator ==(other) { 535 bool operator ==(other) {
561 if (identical(this, other)) return true; 536 if (identical(this, other)) return true;
562 if (other is! NativeClassTag) return false; 537 if (other is! NativeClassTag) return false;
563 return equalElements(names, other.names) && isNonLeaf == other.isNonLeaf; 538 return equalElements(names, other.names) && isNonLeaf == other.isNonLeaf;
564 } 539 }
565 540
566 String toString() => text; 541 String toString() => text;
567 } 542 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698