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

Unified Diff: runtime/vm/parser.cc

Issue 1575383002: Implement ?? as compile-time constant in VM. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Merge to head 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 | « runtime/vm/ast.cc ('k') | tests/language/language.status » ('j') | no next file with comments »
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 4d3e643e7b70a5a3674555eeedb95e574dda72ba..1004d0d7db3c1b6178c1bcb9a53ab7314b0765b1 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -10423,8 +10423,21 @@ AstNode* Parser::OptimizeBinaryOpNode(intptr_t op_pos,
}
if (binary_op == Token::kIFNULL) {
// Handle a ?? b.
+ if ((lhs->EvalConstExpr() != NULL) && (rhs->EvalConstExpr() != NULL)) {
+ Instance& expr_value = Instance::ZoneHandle(Z);
+ if (!GetCachedConstant(op_pos, &expr_value)) {
+ expr_value = EvaluateConstExpr(lhs->token_pos(), lhs).raw();
+ if (expr_value.IsNull()) {
+ expr_value = EvaluateConstExpr(rhs->token_pos(), rhs).raw();
+ }
+ CacheConstantValue(op_pos, expr_value);
+ }
+ return new(Z) LiteralNode(op_pos, expr_value);
+ }
+
LetNode* result = new(Z) LetNode(op_pos);
LocalVariable* left_temp = result->AddInitializer(lhs);
+ left_temp->set_is_final();
const intptr_t no_pos = Token::kNoSourcePos;
LiteralNode* null_operand =
new(Z) LiteralNode(no_pos, Object::null_instance());
« no previous file with comments | « runtime/vm/ast.cc ('k') | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698