| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/ast.h" | 5 #include "vm/ast.h" |
| 6 #include "vm/compiler.h" | 6 #include "vm/compiler.h" |
| 7 #include "vm/dart_entry.h" | 7 #include "vm/dart_entry.h" |
| 8 #include "vm/isolate.h" | 8 #include "vm/isolate.h" |
| 9 #include "vm/log.h" | 9 #include "vm/log.h" |
| 10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 void LetNode::VisitChildren(AstNodeVisitor* visitor) const { | 115 void LetNode::VisitChildren(AstNodeVisitor* visitor) const { |
| 116 for (intptr_t i = 0; i < num_temps(); ++i) { | 116 for (intptr_t i = 0; i < num_temps(); ++i) { |
| 117 initializers_[i]->Visit(visitor); | 117 initializers_[i]->Visit(visitor); |
| 118 } | 118 } |
| 119 for (intptr_t i = 0; i < nodes_.length(); ++i) { | 119 for (intptr_t i = 0; i < nodes_.length(); ++i) { |
| 120 nodes_[i]->Visit(visitor); | 120 nodes_[i]->Visit(visitor); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 bool LetNode::IsPotentiallyConst() const { |
| 125 for (intptr_t i = 0; i < num_temps(); i++) { |
| 126 if (!initializers_[i]->IsPotentiallyConst()) { |
| 127 return false; |
| 128 } |
| 129 } |
| 130 for (intptr_t i = 0; i < nodes_.length(); i++) { |
| 131 if (!nodes_[i]->IsPotentiallyConst()) { |
| 132 return false; |
| 133 } |
| 134 } |
| 135 return true; |
| 136 } |
| 137 |
| 138 const Instance* LetNode::EvalConstExpr() const { |
| 139 for (intptr_t i = 0; i < num_temps(); i++) { |
| 140 if (initializers_[i]->EvalConstExpr() == NULL) { |
| 141 return NULL; |
| 142 } |
| 143 } |
| 144 const Instance* last = NULL; |
| 145 for (intptr_t i = 0; i < nodes_.length(); i++) { |
| 146 last = nodes_[i]->EvalConstExpr(); |
| 147 if (last == NULL) { |
| 148 return NULL; |
| 149 } |
| 150 } |
| 151 return last; |
| 152 } |
| 153 |
| 124 | 154 |
| 125 void ArrayNode::VisitChildren(AstNodeVisitor* visitor) const { | 155 void ArrayNode::VisitChildren(AstNodeVisitor* visitor) const { |
| 126 for (intptr_t i = 0; i < this->length(); i++) { | 156 for (intptr_t i = 0; i < this->length(); i++) { |
| 127 ElementAt(i)->Visit(visitor); | 157 ElementAt(i)->Visit(visitor); |
| 128 } | 158 } |
| 129 } | 159 } |
| 130 | 160 |
| 131 | 161 |
| 132 bool StringInterpolateNode::IsPotentiallyConst() const { | 162 bool StringInterpolateNode::IsPotentiallyConst() const { |
| 133 for (int i = 0; i < value_->length(); i++) { | 163 for (int i = 0; i < value_->length(); i++) { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 case Token::kSUB: | 352 case Token::kSUB: |
| 323 case Token::kMUL: | 353 case Token::kMUL: |
| 324 case Token::kDIV: | 354 case Token::kDIV: |
| 325 case Token::kMOD: | 355 case Token::kMOD: |
| 326 case Token::kTRUNCDIV: | 356 case Token::kTRUNCDIV: |
| 327 case Token::kBIT_OR: | 357 case Token::kBIT_OR: |
| 328 case Token::kBIT_XOR: | 358 case Token::kBIT_XOR: |
| 329 case Token::kBIT_AND: | 359 case Token::kBIT_AND: |
| 330 case Token::kSHL: | 360 case Token::kSHL: |
| 331 case Token::kSHR: | 361 case Token::kSHR: |
| 362 case Token::kIFNULL: |
| 332 return this->left()->IsPotentiallyConst() && | 363 return this->left()->IsPotentiallyConst() && |
| 333 this->right()->IsPotentiallyConst(); | 364 this->right()->IsPotentiallyConst(); |
| 334 default: | 365 default: |
| 335 UNREACHABLE(); | 366 UNREACHABLE(); |
| 336 return false; | 367 return false; |
| 337 } | 368 } |
| 338 } | 369 } |
| 339 | 370 |
| 340 | 371 |
| 341 const Instance* BinaryOpNode::EvalConstExpr() const { | 372 const Instance* BinaryOpNode::EvalConstExpr() const { |
| 342 const Instance* left_val = this->left()->EvalConstExpr(); | 373 const Instance* left_val = this->left()->EvalConstExpr(); |
| 343 if (left_val == NULL) { | 374 if (left_val == NULL) { |
| 344 return NULL; | 375 return NULL; |
| 345 } | 376 } |
| 346 if (!left_val->IsNumber() && !left_val->IsBool() && !left_val->IsString()) { | 377 if (!left_val->IsNumber() && !left_val->IsBool() && !left_val->IsString() && |
| 378 kind_ != Token::kIFNULL) { |
| 347 return NULL; | 379 return NULL; |
| 348 } | 380 } |
| 349 const Instance* right_val = this->right()->EvalConstExpr(); | 381 const Instance* right_val = this->right()->EvalConstExpr(); |
| 350 if (right_val == NULL) { | 382 if (right_val == NULL) { |
| 351 return NULL; | 383 return NULL; |
| 352 } | 384 } |
| 353 switch (kind_) { | 385 switch (kind_) { |
| 354 case Token::kADD: | 386 case Token::kADD: |
| 355 if (left_val->IsString()) { | 387 if (left_val->IsString()) { |
| 356 return right_val->IsString() ? left_val : NULL; | 388 return right_val->IsString() ? left_val : NULL; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 381 right_val->IsInteger()) { | 413 right_val->IsInteger()) { |
| 382 return right_val; | 414 return right_val; |
| 383 } | 415 } |
| 384 return NULL; | 416 return NULL; |
| 385 case Token::kOR: | 417 case Token::kOR: |
| 386 case Token::kAND: | 418 case Token::kAND: |
| 387 if (left_val->IsBool() && right_val->IsBool()) { | 419 if (left_val->IsBool() && right_val->IsBool()) { |
| 388 return left_val; | 420 return left_val; |
| 389 } | 421 } |
| 390 return NULL; | 422 return NULL; |
| 423 case Token::kIFNULL: |
| 424 if (left_val->IsNull()) { |
| 425 return right_val; |
| 426 } |
| 427 return left_val; |
| 391 default: | 428 default: |
| 392 UNREACHABLE(); | 429 UNREACHABLE(); |
| 393 return NULL; | 430 return NULL; |
| 394 } | 431 } |
| 395 return NULL; | 432 return NULL; |
| 396 } | 433 } |
| 397 | 434 |
| 398 | 435 |
| 399 AstNode* UnaryOpNode::UnaryOpOrLiteral(intptr_t token_pos, | 436 AstNode* UnaryOpNode::UnaryOpOrLiteral(intptr_t token_pos, |
| 400 Token::Kind kind, | 437 Token::Kind kind, |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 if (result.IsError() || result.IsNull()) { | 817 if (result.IsError() || result.IsNull()) { |
| 781 // TODO(turnidge): We could get better error messages by returning | 818 // TODO(turnidge): We could get better error messages by returning |
| 782 // the Error object directly to the parser. This will involve | 819 // the Error object directly to the parser. This will involve |
| 783 // replumbing all of the EvalConstExpr methods. | 820 // replumbing all of the EvalConstExpr methods. |
| 784 return NULL; | 821 return NULL; |
| 785 } | 822 } |
| 786 return &Instance::ZoneHandle(Instance::Cast(result).raw()); | 823 return &Instance::ZoneHandle(Instance::Cast(result).raw()); |
| 787 } | 824 } |
| 788 | 825 |
| 789 } // namespace dart | 826 } // namespace dart |
| OLD | NEW |