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

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

Issue 10918188: Stop treating final as const in dart2js. (Closed) Base URL: https://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 | tests/co19/co19-dart2js.status » ('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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 new DartString.concat(left.value, right.value), node); 360 new DartString.concat(left.value, right.value), node);
361 } 361 }
362 362
363 Constant visitStringInterpolation(StringInterpolation node) { 363 Constant visitStringInterpolation(StringInterpolation node) {
364 StringConstant initialString = evaluate(node.string); 364 StringConstant initialString = evaluate(node.string);
365 if (initialString == null) return null; 365 if (initialString == null) return null;
366 DartString accumulator = initialString.value; 366 DartString accumulator = initialString.value;
367 for (StringInterpolationPart part in node.parts) { 367 for (StringInterpolationPart part in node.parts) {
368 Constant expression = evaluate(part.expression); 368 Constant expression = evaluate(part.expression);
369 DartString expressionString; 369 DartString expressionString;
370 if (expression.isNum() || expression.isBool()) { 370 if (expression === null) {
371 return signalNotCompileTimeConstant(part.expression);
372 } else if (expression.isNum() || expression.isBool()) {
371 PrimitiveConstant primitive = expression; 373 PrimitiveConstant primitive = expression;
372 expressionString = new DartString.literal(primitive.value.toString()); 374 expressionString = new DartString.literal(primitive.value.toString());
373 } else if (expression.isString()) { 375 } else if (expression.isString()) {
374 PrimitiveConstant primitive = expression; 376 PrimitiveConstant primitive = expression;
375 expressionString = primitive.value; 377 expressionString = primitive.value;
376 } else { 378 } else {
377 return signalNotCompileTimeConstant(part.expression); 379 return signalNotCompileTimeConstant(part.expression);
378 } 380 }
379 accumulator = new DartString.concat(accumulator, expressionString); 381 accumulator = new DartString.concat(accumulator, expressionString);
380 StringConstant partString = evaluate(part.string); 382 StringConstant partString = evaluate(part.string);
381 if (partString == null) return null; 383 if (partString == null) return null;
382 accumulator = new DartString.concat(accumulator, partString.value); 384 accumulator = new DartString.concat(accumulator, partString.value);
383 }; 385 };
384 return constantSystem.createString(accumulator, node); 386 return constantSystem.createString(accumulator, node);
385 } 387 }
386 388
387 // TODO(floitsch): provide better error-messages. 389 // TODO(floitsch): provide better error-messages.
388 Constant visitSend(Send send) { 390 Constant visitSend(Send send) {
389 Element element = elements[send]; 391 Element element = elements[send];
390 if (Elements.isStaticOrTopLevelField(element)) { 392 if (Elements.isStaticOrTopLevelField(element)) {
391 Constant result; 393 Constant result;
392 if (element.modifiers !== null) { 394 if (element.modifiers !== null) {
393 if (element.modifiers.isConst()) { 395 if (element.modifiers.isConst()) {
394 result = compiler.compileConstant(element); 396 result = compiler.compileConstant(element);
395 } else if (element.modifiers.isFinal()) { 397 } else if (element.modifiers.isFinal() && !isEvaluatingConstant) {
396 // TODO(4516): remove support for final compile-time constants: if
397 // isCompilingConstant is true don't compile the variable.
398 result = compiler.compileVariable(element); 398 result = compiler.compileVariable(element);
399 } 399 }
400 } 400 }
401 if (result == null) return signalNotCompileTimeConstant(send); 401 if (result == null) return signalNotCompileTimeConstant(send);
402 return result; 402 return result;
403 } else if (Elements.isStaticOrTopLevelFunction(element) 403 } else if (Elements.isStaticOrTopLevelFunction(element)
404 && send.isPropertyAccess) { 404 && send.isPropertyAccess) {
405 compiler.codegenWorld.staticFunctionsNeedingGetter.add(element); 405 compiler.codegenWorld.staticFunctionsNeedingGetter.add(element);
406 Constant constant = new FunctionConstant(element); 406 Constant constant = new FunctionConstant(element);
407 compiler.constantHandler.registerCompileTimeConstant(constant); 407 compiler.constantHandler.registerCompileTimeConstant(constant);
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 Constant fieldValue = fieldValues[field]; 754 Constant fieldValue = fieldValues[field];
755 if (fieldValue === null) { 755 if (fieldValue === null) {
756 // Use the default value. 756 // Use the default value.
757 fieldValue = compiler.compileConstant(field); 757 fieldValue = compiler.compileConstant(field);
758 } 758 }
759 jsNewArguments.add(fieldValue); 759 jsNewArguments.add(fieldValue);
760 }); 760 });
761 return jsNewArguments; 761 return jsNewArguments;
762 } 762 }
763 } 763 }
OLDNEW
« no previous file with comments | « no previous file | tests/co19/co19-dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698