OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_AST_AST_H_ | 5 #ifndef V8_AST_AST_H_ |
6 #define V8_AST_AST_H_ | 6 #define V8_AST_AST_H_ |
7 | 7 |
8 #include "src/assembler.h" | 8 #include "src/assembler.h" |
9 #include "src/ast/ast-value-factory.h" | 9 #include "src/ast/ast-value-factory.h" |
10 #include "src/ast/modules.h" | 10 #include "src/ast/modules.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 V(UnaryOperation) \ | 84 V(UnaryOperation) \ |
85 V(CountOperation) \ | 85 V(CountOperation) \ |
86 V(BinaryOperation) \ | 86 V(BinaryOperation) \ |
87 V(CompareOperation) \ | 87 V(CompareOperation) \ |
88 V(Spread) \ | 88 V(Spread) \ |
89 V(ThisFunction) \ | 89 V(ThisFunction) \ |
90 V(SuperPropertyReference) \ | 90 V(SuperPropertyReference) \ |
91 V(SuperCallReference) \ | 91 V(SuperCallReference) \ |
92 V(CaseClause) \ | 92 V(CaseClause) \ |
93 V(EmptyParentheses) \ | 93 V(EmptyParentheses) \ |
94 V(DoExpression) | 94 V(DoExpression) \ |
| 95 V(RewritableAssignmentExpression) |
95 | 96 |
96 #define AST_NODE_LIST(V) \ | 97 #define AST_NODE_LIST(V) \ |
97 DECLARATION_NODE_LIST(V) \ | 98 DECLARATION_NODE_LIST(V) \ |
98 STATEMENT_NODE_LIST(V) \ | 99 STATEMENT_NODE_LIST(V) \ |
99 EXPRESSION_NODE_LIST(V) | 100 EXPRESSION_NODE_LIST(V) |
100 | 101 |
101 // Forward declarations | 102 // Forward declarations |
102 class AstNodeFactory; | 103 class AstNodeFactory; |
103 class AstVisitor; | 104 class AstVisitor; |
104 class Declaration; | 105 class Declaration; |
(...skipping 2222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2327 public: | 2328 public: |
2328 DECLARE_NODE_TYPE(Assignment) | 2329 DECLARE_NODE_TYPE(Assignment) |
2329 | 2330 |
2330 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } | 2331 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } |
2331 | 2332 |
2332 Token::Value binary_op() const; | 2333 Token::Value binary_op() const; |
2333 | 2334 |
2334 Token::Value op() const { return TokenField::decode(bit_field_); } | 2335 Token::Value op() const { return TokenField::decode(bit_field_); } |
2335 Expression* target() const { return target_; } | 2336 Expression* target() const { return target_; } |
2336 Expression* value() const { return value_; } | 2337 Expression* value() const { return value_; } |
| 2338 |
2337 BinaryOperation* binary_operation() const { return binary_operation_; } | 2339 BinaryOperation* binary_operation() const { return binary_operation_; } |
2338 | 2340 |
2339 // This check relies on the definition order of token in token.h. | 2341 // This check relies on the definition order of token in token.h. |
2340 bool is_compound() const { return op() > Token::ASSIGN; } | 2342 bool is_compound() const { return op() > Token::ASSIGN; } |
2341 | 2343 |
2342 static int num_ids() { return parent_num_ids() + 2; } | 2344 static int num_ids() { return parent_num_ids() + 2; } |
2343 BailoutId AssignmentId() const { return BailoutId(local_id(0)); } | 2345 BailoutId AssignmentId() const { return BailoutId(local_id(0)); } |
2344 | 2346 |
2345 // Type feedback information. | 2347 // Type feedback information. |
2346 TypeFeedbackId AssignmentFeedbackId() { return TypeFeedbackId(local_id(1)); } | 2348 TypeFeedbackId AssignmentFeedbackId() { return TypeFeedbackId(local_id(1)); } |
(...skipping 27 matching lines...) Expand all Loading... |
2374 | 2376 |
2375 protected: | 2377 protected: |
2376 Assignment(Zone* zone, Token::Value op, Expression* target, Expression* value, | 2378 Assignment(Zone* zone, Token::Value op, Expression* target, Expression* value, |
2377 int pos); | 2379 int pos); |
2378 static int parent_num_ids() { return Expression::num_ids(); } | 2380 static int parent_num_ids() { return Expression::num_ids(); } |
2379 | 2381 |
2380 private: | 2382 private: |
2381 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 2383 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
2382 | 2384 |
2383 class IsUninitializedField : public BitField16<bool, 0, 1> {}; | 2385 class IsUninitializedField : public BitField16<bool, 0, 1> {}; |
2384 class KeyTypeField : public BitField16<IcCheckType, 1, 1> {}; | 2386 class KeyTypeField |
2385 class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 3> {}; | 2387 : public BitField16<IcCheckType, IsUninitializedField::kNext, 1> {}; |
2386 class TokenField : public BitField16<Token::Value, 5, 8> {}; | 2388 class StoreModeField |
| 2389 : public BitField16<KeyedAccessStoreMode, KeyTypeField::kNext, 3> {}; |
| 2390 class TokenField : public BitField16<Token::Value, StoreModeField::kNext, 8> { |
| 2391 }; |
2387 | 2392 |
2388 // Starts with 16-bit field, which should get packed together with | 2393 // Starts with 16-bit field, which should get packed together with |
2389 // Expression's trailing 16-bit field. | 2394 // Expression's trailing 16-bit field. |
2390 uint16_t bit_field_; | 2395 uint16_t bit_field_; |
2391 Expression* target_; | 2396 Expression* target_; |
2392 Expression* value_; | 2397 Expression* value_; |
2393 BinaryOperation* binary_operation_; | 2398 BinaryOperation* binary_operation_; |
2394 SmallMapList receiver_types_; | 2399 SmallMapList receiver_types_; |
2395 FeedbackVectorSlot slot_; | 2400 FeedbackVectorSlot slot_; |
2396 }; | 2401 }; |
2397 | 2402 |
2398 | 2403 |
| 2404 class RewritableAssignmentExpression : public Expression { |
| 2405 public: |
| 2406 DECLARE_NODE_TYPE(RewritableAssignmentExpression) |
| 2407 |
| 2408 Expression* expression() { return expr_; } |
| 2409 bool is_rewritten() const { return is_rewritten_; } |
| 2410 |
| 2411 void Rewrite(Expression* new_expression) { |
| 2412 DCHECK(!is_rewritten()); |
| 2413 DCHECK_NOT_NULL(new_expression); |
| 2414 expr_ = new_expression; |
| 2415 is_rewritten_ = true; |
| 2416 } |
| 2417 |
| 2418 static int num_ids() { return parent_num_ids(); } |
| 2419 |
| 2420 protected: |
| 2421 RewritableAssignmentExpression(Zone* zone, Expression* expression) |
| 2422 : Expression(zone, expression->position()), |
| 2423 is_rewritten_(false), |
| 2424 expr_(expression) {} |
| 2425 |
| 2426 private: |
| 2427 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
| 2428 |
| 2429 bool is_rewritten_; |
| 2430 Expression* expr_; |
| 2431 }; |
| 2432 |
| 2433 |
2399 class Yield final : public Expression { | 2434 class Yield final : public Expression { |
2400 public: | 2435 public: |
2401 DECLARE_NODE_TYPE(Yield) | 2436 DECLARE_NODE_TYPE(Yield) |
2402 | 2437 |
2403 enum Kind { | 2438 enum Kind { |
2404 kInitial, // The initial yield that returns the unboxed generator object. | 2439 kInitial, // The initial yield that returns the unboxed generator object. |
2405 kSuspend, // A normal yield: { value: EXPRESSION, done: false } | 2440 kSuspend, // A normal yield: { value: EXPRESSION, done: false } |
2406 kDelegating, // A yield*. | 2441 kDelegating, // A yield*. |
2407 kFinal // A return: { value: EXPRESSION, done: true } | 2442 kFinal // A return: { value: EXPRESSION, done: true } |
2408 }; | 2443 }; |
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3189 virtual void VisitStatements(ZoneList<Statement*>* statements); | 3224 virtual void VisitStatements(ZoneList<Statement*>* statements); |
3190 virtual void VisitExpressions(ZoneList<Expression*>* expressions); | 3225 virtual void VisitExpressions(ZoneList<Expression*>* expressions); |
3191 | 3226 |
3192 // Individual AST nodes. | 3227 // Individual AST nodes. |
3193 #define DEF_VISIT(type) \ | 3228 #define DEF_VISIT(type) \ |
3194 virtual void Visit##type(type* node) = 0; | 3229 virtual void Visit##type(type* node) = 0; |
3195 AST_NODE_LIST(DEF_VISIT) | 3230 AST_NODE_LIST(DEF_VISIT) |
3196 #undef DEF_VISIT | 3231 #undef DEF_VISIT |
3197 }; | 3232 }; |
3198 | 3233 |
3199 | |
3200 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \ | 3234 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \ |
3201 public: \ | 3235 public: \ |
3202 void Visit(AstNode* node) final { \ | 3236 void Visit(AstNode* node) final { \ |
3203 if (!CheckStackOverflow()) node->Accept(this); \ | 3237 if (!CheckStackOverflow()) node->Accept(this); \ |
3204 } \ | 3238 } \ |
3205 \ | 3239 \ |
3206 void SetStackOverflow() { stack_overflow_ = true; } \ | 3240 void SetStackOverflow() { stack_overflow_ = true; } \ |
3207 void ClearStackOverflow() { stack_overflow_ = false; } \ | 3241 void ClearStackOverflow() { stack_overflow_ = false; } \ |
3208 bool HasStackOverflow() const { return stack_overflow_; } \ | 3242 bool HasStackOverflow() const { return stack_overflow_; } \ |
3209 \ | 3243 \ |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3542 } | 3576 } |
3543 | 3577 |
3544 Conditional* NewConditional(Expression* condition, | 3578 Conditional* NewConditional(Expression* condition, |
3545 Expression* then_expression, | 3579 Expression* then_expression, |
3546 Expression* else_expression, | 3580 Expression* else_expression, |
3547 int position) { | 3581 int position) { |
3548 return new (local_zone_) Conditional( | 3582 return new (local_zone_) Conditional( |
3549 local_zone_, condition, then_expression, else_expression, position); | 3583 local_zone_, condition, then_expression, else_expression, position); |
3550 } | 3584 } |
3551 | 3585 |
| 3586 RewritableAssignmentExpression* NewRewritableAssignmentExpression( |
| 3587 Expression* expression) { |
| 3588 DCHECK_NOT_NULL(expression); |
| 3589 DCHECK(expression->IsAssignment()); |
| 3590 return new (local_zone_) |
| 3591 RewritableAssignmentExpression(local_zone_, expression); |
| 3592 } |
| 3593 |
3552 Assignment* NewAssignment(Token::Value op, | 3594 Assignment* NewAssignment(Token::Value op, |
3553 Expression* target, | 3595 Expression* target, |
3554 Expression* value, | 3596 Expression* value, |
3555 int pos) { | 3597 int pos) { |
3556 DCHECK(Token::IsAssignmentOp(op)); | 3598 DCHECK(Token::IsAssignmentOp(op)); |
3557 Assignment* assign = | 3599 Assignment* assign = |
3558 new (local_zone_) Assignment(local_zone_, op, target, value, pos); | 3600 new (local_zone_) Assignment(local_zone_, op, target, value, pos); |
3559 if (assign->is_compound()) { | 3601 if (assign->is_compound()) { |
3560 DCHECK(Token::IsAssignmentOp(op)); | 3602 DCHECK(Token::IsAssignmentOp(op)); |
3561 assign->binary_operation_ = | 3603 assign->binary_operation_ = |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3667 // the parser-level zone. | 3709 // the parser-level zone. |
3668 Zone* parser_zone_; | 3710 Zone* parser_zone_; |
3669 AstValueFactory* ast_value_factory_; | 3711 AstValueFactory* ast_value_factory_; |
3670 }; | 3712 }; |
3671 | 3713 |
3672 | 3714 |
3673 } // namespace internal | 3715 } // namespace internal |
3674 } // namespace v8 | 3716 } // namespace v8 |
3675 | 3717 |
3676 #endif // V8_AST_AST_H_ | 3718 #endif // V8_AST_AST_H_ |
OLD | NEW |