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

Side by Side Diff: lib/compiler/implementation/js_backend/emitter.dart

Issue 10911062: Codegen support for the argument definition test. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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
« no previous file with comments | « lib/compiler/implementation/enqueue.dart ('k') | lib/compiler/implementation/resolver.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /** 5 /**
6 * A function element that represents a closure call. The signature is copied 6 * A function element that represents a closure call. The signature is copied
7 * from the given element. 7 * from the given element.
8 */ 8 */
9 class ClosureInvocationElement extends FunctionElement { 9 class ClosureInvocationElement extends FunctionElement {
10 ClosureInvocationElement(SourceString name, 10 ClosureInvocationElement(SourceString name,
11 FunctionElement other) 11 FunctionElement other)
12 : super.from(name, other, other.enclosingElement); 12 : super.from(name, other, other.enclosingElement),
13 methodElement = other;
13 14
14 isInstanceMember() => true; 15 isInstanceMember() => true;
16
17 Element getOutermostEnclosingMemberOrTopLevel() => methodElement;
18
19 /**
20 * The [member] this invocation refers to.
21 */
22 Element methodElement;
15 } 23 }
16 24
17 /** 25 /**
18 * Generates the code for all used classes in the program. Static fields (even 26 * Generates the code for all used classes in the program. Static fields (even
19 * in classes) are ignored, since they can be treated as non-class elements. 27 * in classes) are ignored, since they can be treated as non-class elements.
20 * 28 *
21 * The code for the containing (used) methods must exist in the [:universe:]. 29 * The code for the containing (used) methods must exist in the [:universe:].
22 */ 30 */
23 class CodeEmitterTask extends CompilerTask { 31 class CodeEmitterTask extends CompilerTask {
24 bool needsInheritFunction = false; 32 bool needsInheritFunction = false;
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 // (4) foo$3$c(a, b, c) => foo$4(a, b, c, null); 332 // (4) foo$3$c(a, b, c) => foo$4(a, b, c, null);
325 // (5) foo$3$d(a, b, d) => foo$4(a, b, null, d); 333 // (5) foo$3$d(a, b, d) => foo$4(a, b, null, d);
326 // (6) foo$4$c$d(a, b, c, d) => foo$4(a, b, c, d); 334 // (6) foo$4$c$d(a, b, c, d) => foo$4(a, b, c, d);
327 // (7) Same as (5). 335 // (7) Same as (5).
328 // 336 //
329 // We need to generate a stub for (5) because the order of the 337 // We need to generate a stub for (5) because the order of the
330 // stub arguments and the real method may be different. 338 // stub arguments and the real method may be different.
331 339
332 int count = 0; 340 int count = 0;
333 int indexOfLastOptionalArgumentInParameters = positionalArgumentCount - 1; 341 int indexOfLastOptionalArgumentInParameters = positionalArgumentCount - 1;
342 TreeElements elements =
343 compiler.enqueuer.resolution.getCachedElements(member);
344
334 parameters.forEachParameter((Element element) { 345 parameters.forEachParameter((Element element) {
335 String jsName = JsNames.getValid(element.name.slowToString()); 346 String jsName = JsNames.getValid(element.name.slowToString());
336 if (count < positionalArgumentCount) { 347 if (count < positionalArgumentCount) {
337 parametersBuffer[count] = jsName; 348 parametersBuffer[count] = jsName;
338 argumentsBuffer[count] = jsName; 349 argumentsBuffer[count] = jsName;
339 } else { 350 } else {
340 int index = names.indexOf(element.name); 351 int index = names.indexOf(element.name);
341 if (index != -1) { 352 if (index != -1) {
342 indexOfLastOptionalArgumentInParameters = count; 353 indexOfLastOptionalArgumentInParameters = count;
343 // The order of the named arguments is not the same as the 354 // The order of the named arguments is not the same as the
344 // one in the real method (which is in Dart source order). 355 // one in the real method (which is in Dart source order).
345 argumentsBuffer[count] = jsName; 356 argumentsBuffer[count] = jsName;
346 parametersBuffer[selector.positionalArgumentCount + index] = jsName; 357 parametersBuffer[selector.positionalArgumentCount + index] = jsName;
358 // Note that [elements] may be null for a synthetized [member].
359 } else if (elements != null && elements.isParameterChecked(element)) {
360 CodeBuffer argumentBuffer = new CodeBuffer();
361 handler.writeConstant(argumentBuffer, SentinelConstant.SENTINEL);
362 argumentsBuffer[count] = argumentBuffer.toString();
347 } else { 363 } else {
348 Constant value = handler.initialVariableValues[element]; 364 Constant value = handler.initialVariableValues[element];
349 if (value == null) { 365 if (value == null) {
350 argumentsBuffer[count] = NullConstant.JsNull; 366 argumentsBuffer[count] = NullConstant.JsNull;
351 } else { 367 } else {
352 if (!value.isNull()) { 368 if (!value.isNull()) {
353 // If the value is the null constant, we should not pass it 369 // If the value is the null constant, we should not pass it
354 // down to the native method. 370 // down to the native method.
355 indexOfLastOptionalArgumentInParameters = count; 371 indexOfLastOptionalArgumentInParameters = count;
356 } 372 }
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 sourceName = token.slowToString(); 1215 sourceName = token.slowToString();
1200 } 1216 }
1201 int totalOffset = bufferOffset + offset; 1217 int totalOffset = bufferOffset + offset;
1202 sourceMapBuilder.addMapping( 1218 sourceMapBuilder.addMapping(
1203 sourceFile, token.charOffset, sourceName, totalOffset); 1219 sourceFile, token.charOffset, sourceName, totalOffset);
1204 }); 1220 });
1205 } 1221 }
1206 } 1222 }
1207 1223
1208 typedef void DefineMemberFunction(String invocationName, CodeBuffer definition); 1224 typedef void DefineMemberFunction(String invocationName, CodeBuffer definition);
OLDNEW
« no previous file with comments | « lib/compiler/implementation/enqueue.dart ('k') | lib/compiler/implementation/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698