| OLD | NEW |
| 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 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 } | 502 } |
| 503 if (result != null) { | 503 if (result != null) { |
| 504 return new AstConstant( | 504 return new AstConstant( |
| 505 context, send, | 505 context, send, |
| 506 new VariableConstantExpression(result.value, element)); | 506 new VariableConstantExpression(result.value, element)); |
| 507 } | 507 } |
| 508 } else if (Elements.isClass(element) || Elements.isTypedef(element)) { | 508 } else if (Elements.isClass(element) || Elements.isTypedef(element)) { |
| 509 assert(elements.isTypeLiteral(send)); | 509 assert(elements.isTypeLiteral(send)); |
| 510 return makeTypeConstant(send, elements.getTypeLiteralType(send)); | 510 return makeTypeConstant(send, elements.getTypeLiteralType(send)); |
| 511 } else if (send.receiver != null) { | 511 } else if (send.receiver != null) { |
| 512 if (send.selector.asIdentifier().source == "length") { |
| 513 AstConstant left = evaluate(send.receiver); |
| 514 if (left != null && left.value.isString) { |
| 515 StringConstantValue stringConstantValue = left.value; |
| 516 DartString string = stringConstantValue.primitiveValue; |
| 517 IntConstantValue length = constantSystem.createInt(string.length); |
| 518 return new AstConstant( |
| 519 context, send, new VariableConstantExpression(length, element)); |
| 520 } |
| 521 } |
| 512 // Fall through to error handling. | 522 // Fall through to error handling. |
| 513 } else if (!Elements.isUnresolved(element) | 523 } else if (!Elements.isUnresolved(element) |
| 514 && element.isVariable | 524 && element.isVariable |
| 515 && element.isConst) { | 525 && element.isConst) { |
| 516 ConstantExpression result = handler.compileConstant(element); | 526 ConstantExpression result = handler.compileConstant(element); |
| 517 if (result != null) { | 527 if (result != null) { |
| 518 return new AstConstant( | 528 return new AstConstant( |
| 519 context, send, | 529 context, send, |
| 520 new VariableConstantExpression(result.value, element)); | 530 new VariableConstantExpression(result.value, element)); |
| 521 } | 531 } |
| 522 } | 532 } |
| 523 return signalNotCompileTimeConstant(send); | 533 return signalNotCompileTimeConstant(send); |
| 524 } else if (send.isCall) { | 534 } else if (send.isCall) { |
| 525 if (identical(element, compiler.identicalFunction) | 535 if (element == compiler.identicalFunction |
| 526 && send.argumentCount() == 2) { | 536 && send.argumentCount() == 2) { |
| 527 AstConstant left = evaluate(send.argumentsNode.nodes.head); | 537 AstConstant left = evaluate(send.argumentsNode.nodes.head); |
| 528 AstConstant right = evaluate(send.argumentsNode.nodes.tail.head); | 538 AstConstant right = evaluate(send.argumentsNode.nodes.tail.head); |
| 529 if (left == null || right == null) { | 539 if (left == null || right == null) { |
| 530 return null; | 540 return null; |
| 531 } | 541 } |
| 532 ConstantValue result = | 542 ConstantValue result = |
| 533 constantSystem.identity.fold(left.value, right.value); | 543 constantSystem.identity.fold(left.value, right.value); |
| 534 if (result != null) { | 544 if (result != null) { |
| 535 return new AstConstant( | 545 return new AstConstant( |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 return new AstConstant( | 1111 return new AstConstant( |
| 1102 element, | 1112 element, |
| 1103 element.initializer != null ? element.initializer : element.node, | 1113 element.initializer != null ? element.initializer : element.node, |
| 1104 constant); | 1114 constant); |
| 1105 } | 1115 } |
| 1106 | 1116 |
| 1107 ConstantValue get value => expression.value; | 1117 ConstantValue get value => expression.value; |
| 1108 | 1118 |
| 1109 String toString() => expression.toString(); | 1119 String toString() => expression.toString(); |
| 1110 } | 1120 } |
| OLD | NEW |