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

Unified Diff: runtime/vm/parser.cc

Issue 1493693002: Make ?? a compile-time constant operator. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years 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
« pkg/analyzer/lib/src/generated/constant.dart ('K') | « runtime/vm/ast.cc ('k') | no next file » | 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 26f2ad7adb095eb5f22a4e1473c56684e15d4ad5..48df56b27c134360ecd54bcec4ce89fa6108a4a5 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -10552,6 +10552,18 @@ AstNode* Parser::OptimizeBinaryOpNode(intptr_t op_pos,
}
if (binary_op == Token::kIFNULL) {
// Handle a ?? b.
+ if (lhs->IsPotentiallyConst()) {
hausner 2015/12/02 18:29:37 This is a bit more complicated. You need to use l
Lasse Reichstein Nielsen 2015/12/04 12:11:46 Tried to do that. Still doesn't work for const co
+ // If we know at compile time whether the lhs is null
+ // and side-effect free, just reduce it to either the lhs or rhs.
+ // This enables ?? to be compile-time constant.
+ const Object* left_expr = lhs->EvalConstExpr();
+ if (left_expr != NULL) {
+ if (left_expr->IsNull()) return rhs;
+ return lhs;
+ }
+ }
+ // Otherwise create a temporary variable for the lhs so we can both
+ // check it against null and return it if necessary.
LetNode* result = new(Z) LetNode(op_pos);
LocalVariable* left_temp = result->AddInitializer(lhs);
const intptr_t no_pos = Scanner::kNoSourcePos;
« pkg/analyzer/lib/src/generated/constant.dart ('K') | « runtime/vm/ast.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698