Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The [ConstantHandler] keeps track of compile-time constants, | 8 * The [ConstantHandler] keeps track of compile-time constants, |
| 9 * initializations of global and static fields, and default values of | 9 * initializations of global and static fields, and default values of |
| 10 * optional parameters. | 10 * optional parameters. |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 // constructor to ensure the redirectionTarget has been computed | 627 // constructor to ensure the redirectionTarget has been computed |
| 628 // correctly. Find a way to avoid this. | 628 // correctly. Find a way to avoid this. |
| 629 compiler.analyzeElement(constructor.declaration); | 629 compiler.analyzeElement(constructor.declaration); |
| 630 | 630 |
| 631 InterfaceType type = elements.getType(node); | 631 InterfaceType type = elements.getType(node); |
| 632 List<Constant> evaluateArguments(FunctionElement constructor) { | 632 List<Constant> evaluateArguments(FunctionElement constructor) { |
| 633 Selector selector = elements.getSelector(send); | 633 Selector selector = elements.getSelector(send); |
| 634 return evaluateArgumentsToConstructor( | 634 return evaluateArgumentsToConstructor( |
| 635 node, selector, send.arguments, constructor); | 635 node, selector, send.arguments, constructor); |
| 636 } | 636 } |
| 637 return makeConstructedConstant(node, type, constructor, evaluateArguments); | 637 |
| 638 if (constructor == compiler.intEnvironment | |
| 639 || constructor == compiler.boolEnvironment | |
| 640 || constructor == compiler.stringEnvironment) { | |
| 641 List<Constant> arguments = evaluateArguments(constructor); | |
| 642 Constant firstArgument = arguments[0]; | |
| 643 | |
| 644 if (constructor == compiler.intEnvironment | |
| 645 && !(arguments[1] is NullConstant | |
| 646 || arguments[1] is IntConstant)) { | |
| 647 DartType type = arguments[1].computeType(compiler); | |
| 648 compiler.reportFatalError( | |
| 649 send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE.error, | |
| 650 {'fromType': type, 'toType': compiler.intClass.rawType}); | |
| 651 } | |
| 652 if (constructor == compiler.stringEnvironment | |
| 653 && !(arguments[1] is NullConstant | |
| 654 || arguments[1] is StringConstant)) { | |
| 655 DartType type = arguments[1].computeType(compiler); | |
| 656 compiler.reportFatalError( | |
| 657 send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE.error, | |
| 658 {'fromType': type, 'toType': compiler.stringClass.rawType}); | |
| 659 } | |
| 660 | |
| 661 var value = firstArgument is StringConstant | |
| 662 ? compiler.fromEnvironment(firstArgument.value.slowToString()) | |
| 663 : null; | |
| 664 | |
| 665 if (value == null) { | |
|
kasperl
2013/10/30 13:35:25
Not sure I understand why we want to be so forgivi
Søren Gjesse
2013/10/30 13:59:14
In the VM implementation we throw an error if the
| |
| 666 if (constructor == compiler.boolEnvironment) { | |
|
kasperl
2013/10/30 13:35:25
I'd add a few comments here to explain the behavio
| |
| 667 return constantSystem.createBool(false); | |
| 668 } else { | |
| 669 assert(arguments.length == 2); | |
| 670 return arguments[1]; | |
|
kasperl
2013/10/30 13:35:25
Add local variable for arguments[1] and call it de
ngeoffray
2013/10/30 15:13:59
Done.
| |
| 671 } | |
| 672 } else if (constructor == compiler.intEnvironment) { | |
| 673 return value is int | |
| 674 ? constantSystem.createInt(value) | |
| 675 : arguments[1]; | |
| 676 } else if (constructor == compiler.boolEnvironment) { | |
| 677 return value is bool | |
| 678 ? constantSystem.createBool(value) | |
| 679 : constantSystem.createBool(false); | |
| 680 } else { | |
| 681 assert(constructor == compiler.stringEnvironment); | |
| 682 return value is String | |
| 683 ? constantSystem.createString( | |
| 684 new DartString.literal(value), node) | |
| 685 : arguments[1]; | |
| 686 } | |
| 687 } else { | |
| 688 return makeConstructedConstant( | |
| 689 node, type, constructor, evaluateArguments); | |
| 690 } | |
| 638 } | 691 } |
| 639 | 692 |
| 640 Constant makeConstructedConstant( | 693 Constant makeConstructedConstant( |
| 641 Spannable node, InterfaceType type, FunctionElement constructor, | 694 Spannable node, InterfaceType type, FunctionElement constructor, |
| 642 List<Constant> getArguments(FunctionElement constructor)) { | 695 List<Constant> getArguments(FunctionElement constructor)) { |
| 643 if (constructor.isRedirectingFactory) { | 696 if (constructor.isRedirectingFactory) { |
| 644 type = constructor.computeTargetType(compiler, type); | 697 type = constructor.computeTargetType(compiler, type); |
| 645 } | 698 } |
| 646 | 699 |
| 647 // The redirection chain of this element may not have been resolved through | 700 // The redirection chain of this element may not have been resolved through |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 881 if (fieldValue == null) { | 934 if (fieldValue == null) { |
| 882 // Use the default value. | 935 // Use the default value. |
| 883 fieldValue = handler.compileConstant(field); | 936 fieldValue = handler.compileConstant(field); |
| 884 } | 937 } |
| 885 jsNewArguments.add(fieldValue); | 938 jsNewArguments.add(fieldValue); |
| 886 }, | 939 }, |
| 887 includeSuperAndInjectedMembers: true); | 940 includeSuperAndInjectedMembers: true); |
| 888 return jsNewArguments; | 941 return jsNewArguments; |
| 889 } | 942 } |
| 890 } | 943 } |
| OLD | NEW |