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

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

Issue 11860008: Stop passing library elements to tons of namer functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Diff against https://codereview.chromium.org/11819060/. Created 7 years, 11 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) 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 js_backend; 5 part of js_backend;
6 6
7 /** 7 /**
8 * A function element that represents a closure call. The signature is copied 8 * A function element that represents a closure call. The signature is copied
9 * from the given element. 9 * from the given element.
10 */ 10 */
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 if (parameters.optionalParametersAreNamed 457 if (parameters.optionalParametersAreNamed
458 && selector.namedArgumentCount == parameters.optionalParameterCount) { 458 && selector.namedArgumentCount == parameters.optionalParameterCount) {
459 // If the selector has the same number of named arguments as 459 // If the selector has the same number of named arguments as
460 // the element, we don't need to add a stub. The call site will 460 // the element, we don't need to add a stub. The call site will
461 // hit the method directly. 461 // hit the method directly.
462 return; 462 return;
463 } 463 }
464 ConstantHandler handler = compiler.constantHandler; 464 ConstantHandler handler = compiler.constantHandler;
465 List<SourceString> names = selector.getOrderedNamedArguments(); 465 List<SourceString> names = selector.getOrderedNamedArguments();
466 466
467 String invocationName = 467 String invocationName = namer.invocationName(selector);
468 namer.instanceMethodInvocationName(member.getLibrary(), member.name,
469 selector);
470 if (alreadyGenerated.contains(invocationName)) return; 468 if (alreadyGenerated.contains(invocationName)) return;
471 alreadyGenerated.add(invocationName); 469 alreadyGenerated.add(invocationName);
472 470
473 JavaScriptBackend backend = compiler.backend; 471 JavaScriptBackend backend = compiler.backend;
474 bool isInterceptorClass = 472 bool isInterceptorClass =
475 backend.isInterceptorClass(member.getEnclosingClass()); 473 backend.isInterceptorClass(member.getEnclosingClass());
476 474
477 // If the method is in an interceptor class, we need to also pass 475 // If the method is in an interceptor class, we need to also pass
478 // the actual receiver. 476 // the actual receiver.
479 int extraArgumentCount = isInterceptorClass ? 1 : 0; 477 int extraArgumentCount = isInterceptorClass ? 1 : 0;
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 void emitInterceptorMethods(ClassBuilder builder) { 1077 void emitInterceptorMethods(ClassBuilder builder) {
1080 JavaScriptBackend backend = compiler.backend; 1078 JavaScriptBackend backend = compiler.backend;
1081 // Emit forwarders for the ObjectInterceptor class. We need to 1079 // Emit forwarders for the ObjectInterceptor class. We need to
1082 // emit all possible sends on intercepted methods. 1080 // emit all possible sends on intercepted methods.
1083 for (Selector selector in backend.usedInterceptors) { 1081 for (Selector selector in backend.usedInterceptors) {
1084 1082
1085 List<js.Parameter> parameters = <js.Parameter>[]; 1083 List<js.Parameter> parameters = <js.Parameter>[];
1086 List<js.Expression> arguments = <js.Expression>[]; 1084 List<js.Expression> arguments = <js.Expression>[];
1087 parameters.add(new js.Parameter('receiver')); 1085 parameters.add(new js.Parameter('receiver'));
1088 1086
1089 String name; 1087 String name = backend.namer.invocationName(selector);
1090 if (selector.isGetter()) { 1088 if (selector.isSetter()) {
1091 name = backend.namer.getterName(selector.library, selector.name);
1092 } else if (selector.isSetter()) {
1093 name = backend.namer.setterName(selector.library, selector.name);
1094 parameters.add(new js.Parameter('value')); 1089 parameters.add(new js.Parameter('value'));
1095 arguments.add(new js.VariableUse('value')); 1090 arguments.add(new js.VariableUse('value'));
1096 } else { 1091 } else {
1097 name = backend.namer.instanceMethodInvocationName(
1098 selector.library, selector.name, selector);
1099 for (int i = 0; i < selector.argumentCount; i++) { 1092 for (int i = 0; i < selector.argumentCount; i++) {
1100 String argName = 'a$i'; 1093 String argName = 'a$i';
1101 parameters.add(new js.Parameter(argName)); 1094 parameters.add(new js.Parameter(argName));
1102 arguments.add(new js.VariableUse(argName)); 1095 arguments.add(new js.VariableUse(argName));
1103 } 1096 }
1104 } 1097 }
1105 js.Fun function = 1098 js.Fun function =
1106 new js.Fun(parameters, 1099 new js.Fun(parameters,
1107 new js.Block( 1100 new js.Block(
1108 <js.Statement>[ 1101 <js.Statement>[
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
1482 1475
1483 closureClass = namer.isolateAccess(closureClassElement); 1476 closureClass = namer.isolateAccess(closureClassElement);
1484 1477
1485 // Cache it. 1478 // Cache it.
1486 if (canBeShared) { 1479 if (canBeShared) {
1487 cache[parameterCount] = closureClass; 1480 cache[parameterCount] = closureClass;
1488 } 1481 }
1489 } 1482 }
1490 1483
1491 // And finally the getter. 1484 // And finally the getter.
1492 String getterName = namer.getterName(member.getLibrary(), member.name); 1485 String getterName = namer.getterName(member);
1493 String targetName = namer.instanceMethodName(member); 1486 String targetName = namer.instanceMethodName(member);
1494 1487
1495 List<js.Parameter> parameters = <js.Parameter>[]; 1488 List<js.Parameter> parameters = <js.Parameter>[];
1496 List<js.Expression> arguments = <js.Expression>[]; 1489 List<js.Expression> arguments = <js.Expression>[];
1497 arguments.add(new js.This()); 1490 arguments.add(new js.This());
1498 arguments.add(js.string(targetName)); 1491 arguments.add(js.string(targetName));
1499 if (inInterceptor) { 1492 if (inInterceptor) {
1500 parameters.add(new js.Parameter(extraArg)); 1493 parameters.add(new js.Parameter(extraArg));
1501 arguments.add(new js.VariableUse(extraArg)); 1494 arguments.add(new js.VariableUse(extraArg));
1502 } 1495 }
(...skipping 23 matching lines...) Expand all
1526 JavaScriptBackend backend = compiler.backend; 1519 JavaScriptBackend backend = compiler.backend;
1527 // If the class is an interceptor class, the stub gets the 1520 // If the class is an interceptor class, the stub gets the
1528 // receiver explicitely and we need to pass it to the getter call. 1521 // receiver explicitely and we need to pass it to the getter call.
1529 bool isInterceptorClass = 1522 bool isInterceptorClass =
1530 backend.isInterceptorClass(member.getEnclosingClass()); 1523 backend.isInterceptorClass(member.getEnclosingClass());
1531 1524
1532 const String receiverArgumentName = r'$receiver'; 1525 const String receiverArgumentName = r'$receiver';
1533 1526
1534 js.Expression buildGetter() { 1527 js.Expression buildGetter() {
1535 if (member.isGetter()) { 1528 if (member.isGetter()) {
1536 String getterName = namer.getterName(member.getLibrary(), member.name); 1529 String getterName = namer.getterName(member);
1537 return new js.VariableUse('this').dot(getterName).callWith( 1530 return new js.VariableUse('this').dot(getterName).callWith(
1538 isInterceptorClass 1531 isInterceptorClass
1539 ? <js.Expression>[new js.VariableUse(receiverArgumentName)] 1532 ? <js.Expression>[new js.VariableUse(receiverArgumentName)]
1540 : <js.Expression>[]); 1533 : <js.Expression>[]);
1541 } else { 1534 } else {
1542 String fieldName = member.hasFixedBackendName() 1535 String fieldName = member.hasFixedBackendName()
1543 ? member.fixedBackendName() 1536 ? member.fixedBackendName()
1544 : namer.instanceFieldName(memberLibrary, member.name); 1537 : namer.instanceFieldName(member);
1545 return new js.VariableUse('this').dot(fieldName); 1538 return new js.VariableUse('this').dot(fieldName);
1546 } 1539 }
1547 } 1540 }
1548 1541
1549 for (Selector selector in selectors) { 1542 for (Selector selector in selectors) {
1550 if (selector.applies(member, compiler)) { 1543 if (selector.applies(member, compiler)) {
1551 String invocationName = 1544 String invocationName = namer.invocationName(selector);
1552 namer.instanceMethodInvocationName(memberLibrary, member.name, 1545 Selector callSelector = new Selector.callClosureFrom(selector);
1553 selector); 1546 String closureCallName = namer.invocationName(callSelector);
1554 SourceString callName = namer.closureInvocationSelectorName;
1555 String closureCallName =
1556 namer.instanceMethodInvocationName(memberLibrary, callName,
1557 selector);
1558 1547
1559 List<js.Parameter> parameters = <js.Parameter>[]; 1548 List<js.Parameter> parameters = <js.Parameter>[];
1560 List<js.Expression> arguments = <js.Expression>[]; 1549 List<js.Expression> arguments = <js.Expression>[];
1561 if (isInterceptorClass) { 1550 if (isInterceptorClass) {
1562 parameters.add(new js.Parameter(receiverArgumentName)); 1551 parameters.add(new js.Parameter(receiverArgumentName));
1563 } 1552 }
1564 1553
1565 for (int i = 0; i < selector.argumentCount; i++) { 1554 for (int i = 0; i < selector.argumentCount; i++) {
1566 String name = 'arg$i'; 1555 String name = 'arg$i';
1567 parameters.add(new js.Parameter(name)); 1556 parameters.add(new js.Parameter(name));
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 1860
1872 String buildIsolateSetup(CodeBuffer buffer, 1861 String buildIsolateSetup(CodeBuffer buffer,
1873 Element appMain, 1862 Element appMain,
1874 Element isolateMain) { 1863 Element isolateMain) {
1875 String mainAccess = "${namer.isolateAccess(appMain)}"; 1864 String mainAccess = "${namer.isolateAccess(appMain)}";
1876 String currentIsolate = "${namer.CURRENT_ISOLATE}"; 1865 String currentIsolate = "${namer.CURRENT_ISOLATE}";
1877 // Since we pass the closurized version of the main method to 1866 // Since we pass the closurized version of the main method to
1878 // the isolate method, we must make sure that it exists. 1867 // the isolate method, we must make sure that it exists.
1879 if (!compiler.codegenWorld.staticFunctionsNeedingGetter.contains(appMain)) { 1868 if (!compiler.codegenWorld.staticFunctionsNeedingGetter.contains(appMain)) {
1880 Selector selector = new Selector.callClosure(0); 1869 Selector selector = new Selector.callClosure(0);
1881 String invocationName = "${namer.closureInvocationName(selector)}"; 1870 String invocationName = namer.invocationName(selector);
1882 buffer.add("$mainAccess.$invocationName = $mainAccess"); 1871 buffer.add("$mainAccess.$invocationName = $mainAccess");
1883 } 1872 }
1884 return "${namer.isolateAccess(isolateMain)}($mainAccess)"; 1873 return "${namer.isolateAccess(isolateMain)}($mainAccess)";
1885 } 1874 }
1886 1875
1887 emitMain(CodeBuffer buffer) { 1876 emitMain(CodeBuffer buffer) {
1888 if (compiler.isMockCompilation) return; 1877 if (compiler.isMockCompilation) return;
1889 Element main = compiler.mainApp.find(Compiler.MAIN); 1878 Element main = compiler.mainApp.find(Compiler.MAIN);
1890 String mainCall = null; 1879 String mainCall = null;
1891 if (compiler.hasIsolateSupport()) { 1880 if (compiler.hasIsolateSupport()) {
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 """; 2156 """;
2168 const String HOOKS_API_USAGE = """ 2157 const String HOOKS_API_USAGE = """
2169 // The code supports the following hooks: 2158 // The code supports the following hooks:
2170 // dartPrint(message) - if this function is defined it is called 2159 // dartPrint(message) - if this function is defined it is called
2171 // instead of the Dart [print] method. 2160 // instead of the Dart [print] method.
2172 // dartMainRunner(main) - if this function is defined, the Dart [main] 2161 // dartMainRunner(main) - if this function is defined, the Dart [main]
2173 // method will not be invoked directly. 2162 // method will not be invoked directly.
2174 // Instead, a closure that will invoke [main] is 2163 // Instead, a closure that will invoke [main] is
2175 // passed to [dartMainRunner]. 2164 // passed to [dartMainRunner].
2176 """; 2165 """;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698