Chromium Code Reviews| 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(RewritableExpression) | |
| 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 | 396 |
| 396 int base_id_; | 397 int base_id_; |
| 397 Bounds bounds_; | 398 Bounds bounds_; |
| 398 class ToBooleanTypesField : public BitField16<uint16_t, 0, 9> {}; | 399 class ToBooleanTypesField : public BitField16<uint16_t, 0, 9> {}; |
| 399 uint16_t bit_field_; | 400 uint16_t bit_field_; |
| 400 // Ends with 16-bit field; deriving classes in turn begin with | 401 // Ends with 16-bit field; deriving classes in turn begin with |
| 401 // 16-bit fields for optimum packing efficiency. | 402 // 16-bit fields for optimum packing efficiency. |
| 402 }; | 403 }; |
| 403 | 404 |
| 404 | 405 |
| 406 class RewritableExpression : public Expression { | |
| 407 public: | |
| 408 DECLARE_NODE_TYPE(RewritableExpression); | |
| 409 | |
| 410 enum RewriteHint { | |
| 411 // Reasons for a rewrite to occur. | |
| 412 kDestructuringAssignment = 1, | |
| 413 }; | |
| 414 | |
| 415 Expression* expression() { return expr_; } | |
| 416 int hints() const { return RewriteHintsField::decode(bit_field_); } | |
| 417 | |
| 418 bool IsRewritableAs(RewriteHint hint) const { | |
| 419 return (RewriteHintsField::decode(bit_field_) & hint) != 0 && | |
| 420 !IsRewrittenAs(hint); | |
| 421 } | |
| 422 | |
| 423 bool IsRewrittenAs(RewriteHint reason) const { | |
| 424 return (RewriteReasonField::decode(bit_field_) & reason) != 0; | |
| 425 } | |
| 426 | |
| 427 void RewriteAs(Expression* new_expression, RewriteHint reason) { | |
| 428 DCHECK(!IsRewrittenAs(reason)); | |
| 429 DCHECK((RewriteHintsField::decode(bit_field_) & reason) != 0); | |
| 430 expr_ = new_expression; | |
| 431 bit_field_ = RewriteReasonField::update(bit_field_, reason); | |
| 432 } | |
| 433 | |
| 434 | |
| 435 protected: | |
| 436 RewritableExpression(Zone* zone, Expression* expression, int hints) | |
| 437 : Expression(zone, expression->position()), | |
| 438 expr_(expression), | |
| 439 bit_field_(RewriteHintsField::encode(hints)) {} | |
| 440 | |
| 441 private: | |
| 442 Expression* expr_; | |
|
adamk
2015/12/01 22:42:56
Nit: just call this "expression_"
| |
| 443 uint32_t bit_field_; | |
|
adamk
2015/12/01 22:42:56
If you move this before expr_ and make it a uint8_
| |
| 444 class RewriteHintsField : public BitField<uint16_t, 0, 16> {}; | |
| 445 class RewriteReasonField | |
| 446 : public BitField<uint16_t, RewriteHintsField::kNext, 16> {}; | |
| 447 }; | |
| 448 | |
| 449 | |
| 405 class BreakableStatement : public Statement { | 450 class BreakableStatement : public Statement { |
| 406 public: | 451 public: |
| 407 enum BreakableType { | 452 enum BreakableType { |
| 408 TARGET_FOR_ANONYMOUS, | 453 TARGET_FOR_ANONYMOUS, |
| 409 TARGET_FOR_NAMED_ONLY | 454 TARGET_FOR_NAMED_ONLY |
| 410 }; | 455 }; |
| 411 | 456 |
| 412 // The labels associated with this statement. May be NULL; | 457 // The labels associated with this statement. May be NULL; |
| 413 // if it is != NULL, guaranteed to contain at least one entry. | 458 // if it is != NULL, guaranteed to contain at least one entry. |
| 414 ZoneList<const AstRawString*>* labels() const { return labels_; } | 459 ZoneList<const AstRawString*>* labels() const { return labels_; } |
| (...skipping 1912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2327 public: | 2372 public: |
| 2328 DECLARE_NODE_TYPE(Assignment) | 2373 DECLARE_NODE_TYPE(Assignment) |
| 2329 | 2374 |
| 2330 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } | 2375 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } |
| 2331 | 2376 |
| 2332 Token::Value binary_op() const; | 2377 Token::Value binary_op() const; |
| 2333 | 2378 |
| 2334 Token::Value op() const { return TokenField::decode(bit_field_); } | 2379 Token::Value op() const { return TokenField::decode(bit_field_); } |
| 2335 Expression* target() const { return target_; } | 2380 Expression* target() const { return target_; } |
| 2336 Expression* value() const { return value_; } | 2381 Expression* value() const { return value_; } |
| 2382 | |
| 2337 BinaryOperation* binary_operation() const { return binary_operation_; } | 2383 BinaryOperation* binary_operation() const { return binary_operation_; } |
| 2338 | 2384 |
| 2339 // This check relies on the definition order of token in token.h. | 2385 // This check relies on the definition order of token in token.h. |
| 2340 bool is_compound() const { return op() > Token::ASSIGN; } | 2386 bool is_compound() const { return op() > Token::ASSIGN; } |
| 2341 | 2387 |
| 2342 static int num_ids() { return parent_num_ids() + 2; } | 2388 static int num_ids() { return parent_num_ids() + 2; } |
| 2343 BailoutId AssignmentId() const { return BailoutId(local_id(0)); } | 2389 BailoutId AssignmentId() const { return BailoutId(local_id(0)); } |
| 2344 | 2390 |
| 2345 // Type feedback information. | 2391 // Type feedback information. |
| 2346 TypeFeedbackId AssignmentFeedbackId() { return TypeFeedbackId(local_id(1)); } | 2392 TypeFeedbackId AssignmentFeedbackId() { return TypeFeedbackId(local_id(1)); } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 2374 | 2420 |
| 2375 protected: | 2421 protected: |
| 2376 Assignment(Zone* zone, Token::Value op, Expression* target, Expression* value, | 2422 Assignment(Zone* zone, Token::Value op, Expression* target, Expression* value, |
| 2377 int pos); | 2423 int pos); |
| 2378 static int parent_num_ids() { return Expression::num_ids(); } | 2424 static int parent_num_ids() { return Expression::num_ids(); } |
| 2379 | 2425 |
| 2380 private: | 2426 private: |
| 2381 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 2427 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
| 2382 | 2428 |
| 2383 class IsUninitializedField : public BitField16<bool, 0, 1> {}; | 2429 class IsUninitializedField : public BitField16<bool, 0, 1> {}; |
| 2384 class KeyTypeField : public BitField16<IcCheckType, 1, 1> {}; | 2430 class KeyTypeField |
| 2385 class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 3> {}; | 2431 : public BitField16<IcCheckType, IsUninitializedField::kNext, 1> {}; |
| 2386 class TokenField : public BitField16<Token::Value, 5, 8> {}; | 2432 class StoreModeField |
| 2433 : public BitField16<KeyedAccessStoreMode, KeyTypeField::kNext, 3> {}; | |
| 2434 class TokenField : public BitField16<Token::Value, StoreModeField::kNext, 8> { | |
| 2435 }; | |
| 2387 | 2436 |
| 2388 // Starts with 16-bit field, which should get packed together with | 2437 // Starts with 16-bit field, which should get packed together with |
| 2389 // Expression's trailing 16-bit field. | 2438 // Expression's trailing 16-bit field. |
| 2390 uint16_t bit_field_; | 2439 uint16_t bit_field_; |
| 2391 Expression* target_; | 2440 Expression* target_; |
| 2392 Expression* value_; | 2441 Expression* value_; |
| 2393 BinaryOperation* binary_operation_; | 2442 BinaryOperation* binary_operation_; |
| 2394 SmallMapList receiver_types_; | 2443 SmallMapList receiver_types_; |
| 2395 FeedbackVectorSlot slot_; | 2444 FeedbackVectorSlot slot_; |
| 2396 }; | 2445 }; |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3189 virtual void VisitStatements(ZoneList<Statement*>* statements); | 3238 virtual void VisitStatements(ZoneList<Statement*>* statements); |
| 3190 virtual void VisitExpressions(ZoneList<Expression*>* expressions); | 3239 virtual void VisitExpressions(ZoneList<Expression*>* expressions); |
| 3191 | 3240 |
| 3192 // Individual AST nodes. | 3241 // Individual AST nodes. |
| 3193 #define DEF_VISIT(type) \ | 3242 #define DEF_VISIT(type) \ |
| 3194 virtual void Visit##type(type* node) = 0; | 3243 virtual void Visit##type(type* node) = 0; |
| 3195 AST_NODE_LIST(DEF_VISIT) | 3244 AST_NODE_LIST(DEF_VISIT) |
| 3196 #undef DEF_VISIT | 3245 #undef DEF_VISIT |
| 3197 }; | 3246 }; |
| 3198 | 3247 |
| 3199 | |
| 3200 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \ | 3248 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \ |
| 3201 public: \ | 3249 public: \ |
| 3202 void Visit(AstNode* node) final { \ | 3250 void Visit(AstNode* node) final { \ |
| 3203 if (!CheckStackOverflow()) node->Accept(this); \ | 3251 if (!CheckStackOverflow()) node->Accept(this); \ |
| 3204 } \ | 3252 } \ |
| 3205 \ | 3253 \ |
| 3206 void SetStackOverflow() { stack_overflow_ = true; } \ | 3254 void SetStackOverflow() { stack_overflow_ = true; } \ |
| 3207 void ClearStackOverflow() { stack_overflow_ = false; } \ | 3255 void ClearStackOverflow() { stack_overflow_ = false; } \ |
| 3208 bool HasStackOverflow() const { return stack_overflow_; } \ | 3256 bool HasStackOverflow() const { return stack_overflow_; } \ |
| 3209 \ | 3257 \ |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3542 } | 3590 } |
| 3543 | 3591 |
| 3544 Conditional* NewConditional(Expression* condition, | 3592 Conditional* NewConditional(Expression* condition, |
| 3545 Expression* then_expression, | 3593 Expression* then_expression, |
| 3546 Expression* else_expression, | 3594 Expression* else_expression, |
| 3547 int position) { | 3595 int position) { |
| 3548 return new (local_zone_) Conditional( | 3596 return new (local_zone_) Conditional( |
| 3549 local_zone_, condition, then_expression, else_expression, position); | 3597 local_zone_, condition, then_expression, else_expression, position); |
| 3550 } | 3598 } |
| 3551 | 3599 |
| 3600 RewritableExpression* NewRewritableExpression(Expression* expression, | |
| 3601 int hints) { | |
| 3602 DCHECK_NOT_NULL(expression); | |
| 3603 DCHECK(hints); | |
| 3604 return new (local_zone_) | |
| 3605 RewritableExpression(local_zone_, expression, hints); | |
| 3606 } | |
| 3607 | |
| 3552 Assignment* NewAssignment(Token::Value op, | 3608 Assignment* NewAssignment(Token::Value op, |
| 3553 Expression* target, | 3609 Expression* target, |
| 3554 Expression* value, | 3610 Expression* value, |
| 3555 int pos) { | 3611 int pos) { |
| 3556 DCHECK(Token::IsAssignmentOp(op)); | 3612 DCHECK(Token::IsAssignmentOp(op)); |
| 3557 Assignment* assign = | 3613 Assignment* assign = |
| 3558 new (local_zone_) Assignment(local_zone_, op, target, value, pos); | 3614 new (local_zone_) Assignment(local_zone_, op, target, value, pos); |
| 3559 if (assign->is_compound()) { | 3615 if (assign->is_compound()) { |
| 3560 DCHECK(Token::IsAssignmentOp(op)); | 3616 DCHECK(Token::IsAssignmentOp(op)); |
| 3561 assign->binary_operation_ = | 3617 assign->binary_operation_ = |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3667 // the parser-level zone. | 3723 // the parser-level zone. |
| 3668 Zone* parser_zone_; | 3724 Zone* parser_zone_; |
| 3669 AstValueFactory* ast_value_factory_; | 3725 AstValueFactory* ast_value_factory_; |
| 3670 }; | 3726 }; |
| 3671 | 3727 |
| 3672 | 3728 |
| 3673 } // namespace internal | 3729 } // namespace internal |
| 3674 } // namespace v8 | 3730 } // namespace v8 |
| 3675 | 3731 |
| 3676 #endif // V8_AST_AST_H_ | 3732 #endif // V8_AST_AST_H_ |
| OLD | NEW |