Chromium Code Reviews| 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" |
| 11 #include "vm/scopes.h" | 11 #include "vm/scopes.h" |
| 12 #include "vm/object.h" | 12 #include "vm/object.h" |
| 13 #include "vm/native_entry.h" | 13 #include "vm/native_entry.h" |
| 14 #include "vm/token.h" | 14 #include "vm/token.h" |
| 15 | 15 |
| 16 namespace dart { | 16 namespace dart { |
| 17 | 17 |
| 18 #define FOR_EACH_NODE(V) \ | 18 #define FOR_EACH_NODE(V) \ |
| 19 V(Await) \ | 19 V(Await) \ |
| 20 V(AwaitMarker) \ | |
| 20 V(Return) \ | 21 V(Return) \ |
| 21 V(Literal) \ | 22 V(Literal) \ |
| 22 V(Type) \ | 23 V(Type) \ |
| 23 V(Assignable) \ | 24 V(Assignable) \ |
| 24 V(BinaryOp) \ | 25 V(BinaryOp) \ |
| 25 V(BinaryOpWithMask32) \ | 26 V(BinaryOpWithMask32) \ |
| 26 V(Comparison) \ | 27 V(Comparison) \ |
| 27 V(UnaryOp) \ | 28 V(UnaryOp) \ |
| 28 V(ConditionalExpr) \ | 29 V(ConditionalExpr) \ |
| 29 V(If) \ | 30 V(If) \ |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 | 162 |
| 162 DECLARE_COMMON_NODE_FUNCTIONS(AwaitNode); | 163 DECLARE_COMMON_NODE_FUNCTIONS(AwaitNode); |
| 163 | 164 |
| 164 private: | 165 private: |
| 165 AstNode* expr_; | 166 AstNode* expr_; |
| 166 | 167 |
| 167 DISALLOW_COPY_AND_ASSIGN(AwaitNode); | 168 DISALLOW_COPY_AND_ASSIGN(AwaitNode); |
| 168 }; | 169 }; |
| 169 | 170 |
| 170 | 171 |
| 172 // AwaitMarker nodes are used to generate markers that the FlowGraphBuilder | |
| 173 // relies on. They can occur in two kinds: | |
| 174 // 1) kNewContinuationState: A marker indicating that a new await state needs to | |
| 175 // be added to a function preamble. This type also triggers storing of the | |
| 176 // current context. | |
| 177 // 2) kTargetForContinuation: A marker indicating an entry point for the last | |
|
hausner
2014/08/20 21:42:52
Last as in "most recent" or "previous".
Michael Lippautz (Google)
2014/08/21 16:39:14
done: most recent
| |
| 178 // generated state. | |
| 179 // | |
| 180 // In general it is expected (ASSERT) that the different kinds of markers reach | |
| 181 // the FlowGraphBuilder in alternating order. That is: | |
| 182 // <new state> -> <other nodes> -> <target> -> <other nodes> -> | |
| 183 // <new state> -> ... | |
| 184 class AwaitMarkerNode : public AstNode { | |
| 185 public: | |
| 186 enum Type { | |
| 187 kNewContinuationState, | |
| 188 kTargetForContinuation, | |
| 189 }; | |
| 190 | |
| 191 explicit AwaitMarkerNode(Type type) | |
| 192 : AstNode(Scanner::kNoSourcePos), type_(type) { } | |
| 193 | |
| 194 void VisitChildren(AstNodeVisitor* visitor) const { } | |
| 195 | |
| 196 Type type() const { return type_; } | |
| 197 | |
| 198 LocalScope* scope() const { return scope_; } | |
| 199 void set_scope(LocalScope* scope) { scope_ = scope; } | |
| 200 | |
| 201 DECLARE_COMMON_NODE_FUNCTIONS(AwaitMarkerNode); | |
| 202 | |
| 203 private: | |
| 204 Type type_; | |
| 205 LocalScope* scope_; | |
| 206 | |
| 207 DISALLOW_COPY_AND_ASSIGN(AwaitMarkerNode); | |
| 208 }; | |
| 209 | |
| 210 | |
| 171 class SequenceNode : public AstNode { | 211 class SequenceNode : public AstNode { |
| 172 public: | 212 public: |
| 173 SequenceNode(intptr_t token_pos, LocalScope* scope) | 213 SequenceNode(intptr_t token_pos, LocalScope* scope) |
| 174 : AstNode(token_pos), | 214 : AstNode(token_pos), |
| 175 scope_(scope), | 215 scope_(scope), |
| 176 nodes_(4), | 216 nodes_(4), |
| 177 label_(NULL) { | 217 label_(NULL) { |
| 178 } | 218 } |
| 179 | 219 |
| 180 LocalScope* scope() const { return scope_; } | 220 LocalScope* scope() const { return scope_; } |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 | 569 |
| 530 DECLARE_COMMON_NODE_FUNCTIONS(PrimaryNode); | 570 DECLARE_COMMON_NODE_FUNCTIONS(PrimaryNode); |
| 531 | 571 |
| 532 private: | 572 private: |
| 533 const Object& primary_; | 573 const Object& primary_; |
| 534 bool is_deferred_reference_; | 574 bool is_deferred_reference_; |
| 535 | 575 |
| 536 DISALLOW_IMPLICIT_CONSTRUCTORS(PrimaryNode); | 576 DISALLOW_IMPLICIT_CONSTRUCTORS(PrimaryNode); |
| 537 }; | 577 }; |
| 538 | 578 |
| 539 | 579 // Return nodes can be of different types: |
| 540 // TODO(mlippautz): Implement return nodes that are used to return from a | 580 // * A regular return node that in the case of async functions gets replaced |
| 541 // continuation. | 581 // with appropriate completer calls. This kind is generated by dart code. |
| 582 // * A continuation return that just returns from a function. This kind is | |
| 583 // generated by AST transformers. | |
| 542 class ReturnNode : public AstNode { | 584 class ReturnNode : public AstNode { |
| 543 public: | 585 public: |
| 586 enum Type { | |
|
srdjan
2014/08/20 23:08:42
I would rename the enum since we have a class Type
Michael Lippautz (Google)
2014/08/21 16:39:14
Done.
| |
| 587 kRegular, | |
| 588 kContinuation, | |
| 589 }; | |
| 590 | |
| 544 // Return from a void function returns the null object. | 591 // Return from a void function returns the null object. |
| 545 explicit ReturnNode(intptr_t token_pos) | 592 explicit ReturnNode(intptr_t token_pos) |
| 546 : AstNode(token_pos), | 593 : AstNode(token_pos), |
| 547 value_(new LiteralNode(token_pos, Instance::ZoneHandle())), | 594 value_(new LiteralNode(token_pos, Instance::ZoneHandle())), |
| 548 inlined_finally_list_(), | 595 inlined_finally_list_(), |
| 549 is_regular_return_(true) { } | 596 type_(kRegular) { } |
| 550 // Return from a non-void function. | 597 // Return from a non-void function. |
| 551 ReturnNode(intptr_t token_pos, | 598 ReturnNode(intptr_t token_pos, |
| 552 AstNode* value) | 599 AstNode* value) |
| 553 : AstNode(token_pos), | 600 : AstNode(token_pos), |
| 554 value_(value), | 601 value_(value), |
| 555 inlined_finally_list_(), | 602 inlined_finally_list_(), |
| 556 is_regular_return_(true) { | 603 type_(kRegular) { |
| 557 ASSERT(value_ != NULL); | 604 ASSERT(value_ != NULL); |
| 558 } | 605 } |
| 559 | 606 |
| 560 AstNode* value() const { return value_; } | 607 AstNode* value() const { return value_; } |
| 561 | 608 |
| 562 intptr_t inlined_finally_list_length() const { | 609 intptr_t inlined_finally_list_length() const { |
| 563 return inlined_finally_list_.length(); | 610 return inlined_finally_list_.length(); |
| 564 } | 611 } |
| 565 InlinedFinallyNode* InlinedFinallyNodeAt(intptr_t index) const { | 612 InlinedFinallyNode* InlinedFinallyNodeAt(intptr_t index) const { |
| 566 return inlined_finally_list_[index]; | 613 return inlined_finally_list_[index]; |
| 567 } | 614 } |
| 568 void AddInlinedFinallyNode(InlinedFinallyNode* finally_node) { | 615 void AddInlinedFinallyNode(InlinedFinallyNode* finally_node) { |
| 569 inlined_finally_list_.Add(finally_node); | 616 inlined_finally_list_.Add(finally_node); |
| 570 } | 617 } |
| 571 | 618 |
| 572 virtual void VisitChildren(AstNodeVisitor* visitor) const { | 619 virtual void VisitChildren(AstNodeVisitor* visitor) const { |
| 573 if (value() != NULL) { | 620 if (value() != NULL) { |
| 574 value()->Visit(visitor); | 621 value()->Visit(visitor); |
| 575 } | 622 } |
| 576 } | 623 } |
| 577 | 624 |
| 578 void set_scope(LocalScope* scope) { scope_ = scope; } | 625 void set_scope(LocalScope* scope) { scope_ = scope; } |
| 579 LocalScope* scope() const { return scope_; } | 626 LocalScope* scope() const { return scope_; } |
| 580 | 627 |
| 581 // Returns false if the return node is used to return from a continuation. | 628 Type type() const { return type_; } |
| 582 bool is_regular_return() const { return is_regular_return_; } | 629 void set_type(Type type) { type_ = type; } |
| 583 | 630 |
| 584 DECLARE_COMMON_NODE_FUNCTIONS(ReturnNode); | 631 DECLARE_COMMON_NODE_FUNCTIONS(ReturnNode); |
| 585 | 632 |
| 586 private: | 633 private: |
| 587 AstNode* value_; | 634 AstNode* value_; |
| 588 GrowableArray<InlinedFinallyNode*> inlined_finally_list_; | 635 GrowableArray<InlinedFinallyNode*> inlined_finally_list_; |
| 589 LocalScope* scope_; | 636 LocalScope* scope_; |
| 590 bool is_regular_return_; | 637 Type type_; |
|
srdjan
2014/08/20 23:08:42
Add printing of type to ReturnNode printing.
Michael Lippautz (Google)
2014/08/21 16:39:14
Done.
| |
| 591 | 638 |
| 592 DISALLOW_COPY_AND_ASSIGN(ReturnNode); | 639 DISALLOW_COPY_AND_ASSIGN(ReturnNode); |
| 593 }; | 640 }; |
| 594 | 641 |
| 595 | 642 |
| 596 class ComparisonNode : public AstNode { | 643 class ComparisonNode : public AstNode { |
| 597 public: | 644 public: |
| 598 ComparisonNode(intptr_t token_pos, | 645 ComparisonNode(intptr_t token_pos, |
| 599 Token::Kind kind, | 646 Token::Kind kind, |
| 600 AstNode* left, | 647 AstNode* left, |
| (...skipping 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1848 const intptr_t try_index_; | 1895 const intptr_t try_index_; |
| 1849 | 1896 |
| 1850 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); | 1897 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); |
| 1851 }; | 1898 }; |
| 1852 | 1899 |
| 1853 } // namespace dart | 1900 } // namespace dart |
| 1854 | 1901 |
| 1855 #undef DECLARE_COMMON_NODE_FUNCTIONS | 1902 #undef DECLARE_COMMON_NODE_FUNCTIONS |
| 1856 | 1903 |
| 1857 #endif // VM_AST_H_ | 1904 #endif // VM_AST_H_ |
| OLD | NEW |