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

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

Issue 2142333002: Refactor class declaration logic to the parser and runtime Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: cleanup per Adam 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
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 V(WhileStatement) \ 57 V(WhileStatement) \
58 V(ForStatement) \ 58 V(ForStatement) \
59 V(ForInStatement) \ 59 V(ForInStatement) \
60 V(ForOfStatement) \ 60 V(ForOfStatement) \
61 V(TryCatchStatement) \ 61 V(TryCatchStatement) \
62 V(TryFinallyStatement) \ 62 V(TryFinallyStatement) \
63 V(DebuggerStatement) 63 V(DebuggerStatement)
64 64
65 #define EXPRESSION_NODE_LIST(V) \ 65 #define EXPRESSION_NODE_LIST(V) \
66 V(FunctionLiteral) \ 66 V(FunctionLiteral) \
67 V(ClassLiteral) \
68 V(NativeFunctionLiteral) \ 67 V(NativeFunctionLiteral) \
69 V(Conditional) \ 68 V(Conditional) \
70 V(VariableProxy) \ 69 V(VariableProxy) \
71 V(Literal) \ 70 V(Literal) \
72 V(RegExpLiteral) \ 71 V(RegExpLiteral) \
73 V(ObjectLiteral) \ 72 V(ObjectLiteral) \
74 V(ArrayLiteral) \ 73 V(ArrayLiteral) \
75 V(Assignment) \ 74 V(Assignment) \
76 V(Yield) \ 75 V(Yield) \
77 V(Throw) \ 76 V(Throw) \
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 473
475 474
476 class DoExpression final : public Expression { 475 class DoExpression final : public Expression {
477 public: 476 public:
478 DECLARE_NODE_TYPE(DoExpression) 477 DECLARE_NODE_TYPE(DoExpression)
479 478
480 Block* block() { return block_; } 479 Block* block() { return block_; }
481 void set_block(Block* b) { block_ = b; } 480 void set_block(Block* b) { block_ = b; }
482 VariableProxy* result() { return result_; } 481 VariableProxy* result() { return result_; }
483 void set_result(VariableProxy* v) { result_ = v; } 482 void set_result(VariableProxy* v) { result_ = v; }
483 FunctionLiteral* represented_function() { return represented_function_; }
484 void set_represented_function(FunctionLiteral* f) {
485 represented_function_ = f;
486 }
487
488 bool IsAnonymousFunctionDefinition() const final;
484 489
485 protected: 490 protected:
486 DoExpression(Zone* zone, Block* block, VariableProxy* result, int pos) 491 DoExpression(Zone* zone, Block* block, VariableProxy* result, int pos)
487 : Expression(zone, pos), block_(block), result_(result) { 492 : Expression(zone, pos),
493 block_(block),
494 result_(result),
495 represented_function_(nullptr) {
488 DCHECK_NOT_NULL(block_); 496 DCHECK_NOT_NULL(block_);
489 DCHECK_NOT_NULL(result_); 497 DCHECK_NOT_NULL(result_);
490 } 498 }
491 static int parent_num_ids() { return Expression::num_ids(); } 499 static int parent_num_ids() { return Expression::num_ids(); }
492 500
493 private: 501 private:
494 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 502 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
495 503
496 Block* block_; 504 Block* block_;
497 VariableProxy* result_; 505 VariableProxy* result_;
506 FunctionLiteral* represented_function_;
498 }; 507 };
499 508
500 509
501 class Declaration : public AstNode { 510 class Declaration : public AstNode {
502 public: 511 public:
503 VariableProxy* proxy() const { return proxy_; } 512 VariableProxy* proxy() const { return proxy_; }
504 VariableMode mode() const { return mode_; } 513 VariableMode mode() const { return mode_; }
505 Scope* scope() const { return scope_; } 514 Scope* scope() const { return scope_; }
506 virtual InitializationFlag initialization() const = 0; 515 virtual InitializationFlag initialization() const = 0;
507 516
(...skipping 2241 matching lines...) Expand 10 before | Expand all | Expand 10 after
2749 BailoutReason dont_optimize_reason_; 2758 BailoutReason dont_optimize_reason_;
2750 2759
2751 int materialized_literal_count_; 2760 int materialized_literal_count_;
2752 int expected_property_count_; 2761 int expected_property_count_;
2753 int parameter_count_; 2762 int parameter_count_;
2754 int function_token_position_; 2763 int function_token_position_;
2755 int yield_count_; 2764 int yield_count_;
2756 }; 2765 };
2757 2766
2758 2767
2759 class ClassLiteral final : public Expression {
2760 public:
2761 typedef ObjectLiteralProperty Property;
2762
2763 DECLARE_NODE_TYPE(ClassLiteral)
2764
2765 Scope* scope() const { return scope_; }
2766 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; }
2767 Expression* extends() const { return extends_; }
2768 void set_extends(Expression* e) { extends_ = e; }
2769 FunctionLiteral* constructor() const { return constructor_; }
2770 void set_constructor(FunctionLiteral* f) { constructor_ = f; }
2771 ZoneList<Property*>* properties() const { return properties_; }
2772 int start_position() const { return position(); }
2773 int end_position() const { return end_position_; }
2774
2775 BailoutId EntryId() const { return BailoutId(local_id(0)); }
2776 BailoutId DeclsId() const { return BailoutId(local_id(1)); }
2777 BailoutId ExitId() { return BailoutId(local_id(2)); }
2778 BailoutId CreateLiteralId() const { return BailoutId(local_id(3)); }
2779 BailoutId PrototypeId() { return BailoutId(local_id(4)); }
2780
2781 // Return an AST id for a property that is used in simulate instructions.
2782 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 5)); }
2783
2784 // Unlike other AST nodes, this number of bailout IDs allocated for an
2785 // ClassLiteral can vary, so num_ids() is not a static method.
2786 int num_ids() const { return parent_num_ids() + 5 + properties()->length(); }
2787
2788 // Object literals need one feedback slot for each non-trivial value, as well
2789 // as some slots for home objects.
2790 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec,
2791 FeedbackVectorSlotCache* cache);
2792
2793 bool NeedsProxySlot() const {
2794 return class_variable_proxy() != nullptr &&
2795 class_variable_proxy()->var()->IsUnallocated();
2796 }
2797
2798 FeedbackVectorSlot PrototypeSlot() const { return prototype_slot_; }
2799 FeedbackVectorSlot ProxySlot() const { return proxy_slot_; }
2800
2801 bool IsAnonymousFunctionDefinition() const final {
2802 return constructor()->raw_name()->length() == 0;
2803 }
2804
2805 protected:
2806 ClassLiteral(Zone* zone, Scope* scope, VariableProxy* class_variable_proxy,
2807 Expression* extends, FunctionLiteral* constructor,
2808 ZoneList<Property*>* properties, int start_position,
2809 int end_position)
2810 : Expression(zone, start_position),
2811 scope_(scope),
2812 class_variable_proxy_(class_variable_proxy),
2813 extends_(extends),
2814 constructor_(constructor),
2815 properties_(properties),
2816 end_position_(end_position) {}
2817
2818 static int parent_num_ids() { return Expression::num_ids(); }
2819
2820 private:
2821 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2822
2823 Scope* scope_;
2824 VariableProxy* class_variable_proxy_;
2825 Expression* extends_;
2826 FunctionLiteral* constructor_;
2827 ZoneList<Property*>* properties_;
2828 int end_position_;
2829 FeedbackVectorSlot prototype_slot_;
2830 FeedbackVectorSlot proxy_slot_;
2831 };
2832
2833
2834 class NativeFunctionLiteral final : public Expression { 2768 class NativeFunctionLiteral final : public Expression {
2835 public: 2769 public:
2836 DECLARE_NODE_TYPE(NativeFunctionLiteral) 2770 DECLARE_NODE_TYPE(NativeFunctionLiteral)
2837 2771
2838 Handle<String> name() const { return name_->string(); } 2772 Handle<String> name() const { return name_->string(); }
2839 v8::Extension* extension() const { return extension_; } 2773 v8::Extension* extension() const { return extension_; }
2840 2774
2841 protected: 2775 protected:
2842 NativeFunctionLiteral(Zone* zone, const AstRawString* name, 2776 NativeFunctionLiteral(Zone* zone, const AstRawString* name,
2843 v8::Extension* extension, int pos) 2777 v8::Extension* extension, int pos)
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
3446 int expected_property_count) { 3380 int expected_property_count) {
3447 return new (parser_zone_) FunctionLiteral( 3381 return new (parser_zone_) FunctionLiteral(
3448 parser_zone_, ast_value_factory_->empty_string(), ast_value_factory_, 3382 parser_zone_, ast_value_factory_->empty_string(), ast_value_factory_,
3449 scope, body, materialized_literal_count, expected_property_count, 0, 3383 scope, body, materialized_literal_count, expected_property_count, 0,
3450 FunctionLiteral::kAnonymousExpression, 3384 FunctionLiteral::kAnonymousExpression,
3451 FunctionLiteral::kNoDuplicateParameters, 3385 FunctionLiteral::kNoDuplicateParameters,
3452 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0, 3386 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0,
3453 false); 3387 false);
3454 } 3388 }
3455 3389
3456 ClassLiteral* NewClassLiteral(Scope* scope, VariableProxy* proxy,
3457 Expression* extends,
3458 FunctionLiteral* constructor,
3459 ZoneList<ObjectLiteral::Property*>* properties,
3460 int start_position, int end_position) {
3461 return new (parser_zone_)
3462 ClassLiteral(parser_zone_, scope, proxy, extends, constructor,
3463 properties, start_position, end_position);
3464 }
3465
3466 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, 3390 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name,
3467 v8::Extension* extension, 3391 v8::Extension* extension,
3468 int pos) { 3392 int pos) {
3469 return new (parser_zone_) 3393 return new (parser_zone_)
3470 NativeFunctionLiteral(parser_zone_, name, extension, pos); 3394 NativeFunctionLiteral(parser_zone_, name, extension, pos);
3471 } 3395 }
3472 3396
3473 DoExpression* NewDoExpression(Block* block, Variable* result_var, int pos) { 3397 DoExpression* NewDoExpression(Block* block, Variable* result_var, int pos) {
3474 VariableProxy* result = NewVariableProxy(result_var, pos); 3398 VariableProxy* result = NewVariableProxy(result_var, pos);
3475 return new (parser_zone_) DoExpression(parser_zone_, block, result, pos); 3399 return new (parser_zone_) DoExpression(parser_zone_, block, result, pos);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
3567 : NULL; \ 3491 : NULL; \
3568 } 3492 }
3569 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 3493 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
3570 #undef DECLARE_NODE_FUNCTIONS 3494 #undef DECLARE_NODE_FUNCTIONS
3571 3495
3572 3496
3573 } // namespace internal 3497 } // namespace internal
3574 } // namespace v8 3498 } // namespace v8
3575 3499
3576 #endif // V8_AST_AST_H_ 3500 #endif // V8_AST_AST_H_
OLDNEW
« no previous file with comments | « src/asmjs/typing-asm.cc ('k') | src/ast/ast.cc » ('j') | src/parsing/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698