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

Side by Side 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 unified diff | Download patch
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 #include "vm/parser.h" 5 #include "vm/parser.h"
6 #include "vm/flags.h" 6 #include "vm/flags.h"
7 7
8 #ifndef DART_PRECOMPILED 8 #ifndef DART_PRECOMPILED
9 9
10 #include "lib/invocation_mirror.h" 10 #include "lib/invocation_mirror.h"
(...skipping 11184 matching lines...) Expand 10 before | Expand all | Expand 10 after
11195 NULL); // No existing function. 11195 NULL); // No existing function.
11196 } else if (cls.IsTopLevel() && 11196 } else if (cls.IsTopLevel() &&
11197 (cls.library() == Library::CoreLibrary()) && 11197 (cls.library() == Library::CoreLibrary()) &&
11198 (func.name() == Symbols::Identical().raw())) { 11198 (func.name() == Symbols::Identical().raw())) {
11199 // This is the predefined toplevel function identical(a,b). 11199 // This is the predefined toplevel function identical(a,b).
11200 // Create a comparison node instead of a static call to the function, unless 11200 // Create a comparison node instead of a static call to the function, unless
11201 // javascript warnings are desired and identical is not invoked from a patch 11201 // javascript warnings are desired and identical is not invoked from a patch
11202 // source. 11202 // source.
11203 if (!FLAG_warn_on_javascript_compatibility || is_patch_source()) { 11203 if (!FLAG_warn_on_javascript_compatibility || is_patch_source()) {
11204 ASSERT(num_arguments == 2); 11204 ASSERT(num_arguments == 2);
11205
11206 // If both arguments are constant expressions of type string,
11207 // evaluate and canonicalize them.
11208 // This guarantees that identical("ab", "a"+"b") is true.
11209 // An alternative way to guarantee this would be to introduce
11210 // an AST node that canonicalizes a value.
11211 AstNode* arg0 = arguments->NodeAt(0);
11212 const Instance* val0 = arg0->EvalConstExpr();
11213 if ((val0 != NULL) && (val0->IsString())) {
11214 AstNode* arg1 = arguments->NodeAt(1);
11215 const Instance* val1 = arg1->EvalConstExpr();
11216 if ((val1 != NULL) && (val1->IsString())) {
11217 arguments->SetNodeAt(0,
11218 new(Z) LiteralNode(arg0->token_pos(),
11219 EvaluateConstExpr(arg0->token_pos(), arg0)));
11220 arguments->SetNodeAt(1,
11221 new(Z) LiteralNode(arg1->token_pos(),
11222 EvaluateConstExpr(arg1->token_pos(), arg1)));
11223 }
11224 }
11205 return new(Z) ComparisonNode(ident_pos, 11225 return new(Z) ComparisonNode(ident_pos,
11206 Token::kEQ_STRICT, 11226 Token::kEQ_STRICT,
11207 arguments->NodeAt(0), 11227 arguments->NodeAt(0),
11208 arguments->NodeAt(1)); 11228 arguments->NodeAt(1));
11209 } 11229 }
11210 } 11230 }
11211 return new(Z) StaticCallNode(ident_pos, func, arguments); 11231 return new(Z) StaticCallNode(ident_pos, func, arguments);
11212 } 11232 }
11213 11233
11214 11234
(...skipping 3273 matching lines...) Expand 10 before | Expand all | Expand 10 after
14488 const ArgumentListNode& function_args, 14508 const ArgumentListNode& function_args,
14489 const LocalVariable* temp_for_last_arg, 14509 const LocalVariable* temp_for_last_arg,
14490 bool is_super_invocation) { 14510 bool is_super_invocation) {
14491 UNREACHABLE(); 14511 UNREACHABLE();
14492 return NULL; 14512 return NULL;
14493 } 14513 }
14494 14514
14495 } // namespace dart 14515 } // namespace dart
14496 14516
14497 #endif // DART_PRECOMPILED 14517 #endif // DART_PRECOMPILED
OLDNEW
« 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