| 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" |
| 11 | 11 |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 DECLARE_FLAG(bool, enable_type_checks); |
| 16 |
| 15 #define DEFINE_VISIT_FUNCTION(BaseName) \ | 17 #define DEFINE_VISIT_FUNCTION(BaseName) \ |
| 16 void BaseName##Node::Visit(AstNodeVisitor* visitor) { \ | 18 void BaseName##Node::Visit(AstNodeVisitor* visitor) { \ |
| 17 visitor->Visit##BaseName##Node(this); \ | 19 visitor->Visit##BaseName##Node(this); \ |
| 18 } | 20 } |
| 19 | 21 |
| 20 FOR_EACH_NODE(DEFINE_VISIT_FUNCTION) | 22 FOR_EACH_NODE(DEFINE_VISIT_FUNCTION) |
| 21 #undef DEFINE_VISIT_FUNCTION | 23 #undef DEFINE_VISIT_FUNCTION |
| 22 | 24 |
| 23 | 25 |
| 24 #define DEFINE_NAME_FUNCTION(BaseName) \ | 26 #define DEFINE_NAME_FUNCTION(BaseName) \ |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 return NULL; | 500 return NULL; |
| 499 } | 501 } |
| 500 return new StoreLocalNode(token_pos(), &local(), rhs); | 502 return new StoreLocalNode(token_pos(), &local(), rhs); |
| 501 } | 503 } |
| 502 | 504 |
| 503 | 505 |
| 504 AstNode* LoadStaticFieldNode::MakeAssignmentNode(AstNode* rhs) { | 506 AstNode* LoadStaticFieldNode::MakeAssignmentNode(AstNode* rhs) { |
| 505 if (field().is_final()) { | 507 if (field().is_final()) { |
| 506 return NULL; | 508 return NULL; |
| 507 } | 509 } |
| 510 if (FLAG_enable_type_checks) { |
| 511 rhs = new AssignableNode( |
| 512 field().token_pos(), |
| 513 rhs, |
| 514 AbstractType::ZoneHandle(field().type()), |
| 515 String::ZoneHandle(field().name())); |
| 516 } |
| 508 return new StoreStaticFieldNode(token_pos(), field(), rhs); | 517 return new StoreStaticFieldNode(token_pos(), field(), rhs); |
| 509 } | 518 } |
| 510 | 519 |
| 511 | 520 |
| 512 AstNode* InstanceGetterNode::MakeAssignmentNode(AstNode* rhs) { | 521 AstNode* InstanceGetterNode::MakeAssignmentNode(AstNode* rhs) { |
| 513 return new InstanceSetterNode(token_pos(), receiver(), field_name(), rhs); | 522 return new InstanceSetterNode(token_pos(), receiver(), field_name(), rhs); |
| 514 } | 523 } |
| 515 | 524 |
| 516 | 525 |
| 517 AstNode* LoadIndexedNode::MakeAssignmentNode(AstNode* rhs) { | 526 AstNode* LoadIndexedNode::MakeAssignmentNode(AstNode* rhs) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 // order to trigger the throw at runtime. | 559 // order to trigger the throw at runtime. |
| 551 return new StaticSetterNode(token_pos(), NULL, cls(), field_name(), rhs); | 560 return new StaticSetterNode(token_pos(), NULL, cls(), field_name(), rhs); |
| 552 } | 561 } |
| 553 #if defined(DEBUG) | 562 #if defined(DEBUG) |
| 554 const String& getter_name = String::Handle(Field::GetterName(field_name())); | 563 const String& getter_name = String::Handle(Field::GetterName(field_name())); |
| 555 const Function& getter = | 564 const Function& getter = |
| 556 Function::Handle(cls().LookupStaticFunction(getter_name)); | 565 Function::Handle(cls().LookupStaticFunction(getter_name)); |
| 557 ASSERT(!getter.IsNull() && | 566 ASSERT(!getter.IsNull() && |
| 558 (getter.kind() == RawFunction::kImplicitStaticFinalGetter)); | 567 (getter.kind() == RawFunction::kImplicitStaticFinalGetter)); |
| 559 #endif | 568 #endif |
| 569 if (FLAG_enable_type_checks) { |
| 570 rhs = new AssignableNode( |
| 571 field.token_pos(), |
| 572 rhs, |
| 573 AbstractType::ZoneHandle(field.type()), |
| 574 String::ZoneHandle(field.name())); |
| 575 } |
| 560 return new StoreStaticFieldNode(token_pos(), field, rhs); | 576 return new StoreStaticFieldNode(token_pos(), field, rhs); |
| 561 } | 577 } |
| 562 // Didn't find a static setter or a static field. | 578 // Didn't find a static setter or a static field. |
| 563 // If this static getter is in an instance function where | 579 // If this static getter is in an instance function where |
| 564 // a receiver is available, we turn this static getter | 580 // a receiver is available, we turn this static getter |
| 565 // into an instance setter (and will get an error at runtime if an | 581 // into an instance setter (and will get an error at runtime if an |
| 566 // instance setter cannot be found either). | 582 // instance setter cannot be found either). |
| 567 if (receiver() != NULL) { | 583 if (receiver() != NULL) { |
| 568 return new InstanceSetterNode(token_pos(), receiver(), field_name(), rhs); | 584 return new InstanceSetterNode(token_pos(), receiver(), field_name(), rhs); |
| 569 } | 585 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 if (result.IsError() || result.IsNull()) { | 632 if (result.IsError() || result.IsNull()) { |
| 617 // TODO(turnidge): We could get better error messages by returning | 633 // TODO(turnidge): We could get better error messages by returning |
| 618 // the Error object directly to the parser. This will involve | 634 // the Error object directly to the parser. This will involve |
| 619 // replumbing all of the EvalConstExpr methods. | 635 // replumbing all of the EvalConstExpr methods. |
| 620 return NULL; | 636 return NULL; |
| 621 } | 637 } |
| 622 return &Instance::ZoneHandle(Instance::Cast(result).raw()); | 638 return &Instance::ZoneHandle(Instance::Cast(result).raw()); |
| 623 } | 639 } |
| 624 | 640 |
| 625 } // namespace dart | 641 } // namespace dart |
| OLD | NEW |