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

Unified Diff: runtime/vm/ast.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.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/ast.cc
diff --git a/runtime/vm/ast.cc b/runtime/vm/ast.cc
index 19542b374206b06680f651223f5956d8afbedd66..2deefa29ca5166210d6db5ba98e2943765b116f7 100644
--- a/runtime/vm/ast.cc
+++ b/runtime/vm/ast.cc
@@ -121,6 +121,36 @@ void LetNode::VisitChildren(AstNodeVisitor* visitor) const {
}
}
+bool LetNode::IsPotentiallyConst() const {
+ for (intptr_t i = 0; i < num_temps(); i++) {
+ if (!initializers_[i]->IsPotentiallyConst()) {
+ return false;
+ }
+ }
+ for (intptr_t i = 0; i < nodes_.length(); i++) {
+ if (!nodes_[i]->IsPotentiallyConst()) {
+ return false;
+ }
+ }
+ return true;
+}
+
+const Instance* LetNode::EvalConstExpr() const {
+ for (intptr_t i = 0; i < num_temps(); i++) {
+ if (initializers_[i]->EvalConstExpr() == NULL) {
+ return NULL;
+ }
+ }
+ const Instance* last = NULL;
+ for (intptr_t i = 0; i < nodes_.length(); i++) {
+ last = nodes_[i]->EvalConstExpr();
+ if (last == NULL) {
+ return NULL;
+ }
+ }
+ return last;
+}
+
void ArrayNode::VisitChildren(AstNodeVisitor* visitor) const {
for (intptr_t i = 0; i < this->length(); i++) {
@@ -329,6 +359,7 @@ bool BinaryOpNode::IsPotentiallyConst() const {
case Token::kBIT_AND:
case Token::kSHL:
case Token::kSHR:
+ case Token::kIFNULL:
return this->left()->IsPotentiallyConst() &&
this->right()->IsPotentiallyConst();
default:
@@ -343,7 +374,8 @@ const Instance* BinaryOpNode::EvalConstExpr() const {
if (left_val == NULL) {
return NULL;
}
- if (!left_val->IsNumber() && !left_val->IsBool() && !left_val->IsString()) {
+ if (!left_val->IsNumber() && !left_val->IsBool() && !left_val->IsString() &&
+ kind_ != Token::kIFNULL) {
return NULL;
}
const Instance* right_val = this->right()->EvalConstExpr();
@@ -388,6 +420,11 @@ const Instance* BinaryOpNode::EvalConstExpr() const {
return left_val;
}
return NULL;
+ case Token::kIFNULL:
+ if (left_val->IsNull()) {
+ return right_val;
+ }
+ return left_val;
default:
UNREACHABLE();
return NULL;
« no previous file with comments | « runtime/vm/ast.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698