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 '../common.dart'; | 7 import '../common.dart'; |
8 import '../common/backend_api.dart' | 8 import '../common/backend_api.dart' |
9 show ForeignResolver, NativeRegistry, ImpactTransformer; | 9 show ForeignResolver, NativeRegistry, ImpactTransformer; |
10 import '../common/codegen.dart' show CodegenWorkItem; | 10 import '../common/codegen.dart' show CodegenWorkItem; |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 307 } |
308 | 308 |
309 class JavaScriptBackend { | 309 class JavaScriptBackend { |
310 static const String JS = 'JS'; | 310 static const String JS = 'JS'; |
311 static const String JS_BUILTIN = 'JS_BUILTIN'; | 311 static const String JS_BUILTIN = 'JS_BUILTIN'; |
312 static const String JS_EMBEDDED_GLOBAL = 'JS_EMBEDDED_GLOBAL'; | 312 static const String JS_EMBEDDED_GLOBAL = 'JS_EMBEDDED_GLOBAL'; |
313 static const String JS_INTERCEPTOR_CONSTANT = 'JS_INTERCEPTOR_CONSTANT'; | 313 static const String JS_INTERCEPTOR_CONSTANT = 'JS_INTERCEPTOR_CONSTANT'; |
314 | 314 |
315 final Compiler compiler; | 315 final Compiler compiler; |
316 | 316 |
| 317 FrontendStrategy get frontendStrategy => compiler.frontendStrategy; |
| 318 |
317 /// Returns true if the backend supports reflection. | 319 /// Returns true if the backend supports reflection. |
318 bool get supportsReflection => emitter.supportsReflection; | 320 bool get supportsReflection => emitter.supportsReflection; |
319 | 321 |
320 final OptimizerHintsForTests optimizerHints; | 322 final OptimizerHintsForTests optimizerHints; |
321 | 323 |
322 FunctionCompiler functionCompiler; | 324 FunctionCompiler functionCompiler; |
323 | 325 |
324 CodeEmitterTask emitter; | 326 CodeEmitterTask emitter; |
325 | 327 |
326 /** | 328 /** |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 Tracer tracer; | 446 Tracer tracer; |
445 | 447 |
446 JavaScriptBackend(this.compiler, | 448 JavaScriptBackend(this.compiler, |
447 {bool generateSourceMap: true, | 449 {bool generateSourceMap: true, |
448 bool useStartupEmitter: false, | 450 bool useStartupEmitter: false, |
449 bool useMultiSourceInfo: false, | 451 bool useMultiSourceInfo: false, |
450 bool useNewSourceInfo: false, | 452 bool useNewSourceInfo: false, |
451 bool useKernel: false}) | 453 bool useKernel: false}) |
452 : _rti = new RuntimeTypesImpl( | 454 : _rti = new RuntimeTypesImpl( |
453 compiler.elementEnvironment, compiler.frontendStrategy.dartTypes), | 455 compiler.elementEnvironment, compiler.frontendStrategy.dartTypes), |
454 optimizerHints = new OptimizerHintsForTests( | 456 optimizerHints = new OptimizerHintsForTests(compiler.elementEnvironment, |
455 compiler.elementEnvironment, compiler.commonElements), | 457 compiler.frontendStrategy.commonElements), |
456 this.sourceInformationStrategy = | 458 this.sourceInformationStrategy = |
457 compiler.backendStrategy.sourceInformationStrategy, | 459 compiler.backendStrategy.sourceInformationStrategy, |
458 constantCompilerTask = new JavaScriptConstantTask(compiler), | 460 constantCompilerTask = new JavaScriptConstantTask(compiler), |
459 _nativeDataResolver = new NativeDataResolverImpl(compiler), | 461 _nativeDataResolver = new NativeDataResolverImpl(compiler), |
460 _rtiNeedBuilder = | 462 _rtiNeedBuilder = |
461 compiler.frontendStrategy.createRuntimeTypesNeedBuilder() { | 463 compiler.frontendStrategy.createRuntimeTypesNeedBuilder() { |
462 CommonElements commonElements = compiler.frontendStrategy.commonElements; | 464 CommonElements commonElements = compiler.frontendStrategy.commonElements; |
463 _target = new JavaScriptBackendTarget(this); | 465 _target = new JavaScriptBackendTarget(this); |
464 impacts = new BackendImpacts(compiler.options, commonElements); | 466 impacts = new BackendImpacts(compiler.options, commonElements); |
465 _mirrorsData = compiler.frontendStrategy.createMirrorsDataBuilder(); | 467 _mirrorsData = compiler.frontendStrategy.createMirrorsDataBuilder(); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 !mirrorsData.invokedReflectively(method); | 679 !mirrorsData.invokedReflectively(method); |
678 } | 680 } |
679 | 681 |
680 bool operatorEqHandlesNullArgument(FunctionEntity operatorEqfunction) { | 682 bool operatorEqHandlesNullArgument(FunctionEntity operatorEqfunction) { |
681 return specialOperatorEqClasses.contains(operatorEqfunction.enclosingClass); | 683 return specialOperatorEqClasses.contains(operatorEqfunction.enclosingClass); |
682 } | 684 } |
683 | 685 |
684 void validateInterceptorImplementsAllObjectMethods( | 686 void validateInterceptorImplementsAllObjectMethods( |
685 ClassEntity interceptorClass) { | 687 ClassEntity interceptorClass) { |
686 if (interceptorClass == null) return; | 688 if (interceptorClass == null) return; |
687 ClassEntity objectClass = compiler.commonElements.objectClass; | 689 ClassEntity objectClass = frontendStrategy.commonElements.objectClass; |
688 compiler.elementEnvironment.forEachClassMember(objectClass, | 690 frontendStrategy.elementEnvironment.forEachClassMember(objectClass, |
689 (_, MemberEntity member) { | 691 (_, MemberEntity member) { |
690 if (member.isConstructor) return; | 692 if (member.isConstructor) return; |
691 MemberEntity interceptorMember = compiler.elementEnvironment | 693 MemberEntity interceptorMember = frontendStrategy.elementEnvironment |
692 .lookupClassMember(interceptorClass, member.name); | 694 .lookupClassMember(interceptorClass, member.name); |
693 // Interceptors must override all Object methods due to calling convention | 695 // Interceptors must override all Object methods due to calling convention |
694 // differences. | 696 // differences. |
695 assert( | 697 assert( |
696 interceptorMember.enclosingClass == interceptorClass, | 698 interceptorMember.enclosingClass == interceptorClass, |
697 failedAt( | 699 failedAt( |
698 interceptorMember, | 700 interceptorMember, |
699 "Member ${member.name} not overridden in ${interceptorClass}. " | 701 "Member ${member.name} not overridden in ${interceptorClass}. " |
700 "Found $interceptorMember from " | 702 "Found $interceptorMember from " |
701 "${interceptorMember.enclosingClass}.")); | 703 "${interceptorMember.enclosingClass}.")); |
702 }); | 704 }); |
703 } | 705 } |
704 | 706 |
705 /// Called before processing of the resolution queue is started. | 707 /// Called before processing of the resolution queue is started. |
706 void onResolutionStart(ResolutionEnqueuer enqueuer) { | 708 void onResolutionStart() { |
707 // TODO(johnniwinther): Avoid the compiler.elementEnvironment.getThisType | 709 // TODO(johnniwinther): Avoid the compiler.elementEnvironment.getThisType |
708 // calls. Currently needed to ensure resolution of the classes for various | 710 // calls. Currently needed to ensure resolution of the classes for various |
709 // queries in native behavior computation, inference and codegen. | 711 // queries in native behavior computation, inference and codegen. |
710 compiler.elementEnvironment | 712 frontendStrategy.elementEnvironment |
711 .getThisType(compiler.commonElements.jsArrayClass); | 713 .getThisType(frontendStrategy.commonElements.jsArrayClass); |
712 compiler.elementEnvironment | 714 frontendStrategy.elementEnvironment |
713 .getThisType(compiler.commonElements.jsExtendableArrayClass); | 715 .getThisType(frontendStrategy.commonElements.jsExtendableArrayClass); |
714 | 716 |
715 validateInterceptorImplementsAllObjectMethods( | 717 validateInterceptorImplementsAllObjectMethods( |
716 compiler.commonElements.jsInterceptorClass); | 718 frontendStrategy.commonElements.jsInterceptorClass); |
717 // The null-interceptor must also implement *all* methods. | 719 // The null-interceptor must also implement *all* methods. |
718 validateInterceptorImplementsAllObjectMethods( | 720 validateInterceptorImplementsAllObjectMethods( |
719 compiler.commonElements.jsNullClass); | 721 frontendStrategy.commonElements.jsNullClass); |
720 } | 722 } |
721 | 723 |
722 /// Called when the resolution queue has been closed. | 724 /// Called when the resolution queue has been closed. |
723 void onResolutionEnd() { | 725 void onResolutionEnd() { |
724 compiler.frontendStrategy.annotationProcesser | 726 frontendStrategy.annotationProcesser |
725 .processJsInteropAnnotations(nativeBasicData, nativeDataBuilder); | 727 .processJsInteropAnnotations(nativeBasicData, nativeDataBuilder); |
726 } | 728 } |
727 | 729 |
728 /// Called when the closed world from resolution has been computed. | 730 /// Called when the closed world from resolution has been computed. |
729 void onResolutionClosedWorld( | 731 void onResolutionClosedWorld( |
730 ClosedWorld closedWorld, ClosedWorldRefiner closedWorldRefiner) { | 732 ClosedWorld closedWorld, ClosedWorldRefiner closedWorldRefiner) { |
731 for (MemberEntity entity | 733 for (MemberEntity entity |
732 in compiler.enqueuer.resolution.processedEntities) { | 734 in compiler.enqueuer.resolution.processedEntities) { |
733 processAnnotations( | 735 processAnnotations( |
734 closedWorld.commonElements, entity, closedWorldRefiner); | 736 closedWorld.commonElements, entity, closedWorldRefiner); |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 'count': mirrorCount, | 971 'count': mirrorCount, |
970 'total': totalMethodCount, | 972 'total': totalMethodCount, |
971 'percentage': percentage.round() | 973 'percentage': percentage.round() |
972 }); | 974 }); |
973 | 975 |
974 List<DiagnosticMessage> infos = <DiagnosticMessage>[]; | 976 List<DiagnosticMessage> infos = <DiagnosticMessage>[]; |
975 for (LibraryElement library in compiler.libraryLoader.libraries) { | 977 for (LibraryElement library in compiler.libraryLoader.libraries) { |
976 if (library.isInternalLibrary) continue; | 978 if (library.isInternalLibrary) continue; |
977 for (ImportElement import in library.imports) { | 979 for (ImportElement import in library.imports) { |
978 LibraryElement importedLibrary = import.importedLibrary; | 980 LibraryElement importedLibrary = import.importedLibrary; |
979 if (importedLibrary != compiler.commonElements.mirrorsLibrary) | 981 if (importedLibrary != closedWorld.commonElements.mirrorsLibrary) |
980 continue; | 982 continue; |
981 MessageKind kind = | 983 MessageKind kind = |
982 compiler.mirrorUsageAnalyzerTask.hasMirrorUsage(library) | 984 compiler.mirrorUsageAnalyzerTask.hasMirrorUsage(library) |
983 ? MessageKind.MIRROR_IMPORT | 985 ? MessageKind.MIRROR_IMPORT |
984 : MessageKind.MIRROR_IMPORT_NO_USAGE; | 986 : MessageKind.MIRROR_IMPORT_NO_USAGE; |
985 reporter.withCurrentElement(library, () { | 987 reporter.withCurrentElement(library, () { |
986 infos.add(reporter.createMessage(import, kind)); | 988 infos.add(reporter.createMessage(import, kind)); |
987 }); | 989 }); |
988 } | 990 } |
989 } | 991 } |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1385 | 1387 |
1386 bool canUseAliasedSuperMember(MemberEntity member, Selector selector) { | 1388 bool canUseAliasedSuperMember(MemberEntity member, Selector selector) { |
1387 return !selector.isGetter; | 1389 return !selector.isGetter; |
1388 } | 1390 } |
1389 | 1391 |
1390 /// Returns `true` if [member] is called from a subclass via `super`. | 1392 /// Returns `true` if [member] is called from a subclass via `super`. |
1391 bool isAliasedSuperMember(MemberEntity member) { | 1393 bool isAliasedSuperMember(MemberEntity member) { |
1392 return _aliasedSuperMembers.contains(member); | 1394 return _aliasedSuperMembers.contains(member); |
1393 } | 1395 } |
1394 } | 1396 } |
OLD | NEW |