Chromium Code Reviews| Index: src/ast/ast.h |
| diff --git a/src/ast/ast.h b/src/ast/ast.h |
| index e1adae9f249ce7af7da9142e7761dd141229acc7..61a07cca51a4d68bb08e8926a663abe9cbc0fd33 100644 |
| --- a/src/ast/ast.h |
| +++ b/src/ast/ast.h |
| @@ -91,7 +91,8 @@ namespace internal { |
| V(SuperCallReference) \ |
| V(CaseClause) \ |
| V(EmptyParentheses) \ |
| - V(DoExpression) |
| + V(DoExpression) \ |
| + V(RewritableExpression) |
| #define AST_NODE_LIST(V) \ |
| DECLARATION_NODE_LIST(V) \ |
| @@ -402,6 +403,50 @@ class Expression : public AstNode { |
| }; |
| +class RewritableExpression : public Expression { |
| + public: |
| + DECLARE_NODE_TYPE(RewritableExpression); |
| + |
| + enum RewriteHint { |
| + // Reasons for a rewrite to occur. |
| + kDestructuringAssignment = 1, |
| + }; |
| + |
| + Expression* expression() { return expr_; } |
| + int hints() const { return RewriteHintsField::decode(bit_field_); } |
| + |
| + bool IsRewritableAs(RewriteHint hint) const { |
| + return (RewriteHintsField::decode(bit_field_) & hint) != 0 && |
| + !IsRewrittenAs(hint); |
| + } |
| + |
| + bool IsRewrittenAs(RewriteHint reason) const { |
| + return (RewriteReasonField::decode(bit_field_) & reason) != 0; |
| + } |
| + |
| + void RewriteAs(Expression* new_expression, RewriteHint reason) { |
| + DCHECK(!IsRewrittenAs(reason)); |
| + DCHECK((RewriteHintsField::decode(bit_field_) & reason) != 0); |
| + expr_ = new_expression; |
| + bit_field_ = RewriteReasonField::update(bit_field_, reason); |
| + } |
| + |
| + |
| + protected: |
| + RewritableExpression(Zone* zone, Expression* expression, int hints) |
| + : Expression(zone, expression->position()), |
| + expr_(expression), |
| + bit_field_(RewriteHintsField::encode(hints)) {} |
| + |
| + private: |
| + Expression* expr_; |
|
adamk
2015/12/01 22:42:56
Nit: just call this "expression_"
|
| + uint32_t bit_field_; |
|
adamk
2015/12/01 22:42:56
If you move this before expr_ and make it a uint8_
|
| + class RewriteHintsField : public BitField<uint16_t, 0, 16> {}; |
| + class RewriteReasonField |
| + : public BitField<uint16_t, RewriteHintsField::kNext, 16> {}; |
| +}; |
| + |
| + |
| class BreakableStatement : public Statement { |
| public: |
| enum BreakableType { |
| @@ -2334,6 +2379,7 @@ class Assignment final : public Expression { |
| Token::Value op() const { return TokenField::decode(bit_field_); } |
| Expression* target() const { return target_; } |
| Expression* value() const { return value_; } |
| + |
| BinaryOperation* binary_operation() const { return binary_operation_; } |
| // This check relies on the definition order of token in token.h. |
| @@ -2381,9 +2427,12 @@ class Assignment final : public Expression { |
| int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
| class IsUninitializedField : public BitField16<bool, 0, 1> {}; |
| - class KeyTypeField : public BitField16<IcCheckType, 1, 1> {}; |
| - class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 3> {}; |
| - class TokenField : public BitField16<Token::Value, 5, 8> {}; |
| + class KeyTypeField |
| + : public BitField16<IcCheckType, IsUninitializedField::kNext, 1> {}; |
| + class StoreModeField |
| + : public BitField16<KeyedAccessStoreMode, KeyTypeField::kNext, 3> {}; |
| + class TokenField : public BitField16<Token::Value, StoreModeField::kNext, 8> { |
| + }; |
| // Starts with 16-bit field, which should get packed together with |
| // Expression's trailing 16-bit field. |
| @@ -3196,7 +3245,6 @@ class AstVisitor BASE_EMBEDDED { |
| #undef DEF_VISIT |
| }; |
| - |
| #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \ |
| public: \ |
| void Visit(AstNode* node) final { \ |
| @@ -3549,6 +3597,14 @@ class AstNodeFactory final BASE_EMBEDDED { |
| local_zone_, condition, then_expression, else_expression, position); |
| } |
| + RewritableExpression* NewRewritableExpression(Expression* expression, |
| + int hints) { |
| + DCHECK_NOT_NULL(expression); |
| + DCHECK(hints); |
| + return new (local_zone_) |
| + RewritableExpression(local_zone_, expression, hints); |
| + } |
| + |
| Assignment* NewAssignment(Token::Value op, |
| Expression* target, |
| Expression* value, |