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

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

Issue 19097003: Support new malformed types semantics. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix unittests. Created 7 years, 4 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/dart_backend/placeholder_collector.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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 value = new NullConstant(); 192 value = new NullConstant();
193 } else { 193 } else {
194 Node right = assignment.arguments.head; 194 Node right = assignment.arguments.head;
195 value = 195 value =
196 compileNodeWithDefinitions(right, definitions, isConst: isConst); 196 compileNodeWithDefinitions(right, definitions, isConst: isConst);
197 if (compiler.enableTypeAssertions 197 if (compiler.enableTypeAssertions
198 && value != null 198 && value != null
199 && element.isField()) { 199 && element.isField()) {
200 DartType elementType = element.computeType(compiler); 200 DartType elementType = element.computeType(compiler);
201 DartType constantType = value.computeType(compiler); 201 DartType constantType = value.computeType(compiler);
202 if (elementType.isMalformed || constantType.isMalformed || 202 if (!constantSystem.isSubtype(compiler, constantType, elementType)) {
203 !constantSystem.isSubtype(compiler, constantType, elementType)) {
204 if (isConst) { 203 if (isConst) {
205 compiler.reportFatalError( 204 compiler.reportFatalError(
206 node, MessageKind.NOT_ASSIGNABLE.error, 205 node, MessageKind.NOT_ASSIGNABLE.error,
207 {'fromType': constantType, 'toType': elementType}); 206 {'fromType': constantType, 'toType': elementType});
208 } else { 207 } else {
209 // If the field can be lazily initialized, we will throw 208 // If the field can be lazily initialized, we will throw
210 // the exception at runtime. 209 // the exception at runtime.
211 value = null; 210 value = null;
212 } 211 }
213 } 212 }
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 } 782 }
784 return super.visitSend(send); 783 return super.visitSend(send);
785 } 784 }
786 785
787 void potentiallyCheckType(Node node, Element element, Constant constant) { 786 void potentiallyCheckType(Node node, Element element, Constant constant) {
788 if (compiler.enableTypeAssertions) { 787 if (compiler.enableTypeAssertions) {
789 DartType elementType = element.computeType(compiler); 788 DartType elementType = element.computeType(compiler);
790 DartType constantType = constant.computeType(compiler); 789 DartType constantType = constant.computeType(compiler);
791 // TODO(ngeoffray): Handle type parameters. 790 // TODO(ngeoffray): Handle type parameters.
792 if (elementType.element.isTypeVariable()) return; 791 if (elementType.element.isTypeVariable()) return;
793 if (elementType.isMalformed || constantType.isMalformed || 792 if (!constantSystem.isSubtype(compiler, constantType, elementType)) {
794 !constantSystem.isSubtype(compiler, constantType, elementType)) {
795 compiler.reportFatalError( 793 compiler.reportFatalError(
796 node, MessageKind.NOT_ASSIGNABLE.error, 794 node, MessageKind.NOT_ASSIGNABLE.error,
797 {'fromType': elementType, 'toType': constantType}); 795 {'fromType': elementType, 'toType': constantType});
798 } 796 }
799 } 797 }
800 } 798 }
801 799
802 void updateFieldValue(Node node, Element element, Constant constant) { 800 void updateFieldValue(Node node, Element element, Constant constant) {
803 potentiallyCheckType(node, element, constant); 801 potentiallyCheckType(node, element, constant);
804 fieldValues[element] = constant; 802 fieldValues[element] = constant;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 if (fieldValue == null) { 928 if (fieldValue == null) {
931 // Use the default value. 929 // Use the default value.
932 fieldValue = handler.compileConstant(field); 930 fieldValue = handler.compileConstant(field);
933 } 931 }
934 jsNewArguments.add(fieldValue); 932 jsNewArguments.add(fieldValue);
935 }, 933 },
936 includeSuperAndInjectedMembers: true); 934 includeSuperAndInjectedMembers: true);
937 return jsNewArguments; 935 return jsNewArguments;
938 } 936 }
939 } 937 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/dart_backend/placeholder_collector.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698