| 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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 case Token::kSUB: | 305 case Token::kSUB: |
| 306 case Token::kMUL: | 306 case Token::kMUL: |
| 307 case Token::kDIV: | 307 case Token::kDIV: |
| 308 case Token::kMOD: | 308 case Token::kMOD: |
| 309 case Token::kTRUNCDIV: | 309 case Token::kTRUNCDIV: |
| 310 case Token::kBIT_OR: | 310 case Token::kBIT_OR: |
| 311 case Token::kBIT_XOR: | 311 case Token::kBIT_XOR: |
| 312 case Token::kBIT_AND: | 312 case Token::kBIT_AND: |
| 313 case Token::kSHL: | 313 case Token::kSHL: |
| 314 case Token::kSHR: | 314 case Token::kSHR: |
| 315 case Token::kIFNULL: |
| 315 return this->left()->IsPotentiallyConst() && | 316 return this->left()->IsPotentiallyConst() && |
| 316 this->right()->IsPotentiallyConst(); | 317 this->right()->IsPotentiallyConst(); |
| 317 default: | 318 default: |
| 318 UNREACHABLE(); | 319 UNREACHABLE(); |
| 319 return false; | 320 return false; |
| 320 } | 321 } |
| 321 } | 322 } |
| 322 | 323 |
| 323 | 324 |
| 324 const Instance* BinaryOpNode::EvalConstExpr() const { | 325 const Instance* BinaryOpNode::EvalConstExpr() const { |
| 325 const Instance* left_val = this->left()->EvalConstExpr(); | 326 const Instance* left_val = this->left()->EvalConstExpr(); |
| 326 if (left_val == NULL) { | 327 if (left_val == NULL) { |
| 327 return NULL; | 328 return NULL; |
| 328 } | 329 } |
| 329 if (!left_val->IsNumber() && !left_val->IsBool() && !left_val->IsString()) { | 330 if (!left_val->IsNumber() && !left_val->IsBool() && !left_val->IsString() && |
| 331 kind_ != Token::kIFNULL) { |
| 330 return NULL; | 332 return NULL; |
| 331 } | 333 } |
| 332 const Instance* right_val = this->right()->EvalConstExpr(); | 334 const Instance* right_val = this->right()->EvalConstExpr(); |
| 333 if (right_val == NULL) { | 335 if (right_val == NULL) { |
| 334 return NULL; | 336 return NULL; |
| 335 } | 337 } |
| 336 switch (kind_) { | 338 switch (kind_) { |
| 337 case Token::kADD: | 339 case Token::kADD: |
| 338 if (left_val->IsString()) { | 340 if (left_val->IsString()) { |
| 339 return right_val->IsString() ? left_val : NULL; | 341 return right_val->IsString() ? left_val : NULL; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 364 right_val->IsInteger()) { | 366 right_val->IsInteger()) { |
| 365 return right_val; | 367 return right_val; |
| 366 } | 368 } |
| 367 return NULL; | 369 return NULL; |
| 368 case Token::kOR: | 370 case Token::kOR: |
| 369 case Token::kAND: | 371 case Token::kAND: |
| 370 if (left_val->IsBool() && right_val->IsBool()) { | 372 if (left_val->IsBool() && right_val->IsBool()) { |
| 371 return left_val; | 373 return left_val; |
| 372 } | 374 } |
| 373 return NULL; | 375 return NULL; |
| 376 case Token::kIFNULL: |
| 377 if (left_val->IsNull()) return right_val; |
| 378 return left_val; |
| 374 default: | 379 default: |
| 375 UNREACHABLE(); | 380 UNREACHABLE(); |
| 376 return NULL; | 381 return NULL; |
| 377 } | 382 } |
| 378 return NULL; | 383 return NULL; |
| 379 } | 384 } |
| 380 | 385 |
| 381 | 386 |
| 382 AstNode* UnaryOpNode::UnaryOpOrLiteral(intptr_t token_pos, | 387 AstNode* UnaryOpNode::UnaryOpOrLiteral(intptr_t token_pos, |
| 383 Token::Kind kind, | 388 Token::Kind kind, |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 if (result.IsError() || result.IsNull()) { | 768 if (result.IsError() || result.IsNull()) { |
| 764 // TODO(turnidge): We could get better error messages by returning | 769 // TODO(turnidge): We could get better error messages by returning |
| 765 // the Error object directly to the parser. This will involve | 770 // the Error object directly to the parser. This will involve |
| 766 // replumbing all of the EvalConstExpr methods. | 771 // replumbing all of the EvalConstExpr methods. |
| 767 return NULL; | 772 return NULL; |
| 768 } | 773 } |
| 769 return &Instance::ZoneHandle(Instance::Cast(result).raw()); | 774 return &Instance::ZoneHandle(Instance::Cast(result).raw()); |
| 770 } | 775 } |
| 771 | 776 |
| 772 } // namespace dart | 777 } // namespace dart |
| OLD | NEW |