| 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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 return false; | 317 return false; |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 | 320 |
| 321 | 321 |
| 322 const Instance* BinaryOpNode::EvalConstExpr() const { | 322 const Instance* BinaryOpNode::EvalConstExpr() const { |
| 323 const Instance* left_val = this->left()->EvalConstExpr(); | 323 const Instance* left_val = this->left()->EvalConstExpr(); |
| 324 if (left_val == NULL) { | 324 if (left_val == NULL) { |
| 325 return NULL; | 325 return NULL; |
| 326 } | 326 } |
| 327 if (!left_val->IsNumber() && !left_val->IsBool()) { | 327 if (!left_val->IsNumber() && !left_val->IsBool() && !left_val->IsString()) { |
| 328 return NULL; | 328 return NULL; |
| 329 } | 329 } |
| 330 const Instance* right_val = this->right()->EvalConstExpr(); | 330 const Instance* right_val = this->right()->EvalConstExpr(); |
| 331 if (right_val == NULL) { | 331 if (right_val == NULL) { |
| 332 return NULL; | 332 return NULL; |
| 333 } | 333 } |
| 334 switch (kind_) { | 334 switch (kind_) { |
| 335 case Token::kADD: | 335 case Token::kADD: |
| 336 if (left_val->IsString()) { |
| 337 return right_val->IsString() ? left_val : NULL; |
| 338 } |
| 339 // Fall-through intentional. |
| 336 case Token::kSUB: | 340 case Token::kSUB: |
| 337 case Token::kMUL: | 341 case Token::kMUL: |
| 338 case Token::kDIV: | 342 case Token::kDIV: |
| 339 case Token::kMOD: | 343 case Token::kMOD: |
| 340 case Token::kTRUNCDIV: | 344 case Token::kTRUNCDIV: |
| 341 if (left_val->IsInteger()) { | 345 if (left_val->IsInteger()) { |
| 342 if (right_val->IsInteger()) { | 346 if (right_val->IsInteger()) { |
| 343 return left_val; | 347 return left_val; |
| 344 } else if (right_val->IsNumber()) { | 348 } else if (right_val->IsNumber()) { |
| 345 return right_val; | 349 return right_val; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 } | 528 } |
| 525 return new StoreStaticFieldNode(token_pos(), field(), rhs); | 529 return new StoreStaticFieldNode(token_pos(), field(), rhs); |
| 526 } | 530 } |
| 527 | 531 |
| 528 | 532 |
| 529 AstNode* InstanceGetterNode::MakeAssignmentNode(AstNode* rhs) { | 533 AstNode* InstanceGetterNode::MakeAssignmentNode(AstNode* rhs) { |
| 530 return new InstanceSetterNode(token_pos(), receiver(), field_name(), rhs); | 534 return new InstanceSetterNode(token_pos(), receiver(), field_name(), rhs); |
| 531 } | 535 } |
| 532 | 536 |
| 533 | 537 |
| 538 bool InstanceGetterNode::IsPotentiallyConst() const { |
| 539 return field_name().Equals(Symbols::Length()) && |
| 540 receiver()->IsPotentiallyConst(); |
| 541 } |
| 542 |
| 543 |
| 544 const Instance* InstanceGetterNode::EvalConstExpr() const { |
| 545 if (field_name().Equals(Symbols::Length())) { |
| 546 const Instance* receiver_val = receiver()->EvalConstExpr(); |
| 547 if ((receiver_val != NULL) && receiver_val->IsString()) { |
| 548 return &Instance::ZoneHandle(Smi::New(1)); |
| 549 } |
| 550 } |
| 551 return NULL; |
| 552 } |
| 553 |
| 554 |
| 534 AstNode* LoadIndexedNode::MakeAssignmentNode(AstNode* rhs) { | 555 AstNode* LoadIndexedNode::MakeAssignmentNode(AstNode* rhs) { |
| 535 return new StoreIndexedNode(token_pos(), array(), index_expr(), | 556 return new StoreIndexedNode(token_pos(), array(), index_expr(), |
| 536 rhs, super_class()); | 557 rhs, super_class()); |
| 537 } | 558 } |
| 538 | 559 |
| 539 | 560 |
| 540 AstNode* StaticGetterNode::MakeAssignmentNode(AstNode* rhs) { | 561 AstNode* StaticGetterNode::MakeAssignmentNode(AstNode* rhs) { |
| 541 const String& setter_name = String::Handle(Field::SetterName(field_name())); | 562 const String& setter_name = String::Handle(Field::SetterName(field_name())); |
| 542 | 563 |
| 543 if (is_super_getter_) { | 564 if (is_super_getter_) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 if (result.IsError() || result.IsNull()) { | 661 if (result.IsError() || result.IsNull()) { |
| 641 // TODO(turnidge): We could get better error messages by returning | 662 // TODO(turnidge): We could get better error messages by returning |
| 642 // the Error object directly to the parser. This will involve | 663 // the Error object directly to the parser. This will involve |
| 643 // replumbing all of the EvalConstExpr methods. | 664 // replumbing all of the EvalConstExpr methods. |
| 644 return NULL; | 665 return NULL; |
| 645 } | 666 } |
| 646 return &Instance::ZoneHandle(Instance::Cast(result).raw()); | 667 return &Instance::ZoneHandle(Instance::Cast(result).raw()); |
| 647 } | 668 } |
| 648 | 669 |
| 649 } // namespace dart | 670 } // namespace dart |
| OLD | NEW |