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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/compile_time_constants.dart

Issue 183743031: Introduce constraints of deferred constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 | sdk/lib/_internal/compiler/implementation/resolution/members.dart » ('j') | 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) 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 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 Constant visitNewExpression(NewExpression node) { 621 Constant visitNewExpression(NewExpression node) {
622 if (!node.isConst()) { 622 if (!node.isConst()) {
623 return signalNotCompileTimeConstant(node); 623 return signalNotCompileTimeConstant(node);
624 } 624 }
625 625
626 Send send = node.send; 626 Send send = node.send;
627 FunctionElement constructor = elements[send]; 627 FunctionElement constructor = elements[send];
628 if (Elements.isUnresolved(constructor)) { 628 if (Elements.isUnresolved(constructor)) {
629 return signalNotCompileTimeConstant(node); 629 return signalNotCompileTimeConstant(node);
630 } 630 }
631
632 // Deferred types can not be used in const instance creation expressions.
633 // Check if the constructor comes from a deferred library.
634 Send selectorSend = node.send.selector.asSend();
635 if (selectorSend != null) {
636 Identifier receiver = selectorSend.receiver.asIdentifier();
637 if (receiver != null) {
638 Element element = elements[receiver];
639 if (element.isPrefix() && (element as PrefixElement).isDeferred) {
640 return signalNotCompileTimeConstant(node,
641 message: MessageKind.DEFERRED_COMPILE_TIME_CONSTANT);
642 }
643 }
644 }
645
631 // TODO(ahe): This is nasty: we must eagerly analyze the 646 // TODO(ahe): This is nasty: we must eagerly analyze the
632 // constructor to ensure the redirectionTarget has been computed 647 // constructor to ensure the redirectionTarget has been computed
633 // correctly. Find a way to avoid this. 648 // correctly. Find a way to avoid this.
634 compiler.analyzeElement(constructor.declaration); 649 compiler.analyzeElement(constructor.declaration);
635 650
636 InterfaceType type = elements.getType(node); 651 InterfaceType type = elements.getType(node);
637 List<Constant> evaluateArguments(FunctionElement constructor) { 652 List<Constant> evaluateArguments(FunctionElement constructor) {
638 Selector selector = elements.getSelector(send); 653 Selector selector = elements.getSelector(send);
639 return evaluateArgumentsToConstructor( 654 return evaluateArgumentsToConstructor(
640 node, selector, send.arguments, constructor); 655 node, selector, send.arguments, constructor);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 evaluator.evaluateConstructorFieldValues(arguments); 747 evaluator.evaluateConstructorFieldValues(arguments);
733 List<Constant> jsNewArguments = evaluator.buildJsNewArguments(classElement); 748 List<Constant> jsNewArguments = evaluator.buildJsNewArguments(classElement);
734 749
735 return new ConstructedConstant(constructedType, jsNewArguments); 750 return new ConstructedConstant(constructedType, jsNewArguments);
736 } 751 }
737 752
738 Constant visitParenthesizedExpression(ParenthesizedExpression node) { 753 Constant visitParenthesizedExpression(ParenthesizedExpression node) {
739 return node.expression.accept(this); 754 return node.expression.accept(this);
740 } 755 }
741 756
742 error(Node node) { 757 error(Node node, MessageKind message) {
743 // TODO(floitsch): get the list of constants that are currently compiled 758 // TODO(floitsch): get the list of constants that are currently compiled
744 // and present some kind of stack-trace. 759 // and present some kind of stack-trace.
745 compiler.reportFatalError( 760 compiler.reportFatalError(node, message);
746 node, MessageKind.NOT_A_COMPILE_TIME_CONSTANT);
747 } 761 }
748 762
749 Constant signalNotCompileTimeConstant(Node node) { 763 Constant signalNotCompileTimeConstant(Node node,
764 {MessageKind message: MessageKind.NOT_A_COMPILE_TIME_CONSTANT}) {
750 if (isEvaluatingConstant) { 765 if (isEvaluatingConstant) {
751 error(node); 766 error(node, message);
752 } 767 }
753 // Else we don't need to do anything. The final handler is only 768 // Else we don't need to do anything. The final handler is only
754 // optimistically trying to compile constants. So it is normal that we 769 // optimistically trying to compile constants. So it is normal that we
755 // sometimes see non-compile time constants. 770 // sometimes see non-compile time constants.
756 // Simply return [:null:] which is used to propagate a failing 771 // Simply return [:null:] which is used to propagate a failing
757 // compile-time compilation. 772 // compile-time compilation.
758 return null; 773 return null;
759 } 774 }
760 } 775 }
761 776
762 class TryCompileTimeConstantEvaluator extends CompileTimeConstantEvaluator { 777 class TryCompileTimeConstantEvaluator extends CompileTimeConstantEvaluator {
763 TryCompileTimeConstantEvaluator(ConstantHandler handler, 778 TryCompileTimeConstantEvaluator(ConstantHandler handler,
764 TreeElements elements, 779 TreeElements elements,
765 Compiler compiler) 780 Compiler compiler)
766 : super(handler, elements, compiler, isConst: true); 781 : super(handler, elements, compiler, isConst: true);
767 782
768 error(Node node) { 783 error(Node node, MessageKind message) {
769 // Just fail without reporting it anywhere. 784 // Just fail without reporting it anywhere.
770 throw new CompileTimeConstantError( 785 throw new CompileTimeConstantError(
771 MessageKind.NOT_A_COMPILE_TIME_CONSTANT, const {}, 786 message, const {}, compiler.terseDiagnostics);
772 compiler.terseDiagnostics);
773 } 787 }
774 } 788 }
775 789
776 class CompileTimeConstantError { 790 class CompileTimeConstantError {
777 final Message message; 791 final Message message;
778 CompileTimeConstantError(MessageKind kind, Map arguments, bool terse) 792 CompileTimeConstantError(MessageKind kind, Map arguments, bool terse)
779 : message = new Message(kind, arguments, terse); 793 : message = new Message(kind, arguments, terse);
780 String toString() => message.toString(); 794 String toString() => message.toString();
781 } 795 }
782 796
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 if (fieldValue == null) { 974 if (fieldValue == null) {
961 // Use the default value. 975 // Use the default value.
962 fieldValue = handler.compileConstant(field); 976 fieldValue = handler.compileConstant(field);
963 } 977 }
964 jsNewArguments.add(fieldValue); 978 jsNewArguments.add(fieldValue);
965 }, 979 },
966 includeSuperAndInjectedMembers: true); 980 includeSuperAndInjectedMembers: true);
967 return jsNewArguments; 981 return jsNewArguments;
968 } 982 }
969 } 983 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/resolution/members.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698