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 const VERBOSE_OPTIMIZER_HINTS = false; | 7 const VERBOSE_OPTIMIZER_HINTS = false; |
8 | 8 |
9 class JavaScriptItemCompilationContext extends ItemCompilationContext { | 9 class JavaScriptItemCompilationContext extends ItemCompilationContext { |
10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); | 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 @override | 729 @override |
730 bool isJsInterop(Element element) => nativeData.isJsInterop(element); | 730 bool isJsInterop(Element element) => nativeData.isJsInterop(element); |
731 | 731 |
732 /// Whether [element] corresponds to a native JavaScript construct either | 732 /// Whether [element] corresponds to a native JavaScript construct either |
733 /// through the native mechanism (`@Native(...)` or the `native` pseudo | 733 /// through the native mechanism (`@Native(...)` or the `native` pseudo |
734 /// keyword) which is only allowed for internal libraries or via the typed | 734 /// keyword) which is only allowed for internal libraries or via the typed |
735 /// JavaScriptInterop mechanism which is allowed for user libraries. | 735 /// JavaScriptInterop mechanism which is allowed for user libraries. |
736 @override | 736 @override |
737 bool isNative(Element element) => nativeData.isNative(element); | 737 bool isNative(Element element) => nativeData.isNative(element); |
738 | 738 |
| 739 /// Returns the [NativeBehavior] for calling the native [method]. |
| 740 native.NativeBehavior getNativeMethodBehavior(FunctionElement method) { |
| 741 return nativeData.getNativeMethodBehavior(method); |
| 742 } |
| 743 |
| 744 /// Returns the [NativeBehavior] for reading from the native [field]. |
| 745 native.NativeBehavior getNativeFieldLoadBehavior(FieldElement field) { |
| 746 return nativeData.getNativeFieldLoadBehavior(field); |
| 747 } |
| 748 |
| 749 /// Returns the [NativeBehavior] for writing to the native [field]. |
| 750 native.NativeBehavior getNativeFieldStoreBehavior(FieldElement field) { |
| 751 return nativeData.getNativeFieldStoreBehavior(field); |
| 752 } |
| 753 |
| 754 @override |
| 755 void resolveNativeElement(Element element, NativeRegistry registry) { |
| 756 if (element.isFunction || |
| 757 element.isConstructor || |
| 758 element.isGetter || |
| 759 element.isSetter) { |
| 760 compiler.enqueuer.resolution.nativeEnqueuer |
| 761 .handleMethodAnnotations(element); |
| 762 if (isNative(element)) { |
| 763 native.NativeBehavior behavior = |
| 764 native.NativeBehavior.ofMethod(element, compiler); |
| 765 nativeData.setNativeMethodBehavior(element, behavior); |
| 766 registry.registerNativeData(behavior); |
| 767 } |
| 768 } else if (element.isField) { |
| 769 compiler.enqueuer.resolution.nativeEnqueuer |
| 770 .handleFieldAnnotations(element); |
| 771 if (isNative(element)) { |
| 772 native.NativeBehavior fieldLoadBehavior = |
| 773 native.NativeBehavior.ofFieldLoad(element, compiler); |
| 774 native.NativeBehavior fieldStoreBehavior = |
| 775 native.NativeBehavior.ofFieldStore(element, compiler); |
| 776 nativeData.setNativeFieldLoadBehavior(element, fieldLoadBehavior); |
| 777 nativeData.setNativeFieldStoreBehavior(element, fieldStoreBehavior); |
| 778 |
| 779 // TODO(sra): Process fields for storing separately. |
| 780 // We have to handle both loading and storing to the field because we |
| 781 // only get one look at each member and there might be a load or store |
| 782 // we have not seen yet. |
| 783 registry.registerNativeData(fieldLoadBehavior); |
| 784 registry.registerNativeData(fieldStoreBehavior); |
| 785 } |
| 786 } |
| 787 } |
| 788 |
739 bool isNativeOrExtendsNative(ClassElement element) { | 789 bool isNativeOrExtendsNative(ClassElement element) { |
740 if (element == null) return false; | 790 if (element == null) return false; |
741 if (isNative(element) || isJsInterop(element)) { | 791 if (isNative(element) || isJsInterop(element)) { |
742 return true; | 792 return true; |
743 } | 793 } |
744 assert(element.isResolved); | 794 assert(element.isResolved); |
745 return isNativeOrExtendsNative(element.superclass); | 795 return isNativeOrExtendsNative(element.superclass); |
746 } | 796 } |
747 | 797 |
748 bool isInterceptedMethod(Element element) { | 798 bool isInterceptedMethod(Element element) { |
(...skipping 2276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3025 | 3075 |
3026 @override | 3076 @override |
3027 void onImpactUsed(ImpactUseCase impactUse) { | 3077 void onImpactUsed(ImpactUseCase impactUse) { |
3028 if (impactUse == DeferredLoadTask.IMPACT_USE && !supportSerialization) { | 3078 if (impactUse == DeferredLoadTask.IMPACT_USE && !supportSerialization) { |
3029 // TODO(johnniwinther): Allow emptying when serialization has been | 3079 // TODO(johnniwinther): Allow emptying when serialization has been |
3030 // performed. | 3080 // performed. |
3031 resolution.emptyCache(); | 3081 resolution.emptyCache(); |
3032 } | 3082 } |
3033 } | 3083 } |
3034 } | 3084 } |
OLD | NEW |