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

Unified Diff: runtime/vm/ast.cc

Issue 935713002: Accept constant string concatenation and constant string length as constant (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 10 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 | « runtime/vm/ast.h ('k') | tests/language/compile_time_constant12_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/ast.cc
===================================================================
--- runtime/vm/ast.cc (revision 43823)
+++ runtime/vm/ast.cc (working copy)
@@ -324,7 +324,7 @@
if (left_val == NULL) {
return NULL;
}
- if (!left_val->IsNumber() && !left_val->IsBool()) {
+ if (!left_val->IsNumber() && !left_val->IsBool() && !left_val->IsString()) {
return NULL;
}
const Instance* right_val = this->right()->EvalConstExpr();
@@ -333,6 +333,10 @@
}
switch (kind_) {
case Token::kADD:
+ if (left_val->IsString()) {
+ return right_val->IsString() ? left_val : NULL;
+ }
+ // Fall-through intentional.
case Token::kSUB:
case Token::kMUL:
case Token::kDIV:
@@ -531,6 +535,23 @@
}
+bool InstanceGetterNode::IsPotentiallyConst() const {
+ return receiver()->IsPotentiallyConst() &&
+ field_name().Equals(Symbols::Length());
+}
+
+
+const Instance* InstanceGetterNode::EvalConstExpr() const {
+ const Instance* receiver_val = receiver()->EvalConstExpr();
+ if ((receiver_val != NULL) &&
+ receiver_val->IsString() &&
+ field_name().Equals(Symbols::Length())) {
hausner 2015/02/17 23:07:03 Maybe reverse the order of checks? Testing whether
regis 2015/02/18 00:38:08 Done.
+ return receiver_val;
hausner 2015/02/17 23:07:03 I think you should return a value that represents
regis 2015/02/18 00:38:08 Good catch. length + 1 was not working. It does no
+ }
+ return NULL;
+}
+
+
AstNode* LoadIndexedNode::MakeAssignmentNode(AstNode* rhs) {
return new StoreIndexedNode(token_pos(), array(), index_expr(),
rhs, super_class());
« no previous file with comments | « runtime/vm/ast.h ('k') | tests/language/compile_time_constant12_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698