| 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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 tearOffName = namer.getterName(element); | 444 tearOffName = namer.getterName(element); |
| 445 } | 445 } |
| 446 } | 446 } |
| 447 | 447 |
| 448 if (canTearOff) { | 448 if (canTearOff) { |
| 449 assert(invariant(element, !element.isGenerativeConstructor)); | 449 assert(invariant(element, !element.isGenerativeConstructor)); |
| 450 assert(invariant(element, !element.isGenerativeConstructorBody)); | 450 assert(invariant(element, !element.isGenerativeConstructorBody)); |
| 451 assert(invariant(element, !element.isConstructor)); | 451 assert(invariant(element, !element.isConstructor)); |
| 452 } | 452 } |
| 453 | 453 |
| 454 return new InstanceMethod(element, name, code, needsTearOff: canTearOff, | 454 List<AdapterStubMethod> adapters = needsStubs || canTearOff |
| 455 ? _task.oldEmitter.containerBuilder.generateParameterStubs( |
| 456 element, canTearOff: canTearOff) |
| 457 : const <AdapterStubMethod>[]; |
| 458 |
| 459 String callName = null; |
| 460 if (canTearOff) { |
| 461 Selector callSelector = |
| 462 new Selector.fromElement(element).toCallSelector(); |
| 463 callName = namer.invocationName(callSelector); |
| 464 } |
| 465 |
| 466 return new InstanceMethod(element, name, code, adapters, callName, |
| 467 needsTearOff: canTearOff, |
| 455 tearOffName: tearOffName, isClosure: isClosure, | 468 tearOffName: tearOffName, isClosure: isClosure, |
| 456 hasSuperAlias: hasSuperAlias, canBeApplied: canBeApplied, | 469 hasSuperAlias: hasSuperAlias, canBeApplied: canBeApplied, |
| 457 canBeReflected: canBeReflected, needsStubs: needsStubs); | 470 canBeReflected: canBeReflected, needsStubs: needsStubs); |
| 458 } | 471 } |
| 459 | 472 |
| 460 /// Builds a stub method. | 473 /// Builds a stub method. |
| 461 /// | 474 /// |
| 462 /// Stub methods may have an element that can be used for code-size | 475 /// Stub methods may have an element that can be used for code-size |
| 463 /// attribution. | 476 /// attribution. |
| 464 Method _buildStubMethod(String name, js.Expression code, | 477 Method _buildStubMethod(String name, js.Expression code, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 js.Expression code = stubGenerator.generateOneShotInterceptor(name); | 568 js.Expression code = stubGenerator.generateOneShotInterceptor(name); |
| 556 return new StaticStubMethod(name, holder, code); | 569 return new StaticStubMethod(name, holder, code); |
| 557 }); | 570 }); |
| 558 } | 571 } |
| 559 | 572 |
| 560 StaticDartMethod _buildStaticMethod(FunctionElement element) { | 573 StaticDartMethod _buildStaticMethod(FunctionElement element) { |
| 561 String name = namer.getNameOfMember(element); | 574 String name = namer.getNameOfMember(element); |
| 562 String holder = namer.globalObjectFor(element); | 575 String holder = namer.globalObjectFor(element); |
| 563 js.Expression code = backend.generatedCode[element]; | 576 js.Expression code = backend.generatedCode[element]; |
| 564 | 577 |
| 565 final bool isNotApplyTarget = !element.isConstructor && !element.isAccessor; | 578 final bool isApplyTarget = !element.isConstructor && !element.isAccessor; |
| 566 final bool needsStubs = _methodNeedsStubs(element); | 579 final bool needsStubs = _methodNeedsStubs(element); |
| 567 final bool canBeApplied = _methodCanBeApplied(element); | 580 final bool canBeApplied = _methodCanBeApplied(element); |
| 568 final bool canBeReflected = _methodCanBeReflected(element); | 581 final bool canBeReflected = _methodCanBeReflected(element); |
| 569 | 582 |
| 570 final bool needsTearOff = isNotApplyTarget && (canBeReflected || | 583 final bool needsTearOff = isApplyTarget && |
| 571 universe.staticFunctionsNeedingGetter.contains(element)); | 584 (canBeReflected || |
| 585 universe.staticFunctionsNeedingGetter.contains(element)); |
| 572 | 586 |
| 573 final String tearOffName = | 587 final String tearOffName = |
| 574 needsTearOff ? namer.getStaticClosureName(element) : null; | 588 needsTearOff ? namer.getStaticClosureName(element) : null; |
| 575 | 589 |
| 590 List<AdapterStubMethod> adapters = needsTearOff |
| 591 ? _task.oldEmitter.containerBuilder.generateParameterStubs( |
| 592 element, canTearOff: needsTearOff) |
| 593 : const <AdapterStubMethod>[]; |
| 594 |
| 595 String callName = null; |
| 596 if (needsTearOff) { |
| 597 Selector callSelector = |
| 598 new Selector.fromElement(element).toCallSelector(); |
| 599 callName = namer.invocationName(callSelector); |
| 600 } |
| 601 |
| 576 return new StaticDartMethod(element, | 602 return new StaticDartMethod(element, |
| 577 name, _registry.registerHolder(holder), code, | 603 name, _registry.registerHolder(holder), code, |
| 604 adapters, |
| 605 callName, |
| 578 needsTearOff: needsTearOff, | 606 needsTearOff: needsTearOff, |
| 579 tearOffName: tearOffName, | 607 tearOffName: tearOffName, |
| 580 canBeApplied: canBeApplied, | 608 canBeApplied: canBeApplied, |
| 581 canBeReflected: canBeReflected, | 609 canBeReflected: canBeReflected, |
| 582 needsStubs: needsStubs); | 610 needsStubs: needsStubs); |
| 583 } | 611 } |
| 584 | 612 |
| 585 void _registerConstants(OutputUnit outputUnit, | 613 void _registerConstants(OutputUnit outputUnit, |
| 586 Iterable<ConstantValue> constantValues) { | 614 Iterable<ConstantValue> constantValues) { |
| 587 // `constantValues` is null if an outputUnit doesn't contain any constants. | 615 // `constantValues` is null if an outputUnit doesn't contain any constants. |
| 588 if (constantValues == null) return; | 616 if (constantValues == null) return; |
| 589 for (ConstantValue constantValue in constantValues) { | 617 for (ConstantValue constantValue in constantValues) { |
| 590 _registry.registerConstant(outputUnit, constantValue); | 618 _registry.registerConstant(outputUnit, constantValue); |
| 591 assert(!_constants.containsKey(constantValue)); | 619 assert(!_constants.containsKey(constantValue)); |
| 592 String name = namer.constantName(constantValue); | 620 String name = namer.constantName(constantValue); |
| 593 String constantObject = namer.globalObjectForConstant(constantValue); | 621 String constantObject = namer.globalObjectForConstant(constantValue); |
| 594 Holder holder = _registry.registerHolder(constantObject); | 622 Holder holder = _registry.registerHolder(constantObject); |
| 595 Constant constant = new Constant(name, holder, constantValue); | 623 Constant constant = new Constant(name, holder, constantValue); |
| 596 _constants[constantValue] = constant; | 624 _constants[constantValue] = constant; |
| 597 } | 625 } |
| 598 } | 626 } |
| 599 } | 627 } |
| OLD | NEW |