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; |
11 final Compiler compiler; | 11 final Compiler compiler; |
12 final JavaScriptBackend backend; | 12 final JavaScriptBackend backend; |
13 | 13 |
14 ParameterStubGenerator(this.compiler, this.namer, this.backend); | 14 ParameterStubGenerator(this.compiler, this.namer, this.backend); |
15 | 15 |
16 Emitter get emitter => backend.emitter.emitter; | 16 Emitter get emitter => backend.emitter.emitter; |
17 CodeEmitterTask get emitterTask => backend.emitter; | 17 CodeEmitterTask get emitterTask => backend.emitter; |
| 18 DiagnosticReporter get reporter => compiler.reporter; |
18 | 19 |
19 bool needsSuperGetter(FunctionElement element) => | 20 bool needsSuperGetter(FunctionElement element) => |
20 compiler.codegenWorld.methodsNeedingSuperGetter.contains(element); | 21 compiler.codegenWorld.methodsNeedingSuperGetter.contains(element); |
21 | 22 |
22 /** | 23 /** |
23 * Generates stubs to handle invocation of methods with optional | 24 * Generates stubs to handle invocation of methods with optional |
24 * arguments. | 25 * arguments. |
25 * | 26 * |
26 * A method like `foo([x])` may be invoked by the following | 27 * A method like `foo([x])` may be invoked by the following |
27 * calls: `foo(), foo(1), foo(x: 1)`. This method generates the stub for the | 28 * calls: `foo(), foo(1), foo(x: 1)`. This method generates the stub for the |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // invoked from a subclass. Then we cannot just redirect, since that | 184 // invoked from a subclass. Then we cannot just redirect, since that |
184 // would invoke the methods of the subclass. We have to compile to: | 185 // would invoke the methods of the subclass. We have to compile to: |
185 // (1) foo$2(a, b) => MyClass.foo$4$c$d.call(this, a, b, null, null) | 186 // (1) foo$2(a, b) => MyClass.foo$4$c$d.call(this, a, b, null, null) |
186 // (2) foo$3$c(a, b, c) => MyClass.foo$4$c$d(this, a, b, c, null); | 187 // (2) foo$3$c(a, b, c) => MyClass.foo$4$c$d(this, a, b, c, null); |
187 // (3) foo$3$d(a, b, d) => MyClass.foo$4$c$d(this, a, b, null, d); | 188 // (3) foo$3$d(a, b, d) => MyClass.foo$4$c$d(this, a, b, null, d); |
188 List<ParameterStubMethod> generateParameterStubs(MethodElement member, | 189 List<ParameterStubMethod> generateParameterStubs(MethodElement member, |
189 {bool canTearOff: true}) { | 190 {bool canTearOff: true}) { |
190 if (member.enclosingElement.isClosure) { | 191 if (member.enclosingElement.isClosure) { |
191 ClosureClassElement cls = member.enclosingElement; | 192 ClosureClassElement cls = member.enclosingElement; |
192 if (cls.supertype.element == backend.boundClosureClass) { | 193 if (cls.supertype.element == backend.boundClosureClass) { |
193 compiler.internalError(cls.methodElement, 'Bound closure1.'); | 194 reporter.internalError(cls.methodElement, 'Bound closure1.'); |
194 } | 195 } |
195 if (cls.methodElement.isInstanceMember) { | 196 if (cls.methodElement.isInstanceMember) { |
196 compiler.internalError(cls.methodElement, 'Bound closure2.'); | 197 reporter.internalError(cls.methodElement, 'Bound closure2.'); |
197 } | 198 } |
198 } | 199 } |
199 | 200 |
200 // The set of selectors that apply to `member`. For example, for | 201 // The set of selectors that apply to `member`. For example, for |
201 // a member `foo(x, [y])` the following selectors may apply: | 202 // a member `foo(x, [y])` the following selectors may apply: |
202 // `foo(x)`, and `foo(x, y)`. | 203 // `foo(x)`, and `foo(x, y)`. |
203 Map<Selector, SelectorConstraints> selectors; | 204 Map<Selector, SelectorConstraints> selectors; |
204 // The set of selectors that apply to `member` if it's name was `call`. | 205 // 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 | 206 // 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 | 207 // function use the name `call`, and we must be able to handle every |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 generateParameterStub(member, selector, null); | 275 generateParameterStub(member, selector, null); |
275 if (stub != null) { | 276 if (stub != null) { |
276 stubs.add(stub); | 277 stubs.add(stub); |
277 } | 278 } |
278 } | 279 } |
279 } | 280 } |
280 | 281 |
281 return stubs; | 282 return stubs; |
282 } | 283 } |
283 } | 284 } |
OLD | NEW |