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 library js_backend.backend; | 5 library js_backend.backend; |
6 | 6 |
7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
8 | 8 |
9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; | 9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; |
10 | 10 |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 _target = new JavaScriptBackendTarget(this); | 504 _target = new JavaScriptBackendTarget(this); |
505 helpers = new BackendHelpers(compiler.elementEnvironment, commonElements); | 505 helpers = new BackendHelpers(compiler.elementEnvironment, commonElements); |
506 impacts = new BackendImpacts(compiler.options, commonElements, helpers); | 506 impacts = new BackendImpacts(compiler.options, commonElements, helpers); |
507 _mirrorsData = new MirrorsDataImpl( | 507 _mirrorsData = new MirrorsDataImpl( |
508 compiler, compiler.options, commonElements, helpers, constants); | 508 compiler, compiler.options, commonElements, helpers, constants); |
509 _backendUsageBuilder = new BackendUsageBuilderImpl( | 509 _backendUsageBuilder = new BackendUsageBuilderImpl( |
510 compiler.elementEnvironment, commonElements, helpers); | 510 compiler.elementEnvironment, commonElements, helpers); |
511 _checkedModeHelpers = new CheckedModeHelpers(commonElements, helpers); | 511 _checkedModeHelpers = new CheckedModeHelpers(commonElements, helpers); |
512 emitter = | 512 emitter = |
513 new CodeEmitterTask(compiler, generateSourceMap, useStartupEmitter); | 513 new CodeEmitterTask(compiler, generateSourceMap, useStartupEmitter); |
514 _nativeResolutionEnqueuer = new native.NativeResolutionEnqueuer(compiler); | |
515 _nativeCodegenEnqueuer = new native.NativeCodegenEnqueuer( | |
516 compiler, emitter, _nativeResolutionEnqueuer); | |
517 | 514 |
518 _typeVariableResolutionAnalysis = new TypeVariableResolutionAnalysis( | 515 _typeVariableResolutionAnalysis = new TypeVariableResolutionAnalysis( |
519 compiler.elementEnvironment, impacts, backendUsageBuilder); | 516 compiler.elementEnvironment, impacts, backendUsageBuilder); |
520 jsInteropAnalysis = new JsInteropAnalysis(this); | 517 jsInteropAnalysis = new JsInteropAnalysis(this); |
521 _mirrorsResolutionAnalysis = | 518 _mirrorsResolutionAnalysis = |
522 new MirrorsResolutionAnalysisImpl(this, compiler.resolution); | 519 new MirrorsResolutionAnalysisImpl(this, compiler.resolution); |
523 lookupMapResolutionAnalysis = | 520 lookupMapResolutionAnalysis = |
524 new LookupMapResolutionAnalysis(reporter, compiler.elementEnvironment); | 521 new LookupMapResolutionAnalysis(reporter, compiler.elementEnvironment); |
525 | 522 |
526 noSuchMethodRegistry = new NoSuchMethodRegistry(this); | 523 noSuchMethodRegistry = new NoSuchMethodRegistry(this); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 validateInterceptorImplementsAllObjectMethods(helpers.jsNullClass); | 807 validateInterceptorImplementsAllObjectMethods(helpers.jsNullClass); |
811 } | 808 } |
812 | 809 |
813 void onResolutionComplete( | 810 void onResolutionComplete( |
814 ClosedWorld closedWorld, ClosedWorldRefiner closedWorldRefiner) { | 811 ClosedWorld closedWorld, ClosedWorldRefiner closedWorldRefiner) { |
815 for (Entity entity in compiler.enqueuer.resolution.processedEntities) { | 812 for (Entity entity in compiler.enqueuer.resolution.processedEntities) { |
816 processAnnotations(entity, closedWorldRefiner); | 813 processAnnotations(entity, closedWorldRefiner); |
817 } | 814 } |
818 mirrorsDataBuilder.computeMembersNeededForReflection( | 815 mirrorsDataBuilder.computeMembersNeededForReflection( |
819 compiler.enqueuer.resolution.worldBuilder, closedWorld); | 816 compiler.enqueuer.resolution.worldBuilder, closedWorld); |
820 _backendUsage = _backendUsageBuilder.close(); | 817 _backendUsage = backendUsageBuilder.close(); |
821 _rtiNeed = rtiNeedBuilder.computeRuntimeTypesNeed( | 818 _rtiNeed = rtiNeedBuilder.computeRuntimeTypesNeed( |
822 compiler.enqueuer.resolution.worldBuilder, | 819 compiler.enqueuer.resolution.worldBuilder, |
823 closedWorld, | 820 closedWorld, |
824 compiler.types, | 821 compiler.types, |
825 commonElements, | 822 commonElements, |
826 helpers, | 823 helpers, |
827 _backendUsage, | 824 _backendUsage, |
828 enableTypeAssertions: compiler.options.enableTypeAssertions); | 825 enableTypeAssertions: compiler.options.enableTypeAssertions); |
829 _interceptorData = | 826 _interceptorData = interceptorDataBuilder.onResolutionComplete(closedWorld); |
830 _interceptorDataBuilder.onResolutionComplete(closedWorld); | |
831 _oneShotInterceptorData = | 827 _oneShotInterceptorData = |
832 new OneShotInterceptorData(interceptorData, helpers); | 828 new OneShotInterceptorData(interceptorData, helpers); |
833 mirrorsResolutionAnalysis.onResolutionComplete(); | 829 mirrorsResolutionAnalysis.onResolutionComplete(); |
834 } | 830 } |
835 | 831 |
836 void onTypeInferenceComplete() { | 832 void onTypeInferenceComplete() { |
837 noSuchMethodRegistry.onTypeInferenceComplete(); | 833 noSuchMethodRegistry.onTypeInferenceComplete(); |
838 } | 834 } |
839 | 835 |
840 /// Register a runtime type variable bound tests between [typeArgument] and | 836 /// Register a runtime type variable bound tests between [typeArgument] and |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 return null; | 879 return null; |
884 } | 880 } |
885 | 881 |
886 bool isComplexNoSuchMethod(FunctionElement element) => | 882 bool isComplexNoSuchMethod(FunctionElement element) => |
887 noSuchMethodRegistry.isComplex(element); | 883 noSuchMethodRegistry.isComplex(element); |
888 | 884 |
889 ResolutionEnqueuer createResolutionEnqueuer( | 885 ResolutionEnqueuer createResolutionEnqueuer( |
890 CompilerTask task, Compiler compiler) { | 886 CompilerTask task, Compiler compiler) { |
891 _nativeBasicData = | 887 _nativeBasicData = |
892 nativeBasicDataBuilder.close(compiler.elementEnvironment); | 888 nativeBasicDataBuilder.close(compiler.elementEnvironment); |
| 889 _nativeResolutionEnqueuer = new native.NativeResolutionEnqueuer( |
| 890 compiler, |
| 891 new NativeClassResolverImpl( |
| 892 compiler.resolution, reporter, helpers, nativeBasicData)); |
893 _nativeData = new NativeDataImpl(nativeBasicData); | 893 _nativeData = new NativeDataImpl(nativeBasicData); |
894 _backendClasses = new JavaScriptBackendClasses( | 894 _backendClasses = new JavaScriptBackendClasses( |
895 compiler.elementEnvironment, helpers, nativeBasicData); | 895 compiler.elementEnvironment, helpers, nativeBasicData); |
896 _customElementsResolutionAnalysis = new CustomElementsResolutionAnalysis( | 896 _customElementsResolutionAnalysis = new CustomElementsResolutionAnalysis( |
897 compiler.resolution, | 897 compiler.resolution, |
898 constantSystem, | 898 constantSystem, |
899 commonElements, | 899 commonElements, |
900 backendClasses, | 900 backendClasses, |
901 helpers, | 901 helpers, |
902 nativeBasicData, | 902 nativeBasicData, |
(...skipping 25 matching lines...) Expand all Loading... |
928 : const TreeShakingEnqueuerStrategy(), | 928 : const TreeShakingEnqueuerStrategy(), |
929 new ResolutionEnqueuerListener( | 929 new ResolutionEnqueuerListener( |
930 kernelTask, | 930 kernelTask, |
931 compiler.options, | 931 compiler.options, |
932 compiler.elementEnvironment, | 932 compiler.elementEnvironment, |
933 commonElements, | 933 commonElements, |
934 helpers, | 934 helpers, |
935 impacts, | 935 impacts, |
936 backendClasses, | 936 backendClasses, |
937 nativeBasicData, | 937 nativeBasicData, |
938 _interceptorDataBuilder, | 938 interceptorDataBuilder, |
939 _backendUsageBuilder, | 939 backendUsageBuilder, |
940 _rtiNeedBuilder, | 940 rtiNeedBuilder, |
941 mirrorsDataBuilder, | 941 mirrorsDataBuilder, |
942 noSuchMethodRegistry, | 942 noSuchMethodRegistry, |
943 customElementsResolutionAnalysis, | 943 customElementsResolutionAnalysis, |
944 lookupMapResolutionAnalysis, | 944 lookupMapResolutionAnalysis, |
945 mirrorsResolutionAnalysis, | 945 mirrorsResolutionAnalysis, |
946 typeVariableResolutionAnalysis, | 946 typeVariableResolutionAnalysis, |
947 _nativeResolutionEnqueuer), | 947 nativeResolutionEnqueuer), |
948 new ElementResolutionWorldBuilder( | 948 new ElementResolutionWorldBuilder( |
949 this, compiler.resolution, const OpenWorldStrategy()), | 949 this, compiler.resolution, const OpenWorldStrategy()), |
950 new ResolutionWorkItemBuilder(compiler.resolution)); | 950 new ResolutionWorkItemBuilder(compiler.resolution)); |
951 } | 951 } |
952 | 952 |
953 /// Creates an [Enqueuer] for code generation specific to this backend. | 953 /// Creates an [Enqueuer] for code generation specific to this backend. |
954 CodegenEnqueuer createCodegenEnqueuer( | 954 CodegenEnqueuer createCodegenEnqueuer( |
955 CompilerTask task, Compiler compiler, ClosedWorld closedWorld) { | 955 CompilerTask task, Compiler compiler, ClosedWorld closedWorld) { |
956 _typeVariableCodegenAnalysis = | 956 _typeVariableCodegenAnalysis = |
957 new TypeVariableCodegenAnalysis(this, helpers, mirrorsData); | 957 new TypeVariableCodegenAnalysis(this, helpers, mirrorsData); |
958 _lookupMapAnalysis = new LookupMapAnalysis( | 958 _lookupMapAnalysis = new LookupMapAnalysis( |
959 reporter, | 959 reporter, |
960 constantSystem, | 960 constantSystem, |
961 constants, | 961 constants, |
962 compiler.elementEnvironment, | 962 compiler.elementEnvironment, |
963 commonElements, | 963 commonElements, |
964 helpers, | 964 helpers, |
965 backendClasses, | 965 backendClasses, |
966 lookupMapResolutionAnalysis); | 966 lookupMapResolutionAnalysis); |
967 _mirrorsCodegenAnalysis = mirrorsResolutionAnalysis.close(); | 967 _mirrorsCodegenAnalysis = mirrorsResolutionAnalysis.close(); |
968 _customElementsCodegenAnalysis = new CustomElementsCodegenAnalysis( | 968 _customElementsCodegenAnalysis = new CustomElementsCodegenAnalysis( |
969 compiler.resolution, | 969 compiler.resolution, |
970 constantSystem, | 970 constantSystem, |
971 commonElements, | 971 commonElements, |
972 backendClasses, | 972 backendClasses, |
973 helpers, | 973 helpers, |
974 nativeBasicData); | 974 nativeBasicData); |
| 975 _nativeCodegenEnqueuer = new native.NativeCodegenEnqueuer( |
| 976 compiler, emitter, _nativeResolutionEnqueuer); |
975 return new CodegenEnqueuer( | 977 return new CodegenEnqueuer( |
976 task, | 978 task, |
977 compiler.options, | 979 compiler.options, |
978 const TreeShakingEnqueuerStrategy(), | 980 const TreeShakingEnqueuerStrategy(), |
979 new CodegenWorldBuilderImpl( | 981 new CodegenWorldBuilderImpl( |
980 nativeBasicData, closedWorld, constants, const TypeMaskStrategy()), | 982 nativeBasicData, closedWorld, constants, const TypeMaskStrategy()), |
981 new CodegenWorkItemBuilder(this, compiler.options), | 983 new CodegenWorkItemBuilder(this, compiler.options), |
982 new CodegenEnqueuerListener( | 984 new CodegenEnqueuerListener( |
983 compiler.elementEnvironment, | 985 compiler.elementEnvironment, |
984 commonElements, | 986 commonElements, |
985 helpers, | 987 helpers, |
986 impacts, | 988 impacts, |
987 backendClasses, | 989 backendClasses, |
988 backendUsage, | 990 backendUsage, |
989 rtiNeed, | 991 rtiNeed, |
990 customElementsCodegenAnalysis, | 992 customElementsCodegenAnalysis, |
991 typeVariableCodegenAnalysis, | 993 typeVariableCodegenAnalysis, |
992 lookupMapAnalysis, | 994 lookupMapAnalysis, |
993 mirrorsCodegenAnalysis, | 995 mirrorsCodegenAnalysis, |
994 _nativeCodegenEnqueuer)); | 996 nativeCodegenEnqueuer)); |
995 } | 997 } |
996 | 998 |
997 WorldImpact codegen(CodegenWorkItem work) { | 999 WorldImpact codegen(CodegenWorkItem work) { |
998 Element element = work.element; | 1000 Element element = work.element; |
999 if (compiler.elementHasCompileTimeError(element)) { | 1001 if (compiler.elementHasCompileTimeError(element)) { |
1000 DiagnosticMessage message = | 1002 DiagnosticMessage message = |
1001 // If there's more than one error, the first is probably most | 1003 // If there's more than one error, the first is probably most |
1002 // informative, as the following errors may be side-effects of the | 1004 // informative, as the following errors may be side-effects of the |
1003 // first error. | 1005 // first error. |
1004 compiler.elementsWithCompileTimeErrors[element].first; | 1006 compiler.elementsWithCompileTimeErrors[element].first; |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1614 return _backend.defaultSuperclass(element); | 1616 return _backend.defaultSuperclass(element); |
1615 } | 1617 } |
1616 | 1618 |
1617 @override | 1619 @override |
1618 bool isNativeClass(ClassEntity element) => | 1620 bool isNativeClass(ClassEntity element) => |
1619 _backend.nativeBasicData.isNativeClass(element); | 1621 _backend.nativeBasicData.isNativeClass(element); |
1620 | 1622 |
1621 @override | 1623 @override |
1622 bool isForeign(Element element) => _backend.isForeign(element); | 1624 bool isForeign(Element element) => _backend.isForeign(element); |
1623 } | 1625 } |
OLD | NEW |