OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #ifndef VM_AST_H_ | 5 #ifndef VM_AST_H_ |
6 #define VM_AST_H_ | 6 #define VM_AST_H_ |
7 | 7 |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
(...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 | 1279 |
1280 class LoadStaticFieldNode : public AstNode { | 1280 class LoadStaticFieldNode : public AstNode { |
1281 public: | 1281 public: |
1282 LoadStaticFieldNode(intptr_t token_pos, const Field& field) | 1282 LoadStaticFieldNode(intptr_t token_pos, const Field& field) |
1283 : AstNode(token_pos), field_(field), is_deferred_reference_(false) { | 1283 : AstNode(token_pos), field_(field), is_deferred_reference_(false) { |
1284 ASSERT(field_.IsZoneHandle()); | 1284 ASSERT(field_.IsZoneHandle()); |
1285 } | 1285 } |
1286 | 1286 |
1287 const Field& field() const { return field_; } | 1287 const Field& field() const { return field_; } |
1288 void set_is_deferred(bool value) { is_deferred_reference_ = value; } | 1288 void set_is_deferred(bool value) { is_deferred_reference_ = value; } |
| 1289 bool is_deferred_reference() const { return is_deferred_reference_; } |
1289 | 1290 |
1290 virtual void VisitChildren(AstNodeVisitor* visitor) const { } | 1291 virtual void VisitChildren(AstNodeVisitor* visitor) const { } |
1291 | 1292 |
1292 virtual AstNode* MakeAssignmentNode(AstNode* rhs); | 1293 virtual AstNode* MakeAssignmentNode(AstNode* rhs); |
1293 | 1294 |
1294 virtual bool IsPotentiallyConst() const { | 1295 virtual bool IsPotentiallyConst() const { |
1295 return field_.is_const(); | 1296 return field_.is_const(); |
1296 } | 1297 } |
1297 | 1298 |
1298 virtual const Instance* EvalConstExpr() const { | 1299 virtual const Instance* EvalConstExpr() const { |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1543 | 1544 |
1544 | 1545 |
1545 class StaticGetterNode : public AstNode { | 1546 class StaticGetterNode : public AstNode { |
1546 public: | 1547 public: |
1547 StaticGetterNode(intptr_t token_pos, | 1548 StaticGetterNode(intptr_t token_pos, |
1548 AstNode* receiver, | 1549 AstNode* receiver, |
1549 const Class& cls, | 1550 const Class& cls, |
1550 const String& field_name) | 1551 const String& field_name) |
1551 : AstNode(token_pos), | 1552 : AstNode(token_pos), |
1552 receiver_(receiver), | 1553 receiver_(receiver), |
| 1554 owner_(Object::ZoneHandle(cls.raw())), |
1553 cls_(cls), | 1555 cls_(cls), |
1554 field_name_(field_name), | 1556 field_name_(field_name), |
1555 is_deferred_reference_(false) { | 1557 is_deferred_reference_(false) { |
1556 ASSERT(cls_.IsZoneHandle()); | 1558 ASSERT(cls_.IsZoneHandle()); |
1557 ASSERT(field_name_.IsZoneHandle()); | 1559 ASSERT(field_name_.IsZoneHandle()); |
1558 ASSERT(field_name_.IsSymbol()); | 1560 ASSERT(field_name_.IsSymbol()); |
1559 } | 1561 } |
1560 | 1562 |
1561 // The receiver is required for a super getter (an instance method that | 1563 // The receiver is required for a super getter (an instance method that |
1562 // is resolved at compile time rather than at runtime). | 1564 // is resolved at compile time rather than at runtime). |
1563 AstNode* receiver() const { return receiver_; } | 1565 AstNode* receiver() const { return receiver_; } |
| 1566 |
| 1567 // The getter node needs to remmeber how the getter was referenced |
| 1568 // so that it can resolve a corresponding setter if necessary. |
| 1569 // The owner of this getter is either a class, the top-level library scope, |
| 1570 // or a prefix (if the getter has been referenced throug a library prefix). |
| 1571 void set_owner(const Object& value) { |
| 1572 ASSERT(value.IsLibraryPrefix() || value.IsLibrary() || value.IsClass()); |
| 1573 owner_ = value.raw(); |
| 1574 } |
| 1575 const Object& owner() const { return owner_; } |
| 1576 |
1564 const Class& cls() const { return cls_; } | 1577 const Class& cls() const { return cls_; } |
1565 const String& field_name() const { return field_name_; } | 1578 const String& field_name() const { return field_name_; } |
1566 bool is_super_getter() const { return receiver_ != NULL; } | 1579 bool is_super_getter() const { return receiver_ != NULL; } |
1567 void set_is_deferred(bool value) { is_deferred_reference_ = value; } | 1580 void set_is_deferred(bool value) { is_deferred_reference_ = value; } |
1568 | 1581 |
1569 virtual void VisitChildren(AstNodeVisitor* visitor) const { } | 1582 virtual void VisitChildren(AstNodeVisitor* visitor) const { } |
1570 | 1583 |
1571 virtual AstNode* MakeAssignmentNode(AstNode* rhs); | 1584 virtual AstNode* MakeAssignmentNode(AstNode* rhs); |
1572 | 1585 |
1573 virtual bool IsPotentiallyConst() const; | 1586 virtual bool IsPotentiallyConst() const; |
1574 virtual const Instance* EvalConstExpr() const; | 1587 virtual const Instance* EvalConstExpr() const; |
1575 | 1588 |
1576 DECLARE_COMMON_NODE_FUNCTIONS(StaticGetterNode); | 1589 DECLARE_COMMON_NODE_FUNCTIONS(StaticGetterNode); |
1577 | 1590 |
1578 private: | 1591 private: |
1579 AstNode* receiver_; | 1592 AstNode* receiver_; |
| 1593 Object& owner_; |
1580 const Class& cls_; | 1594 const Class& cls_; |
1581 const String& field_name_; | 1595 const String& field_name_; |
1582 bool is_deferred_reference_; | 1596 bool is_deferred_reference_; |
1583 | 1597 |
1584 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticGetterNode); | 1598 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticGetterNode); |
1585 }; | 1599 }; |
1586 | 1600 |
1587 | 1601 |
1588 class StaticSetterNode : public AstNode { | 1602 class StaticSetterNode : public AstNode { |
1589 public: | 1603 public: |
| 1604 // Static setter with resolved setter function. |
| 1605 StaticSetterNode(intptr_t token_pos, |
| 1606 AstNode* receiver, |
| 1607 const String& field_name, |
| 1608 const Function& function, |
| 1609 AstNode* value) |
| 1610 : AstNode(token_pos), |
| 1611 receiver_(receiver), |
| 1612 cls_(Class::ZoneHandle(function.Owner())), |
| 1613 field_name_(field_name), |
| 1614 function_(function), |
| 1615 value_(value) { |
| 1616 ASSERT(function_.IsZoneHandle()); |
| 1617 ASSERT(function.is_static() || receiver != NULL); |
| 1618 ASSERT(field_name_.IsZoneHandle()); |
| 1619 ASSERT(value_ != NULL); |
| 1620 } |
| 1621 |
| 1622 // For unresolved setters. |
1590 StaticSetterNode(intptr_t token_pos, | 1623 StaticSetterNode(intptr_t token_pos, |
1591 AstNode* receiver, | 1624 AstNode* receiver, |
1592 const Class& cls, | 1625 const Class& cls, |
1593 const String& field_name, | 1626 const String& field_name, |
1594 AstNode* value) | 1627 AstNode* value) |
1595 : AstNode(token_pos), | 1628 : AstNode(token_pos), |
1596 receiver_(receiver), | 1629 receiver_(receiver), |
1597 cls_(cls), | 1630 cls_(cls), |
1598 field_name_(field_name), | 1631 field_name_(field_name), |
1599 value_(value) { | 1632 function_(Function::ZoneHandle()), |
| 1633 value_(value) { |
1600 ASSERT(cls_.IsZoneHandle()); | 1634 ASSERT(cls_.IsZoneHandle()); |
1601 ASSERT(field_name_.IsZoneHandle()); | 1635 ASSERT(field_name_.IsZoneHandle()); |
1602 ASSERT(value_ != NULL); | 1636 ASSERT(value_ != NULL); |
1603 } | 1637 } |
1604 | 1638 |
1605 // The receiver is required for a super setter (an instance method | 1639 // The receiver is required for a super setter (an instance method |
1606 // that is resolved at compile time rather than at runtime). | 1640 // that is resolved at compile time rather than at runtime). |
1607 AstNode* receiver() const { return receiver_; } | 1641 AstNode* receiver() const { return receiver_; } |
1608 const Class& cls() const { return cls_; } | 1642 const Class& cls() const { return cls_; } |
1609 const String& field_name() const { return field_name_; } | 1643 const String& field_name() const { return field_name_; } |
| 1644 // function() returns null for unresolved setters. |
| 1645 const Function& function() const { return function_; } |
1610 AstNode* value() const { return value_; } | 1646 AstNode* value() const { return value_; } |
1611 | 1647 |
1612 virtual void VisitChildren(AstNodeVisitor* visitor) const { | 1648 virtual void VisitChildren(AstNodeVisitor* visitor) const { |
1613 value()->Visit(visitor); | 1649 value()->Visit(visitor); |
1614 } | 1650 } |
1615 | 1651 |
1616 DECLARE_COMMON_NODE_FUNCTIONS(StaticSetterNode); | 1652 DECLARE_COMMON_NODE_FUNCTIONS(StaticSetterNode); |
1617 | 1653 |
1618 private: | 1654 private: |
1619 AstNode* receiver_; | 1655 AstNode* receiver_; |
1620 const Class& cls_; | 1656 const Class& cls_; |
1621 const String& field_name_; | 1657 const String& field_name_; |
| 1658 const Function& function_; |
1622 AstNode* value_; | 1659 AstNode* value_; |
1623 | 1660 |
1624 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticSetterNode); | 1661 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticSetterNode); |
1625 }; | 1662 }; |
1626 | 1663 |
1627 | 1664 |
1628 class StaticCallNode : public AstNode { | 1665 class StaticCallNode : public AstNode { |
1629 public: | 1666 public: |
1630 StaticCallNode(intptr_t token_pos, | 1667 StaticCallNode(intptr_t token_pos, |
1631 const Function& function, | 1668 const Function& function, |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1962 const intptr_t try_index_; | 1999 const intptr_t try_index_; |
1963 | 2000 |
1964 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); | 2001 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); |
1965 }; | 2002 }; |
1966 | 2003 |
1967 } // namespace dart | 2004 } // namespace dart |
1968 | 2005 |
1969 #undef DECLARE_COMMON_NODE_FUNCTIONS | 2006 #undef DECLARE_COMMON_NODE_FUNCTIONS |
1970 | 2007 |
1971 #endif // VM_AST_H_ | 2008 #endif // VM_AST_H_ |
OLD | NEW |