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

Unified Diff: runtime/vm/parser.cc

Issue 1558033002: Canonicalize expressions that may be used as constants (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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 | tests/language/const_string_test.dart » ('j') | tests/language/const_string_test.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc
index 76301a99b0e739f42f28582088ba0c0ab5c4be27..a0a0aecc68d15cfec0205f58a8ce901fdbfbeee9 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -11202,6 +11202,26 @@ AstNode* Parser::ParseStaticCall(const Class& cls,
// source.
if (!FLAG_warn_on_javascript_compatibility || is_patch_source()) {
ASSERT(num_arguments == 2);
+
+ // If both arguments are constant expressions of type string,
+ // evaluate and canonicalize them.
+ // This guarantees that identical("ab", "a"+"b") is true.
+ // An alternative way to guarantee this would be to introduce
+ // an AST node that canonicalizes a value.
+ AstNode* arg0 = arguments->NodeAt(0);
+ const Instance* val0 = arg0->EvalConstExpr();
+ if ((val0 != NULL) && (val0->IsString())) {
+ AstNode* arg1 = arguments->NodeAt(1);
+ const Instance* val1 = arg1->EvalConstExpr();
+ if ((val1 != NULL) && (val1->IsString())) {
+ arguments->SetNodeAt(0,
+ new(Z) LiteralNode(arg0->token_pos(),
+ EvaluateConstExpr(arg0->token_pos(), arg0)));
+ arguments->SetNodeAt(1,
+ new(Z) LiteralNode(arg1->token_pos(),
+ EvaluateConstExpr(arg1->token_pos(), arg1)));
+ }
+ }
return new(Z) ComparisonNode(ident_pos,
Token::kEQ_STRICT,
arguments->NodeAt(0),
« no previous file with comments | « no previous file | tests/language/const_string_test.dart » ('j') | tests/language/const_string_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698