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

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

Issue 940053002: dart2js: add function type to the model. (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
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.js_emitter.program_builder; 5 library dart2js.js_emitter.program_builder;
6 6
7 import 'js_emitter.dart' show computeMixinClass; 7 import 'js_emitter.dart' show computeMixinClass;
8 import 'model.dart'; 8 import 'model.dart';
9 9
10 import '../common.dart'; 10 import '../common.dart';
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 bool isNotApplyTarget = !element.isFunction || element.isAccessor; 497 bool isNotApplyTarget = !element.isFunction || element.isAccessor;
498 498
499 bool canBeReflected = _methodCanBeReflected(element); 499 bool canBeReflected = _methodCanBeReflected(element);
500 bool needsStubs = _methodNeedsStubs(element); 500 bool needsStubs = _methodNeedsStubs(element);
501 bool canBeApplied = _methodCanBeApplied(element); 501 bool canBeApplied = _methodCanBeApplied(element);
502 502
503 String aliasName = backend.isAliasedSuperMember(element) 503 String aliasName = backend.isAliasedSuperMember(element)
504 ? namer.getNameOfAliasedSuperMember(element) 504 ? namer.getNameOfAliasedSuperMember(element)
505 : null; 505 : null;
506 506
507 js.Expression functionType;
floitsch 2015/02/20 11:00:11 Declare the variable closer to its use.
zarah 2015/02/20 12:59:32 Done.
508
507 if (isNotApplyTarget) { 509 if (isNotApplyTarget) {
508 canTearOff = false; 510 canTearOff = false;
509 } else { 511 } else {
510 if (element.enclosingClass.isClosure) { 512 if (element.enclosingClass.isClosure) {
511 canTearOff = false; 513 canTearOff = false;
512 isClosure = true; 514 isClosure = true;
513 } else { 515 } else {
514 // Careful with operators. 516 // Careful with operators.
515 canTearOff = universe.hasInvokedGetter(element, _compiler.world) || 517 canTearOff = universe.hasInvokedGetter(element, _compiler.world) ||
516 (canBeReflected && !element.isOperator); 518 (canBeReflected && !element.isOperator);
(...skipping 20 matching lines...) Expand all
537 if (element.isGenerativeConstructorBody) { 539 if (element.isGenerativeConstructorBody) {
538 // TODO(herhut): Why does this need to be normalized away? We never need 540 // TODO(herhut): Why does this need to be normalized away? We never need
539 // this information anyway as they cannot be torn off or 541 // this information anyway as they cannot be torn off or
540 // reflected. 542 // reflected.
541 var body = element; 543 var body = element;
542 memberType = body.constructor.type; 544 memberType = body.constructor.type;
543 } else { 545 } else {
544 memberType = element.type; 546 memberType = element.type;
545 } 547 }
546 548
549 if (canTearOff || canBeReflected) {
550 functionType = _generateFunctionType(memberType);
551 }
552
547 int requiredParameterCount; 553 int requiredParameterCount;
548 var /* List | Map */ optionalParameterDefaultValues; 554 var /* List | Map */ optionalParameterDefaultValues;
549 if (canBeApplied || canBeReflected) { 555 if (canBeApplied || canBeReflected) {
550 FunctionSignature signature = element.functionSignature; 556 FunctionSignature signature = element.functionSignature;
551 requiredParameterCount = signature.requiredParameterCount; 557 requiredParameterCount = signature.requiredParameterCount;
552 optionalParameterDefaultValues = 558 optionalParameterDefaultValues =
553 _computeParameterDefaultValues(signature); 559 _computeParameterDefaultValues(signature);
554 } 560 }
555 561
556 return new InstanceMethod(element, name, code, 562 return new InstanceMethod(element, name, code,
557 _generateParameterStubs(element, canTearOff), callName, memberType, 563 _generateParameterStubs(element, canTearOff), callName, memberType,
558 needsTearOff: canTearOff, tearOffName: tearOffName, 564 needsTearOff: canTearOff, tearOffName: tearOffName,
559 isClosure: isClosure, aliasName: aliasName, 565 isClosure: isClosure, aliasName: aliasName,
560 canBeApplied: canBeApplied, canBeReflected: canBeReflected, 566 canBeApplied: canBeApplied, canBeReflected: canBeReflected,
561 requiredParameterCount: requiredParameterCount, 567 requiredParameterCount: requiredParameterCount,
562 optionalParameterDefaultValues: optionalParameterDefaultValues); 568 optionalParameterDefaultValues: optionalParameterDefaultValues,
569 functionType: functionType);
570 }
571
572 js.Expression _generateFunctionType(DartType type) {
573 if (type.containsTypeVariables) {
574 js.Expression thisAccess = js.js(r'this.$receiver');
575 return backend.rti.getSignatureEncoding(type, thisAccess);
576 } else {
577 return js.number(backend.emitter.metadataCollector.reifyType(type));
578 }
563 } 579 }
564 580
565 List<ParameterStubMethod> _generateParameterStubs(FunctionElement element, 581 List<ParameterStubMethod> _generateParameterStubs(FunctionElement element,
566 bool canTearOff) { 582 bool canTearOff) {
567 583
568 if (!_methodNeedsStubs(element)) return const <ParameterStubMethod>[]; 584 if (!_methodNeedsStubs(element)) return const <ParameterStubMethod>[];
569 585
570 ParameterStubGenerator generator = 586 ParameterStubGenerator generator =
571 new ParameterStubGenerator(_compiler, namer, backend); 587 new ParameterStubGenerator(_compiler, namer, backend);
572 return generator.generateParameterStubs(element, canTearOff: canTearOff); 588 return generator.generateParameterStubs(element, canTearOff: canTearOff);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 bool canBeApplied = _methodCanBeApplied(element); 701 bool canBeApplied = _methodCanBeApplied(element);
686 bool canBeReflected = _methodCanBeReflected(element); 702 bool canBeReflected = _methodCanBeReflected(element);
687 703
688 bool needsTearOff = isApplyTarget && 704 bool needsTearOff = isApplyTarget &&
689 (canBeReflected || 705 (canBeReflected ||
690 universe.staticFunctionsNeedingGetter.contains(element)); 706 universe.staticFunctionsNeedingGetter.contains(element));
691 707
692 String tearOffName = 708 String tearOffName =
693 needsTearOff ? namer.getStaticClosureName(element) : null; 709 needsTearOff ? namer.getStaticClosureName(element) : null;
694 710
711 js.Expression functionType;
712
695 String callName = null; 713 String callName = null;
696 if (needsTearOff) { 714 if (needsTearOff) {
697 Selector callSelector = 715 Selector callSelector =
698 new Selector.fromElement(element).toCallSelector(); 716 new Selector.fromElement(element).toCallSelector();
699 callName = namer.invocationName(callSelector); 717 callName = namer.invocationName(callSelector);
700 } 718 }
701 719
720 DartType type = element.type;
721 if (needsTearOff || canBeReflected) {
722 functionType = _generateFunctionType(type);
723 }
724
702 int requiredParameterCount; 725 int requiredParameterCount;
703 var /* List | Map */ optionalParameterDefaultValues; 726 var /* List | Map */ optionalParameterDefaultValues;
704 if (canBeApplied || canBeReflected) { 727 if (canBeApplied || canBeReflected) {
705 FunctionSignature signature = element.functionSignature; 728 FunctionSignature signature = element.functionSignature;
706 requiredParameterCount = signature.requiredParameterCount; 729 requiredParameterCount = signature.requiredParameterCount;
707 optionalParameterDefaultValues = 730 optionalParameterDefaultValues =
708 _computeParameterDefaultValues(signature); 731 _computeParameterDefaultValues(signature);
709 } 732 }
710 733
711 // TODO(floitsch): we shouldn't update the registry in the middle of 734 // TODO(floitsch): we shouldn't update the registry in the middle of
712 // building a static method. 735 // building a static method.
713 return new StaticDartMethod(element, 736 return new StaticDartMethod(element,
714 name, _registry.registerHolder(holder), code, 737 name, _registry.registerHolder(holder), code,
715 _generateParameterStubs(element, needsTearOff), 738 _generateParameterStubs(element, needsTearOff),
716 callName, element.type, 739 callName, type,
717 needsTearOff: needsTearOff, 740 needsTearOff: needsTearOff,
718 tearOffName: tearOffName, 741 tearOffName: tearOffName,
719 canBeApplied: canBeApplied, 742 canBeApplied: canBeApplied,
720 canBeReflected: canBeReflected, 743 canBeReflected: canBeReflected,
721 requiredParameterCount: requiredParameterCount, 744 requiredParameterCount: requiredParameterCount,
722 optionalParameterDefaultValues: 745 optionalParameterDefaultValues:
723 optionalParameterDefaultValues); 746 optionalParameterDefaultValues,
747 functionType: functionType);
724 } 748 }
725 749
726 void _registerConstants(OutputUnit outputUnit, 750 void _registerConstants(OutputUnit outputUnit,
727 Iterable<ConstantValue> constantValues) { 751 Iterable<ConstantValue> constantValues) {
728 // `constantValues` is null if an outputUnit doesn't contain any constants. 752 // `constantValues` is null if an outputUnit doesn't contain any constants.
729 if (constantValues == null) return; 753 if (constantValues == null) return;
730 for (ConstantValue constantValue in constantValues) { 754 for (ConstantValue constantValue in constantValues) {
731 _registry.registerConstant(outputUnit, constantValue); 755 _registry.registerConstant(outputUnit, constantValue);
732 assert(!_constants.containsKey(constantValue)); 756 assert(!_constants.containsKey(constantValue));
733 String name = namer.constantName(constantValue); 757 String name = namer.constantName(constantValue);
734 String constantObject = namer.globalObjectForConstant(constantValue); 758 String constantObject = namer.globalObjectForConstant(constantValue);
735 Holder holder = _registry.registerHolder(constantObject); 759 Holder holder = _registry.registerHolder(constantObject);
736 Constant constant = new Constant(name, holder, constantValue); 760 Constant constant = new Constant(name, holder, constantValue);
737 _constants[constantValue] = constant; 761 _constants[constantValue] = constant;
738 } 762 }
739 } 763 }
740 } 764 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698