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_H_ | 5 #ifndef V8_AST_H_ |
6 #define V8_AST_H_ | 6 #define V8_AST_H_ |
7 | 7 |
8 #include "src/assembler.h" | 8 #include "src/assembler.h" |
9 #include "src/ast-value-factory.h" | 9 #include "src/ast-value-factory.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 V(FunctionLiteral) \ | 68 V(FunctionLiteral) \ |
69 V(ClassLiteral) \ | 69 V(ClassLiteral) \ |
70 V(NativeFunctionLiteral) \ | 70 V(NativeFunctionLiteral) \ |
71 V(Conditional) \ | 71 V(Conditional) \ |
72 V(VariableProxy) \ | 72 V(VariableProxy) \ |
73 V(Literal) \ | 73 V(Literal) \ |
74 V(RegExpLiteral) \ | 74 V(RegExpLiteral) \ |
75 V(ObjectLiteral) \ | 75 V(ObjectLiteral) \ |
76 V(ArrayLiteral) \ | 76 V(ArrayLiteral) \ |
77 V(Assignment) \ | 77 V(Assignment) \ |
| 78 V(AssignmentPattern) \ |
78 V(Yield) \ | 79 V(Yield) \ |
79 V(Throw) \ | 80 V(Throw) \ |
80 V(Property) \ | 81 V(Property) \ |
81 V(Call) \ | 82 V(Call) \ |
82 V(CallNew) \ | 83 V(CallNew) \ |
83 V(CallRuntime) \ | 84 V(CallRuntime) \ |
84 V(UnaryOperation) \ | 85 V(UnaryOperation) \ |
85 V(CountOperation) \ | 86 V(CountOperation) \ |
86 V(BinaryOperation) \ | 87 V(BinaryOperation) \ |
87 V(CompareOperation) \ | 88 V(CompareOperation) \ |
(...skipping 2301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2389 // Expression's trailing 16-bit field. | 2390 // Expression's trailing 16-bit field. |
2390 uint16_t bit_field_; | 2391 uint16_t bit_field_; |
2391 Expression* target_; | 2392 Expression* target_; |
2392 Expression* value_; | 2393 Expression* value_; |
2393 BinaryOperation* binary_operation_; | 2394 BinaryOperation* binary_operation_; |
2394 SmallMapList receiver_types_; | 2395 SmallMapList receiver_types_; |
2395 FeedbackVectorSlot slot_; | 2396 FeedbackVectorSlot slot_; |
2396 }; | 2397 }; |
2397 | 2398 |
2398 | 2399 |
| 2400 class AssignmentPattern final : public Expression { |
| 2401 public: |
| 2402 DECLARE_NODE_TYPE(AssignmentPattern) |
| 2403 |
| 2404 // AssignmentPattern should always be the Target of an Assignment. |
| 2405 // If encountered during compilation, and the assignment expression |
| 2406 // is not null (the node has been rewritten), the rewritten expression |
| 2407 // should be used in place of the normal assignment behaviour. |
| 2408 // Otherwise, the LHS is treated as the original pattern, which should |
| 2409 // result in an exception. |
| 2410 bool is_rewritten() const { return expression_ != pattern_; } |
| 2411 Expression* pattern() const { return pattern_; } |
| 2412 Expression* expression() const { return expression_; } |
| 2413 |
| 2414 static int num_ids() { return parent_num_ids(); } |
| 2415 |
| 2416 void set_expression(Expression* expr) { |
| 2417 // Only to be called by Parser::PatternRewriter |
| 2418 DCHECK_NE(expr, pattern_); |
| 2419 DCHECK_NOT_NULL(expr); |
| 2420 expression_ = expr; |
| 2421 } |
| 2422 |
| 2423 protected: |
| 2424 AssignmentPattern(Zone* zone, Expression* pattern, int pos) |
| 2425 : Expression(zone, pos), pattern_(pattern), expression_(pattern) {} |
| 2426 static int parent_num_ids() { return Expression::num_ids(); } |
| 2427 |
| 2428 private: |
| 2429 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
| 2430 |
| 2431 Expression* pattern_; |
| 2432 Expression* expression_; |
| 2433 }; |
| 2434 |
| 2435 |
2399 class Yield final : public Expression { | 2436 class Yield final : public Expression { |
2400 public: | 2437 public: |
2401 DECLARE_NODE_TYPE(Yield) | 2438 DECLARE_NODE_TYPE(Yield) |
2402 | 2439 |
2403 enum Kind { | 2440 enum Kind { |
2404 kInitial, // The initial yield that returns the unboxed generator object. | 2441 kInitial, // The initial yield that returns the unboxed generator object. |
2405 kSuspend, // A normal yield: { value: EXPRESSION, done: false } | 2442 kSuspend, // A normal yield: { value: EXPRESSION, done: false } |
2406 kDelegating, // A yield*. | 2443 kDelegating, // A yield*. |
2407 kFinal // A return: { value: EXPRESSION, done: true } | 2444 kFinal // A return: { value: EXPRESSION, done: true } |
2408 }; | 2445 }; |
(...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3550 Assignment* assign = | 3587 Assignment* assign = |
3551 new (local_zone_) Assignment(local_zone_, op, target, value, pos); | 3588 new (local_zone_) Assignment(local_zone_, op, target, value, pos); |
3552 if (assign->is_compound()) { | 3589 if (assign->is_compound()) { |
3553 DCHECK(Token::IsAssignmentOp(op)); | 3590 DCHECK(Token::IsAssignmentOp(op)); |
3554 assign->binary_operation_ = | 3591 assign->binary_operation_ = |
3555 NewBinaryOperation(assign->binary_op(), target, value, pos + 1); | 3592 NewBinaryOperation(assign->binary_op(), target, value, pos + 1); |
3556 } | 3593 } |
3557 return assign; | 3594 return assign; |
3558 } | 3595 } |
3559 | 3596 |
| 3597 AssignmentPattern* NewAssignmentPattern(Expression* pattern, int pos) { |
| 3598 DCHECK(pattern->IsObjectLiteral() || pattern->IsArrayLiteral()); |
| 3599 return new (local_zone_) AssignmentPattern(local_zone_, pattern, pos); |
| 3600 } |
| 3601 |
3560 Yield* NewYield(Expression *generator_object, | 3602 Yield* NewYield(Expression *generator_object, |
3561 Expression* expression, | 3603 Expression* expression, |
3562 Yield::Kind yield_kind, | 3604 Yield::Kind yield_kind, |
3563 int pos) { | 3605 int pos) { |
3564 if (!expression) expression = NewUndefinedLiteral(pos); | 3606 if (!expression) expression = NewUndefinedLiteral(pos); |
3565 return new (local_zone_) | 3607 return new (local_zone_) |
3566 Yield(local_zone_, generator_object, expression, yield_kind, pos); | 3608 Yield(local_zone_, generator_object, expression, yield_kind, pos); |
3567 } | 3609 } |
3568 | 3610 |
3569 Throw* NewThrow(Expression* exception, int pos) { | 3611 Throw* NewThrow(Expression* exception, int pos) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3660 // the parser-level zone. | 3702 // the parser-level zone. |
3661 Zone* parser_zone_; | 3703 Zone* parser_zone_; |
3662 AstValueFactory* ast_value_factory_; | 3704 AstValueFactory* ast_value_factory_; |
3663 }; | 3705 }; |
3664 | 3706 |
3665 | 3707 |
3666 } // namespace internal | 3708 } // namespace internal |
3667 } // namespace v8 | 3709 } // namespace v8 |
3668 | 3710 |
3669 #endif // V8_AST_H_ | 3711 #endif // V8_AST_H_ |
OLD | NEW |