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

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

Issue 1383483006: Extract DiagnosticReporter implementation from Compiler. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fixes after rebase. Created 5 years, 2 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) 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 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 generateSourceMap 645 generateSourceMap
646 ? (useNewSourceInfo 646 ? (useNewSourceInfo
647 ? const PositionSourceInformationStrategy() 647 ? const PositionSourceInformationStrategy()
648 : const StartEndSourceInformationStrategy()) 648 : const StartEndSourceInformationStrategy())
649 : const JavaScriptSourceInformationStrategy(), 649 : const JavaScriptSourceInformationStrategy(),
650 super(compiler) { 650 super(compiler) {
651 emitter = new CodeEmitterTask( 651 emitter = new CodeEmitterTask(
652 compiler, namer, generateSourceMap, useStartupEmitter); 652 compiler, namer, generateSourceMap, useStartupEmitter);
653 typeVariableHandler = new TypeVariableHandler(compiler); 653 typeVariableHandler = new TypeVariableHandler(compiler);
654 customElementsAnalysis = new CustomElementsAnalysis(this); 654 customElementsAnalysis = new CustomElementsAnalysis(this);
655 lookupMapAnalysis = new LookupMapAnalysis(this); 655 lookupMapAnalysis = new LookupMapAnalysis(this, reporter);
656 noSuchMethodRegistry = new NoSuchMethodRegistry(this); 656 noSuchMethodRegistry = new NoSuchMethodRegistry(this);
657 constantCompilerTask = new JavaScriptConstantTask(compiler); 657 constantCompilerTask = new JavaScriptConstantTask(compiler);
658 resolutionCallbacks = new JavaScriptResolutionCallbacks(this); 658 resolutionCallbacks = new JavaScriptResolutionCallbacks(this);
659 patchResolverTask = new PatchResolverTask(compiler); 659 patchResolverTask = new PatchResolverTask(compiler);
660 functionCompiler = compiler.useCpsIr 660 functionCompiler = compiler.useCpsIr
661 ? new CpsFunctionCompiler( 661 ? new CpsFunctionCompiler(
662 compiler, this, sourceInformationStrategy) 662 compiler, this, sourceInformationStrategy)
663 : new SsaFunctionCompiler(this, sourceInformationStrategy); 663 : new SsaFunctionCompiler(this, sourceInformationStrategy);
664 } 664 }
665 665
666 ConstantSystem get constantSystem => constants.constantSystem; 666 ConstantSystem get constantSystem => constants.constantSystem;
667 667
668 DiagnosticReporter get reporter => compiler.reporter;
669
668 Resolution get resolution => compiler.resolution; 670 Resolution get resolution => compiler.resolution;
669 671
670 /// Returns constant environment for the JavaScript interpretation of the 672 /// Returns constant environment for the JavaScript interpretation of the
671 /// constants. 673 /// constants.
672 JavaScriptConstantCompiler get constants { 674 JavaScriptConstantCompiler get constants {
673 return constantCompilerTask.jsConstantCompiler; 675 return constantCompilerTask.jsConstantCompiler;
674 } 676 }
675 677
676 FunctionElement resolveExternalFunction(FunctionElement element) { 678 FunctionElement resolveExternalFunction(FunctionElement element) {
677 if (isForeign(element)) return element; 679 if (isForeign(element)) return element;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 assert(interceptorMember.enclosingClass == interceptorClass); 899 assert(interceptorMember.enclosingClass == interceptorClass);
898 }); 900 });
899 } 901 }
900 902
901 void addInterceptorsForNativeClassMembers( 903 void addInterceptorsForNativeClassMembers(
902 ClassElement cls, Enqueuer enqueuer) { 904 ClassElement cls, Enqueuer enqueuer) {
903 if (enqueuer.isResolutionQueue) { 905 if (enqueuer.isResolutionQueue) {
904 cls.ensureResolved(resolution); 906 cls.ensureResolved(resolution);
905 cls.forEachMember((ClassElement classElement, Element member) { 907 cls.forEachMember((ClassElement classElement, Element member) {
906 if (member.name == Identifiers.call) { 908 if (member.name == Identifiers.call) {
907 compiler.reportErrorMessage( 909 reporter.reportErrorMessage(
908 member, 910 member,
909 MessageKind.CALL_NOT_SUPPORTED_ON_NATIVE_CLASS); 911 MessageKind.CALL_NOT_SUPPORTED_ON_NATIVE_CLASS);
910 return; 912 return;
911 } 913 }
912 if (member.isSynthesized) return; 914 if (member.isSynthesized) return;
913 // All methods on [Object] are shadowed by [Interceptor]. 915 // All methods on [Object] are shadowed by [Interceptor].
914 if (classElement == compiler.objectClass) return; 916 if (classElement == compiler.objectClass) return;
915 Set<Element> set = interceptedElements.putIfAbsent( 917 Set<Element> set = interceptedElements.putIfAbsent(
916 member.name, () => new Set<Element>()); 918 member.name, () => new Set<Element>());
917 set.add(member); 919 set.add(member);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 // For map literals, the dependency between the implementation class 1084 // For map literals, the dependency between the implementation class
1083 // and [Map] is not visible, so we have to add it manually. 1085 // and [Map] is not visible, so we have to add it manually.
1084 Element getFactory(String name, int arity) { 1086 Element getFactory(String name, int arity) {
1085 // The constructor is on the patch class, but dart2js unit tests don't 1087 // The constructor is on the patch class, but dart2js unit tests don't
1086 // have a patch class. 1088 // have a patch class.
1087 ClassElement implementation = cls.patch != null ? cls.patch : cls; 1089 ClassElement implementation = cls.patch != null ? cls.patch : cls;
1088 ConstructorElement ctor = implementation.lookupConstructor(name); 1090 ConstructorElement ctor = implementation.lookupConstructor(name);
1089 if (ctor == null 1091 if (ctor == null
1090 || (Name.isPrivateName(name) 1092 || (Name.isPrivateName(name)
1091 && ctor.library != mapLiteralClass.library)) { 1093 && ctor.library != mapLiteralClass.library)) {
1092 compiler.internalError(mapLiteralClass, 1094 reporter.internalError(mapLiteralClass,
1093 "Map literal class $mapLiteralClass missing " 1095 "Map literal class $mapLiteralClass missing "
1094 "'$name' constructor" 1096 "'$name' constructor"
1095 " ${mapLiteralClass.constructors}"); 1097 " ${mapLiteralClass.constructors}");
1096 } 1098 }
1097 return ctor; 1099 return ctor;
1098 } 1100 }
1099 Element getMember(String name) { 1101 Element getMember(String name) {
1100 // The constructor is on the patch class, but dart2js unit tests don't 1102 // The constructor is on the patch class, but dart2js unit tests don't
1101 // have a patch class. 1103 // have a patch class.
1102 ClassElement implementation = cls.patch != null ? cls.patch : cls; 1104 ClassElement implementation = cls.patch != null ? cls.patch : cls;
1103 Element element = implementation.lookupLocalMember(name); 1105 Element element = implementation.lookupLocalMember(name);
1104 if (element == null || !element.isFunction || !element.isStatic) { 1106 if (element == null || !element.isFunction || !element.isStatic) {
1105 compiler.internalError(mapLiteralClass, 1107 reporter.internalError(mapLiteralClass,
1106 "Map literal class $mapLiteralClass missing " 1108 "Map literal class $mapLiteralClass missing "
1107 "'$name' static member function"); 1109 "'$name' static member function");
1108 } 1110 }
1109 return element; 1111 return element;
1110 } 1112 }
1111 mapLiteralConstructor = getFactory('_literal', 1); 1113 mapLiteralConstructor = getFactory('_literal', 1);
1112 mapLiteralConstructorEmpty = getFactory('_empty', 0); 1114 mapLiteralConstructorEmpty = getFactory('_empty', 0);
1113 enqueueInResolution(mapLiteralConstructor, registry); 1115 enqueueInResolution(mapLiteralConstructor, registry);
1114 enqueueInResolution(mapLiteralConstructorEmpty, registry); 1116 enqueueInResolution(mapLiteralConstructorEmpty, registry);
1115 1117
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 Node argument = node.argumentsNode.nodes.head; 1374 Node argument = node.argumentsNode.nodes.head;
1373 ConstantExpression constant = resolver.getConstant(argument); 1375 ConstantExpression constant = resolver.getConstant(argument);
1374 if (constant != null && constant.kind == ConstantExpressionKind.TYPE) { 1376 if (constant != null && constant.kind == ConstantExpressionKind.TYPE) {
1375 TypeConstantExpression typeConstant = constant; 1377 TypeConstantExpression typeConstant = constant;
1376 if (typeConstant.type is InterfaceType) { 1378 if (typeConstant.type is InterfaceType) {
1377 resolver.registerInstantiatedType(typeConstant.type); 1379 resolver.registerInstantiatedType(typeConstant.type);
1378 return; 1380 return;
1379 } 1381 }
1380 } 1382 }
1381 } 1383 }
1382 compiler.reportErrorMessage( 1384 reporter.reportErrorMessage(
1383 node, 1385 node,
1384 MessageKind.WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT); 1386 MessageKind.WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT);
1385 } 1387 }
1386 } 1388 }
1387 1389
1388 void enableNoSuchMethod(Enqueuer world) { 1390 void enableNoSuchMethod(Enqueuer world) {
1389 enqueue(world, getCreateInvocationMirror(), compiler.globalDependencies); 1391 enqueue(world, getCreateInvocationMirror(), compiler.globalDependencies);
1390 world.registerInvocation( 1392 world.registerInvocation(
1391 new UniverseSelector(Selectors.noSuchMethod_, null)); 1393 new UniverseSelector(Selectors.noSuchMethod_, null));
1392 } 1394 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 return jsAst.prettyPrint(generatedCode[element], compiler).getText(); 1566 return jsAst.prettyPrint(generatedCode[element], compiler).getText();
1565 } 1567 }
1566 1568
1567 int assembleProgram() { 1569 int assembleProgram() {
1568 int programSize = emitter.assembleProgram(); 1570 int programSize = emitter.assembleProgram();
1569 noSuchMethodRegistry.emitDiagnostic(); 1571 noSuchMethodRegistry.emitDiagnostic();
1570 int totalMethodCount = generatedCode.length; 1572 int totalMethodCount = generatedCode.length;
1571 if (totalMethodCount != preMirrorsMethodCount) { 1573 if (totalMethodCount != preMirrorsMethodCount) {
1572 int mirrorCount = totalMethodCount - preMirrorsMethodCount; 1574 int mirrorCount = totalMethodCount - preMirrorsMethodCount;
1573 double percentage = (mirrorCount / totalMethodCount) * 100; 1575 double percentage = (mirrorCount / totalMethodCount) * 100;
1574 DiagnosticMessage hint = compiler.createMessage( 1576 DiagnosticMessage hint = reporter.createMessage(
1575 compiler.mainApp, MessageKind.MIRROR_BLOAT, 1577 compiler.mainApp, MessageKind.MIRROR_BLOAT,
1576 {'count': mirrorCount, 1578 {'count': mirrorCount,
1577 'total': totalMethodCount, 1579 'total': totalMethodCount,
1578 'percentage': percentage.round()}); 1580 'percentage': percentage.round()});
1579 1581
1580 List<DiagnosticMessage> infos = <DiagnosticMessage>[]; 1582 List<DiagnosticMessage> infos = <DiagnosticMessage>[];
1581 for (LibraryElement library in compiler.libraryLoader.libraries) { 1583 for (LibraryElement library in compiler.libraryLoader.libraries) {
1582 if (library.isInternalLibrary) continue; 1584 if (library.isInternalLibrary) continue;
1583 for (ImportElement import in library.imports) { 1585 for (ImportElement import in library.imports) {
1584 LibraryElement importedLibrary = import.importedLibrary; 1586 LibraryElement importedLibrary = import.importedLibrary;
1585 if (importedLibrary != compiler.mirrorsLibrary) continue; 1587 if (importedLibrary != compiler.mirrorsLibrary) continue;
1586 MessageKind kind = 1588 MessageKind kind =
1587 compiler.mirrorUsageAnalyzerTask.hasMirrorUsage(library) 1589 compiler.mirrorUsageAnalyzerTask.hasMirrorUsage(library)
1588 ? MessageKind.MIRROR_IMPORT 1590 ? MessageKind.MIRROR_IMPORT
1589 : MessageKind.MIRROR_IMPORT_NO_USAGE; 1591 : MessageKind.MIRROR_IMPORT_NO_USAGE;
1590 compiler.withCurrentElement(library, () { 1592 reporter.withCurrentElement(library, () {
1591 infos.add(compiler.createMessage(import, kind)); 1593 infos.add(reporter.createMessage(import, kind));
1592 }); 1594 });
1593 } 1595 }
1594 } 1596 }
1595 compiler.reportHint(hint, infos); 1597 reporter.reportHint(hint, infos);
1596 } 1598 }
1597 return programSize; 1599 return programSize;
1598 } 1600 }
1599 1601
1600 Element getDartClass(Element element) { 1602 Element getDartClass(Element element) {
1601 for (ClassElement dartClass in implementationClasses.keys) { 1603 for (ClassElement dartClass in implementationClasses.keys) {
1602 if (element == implementationClasses[dartClass]) { 1604 if (element == implementationClasses[dartClass]) {
1603 return dartClass; 1605 return dartClass;
1604 } 1606 }
1605 } 1607 }
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
2121 ClassElement result = findHelper(name); 2123 ClassElement result = findHelper(name);
2122 if (result == null) { 2124 if (result == null) {
2123 missingHelperClasses.add(name); 2125 missingHelperClasses.add(name);
2124 } 2126 }
2125 return result; 2127 return result;
2126 } 2128 }
2127 jsInvocationMirrorClass = lookupHelperClass('JSInvocationMirror'); 2129 jsInvocationMirrorClass = lookupHelperClass('JSInvocationMirror');
2128 boundClosureClass = lookupHelperClass('BoundClosure'); 2130 boundClosureClass = lookupHelperClass('BoundClosure');
2129 closureClass = lookupHelperClass('Closure'); 2131 closureClass = lookupHelperClass('Closure');
2130 if (!missingHelperClasses.isEmpty) { 2132 if (!missingHelperClasses.isEmpty) {
2131 compiler.internalError(jsHelperLibrary, 2133 reporter.internalError(jsHelperLibrary,
2132 'dart:_js_helper library does not contain required classes: ' 2134 'dart:_js_helper library does not contain required classes: '
2133 '$missingHelperClasses'); 2135 '$missingHelperClasses');
2134 } 2136 }
2135 } 2137 }
2136 2138
2137 Future onLibraryScanned(LibraryElement library, LibraryLoader loader) { 2139 Future onLibraryScanned(LibraryElement library, LibraryLoader loader) {
2138 return super.onLibraryScanned(library, loader).then((_) { 2140 return super.onLibraryScanned(library, loader).then((_) {
2139 if (library.isPlatformLibrary && 2141 if (library.isPlatformLibrary &&
2140 // Don't patch library currently disallowed. 2142 // Don't patch library currently disallowed.
2141 !library.isSynthesized && 2143 !library.isSynthesized &&
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
2637 2639
2638 if (isTreeShakingDisabled) { 2640 if (isTreeShakingDisabled) {
2639 enqueuer.enqueueReflectiveElements(recentClasses); 2641 enqueuer.enqueueReflectiveElements(recentClasses);
2640 } else if (!targetsUsed.isEmpty && enqueuer.isResolutionQueue) { 2642 } else if (!targetsUsed.isEmpty && enqueuer.isResolutionQueue) {
2641 // Add all static elements (not classes) that have been requested for 2643 // Add all static elements (not classes) that have been requested for
2642 // reflection. If there is no mirror-usage these are probably not 2644 // reflection. If there is no mirror-usage these are probably not
2643 // necessary, but the backend relies on them being resolved. 2645 // necessary, but the backend relies on them being resolved.
2644 enqueuer.enqueueReflectiveStaticFields(_findStaticFieldTargets()); 2646 enqueuer.enqueueReflectiveStaticFields(_findStaticFieldTargets());
2645 } 2647 }
2646 2648
2647 if (mustPreserveNames) compiler.log('Preserving names.'); 2649 if (mustPreserveNames) reporter.log('Preserving names.');
2648 2650
2649 if (mustRetainMetadata) { 2651 if (mustRetainMetadata) {
2650 compiler.log('Retaining metadata.'); 2652 reporter.log('Retaining metadata.');
2651 2653
2652 compiler.libraryLoader.libraries.forEach(retainMetadataOf); 2654 compiler.libraryLoader.libraries.forEach(retainMetadataOf);
2653 if (!enqueuer.isResolutionQueue) { 2655 if (!enqueuer.isResolutionQueue) {
2654 for (Dependency dependency in metadataConstants) { 2656 for (Dependency dependency in metadataConstants) {
2655 registerCompileTimeConstant( 2657 registerCompileTimeConstant(
2656 dependency.constant, 2658 dependency.constant,
2657 new CodegenRegistry(compiler, 2659 new CodegenRegistry(compiler,
2658 dependency.annotatedElement.analyzableElement.treeElements), 2660 dependency.annotatedElement.analyzableElement.treeElements),
2659 addForEmission: false); 2661 addForEmission: false);
2660 } 2662 }
(...skipping 26 matching lines...) Expand all
2687 for (MetadataAnnotation metadata in element.implementation.metadata) { 2689 for (MetadataAnnotation metadata in element.implementation.metadata) {
2688 metadata.ensureResolved(resolution); 2690 metadata.ensureResolved(resolution);
2689 ConstantValue constantValue = 2691 ConstantValue constantValue =
2690 compiler.constants.getConstantValue(metadata.constant); 2692 compiler.constants.getConstantValue(metadata.constant);
2691 if (!constantValue.isConstructedObject) continue; 2693 if (!constantValue.isConstructedObject) continue;
2692 ObjectConstantValue value = constantValue; 2694 ObjectConstantValue value = constantValue;
2693 ClassElement cls = value.type.element; 2695 ClassElement cls = value.type.element;
2694 if (cls == forceInlineClass) { 2696 if (cls == forceInlineClass) {
2695 hasForceInline = true; 2697 hasForceInline = true;
2696 if (VERBOSE_OPTIMIZER_HINTS) { 2698 if (VERBOSE_OPTIMIZER_HINTS) {
2697 compiler.reportHintMessage( 2699 reporter.reportHintMessage(
2698 element, 2700 element,
2699 MessageKind.GENERIC, 2701 MessageKind.GENERIC,
2700 {'text': "Must inline"}); 2702 {'text': "Must inline"});
2701 } 2703 }
2702 inlineCache.markAsMustInline(element); 2704 inlineCache.markAsMustInline(element);
2703 } else if (cls == noInlineClass) { 2705 } else if (cls == noInlineClass) {
2704 hasNoInline = true; 2706 hasNoInline = true;
2705 if (VERBOSE_OPTIMIZER_HINTS) { 2707 if (VERBOSE_OPTIMIZER_HINTS) {
2706 compiler.reportHintMessage( 2708 reporter.reportHintMessage(
2707 element, 2709 element,
2708 MessageKind.GENERIC, 2710 MessageKind.GENERIC,
2709 {'text': "Cannot inline"}); 2711 {'text': "Cannot inline"});
2710 } 2712 }
2711 inlineCache.markAsNonInlinable(element); 2713 inlineCache.markAsNonInlinable(element);
2712 } else if (cls == noThrowsClass) { 2714 } else if (cls == noThrowsClass) {
2713 hasNoThrows = true; 2715 hasNoThrows = true;
2714 if (!Elements.isStaticOrTopLevelFunction(element)) { 2716 if (!Elements.isStaticOrTopLevelFunction(element)) {
2715 compiler.internalError(element, 2717 reporter.internalError(element,
2716 "@NoThrows() is currently limited to top-level" 2718 "@NoThrows() is currently limited to top-level"
2717 " or static functions"); 2719 " or static functions");
2718 } 2720 }
2719 if (VERBOSE_OPTIMIZER_HINTS) { 2721 if (VERBOSE_OPTIMIZER_HINTS) {
2720 compiler.reportHintMessage( 2722 reporter.reportHintMessage(
2721 element, 2723 element,
2722 MessageKind.GENERIC, 2724 MessageKind.GENERIC,
2723 {'text': "Cannot throw"}); 2725 {'text': "Cannot throw"});
2724 } 2726 }
2725 compiler.world.registerCannotThrow(element); 2727 compiler.world.registerCannotThrow(element);
2726 } else if (cls == noSideEffectsClass) { 2728 } else if (cls == noSideEffectsClass) {
2727 hasNoSideEffects = true; 2729 hasNoSideEffects = true;
2728 if (VERBOSE_OPTIMIZER_HINTS) { 2730 if (VERBOSE_OPTIMIZER_HINTS) {
2729 compiler.reportHintMessage( 2731 reporter.reportHintMessage(
2730 element, 2732 element,
2731 MessageKind.GENERIC, 2733 MessageKind.GENERIC,
2732 {'text': "Has no side effects"}); 2734 {'text': "Has no side effects"});
2733 } 2735 }
2734 compiler.world.registerSideEffectsFree(element); 2736 compiler.world.registerSideEffectsFree(element);
2735 } 2737 }
2736 } 2738 }
2737 if (hasForceInline && hasNoInline) { 2739 if (hasForceInline && hasNoInline) {
2738 compiler.internalError(element, 2740 reporter.internalError(element,
2739 "@ForceInline() must not be used with @NoInline."); 2741 "@ForceInline() must not be used with @NoInline.");
2740 } 2742 }
2741 if (hasNoThrows && !hasNoInline) { 2743 if (hasNoThrows && !hasNoInline) {
2742 compiler.internalError(element, 2744 reporter.internalError(element,
2743 "@NoThrows() should always be combined with @NoInline."); 2745 "@NoThrows() should always be combined with @NoInline.");
2744 } 2746 }
2745 if (hasNoSideEffects && !hasNoInline) { 2747 if (hasNoSideEffects && !hasNoInline) {
2746 compiler.internalError(element, 2748 reporter.internalError(element,
2747 "@NoSideEffects() should always be combined with @NoInline."); 2749 "@NoSideEffects() should always be combined with @NoInline.");
2748 } 2750 }
2749 if (element == invokeOnMethod) { 2751 if (element == invokeOnMethod) {
2750 compiler.enabledInvokeOn = true; 2752 compiler.enabledInvokeOn = true;
2751 } 2753 }
2752 } 2754 }
2753 2755
2754 CodeBuffer codeOf(Element element) { 2756 CodeBuffer codeOf(Element element) {
2755 return generatedCode.containsKey(element) 2757 return generatedCode.containsKey(element)
2756 ? jsAst.prettyPrint(generatedCode[element], compiler) 2758 ? jsAst.prettyPrint(generatedCode[element], compiler)
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2826 2828
2827 @override 2829 @override
2828 bool enableDeferredLoadingIfSupported(Spannable node, Registry registry) { 2830 bool enableDeferredLoadingIfSupported(Spannable node, Registry registry) {
2829 registerCheckDeferredIsLoaded(registry); 2831 registerCheckDeferredIsLoaded(registry);
2830 return true; 2832 return true;
2831 } 2833 }
2832 2834
2833 @override 2835 @override
2834 bool enableCodegenWithErrorsIfSupported(Spannable node) { 2836 bool enableCodegenWithErrorsIfSupported(Spannable node) {
2835 if (compiler.useCpsIr) { 2837 if (compiler.useCpsIr) {
2836 compiler.reportHintMessage( 2838 reporter.reportHintMessage(
2837 node, 2839 node,
2838 MessageKind.GENERIC, 2840 MessageKind.GENERIC,
2839 {'text': "Generation of code with compile time errors is currently " 2841 {'text': "Generation of code with compile time errors is currently "
2840 "not supported with the CPS IR."}); 2842 "not supported with the CPS IR."});
2841 return false; 2843 return false;
2842 } 2844 }
2843 return true; 2845 return true;
2844 } 2846 }
2845 2847
2846 jsAst.Expression rewriteAsync(FunctionElement element, 2848 jsAst.Expression rewriteAsync(FunctionElement element,
2847 jsAst.Expression code) { 2849 jsAst.Expression code) {
2848 AsyncRewriterBase rewriter = null; 2850 AsyncRewriterBase rewriter = null;
2849 jsAst.Name name = namer.methodPropertyName(element); 2851 jsAst.Name name = namer.methodPropertyName(element);
2850 switch (element.asyncMarker) { 2852 switch (element.asyncMarker) {
2851 case AsyncMarker.ASYNC: 2853 case AsyncMarker.ASYNC:
2852 rewriter = new AsyncRewriter( 2854 rewriter = new AsyncRewriter(
2853 compiler, 2855 reporter,
2854 compiler.currentElement, 2856 element,
2855 asyncHelper: 2857 asyncHelper:
2856 emitter.staticFunctionAccess(getAsyncHelper()), 2858 emitter.staticFunctionAccess(getAsyncHelper()),
2857 wrapBody: 2859 wrapBody:
2858 emitter.staticFunctionAccess(getWrapBody()), 2860 emitter.staticFunctionAccess(getWrapBody()),
2859 newCompleter: emitter.staticFunctionAccess( 2861 newCompleter: emitter.staticFunctionAccess(
2860 getSyncCompleterConstructor()), 2862 getSyncCompleterConstructor()),
2861 safeVariableName: namer.safeVariablePrefixForAsyncRewrite, 2863 safeVariableName: namer.safeVariablePrefixForAsyncRewrite,
2862 bodyName: namer.deriveAsyncBodyName(name)); 2864 bodyName: namer.deriveAsyncBodyName(name));
2863 break; 2865 break;
2864 case AsyncMarker.SYNC_STAR: 2866 case AsyncMarker.SYNC_STAR:
2865 rewriter = new SyncStarRewriter( 2867 rewriter = new SyncStarRewriter(
2866 compiler, 2868 reporter,
2867 compiler.currentElement, 2869 element,
2868 endOfIteration: emitter.staticFunctionAccess( 2870 endOfIteration: emitter.staticFunctionAccess(
2869 getEndOfIteration()), 2871 getEndOfIteration()),
2870 newIterable: emitter.staticFunctionAccess( 2872 newIterable: emitter.staticFunctionAccess(
2871 getSyncStarIterableConstructor()), 2873 getSyncStarIterableConstructor()),
2872 yieldStarExpression: emitter.staticFunctionAccess( 2874 yieldStarExpression: emitter.staticFunctionAccess(
2873 getYieldStar()), 2875 getYieldStar()),
2874 uncaughtErrorExpression: emitter.staticFunctionAccess( 2876 uncaughtErrorExpression: emitter.staticFunctionAccess(
2875 getSyncStarUncaughtError()), 2877 getSyncStarUncaughtError()),
2876 safeVariableName: namer.safeVariablePrefixForAsyncRewrite, 2878 safeVariableName: namer.safeVariablePrefixForAsyncRewrite,
2877 bodyName: namer.deriveAsyncBodyName(name)); 2879 bodyName: namer.deriveAsyncBodyName(name));
2878 break; 2880 break;
2879 case AsyncMarker.ASYNC_STAR: 2881 case AsyncMarker.ASYNC_STAR:
2880 rewriter = new AsyncStarRewriter( 2882 rewriter = new AsyncStarRewriter(
2881 compiler, 2883 reporter,
2882 compiler.currentElement, 2884 element,
2883 asyncStarHelper: emitter.staticFunctionAccess( 2885 asyncStarHelper: emitter.staticFunctionAccess(
2884 getAsyncStarHelper()), 2886 getAsyncStarHelper()),
2885 streamOfController: emitter.staticFunctionAccess( 2887 streamOfController: emitter.staticFunctionAccess(
2886 getStreamOfController()), 2888 getStreamOfController()),
2887 wrapBody: 2889 wrapBody:
2888 emitter.staticFunctionAccess(getWrapBody()), 2890 emitter.staticFunctionAccess(getWrapBody()),
2889 newController: emitter.staticFunctionAccess( 2891 newController: emitter.staticFunctionAccess(
2890 getASyncStarControllerConstructor()), 2892 getASyncStarControllerConstructor()),
2891 safeVariableName: namer.safeVariablePrefixForAsyncRewrite, 2893 safeVariableName: namer.safeVariablePrefixForAsyncRewrite,
2892 yieldExpression: emitter.staticFunctionAccess( 2894 yieldExpression: emitter.staticFunctionAccess(
(...skipping 16 matching lines...) Expand all
2909 new Uri(scheme: 'package', path: 'expect/expect.dart'); 2911 new Uri(scheme: 'package', path: 'expect/expect.dart');
2910 2912
2911 final Compiler compiler; 2913 final Compiler compiler;
2912 2914
2913 ClassElement expectNoInlineClass; 2915 ClassElement expectNoInlineClass;
2914 ClassElement expectTrustTypeAnnotationsClass; 2916 ClassElement expectTrustTypeAnnotationsClass;
2915 ClassElement expectAssumeDynamicClass; 2917 ClassElement expectAssumeDynamicClass;
2916 2918
2917 JavaScriptBackend get backend => compiler.backend; 2919 JavaScriptBackend get backend => compiler.backend;
2918 2920
2921 DiagnosticReporter get reporter => compiler.reporter;
2922
2919 Annotations(this.compiler); 2923 Annotations(this.compiler);
2920 2924
2921 void onLibraryScanned(LibraryElement library) { 2925 void onLibraryScanned(LibraryElement library) {
2922 if (library.canonicalUri == PACKAGE_EXPECT) { 2926 if (library.canonicalUri == PACKAGE_EXPECT) {
2923 expectNoInlineClass = library.find('NoInline'); 2927 expectNoInlineClass = library.find('NoInline');
2924 expectTrustTypeAnnotationsClass = library.find('TrustTypeAnnotations'); 2928 expectTrustTypeAnnotationsClass = library.find('TrustTypeAnnotations');
2925 expectAssumeDynamicClass = library.find('AssumeDynamic'); 2929 expectAssumeDynamicClass = library.find('AssumeDynamic');
2926 if (expectNoInlineClass == null || 2930 if (expectNoInlineClass == null ||
2927 expectTrustTypeAnnotationsClass == null || 2931 expectTrustTypeAnnotationsClass == null ||
2928 expectAssumeDynamicClass == null) { 2932 expectAssumeDynamicClass == null) {
(...skipping 21 matching lines...) Expand all
2950 } 2954 }
2951 2955
2952 /// Returns `true` if inference of parameter types is disabled for [element]. 2956 /// Returns `true` if inference of parameter types is disabled for [element].
2953 bool assumeDynamic(Element element) { 2957 bool assumeDynamic(Element element) {
2954 return _hasAnnotation(element, expectAssumeDynamicClass); 2958 return _hasAnnotation(element, expectAssumeDynamicClass);
2955 } 2959 }
2956 2960
2957 /// Returns `true` if [element] is annotated with [annotationClass]. 2961 /// Returns `true` if [element] is annotated with [annotationClass].
2958 bool _hasAnnotation(Element element, ClassElement annotationClass) { 2962 bool _hasAnnotation(Element element, ClassElement annotationClass) {
2959 if (annotationClass == null) return false; 2963 if (annotationClass == null) return false;
2960 return compiler.withCurrentElement(element, () { 2964 return reporter.withCurrentElement(element, () {
2961 for (MetadataAnnotation metadata in element.metadata) { 2965 for (MetadataAnnotation metadata in element.metadata) {
2962 assert(invariant(metadata, metadata.constant != null, 2966 assert(invariant(metadata, metadata.constant != null,
2963 message: "Unevaluated metadata constant.")); 2967 message: "Unevaluated metadata constant."));
2964 ConstantValue value = 2968 ConstantValue value =
2965 compiler.constants.getConstantValue(metadata.constant); 2969 compiler.constants.getConstantValue(metadata.constant);
2966 if (value.isConstructedObject) { 2970 if (value.isConstructedObject) {
2967 ConstructedConstantValue constructedConstant = value; 2971 ConstructedConstantValue constructedConstant = value;
2968 if (constructedConstant.type.element == annotationClass) { 2972 if (constructedConstant.type.element == annotationClass) {
2969 return true; 2973 return true;
2970 } 2974 }
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
3237 } 3241 }
3238 } 3242 }
3239 3243
3240 /// Records that [constant] is used by the element behind [registry]. 3244 /// Records that [constant] is used by the element behind [registry].
3241 class Dependency { 3245 class Dependency {
3242 final ConstantValue constant; 3246 final ConstantValue constant;
3243 final Element annotatedElement; 3247 final Element annotatedElement;
3244 3248
3245 const Dependency(this.constant, this.annotatedElement); 3249 const Dependency(this.constant, this.annotatedElement);
3246 } 3250 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js/rewrite_async.dart ('k') | pkg/compiler/lib/src/js_backend/codegen/glue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698