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

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

Issue 10908143: Support check mode for statics. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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 | lib/compiler/implementation/constants.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 /** 5 /**
6 * The [ConstantHandler] keeps track of compile-time constants, 6 * The [ConstantHandler] keeps track of compile-time constants,
7 * initializations of global and static fields, and default values of 7 * initializations of global and static fields, and default values of
8 * optional parameters. 8 * optional parameters.
9 */ 9 */
10 class ConstantHandler extends CompilerTask { 10 class ConstantHandler extends CompilerTask {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 SendSet assignment = node.asSendSet(); 119 SendSet assignment = node.asSendSet();
120 Constant value; 120 Constant value;
121 if (assignment === null) { 121 if (assignment === null) {
122 // No initial value. 122 // No initial value.
123 value = new NullConstant(); 123 value = new NullConstant();
124 } else { 124 } else {
125 Node right = assignment.arguments.head; 125 Node right = assignment.arguments.head;
126 value = 126 value =
127 compileNodeWithDefinitions(right, definitions, isConst: isConst); 127 compileNodeWithDefinitions(right, definitions, isConst: isConst);
128 if (compiler.enableTypeAssertions
129 && value != null
130 && element.isField()) {
131 DartType elementType = element.computeType(compiler);
132 DartType constantType = value.computeType(compiler);
133 if (!compiler.types.isSubtype(constantType, elementType)) {
134 if (isConst) {
135 MessageKind kind = MessageKind.NOT_ASSIGNABLE;
136 compiler.reportError(node, new CompileTimeConstantError(
137 kind, [elementType, constantType]));
138 } else {
139 // If the field can be lazily initialized, we will throw
140 // the exception at runtime.
141 value = null;
142 }
143 }
144 }
128 } 145 }
129 if (value != null) { 146 if (value != null) {
130 initialVariableValues[element] = value; 147 initialVariableValues[element] = value;
131 } else { 148 } else {
132 assert(!isConst); 149 assert(!isConst);
133 lazyStatics.add(element); 150 lazyStatics.add(element);
134 } 151 }
135 pendingVariables.remove(element); 152 pendingVariables.remove(element);
136 return value; 153 return value;
137 }); 154 });
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 Constant visitLiteralList(LiteralList node) { 283 Constant visitLiteralList(LiteralList node) {
267 if (!node.isConst()) { 284 if (!node.isConst()) {
268 return signalNotCompileTimeConstant(node); 285 return signalNotCompileTimeConstant(node);
269 } 286 }
270 List<Constant> arguments = <Constant>[]; 287 List<Constant> arguments = <Constant>[];
271 for (Link<Node> link = node.elements.nodes; 288 for (Link<Node> link = node.elements.nodes;
272 !link.isEmpty(); 289 !link.isEmpty();
273 link = link.tail) { 290 link = link.tail) {
274 arguments.add(evaluateConstant(link.head)); 291 arguments.add(evaluateConstant(link.head));
275 } 292 }
276 // TODO(floitsch): get type from somewhere. 293 // TODO(floitsch): get type parameters.
277 DartType type = null; 294 DartType type = new InterfaceType(compiler.listClass);
278 Constant constant = new ListConstant(type, arguments); 295 Constant constant = new ListConstant(type, arguments);
279 compiler.constantHandler.registerCompileTimeConstant(constant); 296 compiler.constantHandler.registerCompileTimeConstant(constant);
280 return constant; 297 return constant;
281 } 298 }
282 299
283 Constant visitLiteralMap(LiteralMap node) { 300 Constant visitLiteralMap(LiteralMap node) {
284 if (!node.isConst()) { 301 if (!node.isConst()) {
285 signalNotCompileTimeConstant(node); 302 signalNotCompileTimeConstant(node);
286 error(node); 303 error(node);
287 } 304 }
(...skipping 16 matching lines...) Expand all
304 Constant protoValue = null; 321 Constant protoValue = null;
305 for (StringConstant key in keys) { 322 for (StringConstant key in keys) {
306 if (key.value == MapConstant.PROTO_PROPERTY) { 323 if (key.value == MapConstant.PROTO_PROPERTY) {
307 protoValue = map[key]; 324 protoValue = map[key];
308 } else { 325 } else {
309 values.add(map[key]); 326 values.add(map[key]);
310 } 327 }
311 } 328 }
312 bool hasProtoKey = (protoValue !== null); 329 bool hasProtoKey = (protoValue !== null);
313 // TODO(floitsch): this should be a List<String> type. 330 // TODO(floitsch): this should be a List<String> type.
314 DartType keysType = null; 331 DartType keysType = new InterfaceType(compiler.listClass);
315 ListConstant keysList = new ListConstant(keysType, keys); 332 ListConstant keysList = new ListConstant(keysType, keys);
316 compiler.constantHandler.registerCompileTimeConstant(keysList); 333 compiler.constantHandler.registerCompileTimeConstant(keysList);
317 SourceString className = hasProtoKey 334 SourceString className = hasProtoKey
318 ? MapConstant.DART_PROTO_CLASS 335 ? MapConstant.DART_PROTO_CLASS
319 : MapConstant.DART_CLASS; 336 : MapConstant.DART_CLASS;
320 ClassElement classElement = compiler.jsHelperLibrary.find(className); 337 ClassElement classElement = compiler.jsHelperLibrary.find(className);
321 classElement.ensureResolved(compiler); 338 classElement.ensureResolved(compiler);
322 // TODO(floitsch): copy over the generic type. 339 // TODO(floitsch): copy over the generic type.
323 DartType type = new InterfaceType(classElement); 340 DartType type = new InterfaceType(classElement);
324 compiler.enqueuer.codegen.registerInstantiatedClass(classElement); 341 compiler.enqueuer.codegen.registerInstantiatedClass(classElement);
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 Constant fieldValue = fieldValues[field]; 754 Constant fieldValue = fieldValues[field];
738 if (fieldValue === null) { 755 if (fieldValue === null) {
739 // Use the default value. 756 // Use the default value.
740 fieldValue = compiler.compileConstant(field); 757 fieldValue = compiler.compileConstant(field);
741 } 758 }
742 jsNewArguments.add(fieldValue); 759 jsNewArguments.add(fieldValue);
743 }); 760 });
744 return jsNewArguments; 761 return jsNewArguments;
745 } 762 }
746 } 763 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/constants.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698