| 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/object_store.h" | 9 #include "vm/object_store.h" |
| 10 #include "vm/resolver.h" | 10 #include "vm/resolver.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 107 |
| 108 void LetNode::VisitChildren(AstNodeVisitor* visitor) const { | 108 void LetNode::VisitChildren(AstNodeVisitor* visitor) const { |
| 109 for (intptr_t i = 0; i < num_temps(); ++i) { | 109 for (intptr_t i = 0; i < num_temps(); ++i) { |
| 110 initializers_[i]->Visit(visitor); | 110 initializers_[i]->Visit(visitor); |
| 111 } | 111 } |
| 112 for (intptr_t i = 0; i < nodes_.length(); ++i) { | 112 for (intptr_t i = 0; i < nodes_.length(); ++i) { |
| 113 nodes_[i]->Visit(visitor); | 113 nodes_[i]->Visit(visitor); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 bool LetNode::IsPotentiallyConst() const { |
| 118 for (intptr_t i = 0; i < num_temps(); i++) { |
| 119 if (!initializers_[i]->IsPotentiallyConst()) { |
| 120 return false; |
| 121 } |
| 122 } |
| 123 for (intptr_t i = 0; i < nodes_.length(); i++) { |
| 124 if (!nodes_[i]->IsPotentiallyConst()) { |
| 125 return false; |
| 126 } |
| 127 } |
| 128 return true; |
| 129 } |
| 130 |
| 131 const Instance* LetNode::EvalConstExpr() const { |
| 132 for (intptr_t i = 0; i < num_temps(); i++) { |
| 133 if (initializers_[i]->EvalConstExpr() == NULL) { |
| 134 return NULL; |
| 135 } |
| 136 } |
| 137 const Instance* last = NULL; |
| 138 for (intptr_t i = 0; i < nodes_.length(); i++) { |
| 139 last = nodes_[i]->EvalConstExpr(); |
| 140 if (last == NULL) { |
| 141 return NULL; |
| 142 } |
| 143 } |
| 144 return last; |
| 145 } |
| 146 |
| 117 | 147 |
| 118 void ArrayNode::VisitChildren(AstNodeVisitor* visitor) const { | 148 void ArrayNode::VisitChildren(AstNodeVisitor* visitor) const { |
| 119 for (intptr_t i = 0; i < this->length(); i++) { | 149 for (intptr_t i = 0; i < this->length(); i++) { |
| 120 ElementAt(i)->Visit(visitor); | 150 ElementAt(i)->Visit(visitor); |
| 121 } | 151 } |
| 122 } | 152 } |
| 123 | 153 |
| 124 | 154 |
| 125 bool StringInterpolateNode::IsPotentiallyConst() const { | 155 bool StringInterpolateNode::IsPotentiallyConst() const { |
| 126 for (int i = 0; i < value_->length(); i++) { | 156 for (int i = 0; i < value_->length(); i++) { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 case Token::kSUB: | 345 case Token::kSUB: |
| 316 case Token::kMUL: | 346 case Token::kMUL: |
| 317 case Token::kDIV: | 347 case Token::kDIV: |
| 318 case Token::kMOD: | 348 case Token::kMOD: |
| 319 case Token::kTRUNCDIV: | 349 case Token::kTRUNCDIV: |
| 320 case Token::kBIT_OR: | 350 case Token::kBIT_OR: |
| 321 case Token::kBIT_XOR: | 351 case Token::kBIT_XOR: |
| 322 case Token::kBIT_AND: | 352 case Token::kBIT_AND: |
| 323 case Token::kSHL: | 353 case Token::kSHL: |
| 324 case Token::kSHR: | 354 case Token::kSHR: |
| 355 case Token::kIFNULL: |
| 325 return this->left()->IsPotentiallyConst() && | 356 return this->left()->IsPotentiallyConst() && |
| 326 this->right()->IsPotentiallyConst(); | 357 this->right()->IsPotentiallyConst(); |
| 327 default: | 358 default: |
| 328 UNREACHABLE(); | 359 UNREACHABLE(); |
| 329 return false; | 360 return false; |
| 330 } | 361 } |
| 331 } | 362 } |
| 332 | 363 |
| 333 | 364 |
| 334 const Instance* BinaryOpNode::EvalConstExpr() const { | 365 const Instance* BinaryOpNode::EvalConstExpr() const { |
| 335 const Instance* left_val = this->left()->EvalConstExpr(); | 366 const Instance* left_val = this->left()->EvalConstExpr(); |
| 336 if (left_val == NULL) { | 367 if (left_val == NULL) { |
| 337 return NULL; | 368 return NULL; |
| 338 } | 369 } |
| 339 if (!left_val->IsNumber() && !left_val->IsBool() && !left_val->IsString()) { | 370 if (!left_val->IsNumber() && !left_val->IsBool() && !left_val->IsString() && |
| 371 kind_ != Token::kIFNULL) { |
| 340 return NULL; | 372 return NULL; |
| 341 } | 373 } |
| 342 const Instance* right_val = this->right()->EvalConstExpr(); | 374 const Instance* right_val = this->right()->EvalConstExpr(); |
| 343 if (right_val == NULL) { | 375 if (right_val == NULL) { |
| 344 return NULL; | 376 return NULL; |
| 345 } | 377 } |
| 346 switch (kind_) { | 378 switch (kind_) { |
| 347 case Token::kADD: | 379 case Token::kADD: |
| 348 if (left_val->IsString()) { | 380 if (left_val->IsString()) { |
| 349 return right_val->IsString() ? left_val : NULL; | 381 return right_val->IsString() ? left_val : NULL; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 374 right_val->IsInteger()) { | 406 right_val->IsInteger()) { |
| 375 return right_val; | 407 return right_val; |
| 376 } | 408 } |
| 377 return NULL; | 409 return NULL; |
| 378 case Token::kOR: | 410 case Token::kOR: |
| 379 case Token::kAND: | 411 case Token::kAND: |
| 380 if (left_val->IsBool() && right_val->IsBool()) { | 412 if (left_val->IsBool() && right_val->IsBool()) { |
| 381 return left_val; | 413 return left_val; |
| 382 } | 414 } |
| 383 return NULL; | 415 return NULL; |
| 416 case Token::kIFNULL: |
| 417 if (left_val->IsNull()) { |
| 418 return right_val; |
| 419 } |
| 420 return left_val; |
| 384 default: | 421 default: |
| 385 UNREACHABLE(); | 422 UNREACHABLE(); |
| 386 return NULL; | 423 return NULL; |
| 387 } | 424 } |
| 388 return NULL; | 425 return NULL; |
| 389 } | 426 } |
| 390 | 427 |
| 391 | 428 |
| 392 AstNode* UnaryOpNode::UnaryOpOrLiteral(intptr_t token_pos, | 429 AstNode* UnaryOpNode::UnaryOpOrLiteral(intptr_t token_pos, |
| 393 Token::Kind kind, | 430 Token::Kind kind, |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 if (result.IsError() || result.IsNull()) { | 810 if (result.IsError() || result.IsNull()) { |
| 774 // TODO(turnidge): We could get better error messages by returning | 811 // TODO(turnidge): We could get better error messages by returning |
| 775 // the Error object directly to the parser. This will involve | 812 // the Error object directly to the parser. This will involve |
| 776 // replumbing all of the EvalConstExpr methods. | 813 // replumbing all of the EvalConstExpr methods. |
| 777 return NULL; | 814 return NULL; |
| 778 } | 815 } |
| 779 return &Instance::ZoneHandle(Instance::Cast(result).raw()); | 816 return &Instance::ZoneHandle(Instance::Cast(result).raw()); |
| 780 } | 817 } |
| 781 | 818 |
| 782 } // namespace dart | 819 } // namespace dart |
| OLD | NEW |