| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
| 6 | 6 |
| 7 class ParameterStubGenerator { | 7 class ParameterStubGenerator { |
| 8 static final Set<Selector> emptySelectorSet = new Set<Selector>(); | 8 static final Set<Selector> emptySelectorSet = new Set<Selector>(); |
| 9 | 9 |
| 10 final Namer namer; | 10 final Namer namer; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 return null; | 53 return null; |
| 54 } | 54 } |
| 55 JavaScriptConstantCompiler handler = backend.constants; | 55 JavaScriptConstantCompiler handler = backend.constants; |
| 56 List<String> names = callStructure.getOrderedNamedArguments(); | 56 List<String> names = callStructure.getOrderedNamedArguments(); |
| 57 | 57 |
| 58 bool isInterceptedMethod = backend.isInterceptedMethod(member); | 58 bool isInterceptedMethod = backend.isInterceptedMethod(member); |
| 59 | 59 |
| 60 // If the method is intercepted, we need to also pass the actual receiver. | 60 // If the method is intercepted, we need to also pass the actual receiver. |
| 61 int extraArgumentCount = isInterceptedMethod ? 1 : 0; | 61 int extraArgumentCount = isInterceptedMethod ? 1 : 0; |
| 62 // Use '$receiver' to avoid clashes with other parameter names. Using | 62 // Use '$receiver' to avoid clashes with other parameter names. Using |
| 63 // '$receiver' works because namer.safeVariableName used for getting paramet
er | 63 // '$receiver' works because namer.safeVariableName used for getting |
| 64 // names never returns a name beginning with a single '$'. | 64 // parameter names never returns a name beginning with a single '$'. |
| 65 String receiverArgumentName = r'$receiver'; | 65 String receiverArgumentName = r'$receiver'; |
| 66 | 66 |
| 67 // The parameters that this stub takes. | 67 // The parameters that this stub takes. |
| 68 List<jsAst.Parameter> parametersBuffer = | 68 List<jsAst.Parameter> parametersBuffer = |
| 69 new List<jsAst.Parameter>(selector.argumentCount + extraArgumentCount); | 69 new List<jsAst.Parameter>(selector.argumentCount + extraArgumentCount); |
| 70 // The arguments that will be passed to the real method. | 70 // The arguments that will be passed to the real method. |
| 71 List<jsAst.Expression> argumentsBuffer = | 71 List<jsAst.Expression> argumentsBuffer = |
| 72 new List<jsAst.Expression>( | 72 new List<jsAst.Expression>( |
| 73 parameters.parameterCount + extraArgumentCount); | 73 parameters.parameterCount + extraArgumentCount); |
| 74 | 74 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 compiler.internalError(cls.methodElement, 'Bound closure1.'); | 193 compiler.internalError(cls.methodElement, 'Bound closure1.'); |
| 194 } | 194 } |
| 195 if (cls.methodElement.isInstanceMember) { | 195 if (cls.methodElement.isInstanceMember) { |
| 196 compiler.internalError(cls.methodElement, 'Bound closure2.'); | 196 compiler.internalError(cls.methodElement, 'Bound closure2.'); |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 | 199 |
| 200 // The set of selectors that apply to `member`. For example, for | 200 // The set of selectors that apply to `member`. For example, for |
| 201 // a member `foo(x, [y])` the following selectors may apply: | 201 // a member `foo(x, [y])` the following selectors may apply: |
| 202 // `foo(x)`, and `foo(x, y)`. | 202 // `foo(x)`, and `foo(x, y)`. |
| 203 Map<Selector, ReceiverMaskSet> selectors; | 203 Map<Selector, SelectorConstraints> selectors; |
| 204 // The set of selectors that apply to `member` if it's name was `call`. | 204 // The set of selectors that apply to `member` if it's name was `call`. |
| 205 // This happens when a member is torn off. In that case calls to the | 205 // This happens when a member is torn off. In that case calls to the |
| 206 // function use the name `call`, and we must be able to handle every | 206 // function use the name `call`, and we must be able to handle every |
| 207 // `call` invocation that matches the signature. For example, for | 207 // `call` invocation that matches the signature. For example, for |
| 208 // a member `foo(x, [y])` the following selectors would be possible | 208 // a member `foo(x, [y])` the following selectors would be possible |
| 209 // call-selectors: `call(x)`, and `call(x, y)`. | 209 // call-selectors: `call(x)`, and `call(x, y)`. |
| 210 Map<Selector, ReceiverMaskSet> callSelectors; | 210 Map<Selector, SelectorConstraints> callSelectors; |
| 211 | 211 |
| 212 // Only instance members (not static methods) need stubs. | 212 // Only instance members (not static methods) need stubs. |
| 213 if (member.isInstanceMember) { | 213 if (member.isInstanceMember) { |
| 214 selectors = compiler.codegenWorld.invocationsByName(member.name); | 214 selectors = compiler.codegenWorld.invocationsByName(member.name); |
| 215 } | 215 } |
| 216 | 216 |
| 217 if (canTearOff) { | 217 if (canTearOff) { |
| 218 String call = namer.closureInvocationSelectorName; | 218 String call = namer.closureInvocationSelectorName; |
| 219 callSelectors = compiler.codegenWorld.invocationsByName(call); | 219 callSelectors = compiler.codegenWorld.invocationsByName(call); |
| 220 } | 220 } |
| 221 | 221 |
| 222 assert(emptySelectorSet.isEmpty); | 222 assert(emptySelectorSet.isEmpty); |
| 223 if (selectors == null) selectors = const <Selector, ReceiverMaskSet>{}; | 223 if (selectors == null) selectors = const <Selector, SelectorConstraints>{}; |
| 224 if (callSelectors == null) callSelectors = | 224 if (callSelectors == null) callSelectors = |
| 225 const <Selector, ReceiverMaskSet>{}; | 225 const <Selector, SelectorConstraints>{}; |
| 226 | 226 |
| 227 List<ParameterStubMethod> stubs = <ParameterStubMethod>[]; | 227 List<ParameterStubMethod> stubs = <ParameterStubMethod>[]; |
| 228 | 228 |
| 229 if (selectors.isEmpty && callSelectors.isEmpty) { | 229 if (selectors.isEmpty && callSelectors.isEmpty) { |
| 230 return stubs; | 230 return stubs; |
| 231 } | 231 } |
| 232 | 232 |
| 233 // For every call-selector the corresponding selector with the name of the | 233 // For every call-selector the corresponding selector with the name of the |
| 234 // member. | 234 // member. |
| 235 // | 235 // |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 generateParameterStub(member, selector, null); | 274 generateParameterStub(member, selector, null); |
| 275 if (stub != null) { | 275 if (stub != null) { |
| 276 stubs.add(stub); | 276 stubs.add(stub); |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 | 280 |
| 281 return stubs; | 281 return stubs; |
| 282 } | 282 } |
| 283 } | 283 } |
| OLD | NEW |