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 ssa; | 5 part of ssa; |
6 | 6 |
7 class SsaFunctionCompiler implements FunctionCompiler { | 7 class SsaFunctionCompiler implements FunctionCompiler { |
8 final SsaCodeGeneratorTask generator; | 8 final SsaCodeGeneratorTask generator; |
9 final SsaBuilderTask builder; | 9 final SsaBuilderTask builder; |
10 final SsaOptimizerTask optimizer; | 10 final SsaOptimizerTask optimizer; |
(...skipping 5846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5857 ..sourceInformation = sourceInformation); | 5857 ..sourceInformation = sourceInformation); |
5858 } | 5858 } |
5859 } | 5859 } |
5860 | 5860 |
5861 bool _hasNamedParameters(FunctionElement function) { | 5861 bool _hasNamedParameters(FunctionElement function) { |
5862 FunctionSignature params = function.functionSignature; | 5862 FunctionSignature params = function.functionSignature; |
5863 return params.optionalParameterCount > 0 | 5863 return params.optionalParameterCount > 0 |
5864 && params.optionalParametersAreNamed; | 5864 && params.optionalParametersAreNamed; |
5865 } | 5865 } |
5866 | 5866 |
5867 HForeignCode invokeJsInteropFunction(Element element, | 5867 HForeignCode invokeJsInteropFunction(FunctionElement element, |
5868 List<HInstruction> arguments, | 5868 List<HInstruction> arguments, |
5869 SourceInformation sourceInformation) { | 5869 SourceInformation sourceInformation) { |
5870 assert(backend.isJsInterop(element)); | 5870 assert(backend.isJsInterop(element)); |
5871 nativeEmitter.nativeMethods.add(element); | 5871 nativeEmitter.nativeMethods.add(element); |
5872 String templateString; | 5872 String templateString; |
5873 | 5873 |
5874 if (element.isFactoryConstructor && | 5874 if (element.isFactoryConstructor && |
5875 backend.jsInteropAnalysis.hasAnonymousAnnotation(element.contextClass)) { | 5875 backend.jsInteropAnalysis.hasAnonymousAnnotation(element.contextClass)) { |
5876 // Factory constructor that is syntactic sugar for creating a JavaScript | 5876 // Factory constructor that is syntactic sugar for creating a JavaScript |
5877 // object literal. | 5877 // object literal. |
(...skipping 13 matching lines...) Expand all Loading... | |
5891 parameterNameMap[parameter.name] = | 5891 parameterNameMap[parameter.name] = |
5892 new js.InterpolatedExpression(positions++); | 5892 new js.InterpolatedExpression(positions++); |
5893 } | 5893 } |
5894 i++; | 5894 i++; |
5895 }); | 5895 }); |
5896 var codeTemplate = new js.Template(null, | 5896 var codeTemplate = new js.Template(null, |
5897 js.objectLiteral(parameterNameMap)); | 5897 js.objectLiteral(parameterNameMap)); |
5898 | 5898 |
5899 var nativeBehavior = new native.NativeBehavior() | 5899 var nativeBehavior = new native.NativeBehavior() |
5900 ..codeTemplate = codeTemplate; | 5900 ..codeTemplate = codeTemplate; |
5901 if (compiler.trustJSInteropTypeAnnotations) { | |
5902 nativeBehavior.typesReturned.add(constructor.enclosingClass.thisType); | |
5903 } | |
5901 return new HForeignCode( | 5904 return new HForeignCode( |
5902 codeTemplate, | 5905 codeTemplate, |
5903 backend.dynamicType, filteredArguments, | 5906 backend.dynamicType, filteredArguments, |
5904 nativeBehavior: nativeBehavior) | 5907 nativeBehavior: nativeBehavior) |
5905 ..sourceInformation = sourceInformation; | 5908 ..sourceInformation = sourceInformation; |
5906 } | 5909 } |
5907 var target = new HForeignCode(js.js.parseForeignJS( | 5910 var target = new HForeignCode(js.js.parseForeignJS( |
5908 "${backend.namer.fixedBackendPath(element)}." | 5911 "${backend.namer.fixedBackendPath(element)}." |
5909 "${backend.getFixedBackendName(element)}"), | 5912 "${backend.getFixedBackendName(element)}"), |
5910 backend.dynamicType, | 5913 backend.dynamicType, |
5911 <HInstruction>[]); | 5914 <HInstruction>[]); |
5912 add(target); | 5915 add(target); |
5913 // Strip off trailing arguments that were not specified. | 5916 // Strip off trailing arguments that were not specified. |
5914 // we could assert that the trailing arguments are all null. | 5917 // we could assert that the trailing arguments are all null. |
5915 // TODO(jacobr): rewrite named arguments to an object literal matching | 5918 // TODO(jacobr): rewrite named arguments to an object literal matching |
5916 // the factory constructor case. | 5919 // the factory constructor case. |
5917 arguments = arguments.where((arg) => arg != null).toList(); | 5920 arguments = arguments.where((arg) => arg != null).toList(); |
5918 var inputs = <HInstruction>[target]..addAll(arguments); | 5921 var inputs = <HInstruction>[target]..addAll(arguments); |
5919 | 5922 |
5920 js.Template codeTemplate; | 5923 var nativeBehavior = new native.NativeBehavior() |
5921 if (element.isGetter) { | 5924 ..sideEffects.setAllSideEffects(); |
5922 codeTemplate = js.js.parseForeignJS("#"); | |
5923 } else if (element.isSetter) { | |
5924 codeTemplate = js.js.parseForeignJS("# = #"); | |
5925 } else { | |
5926 FunctionElement function = element; | |
5927 FunctionSignature params = function.functionSignature; | |
5928 | 5925 |
5929 var argsStub = <String>[]; | 5926 DartType type = element.isConstructor ? |
5930 for (int i = 0; i < arguments.length; i++) { | 5927 element.enclosingClass.thisType : element.type.returnType; |
5931 argsStub.add('#'); | 5928 // Native behavior effects here are similar to native/behavior.dart. |
5932 } | 5929 // The return type is dynamic if we don't trust js-interop type |
5930 // declarations. | |
5931 nativeBehavior.typesReturned.add( | |
5932 compiler.trustJSInteropTypeAnnotations ? type : const DynamicType()); | |
5933 | 5933 |
5934 if (element.isConstructor) { | 5934 // The allocation effects include the declared type if it is native (which |
5935 codeTemplate = js.js.parseForeignJS("new #(${argsStub.join(",")})"); | 5935 // includes js interop types). |
5936 } else { | 5936 if (type.element != null && backend.isNative(type.element)) { |
5937 codeTemplate = js.js.parseForeignJS("#(${argsStub.join(",")})"); | 5937 nativeBehavior.typesInstantiated.add(type); |
5938 } | |
5939 } | 5938 } |
5940 | 5939 |
5941 var nativeBehavior = new native.NativeBehavior() | 5940 // It also includes any other JS interop type if we don't trust the |
5942 ..codeTemplate = codeTemplate | 5941 // annotation or if is declared too broad. |
5943 ..typesReturned.add( | 5942 if (!compiler.trustJSInteropTypeAnnotations || type.isObject || |
5944 helpers.jsJavaScriptObjectClass.thisType) | 5943 type.isDynamic) { |
5945 ..typesInstantiated.add( | 5944 nativeBehavior.typesInstantiated.add( |
5946 helpers.jsJavaScriptObjectClass.thisType) | 5945 backend.helpers.jsJavaScriptObjectClass.thisType); |
5947 ..sideEffects.setAllSideEffects(); | 5946 } |
5947 | |
5948 String code; | |
Siggi Cherem (dart-lang)
2015/12/01 00:22:16
note this portion is the same as before, I just si
| |
5949 if (element.isGetter) { | |
5950 code = "#"; | |
5951 } else if (element.isSetter) { | |
5952 code = "# = #"; | |
5953 } else { | |
5954 var args = new List.filled(arguments.length, '#').join(','); | |
5955 code = element.isConstructor ? "new #($args)" : "#($args)"; | |
5956 } | |
5957 js.Template codeTemplate = js.js.parseForeignJS(code); | |
5958 nativeBehavior.codeTemplate = codeTemplate; | |
5959 | |
5948 return new HForeignCode( | 5960 return new HForeignCode( |
5949 codeTemplate, | 5961 codeTemplate, |
5950 backend.dynamicType, inputs, | 5962 backend.dynamicType, inputs, |
5951 nativeBehavior: nativeBehavior) | 5963 nativeBehavior: nativeBehavior) |
5952 ..sourceInformation = sourceInformation; | 5964 ..sourceInformation = sourceInformation; |
5953 } | 5965 } |
5954 | 5966 |
5955 void pushInvokeStatic(ast.Node location, | 5967 void pushInvokeStatic(ast.Node location, |
5956 Element element, | 5968 Element element, |
5957 List<HInstruction> arguments, | 5969 List<HInstruction> arguments, |
(...skipping 3203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9161 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 9173 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
9162 unaliased.accept(this, builder); | 9174 unaliased.accept(this, builder); |
9163 } | 9175 } |
9164 | 9176 |
9165 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 9177 void visitDynamicType(DynamicType type, SsaBuilder builder) { |
9166 JavaScriptBackend backend = builder.compiler.backend; | 9178 JavaScriptBackend backend = builder.compiler.backend; |
9167 ClassElement cls = backend.helpers.DynamicRuntimeType; | 9179 ClassElement cls = backend.helpers.DynamicRuntimeType; |
9168 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); | 9180 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); |
9169 } | 9181 } |
9170 } | 9182 } |
OLD | NEW |