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

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

Issue 2176653003: Wrap ClassLiterals in DoExpressions instead of giving them BlockScopes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 4 years, 5 months 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.cc » ('j') | src/full-codegen/full-codegen.cc » ('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/ast/ast-value-factory.h" 8 #include "src/ast/ast-value-factory.h"
9 #include "src/ast/modules.h" 9 #include "src/ast/modules.h"
10 #include "src/ast/variables.h" 10 #include "src/ast/variables.h"
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 468
469 469
470 class DoExpression final : public Expression { 470 class DoExpression final : public Expression {
471 public: 471 public:
472 DECLARE_NODE_TYPE(DoExpression) 472 DECLARE_NODE_TYPE(DoExpression)
473 473
474 Block* block() { return block_; } 474 Block* block() { return block_; }
475 void set_block(Block* b) { block_ = b; } 475 void set_block(Block* b) { block_ = b; }
476 VariableProxy* result() { return result_; } 476 VariableProxy* result() { return result_; }
477 void set_result(VariableProxy* v) { result_ = v; } 477 void set_result(VariableProxy* v) { result_ = v; }
478 FunctionLiteral* represented_function() { return represented_function_; }
479 void set_represented_function(FunctionLiteral* f) {
480 represented_function_ = f;
481 }
482 bool IsAnonymousFunctionDefinition() const;
478 483
479 protected: 484 protected:
480 DoExpression(Zone* zone, Block* block, VariableProxy* result, int pos) 485 DoExpression(Zone* zone, Block* block, VariableProxy* result, int pos)
481 : Expression(zone, pos, kDoExpression), block_(block), result_(result) { 486 : Expression(zone, pos, kDoExpression),
487 block_(block),
488 result_(result),
489 represented_function_(nullptr) {
482 DCHECK_NOT_NULL(block_); 490 DCHECK_NOT_NULL(block_);
483 DCHECK_NOT_NULL(result_); 491 DCHECK_NOT_NULL(result_);
484 } 492 }
485 static int parent_num_ids() { return Expression::num_ids(); } 493 static int parent_num_ids() { return Expression::num_ids(); }
486 494
487 private: 495 private:
488 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 496 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
489 497
490 Block* block_; 498 Block* block_;
491 VariableProxy* result_; 499 VariableProxy* result_;
500 FunctionLiteral* represented_function_;
492 }; 501 };
493 502
494 503
495 class Declaration : public AstNode { 504 class Declaration : public AstNode {
496 public: 505 public:
497 VariableProxy* proxy() const { return proxy_; } 506 VariableProxy* proxy() const { return proxy_; }
498 VariableMode mode() const { return mode_; } 507 VariableMode mode() const { return mode_; }
499 Scope* scope() const { return scope_; } 508 Scope* scope() const { return scope_; }
500 InitializationFlag initialization() const; 509 InitializationFlag initialization() const;
501 510
(...skipping 2207 matching lines...) Expand 10 before | Expand all | Expand 10 after
2709 AstProperties ast_properties_; 2718 AstProperties ast_properties_;
2710 }; 2719 };
2711 2720
2712 2721
2713 class ClassLiteral final : public Expression { 2722 class ClassLiteral final : public Expression {
2714 public: 2723 public:
2715 typedef ObjectLiteralProperty Property; 2724 typedef ObjectLiteralProperty Property;
2716 2725
2717 DECLARE_NODE_TYPE(ClassLiteral) 2726 DECLARE_NODE_TYPE(ClassLiteral)
2718 2727
2719 Scope* scope() const { return scope_; }
2720 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; } 2728 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; }
2721 Expression* extends() const { return extends_; } 2729 Expression* extends() const { return extends_; }
2722 void set_extends(Expression* e) { extends_ = e; } 2730 void set_extends(Expression* e) { extends_ = e; }
2723 FunctionLiteral* constructor() const { return constructor_; } 2731 FunctionLiteral* constructor() const { return constructor_; }
2724 void set_constructor(FunctionLiteral* f) { constructor_ = f; } 2732 void set_constructor(FunctionLiteral* f) { constructor_ = f; }
2725 ZoneList<Property*>* properties() const { return properties_; } 2733 ZoneList<Property*>* properties() const { return properties_; }
2726 int start_position() const { return position(); } 2734 int start_position() const { return position(); }
2727 int end_position() const { return end_position_; } 2735 int end_position() const { return end_position_; }
2728 2736
2729 BailoutId EntryId() const { return BailoutId(local_id(0)); } 2737 BailoutId EntryId() const { return BailoutId(local_id(0)); }
2730 BailoutId DeclsId() const { return BailoutId(local_id(1)); } 2738 BailoutId DeclsId() const { return BailoutId(local_id(1)); }
2731 BailoutId ExitId() { return BailoutId(local_id(2)); } 2739 BailoutId ExitId() { return BailoutId(local_id(2)); }
Michael Starzinger 2016/07/25 14:56:47 The first three bailout ids should no longer be re
bakkot 2016/07/25 18:52:04 Done. Also edited GetIdForProperty, which I am *pr
2732 BailoutId CreateLiteralId() const { return BailoutId(local_id(3)); } 2740 BailoutId CreateLiteralId() const { return BailoutId(local_id(3)); }
2733 BailoutId PrototypeId() { return BailoutId(local_id(4)); } 2741 BailoutId PrototypeId() { return BailoutId(local_id(4)); }
2734 2742
2735 // Return an AST id for a property that is used in simulate instructions. 2743 // Return an AST id for a property that is used in simulate instructions.
2736 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 5)); } 2744 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 5)); }
2737 2745
2738 // Unlike other AST nodes, this number of bailout IDs allocated for an 2746 // Unlike other AST nodes, this number of bailout IDs allocated for an
2739 // ClassLiteral can vary, so num_ids() is not a static method. 2747 // ClassLiteral can vary, so num_ids() is not a static method.
2740 int num_ids() const { return parent_num_ids() + 5 + properties()->length(); } 2748 int num_ids() const { return parent_num_ids() + 5 + properties()->length(); }
2741 2749
2742 // Object literals need one feedback slot for each non-trivial value, as well 2750 // Object literals need one feedback slot for each non-trivial value, as well
2743 // as some slots for home objects. 2751 // as some slots for home objects.
2744 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, 2752 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec,
2745 FeedbackVectorSlotCache* cache); 2753 FeedbackVectorSlotCache* cache);
2746 2754
2747 bool NeedsProxySlot() const { 2755 bool NeedsProxySlot() const {
2748 return class_variable_proxy() != nullptr && 2756 return class_variable_proxy() != nullptr &&
2749 class_variable_proxy()->var()->IsUnallocated(); 2757 class_variable_proxy()->var()->IsUnallocated();
2750 } 2758 }
2751 2759
2752 FeedbackVectorSlot PrototypeSlot() const { return prototype_slot_; } 2760 FeedbackVectorSlot PrototypeSlot() const { return prototype_slot_; }
2753 FeedbackVectorSlot ProxySlot() const { return proxy_slot_; } 2761 FeedbackVectorSlot ProxySlot() const { return proxy_slot_; }
2754 2762
2755 bool IsAnonymousFunctionDefinition() const {
2756 return constructor()->raw_name()->length() == 0;
2757 }
2758
2759 protected: 2763 protected:
2760 ClassLiteral(Zone* zone, Scope* scope, VariableProxy* class_variable_proxy, 2764 ClassLiteral(Zone* zone, VariableProxy* class_variable_proxy,
2761 Expression* extends, FunctionLiteral* constructor, 2765 Expression* extends, FunctionLiteral* constructor,
2762 ZoneList<Property*>* properties, int start_position, 2766 ZoneList<Property*>* properties, int start_position,
2763 int end_position) 2767 int end_position)
2764 : Expression(zone, start_position, kClassLiteral), 2768 : Expression(zone, start_position, kClassLiteral),
2765 end_position_(end_position), 2769 end_position_(end_position),
2766 scope_(scope),
2767 class_variable_proxy_(class_variable_proxy), 2770 class_variable_proxy_(class_variable_proxy),
2768 extends_(extends), 2771 extends_(extends),
2769 constructor_(constructor), 2772 constructor_(constructor),
2770 properties_(properties) {} 2773 properties_(properties) {}
2771 2774
2772 static int parent_num_ids() { return Expression::num_ids(); } 2775 static int parent_num_ids() { return Expression::num_ids(); }
2773 2776
2774 private: 2777 private:
2775 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2778 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2776 2779
2777 int end_position_; 2780 int end_position_;
2778 FeedbackVectorSlot prototype_slot_; 2781 FeedbackVectorSlot prototype_slot_;
2779 FeedbackVectorSlot proxy_slot_; 2782 FeedbackVectorSlot proxy_slot_;
2780 Scope* scope_;
2781 VariableProxy* class_variable_proxy_; 2783 VariableProxy* class_variable_proxy_;
2782 Expression* extends_; 2784 Expression* extends_;
2783 FunctionLiteral* constructor_; 2785 FunctionLiteral* constructor_;
2784 ZoneList<Property*>* properties_; 2786 ZoneList<Property*>* properties_;
2785 }; 2787 };
2786 2788
2787 2789
2788 class NativeFunctionLiteral final : public Expression { 2790 class NativeFunctionLiteral final : public Expression {
2789 public: 2791 public:
2790 DECLARE_NODE_TYPE(NativeFunctionLiteral) 2792 DECLARE_NODE_TYPE(NativeFunctionLiteral)
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
3451 int expected_property_count) { 3453 int expected_property_count) {
3452 return new (local_zone_) FunctionLiteral( 3454 return new (local_zone_) FunctionLiteral(
3453 local_zone_, ast_value_factory_->empty_string(), ast_value_factory_, 3455 local_zone_, ast_value_factory_->empty_string(), ast_value_factory_,
3454 scope, body, materialized_literal_count, expected_property_count, 0, 3456 scope, body, materialized_literal_count, expected_property_count, 0,
3455 FunctionLiteral::kAnonymousExpression, 3457 FunctionLiteral::kAnonymousExpression,
3456 FunctionLiteral::kNoDuplicateParameters, 3458 FunctionLiteral::kNoDuplicateParameters,
3457 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0, 3459 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0,
3458 false); 3460 false);
3459 } 3461 }
3460 3462
3461 ClassLiteral* NewClassLiteral(Scope* scope, VariableProxy* proxy, 3463 ClassLiteral* NewClassLiteral(VariableProxy* proxy, Expression* extends,
3462 Expression* extends,
3463 FunctionLiteral* constructor, 3464 FunctionLiteral* constructor,
3464 ZoneList<ObjectLiteral::Property*>* properties, 3465 ZoneList<ObjectLiteral::Property*>* properties,
3465 int start_position, int end_position) { 3466 int start_position, int end_position) {
3466 return new (local_zone_) 3467 return new (local_zone_)
3467 ClassLiteral(local_zone_, scope, proxy, extends, constructor, 3468 ClassLiteral(local_zone_, proxy, extends, constructor, properties,
3468 properties, start_position, end_position); 3469 start_position, end_position);
3469 } 3470 }
3470 3471
3471 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, 3472 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name,
3472 v8::Extension* extension, 3473 v8::Extension* extension,
3473 int pos) { 3474 int pos) {
3474 return new (local_zone_) 3475 return new (local_zone_)
3475 NativeFunctionLiteral(local_zone_, name, extension, pos); 3476 NativeFunctionLiteral(local_zone_, name, extension, pos);
3476 } 3477 }
3477 3478
3478 DoExpression* NewDoExpression(Block* block, Variable* result_var, int pos) { 3479 DoExpression* NewDoExpression(Block* block, Variable* result_var, int pos) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
3572 : NULL; \ 3573 : NULL; \
3573 } 3574 }
3574 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 3575 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
3575 #undef DECLARE_NODE_FUNCTIONS 3576 #undef DECLARE_NODE_FUNCTIONS
3576 3577
3577 3578
3578 } // namespace internal 3579 } // namespace internal
3579 } // namespace v8 3580 } // namespace v8
3580 3581
3581 #endif // V8_AST_AST_H_ 3582 #endif // V8_AST_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast/ast.cc » ('j') | src/full-codegen/full-codegen.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698