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 5825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5836 push( | 5836 push( |
5837 new HInvokeDynamicSetter(selector, mask, null, inputs, type) | 5837 new HInvokeDynamicSetter(selector, mask, null, inputs, type) |
5838 ..sourceInformation = sourceInformation); | 5838 ..sourceInformation = sourceInformation); |
5839 } else { | 5839 } else { |
5840 push( | 5840 push( |
5841 new HInvokeDynamicMethod(selector, mask, inputs, type, isIntercepted) | 5841 new HInvokeDynamicMethod(selector, mask, inputs, type, isIntercepted) |
5842 ..sourceInformation = sourceInformation); | 5842 ..sourceInformation = sourceInformation); |
5843 } | 5843 } |
5844 } | 5844 } |
5845 | 5845 |
| 5846 bool _hasNamedParameters(FunctionElement function) { |
| 5847 FunctionSignature params = function.functionSignature; |
| 5848 return params.optionalParameterCount > 0 |
| 5849 && params.optionalParametersAreNamed; |
| 5850 } |
| 5851 |
5846 HForeignCode invokeJsInteropFunction(Element element, | 5852 HForeignCode invokeJsInteropFunction(Element element, |
5847 List<HInstruction> arguments, | 5853 List<HInstruction> arguments, |
5848 SourceInformation sourceInformation) { | 5854 SourceInformation sourceInformation) { |
5849 assert(backend.isJsInterop(element)); | 5855 assert(backend.isJsInterop(element)); |
5850 nativeEmitter.nativeMethods.add(element); | 5856 nativeEmitter.nativeMethods.add(element); |
5851 String templateString; | 5857 String templateString; |
5852 | 5858 |
5853 if (element.isFactoryConstructor) { | 5859 if (element.isFactoryConstructor && |
5854 // Treat factory constructors as syntactic sugar for creating object | 5860 backend.jsInteropAnalysis.hasAnonymousAnnotation(element.contextClass))
{ |
5855 // literals. | 5861 // Factory constructor that is syntactic sugar for creating a JavaScript |
| 5862 // object literal. |
5856 ConstructorElement constructor = element; | 5863 ConstructorElement constructor = element; |
5857 FunctionSignature params = constructor.functionSignature; | 5864 FunctionSignature params = constructor.functionSignature; |
5858 int i = 0; | 5865 int i = 0; |
5859 int positions = 0; | 5866 int positions = 0; |
5860 var filteredArguments = <HInstruction>[]; | 5867 var filteredArguments = <HInstruction>[]; |
5861 var parameterNameMap = new Map<String, js.Expression>(); | 5868 var parameterNameMap = new Map<String, js.Expression>(); |
5862 params.orderedForEachParameter((ParameterElement parameter) { | 5869 params.orderedForEachParameter((ParameterElement parameter) { |
5863 // TODO(jacobr): throw if parameter names do not match names of property | 5870 // TODO(jacobr): throw if parameter names do not match names of property |
5864 // names in the class. | 5871 // names in the class. |
5865 assert (parameter.isNamed); | 5872 assert (parameter.isNamed); |
5866 if (!parameter.isNamed) { | |
5867 reporter.reportErrorMessage( | |
5868 parameter, MessageKind.GENERIC, | |
5869 {'text': 'All arguments to external constructors of JavaScript ' | |
5870 'interop classes must be named as these constructors ' | |
5871 'are syntactic sugar for object literals.'}); | |
5872 } | |
5873 HInstruction argument = arguments[i]; | 5873 HInstruction argument = arguments[i]; |
5874 if (argument != null) { | 5874 if (argument != null) { |
5875 filteredArguments.add(argument); | 5875 filteredArguments.add(argument); |
5876 parameterNameMap[parameter.name] = | 5876 parameterNameMap[parameter.name] = |
5877 new js.InterpolatedExpression(positions++); | 5877 new js.InterpolatedExpression(positions++); |
5878 } | 5878 } |
5879 i++; | 5879 i++; |
5880 }); | 5880 }); |
5881 var codeTemplate = new js.Template(null, | 5881 var codeTemplate = new js.Template(null, |
5882 js.objectLiteral(parameterNameMap)); | 5882 js.objectLiteral(parameterNameMap)); |
(...skipping 18 matching lines...) Expand all Loading... |
5901 // the factory constructor case. | 5901 // the factory constructor case. |
5902 arguments = arguments.where((arg) => arg != null).toList(); | 5902 arguments = arguments.where((arg) => arg != null).toList(); |
5903 var inputs = <HInstruction>[target]..addAll(arguments); | 5903 var inputs = <HInstruction>[target]..addAll(arguments); |
5904 | 5904 |
5905 js.Template codeTemplate; | 5905 js.Template codeTemplate; |
5906 if (element.isGetter) { | 5906 if (element.isGetter) { |
5907 codeTemplate = js.js.parseForeignJS("#"); | 5907 codeTemplate = js.js.parseForeignJS("#"); |
5908 } else if (element.isSetter) { | 5908 } else if (element.isSetter) { |
5909 codeTemplate = js.js.parseForeignJS("# = #"); | 5909 codeTemplate = js.js.parseForeignJS("# = #"); |
5910 } else { | 5910 } else { |
| 5911 FunctionElement function = element; |
| 5912 FunctionSignature params = function.functionSignature; |
| 5913 |
5911 var argsStub = <String>[]; | 5914 var argsStub = <String>[]; |
5912 for (int i = 0; i < arguments.length; i++) { | 5915 for (int i = 0; i < arguments.length; i++) { |
5913 argsStub.add('#'); | 5916 argsStub.add('#'); |
5914 } | 5917 } |
| 5918 |
5915 if (element.isConstructor) { | 5919 if (element.isConstructor) { |
5916 codeTemplate = js.js.parseForeignJS("new #(${argsStub.join(",")})"); | 5920 codeTemplate = js.js.parseForeignJS("new #(${argsStub.join(",")})"); |
5917 } else { | 5921 } else { |
5918 codeTemplate = js.js.parseForeignJS("#(${argsStub.join(",")})"); | 5922 codeTemplate = js.js.parseForeignJS("#(${argsStub.join(",")})"); |
5919 } | 5923 } |
5920 } | 5924 } |
5921 | 5925 |
5922 var nativeBehavior = new native.NativeBehavior() | 5926 var nativeBehavior = new native.NativeBehavior() |
5923 ..codeTemplate = codeTemplate | 5927 ..codeTemplate = codeTemplate |
5924 ..typesReturned.add( | 5928 ..typesReturned.add( |
(...skipping 3217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9142 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 9146 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
9143 unaliased.accept(this, builder); | 9147 unaliased.accept(this, builder); |
9144 } | 9148 } |
9145 | 9149 |
9146 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 9150 void visitDynamicType(DynamicType type, SsaBuilder builder) { |
9147 JavaScriptBackend backend = builder.compiler.backend; | 9151 JavaScriptBackend backend = builder.compiler.backend; |
9148 ClassElement cls = backend.helpers.DynamicRuntimeType; | 9152 ClassElement cls = backend.helpers.DynamicRuntimeType; |
9149 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); | 9153 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); |
9150 } | 9154 } |
9151 } | 9155 } |
OLD | NEW |