| 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_PARSING_PARSER_H_ | 5 #ifndef V8_PARSING_PARSER_H_ |
| 6 #define V8_PARSING_PARSER_H_ | 6 #define V8_PARSING_PARSER_H_ |
| 7 | 7 |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
| 10 #include "src/parsing/parser-base.h" | 10 #include "src/parsing/parser-base.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 typedef Yield* YieldExpression; | 152 typedef Yield* YieldExpression; |
| 153 typedef v8::internal::FunctionLiteral* FunctionLiteral; | 153 typedef v8::internal::FunctionLiteral* FunctionLiteral; |
| 154 typedef v8::internal::ClassLiteral* ClassLiteral; | 154 typedef v8::internal::ClassLiteral* ClassLiteral; |
| 155 typedef v8::internal::Literal* Literal; | 155 typedef v8::internal::Literal* Literal; |
| 156 typedef ObjectLiteral::Property* ObjectLiteralProperty; | 156 typedef ObjectLiteral::Property* ObjectLiteralProperty; |
| 157 typedef ZoneList<v8::internal::Expression*>* ExpressionList; | 157 typedef ZoneList<v8::internal::Expression*>* ExpressionList; |
| 158 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; | 158 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; |
| 159 typedef ParserFormalParameters::Parameter FormalParameter; | 159 typedef ParserFormalParameters::Parameter FormalParameter; |
| 160 typedef ParserFormalParameters FormalParameters; | 160 typedef ParserFormalParameters FormalParameters; |
| 161 typedef ZoneList<v8::internal::Statement*>* StatementList; | 161 typedef ZoneList<v8::internal::Statement*>* StatementList; |
| 162 typedef v8::internal::Block* Block; |
| 162 | 163 |
| 163 // For constructing objects returned by the traversing functions. | 164 // For constructing objects returned by the traversing functions. |
| 164 typedef AstNodeFactory Factory; | 165 typedef AstNodeFactory Factory; |
| 165 }; | 166 }; |
| 166 | 167 |
| 167 class Parser : public ParserBase<Parser> { | 168 class Parser : public ParserBase<Parser> { |
| 168 public: | 169 public: |
| 169 explicit Parser(ParseInfo* info); | 170 explicit Parser(ParseInfo* info); |
| 170 ~Parser() { | 171 ~Parser() { |
| 171 delete reusable_preparser_; | 172 delete reusable_preparser_; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 Statement* ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, | 289 Statement* ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, |
| 289 bool default_export, bool* ok); | 290 bool default_export, bool* ok); |
| 290 Expression* ParseAsyncFunctionExpression(bool* ok); | 291 Expression* ParseAsyncFunctionExpression(bool* ok); |
| 291 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names, | 292 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names, |
| 292 bool default_export, bool* ok); | 293 bool default_export, bool* ok); |
| 293 Statement* ParseNativeDeclaration(bool* ok); | 294 Statement* ParseNativeDeclaration(bool* ok); |
| 294 Block* ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok); | 295 Block* ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok); |
| 295 Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result, | 296 Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result, |
| 296 ZoneList<const AstRawString*>* names, | 297 ZoneList<const AstRawString*>* names, |
| 297 bool* ok); | 298 bool* ok); |
| 299 void DeclareAndInitializeVariables( |
| 300 Block* block, const DeclarationDescriptor* declaration_descriptor, |
| 301 const DeclarationParsingResult::Declaration* declaration, |
| 302 ZoneList<const AstRawString*>* names, bool* ok); |
| 298 | 303 |
| 299 Block* ParseVariableStatement(VariableDeclarationContext var_context, | 304 Block* ParseVariableStatement(VariableDeclarationContext var_context, |
| 300 ZoneList<const AstRawString*>* names, | 305 ZoneList<const AstRawString*>* names, |
| 301 bool* ok); | 306 bool* ok); |
| 302 DoExpression* ParseDoExpression(bool* ok); | 307 DoExpression* ParseDoExpression(bool* ok); |
| 303 Expression* ParseYieldStarExpression(bool* ok); | 308 Expression* ParseYieldStarExpression(bool* ok); |
| 304 | 309 |
| 305 class PatternRewriter final : public AstVisitor<PatternRewriter> { | 310 class PatternRewriter final : public AstVisitor<PatternRewriter> { |
| 306 public: | 311 public: |
| 307 static void DeclareAndInitializeVariables( | 312 static void DeclareAndInitializeVariables( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 Block* block_; | 381 Block* block_; |
| 377 const DeclarationDescriptor* descriptor_; | 382 const DeclarationDescriptor* descriptor_; |
| 378 ZoneList<const AstRawString*>* names_; | 383 ZoneList<const AstRawString*>* names_; |
| 379 Expression* current_value_; | 384 Expression* current_value_; |
| 380 int recursion_level_; | 385 int recursion_level_; |
| 381 bool* ok_; | 386 bool* ok_; |
| 382 | 387 |
| 383 DEFINE_AST_VISITOR_MEMBERS_WITHOUT_STACKOVERFLOW() | 388 DEFINE_AST_VISITOR_MEMBERS_WITHOUT_STACKOVERFLOW() |
| 384 }; | 389 }; |
| 385 | 390 |
| 386 Block* ParseVariableDeclarations(VariableDeclarationContext var_context, | |
| 387 DeclarationParsingResult* parsing_result, | |
| 388 ZoneList<const AstRawString*>* names, | |
| 389 bool* ok); | |
| 390 Statement* ParseExpressionOrLabelledStatement( | 391 Statement* ParseExpressionOrLabelledStatement( |
| 391 ZoneList<const AstRawString*>* labels, | 392 ZoneList<const AstRawString*>* labels, |
| 392 AllowLabelledFunctionStatement allow_function, bool* ok); | 393 AllowLabelledFunctionStatement allow_function, bool* ok); |
| 393 IfStatement* ParseIfStatement(ZoneList<const AstRawString*>* labels, | 394 IfStatement* ParseIfStatement(ZoneList<const AstRawString*>* labels, |
| 394 bool* ok); | 395 bool* ok); |
| 395 Statement* ParseContinueStatement(bool* ok); | 396 Statement* ParseContinueStatement(bool* ok); |
| 396 Statement* ParseBreakStatement(ZoneList<const AstRawString*>* labels, | 397 Statement* ParseBreakStatement(ZoneList<const AstRawString*>* labels, |
| 397 bool* ok); | 398 bool* ok); |
| 398 Statement* ParseReturnStatement(bool* ok); | 399 Statement* ParseReturnStatement(bool* ok); |
| 399 Statement* ParseWithStatement(ZoneList<const AstRawString*>* labels, | 400 Statement* ParseWithStatement(ZoneList<const AstRawString*>* labels, |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 return property->value(); | 715 return property->value(); |
| 715 } | 716 } |
| 716 | 717 |
| 717 // Functions for encapsulating the differences between parsing and preparsing; | 718 // Functions for encapsulating the differences between parsing and preparsing; |
| 718 // operations interleaved with the recursive descent. | 719 // operations interleaved with the recursive descent. |
| 719 V8_INLINE static void PushLiteralName(FuncNameInferrer* fni, | 720 V8_INLINE static void PushLiteralName(FuncNameInferrer* fni, |
| 720 const AstRawString* id) { | 721 const AstRawString* id) { |
| 721 fni->PushLiteralName(id); | 722 fni->PushLiteralName(id); |
| 722 } | 723 } |
| 723 | 724 |
| 725 V8_INLINE static void PushVariableName(FuncNameInferrer* fni, |
| 726 const AstRawString* id) { |
| 727 fni->PushVariableName(id); |
| 728 } |
| 729 |
| 724 V8_INLINE void PushPropertyName(FuncNameInferrer* fni, | 730 V8_INLINE void PushPropertyName(FuncNameInferrer* fni, |
| 725 Expression* expression) { | 731 Expression* expression) { |
| 726 if (expression->IsPropertyName()) { | 732 if (expression->IsPropertyName()) { |
| 727 fni->PushLiteralName(expression->AsLiteral()->AsRawPropertyName()); | 733 fni->PushLiteralName(expression->AsLiteral()->AsRawPropertyName()); |
| 728 } else { | 734 } else { |
| 729 fni->PushLiteralName(ast_value_factory()->anonymous_function_string()); | 735 fni->PushLiteralName(ast_value_factory()->anonymous_function_string()); |
| 730 } | 736 } |
| 731 } | 737 } |
| 732 | 738 |
| 733 V8_INLINE static void InferFunctionName(FuncNameInferrer* fni, | 739 V8_INLINE static void InferFunctionName(FuncNameInferrer* fni, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 } | 839 } |
| 834 | 840 |
| 835 // "null" return type creators. | 841 // "null" return type creators. |
| 836 V8_INLINE static const AstRawString* EmptyIdentifier() { return nullptr; } | 842 V8_INLINE static const AstRawString* EmptyIdentifier() { return nullptr; } |
| 837 V8_INLINE static Expression* EmptyExpression() { return nullptr; } | 843 V8_INLINE static Expression* EmptyExpression() { return nullptr; } |
| 838 V8_INLINE static Literal* EmptyLiteral() { return nullptr; } | 844 V8_INLINE static Literal* EmptyLiteral() { return nullptr; } |
| 839 V8_INLINE static ObjectLiteralProperty* EmptyObjectLiteralProperty() { | 845 V8_INLINE static ObjectLiteralProperty* EmptyObjectLiteralProperty() { |
| 840 return nullptr; | 846 return nullptr; |
| 841 } | 847 } |
| 842 V8_INLINE static FunctionLiteral* EmptyFunctionLiteral() { return nullptr; } | 848 V8_INLINE static FunctionLiteral* EmptyFunctionLiteral() { return nullptr; } |
| 849 V8_INLINE static Block* NullBlock() { return nullptr; } |
| 843 | 850 |
| 844 V8_INLINE static bool IsEmptyExpression(Expression* expr) { | 851 V8_INLINE static bool IsEmptyExpression(Expression* expr) { |
| 845 return expr == nullptr; | 852 return expr == nullptr; |
| 846 } | 853 } |
| 847 | 854 |
| 848 // Used in error return values. | 855 // Used in error return values. |
| 849 V8_INLINE static ZoneList<Expression*>* NullExpressionList() { | 856 V8_INLINE static ZoneList<Expression*>* NullExpressionList() { |
| 850 return nullptr; | 857 return nullptr; |
| 851 } | 858 } |
| 852 | 859 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 return new (zone()) ZoneList<Expression*>(size, zone()); | 916 return new (zone()) ZoneList<Expression*>(size, zone()); |
| 910 } | 917 } |
| 911 V8_INLINE ZoneList<ObjectLiteral::Property*>* NewPropertyList( | 918 V8_INLINE ZoneList<ObjectLiteral::Property*>* NewPropertyList( |
| 912 int size) const { | 919 int size) const { |
| 913 return new (zone()) ZoneList<ObjectLiteral::Property*>(size, zone()); | 920 return new (zone()) ZoneList<ObjectLiteral::Property*>(size, zone()); |
| 914 } | 921 } |
| 915 V8_INLINE ZoneList<Statement*>* NewStatementList(int size) const { | 922 V8_INLINE ZoneList<Statement*>* NewStatementList(int size) const { |
| 916 return new (zone()) ZoneList<Statement*>(size, zone()); | 923 return new (zone()) ZoneList<Statement*>(size, zone()); |
| 917 } | 924 } |
| 918 | 925 |
| 926 V8_INLINE Block* NewBlock(ZoneList<const AstRawString*>* labels, int capacity, |
| 927 bool ignore_completion_value, int pos) { |
| 928 return factory()->NewBlock(labels, capacity, ignore_completion_value, pos); |
| 929 } |
| 930 |
| 919 V8_INLINE void AddParameterInitializationBlock( | 931 V8_INLINE void AddParameterInitializationBlock( |
| 920 const ParserFormalParameters& parameters, ZoneList<Statement*>* body, | 932 const ParserFormalParameters& parameters, ZoneList<Statement*>* body, |
| 921 bool is_async, bool* ok) { | 933 bool is_async, bool* ok) { |
| 922 if (parameters.is_simple) return; | 934 if (parameters.is_simple) return; |
| 923 auto* init_block = BuildParameterInitializationBlock(parameters, ok); | 935 auto* init_block = BuildParameterInitializationBlock(parameters, ok); |
| 924 if (!*ok) return; | 936 if (!*ok) return; |
| 925 if (is_async) { | 937 if (is_async) { |
| 926 init_block = BuildRejectPromiseOnException(init_block, ok); | 938 init_block = BuildRejectPromiseOnException(init_block, ok); |
| 927 if (!*ok) return; | 939 if (!*ok) return; |
| 928 } | 940 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 static const int kLiteralTypeSlot = 0; | 1062 static const int kLiteralTypeSlot = 0; |
| 1051 static const int kElementsSlot = 1; | 1063 static const int kElementsSlot = 1; |
| 1052 | 1064 |
| 1053 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 1065 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 1054 }; | 1066 }; |
| 1055 | 1067 |
| 1056 } // namespace internal | 1068 } // namespace internal |
| 1057 } // namespace v8 | 1069 } // namespace v8 |
| 1058 | 1070 |
| 1059 #endif // V8_PARSING_PARSER_H_ | 1071 #endif // V8_PARSING_PARSER_H_ |
| OLD | NEW |