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

Unified Diff: pkg/compiler/lib/src/compile_time_constants.dart

Issue 585173002: dart2js: Support new const operations on strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase and status file updates. Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/constant_system_dart.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/compile_time_constants.dart
diff --git a/pkg/compiler/lib/src/compile_time_constants.dart b/pkg/compiler/lib/src/compile_time_constants.dart
index 6397242081cf1f897e56d1ee6360b5d507c32201..5115f4a2c0e0a54f901a2c7178bd741b6c28f5d5 100644
--- a/pkg/compiler/lib/src/compile_time_constants.dart
+++ b/pkg/compiler/lib/src/compile_time_constants.dart
@@ -509,6 +509,16 @@ class CompileTimeConstantEvaluator extends Visitor<AstConstant> {
assert(elements.isTypeLiteral(send));
return makeTypeConstant(send, elements.getTypeLiteralType(send));
} else if (send.receiver != null) {
+ if (send.selector.asIdentifier().source == "length") {
+ AstConstant left = evaluate(send.receiver);
+ if (left != null && left.value.isString) {
+ StringConstantValue stringConstantValue = left.value;
+ DartString string = stringConstantValue.primitiveValue;
+ IntConstantValue length = constantSystem.createInt(string.length);
+ return new AstConstant(
+ context, send, new VariableConstantExpression(length, element));
+ }
+ }
// Fall through to error handling.
} else if (!Elements.isUnresolved(element)
&& element.isVariable
@@ -522,7 +532,7 @@ class CompileTimeConstantEvaluator extends Visitor<AstConstant> {
}
return signalNotCompileTimeConstant(send);
} else if (send.isCall) {
- if (identical(element, compiler.identicalFunction)
+ if (element == compiler.identicalFunction
&& send.argumentCount() == 2) {
AstConstant left = evaluate(send.argumentsNode.nodes.head);
AstConstant right = evaluate(send.argumentsNode.nodes.tail.head);
« no previous file with comments | « no previous file | pkg/compiler/lib/src/constant_system_dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698