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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // parsing as the assignment context was not known yet at that time. | 121 // parsing as the assignment context was not known yet at that time. |
122 virtual AstNode* MakeAssignmentNode(AstNode* rhs) { | 122 virtual AstNode* MakeAssignmentNode(AstNode* rhs) { |
123 return NULL; // By default all nodes are not assignable. | 123 return NULL; // By default all nodes are not assignable. |
124 } | 124 } |
125 | 125 |
126 // Return NULL if 'unary_op_kind' can't be applied. | 126 // Return NULL if 'unary_op_kind' can't be applied. |
127 virtual AstNode* ApplyUnaryOp(Token::Kind unary_op_kind) { | 127 virtual AstNode* ApplyUnaryOp(Token::Kind unary_op_kind) { |
128 return NULL; | 128 return NULL; |
129 } | 129 } |
130 | 130 |
| 131 virtual bool IsPotentiallyConst() const { return false; } |
| 132 |
131 // Analyzes an expression to determine whether it is a compile time | 133 // Analyzes an expression to determine whether it is a compile time |
132 // constant or not. Returns NULL if the expression is not a compile time | 134 // constant or not. Returns NULL if the expression is not a compile time |
133 // constant. Otherwise, the return value is an approximation of the | 135 // constant. Otherwise, the return value is an approximation of the |
134 // actual value of the const expression. The type of the returned value | 136 // actual value of the const expression. The type of the returned value |
135 // corresponds to the type of the const expression and is either | 137 // corresponds to the type of the const expression and is either |
136 // Number, Integer, String, Bool, or anything else (not a subtype of | 138 // Number, Integer, String, Bool, or anything else (not a subtype of |
137 // the former). | 139 // the former). |
138 virtual const Instance* EvalConstExpr() const { return NULL; } | 140 virtual const Instance* EvalConstExpr() const { return NULL; } |
139 | 141 |
140 protected: | 142 protected: |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 ASSERT(String::Cast(literal_).IsSymbol()); | 322 ASSERT(String::Cast(literal_).IsSymbol()); |
321 } | 323 } |
322 #endif // defined(DEBUG) | 324 #endif // defined(DEBUG) |
323 ASSERT(literal_.IsNull() || | 325 ASSERT(literal_.IsNull() || |
324 Class::Handle(literal_.clazz()).is_finalized() || | 326 Class::Handle(literal_.clazz()).is_finalized() || |
325 Class::Handle(literal_.clazz()).is_prefinalized()); | 327 Class::Handle(literal_.clazz()).is_prefinalized()); |
326 } | 328 } |
327 | 329 |
328 const Instance& literal() const { return literal_; } | 330 const Instance& literal() const { return literal_; } |
329 | 331 |
| 332 virtual bool IsPotentiallyConst() const; |
330 virtual const Instance* EvalConstExpr() const { | 333 virtual const Instance* EvalConstExpr() const { |
331 return &literal(); | 334 return &literal(); |
332 } | 335 } |
333 | 336 |
334 virtual void VisitChildren(AstNodeVisitor* visitor) const { } | 337 virtual void VisitChildren(AstNodeVisitor* visitor) const { } |
335 | 338 |
336 virtual AstNode* ApplyUnaryOp(Token::Kind unary_op_kind); | 339 virtual AstNode* ApplyUnaryOp(Token::Kind unary_op_kind); |
337 | 340 |
338 DECLARE_COMMON_NODE_FUNCTIONS(LiteralNode); | 341 DECLARE_COMMON_NODE_FUNCTIONS(LiteralNode); |
339 | 342 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 AstNode* receiver() const { return receiver_; } | 432 AstNode* receiver() const { return receiver_; } |
430 LocalScope* scope() const { return scope_; } | 433 LocalScope* scope() const { return scope_; } |
431 | 434 |
432 virtual void VisitChildren(AstNodeVisitor* visitor) const { | 435 virtual void VisitChildren(AstNodeVisitor* visitor) const { |
433 if (receiver() != NULL) { | 436 if (receiver() != NULL) { |
434 receiver()->Visit(visitor); | 437 receiver()->Visit(visitor); |
435 } | 438 } |
436 } | 439 } |
437 | 440 |
438 virtual AstNode* MakeAssignmentNode(AstNode* rhs); | 441 virtual AstNode* MakeAssignmentNode(AstNode* rhs); |
439 | 442 virtual bool IsPotentiallyConst() const; |
440 virtual const Instance* EvalConstExpr() const; | 443 virtual const Instance* EvalConstExpr() const; |
441 | 444 |
442 DECLARE_COMMON_NODE_FUNCTIONS(ClosureNode); | 445 DECLARE_COMMON_NODE_FUNCTIONS(ClosureNode); |
443 | 446 |
444 private: | 447 private: |
445 const Function& function_; | 448 const Function& function_; |
446 AstNode* receiver_; | 449 AstNode* receiver_; |
447 LocalScope* scope_; | 450 LocalScope* scope_; |
448 | 451 |
449 DISALLOW_IMPLICIT_CONSTRUCTORS(ClosureNode); | 452 DISALLOW_IMPLICIT_CONSTRUCTORS(ClosureNode); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 Token::Kind kind() const { return kind_; } | 538 Token::Kind kind() const { return kind_; } |
536 AstNode* left() const { return left_; } | 539 AstNode* left() const { return left_; } |
537 AstNode* right() const { return right_; } | 540 AstNode* right() const { return right_; } |
538 | 541 |
539 virtual void VisitChildren(AstNodeVisitor* visitor) const { | 542 virtual void VisitChildren(AstNodeVisitor* visitor) const { |
540 left()->Visit(visitor); | 543 left()->Visit(visitor); |
541 right()->Visit(visitor); | 544 right()->Visit(visitor); |
542 } | 545 } |
543 | 546 |
544 virtual const char* Name() const; | 547 virtual const char* Name() const; |
| 548 virtual bool IsPotentiallyConst() const; |
545 virtual const Instance* EvalConstExpr() const; | 549 virtual const Instance* EvalConstExpr() const; |
546 | 550 |
547 DECLARE_COMMON_NODE_FUNCTIONS(ComparisonNode); | 551 DECLARE_COMMON_NODE_FUNCTIONS(ComparisonNode); |
548 | 552 |
549 private: | 553 private: |
550 const Token::Kind kind_; | 554 const Token::Kind kind_; |
551 AstNode* left_; | 555 AstNode* left_; |
552 AstNode* right_; | 556 AstNode* right_; |
553 | 557 |
554 bool IsKindValid() const; | 558 bool IsKindValid() const; |
(...skipping 17 matching lines...) Expand all Loading... |
572 Token::Kind kind() const { return kind_; } | 576 Token::Kind kind() const { return kind_; } |
573 AstNode* left() const { return left_; } | 577 AstNode* left() const { return left_; } |
574 AstNode* right() const { return right_; } | 578 AstNode* right() const { return right_; } |
575 | 579 |
576 virtual void VisitChildren(AstNodeVisitor* visitor) const { | 580 virtual void VisitChildren(AstNodeVisitor* visitor) const { |
577 left()->Visit(visitor); | 581 left()->Visit(visitor); |
578 right()->Visit(visitor); | 582 right()->Visit(visitor); |
579 } | 583 } |
580 | 584 |
581 virtual const char* Name() const; | 585 virtual const char* Name() const; |
| 586 virtual bool IsPotentiallyConst() const; |
582 virtual const Instance* EvalConstExpr() const; | 587 virtual const Instance* EvalConstExpr() const; |
583 | 588 |
584 DECLARE_COMMON_NODE_FUNCTIONS(BinaryOpNode); | 589 DECLARE_COMMON_NODE_FUNCTIONS(BinaryOpNode); |
585 | 590 |
586 private: | 591 private: |
587 const Token::Kind kind_; | 592 const Token::Kind kind_; |
588 AstNode* left_; | 593 AstNode* left_; |
589 AstNode* right_; | 594 AstNode* right_; |
590 | 595 |
591 bool IsKindValid() const; | 596 bool IsKindValid() const; |
(...skipping 17 matching lines...) Expand all Loading... |
609 } | 614 } |
610 | 615 |
611 Token::Kind kind() const { return kind_; } | 616 Token::Kind kind() const { return kind_; } |
612 AstNode* operand() const { return operand_; } | 617 AstNode* operand() const { return operand_; } |
613 | 618 |
614 virtual void VisitChildren(AstNodeVisitor* visitor) const { | 619 virtual void VisitChildren(AstNodeVisitor* visitor) const { |
615 operand()->Visit(visitor); | 620 operand()->Visit(visitor); |
616 } | 621 } |
617 | 622 |
618 virtual const char* Name() const; | 623 virtual const char* Name() const; |
| 624 virtual bool IsPotentiallyConst() const; |
619 virtual const Instance* EvalConstExpr() const; | 625 virtual const Instance* EvalConstExpr() const; |
620 | 626 |
621 DECLARE_COMMON_NODE_FUNCTIONS(UnaryOpNode); | 627 DECLARE_COMMON_NODE_FUNCTIONS(UnaryOpNode); |
622 | 628 |
623 private: | 629 private: |
624 const Token::Kind kind_; | 630 const Token::Kind kind_; |
625 AstNode* operand_; | 631 AstNode* operand_; |
626 | 632 |
627 bool IsKindValid() const; | 633 bool IsKindValid() const; |
628 | 634 |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 LoadLocalNode(intptr_t token_pos, const LocalVariable* local) | 957 LoadLocalNode(intptr_t token_pos, const LocalVariable* local) |
952 : AstNode(token_pos), local_(*local) { | 958 : AstNode(token_pos), local_(*local) { |
953 ASSERT(local != NULL); | 959 ASSERT(local != NULL); |
954 } | 960 } |
955 | 961 |
956 const LocalVariable& local() const { return local_; } | 962 const LocalVariable& local() const { return local_; } |
957 | 963 |
958 virtual void VisitChildren(AstNodeVisitor* visitor) const { } | 964 virtual void VisitChildren(AstNodeVisitor* visitor) const { } |
959 | 965 |
960 virtual const Instance* EvalConstExpr() const; | 966 virtual const Instance* EvalConstExpr() const; |
| 967 virtual bool IsPotentiallyConst() const; |
961 virtual AstNode* MakeAssignmentNode(AstNode* rhs); | 968 virtual AstNode* MakeAssignmentNode(AstNode* rhs); |
962 | 969 |
963 DECLARE_COMMON_NODE_FUNCTIONS(LoadLocalNode); | 970 DECLARE_COMMON_NODE_FUNCTIONS(LoadLocalNode); |
964 | 971 |
965 private: | 972 private: |
966 const LocalVariable& local_; | 973 const LocalVariable& local_; |
967 | 974 |
968 DISALLOW_IMPLICIT_CONSTRUCTORS(LoadLocalNode); | 975 DISALLOW_IMPLICIT_CONSTRUCTORS(LoadLocalNode); |
969 }; | 976 }; |
970 | 977 |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 // static getter, but no field and no static setter are declared. | 1323 // static getter, but no field and no static setter are declared. |
1317 AstNode* receiver() const { return receiver_; } | 1324 AstNode* receiver() const { return receiver_; } |
1318 const Class& cls() const { return cls_; } | 1325 const Class& cls() const { return cls_; } |
1319 const String& field_name() const { return field_name_; } | 1326 const String& field_name() const { return field_name_; } |
1320 bool is_super_getter() const { return is_super_getter_; } | 1327 bool is_super_getter() const { return is_super_getter_; } |
1321 | 1328 |
1322 virtual void VisitChildren(AstNodeVisitor* visitor) const { } | 1329 virtual void VisitChildren(AstNodeVisitor* visitor) const { } |
1323 | 1330 |
1324 virtual AstNode* MakeAssignmentNode(AstNode* rhs); | 1331 virtual AstNode* MakeAssignmentNode(AstNode* rhs); |
1325 | 1332 |
| 1333 virtual bool IsPotentiallyConst() const; |
1326 virtual const Instance* EvalConstExpr() const; | 1334 virtual const Instance* EvalConstExpr() const; |
1327 | 1335 |
1328 DECLARE_COMMON_NODE_FUNCTIONS(StaticGetterNode); | 1336 DECLARE_COMMON_NODE_FUNCTIONS(StaticGetterNode); |
1329 | 1337 |
1330 private: | 1338 private: |
1331 AstNode* receiver_; | 1339 AstNode* receiver_; |
1332 const Class& cls_; | 1340 const Class& cls_; |
1333 const String& field_name_; | 1341 const String& field_name_; |
1334 const bool is_super_getter_; | 1342 const bool is_super_getter_; |
1335 | 1343 |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1683 const LocalVariable& context_var_; | 1691 const LocalVariable& context_var_; |
1684 | 1692 |
1685 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); | 1693 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); |
1686 }; | 1694 }; |
1687 | 1695 |
1688 } // namespace dart | 1696 } // namespace dart |
1689 | 1697 |
1690 #undef DECLARE_COMMON_NODE_FUNCTIONS | 1698 #undef DECLARE_COMMON_NODE_FUNCTIONS |
1691 | 1699 |
1692 #endif // VM_AST_H_ | 1700 #endif // VM_AST_H_ |
OLD | NEW |