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

Side by Side Diff: pkg/compiler/lib/src/compile_time_constants.dart

Issue 804333002: Add CoreTypes interface. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 | pkg/compiler/lib/src/compiler.dart » ('j') | pkg/compiler/lib/src/compiler.dart » ('J')
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 /// A [ConstantEnvironment] provides access for constants compiled for variable 7 /// A [ConstantEnvironment] provides access for constants compiled for variable
8 /// initializers. 8 /// initializers.
9 abstract class ConstantEnvironment { 9 abstract class ConstantEnvironment {
10 /// Returns the constant for the initializer of [element]. 10 /// Returns the constant for the initializer of [element].
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 if (elementType.isMalformed && !value.value.isNull) { 155 if (elementType.isMalformed && !value.value.isNull) {
156 if (isConst) { 156 if (isConst) {
157 ErroneousElement element = elementType.element; 157 ErroneousElement element = elementType.element;
158 compiler.reportFatalError( 158 compiler.reportFatalError(
159 node, element.messageKind, element.messageArguments); 159 node, element.messageKind, element.messageArguments);
160 } else { 160 } else {
161 // We need to throw an exception at runtime. 161 // We need to throw an exception at runtime.
162 value = null; 162 value = null;
163 } 163 }
164 } else { 164 } else {
165 DartType constantType = value.value.computeType(compiler); 165 DartType constantType = value.value.getType(compiler.coreTypes);
166 if (!constantSystem.isSubtype(compiler, 166 if (!constantSystem.isSubtype(compiler,
167 constantType, elementType)) { 167 constantType, elementType)) {
168 if (isConst) { 168 if (isConst) {
169 compiler.reportFatalError( 169 compiler.reportFatalError(
170 node, MessageKind.NOT_ASSIGNABLE, 170 node, MessageKind.NOT_ASSIGNABLE,
171 {'fromType': constantType, 'toType': elementType}); 171 {'fromType': constantType, 'toType': elementType});
172 } else { 172 } else {
173 // If the field cannot be lazily initialized, we will throw 173 // If the field cannot be lazily initialized, we will throw
174 // the exception at runtime. 174 // the exception at runtime.
175 value = null; 175 value = null;
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 478
479 // TODO(floitsch): provide better error-messages. 479 // TODO(floitsch): provide better error-messages.
480 AstConstant visitSend(Send send) { 480 AstConstant visitSend(Send send) {
481 Element element = elements[send]; 481 Element element = elements[send];
482 if (send.isPropertyAccess) { 482 if (send.isPropertyAccess) {
483 if (isDeferredUse(send)) { 483 if (isDeferredUse(send)) {
484 return signalNotCompileTimeConstant(send, 484 return signalNotCompileTimeConstant(send,
485 message: MessageKind.DEFERRED_COMPILE_TIME_CONSTANT); 485 message: MessageKind.DEFERRED_COMPILE_TIME_CONSTANT);
486 } 486 }
487 if (Elements.isStaticOrTopLevelFunction(element)) { 487 if (Elements.isStaticOrTopLevelFunction(element)) {
488 FunctionElementX function = element;
489 function.computeType(compiler);
488 return new AstConstant( 490 return new AstConstant(
489 context, send, new FunctionConstantExpression( 491 context, send, new FunctionConstantExpression(
490 new FunctionConstantValue(element), 492 new FunctionConstantValue(function),
491 element)); 493 function));
492 } else if (Elements.isStaticOrTopLevelField(element)) { 494 } else if (Elements.isStaticOrTopLevelField(element)) {
493 ConstantExpression result; 495 ConstantExpression result;
494 if (element.isConst) { 496 if (element.isConst) {
495 result = handler.compileConstant(element); 497 result = handler.compileConstant(element);
496 } else if (element.isFinal && !isEvaluatingConstant) { 498 } else if (element.isFinal && !isEvaluatingConstant) {
497 result = handler.compileVariable(element); 499 result = handler.compileVariable(element);
498 } 500 }
499 if (result != null) { 501 if (result != null) {
500 return new AstConstant( 502 return new AstConstant(
501 context, send, 503 context, send,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 left.expression, op.source, right.expression)); 596 left.expression, op.source, right.expression));
595 } 597 }
596 return signalNotCompileTimeConstant(send); 598 return signalNotCompileTimeConstant(send);
597 } 599 }
598 600
599 AstConstant visitConditional(Conditional node) { 601 AstConstant visitConditional(Conditional node) {
600 AstConstant condition = evaluate(node.condition); 602 AstConstant condition = evaluate(node.condition);
601 if (condition == null) { 603 if (condition == null) {
602 return null; 604 return null;
603 } else if (!condition.value.isBool) { 605 } else if (!condition.value.isBool) {
604 DartType conditionType = condition.value.computeType(compiler); 606 DartType conditionType = condition.value.getType(compiler.coreTypes);
605 if (isEvaluatingConstant) { 607 if (isEvaluatingConstant) {
606 compiler.reportFatalError( 608 compiler.reportFatalError(
607 node.condition, MessageKind.NOT_ASSIGNABLE, 609 node.condition, MessageKind.NOT_ASSIGNABLE,
608 {'fromType': conditionType, 'toType': compiler.boolClass.rawType}); 610 {'fromType': conditionType, 'toType': compiler.boolClass.rawType});
609 } 611 }
610 return null; 612 return null;
611 } 613 }
612 AstConstant thenExpression = evaluate(node.thenExpression); 614 AstConstant thenExpression = evaluate(node.thenExpression);
613 AstConstant elseExpression = evaluate(node.elseExpression); 615 AstConstant elseExpression = evaluate(node.elseExpression);
614 if (thenExpression == null || elseExpression == null) { 616 if (thenExpression == null || elseExpression == null) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 var firstArgument = normalizedArguments[0].value; 727 var firstArgument = normalizedArguments[0].value;
726 ConstantValue defaultValue = normalizedArguments[1].value; 728 ConstantValue defaultValue = normalizedArguments[1].value;
727 729
728 if (firstArgument.isNull) { 730 if (firstArgument.isNull) {
729 compiler.reportFatalError( 731 compiler.reportFatalError(
730 send.arguments.head, MessageKind.NULL_NOT_ALLOWED); 732 send.arguments.head, MessageKind.NULL_NOT_ALLOWED);
731 return null; 733 return null;
732 } 734 }
733 735
734 if (!firstArgument.isString) { 736 if (!firstArgument.isString) {
735 DartType type = defaultValue.computeType(compiler); 737 DartType type = defaultValue.getType(compiler.coreTypes);
736 compiler.reportFatalError( 738 compiler.reportFatalError(
737 send.arguments.head, MessageKind.NOT_ASSIGNABLE, 739 send.arguments.head, MessageKind.NOT_ASSIGNABLE,
738 {'fromType': type, 'toType': compiler.stringClass.rawType}); 740 {'fromType': type, 'toType': compiler.stringClass.rawType});
739 return null; 741 return null;
740 } 742 }
741 743
742 if (constructor == compiler.intEnvironment && 744 if (constructor == compiler.intEnvironment &&
743 !(defaultValue.isNull || defaultValue.isInt)) { 745 !(defaultValue.isNull || defaultValue.isInt)) {
744 DartType type = defaultValue.computeType(compiler); 746 DartType type = defaultValue.getType(compiler.coreTypes);
745 compiler.reportFatalError( 747 compiler.reportFatalError(
746 send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE, 748 send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE,
747 {'fromType': type, 'toType': compiler.intClass.rawType}); 749 {'fromType': type, 'toType': compiler.intClass.rawType});
748 return null; 750 return null;
749 } 751 }
750 752
751 if (constructor == compiler.boolEnvironment && 753 if (constructor == compiler.boolEnvironment &&
752 !(defaultValue.isNull || defaultValue.isBool)) { 754 !(defaultValue.isNull || defaultValue.isBool)) {
753 DartType type = defaultValue.computeType(compiler); 755 DartType type = defaultValue.getType(compiler.coreTypes);
754 compiler.reportFatalError( 756 compiler.reportFatalError(
755 send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE, 757 send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE,
756 {'fromType': type, 'toType': compiler.boolClass.rawType}); 758 {'fromType': type, 'toType': compiler.boolClass.rawType});
757 return null; 759 return null;
758 } 760 }
759 761
760 if (constructor == compiler.stringEnvironment && 762 if (constructor == compiler.stringEnvironment &&
761 !(defaultValue.isNull || defaultValue.isString)) { 763 !(defaultValue.isNull || defaultValue.isString)) {
762 DartType type = defaultValue.computeType(compiler); 764 DartType type = defaultValue.getType(compiler.coreTypes);
763 compiler.reportFatalError( 765 compiler.reportFatalError(
764 send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE, 766 send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE,
765 {'fromType': type, 'toType': compiler.stringClass.rawType}); 767 {'fromType': type, 'toType': compiler.stringClass.rawType});
766 return null; 768 return null;
767 } 769 }
768 770
769 String value = 771 String value =
770 compiler.fromEnvironment(firstArgument.primitiveValue.slowToString()); 772 compiler.fromEnvironment(firstArgument.primitiveValue.slowToString());
771 773
772 if (value == null) { 774 if (value == null) {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 return constant; 902 return constant;
901 } 903 }
902 return super.visitSend(send); 904 return super.visitSend(send);
903 } 905 }
904 906
905 void potentiallyCheckType(Node node, 907 void potentiallyCheckType(Node node,
906 TypedElement element, 908 TypedElement element,
907 AstConstant constant) { 909 AstConstant constant) {
908 if (compiler.enableTypeAssertions) { 910 if (compiler.enableTypeAssertions) {
909 DartType elementType = element.type.substByContext(constructedType); 911 DartType elementType = element.type.substByContext(constructedType);
910 DartType constantType = constant.value.computeType(compiler); 912 DartType constantType = constant.value.getType(compiler.coreTypes);
911 if (!constantSystem.isSubtype(compiler, constantType, elementType)) { 913 if (!constantSystem.isSubtype(compiler, constantType, elementType)) {
912 compiler.withCurrentElement(constant.element, () { 914 compiler.withCurrentElement(constant.element, () {
913 compiler.reportFatalError( 915 compiler.reportFatalError(
914 constant.node, MessageKind.NOT_ASSIGNABLE, 916 constant.node, MessageKind.NOT_ASSIGNABLE,
915 {'fromType': constantType, 'toType': elementType}); 917 {'fromType': constantType, 'toType': elementType});
916 }); 918 });
917 } 919 }
918 } 920 }
919 } 921 }
920 922
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 return new AstConstant( 1091 return new AstConstant(
1090 element, 1092 element,
1091 element.initializer != null ? element.initializer : element.node, 1093 element.initializer != null ? element.initializer : element.node,
1092 constant); 1094 constant);
1093 } 1095 }
1094 1096
1095 ConstantValue get value => expression.value; 1097 ConstantValue get value => expression.value;
1096 1098
1097 String toString() => expression.toString(); 1099 String toString() => expression.toString();
1098 } 1100 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/compiler.dart » ('j') | pkg/compiler/lib/src/compiler.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698