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

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

Issue 910723002: dart2js: don't emit tear-off data if not needed. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | « no previous file | no next file » | 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library dart2js.new_js_emitter.model_emitter; 5 library dart2js.new_js_emitter.model_emitter;
6 6
7 import '../../dart2jslib.dart' show Compiler; 7 import '../../dart2jslib.dart' show Compiler;
8 import '../../dart_types.dart' show DartType; 8 import '../../dart_types.dart' show DartType;
9 import '../../elements/elements.dart' show ClassElement; 9 import '../../elements/elements.dart' show ClassElement;
10 import '../../js/js.dart' as js; 10 import '../../js/js.dart' as js;
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 } 498 }
499 499
500 /// JavaScript code template that implements parsing of a function descriptor. 500 /// JavaScript code template that implements parsing of a function descriptor.
501 /// Descriptors are used in place of the actual JavaScript function 501 /// Descriptors are used in place of the actual JavaScript function
502 /// definition in the output if additional information needs to be passed to 502 /// definition in the output if additional information needs to be passed to
503 /// facilitate the generation of tearOffs at runtime. The format is an array 503 /// facilitate the generation of tearOffs at runtime. The format is an array
504 /// with the following fields: 504 /// with the following fields:
505 /// 505 ///
506 /// [Method.code] 506 /// [Method.code]
507 /// [DartMethod.callName] 507 /// [DartMethod.callName]
508 /// [InstanceMethod.aliasName]
508 /// [DartMethod.tearOffName] 509 /// [DartMethod.tearOffName]
509 /// [JavaScriptBackend.isInterceptedMethod] 510 /// [JavaScriptBackend.isInterceptedMethod]
510 /// functionType 511 /// functionType
511 /// [InstanceMethod.aliasName]
512 /// 512 ///
513 /// followed by 513 /// followed by
514 /// 514 ///
515 /// [ParameterStubMethod.name] 515 /// [ParameterStubMethod.name]
516 /// [ParameterStubMethod.code] 516 /// [ParameterStubMethod.code]
517 /// 517 ///
518 /// for each stub in [DartMethod.parameterStubs]. 518 /// for each stub in [DartMethod.parameterStubs].
519 519
520 static final String parseFunctionDescriptorBoilerplate = r""" 520 static final String parseFunctionDescriptorBoilerplate = r"""
521 function parseFunctionDescriptor(proto, name, descriptor) { 521 function parseFunctionDescriptor(proto, name, descriptor) {
522 if (descriptor instanceof Array) { 522 if (descriptor instanceof Array) {
523 proto[name] = descriptor[0]; 523 proto[name] = descriptor[0];
524 var funs = [descriptor[0]]; 524 var funs = [descriptor[0]];
525 funs[0].$callName = descriptor[1]; 525 funs[0].$callName = descriptor[1];
526 for (var pos = 6; pos < descriptor.length; pos += 3) { 526 for (var pos = 6; pos < descriptor.length; pos += 3) {
527 var stub = descriptor[pos + 2]; 527 var stub = descriptor[pos + 2];
528 stub.$callName = descriptor[pos + 1]; 528 stub.$callName = descriptor[pos + 1];
529 proto[descriptor[pos]] = stub; 529 proto[descriptor[pos]] = stub;
530 funs.push(stub); 530 funs.push(stub);
531 } 531 }
532 if (descriptor[2] != null) { 532 if (descriptor[3] != null) {
533 var isIntercepted = descriptor[3]; 533 var isIntercepted = descriptor[4];
534 var reflectionInfo = descriptor[4]; 534 var reflectionInfo = descriptor[5];
535 proto[descriptor[2]] = 535 proto[descriptor[3]] =
536 tearOff(funs, reflectionInfo, false, name, isIntercepted); 536 tearOff(funs, reflectionInfo, false, name, isIntercepted);
537 } 537 }
538 // Install the alias for super calls on the prototype chain. 538 // Install the alias for super calls on the prototype chain.
floitsch 2015/02/09 12:41:41 Move this code into right order. First a check for
zarah 2015/02/09 15:52:00 Acknowledged.
539 if (descriptor[5] != null) { 539 if (descriptor[2] != null) {
540 proto[descriptor[5]] = descriptor[0]; 540 proto[descriptor[2]] = descriptor[0];
541 } 541 }
542 } else { 542 } else {
543 proto[name] = descriptor; 543 proto[name] = descriptor;
544 } 544 }
545 } 545 }
546 """; 546 """;
547 547
548 js.Expression _generateFunctionType(DartType memberType) { 548 js.Expression _generateFunctionType(DartType memberType) {
549 if (memberType.containsTypeVariables) { 549 if (memberType.containsTypeVariables) {
550 js.Expression thisAccess = js.js(r'this.$receiver'); 550 js.Expression thisAccess = js.js(r'this.$receiver');
(...skipping 13 matching lines...) Expand all
564 js.Expression callName = stub.callName == null 564 js.Expression callName = stub.callName == null
565 ? new js.LiteralNull() 565 ? new js.LiteralNull()
566 : js.string(stub.callName); 566 : js.string(stub.callName);
567 return [js.string(stub.name), callName, stub.code]; 567 return [js.string(stub.name), callName, stub.code];
568 } 568 }
569 569
570 if (method is InstanceMethod) { 570 if (method is InstanceMethod) {
571 if (method.needsTearOff || method.aliasName != null) { 571 if (method.needsTearOff || method.aliasName != null) {
572 /// See [parseFunctionDescriptorBoilerplate] for a full description of 572 /// See [parseFunctionDescriptorBoilerplate] for a full description of
573 /// the format. 573 /// the format.
574 // [name, [function, callName, tearOffName, isIntercepted, functionType, 574 // [name, [function, callName, aliasName, tearOffName, isIntercepted,
575 // aliasName, stub1_name, stub1_callName, stub1_code, ...] 575 // functionType, stub1_name, stub1_callName, stub1_code, ...]
576 bool isIntercepted = backend.isInterceptedMethod(method.element);
577 var data = [method.code]; 576 var data = [method.code];
578 data.add(js.string(method.callName)); 577 data.add(js.string(method.callName));
579 data.add(js.string(method.tearOffName)); 578
580 data.add(new js.LiteralBool(isIntercepted));
581 data.add(_generateFunctionType(method.type));
582 if (method.aliasName != null) { 579 if (method.aliasName != null) {
583 data.add(js.string(method.aliasName)); 580 data.add(js.string(method.aliasName));
584 } else { 581 } else {
585 data.add(new js.LiteralNull()); 582 data.add(new js.LiteralNull());
586 } 583 }
584
585 if (method.needsTearOff) {
floitsch 2015/02/09 12:41:41 You can only avoid adding these if there aren't an
zarah 2015/02/09 15:52:00 Acknowledged.
586 data.add(js.string(method.tearOffName));
587 bool isIntercepted = backend.isInterceptedMethod(method.element);
588 data.add(new js.LiteralBool(isIntercepted));
589 data.add(_generateFunctionType(method.type));
590 }
591
587 data.addAll(method.parameterStubs.expand(makeNameCallNameCodeTriplet)); 592 data.addAll(method.parameterStubs.expand(makeNameCallNameCodeTriplet));
588 return [js.string(method.name), new js.ArrayInitializer(data)]; 593 return [js.string(method.name), new js.ArrayInitializer(data)];
589 } else { 594 } else {
590 // TODO(floitsch): not the most efficient way... 595 // TODO(floitsch): not the most efficient way...
591 return ([method]..addAll(method.parameterStubs)) 596 return ([method]..addAll(method.parameterStubs))
592 .expand(makeNameCodePair); 597 .expand(makeNameCodePair);
593 } 598 }
594 } else { 599 } else {
595 return makeNameCodePair(method); 600 return makeNameCodePair(method);
596 } 601 }
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 911
907 var end = Date.now(); 912 var end = Date.now();
908 print('Setup: ' + (end - start) + ' ms.'); 913 print('Setup: ' + (end - start) + ' ms.');
909 914
910 #main(); // Start main. 915 #main(); // Start main.
911 916
912 }(Date.now(), #code) 917 }(Date.now(), #code)
913 }"""; 918 }""";
914 919
915 } 920 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698