Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(839)

Side by Side Diff: runtime/vm/ast.h

Issue 10354019: Removing all incr-op nodes. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/ast.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 NODE_LIST(V) \ 18 #define NODE_LIST(V) \
19 V(ReturnNode, "return") \ 19 V(ReturnNode, "return") \
20 V(LiteralNode, "literal") \ 20 V(LiteralNode, "literal") \
21 V(TypeNode, "type") \ 21 V(TypeNode, "type") \
22 V(AssignableNode, "assignable") \ 22 V(AssignableNode, "assignable") \
23 V(BinaryOpNode, "binop") \ 23 V(BinaryOpNode, "binop") \
24 V(StringConcatNode, "concat") \ 24 V(StringConcatNode, "concat") \
25 V(ComparisonNode, "compare") \ 25 V(ComparisonNode, "compare") \
26 V(UnaryOpNode, "unaryop") \ 26 V(UnaryOpNode, "unaryop") \
27 V(IncrOpInstanceFieldNode, "incr instance field") \
28 V(IncrOpIndexedNode, "incr indexed") \
29 V(ConditionalExprNode, "?:") \ 27 V(ConditionalExprNode, "?:") \
30 V(IfNode, "if") \ 28 V(IfNode, "if") \
31 V(SwitchNode, "switch") \ 29 V(SwitchNode, "switch") \
32 V(CaseNode, "case") \ 30 V(CaseNode, "case") \
33 V(WhileNode, "while") \ 31 V(WhileNode, "while") \
34 V(DoWhileNode, "dowhile") \ 32 V(DoWhileNode, "dowhile") \
35 V(ForNode, "for") \ 33 V(ForNode, "for") \
36 V(JumpNode, "jump") \ 34 V(JumpNode, "jump") \
37 V(ArgumentListNode, "args") \ 35 V(ArgumentListNode, "args") \
38 V(ArrayNode, "array") \ 36 V(ArrayNode, "array") \
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // parsing as the assignment context was not known yet at that time. 145 // parsing as the assignment context was not known yet at that time.
148 virtual AstNode* MakeAssignmentNode(AstNode* rhs) { 146 virtual AstNode* MakeAssignmentNode(AstNode* rhs) {
149 return NULL; // By default all nodes are not assignable. 147 return NULL; // By default all nodes are not assignable.
150 } 148 }
151 149
152 // Return NULL if 'unary_op_kind' can't be applied. 150 // Return NULL if 'unary_op_kind' can't be applied.
153 virtual AstNode* ApplyUnaryOp(Token::Kind unary_op_kind) { 151 virtual AstNode* ApplyUnaryOp(Token::Kind unary_op_kind) {
154 return NULL; 152 return NULL;
155 } 153 }
156 154
157 // Creates a an IncrOpXXXNode that corresponds to this node type, e.g.,
158 // LoadLocalNode creates the appropriate IncrOpLocalNode
159 virtual AstNode* MakeIncrOpNode(intptr_t token_index,
160 Token::Kind kind,
161 bool is_prefix) {
162 return NULL;
163 }
164
165 // Analyzes an expression to determine whether it is a compile time 155 // Analyzes an expression to determine whether it is a compile time
166 // constant or not. Returns NULL if the expression is not a compile time 156 // constant or not. Returns NULL if the expression is not a compile time
167 // constant. Otherwise, the return value is an approximation of the 157 // constant. Otherwise, the return value is an approximation of the
168 // actual value of the const expression. The type of the returned value 158 // actual value of the const expression. The type of the returned value
169 // corresponds to the type of the const expression and is either 159 // corresponds to the type of the const expression and is either
170 // Number, Integer, String, Bool, or anything else (not a subtype of 160 // Number, Integer, String, Bool, or anything else (not a subtype of
171 // the former). 161 // the former).
172 virtual const Instance* EvalConstExpr() const { return NULL; } 162 virtual const Instance* EvalConstExpr() const { return NULL; }
173 163
174 protected: 164 protected:
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 private: 644 private:
655 const Token::Kind kind_; 645 const Token::Kind kind_;
656 AstNode* operand_; 646 AstNode* operand_;
657 647
658 bool IsKindValid() const; 648 bool IsKindValid() const;
659 649
660 DISALLOW_IMPLICIT_CONSTRUCTORS(UnaryOpNode); 650 DISALLOW_IMPLICIT_CONSTRUCTORS(UnaryOpNode);
661 }; 651 };
662 652
663 653
664 class IncrOpInstanceFieldNode : public AstNode {
665 public:
666 IncrOpInstanceFieldNode(intptr_t token_index,
667 Token::Kind kind,
668 bool prefix,
669 AstNode* receiver,
670 const String& field_name)
671 : AstNode(token_index),
672 kind_(kind),
673 prefix_(prefix),
674 receiver_(receiver),
675 field_name_(field_name),
676 operator_id_(AstNode::GetNextId()),
677 setter_id_(AstNode::GetNextId()),
678 operator_ic_data_(ICData::ZoneHandle()),
679 setter_ic_data_(ICData::ZoneHandle()) {
680 ASSERT(receiver_ != NULL);
681 ASSERT(field_name_.IsZoneHandle());
682 ASSERT(kind_ == Token::kINCR || kind_ == Token::kDECR);
683 }
684
685 Token::Kind kind() const { return kind_; }
686 bool prefix() const { return prefix_; }
687 AstNode* receiver() const { return receiver_; }
688 const String& field_name() const { return field_name_; }
689
690 intptr_t getter_id() const { return id(); }
691 intptr_t operator_id() const { return operator_id_; }
692 intptr_t setter_id() const { return setter_id_; }
693
694 virtual bool HasId(intptr_t value) const {
695 return (getter_id() == value) ||
696 (operator_id() == value) ||
697 (setter_id() == value);
698 }
699
700 virtual void SetIcDataAtId(intptr_t node_id, const ICData& value) {
701 ASSERT(HasId(node_id));
702 if (node_id == getter_id()) {
703 set_ic_data(value);
704 } else if (node_id == operator_id()) {
705 operator_ic_data_ = value.raw();
706 } else {
707 ASSERT(node_id == setter_id());
708 setter_ic_data_ = value.raw();
709 }
710 }
711
712 virtual const ICData& ICDataAtId(intptr_t node_id) const {
713 ASSERT(HasId(node_id));
714 if (node_id == getter_id()) {
715 return ic_data();
716 } else if (node_id == operator_id()) {
717 return operator_ic_data_;
718 } else {
719 ASSERT(node_id == setter_id());
720 return setter_ic_data_;
721 }
722 }
723
724 virtual void VisitChildren(AstNodeVisitor* visitor) const {
725 receiver()->Visit(visitor);
726 }
727
728 virtual const char* Name() const;
729
730 DECLARE_COMMON_NODE_FUNCTIONS(IncrOpInstanceFieldNode);
731
732 private:
733 const Token::Kind kind_;
734 const bool prefix_;
735 AstNode* receiver_;
736 const String& field_name_;
737 const intptr_t operator_id_;
738 const intptr_t setter_id_;
739 ICData& operator_ic_data_;
740 ICData& setter_ic_data_;
741
742 DISALLOW_IMPLICIT_CONSTRUCTORS(IncrOpInstanceFieldNode);
743 };
744
745
746 class IncrOpIndexedNode : public AstNode {
747 public:
748 IncrOpIndexedNode(intptr_t token_index,
749 Token::Kind kind,
750 bool prefix,
751 AstNode* array,
752 AstNode* index)
753 : AstNode(token_index),
754 kind_(kind),
755 prefix_(prefix),
756 array_(array),
757 index_(index),
758 operator_id_(AstNode::GetNextId()),
759 store_id_(AstNode::GetNextId()),
760 operator_ic_data_(ICData::ZoneHandle()),
761 store_ic_data_(ICData::ZoneHandle()) {
762 ASSERT(kind_ == Token::kINCR || kind_ == Token::kDECR);
763 ASSERT(array_ != NULL);
764 ASSERT(index_ != NULL);
765 }
766
767 Token::Kind kind() const { return kind_; }
768 bool prefix() const { return prefix_; }
769 AstNode* array() const { return array_; }
770 AstNode* index() const { return index_; }
771
772 intptr_t load_id() const { return id(); }
773 intptr_t operator_id() const { return operator_id_; }
774 intptr_t store_id() const { return store_id_; }
775
776 virtual bool HasId(intptr_t value) const {
777 return (load_id() == value) ||
778 (operator_id() == value) ||
779 (store_id() == value);
780 }
781
782 virtual const ICData& ICDataAtId(intptr_t node_id) const {
783 ASSERT(HasId(node_id));
784 if (node_id == load_id()) {
785 return ic_data();
786 } else if (node_id == operator_id()) {
787 return operator_ic_data_;
788 } else {
789 ASSERT(node_id == store_id());
790 return store_ic_data_;
791 }
792 }
793
794 virtual void SetIcDataAtId(intptr_t node_id, const ICData& value) {
795 ASSERT(HasId(node_id));
796 if (node_id == load_id()) {
797 set_ic_data(value);
798 } else if (node_id == operator_id()) {
799 operator_ic_data_ = value.raw();
800 } else {
801 ASSERT(node_id == store_id());
802 store_ic_data_ = value.raw();
803 }
804 }
805
806 virtual void VisitChildren(AstNodeVisitor* visitor) const {
807 array()->Visit(visitor);
808 index()->Visit(visitor);
809 }
810
811 virtual const char* Name() const;
812
813 DECLARE_COMMON_NODE_FUNCTIONS(IncrOpIndexedNode);
814
815 private:
816 const Token::Kind kind_;
817 const bool prefix_;
818 AstNode* array_;
819 AstNode* index_;
820 const intptr_t operator_id_;
821 const intptr_t store_id_;
822 ICData& operator_ic_data_;
823 ICData& store_ic_data_;
824 };
825
826
827 class ConditionalExprNode : public AstNode { 654 class ConditionalExprNode : public AstNode {
828 public: 655 public:
829 ConditionalExprNode(intptr_t token_index, 656 ConditionalExprNode(intptr_t token_index,
830 AstNode* condition, 657 AstNode* condition,
831 AstNode* true_expr, 658 AstNode* true_expr,
832 AstNode* false_expr) 659 AstNode* false_expr)
833 : AstNode(token_index), 660 : AstNode(token_index),
834 condition_(condition), 661 condition_(condition),
835 true_expr_(true_expr), 662 true_expr_(true_expr),
836 false_expr_(false_expr) { 663 false_expr_(false_expr) {
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 bool HasPseudo() const { return pseudo_ != NULL; } 974 bool HasPseudo() const { return pseudo_ != NULL; }
1148 975
1149 virtual void VisitChildren(AstNodeVisitor* visitor) const { 976 virtual void VisitChildren(AstNodeVisitor* visitor) const {
1150 if (HasPseudo()) { 977 if (HasPseudo()) {
1151 pseudo()->Visit(visitor); 978 pseudo()->Visit(visitor);
1152 } 979 }
1153 } 980 }
1154 981
1155 virtual AstNode* MakeAssignmentNode(AstNode* rhs); 982 virtual AstNode* MakeAssignmentNode(AstNode* rhs);
1156 983
1157 virtual AstNode* MakeIncrOpNode(intptr_t token_index,
1158 Token::Kind kind,
1159 bool is_prefix);
1160
1161 DECLARE_COMMON_NODE_FUNCTIONS(LoadLocalNode); 984 DECLARE_COMMON_NODE_FUNCTIONS(LoadLocalNode);
1162 985
1163 private: 986 private:
1164 const LocalVariable& local_; 987 const LocalVariable& local_;
1165 AstNode* pseudo_; 988 AstNode* pseudo_;
1166 989
1167 DISALLOW_IMPLICIT_CONSTRUCTORS(LoadLocalNode); 990 DISALLOW_IMPLICIT_CONSTRUCTORS(LoadLocalNode);
1168 }; 991 };
1169 992
1170 993
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 : AstNode(token_index), field_(field) { 1086 : AstNode(token_index), field_(field) {
1264 ASSERT(field.IsZoneHandle()); 1087 ASSERT(field.IsZoneHandle());
1265 } 1088 }
1266 1089
1267 const Field& field() const { return field_; } 1090 const Field& field() const { return field_; }
1268 1091
1269 virtual void VisitChildren(AstNodeVisitor* visitor) const { } 1092 virtual void VisitChildren(AstNodeVisitor* visitor) const { }
1270 1093
1271 virtual AstNode* MakeAssignmentNode(AstNode* rhs); 1094 virtual AstNode* MakeAssignmentNode(AstNode* rhs);
1272 1095
1273 virtual AstNode* MakeIncrOpNode(intptr_t token_index,
1274 Token::Kind kind,
1275 bool is_prefix);
1276
1277 virtual const Instance* EvalConstExpr() const { 1096 virtual const Instance* EvalConstExpr() const {
1278 ASSERT(field_.is_static()); 1097 ASSERT(field_.is_static());
1279 return field_.is_final() ? &Instance::ZoneHandle(field_.value()) : NULL; 1098 return field_.is_final() ? &Instance::ZoneHandle(field_.value()) : NULL;
1280 } 1099 }
1281 1100
1282 DECLARE_COMMON_NODE_FUNCTIONS(LoadStaticFieldNode); 1101 DECLARE_COMMON_NODE_FUNCTIONS(LoadStaticFieldNode);
1283 1102
1284 private: 1103 private:
1285 const Field& field_; 1104 const Field& field_;
1286 1105
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 AstNode* array() const { return array_; } 1143 AstNode* array() const { return array_; }
1325 AstNode* index_expr() const { return index_expr_; } 1144 AstNode* index_expr() const { return index_expr_; }
1326 1145
1327 virtual void VisitChildren(AstNodeVisitor* visitor) const { 1146 virtual void VisitChildren(AstNodeVisitor* visitor) const {
1328 array()->Visit(visitor); 1147 array()->Visit(visitor);
1329 index_expr()->Visit(visitor); 1148 index_expr()->Visit(visitor);
1330 } 1149 }
1331 1150
1332 virtual AstNode* MakeAssignmentNode(AstNode* rhs); 1151 virtual AstNode* MakeAssignmentNode(AstNode* rhs);
1333 1152
1334 virtual AstNode* MakeIncrOpNode(intptr_t token_index,
1335 Token::Kind kind,
1336 bool is_prefix);
1337
1338 DECLARE_COMMON_NODE_FUNCTIONS(LoadIndexedNode); 1153 DECLARE_COMMON_NODE_FUNCTIONS(LoadIndexedNode);
1339 1154
1340 private: 1155 private:
1341 AstNode* array_; 1156 AstNode* array_;
1342 AstNode* index_expr_; 1157 AstNode* index_expr_;
1343 DISALLOW_IMPLICIT_CONSTRUCTORS(LoadIndexedNode); 1158 DISALLOW_IMPLICIT_CONSTRUCTORS(LoadIndexedNode);
1344 }; 1159 };
1345 1160
1346 1161
1347 class StoreIndexedNode : public AstNode { 1162 class StoreIndexedNode : public AstNode {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 1240
1426 AstNode* receiver() const { return receiver_; } 1241 AstNode* receiver() const { return receiver_; }
1427 const String& field_name() const { return field_name_; } 1242 const String& field_name() const { return field_name_; }
1428 1243
1429 virtual void VisitChildren(AstNodeVisitor* visitor) const { 1244 virtual void VisitChildren(AstNodeVisitor* visitor) const {
1430 receiver()->Visit(visitor); 1245 receiver()->Visit(visitor);
1431 } 1246 }
1432 1247
1433 virtual AstNode* MakeAssignmentNode(AstNode* rhs); 1248 virtual AstNode* MakeAssignmentNode(AstNode* rhs);
1434 1249
1435 virtual AstNode* MakeIncrOpNode(intptr_t token_index,
1436 Token::Kind kind,
1437 bool is_prefix);
1438
1439 DECLARE_COMMON_NODE_FUNCTIONS(InstanceGetterNode); 1250 DECLARE_COMMON_NODE_FUNCTIONS(InstanceGetterNode);
1440 1251
1441 private: 1252 private:
1442 AstNode* receiver_; 1253 AstNode* receiver_;
1443 const String& field_name_; 1254 const String& field_name_;
1444 1255
1445 DISALLOW_IMPLICIT_CONSTRUCTORS(InstanceGetterNode); 1256 DISALLOW_IMPLICIT_CONSTRUCTORS(InstanceGetterNode);
1446 }; 1257 };
1447 1258
1448 1259
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 ASSERT(field_name_.IsSymbol()); 1306 ASSERT(field_name_.IsSymbol());
1496 } 1307 }
1497 1308
1498 const Class& cls() const { return cls_; } 1309 const Class& cls() const { return cls_; }
1499 const String& field_name() const { return field_name_; } 1310 const String& field_name() const { return field_name_; }
1500 1311
1501 virtual void VisitChildren(AstNodeVisitor* visitor) const { } 1312 virtual void VisitChildren(AstNodeVisitor* visitor) const { }
1502 1313
1503 virtual AstNode* MakeAssignmentNode(AstNode* rhs); 1314 virtual AstNode* MakeAssignmentNode(AstNode* rhs);
1504 1315
1505 virtual AstNode* MakeIncrOpNode(intptr_t token_index,
1506 Token::Kind kind,
1507 bool is_prefix);
1508
1509 virtual const Instance* EvalConstExpr() const; 1316 virtual const Instance* EvalConstExpr() const;
1510 1317
1511 DECLARE_COMMON_NODE_FUNCTIONS(StaticGetterNode); 1318 DECLARE_COMMON_NODE_FUNCTIONS(StaticGetterNode);
1512 1319
1513 private: 1320 private:
1514 const Class& cls_; 1321 const Class& cls_;
1515 const String& field_name_; 1322 const String& field_name_;
1516 1323
1517 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticGetterNode); 1324 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticGetterNode);
1518 }; 1325 };
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 const LocalVariable& context_var_; 1664 const LocalVariable& context_var_;
1858 1665
1859 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); 1666 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode);
1860 }; 1667 };
1861 1668
1862 } // namespace dart 1669 } // namespace dart
1863 1670
1864 #undef DECLARE_COMMON_NODE_FUNCTIONS 1671 #undef DECLARE_COMMON_NODE_FUNCTIONS
1865 1672
1866 #endif // VM_AST_H_ 1673 #endif // VM_AST_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698