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

Side by Side Diff: pkg/compiler/lib/src/native/behavior.dart

Issue 1803303002: Move all flags to CompilerOptions (first step to stop passing the compiler to (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 import '../common.dart'; 5 import '../common.dart';
6 import '../common/backend_api.dart' show 6 import '../common/backend_api.dart' show
7 ForeignResolver; 7 ForeignResolver;
8 import '../common/resolution.dart' show 8 import '../common/resolution.dart' show
9 Parsing, 9 Parsing,
10 Resolution; 10 Resolution;
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 // Note: For dart:html and other internal libraries we maintain, we can 699 // Note: For dart:html and other internal libraries we maintain, we can
700 // trust the return type and use it to limit what we enqueue. We have to 700 // trust the return type and use it to limit what we enqueue. We have to
701 // be more conservative about JS interop types and assume they can return 701 // be more conservative about JS interop types and assume they can return
702 // anything (unless the user provides the experimental flag to trust the 702 // anything (unless the user provides the experimental flag to trust the
703 // type of js-interop APIs). We do restrict the allocation effects and say 703 // type of js-interop APIs). We do restrict the allocation effects and say
704 // that interop calls create only interop types (which may be unsound if 704 // that interop calls create only interop types (which may be unsound if
705 // an interop call returns a DOM type and declares a dynamic return type, 705 // an interop call returns a DOM type and declares a dynamic return type,
706 // but otherwise we would include a lot of code by default). 706 // but otherwise we would include a lot of code by default).
707 // TODO(sigmund,sra): consider doing something better for numeric types. 707 // TODO(sigmund,sra): consider doing something better for numeric types.
708 behavior.typesReturned.add( 708 behavior.typesReturned.add(
709 !isInterop || compiler.trustJSInteropTypeAnnotations ? returnType 709 !isInterop || compiler.options.trustJSInteropTypeAnnotations
710 : const DynamicType()); 710 ? returnType : const DynamicType());
711 if (!type.returnType.isVoid) { 711 if (!type.returnType.isVoid) {
712 // Declared types are nullable. 712 // Declared types are nullable.
713 behavior.typesReturned.add(compiler.coreTypes.nullType); 713 behavior.typesReturned.add(compiler.coreTypes.nullType);
714 } 714 }
715 behavior._capture(type, compiler.resolution, 715 behavior._capture(type, compiler.resolution,
716 isInterop: isInterop, compiler: compiler); 716 isInterop: isInterop, compiler: compiler);
717 717
718 // TODO(sra): Optional arguments are currently missing from the 718 // TODO(sra): Optional arguments are currently missing from the
719 // DartType. This should be fixed so the following work-around can be 719 // DartType. This should be fixed so the following work-around can be
720 // removed. 720 // removed.
721 method.functionSignature.forEachOptionalParameter( 721 method.functionSignature.forEachOptionalParameter(
722 (ParameterElement parameter) { 722 (ParameterElement parameter) {
723 behavior._escape(parameter.type, compiler.resolution); 723 behavior._escape(parameter.type, compiler.resolution);
724 }); 724 });
725 725
726 behavior._overrideWithAnnotations(method, compiler); 726 behavior._overrideWithAnnotations(method, compiler);
727 return behavior; 727 return behavior;
728 } 728 }
729 729
730 static NativeBehavior ofFieldLoad(MemberElement field, Compiler compiler) { 730 static NativeBehavior ofFieldLoad(MemberElement field, Compiler compiler) {
731 Resolution resolution = compiler.resolution; 731 Resolution resolution = compiler.resolution;
732 DartType type = field.computeType(resolution); 732 DartType type = field.computeType(resolution);
733 var behavior = new NativeBehavior(); 733 var behavior = new NativeBehavior();
734 bool isInterop = compiler.backend.isJsInterop(field); 734 bool isInterop = compiler.backend.isJsInterop(field);
735 // TODO(sigmund,sra): consider doing something better for numeric types. 735 // TODO(sigmund,sra): consider doing something better for numeric types.
736 behavior.typesReturned.add( 736 behavior.typesReturned.add(
737 !isInterop || compiler.trustJSInteropTypeAnnotations ? type 737 !isInterop || compiler.options.trustJSInteropTypeAnnotations
738 : const DynamicType()); 738 ? type : const DynamicType());
739 // Declared types are nullable. 739 // Declared types are nullable.
740 behavior.typesReturned.add(resolution.coreTypes.nullType); 740 behavior.typesReturned.add(resolution.coreTypes.nullType);
741 behavior._capture(type, resolution, 741 behavior._capture(type, resolution,
742 isInterop: isInterop, compiler: compiler); 742 isInterop: isInterop, compiler: compiler);
743 behavior._overrideWithAnnotations(field, compiler); 743 behavior._overrideWithAnnotations(field, compiler);
744 return behavior; 744 return behavior;
745 } 745 }
746 746
747 static NativeBehavior ofFieldStore(MemberElement field, Compiler compiler) { 747 static NativeBehavior ofFieldStore(MemberElement field, Compiler compiler) {
748 Resolution resolution = compiler.resolution; 748 Resolution resolution = compiler.resolution;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 JavaScriptBackend backend = compiler?.backend; 852 JavaScriptBackend backend = compiler?.backend;
853 if (!isInterop) { 853 if (!isInterop) {
854 typesInstantiated.add(type); 854 typesInstantiated.add(type);
855 } else { 855 } else {
856 if (type.element != null && backend.isNative(type.element)) { 856 if (type.element != null && backend.isNative(type.element)) {
857 // Any declared native or interop type (isNative implies isJsInterop) 857 // Any declared native or interop type (isNative implies isJsInterop)
858 // is assumed to be allocated. 858 // is assumed to be allocated.
859 typesInstantiated.add(type); 859 typesInstantiated.add(type);
860 } 860 }
861 861
862 if (!compiler.trustJSInteropTypeAnnotations || 862 if (!compiler.options.trustJSInteropTypeAnnotations ||
863 type.isDynamic || type.isObject) { 863 type.isDynamic || type.isObject) {
864 // By saying that only JS-interop types can be created, we prevent 864 // By saying that only JS-interop types can be created, we prevent
865 // pulling in every other native type (e.g. all of dart:html) when a 865 // pulling in every other native type (e.g. all of dart:html) when a
866 // JS interop API returns dynamic or when we don't trust the type 866 // JS interop API returns dynamic or when we don't trust the type
867 // annotations. This means that to some degree we still use the return 867 // annotations. This means that to some degree we still use the return
868 // type to decide whether to include native types, even if we don't 868 // type to decide whether to include native types, even if we don't
869 // trust the type annotation. 869 // trust the type annotation.
870 ClassElement cls = backend.helpers.jsJavaScriptObjectClass; 870 ClassElement cls = backend.helpers.jsJavaScriptObjectClass;
871 cls.ensureResolved(resolution); 871 cls.ensureResolved(resolution);
872 typesInstantiated.add(cls.thisType); 872 typesInstantiated.add(cls.thisType);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 MessageKind.GENERIC, 911 MessageKind.GENERIC,
912 {'text': "Type '$typeString' not found."}); 912 {'text': "Type '$typeString' not found."});
913 return const DynamicType(); 913 return const DynamicType();
914 } 914 }
915 915
916 static _errorNode(locationNodeOrElement, Parsing parsing) { 916 static _errorNode(locationNodeOrElement, Parsing parsing) {
917 if (locationNodeOrElement is Node) return locationNodeOrElement; 917 if (locationNodeOrElement is Node) return locationNodeOrElement;
918 return locationNodeOrElement.parseNode(parsing); 918 return locationNodeOrElement.parseNode(parsing);
919 } 919 }
920 } 920 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart ('k') | pkg/compiler/lib/src/native/enqueue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698