| OLD | NEW |
| 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 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 if (element.isGenerativeConstructorBody) { | 537 if (element.isGenerativeConstructorBody) { |
| 538 // TODO(herhut): Why does this need to be normalized away? We never need | 538 // TODO(herhut): Why does this need to be normalized away? We never need |
| 539 // this information anyway as they cannot be torn off or | 539 // this information anyway as they cannot be torn off or |
| 540 // reflected. | 540 // reflected. |
| 541 var body = element; | 541 var body = element; |
| 542 memberType = body.constructor.type; | 542 memberType = body.constructor.type; |
| 543 } else { | 543 } else { |
| 544 memberType = element.type; | 544 memberType = element.type; |
| 545 } | 545 } |
| 546 | 546 |
| 547 js.Expression functionType; |
| 548 if (canTearOff || canBeReflected) { |
| 549 functionType = _generateFunctionType(memberType); |
| 550 } |
| 551 |
| 547 int requiredParameterCount; | 552 int requiredParameterCount; |
| 548 var /* List | Map */ optionalParameterDefaultValues; | 553 var /* List | Map */ optionalParameterDefaultValues; |
| 549 if (canBeApplied || canBeReflected) { | 554 if (canBeApplied || canBeReflected) { |
| 550 FunctionSignature signature = element.functionSignature; | 555 FunctionSignature signature = element.functionSignature; |
| 551 requiredParameterCount = signature.requiredParameterCount; | 556 requiredParameterCount = signature.requiredParameterCount; |
| 552 optionalParameterDefaultValues = | 557 optionalParameterDefaultValues = |
| 553 _computeParameterDefaultValues(signature); | 558 _computeParameterDefaultValues(signature); |
| 554 } | 559 } |
| 555 | 560 |
| 556 return new InstanceMethod(element, name, code, | 561 return new InstanceMethod(element, name, code, |
| 557 _generateParameterStubs(element, canTearOff), callName, memberType, | 562 _generateParameterStubs(element, canTearOff), callName, |
| 558 needsTearOff: canTearOff, tearOffName: tearOffName, | 563 needsTearOff: canTearOff, tearOffName: tearOffName, |
| 559 isClosure: isClosure, aliasName: aliasName, | 564 isClosure: isClosure, aliasName: aliasName, |
| 560 canBeApplied: canBeApplied, canBeReflected: canBeReflected, | 565 canBeApplied: canBeApplied, canBeReflected: canBeReflected, |
| 561 requiredParameterCount: requiredParameterCount, | 566 requiredParameterCount: requiredParameterCount, |
| 562 optionalParameterDefaultValues: optionalParameterDefaultValues); | 567 optionalParameterDefaultValues: optionalParameterDefaultValues, |
| 568 functionType: functionType); |
| 569 } |
| 570 |
| 571 js.Expression _generateFunctionType(DartType type) { |
| 572 if (type.containsTypeVariables) { |
| 573 js.Expression thisAccess = js.js(r'this.$receiver'); |
| 574 return backend.rti.getSignatureEncoding(type, thisAccess); |
| 575 } else { |
| 576 return js.number(backend.emitter.metadataCollector.reifyType(type)); |
| 577 } |
| 563 } | 578 } |
| 564 | 579 |
| 565 List<ParameterStubMethod> _generateParameterStubs(FunctionElement element, | 580 List<ParameterStubMethod> _generateParameterStubs(FunctionElement element, |
| 566 bool canTearOff) { | 581 bool canTearOff) { |
| 567 | 582 |
| 568 if (!_methodNeedsStubs(element)) return const <ParameterStubMethod>[]; | 583 if (!_methodNeedsStubs(element)) return const <ParameterStubMethod>[]; |
| 569 | 584 |
| 570 ParameterStubGenerator generator = | 585 ParameterStubGenerator generator = |
| 571 new ParameterStubGenerator(_compiler, namer, backend); | 586 new ParameterStubGenerator(_compiler, namer, backend); |
| 572 return generator.generateParameterStubs(element, canTearOff: canTearOff); | 587 return generator.generateParameterStubs(element, canTearOff: canTearOff); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 bool canBeApplied = _methodCanBeApplied(element); | 700 bool canBeApplied = _methodCanBeApplied(element); |
| 686 bool canBeReflected = _methodCanBeReflected(element); | 701 bool canBeReflected = _methodCanBeReflected(element); |
| 687 | 702 |
| 688 bool needsTearOff = isApplyTarget && | 703 bool needsTearOff = isApplyTarget && |
| 689 (canBeReflected || | 704 (canBeReflected || |
| 690 universe.staticFunctionsNeedingGetter.contains(element)); | 705 universe.staticFunctionsNeedingGetter.contains(element)); |
| 691 | 706 |
| 692 String tearOffName = | 707 String tearOffName = |
| 693 needsTearOff ? namer.getStaticClosureName(element) : null; | 708 needsTearOff ? namer.getStaticClosureName(element) : null; |
| 694 | 709 |
| 710 |
| 695 String callName = null; | 711 String callName = null; |
| 696 if (needsTearOff) { | 712 if (needsTearOff) { |
| 697 Selector callSelector = | 713 Selector callSelector = |
| 698 new Selector.fromElement(element).toCallSelector(); | 714 new Selector.fromElement(element).toCallSelector(); |
| 699 callName = namer.invocationName(callSelector); | 715 callName = namer.invocationName(callSelector); |
| 700 } | 716 } |
| 717 js.Expression functionType; |
| 718 DartType type = element.type; |
| 719 if (needsTearOff || canBeReflected) { |
| 720 functionType = _generateFunctionType(type); |
| 721 } |
| 701 | 722 |
| 702 int requiredParameterCount; | 723 int requiredParameterCount; |
| 703 var /* List | Map */ optionalParameterDefaultValues; | 724 var /* List | Map */ optionalParameterDefaultValues; |
| 704 if (canBeApplied || canBeReflected) { | 725 if (canBeApplied || canBeReflected) { |
| 705 FunctionSignature signature = element.functionSignature; | 726 FunctionSignature signature = element.functionSignature; |
| 706 requiredParameterCount = signature.requiredParameterCount; | 727 requiredParameterCount = signature.requiredParameterCount; |
| 707 optionalParameterDefaultValues = | 728 optionalParameterDefaultValues = |
| 708 _computeParameterDefaultValues(signature); | 729 _computeParameterDefaultValues(signature); |
| 709 } | 730 } |
| 710 | 731 |
| 711 // TODO(floitsch): we shouldn't update the registry in the middle of | 732 // TODO(floitsch): we shouldn't update the registry in the middle of |
| 712 // building a static method. | 733 // building a static method. |
| 713 return new StaticDartMethod(element, | 734 return new StaticDartMethod(element, |
| 714 name, _registry.registerHolder(holder), code, | 735 name, _registry.registerHolder(holder), code, |
| 715 _generateParameterStubs(element, needsTearOff), | 736 _generateParameterStubs(element, needsTearOff), |
| 716 callName, element.type, | 737 callName, |
| 717 needsTearOff: needsTearOff, | 738 needsTearOff: needsTearOff, |
| 718 tearOffName: tearOffName, | 739 tearOffName: tearOffName, |
| 719 canBeApplied: canBeApplied, | 740 canBeApplied: canBeApplied, |
| 720 canBeReflected: canBeReflected, | 741 canBeReflected: canBeReflected, |
| 721 requiredParameterCount: requiredParameterCount, | 742 requiredParameterCount: requiredParameterCount, |
| 722 optionalParameterDefaultValues: | 743 optionalParameterDefaultValues: |
| 723 optionalParameterDefaultValues); | 744 optionalParameterDefaultValues, |
| 745 functionType: functionType); |
| 724 } | 746 } |
| 725 | 747 |
| 726 void _registerConstants(OutputUnit outputUnit, | 748 void _registerConstants(OutputUnit outputUnit, |
| 727 Iterable<ConstantValue> constantValues) { | 749 Iterable<ConstantValue> constantValues) { |
| 728 // `constantValues` is null if an outputUnit doesn't contain any constants. | 750 // `constantValues` is null if an outputUnit doesn't contain any constants. |
| 729 if (constantValues == null) return; | 751 if (constantValues == null) return; |
| 730 for (ConstantValue constantValue in constantValues) { | 752 for (ConstantValue constantValue in constantValues) { |
| 731 _registry.registerConstant(outputUnit, constantValue); | 753 _registry.registerConstant(outputUnit, constantValue); |
| 732 assert(!_constants.containsKey(constantValue)); | 754 assert(!_constants.containsKey(constantValue)); |
| 733 String name = namer.constantName(constantValue); | 755 String name = namer.constantName(constantValue); |
| 734 String constantObject = namer.globalObjectForConstant(constantValue); | 756 String constantObject = namer.globalObjectForConstant(constantValue); |
| 735 Holder holder = _registry.registerHolder(constantObject); | 757 Holder holder = _registry.registerHolder(constantObject); |
| 736 Constant constant = new Constant(name, holder, constantValue); | 758 Constant constant = new Constant(name, holder, constantValue); |
| 737 _constants[constantValue] = constant; | 759 _constants[constantValue] = constant; |
| 738 } | 760 } |
| 739 } | 761 } |
| 740 } | 762 } |
| OLD | NEW |