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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/parameter_stub_generator.dart

Issue 1062913003: Extract CallStructure from Selector. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
OLDNEW
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 20 matching lines...) Expand all
31 * 31 *
32 * Members may be invoked in two ways: directly, or through a closure. In the 32 * Members may be invoked in two ways: directly, or through a closure. In the
33 * latter case the caller invokes the closure's `call` method. This method 33 * latter case the caller invokes the closure's `call` method. This method
34 * accepts two selectors. The returned stub method has the corresponding 34 * accepts two selectors. The returned stub method has the corresponding
35 * name [ParameterStubMethod.name] and [ParameterStubMethod.callName] set if 35 * name [ParameterStubMethod.name] and [ParameterStubMethod.callName] set if
36 * the input selector is non-null (and the member needs a stub). 36 * the input selector is non-null (and the member needs a stub).
37 */ 37 */
38 ParameterStubMethod generateParameterStub(FunctionElement member, 38 ParameterStubMethod generateParameterStub(FunctionElement member,
39 Selector selector, 39 Selector selector,
40 Selector callSelector) { 40 Selector callSelector) {
41 CallStructure callStructure = selector.callStructure;
41 FunctionSignature parameters = member.functionSignature; 42 FunctionSignature parameters = member.functionSignature;
42 int positionalArgumentCount = selector.positionalArgumentCount; 43 int positionalArgumentCount = callStructure.positionalArgumentCount;
43 if (positionalArgumentCount == parameters.parameterCount) { 44 if (positionalArgumentCount == parameters.parameterCount) {
44 assert(selector.namedArgumentCount == 0); 45 assert(callStructure.isUnnamed);
45 return null; 46 return null;
46 } 47 }
47 if (parameters.optionalParametersAreNamed 48 if (parameters.optionalParametersAreNamed &&
48 && selector.namedArgumentCount == parameters.optionalParameterCount) { 49 callStructure.namedArgumentCount == parameters.optionalParameterCount) {
49 // If the selector has the same number of named arguments as the element, 50 // If the selector has the same number of named arguments as the element,
50 // we don't need to add a stub. The call site will hit the method 51 // we don't need to add a stub. The call site will hit the method
51 // directly. 52 // directly.
52 return null; 53 return null;
53 } 54 }
54 JavaScriptConstantCompiler handler = backend.constants; 55 JavaScriptConstantCompiler handler = backend.constants;
55 List<String> names = selector.getOrderedNamedArguments(); 56 List<String> names = callStructure.getOrderedNamedArguments();
56 57
57 bool isInterceptedMethod = backend.isInterceptedMethod(member); 58 bool isInterceptedMethod = backend.isInterceptedMethod(member);
58 59
59 // 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.
60 int extraArgumentCount = isInterceptedMethod ? 1 : 0; 61 int extraArgumentCount = isInterceptedMethod ? 1 : 0;
61 // Use '$receiver' to avoid clashes with other parameter names. Using 62 // Use '$receiver' to avoid clashes with other parameter names. Using
62 // '$receiver' works because namer.safeVariableName used for getting paramet er 63 // '$receiver' works because namer.safeVariableName used for getting paramet er
63 // names never returns a name beginning with a single '$'. 64 // names never returns a name beginning with a single '$'.
64 String receiverArgumentName = r'$receiver'; 65 String receiverArgumentName = r'$receiver';
65 66
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // (3) foo$3$d(a, b, d) => foo$4$c$d(a, b, null, d); 180 // (3) foo$3$d(a, b, d) => foo$4$c$d(a, b, null, d);
180 // (4) No stub generated, call is direct. 181 // (4) No stub generated, call is direct.
181 // (5) No stub generated, call is direct. 182 // (5) No stub generated, call is direct.
182 // 183 //
183 // We need to pay attention if this stub is for a function that has been 184 // We need to pay attention if this stub is for a function that has been
184 // invoked from a subclass. Then we cannot just redirect, since that 185 // invoked from a subclass. Then we cannot just redirect, since that
185 // would invoke the methods of the subclass. We have to compile to: 186 // would invoke the methods of the subclass. We have to compile to:
186 // (1) foo$2(a, b) => MyClass.foo$4$c$d.call(this, a, b, null, null) 187 // (1) foo$2(a, b) => MyClass.foo$4$c$d.call(this, a, b, null, null)
187 // (2) foo$3$c(a, b, c) => MyClass.foo$4$c$d(this, a, b, c, null); 188 // (2) foo$3$c(a, b, c) => MyClass.foo$4$c$d(this, a, b, c, null);
188 // (3) foo$3$d(a, b, d) => MyClass.foo$4$c$d(this, a, b, null, d); 189 // (3) foo$3$d(a, b, d) => MyClass.foo$4$c$d(this, a, b, null, d);
189 List<ParameterStubMethod> generateParameterStubs(FunctionElement member, 190 List<ParameterStubMethod> generateParameterStubs(MethodElement member,
190 {bool canTearOff: true}) { 191 {bool canTearOff: true}) {
191 if (member.enclosingElement.isClosure) { 192 if (member.enclosingElement.isClosure) {
192 ClosureClassElement cls = member.enclosingElement; 193 ClosureClassElement cls = member.enclosingElement;
193 if (cls.supertype.element == backend.boundClosureClass) { 194 if (cls.supertype.element == backend.boundClosureClass) {
194 compiler.internalError(cls.methodElement, 'Bound closure1.'); 195 compiler.internalError(cls.methodElement, 'Bound closure1.');
195 } 196 }
196 if (cls.methodElement.isInstanceMember) { 197 if (cls.methodElement.isInstanceMember) {
197 compiler.internalError(cls.methodElement, 'Bound closure2.'); 198 compiler.internalError(cls.methodElement, 'Bound closure2.');
198 } 199 }
199 } 200 }
200 201
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // For example, for the call-selector `call(x, y)` the renamed selector 237 // For example, for the call-selector `call(x, y)` the renamed selector
237 // for member `foo` would be `foo(x, y)`. 238 // for member `foo` would be `foo(x, y)`.
238 Set<Selector> renamedCallSelectors = 239 Set<Selector> renamedCallSelectors =
239 callSelectors.isEmpty ? emptySelectorSet : new Set<Selector>(); 240 callSelectors.isEmpty ? emptySelectorSet : new Set<Selector>();
240 241
241 Set<Selector> untypedSelectors = new Set<Selector>(); 242 Set<Selector> untypedSelectors = new Set<Selector>();
242 243
243 // Start with the callSelectors since they imply the generation of the 244 // Start with the callSelectors since they imply the generation of the
244 // non-call version. 245 // non-call version.
245 for (Selector selector in callSelectors) { 246 for (Selector selector in callSelectors) {
246 Selector renamedSelector = new Selector.call( 247 Selector renamedSelector = new Selector(
247 member.name, member.library, 248 SelectorKind.CALL,
248 selector.argumentCount, selector.namedArguments); 249 member.memberName,
250 selector.callStructure);
249 renamedCallSelectors.add(renamedSelector); 251 renamedCallSelectors.add(renamedSelector);
250 252
251 if (!renamedSelector.appliesUnnamed(member, compiler.world)) continue; 253 if (!renamedSelector.appliesUnnamed(member, compiler.world)) continue;
252 254
253 if (untypedSelectors.add(renamedSelector.asUntyped)) { 255 if (untypedSelectors.add(renamedSelector.asUntyped)) {
254 ParameterStubMethod stub = 256 ParameterStubMethod stub =
255 generateParameterStub(member, renamedSelector, selector); 257 generateParameterStub(member, renamedSelector, selector);
256 if (stub != null) { 258 if (stub != null) {
257 stubs.add(stub); 259 stubs.add(stub);
258 } 260 }
(...skipping 12 matching lines...) Expand all
271 generateParameterStub(member, selector, null); 273 generateParameterStub(member, selector, null);
272 if (stub != null) { 274 if (stub != null) {
273 stubs.add(stub); 275 stubs.add(stub);
274 } 276 }
275 } 277 }
276 } 278 }
277 279
278 return stubs; 280 return stubs;
279 } 281 }
280 } 282 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698