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

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

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

Powered by Google App Engine
This is Rietveld 408576698