Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: src/ast/ast.h

Issue 1309813007: [es6] implement destructuring assignment (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove facilities for rewriting the expression multiple ways Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/ast/ast-expression-visitor.cc » ('j') | src/flag-definitions.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 {
adamk 2015/12/02 01:51:36 This got lost in the back-and-forth, but now that
407 public:
408 DECLARE_NODE_TYPE(RewritableExpression)
409
410 Expression* expression() { return expr_; }
411 bool is_rewritten() const { return is_rewritten_; }
412
413 void Rewrite(Expression* new_expression) {
414 DCHECK(!is_rewritten());
415 DCHECK_NOT_NULL(new_expression);
416 expr_ = new_expression;
417 is_rewritten_ = true;
418 }
419
420 static int num_ids() { return parent_num_ids(); }
421
422 protected:
423 RewritableExpression(Zone* zone, Expression* expression)
424 : Expression(zone, expression->position()),
425 is_rewritten_(false),
426 expr_(expression) {}
427
428 private:
429 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
430
431 bool is_rewritten_;
432 Expression* expr_;
433 };
434
435
405 class BreakableStatement : public Statement { 436 class BreakableStatement : public Statement {
406 public: 437 public:
407 enum BreakableType { 438 enum BreakableType {
408 TARGET_FOR_ANONYMOUS, 439 TARGET_FOR_ANONYMOUS,
409 TARGET_FOR_NAMED_ONLY 440 TARGET_FOR_NAMED_ONLY
410 }; 441 };
411 442
412 // The labels associated with this statement. May be NULL; 443 // The labels associated with this statement. May be NULL;
413 // if it is != NULL, guaranteed to contain at least one entry. 444 // if it is != NULL, guaranteed to contain at least one entry.
414 ZoneList<const AstRawString*>* labels() const { return labels_; } 445 ZoneList<const AstRawString*>* labels() const { return labels_; }
(...skipping 1911 matching lines...) Expand 10 before | Expand all | Expand 10 after
2326 public: 2357 public:
2327 DECLARE_NODE_TYPE(Assignment) 2358 DECLARE_NODE_TYPE(Assignment)
2328 2359
2329 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } 2360 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; }
2330 2361
2331 Token::Value binary_op() const; 2362 Token::Value binary_op() const;
2332 2363
2333 Token::Value op() const { return TokenField::decode(bit_field_); } 2364 Token::Value op() const { return TokenField::decode(bit_field_); }
2334 Expression* target() const { return target_; } 2365 Expression* target() const { return target_; }
2335 Expression* value() const { return value_; } 2366 Expression* value() const { return value_; }
2367
2336 BinaryOperation* binary_operation() const { return binary_operation_; } 2368 BinaryOperation* binary_operation() const { return binary_operation_; }
2337 2369
2338 // This check relies on the definition order of token in token.h. 2370 // This check relies on the definition order of token in token.h.
2339 bool is_compound() const { return op() > Token::ASSIGN; } 2371 bool is_compound() const { return op() > Token::ASSIGN; }
2340 2372
2341 static int num_ids() { return parent_num_ids() + 2; } 2373 static int num_ids() { return parent_num_ids() + 2; }
2342 BailoutId AssignmentId() const { return BailoutId(local_id(0)); } 2374 BailoutId AssignmentId() const { return BailoutId(local_id(0)); }
2343 2375
2344 // Type feedback information. 2376 // Type feedback information.
2345 TypeFeedbackId AssignmentFeedbackId() { return TypeFeedbackId(local_id(1)); } 2377 TypeFeedbackId AssignmentFeedbackId() { return TypeFeedbackId(local_id(1)); }
(...skipping 27 matching lines...) Expand all
2373 2405
2374 protected: 2406 protected:
2375 Assignment(Zone* zone, Token::Value op, Expression* target, Expression* value, 2407 Assignment(Zone* zone, Token::Value op, Expression* target, Expression* value,
2376 int pos); 2408 int pos);
2377 static int parent_num_ids() { return Expression::num_ids(); } 2409 static int parent_num_ids() { return Expression::num_ids(); }
2378 2410
2379 private: 2411 private:
2380 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2412 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2381 2413
2382 class IsUninitializedField : public BitField16<bool, 0, 1> {}; 2414 class IsUninitializedField : public BitField16<bool, 0, 1> {};
2383 class KeyTypeField : public BitField16<IcCheckType, 1, 1> {}; 2415 class KeyTypeField
2384 class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 3> {}; 2416 : public BitField16<IcCheckType, IsUninitializedField::kNext, 1> {};
2385 class TokenField : public BitField16<Token::Value, 5, 8> {}; 2417 class StoreModeField
2418 : public BitField16<KeyedAccessStoreMode, KeyTypeField::kNext, 3> {};
2419 class TokenField : public BitField16<Token::Value, StoreModeField::kNext, 8> {
2420 };
2386 2421
2387 // Starts with 16-bit field, which should get packed together with 2422 // Starts with 16-bit field, which should get packed together with
2388 // Expression's trailing 16-bit field. 2423 // Expression's trailing 16-bit field.
2389 uint16_t bit_field_; 2424 uint16_t bit_field_;
2390 Expression* target_; 2425 Expression* target_;
2391 Expression* value_; 2426 Expression* value_;
2392 BinaryOperation* binary_operation_; 2427 BinaryOperation* binary_operation_;
2393 SmallMapList receiver_types_; 2428 SmallMapList receiver_types_;
2394 FeedbackVectorSlot slot_; 2429 FeedbackVectorSlot slot_;
2395 }; 2430 };
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after
3188 virtual void VisitStatements(ZoneList<Statement*>* statements); 3223 virtual void VisitStatements(ZoneList<Statement*>* statements);
3189 virtual void VisitExpressions(ZoneList<Expression*>* expressions); 3224 virtual void VisitExpressions(ZoneList<Expression*>* expressions);
3190 3225
3191 // Individual AST nodes. 3226 // Individual AST nodes.
3192 #define DEF_VISIT(type) \ 3227 #define DEF_VISIT(type) \
3193 virtual void Visit##type(type* node) = 0; 3228 virtual void Visit##type(type* node) = 0;
3194 AST_NODE_LIST(DEF_VISIT) 3229 AST_NODE_LIST(DEF_VISIT)
3195 #undef DEF_VISIT 3230 #undef DEF_VISIT
3196 }; 3231 };
3197 3232
3198
3199 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \ 3233 #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \
3200 public: \ 3234 public: \
3201 void Visit(AstNode* node) final { \ 3235 void Visit(AstNode* node) final { \
3202 if (!CheckStackOverflow()) node->Accept(this); \ 3236 if (!CheckStackOverflow()) node->Accept(this); \
3203 } \ 3237 } \
3204 \ 3238 \
3205 void SetStackOverflow() { stack_overflow_ = true; } \ 3239 void SetStackOverflow() { stack_overflow_ = true; } \
3206 void ClearStackOverflow() { stack_overflow_ = false; } \ 3240 void ClearStackOverflow() { stack_overflow_ = false; } \
3207 bool HasStackOverflow() const { return stack_overflow_; } \ 3241 bool HasStackOverflow() const { return stack_overflow_; } \
3208 \ 3242 \
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
3541 } 3575 }
3542 3576
3543 Conditional* NewConditional(Expression* condition, 3577 Conditional* NewConditional(Expression* condition,
3544 Expression* then_expression, 3578 Expression* then_expression,
3545 Expression* else_expression, 3579 Expression* else_expression,
3546 int position) { 3580 int position) {
3547 return new (local_zone_) Conditional( 3581 return new (local_zone_) Conditional(
3548 local_zone_, condition, then_expression, else_expression, position); 3582 local_zone_, condition, then_expression, else_expression, position);
3549 } 3583 }
3550 3584
3585 RewritableExpression* NewRewritableExpression(Expression* expression) {
adamk 2015/12/02 01:51:36 And this should take an Assignment*
caitp (gmail) 2015/12/02 02:25:26 complicates things a bit too much --- causes issue
3586 DCHECK_NOT_NULL(expression);
3587 return new (local_zone_) RewritableExpression(local_zone_, expression);
3588 }
3589
3551 Assignment* NewAssignment(Token::Value op, 3590 Assignment* NewAssignment(Token::Value op,
3552 Expression* target, 3591 Expression* target,
3553 Expression* value, 3592 Expression* value,
3554 int pos) { 3593 int pos) {
3555 DCHECK(Token::IsAssignmentOp(op)); 3594 DCHECK(Token::IsAssignmentOp(op));
3556 Assignment* assign = 3595 Assignment* assign =
3557 new (local_zone_) Assignment(local_zone_, op, target, value, pos); 3596 new (local_zone_) Assignment(local_zone_, op, target, value, pos);
3558 if (assign->is_compound()) { 3597 if (assign->is_compound()) {
3559 DCHECK(Token::IsAssignmentOp(op)); 3598 DCHECK(Token::IsAssignmentOp(op));
3560 assign->binary_operation_ = 3599 assign->binary_operation_ =
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
3666 // the parser-level zone. 3705 // the parser-level zone.
3667 Zone* parser_zone_; 3706 Zone* parser_zone_;
3668 AstValueFactory* ast_value_factory_; 3707 AstValueFactory* ast_value_factory_;
3669 }; 3708 };
3670 3709
3671 3710
3672 } // namespace internal 3711 } // namespace internal
3673 } // namespace v8 3712 } // namespace v8
3674 3713
3675 #endif // V8_AST_AST_H_ 3714 #endif // V8_AST_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast/ast-expression-visitor.cc » ('j') | src/flag-definitions.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698