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

Side by Side 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 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 10534 matching lines...) Expand 10 before | Expand all | Expand 10 after
10545 BinaryOpNode* old = lhs->AsBinaryOpNode(); 10545 BinaryOpNode* old = lhs->AsBinaryOpNode();
10546 BinaryOpWithMask32Node* binop = new(Z) BinaryOpWithMask32Node( 10546 BinaryOpWithMask32Node* binop = new(Z) BinaryOpWithMask32Node(
10547 old->token_pos(), old->kind(), old->left(), old->right(), val); 10547 old->token_pos(), old->kind(), old->left(), old->right(), val);
10548 return binop; 10548 return binop;
10549 } 10549 }
10550 } 10550 }
10551 } 10551 }
10552 } 10552 }
10553 if (binary_op == Token::kIFNULL) { 10553 if (binary_op == Token::kIFNULL) {
10554 // Handle a ?? b. 10554 // Handle a ?? b.
10555 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
10556 // If we know at compile time whether the lhs is null
10557 // and side-effect free, just reduce it to either the lhs or rhs.
10558 // This enables ?? to be compile-time constant.
10559 const Object* left_expr = lhs->EvalConstExpr();
10560 if (left_expr != NULL) {
10561 if (left_expr->IsNull()) return rhs;
10562 return lhs;
10563 }
10564 }
10565 // Otherwise create a temporary variable for the lhs so we can both
10566 // check it against null and return it if necessary.
10555 LetNode* result = new(Z) LetNode(op_pos); 10567 LetNode* result = new(Z) LetNode(op_pos);
10556 LocalVariable* left_temp = result->AddInitializer(lhs); 10568 LocalVariable* left_temp = result->AddInitializer(lhs);
10557 const intptr_t no_pos = Scanner::kNoSourcePos; 10569 const intptr_t no_pos = Scanner::kNoSourcePos;
10558 LiteralNode* null_operand = 10570 LiteralNode* null_operand =
10559 new(Z) LiteralNode(no_pos, Instance::ZoneHandle(Z)); 10571 new(Z) LiteralNode(no_pos, Instance::ZoneHandle(Z));
10560 LoadLocalNode* load_left_temp = new(Z) LoadLocalNode(no_pos, left_temp); 10572 LoadLocalNode* load_left_temp = new(Z) LoadLocalNode(no_pos, left_temp);
10561 ComparisonNode* null_compare = 10573 ComparisonNode* null_compare =
10562 new(Z) ComparisonNode(no_pos, 10574 new(Z) ComparisonNode(no_pos,
10563 Token::kNE_STRICT, 10575 Token::kNE_STRICT,
10564 load_left_temp, 10576 load_left_temp,
(...skipping 3856 matching lines...) Expand 10 before | Expand all | Expand 10 after
14421 const ArgumentListNode& function_args, 14433 const ArgumentListNode& function_args,
14422 const LocalVariable* temp_for_last_arg, 14434 const LocalVariable* temp_for_last_arg,
14423 bool is_super_invocation) { 14435 bool is_super_invocation) {
14424 UNREACHABLE(); 14436 UNREACHABLE();
14425 return NULL; 14437 return NULL;
14426 } 14438 }
14427 14439
14428 } // namespace dart 14440 } // namespace dart
14429 14441
14430 #endif // DART_PRECOMPILED 14442 #endif // DART_PRECOMPILED
OLDNEW
« 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