OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 252 |
253 friend class CaseClause; // Generates AST IDs. | 253 friend class CaseClause; // Generates AST IDs. |
254 }; | 254 }; |
255 | 255 |
256 | 256 |
257 class Statement: public AstNode { | 257 class Statement: public AstNode { |
258 public: | 258 public: |
259 Statement() : statement_pos_(RelocInfo::kNoPosition) {} | 259 Statement() : statement_pos_(RelocInfo::kNoPosition) {} |
260 | 260 |
261 bool IsEmpty() { return AsEmptyStatement() != NULL; } | 261 bool IsEmpty() { return AsEmptyStatement() != NULL; } |
262 virtual bool IsJump() const { return false; } | |
263 | 262 |
264 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } | 263 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } |
265 int statement_pos() const { return statement_pos_; } | 264 int statement_pos() const { return statement_pos_; } |
266 | 265 |
267 private: | 266 private: |
268 int statement_pos_; | 267 int statement_pos_; |
269 }; | 268 }; |
270 | 269 |
271 | 270 |
272 class SmallMapList { | 271 class SmallMapList { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 | 382 |
384 // TODO(rossberg): this should move to its own AST node eventually. | 383 // TODO(rossberg): this should move to its own AST node eventually. |
385 virtual void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle); | 384 virtual void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle); |
386 byte to_boolean_types() const { return to_boolean_types_; } | 385 byte to_boolean_types() const { return to_boolean_types_; } |
387 | 386 |
388 BailoutId id() const { return id_; } | 387 BailoutId id() const { return id_; } |
389 TypeFeedbackId test_id() const { return test_id_; } | 388 TypeFeedbackId test_id() const { return test_id_; } |
390 | 389 |
391 protected: | 390 protected: |
392 explicit Expression(Isolate* isolate) | 391 explicit Expression(Isolate* isolate) |
393 : bounds_(Bounds::Unbounded(isolate)), | 392 : bounds_(Type::None(), Type::Any(), isolate), |
394 id_(GetNextId(isolate)), | 393 id_(GetNextId(isolate)), |
395 test_id_(GetNextId(isolate)) {} | 394 test_id_(GetNextId(isolate)) {} |
396 void set_to_boolean_types(byte types) { to_boolean_types_ = types; } | 395 void set_to_boolean_types(byte types) { to_boolean_types_ = types; } |
397 | 396 |
398 private: | 397 private: |
399 Bounds bounds_; | 398 Bounds bounds_; |
400 byte to_boolean_types_; | 399 byte to_boolean_types_; |
401 | 400 |
402 const BailoutId id_; | 401 const BailoutId id_; |
403 const TypeFeedbackId test_id_; | 402 const TypeFeedbackId test_id_; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 public: | 452 public: |
454 DECLARE_NODE_TYPE(Block) | 453 DECLARE_NODE_TYPE(Block) |
455 | 454 |
456 void AddStatement(Statement* statement, Zone* zone) { | 455 void AddStatement(Statement* statement, Zone* zone) { |
457 statements_.Add(statement, zone); | 456 statements_.Add(statement, zone); |
458 } | 457 } |
459 | 458 |
460 ZoneList<Statement*>* statements() { return &statements_; } | 459 ZoneList<Statement*>* statements() { return &statements_; } |
461 bool is_initializer_block() const { return is_initializer_block_; } | 460 bool is_initializer_block() const { return is_initializer_block_; } |
462 | 461 |
463 virtual bool IsJump() const { | |
464 return !statements_.is_empty() && statements_.last()->IsJump() | |
465 && labels() == NULL; // Good enough as an approximation... | |
466 } | |
467 | |
468 Scope* scope() const { return scope_; } | 462 Scope* scope() const { return scope_; } |
469 void set_scope(Scope* scope) { scope_ = scope; } | 463 void set_scope(Scope* scope) { scope_ = scope; } |
470 | 464 |
471 protected: | 465 protected: |
472 Block(Isolate* isolate, | 466 Block(Isolate* isolate, |
473 ZoneStringList* labels, | 467 ZoneStringList* labels, |
474 int capacity, | 468 int capacity, |
475 bool is_initializer_block, | 469 bool is_initializer_block, |
476 Zone* zone) | 470 Zone* zone) |
477 : BreakableStatement(isolate, labels, TARGET_FOR_NAMED_ONLY), | 471 : BreakableStatement(isolate, labels, TARGET_FOR_NAMED_ONLY), |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 const BailoutId back_edge_id_; | 1002 const BailoutId back_edge_id_; |
1009 }; | 1003 }; |
1010 | 1004 |
1011 | 1005 |
1012 class ExpressionStatement: public Statement { | 1006 class ExpressionStatement: public Statement { |
1013 public: | 1007 public: |
1014 DECLARE_NODE_TYPE(ExpressionStatement) | 1008 DECLARE_NODE_TYPE(ExpressionStatement) |
1015 | 1009 |
1016 void set_expression(Expression* e) { expression_ = e; } | 1010 void set_expression(Expression* e) { expression_ = e; } |
1017 Expression* expression() const { return expression_; } | 1011 Expression* expression() const { return expression_; } |
1018 virtual bool IsJump() const { return expression_->IsThrow(); } | |
1019 | 1012 |
1020 protected: | 1013 protected: |
1021 explicit ExpressionStatement(Expression* expression) | 1014 explicit ExpressionStatement(Expression* expression) |
1022 : expression_(expression) { } | 1015 : expression_(expression) { } |
1023 | 1016 |
1024 private: | 1017 private: |
1025 Expression* expression_; | 1018 Expression* expression_; |
1026 }; | 1019 }; |
1027 | 1020 |
1028 | 1021 |
1029 class JumpStatement: public Statement { | 1022 class ContinueStatement: public Statement { |
1030 public: | |
1031 virtual bool IsJump() const { return true; } | |
1032 | |
1033 protected: | |
1034 JumpStatement() {} | |
1035 }; | |
1036 | |
1037 | |
1038 class ContinueStatement: public JumpStatement { | |
1039 public: | 1023 public: |
1040 DECLARE_NODE_TYPE(ContinueStatement) | 1024 DECLARE_NODE_TYPE(ContinueStatement) |
1041 | 1025 |
1042 IterationStatement* target() const { return target_; } | 1026 IterationStatement* target() const { return target_; } |
1043 | 1027 |
1044 protected: | 1028 protected: |
1045 explicit ContinueStatement(IterationStatement* target) | 1029 explicit ContinueStatement(IterationStatement* target) |
1046 : target_(target) { } | 1030 : target_(target) { } |
1047 | 1031 |
1048 private: | 1032 private: |
1049 IterationStatement* target_; | 1033 IterationStatement* target_; |
1050 }; | 1034 }; |
1051 | 1035 |
1052 | 1036 |
1053 class BreakStatement: public JumpStatement { | 1037 class BreakStatement: public Statement { |
1054 public: | 1038 public: |
1055 DECLARE_NODE_TYPE(BreakStatement) | 1039 DECLARE_NODE_TYPE(BreakStatement) |
1056 | 1040 |
1057 BreakableStatement* target() const { return target_; } | 1041 BreakableStatement* target() const { return target_; } |
1058 | 1042 |
1059 protected: | 1043 protected: |
1060 explicit BreakStatement(BreakableStatement* target) | 1044 explicit BreakStatement(BreakableStatement* target) |
1061 : target_(target) { } | 1045 : target_(target) { } |
1062 | 1046 |
1063 private: | 1047 private: |
1064 BreakableStatement* target_; | 1048 BreakableStatement* target_; |
1065 }; | 1049 }; |
1066 | 1050 |
1067 | 1051 |
1068 class ReturnStatement: public JumpStatement { | 1052 class ReturnStatement: public Statement { |
1069 public: | 1053 public: |
1070 DECLARE_NODE_TYPE(ReturnStatement) | 1054 DECLARE_NODE_TYPE(ReturnStatement) |
1071 | 1055 |
1072 Expression* expression() const { return expression_; } | 1056 Expression* expression() const { return expression_; } |
1073 | 1057 |
1074 protected: | 1058 protected: |
1075 explicit ReturnStatement(Expression* expression) | 1059 explicit ReturnStatement(Expression* expression) |
1076 : expression_(expression) { } | 1060 : expression_(expression) { } |
1077 | 1061 |
1078 private: | 1062 private: |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 public: | 1161 public: |
1178 DECLARE_NODE_TYPE(IfStatement) | 1162 DECLARE_NODE_TYPE(IfStatement) |
1179 | 1163 |
1180 bool HasThenStatement() const { return !then_statement()->IsEmpty(); } | 1164 bool HasThenStatement() const { return !then_statement()->IsEmpty(); } |
1181 bool HasElseStatement() const { return !else_statement()->IsEmpty(); } | 1165 bool HasElseStatement() const { return !else_statement()->IsEmpty(); } |
1182 | 1166 |
1183 Expression* condition() const { return condition_; } | 1167 Expression* condition() const { return condition_; } |
1184 Statement* then_statement() const { return then_statement_; } | 1168 Statement* then_statement() const { return then_statement_; } |
1185 Statement* else_statement() const { return else_statement_; } | 1169 Statement* else_statement() const { return else_statement_; } |
1186 | 1170 |
1187 virtual bool IsJump() const { | |
1188 return HasThenStatement() && then_statement()->IsJump() | |
1189 && HasElseStatement() && else_statement()->IsJump(); | |
1190 } | |
1191 | |
1192 BailoutId IfId() const { return if_id_; } | 1171 BailoutId IfId() const { return if_id_; } |
1193 BailoutId ThenId() const { return then_id_; } | 1172 BailoutId ThenId() const { return then_id_; } |
1194 BailoutId ElseId() const { return else_id_; } | 1173 BailoutId ElseId() const { return else_id_; } |
1195 | 1174 |
1196 protected: | 1175 protected: |
1197 IfStatement(Isolate* isolate, | 1176 IfStatement(Isolate* isolate, |
1198 Expression* condition, | 1177 Expression* condition, |
1199 Statement* then_statement, | 1178 Statement* then_statement, |
1200 Statement* else_statement) | 1179 Statement* else_statement) |
1201 : condition_(condition), | 1180 : condition_(condition), |
(...skipping 2028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3230 private: | 3209 private: |
3231 Isolate* isolate_; | 3210 Isolate* isolate_; |
3232 Zone* zone_; | 3211 Zone* zone_; |
3233 Visitor visitor_; | 3212 Visitor visitor_; |
3234 }; | 3213 }; |
3235 | 3214 |
3236 | 3215 |
3237 } } // namespace v8::internal | 3216 } } // namespace v8::internal |
3238 | 3217 |
3239 #endif // V8_AST_H_ | 3218 #endif // V8_AST_H_ |
OLD | NEW |