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

Side by Side Diff: pkg/compiler/lib/src/ssa/codegen.dart

Issue 702423002: Revert "Drop trailing null arguments in generated JS." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 | « no previous file | tests/compiler/dart2js/drop_trailing_null_arguments_test.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 part of ssa; 5 part of ssa;
6 6
7 class SsaCodeGeneratorTask extends CompilerTask { 7 class SsaCodeGeneratorTask extends CompilerTask {
8 8
9 final JavaScriptBackend backend; 9 final JavaScriptBackend backend;
10 10
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 js.Expression result = sequenceElements.removeLast(); 464 js.Expression result = sequenceElements.removeLast();
465 while (sequenceElements.isNotEmpty) { 465 while (sequenceElements.isNotEmpty) {
466 result = new js.Binary(',', sequenceElements.removeLast(), result); 466 result = new js.Binary(',', sequenceElements.removeLast(), result);
467 } 467 }
468 return result; 468 return result;
469 } 469 }
470 } 470 }
471 471
472 /** 472 /**
473 * Only visits the arguments starting at inputs[HInvoke.ARGUMENTS_OFFSET]. 473 * Only visits the arguments starting at inputs[HInvoke.ARGUMENTS_OFFSET].
474 * Also, skip all trailing constant `null` arguments. JavaScript will fill
475 * missing arguments with `undefined` anyway. For functions that rely on
476 * 'arguments.length' in JavaScript, [allArgsRequired] should be set to
477 * `true`.
478 */ 474 */
479 List<js.Expression> visitArguments(List<HInstruction> inputs, 475 List<js.Expression> visitArguments(List<HInstruction> inputs,
480 {int start: HInvoke.ARGUMENTS_OFFSET, 476 {int start: HInvoke.ARGUMENTS_OFFSET}) {
481 bool allArgsRequired: false}) {
482 assert(inputs.length >= start); 477 assert(inputs.length >= start);
483 int max; 478 List<js.Expression> result = new List<js.Expression>(inputs.length - start);
484 if (allArgsRequired) { 479 for (int i = start; i < inputs.length; i++) {
485 max = inputs.length;
486 } else {
487 for (max = inputs.length; max > start; --max) {
488 HInstruction input = inputs[max-1];
489 if (input is! HConstant) break;
490 HConstant constant = input;
491 if (!constant.constant.isNull) break;
492 }
493 }
494 List<js.Expression> result = new List<js.Expression>(max - start);
495 for (int i = start; i < max; i++) {
496 use(inputs[i]); 480 use(inputs[i]);
497 result[i - start] = pop(); 481 result[i - start] = pop();
498 } 482 }
499 return result; 483 return result;
500 } 484 }
501 485
502 bool isVariableDeclared(String variableName) { 486 bool isVariableDeclared(String variableName) {
503 return declaredLocals.contains(variableName) || 487 return declaredLocals.contains(variableName) ||
504 collectedVariableDeclarations.contains(variableName); 488 collectedVariableDeclarations.contains(variableName);
505 } 489 }
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 List<js.Expression> arguments = <js.Expression>[pop()]; 1506 List<js.Expression> arguments = <js.Expression>[pop()];
1523 push(jsPropertyCall(isolate, name, arguments), node); 1507 push(jsPropertyCall(isolate, name, arguments), node);
1524 registry.registerUseInterceptor(); 1508 registry.registerUseInterceptor();
1525 } 1509 }
1526 1510
1527 visitInvokeDynamicMethod(HInvokeDynamicMethod node) { 1511 visitInvokeDynamicMethod(HInvokeDynamicMethod node) {
1528 use(node.receiver); 1512 use(node.receiver);
1529 js.Expression object = pop(); 1513 js.Expression object = pop();
1530 String name = node.selector.name; 1514 String name = node.selector.name;
1531 String methodName; 1515 String methodName;
1532 bool allArgsRequired = false; 1516 List<js.Expression> arguments = visitArguments(node.inputs);
1533 Element target = node.element; 1517 Element target = node.element;
1534 1518
1535 if (target != null && !node.isInterceptedCall) { 1519 if (target != null && !node.isInterceptedCall) {
1536 if (target == backend.jsArrayAdd) { 1520 if (target == backend.jsArrayAdd) {
1537 methodName = 'push'; 1521 methodName = 'push';
1538 allArgsRequired = true;
1539 } else if (target == backend.jsArrayRemoveLast) { 1522 } else if (target == backend.jsArrayRemoveLast) {
1540 methodName = 'pop'; 1523 methodName = 'pop';
1541 } else if (target == backend.jsStringSplit) { 1524 } else if (target == backend.jsStringSplit) {
1542 methodName = 'split'; 1525 methodName = 'split';
1543 // Split returns a List, so we make sure the backend knows the 1526 // Split returns a List, so we make sure the backend knows the
1544 // list class is instantiated. 1527 // list class is instantiated.
1545 registry.registerInstantiatedClass(compiler.listClass); 1528 registry.registerInstantiatedClass(compiler.listClass);
1546 } else if (target.isNative && target.isFunction) { 1529 } else if (target.isNative && target.isFunction
1530 && !node.isInterceptedCall) {
1547 // A direct (i.e. non-interceptor) native call is the result of 1531 // A direct (i.e. non-interceptor) native call is the result of
1548 // optimization. The optimization ensures any type checks or 1532 // optimization. The optimization ensures any type checks or
1549 // conversions have been satisified. 1533 // conversions have been satisified.
1550 methodName = target.fixedBackendName; 1534 methodName = target.fixedBackendName;
1551 // TODO(herhut): Add notion of allArgsRequired to native annotations.
1552 allArgsRequired = true;
1553 } 1535 }
1554 } 1536 }
1555 // TODO(herhut): Add proper calling conventions to encode when arguments
1556 // may be dropped.
1557 List<js.Expression> arguments = visitArguments(node.inputs,
1558 allArgsRequired: allArgsRequired);
1559 1537
1560 if (methodName == null) { 1538 if (methodName == null) {
1561 methodName = backend.namer.invocationName(node.selector); 1539 methodName = backend.namer.invocationName(node.selector);
1562 registerMethodInvoke(node); 1540 registerMethodInvoke(node);
1563 } 1541 }
1564 push(jsPropertyCall(object, methodName, arguments), node); 1542 push(jsPropertyCall(object, methodName, arguments), node);
1565 } 1543 }
1566 1544
1567 void visitInvokeConstructorBody(HInvokeConstructorBody node) { 1545 void visitInvokeConstructorBody(HInvokeConstructorBody node) {
1568 use(node.inputs[0]); 1546 use(node.inputs[0]);
(...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after
2744 js.PropertyAccess accessHelper(String name) { 2722 js.PropertyAccess accessHelper(String name) {
2745 Element helper = backend.findHelper(name); 2723 Element helper = backend.findHelper(name);
2746 if (helper == null) { 2724 if (helper == null) {
2747 // For mocked-up tests. 2725 // For mocked-up tests.
2748 return js.js('(void 0).$name'); 2726 return js.js('(void 0).$name');
2749 } 2727 }
2750 registry.registerStaticUse(helper); 2728 registry.registerStaticUse(helper);
2751 return backend.namer.elementAccess(helper); 2729 return backend.namer.elementAccess(helper);
2752 } 2730 }
2753 } 2731 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/drop_trailing_null_arguments_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698