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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 139 |
140 template <> | 140 template <> |
141 struct ParserTypes<Parser> { | 141 struct ParserTypes<Parser> { |
142 typedef ParserBase<Parser> Base; | 142 typedef ParserBase<Parser> Base; |
143 typedef Parser Impl; | 143 typedef Parser Impl; |
144 | 144 |
145 typedef Variable GeneratorVariable; | 145 typedef Variable GeneratorVariable; |
146 | 146 |
147 typedef v8::internal::AstProperties AstProperties; | 147 typedef v8::internal::AstProperties AstProperties; |
148 | 148 |
149 typedef v8::internal::ExpressionClassifier<ParserTypes<Parser>> | |
150 ExpressionClassifier; | |
151 | |
152 // Return types for traversing functions. | 149 // Return types for traversing functions. |
153 typedef const AstRawString* Identifier; | 150 typedef const AstRawString* Identifier; |
154 typedef v8::internal::Expression* Expression; | 151 typedef v8::internal::Expression* Expression; |
155 typedef Yield* YieldExpression; | 152 typedef Yield* YieldExpression; |
156 typedef v8::internal::FunctionLiteral* FunctionLiteral; | 153 typedef v8::internal::FunctionLiteral* FunctionLiteral; |
157 typedef v8::internal::ClassLiteral* ClassLiteral; | 154 typedef v8::internal::ClassLiteral* ClassLiteral; |
158 typedef v8::internal::Literal* Literal; | 155 typedef v8::internal::Literal* Literal; |
159 typedef ObjectLiteral::Property* ObjectLiteralProperty; | 156 typedef ObjectLiteral::Property* ObjectLiteralProperty; |
160 typedef ZoneList<v8::internal::Expression*>* ExpressionList; | 157 typedef ZoneList<v8::internal::Expression*>* ExpressionList; |
161 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; | 158 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 Expression* iterable, Statement* body, | 467 Expression* iterable, Statement* body, |
471 bool finalize, | 468 bool finalize, |
472 int next_result_pos = kNoSourcePosition); | 469 int next_result_pos = kNoSourcePosition); |
473 Statement* DesugarLexicalBindingsInForStatement( | 470 Statement* DesugarLexicalBindingsInForStatement( |
474 Scope* inner_scope, VariableMode mode, | 471 Scope* inner_scope, VariableMode mode, |
475 ZoneList<const AstRawString*>* names, ForStatement* loop, Statement* init, | 472 ZoneList<const AstRawString*>* names, ForStatement* loop, Statement* init, |
476 Expression* cond, Statement* next, Statement* body, bool* ok); | 473 Expression* cond, Statement* next, Statement* body, bool* ok); |
477 | 474 |
478 void DesugarAsyncFunctionBody(const AstRawString* function_name, Scope* scope, | 475 void DesugarAsyncFunctionBody(const AstRawString* function_name, Scope* scope, |
479 ZoneList<Statement*>* body, | 476 ZoneList<Statement*>* body, |
480 ExpressionClassifier* classifier, | |
481 FunctionKind kind, FunctionBodyType type, | 477 FunctionKind kind, FunctionBodyType type, |
482 bool accept_IN, int pos, bool* ok); | 478 bool accept_IN, int pos, bool* ok); |
483 | 479 |
484 void RewriteDoExpression(Expression* expr, bool* ok); | 480 void RewriteDoExpression(Expression* expr, bool* ok); |
485 | 481 |
486 FunctionLiteral* ParseFunctionLiteral( | 482 FunctionLiteral* ParseFunctionLiteral( |
487 const AstRawString* name, Scanner::Location function_name_location, | 483 const AstRawString* name, Scanner::Location function_name_location, |
488 FunctionNameValidity function_name_validity, FunctionKind kind, | 484 FunctionNameValidity function_name_validity, FunctionKind kind, |
489 int function_token_position, FunctionLiteral::FunctionType type, | 485 int function_token_position, FunctionLiteral::FunctionType type, |
490 LanguageMode language_mode, bool* ok); | 486 LanguageMode language_mode, bool* ok); |
491 | 487 |
492 Expression* ParseClassLiteral(ExpressionClassifier* classifier, | 488 Expression* ParseClassLiteral(const AstRawString* name, |
493 const AstRawString* name, | |
494 Scanner::Location class_name_location, | 489 Scanner::Location class_name_location, |
495 bool name_is_strict_reserved, int pos, | 490 bool name_is_strict_reserved, int pos, |
496 bool* ok); | 491 bool* ok); |
497 | 492 |
498 // Magical syntax support. | 493 // Magical syntax support. |
499 Expression* ParseV8Intrinsic(bool* ok); | 494 Expression* ParseV8Intrinsic(bool* ok); |
500 | 495 |
501 // Get odd-ball literals. | 496 // Get odd-ball literals. |
502 Literal* GetLiteralUndefined(int position); | 497 Literal* GetLiteralUndefined(int position); |
503 | 498 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 TemplateLiteralState OpenTemplateLiteral(int pos); | 600 TemplateLiteralState OpenTemplateLiteral(int pos); |
606 void AddTemplateSpan(TemplateLiteralState* state, bool tail); | 601 void AddTemplateSpan(TemplateLiteralState* state, bool tail); |
607 void AddTemplateExpression(TemplateLiteralState* state, | 602 void AddTemplateExpression(TemplateLiteralState* state, |
608 Expression* expression); | 603 Expression* expression); |
609 Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start, | 604 Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start, |
610 Expression* tag); | 605 Expression* tag); |
611 uint32_t ComputeTemplateLiteralHash(const TemplateLiteral* lit); | 606 uint32_t ComputeTemplateLiteralHash(const TemplateLiteral* lit); |
612 | 607 |
613 void ParseAsyncArrowSingleExpressionBody(ZoneList<Statement*>* body, | 608 void ParseAsyncArrowSingleExpressionBody(ZoneList<Statement*>* body, |
614 bool accept_IN, | 609 bool accept_IN, |
615 ExpressionClassifier* classifier, | |
616 int pos, bool* ok) { | 610 int pos, bool* ok) { |
617 DesugarAsyncFunctionBody(ast_value_factory()->empty_string(), scope(), body, | 611 DesugarAsyncFunctionBody( |
618 classifier, kAsyncArrowFunction, | 612 ast_value_factory()->empty_string(), scope(), body, kAsyncArrowFunction, |
619 FunctionBodyType::kSingleExpression, accept_IN, | 613 FunctionBodyType::kSingleExpression, accept_IN, pos, ok); |
620 pos, ok); | |
621 } | 614 } |
622 | 615 |
623 ZoneList<Expression*>* PrepareSpreadArguments(ZoneList<Expression*>* list); | 616 ZoneList<Expression*>* PrepareSpreadArguments(ZoneList<Expression*>* list); |
624 Expression* SpreadCall(Expression* function, ZoneList<Expression*>* args, | 617 Expression* SpreadCall(Expression* function, ZoneList<Expression*>* args, |
625 int pos); | 618 int pos); |
626 Expression* SpreadCallNew(Expression* function, ZoneList<Expression*>* args, | 619 Expression* SpreadCallNew(Expression* function, ZoneList<Expression*>* args, |
627 int pos); | 620 int pos); |
628 | 621 |
629 void SetLanguageMode(Scope* scope, LanguageMode mode); | 622 void SetLanguageMode(Scope* scope, LanguageMode mode); |
630 void RaiseLanguageMode(LanguageMode mode); | 623 void RaiseLanguageMode(LanguageMode mode); |
631 | 624 |
632 V8_INLINE void MarkCollectedTailCallExpressions(); | 625 V8_INLINE void MarkCollectedTailCallExpressions(); |
633 V8_INLINE void MarkTailPosition(Expression* expression); | 626 V8_INLINE void MarkTailPosition(Expression* expression); |
634 | 627 |
635 // Rewrite all DestructuringAssignments in the current FunctionState. | 628 // Rewrite all DestructuringAssignments in the current FunctionState. |
636 V8_INLINE void RewriteDestructuringAssignments(); | 629 V8_INLINE void RewriteDestructuringAssignments(); |
637 | 630 |
638 V8_INLINE Expression* RewriteExponentiation(Expression* left, | 631 V8_INLINE Expression* RewriteExponentiation(Expression* left, |
639 Expression* right, int pos); | 632 Expression* right, int pos); |
640 V8_INLINE Expression* RewriteAssignExponentiation(Expression* left, | 633 V8_INLINE Expression* RewriteAssignExponentiation(Expression* left, |
641 Expression* right, int pos); | 634 Expression* right, int pos); |
642 | 635 |
643 friend class NonPatternRewriter; | 636 friend class NonPatternRewriter; |
644 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit); | 637 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit); |
645 | 638 |
646 // Rewrite expressions that are not used as patterns | 639 // Rewrite expressions that are not used as patterns |
647 V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok); | 640 V8_INLINE void RewriteNonPattern(bool* ok); |
648 | 641 |
649 V8_INLINE void QueueDestructuringAssignmentForRewriting( | 642 V8_INLINE void QueueDestructuringAssignmentForRewriting( |
650 Expression* assignment); | 643 Expression* assignment); |
651 V8_INLINE void QueueNonPatternForRewriting(Expression* expr, bool* ok); | 644 V8_INLINE void QueueNonPatternForRewriting(Expression* expr, bool* ok); |
652 | 645 |
653 friend class InitializerRewriter; | 646 friend class InitializerRewriter; |
654 void RewriteParameterInitializer(Expression* expr, Scope* scope); | 647 void RewriteParameterInitializer(Expression* expr, Scope* scope); |
655 | 648 |
656 Expression* BuildCreateJSGeneratorObject(int pos, FunctionKind kind); | 649 Expression* BuildCreateJSGeneratorObject(int pos, FunctionKind kind); |
657 Expression* BuildResolvePromise(Expression* value, int pos); | 650 Expression* BuildResolvePromise(Expression* value, int pos); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 ? pattern->AsVariableProxy()->raw_name() | 968 ? pattern->AsVariableProxy()->raw_name() |
976 : ast_value_factory()->empty_string(); | 969 : ast_value_factory()->empty_string(); |
977 parameters->params.Add( | 970 parameters->params.Add( |
978 ParserFormalParameters::Parameter(name, pattern, initializer, | 971 ParserFormalParameters::Parameter(name, pattern, initializer, |
979 initializer_end_position, is_rest), | 972 initializer_end_position, is_rest), |
980 parameters->scope->zone()); | 973 parameters->scope->zone()); |
981 } | 974 } |
982 | 975 |
983 V8_INLINE void DeclareFormalParameter( | 976 V8_INLINE void DeclareFormalParameter( |
984 DeclarationScope* scope, | 977 DeclarationScope* scope, |
985 const ParserFormalParameters::Parameter& parameter, | 978 const ParserFormalParameters::Parameter& parameter) { |
986 ExpressionClassifier* classifier) { | |
987 bool is_duplicate = false; | 979 bool is_duplicate = false; |
988 bool is_simple = classifier->is_simple_parameter_list(); | 980 bool is_simple = classifier()->is_simple_parameter_list(); |
989 auto name = is_simple || parameter.is_rest | 981 auto name = is_simple || parameter.is_rest |
990 ? parameter.name | 982 ? parameter.name |
991 : ast_value_factory()->empty_string(); | 983 : ast_value_factory()->empty_string(); |
992 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY; | 984 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY; |
993 if (!is_simple) scope->SetHasNonSimpleParameters(); | 985 if (!is_simple) scope->SetHasNonSimpleParameters(); |
994 bool is_optional = parameter.initializer != nullptr; | 986 bool is_optional = parameter.initializer != nullptr; |
995 Variable* var = | 987 Variable* var = |
996 scope->DeclareParameter(name, mode, is_optional, parameter.is_rest, | 988 scope->DeclareParameter(name, mode, is_optional, parameter.is_rest, |
997 &is_duplicate, ast_value_factory()); | 989 &is_duplicate, ast_value_factory()); |
998 if (is_duplicate) { | 990 if (is_duplicate) { |
999 classifier->RecordDuplicateFormalParameterError(scanner()->location()); | 991 classifier()->RecordDuplicateFormalParameterError(scanner()->location()); |
1000 } | 992 } |
1001 if (is_sloppy(scope->language_mode())) { | 993 if (is_sloppy(scope->language_mode())) { |
1002 // TODO(sigurds) Mark every parameter as maybe assigned. This is a | 994 // TODO(sigurds) Mark every parameter as maybe assigned. This is a |
1003 // conservative approximation necessary to account for parameters | 995 // conservative approximation necessary to account for parameters |
1004 // that are assigned via the arguments array. | 996 // that are assigned via the arguments array. |
1005 var->set_maybe_assigned(); | 997 var->set_maybe_assigned(); |
1006 } | 998 } |
1007 } | 999 } |
1008 | 1000 |
1009 void ParseArrowFunctionFormalParameterList( | 1001 void ParseArrowFunctionFormalParameterList( |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 static const int kLiteralTypeSlot = 0; | 1079 static const int kLiteralTypeSlot = 0; |
1088 static const int kElementsSlot = 1; | 1080 static const int kElementsSlot = 1; |
1089 | 1081 |
1090 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 1082 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
1091 }; | 1083 }; |
1092 | 1084 |
1093 } // namespace internal | 1085 } // namespace internal |
1094 } // namespace v8 | 1086 } // namespace v8 |
1095 | 1087 |
1096 #endif // V8_PARSING_PARSER_H_ | 1088 #endif // V8_PARSING_PARSER_H_ |
OLD | NEW |