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_); } | |
|
adamk
2015/12/02 01:13:13
This returns an int, but will only ever be kDestru
| |
| 417 | |
| 418 bool IsRewritableAs(RewriteHint hint) const { | |
|
adamk
2015/12/02 01:13:13
There is only a single argument that could be pass
| |
| 419 return (RewriteHintsField::decode(bit_field_) & hint) != 0 && | |
| 420 !IsRewrittenAs(hint); | |
| 421 } | |
| 422 | |
| 423 bool IsRewrittenAs(RewriteHint reason) const { | |
|
adamk
2015/12/02 01:13:13
Ditto
| |
| 424 return (RewriteReasonField::decode(bit_field_) & reason) != 0; | |
| 425 } | |
| 426 | |
| 427 void RewriteAs(Expression* new_expression, RewriteHint reason) { | |
|
adamk
2015/12/02 01:13:13
And again, the second argument here is can only ev
| |
| 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 static int num_ids() { return parent_num_ids(); } | |
| 435 | |
| 436 protected: | |
| 437 RewritableExpression(Zone* zone, Expression* expression, int hints) | |
| 438 : Expression(zone, expression->position()), | |
| 439 bit_field_(RewriteHintsField::encode(hints)), | |
| 440 expr_(expression) {} | |
| 441 | |
| 442 private: | |
| 443 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | |
| 444 | |
| 445 uint8_t bit_field_; | |
| 446 Expression* expr_; | |
| 447 class RewriteHintsField : public BitField<uint16_t, 0, 4> {}; | |
|
adamk
2015/12/02 01:13:13
This bit field wouldn't be necessary, you could ha
| |
| 448 class RewriteReasonField | |
| 449 : public BitField<uint16_t, RewriteHintsField::kNext, 4> {}; | |
| 450 }; | |
| 451 | |
| 452 | |
| 405 class BreakableStatement : public Statement { | 453 class BreakableStatement : public Statement { |
| 406 public: | 454 public: |
| 407 enum BreakableType { | 455 enum BreakableType { |
| 408 TARGET_FOR_ANONYMOUS, | 456 TARGET_FOR_ANONYMOUS, |
| 409 TARGET_FOR_NAMED_ONLY | 457 TARGET_FOR_NAMED_ONLY |
| 410 }; | 458 }; |
| 411 | 459 |
| 412 // The labels associated with this statement. May be NULL; | 460 // The labels associated with this statement. May be NULL; |
| 413 // if it is != NULL, guaranteed to contain at least one entry. | 461 // if it is != NULL, guaranteed to contain at least one entry. |
| 414 ZoneList<const AstRawString*>* labels() const { return labels_; } | 462 ZoneList<const AstRawString*>* labels() const { return labels_; } |
| (...skipping 1911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2326 public: | 2374 public: |
| 2327 DECLARE_NODE_TYPE(Assignment) | 2375 DECLARE_NODE_TYPE(Assignment) |
| 2328 | 2376 |
| 2329 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } | 2377 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } |
| 2330 | 2378 |
| 2331 Token::Value binary_op() const; | 2379 Token::Value binary_op() const; |
| 2332 | 2380 |
| 2333 Token::Value op() const { return TokenField::decode(bit_field_); } | 2381 Token::Value op() const { return TokenField::decode(bit_field_); } |
| 2334 Expression* target() const { return target_; } | 2382 Expression* target() const { return target_; } |
| 2335 Expression* value() const { return value_; } | 2383 Expression* value() const { return value_; } |
| 2384 | |
| 2336 BinaryOperation* binary_operation() const { return binary_operation_; } | 2385 BinaryOperation* binary_operation() const { return binary_operation_; } |
| 2337 | 2386 |
| 2338 // This check relies on the definition order of token in token.h. | 2387 // This check relies on the definition order of token in token.h. |
| 2339 bool is_compound() const { return op() > Token::ASSIGN; } | 2388 bool is_compound() const { return op() > Token::ASSIGN; } |
| 2340 | 2389 |
| 2341 static int num_ids() { return parent_num_ids() + 2; } | 2390 static int num_ids() { return parent_num_ids() + 2; } |
| 2342 BailoutId AssignmentId() const { return BailoutId(local_id(0)); } | 2391 BailoutId AssignmentId() const { return BailoutId(local_id(0)); } |
| 2343 | 2392 |
| 2344 // Type feedback information. | 2393 // Type feedback information. |
| 2345 TypeFeedbackId AssignmentFeedbackId() { return TypeFeedbackId(local_id(1)); } | 2394 TypeFeedbackId AssignmentFeedbackId() { return TypeFeedbackId(local_id(1)); } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 2373 | 2422 |
| 2374 protected: | 2423 protected: |
| 2375 Assignment(Zone* zone, Token::Value op, Expression* target, Expression* value, | 2424 Assignment(Zone* zone, Token::Value op, Expression* target, Expression* value, |
| 2376 int pos); | 2425 int pos); |
| 2377 static int parent_num_ids() { return Expression::num_ids(); } | 2426 static int parent_num_ids() { return Expression::num_ids(); } |
| 2378 | 2427 |
| 2379 private: | 2428 private: |
| 2380 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 2429 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
| 2381 | 2430 |
| 2382 class IsUninitializedField : public BitField16<bool, 0, 1> {}; | 2431 class IsUninitializedField : public BitField16<bool, 0, 1> {}; |
| 2383 class KeyTypeField : public BitField16<IcCheckType, 1, 1> {}; | 2432 class KeyTypeField |
| 2384 class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 3> {}; | 2433 : public BitField16<IcCheckType, IsUninitializedField::kNext, 1> {}; |
| 2385 class TokenField : public BitField16<Token::Value, 5, 8> {}; | 2434 class StoreModeField |
| 2435 : public BitField16<KeyedAccessStoreMode, KeyTypeField::kNext, 3> {}; | |
| 2436 class TokenField : public BitField16<Token::Value, StoreModeField::kNext, 8> { | |
| 2437 }; | |
| 2386 | 2438 |
| 2387 // Starts with 16-bit field, which should get packed together with | 2439 // Starts with 16-bit field, which should get packed together with |
| 2388 // Expression's trailing 16-bit field. | 2440 // Expression's trailing 16-bit field. |
| 2389 uint16_t bit_field_; | 2441 uint16_t bit_field_; |
| 2390 Expression* target_; | 2442 Expression* target_; |
| 2391 Expression* value_; | 2443 Expression* value_; |
| 2392 BinaryOperation* binary_operation_; | 2444 BinaryOperation* binary_operation_; |
| 2393 SmallMapList receiver_types_; | 2445 SmallMapList receiver_types_; |
| 2394 FeedbackVectorSlot slot_; | 2446 FeedbackVectorSlot slot_; |
| 2395 }; | 2447 }; |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3188 virtual void VisitStatements(ZoneList<Statement*>* statements); | 3240 virtual void VisitStatements(ZoneList<Statement*>* statements); |
| 3189 virtual void VisitExpressions(ZoneList<Expression*>* expressions); | 3241 virtual void VisitExpressions(ZoneList<Expression*>* expressions); |
| 3190 | 3242 |
| 3191 // Individual AST nodes. | 3243 // Individual AST nodes. |
| 3192 #define DEF_VISIT(type) \ | 3244 #define DEF_VISIT(type) \ |
| 3193 virtual void Visit##type(type* node) = 0; | 3245 virtual void Visit##type(type* node) = 0; |
| 3194 AST_NODE_LIST(DEF_VISIT) | 3246 AST_NODE_LIST(DEF_VISIT) |
| 3195 #undef DEF_VISIT | 3247 #undef DEF_VISIT |
| 3196 }; | 3248 }; |
| 3197 | 3249 |
| 3198 | |
| 3199 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \ | 3250 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \ |
| 3200 public: \ | 3251 public: \ |
| 3201 void Visit(AstNode* node) final { \ | 3252 void Visit(AstNode* node) final { \ |
| 3202 if (!CheckStackOverflow()) node->Accept(this); \ | 3253 if (!CheckStackOverflow()) node->Accept(this); \ |
| 3203 } \ | 3254 } \ |
| 3204 \ | 3255 \ |
| 3205 void SetStackOverflow() { stack_overflow_ = true; } \ | 3256 void SetStackOverflow() { stack_overflow_ = true; } \ |
| 3206 void ClearStackOverflow() { stack_overflow_ = false; } \ | 3257 void ClearStackOverflow() { stack_overflow_ = false; } \ |
| 3207 bool HasStackOverflow() const { return stack_overflow_; } \ | 3258 bool HasStackOverflow() const { return stack_overflow_; } \ |
| 3208 \ | 3259 \ |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3541 } | 3592 } |
| 3542 | 3593 |
| 3543 Conditional* NewConditional(Expression* condition, | 3594 Conditional* NewConditional(Expression* condition, |
| 3544 Expression* then_expression, | 3595 Expression* then_expression, |
| 3545 Expression* else_expression, | 3596 Expression* else_expression, |
| 3546 int position) { | 3597 int position) { |
| 3547 return new (local_zone_) Conditional( | 3598 return new (local_zone_) Conditional( |
| 3548 local_zone_, condition, then_expression, else_expression, position); | 3599 local_zone_, condition, then_expression, else_expression, position); |
| 3549 } | 3600 } |
| 3550 | 3601 |
| 3602 RewritableExpression* NewRewritableExpression(Expression* expression, | |
| 3603 int hints) { | |
| 3604 DCHECK_NOT_NULL(expression); | |
| 3605 DCHECK(hints); | |
| 3606 return new (local_zone_) | |
| 3607 RewritableExpression(local_zone_, expression, hints); | |
| 3608 } | |
| 3609 | |
| 3551 Assignment* NewAssignment(Token::Value op, | 3610 Assignment* NewAssignment(Token::Value op, |
| 3552 Expression* target, | 3611 Expression* target, |
| 3553 Expression* value, | 3612 Expression* value, |
| 3554 int pos) { | 3613 int pos) { |
| 3555 DCHECK(Token::IsAssignmentOp(op)); | 3614 DCHECK(Token::IsAssignmentOp(op)); |
| 3556 Assignment* assign = | 3615 Assignment* assign = |
| 3557 new (local_zone_) Assignment(local_zone_, op, target, value, pos); | 3616 new (local_zone_) Assignment(local_zone_, op, target, value, pos); |
| 3558 if (assign->is_compound()) { | 3617 if (assign->is_compound()) { |
| 3559 DCHECK(Token::IsAssignmentOp(op)); | 3618 DCHECK(Token::IsAssignmentOp(op)); |
| 3560 assign->binary_operation_ = | 3619 assign->binary_operation_ = |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3666 // the parser-level zone. | 3725 // the parser-level zone. |
| 3667 Zone* parser_zone_; | 3726 Zone* parser_zone_; |
| 3668 AstValueFactory* ast_value_factory_; | 3727 AstValueFactory* ast_value_factory_; |
| 3669 }; | 3728 }; |
| 3670 | 3729 |
| 3671 | 3730 |
| 3672 } // namespace internal | 3731 } // namespace internal |
| 3673 } // namespace v8 | 3732 } // namespace v8 |
| 3674 | 3733 |
| 3675 #endif // V8_AST_AST_H_ | 3734 #endif // V8_AST_AST_H_ |
| OLD | NEW |