OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of js_backend; | 5 part of js_backend; |
6 | 6 |
7 class JavaScriptItemCompilationContext extends ItemCompilationContext { | 7 class JavaScriptItemCompilationContext extends ItemCompilationContext { |
8 final Set<HInstruction> boundsChecked; | 8 final Set<HInstruction> boundsChecked; |
9 | 9 |
10 JavaScriptItemCompilationContext() | 10 JavaScriptItemCompilationContext() |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 Element jsStringToString; | 194 Element jsStringToString; |
195 Element objectEquals; | 195 Element objectEquals; |
196 | 196 |
197 ClassElement typeLiteralClass; | 197 ClassElement typeLiteralClass; |
198 ClassElement mapLiteralClass; | 198 ClassElement mapLiteralClass; |
199 ClassElement constMapLiteralClass; | 199 ClassElement constMapLiteralClass; |
200 | 200 |
201 Element getInterceptorMethod; | 201 Element getInterceptorMethod; |
202 Element interceptedNames; | 202 Element interceptedNames; |
203 | 203 |
| 204 /** |
| 205 * This element is a top-level variable (in generated output) that the |
| 206 * compiler initializes to a datastructure used to map from a Type to the |
| 207 * interceptor. See declaration of `mapTypeToInterceptor` in |
| 208 * `interceptors.dart`. |
| 209 */ |
| 210 Element mapTypeToInterceptor; |
| 211 |
204 HType stringType; | 212 HType stringType; |
205 HType indexablePrimitiveType; | 213 HType indexablePrimitiveType; |
206 HType readableArrayType; | 214 HType readableArrayType; |
207 HType mutableArrayType; | 215 HType mutableArrayType; |
208 HType fixedArrayType; | 216 HType fixedArrayType; |
209 HType extendableArrayType; | 217 HType extendableArrayType; |
210 | 218 |
211 // TODO(9577): Make it so that these are not needed when there are no native | 219 // TODO(9577): Make it so that these are not needed when there are no native |
212 // classes. | 220 // classes. |
213 Element dispatchPropertyName; | 221 Element dispatchPropertyName; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 } | 357 } |
350 | 358 |
351 static Namer determineNamer(Compiler compiler) { | 359 static Namer determineNamer(Compiler compiler) { |
352 return compiler.enableMinification ? | 360 return compiler.enableMinification ? |
353 new MinifyNamer(compiler) : | 361 new MinifyNamer(compiler) : |
354 new Namer(compiler); | 362 new Namer(compiler); |
355 } | 363 } |
356 | 364 |
357 bool isInterceptorClass(ClassElement element) { | 365 bool isInterceptorClass(ClassElement element) { |
358 if (element == null) return false; | 366 if (element == null) return false; |
359 if (element.isNative()) return true; | 367 if (Elements.isNativeOrExtendsNative(element)) return true; |
360 if (interceptedClasses.contains(element)) return true; | 368 if (interceptedClasses.contains(element)) return true; |
361 if (classesMixedIntoNativeClasses.contains(element)) return true; | 369 if (classesMixedIntoNativeClasses.contains(element)) return true; |
362 return false; | 370 return false; |
363 } | 371 } |
364 | 372 |
365 String registerOneShotInterceptor(Selector selector) { | 373 String registerOneShotInterceptor(Selector selector) { |
366 Set<ClassElement> classes = getInterceptedClassesOn(selector.name); | 374 Set<ClassElement> classes = getInterceptedClassesOn(selector.name); |
367 String name = namer.getOneShotInterceptorName(selector, classes); | 375 String name = namer.getOneShotInterceptorName(selector, classes); |
368 if (!oneShotInterceptors.containsKey(name)) { | 376 if (!oneShotInterceptors.containsKey(name)) { |
369 registerSpecializedGetInterceptor(classes); | 377 registerSpecializedGetInterceptor(classes); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 */ | 413 */ |
406 Set<ClassElement> getInterceptedClassesOn(SourceString name) { | 414 Set<ClassElement> getInterceptedClassesOn(SourceString name) { |
407 Set<Element> intercepted = interceptedElements[name]; | 415 Set<Element> intercepted = interceptedElements[name]; |
408 if (intercepted == null) return null; | 416 if (intercepted == null) return null; |
409 return interceptedClassesCache.putIfAbsent(name, () { | 417 return interceptedClassesCache.putIfAbsent(name, () { |
410 // Populate the cache by running through all the elements and | 418 // Populate the cache by running through all the elements and |
411 // determine if the given selector applies to them. | 419 // determine if the given selector applies to them. |
412 Set<ClassElement> result = new Set<ClassElement>(); | 420 Set<ClassElement> result = new Set<ClassElement>(); |
413 for (Element element in intercepted) { | 421 for (Element element in intercepted) { |
414 ClassElement classElement = element.getEnclosingClass(); | 422 ClassElement classElement = element.getEnclosingClass(); |
415 if (classElement.isNative() | 423 if (Elements.isNativeOrExtendsNative(classElement) |
416 || interceptedClasses.contains(classElement)) { | 424 || interceptedClasses.contains(classElement)) { |
417 result.add(classElement); | 425 result.add(classElement); |
418 } | 426 } |
419 if (classesMixedIntoNativeClasses.contains(classElement)) { | 427 if (classesMixedIntoNativeClasses.contains(classElement)) { |
420 Set<ClassElement> nativeSubclasses = | 428 Set<ClassElement> nativeSubclasses = |
421 nativeSubclassesOfMixin(classElement); | 429 nativeSubclassesOfMixin(classElement); |
422 if (nativeSubclasses != null) result.addAll(nativeSubclasses); | 430 if (nativeSubclasses != null) result.addAll(nativeSubclasses); |
423 } | 431 } |
424 } | 432 } |
425 return result; | 433 return result; |
(...skipping 21 matching lines...) Expand all Loading... |
447 bool operatorEqHandlesNullArgument(FunctionElement operatorEqfunction) { | 455 bool operatorEqHandlesNullArgument(FunctionElement operatorEqfunction) { |
448 return specialOperatorEqClasses.contains( | 456 return specialOperatorEqClasses.contains( |
449 operatorEqfunction.getEnclosingClass()); | 457 operatorEqfunction.getEnclosingClass()); |
450 } | 458 } |
451 | 459 |
452 void initializeHelperClasses() { | 460 void initializeHelperClasses() { |
453 getInterceptorMethod = | 461 getInterceptorMethod = |
454 compiler.findInterceptor(const SourceString('getInterceptor')); | 462 compiler.findInterceptor(const SourceString('getInterceptor')); |
455 interceptedNames = | 463 interceptedNames = |
456 compiler.findInterceptor(const SourceString('interceptedNames')); | 464 compiler.findInterceptor(const SourceString('interceptedNames')); |
| 465 mapTypeToInterceptor = |
| 466 compiler.findInterceptor(const SourceString('mapTypeToInterceptor')); |
457 dispatchPropertyName = | 467 dispatchPropertyName = |
458 compiler.findInterceptor(const SourceString('dispatchPropertyName')); | 468 compiler.findInterceptor(const SourceString('dispatchPropertyName')); |
459 getDispatchPropertyMethod = | 469 getDispatchPropertyMethod = |
460 compiler.findInterceptor(const SourceString('getDispatchProperty')); | 470 compiler.findInterceptor(const SourceString('getDispatchProperty')); |
461 setDispatchPropertyMethod = | 471 setDispatchPropertyMethod = |
462 compiler.findInterceptor(const SourceString('setDispatchProperty')); | 472 compiler.findInterceptor(const SourceString('setDispatchProperty')); |
463 getNativeInterceptorMethod = | 473 getNativeInterceptorMethod = |
464 compiler.findInterceptor(const SourceString('getNativeInterceptor')); | 474 compiler.findInterceptor(const SourceString('getNativeInterceptor')); |
465 initializeDispatchPropertyMethod = | 475 initializeDispatchPropertyMethod = |
466 compiler.findInterceptor( | 476 compiler.findInterceptor( |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 if (enqueuer.isResolutionQueue) { | 597 if (enqueuer.isResolutionQueue) { |
588 cls.ensureResolved(compiler); | 598 cls.ensureResolved(compiler); |
589 cls.forEachMember((ClassElement classElement, Element member) { | 599 cls.forEachMember((ClassElement classElement, Element member) { |
590 if (member.isSynthesized) return; | 600 if (member.isSynthesized) return; |
591 // All methods on [Object] are shadowed by [Interceptor]. | 601 // All methods on [Object] are shadowed by [Interceptor]. |
592 if (classElement == compiler.objectClass) return; | 602 if (classElement == compiler.objectClass) return; |
593 Set<Element> set = interceptedElements.putIfAbsent( | 603 Set<Element> set = interceptedElements.putIfAbsent( |
594 member.name, () => new Set<Element>()); | 604 member.name, () => new Set<Element>()); |
595 set.add(member); | 605 set.add(member); |
596 if (classElement == jsInterceptorClass) return; | 606 if (classElement == jsInterceptorClass) return; |
597 if (!classElement.isNative()) { | 607 if (classElement.isMixinApplication) { |
598 MixinApplicationElement mixinApplication = classElement; | 608 MixinApplicationElement mixinApplication = classElement; |
599 assert(member.getEnclosingClass() == mixinApplication.mixin); | 609 assert(member.getEnclosingClass() == mixinApplication.mixin); |
600 classesMixedIntoNativeClasses.add(mixinApplication.mixin); | 610 classesMixedIntoNativeClasses.add(mixinApplication.mixin); |
601 } | 611 } |
602 }, | 612 }, |
603 includeSuperAndInjectedMembers: true); | 613 includeSuperAndInjectedMembers: true); |
604 } | 614 } |
605 } | 615 } |
606 | 616 |
607 void addInterceptors(ClassElement cls, | 617 void addInterceptors(ClassElement cls, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 } else if (cls == compiler.nullClass || cls == jsNullClass) { | 706 } else if (cls == compiler.nullClass || cls == jsNullClass) { |
697 addInterceptors(jsNullClass, enqueuer, elements); | 707 addInterceptors(jsNullClass, enqueuer, elements); |
698 } else if (cls == compiler.numClass || cls == jsNumberClass) { | 708 } else if (cls == compiler.numClass || cls == jsNumberClass) { |
699 addInterceptors(jsIntClass, enqueuer, elements); | 709 addInterceptors(jsIntClass, enqueuer, elements); |
700 addInterceptors(jsDoubleClass, enqueuer, elements); | 710 addInterceptors(jsDoubleClass, enqueuer, elements); |
701 addInterceptors(jsNumberClass, enqueuer, elements); | 711 addInterceptors(jsNumberClass, enqueuer, elements); |
702 } else if (cls == jsPlainJavaScriptObjectClass) { | 712 } else if (cls == jsPlainJavaScriptObjectClass) { |
703 addInterceptors(jsPlainJavaScriptObjectClass, enqueuer, elements); | 713 addInterceptors(jsPlainJavaScriptObjectClass, enqueuer, elements); |
704 } else if (cls == jsUnknownJavaScriptObjectClass) { | 714 } else if (cls == jsUnknownJavaScriptObjectClass) { |
705 addInterceptors(jsUnknownJavaScriptObjectClass, enqueuer, elements); | 715 addInterceptors(jsUnknownJavaScriptObjectClass, enqueuer, elements); |
706 } else if (cls.isNative()) { | 716 } else if (Elements.isNativeOrExtendsNative(cls)) { |
707 addInterceptorsForNativeClassMembers(cls, enqueuer); | 717 addInterceptorsForNativeClassMembers(cls, enqueuer); |
708 } | 718 } |
709 } | 719 } |
710 | 720 |
711 void registerUseInterceptor(Enqueuer enqueuer) { | 721 void registerUseInterceptor(Enqueuer enqueuer) { |
712 assert(!enqueuer.isResolutionQueue); | 722 assert(!enqueuer.isResolutionQueue); |
713 if (!enqueuer.nativeEnqueuer.hasInstantiatedNativeClasses()) return; | 723 if (!enqueuer.nativeEnqueuer.hasInstantiatedNativeClasses()) return; |
714 enqueuer.registerStaticUse(getNativeInterceptorMethod); | 724 enqueuer.registerStaticUse(getNativeInterceptorMethod); |
715 enqueuer.registerStaticUse(defineNativeMethodsFinishMethod); | 725 enqueuer.registerStaticUse(defineNativeMethodsFinishMethod); |
716 enqueuer.registerStaticUse(initializeDispatchPropertyMethod); | 726 enqueuer.registerStaticUse(initializeDispatchPropertyMethod); |
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1577 copy(constant.values); | 1587 copy(constant.values); |
1578 copy(constant.protoValue); | 1588 copy(constant.protoValue); |
1579 copy(constant); | 1589 copy(constant); |
1580 } | 1590 } |
1581 | 1591 |
1582 void visitConstructed(ConstructedConstant constant) { | 1592 void visitConstructed(ConstructedConstant constant) { |
1583 copy(constant.fields); | 1593 copy(constant.fields); |
1584 copy(constant); | 1594 copy(constant); |
1585 } | 1595 } |
1586 } | 1596 } |
OLD | NEW |