| 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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 | 317 |
| 318 // Helpers for ToBoolean conversion. | 318 // Helpers for ToBoolean conversion. |
| 319 virtual bool ToBooleanIsTrue() const { return false; } | 319 virtual bool ToBooleanIsTrue() const { return false; } |
| 320 virtual bool ToBooleanIsFalse() const { return false; } | 320 virtual bool ToBooleanIsFalse() const { return false; } |
| 321 | 321 |
| 322 // Symbols that cannot be parsed as array indices are considered property | 322 // Symbols that cannot be parsed as array indices are considered property |
| 323 // names. We do not treat symbols that can be array indexes as property | 323 // names. We do not treat symbols that can be array indexes as property |
| 324 // names because [] for string objects is handled only by keyed ICs. | 324 // names because [] for string objects is handled only by keyed ICs. |
| 325 virtual bool IsPropertyName() const { return false; } | 325 virtual bool IsPropertyName() const { return false; } |
| 326 | 326 |
| 327 // True iff the expression is a class or function expression without |
| 328 // a syntactic name. |
| 329 virtual bool IsAnonymousFunctionDefinition() const { return false; } |
| 330 |
| 327 // True iff the expression is a literal represented as a smi. | 331 // True iff the expression is a literal represented as a smi. |
| 328 bool IsSmiLiteral() const; | 332 bool IsSmiLiteral() const; |
| 329 | 333 |
| 330 // True iff the expression is a string literal. | 334 // True iff the expression is a string literal. |
| 331 bool IsStringLiteral() const; | 335 bool IsStringLiteral() const; |
| 332 | 336 |
| 333 // True iff the expression is the null literal. | 337 // True iff the expression is the null literal. |
| 334 bool IsNullLiteral() const; | 338 bool IsNullLiteral() const; |
| 335 | 339 |
| 336 // True if we can prove that the expression is the undefined literal. | 340 // True if we can prove that the expression is the undefined literal. |
| (...skipping 2414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2751 } | 2755 } |
| 2752 const FeedbackVectorSpec* feedback_vector_spec() const { | 2756 const FeedbackVectorSpec* feedback_vector_spec() const { |
| 2753 return ast_properties_.get_spec(); | 2757 return ast_properties_.get_spec(); |
| 2754 } | 2758 } |
| 2755 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } | 2759 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } |
| 2756 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } | 2760 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } |
| 2757 void set_dont_optimize_reason(BailoutReason reason) { | 2761 void set_dont_optimize_reason(BailoutReason reason) { |
| 2758 dont_optimize_reason_ = reason; | 2762 dont_optimize_reason_ = reason; |
| 2759 } | 2763 } |
| 2760 | 2764 |
| 2765 bool IsAnonymousFunctionDefinition() const final { |
| 2766 // TODO(adamk): This isn't quite accurate, as many non-expressions |
| 2767 // (such as concise methods) are marked as anonymous, but it's |
| 2768 // sufficient for the current callers. |
| 2769 return is_anonymous(); |
| 2770 } |
| 2771 |
| 2761 protected: | 2772 protected: |
| 2762 FunctionLiteral(Zone* zone, const AstString* name, | 2773 FunctionLiteral(Zone* zone, const AstString* name, |
| 2763 AstValueFactory* ast_value_factory, Scope* scope, | 2774 AstValueFactory* ast_value_factory, Scope* scope, |
| 2764 ZoneList<Statement*>* body, int materialized_literal_count, | 2775 ZoneList<Statement*>* body, int materialized_literal_count, |
| 2765 int expected_property_count, int parameter_count, | 2776 int expected_property_count, int parameter_count, |
| 2766 FunctionType function_type, | 2777 FunctionType function_type, |
| 2767 ParameterFlag has_duplicate_parameters, | 2778 ParameterFlag has_duplicate_parameters, |
| 2768 EagerCompileHint eager_compile_hint, FunctionKind kind, | 2779 EagerCompileHint eager_compile_hint, FunctionKind kind, |
| 2769 int position) | 2780 int position) |
| 2770 : Expression(zone, position), | 2781 : Expression(zone, position), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2818 int function_token_position_; | 2829 int function_token_position_; |
| 2819 }; | 2830 }; |
| 2820 | 2831 |
| 2821 | 2832 |
| 2822 class ClassLiteral final : public Expression { | 2833 class ClassLiteral final : public Expression { |
| 2823 public: | 2834 public: |
| 2824 typedef ObjectLiteralProperty Property; | 2835 typedef ObjectLiteralProperty Property; |
| 2825 | 2836 |
| 2826 DECLARE_NODE_TYPE(ClassLiteral) | 2837 DECLARE_NODE_TYPE(ClassLiteral) |
| 2827 | 2838 |
| 2828 Handle<String> name() const { return raw_name_->string(); } | |
| 2829 const AstRawString* raw_name() const { return raw_name_; } | |
| 2830 void set_raw_name(const AstRawString* name) { | |
| 2831 DCHECK_NULL(raw_name_); | |
| 2832 raw_name_ = name; | |
| 2833 } | |
| 2834 | |
| 2835 Scope* scope() const { return scope_; } | 2839 Scope* scope() const { return scope_; } |
| 2836 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; } | 2840 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; } |
| 2837 Expression* extends() const { return extends_; } | 2841 Expression* extends() const { return extends_; } |
| 2838 void set_extends(Expression* e) { extends_ = e; } | 2842 void set_extends(Expression* e) { extends_ = e; } |
| 2839 FunctionLiteral* constructor() const { return constructor_; } | 2843 FunctionLiteral* constructor() const { return constructor_; } |
| 2840 void set_constructor(FunctionLiteral* f) { constructor_ = f; } | 2844 void set_constructor(FunctionLiteral* f) { constructor_ = f; } |
| 2841 ZoneList<Property*>* properties() const { return properties_; } | 2845 ZoneList<Property*>* properties() const { return properties_; } |
| 2842 int start_position() const { return position(); } | 2846 int start_position() const { return position(); } |
| 2843 int end_position() const { return end_position_; } | 2847 int end_position() const { return end_position_; } |
| 2844 | 2848 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2859 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, | 2863 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, |
| 2860 FeedbackVectorSlotCache* cache) override; | 2864 FeedbackVectorSlotCache* cache) override; |
| 2861 | 2865 |
| 2862 bool NeedsProxySlot() const { | 2866 bool NeedsProxySlot() const { |
| 2863 return class_variable_proxy() != nullptr && | 2867 return class_variable_proxy() != nullptr && |
| 2864 class_variable_proxy()->var()->IsUnallocated(); | 2868 class_variable_proxy()->var()->IsUnallocated(); |
| 2865 } | 2869 } |
| 2866 | 2870 |
| 2867 FeedbackVectorSlot ProxySlot() const { return slot_; } | 2871 FeedbackVectorSlot ProxySlot() const { return slot_; } |
| 2868 | 2872 |
| 2873 bool IsAnonymousFunctionDefinition() const final { |
| 2874 return constructor()->raw_name()->length() == 0; |
| 2875 } |
| 2876 |
| 2869 protected: | 2877 protected: |
| 2870 ClassLiteral(Zone* zone, const AstRawString* name, Scope* scope, | 2878 ClassLiteral(Zone* zone, Scope* scope, VariableProxy* class_variable_proxy, |
| 2871 VariableProxy* class_variable_proxy, Expression* extends, | 2879 Expression* extends, FunctionLiteral* constructor, |
| 2872 FunctionLiteral* constructor, ZoneList<Property*>* properties, | 2880 ZoneList<Property*>* properties, int start_position, |
| 2873 int start_position, int end_position) | 2881 int end_position) |
| 2874 : Expression(zone, start_position), | 2882 : Expression(zone, start_position), |
| 2875 raw_name_(name), | |
| 2876 scope_(scope), | 2883 scope_(scope), |
| 2877 class_variable_proxy_(class_variable_proxy), | 2884 class_variable_proxy_(class_variable_proxy), |
| 2878 extends_(extends), | 2885 extends_(extends), |
| 2879 constructor_(constructor), | 2886 constructor_(constructor), |
| 2880 properties_(properties), | 2887 properties_(properties), |
| 2881 end_position_(end_position) {} | 2888 end_position_(end_position) {} |
| 2882 | 2889 |
| 2883 static int parent_num_ids() { return Expression::num_ids(); } | 2890 static int parent_num_ids() { return Expression::num_ids(); } |
| 2884 | 2891 |
| 2885 private: | 2892 private: |
| 2886 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 2893 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
| 2887 | 2894 |
| 2888 const AstRawString* raw_name_; | |
| 2889 Scope* scope_; | 2895 Scope* scope_; |
| 2890 VariableProxy* class_variable_proxy_; | 2896 VariableProxy* class_variable_proxy_; |
| 2891 Expression* extends_; | 2897 Expression* extends_; |
| 2892 FunctionLiteral* constructor_; | 2898 FunctionLiteral* constructor_; |
| 2893 ZoneList<Property*>* properties_; | 2899 ZoneList<Property*>* properties_; |
| 2894 int end_position_; | 2900 int end_position_; |
| 2895 FeedbackVectorSlot slot_; | 2901 FeedbackVectorSlot slot_; |
| 2896 }; | 2902 }; |
| 2897 | 2903 |
| 2898 | 2904 |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3474 FunctionLiteral::FunctionType function_type, | 3480 FunctionLiteral::FunctionType function_type, |
| 3475 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind, | 3481 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind, |
| 3476 int position) { | 3482 int position) { |
| 3477 return new (parser_zone_) FunctionLiteral( | 3483 return new (parser_zone_) FunctionLiteral( |
| 3478 parser_zone_, name, ast_value_factory_, scope, body, | 3484 parser_zone_, name, ast_value_factory_, scope, body, |
| 3479 materialized_literal_count, expected_property_count, parameter_count, | 3485 materialized_literal_count, expected_property_count, parameter_count, |
| 3480 function_type, has_duplicate_parameters, eager_compile_hint, kind, | 3486 function_type, has_duplicate_parameters, eager_compile_hint, kind, |
| 3481 position); | 3487 position); |
| 3482 } | 3488 } |
| 3483 | 3489 |
| 3484 ClassLiteral* NewClassLiteral(const AstRawString* name, Scope* scope, | 3490 ClassLiteral* NewClassLiteral(Scope* scope, VariableProxy* proxy, |
| 3485 VariableProxy* proxy, Expression* extends, | 3491 Expression* extends, |
| 3486 FunctionLiteral* constructor, | 3492 FunctionLiteral* constructor, |
| 3487 ZoneList<ObjectLiteral::Property*>* properties, | 3493 ZoneList<ObjectLiteral::Property*>* properties, |
| 3488 int start_position, int end_position) { | 3494 int start_position, int end_position) { |
| 3489 return new (parser_zone_) | 3495 return new (parser_zone_) |
| 3490 ClassLiteral(parser_zone_, name, scope, proxy, extends, constructor, | 3496 ClassLiteral(parser_zone_, scope, proxy, extends, constructor, |
| 3491 properties, start_position, end_position); | 3497 properties, start_position, end_position); |
| 3492 } | 3498 } |
| 3493 | 3499 |
| 3494 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, | 3500 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, |
| 3495 v8::Extension* extension, | 3501 v8::Extension* extension, |
| 3496 int pos) { | 3502 int pos) { |
| 3497 return new (parser_zone_) | 3503 return new (parser_zone_) |
| 3498 NativeFunctionLiteral(parser_zone_, name, extension, pos); | 3504 NativeFunctionLiteral(parser_zone_, name, extension, pos); |
| 3499 } | 3505 } |
| 3500 | 3506 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3555 // the parser-level zone. | 3561 // the parser-level zone. |
| 3556 Zone* parser_zone_; | 3562 Zone* parser_zone_; |
| 3557 AstValueFactory* ast_value_factory_; | 3563 AstValueFactory* ast_value_factory_; |
| 3558 }; | 3564 }; |
| 3559 | 3565 |
| 3560 | 3566 |
| 3561 } // namespace internal | 3567 } // namespace internal |
| 3562 } // namespace v8 | 3568 } // namespace v8 |
| 3563 | 3569 |
| 3564 #endif // V8_AST_AST_H_ | 3570 #endif // V8_AST_AST_H_ |
| OLD | NEW |